A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
dsdv-testcase.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Hemanth Narra
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Hemanth Narra <hemanth@ittc.ku.com>
19
*
20
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22
* Information and Telecommunication Technology Center (ITTC)
23
* and Department of Electrical Engineering and Computer Science
24
* The University of Kansas Lawrence, KS USA.
25
*
26
* Work supported in part by NSF FIND (Future Internet Design) Program
27
* under grant CNS-0626918 (Postmodern Internet Architecture),
28
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
* US Department of Defense (DoD), and ITTC at The University of Kansas.
30
*/
31
#include "ns3/test.h"
32
#include "ns3/mesh-helper.h"
33
#include "ns3/simulator.h"
34
#include "ns3/mobility-helper.h"
35
#include "ns3/dsdv-helper.h"
36
#include "ns3/double.h"
37
#include "ns3/uinteger.h"
38
#include "ns3/v4ping-helper.h"
39
#include "ns3/string.h"
40
#include "ns3/boolean.h"
41
#include "ns3/pcap-file.h"
42
#include "ns3/internet-stack-helper.h"
43
#include "ns3/ipv4-address-helper.h"
44
#include "ns3/dsdv-packet.h"
45
#include "ns3/dsdv-rtable.h"
46
47
using namespace
ns3
;
48
62
class
DsdvHeaderTestCase
:
public
TestCase
63
{
64
public
:
65
DsdvHeaderTestCase
();
66
~
DsdvHeaderTestCase
();
67
virtual
void
68
DoRun (
void
);
69
};
70
DsdvHeaderTestCase::DsdvHeaderTestCase
()
71
:
TestCase
(
"Verifying the DSDV header"
)
72
{
73
}
74
DsdvHeaderTestCase::~DsdvHeaderTestCase
()
75
{
76
}
77
void
78
DsdvHeaderTestCase::DoRun
()
79
{
80
Ptr<Packet>
packet = Create<Packet> ();
81
82
{
83
dsdv::DsdvHeader
hdr1;
84
hdr1.
SetDst
(
Ipv4Address
(
"10.1.1.2"
));
85
hdr1.
SetDstSeqno
(2);
86
hdr1.
SetHopCount
(2);
87
packet->
AddHeader
(hdr1);
88
dsdv::DsdvHeader
hdr2;
89
hdr2.
SetDst
(
Ipv4Address
(
"10.1.1.3"
));
90
hdr2.
SetDstSeqno
(4);
91
hdr2.
SetHopCount
(1);
92
packet->
AddHeader
(hdr2);
93
NS_TEST_ASSERT_MSG_EQ
(packet->
GetSize
(), 24,
"001"
);
94
}
95
96
{
97
dsdv::DsdvHeader
hdr2;
98
packet->
RemoveHeader
(hdr2);
99
NS_TEST_ASSERT_MSG_EQ
(hdr2.
GetSerializedSize
(),12,
"002"
);
100
NS_TEST_ASSERT_MSG_EQ
(hdr2.
GetDst
(),
Ipv4Address
(
"10.1.1.3"
),
"003"
);
101
NS_TEST_ASSERT_MSG_EQ
(hdr2.
GetDstSeqno
(),4,
"004"
);
102
NS_TEST_ASSERT_MSG_EQ
(hdr2.
GetHopCount
(),1,
"005"
);
103
dsdv::DsdvHeader
hdr1;
104
packet->
RemoveHeader
(hdr1);
105
NS_TEST_ASSERT_MSG_EQ
(hdr1.
GetSerializedSize
(),12,
"006"
);
106
NS_TEST_ASSERT_MSG_EQ
(hdr1.
GetDst
(),
Ipv4Address
(
"10.1.1.2"
),
"008"
);
107
NS_TEST_ASSERT_MSG_EQ
(hdr1.
GetDstSeqno
(),2,
"009"
);
108
NS_TEST_ASSERT_MSG_EQ
(hdr1.
GetHopCount
(),2,
"010"
);
109
}
110
}
111
118
class
DsdvTableTestCase
:
public
TestCase
119
{
120
public
:
121
DsdvTableTestCase
();
122
~DsdvTableTestCase
();
123
virtual
void
124
DoRun
(
void
);
125
};
126
127
DsdvTableTestCase::DsdvTableTestCase
()
128
:
TestCase
(
"Dsdv Routing Table test case"
)
129
{
130
}
131
DsdvTableTestCase::~DsdvTableTestCase
()
132
{
133
}
134
void
135
DsdvTableTestCase::DoRun
()
136
{
137
dsdv::RoutingTable
rtable;
138
Ptr<NetDevice>
dev;
139
{
140
dsdv::RoutingTableEntry
rEntry1 (
141
/*device=*/
dev,
/*dst=*/
142
Ipv4Address
(
"10.1.1.4"
),
/*seqno=*/
2,
143
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
144
/*hops=*/
2,
/*next hop=*/
145
Ipv4Address
(
"10.1.1.2"
),
146
/*lifetime=*/
Seconds
(10));
147
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rEntry1),
true
,
"add route"
);
148
dsdv::RoutingTableEntry
rEntry2 (
149
/*device=*/
dev,
/*dst=*/
150
Ipv4Address
(
"10.1.1.2"
),
/*seqno=*/
4,
151
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
152
/*hops=*/
1,
/*next hop=*/
153
Ipv4Address
(
"10.1.1.2"
),
154
/*lifetime=*/
Seconds
(10));
155
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rEntry2),
true
,
"add route"
);
156
dsdv::RoutingTableEntry
rEntry3 (
157
/*device=*/
dev,
/*dst=*/
158
Ipv4Address
(
"10.1.1.3"
),
/*seqno=*/
4,
159
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
160
/*hops=*/
1,
/*next hop=*/
161
Ipv4Address
(
"10.1.1.3"
),
162
/*lifetime=*/
Seconds
(10));
163
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rEntry3),
true
,
"add route"
);
164
dsdv::RoutingTableEntry
rEntry4 (
165
/*device=*/
dev,
/*dst=*/
166
Ipv4Address
(
"10.1.1.255"
),
/*seqno=*/
0,
167
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
168
/*hops=*/
0,
/*next hop=*/
169
Ipv4Address
(
"10.1.1.255"
),
170
/*lifetime=*/
Seconds
(10));
171
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rEntry4),
true
,
"add route"
);
172
}
173
{
174
dsdv::RoutingTableEntry
rEntry;
175
if
(rtable.
LookupRoute
(
Ipv4Address
(
"10.1.1.4"
), rEntry))
176
{
177
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetDestination
(),
Ipv4Address
(
"10.1.1.4"
),
"100"
);
178
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetSeqNo
(),2,
"101"
);
179
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetHop
(),2,
"102"
);
180
}
181
if
(rtable.
LookupRoute
(
Ipv4Address
(
"10.1.1.2"
), rEntry))
182
{
183
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetDestination
(),
Ipv4Address
(
"10.1.1.2"
),
"103"
);
184
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetSeqNo
(),4,
"104"
);
185
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetHop
(),1,
"105"
);
186
}
187
if
(rtable.
LookupRoute
(
Ipv4Address
(
"10.1.1.3"
), rEntry))
188
{
189
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetDestination
(),
Ipv4Address
(
"10.1.1.3"
),
"106"
);
190
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetSeqNo
(),4,
"107"
);
191
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetHop
(),1,
"108"
);
192
}
193
if
(rtable.
LookupRoute
(
Ipv4Address
(
"10.1.1.255"
), rEntry))
194
{
195
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetDestination
(),
Ipv4Address
(
"10.1.1.255"
),
"109"
);
196
}
197
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetInterface
().
GetLocal
(),
Ipv4Address
(
"10.1.1.1"
),
"110"
);
198
NS_TEST_ASSERT_MSG_EQ
(rEntry.
GetInterface
().
GetBroadcast
(),
Ipv4Address
(
"10.1.1.255"
),
"111"
);
199
NS_TEST_ASSERT_MSG_EQ
(rtable.
RoutingTableSize
(),4,
"Rtable size incorrect"
);
200
}
201
Simulator::Destroy ();
202
}
203
210
class
DsdvTestSuite
:
public
TestSuite
211
{
212
public
:
213
DsdvTestSuite
() :
TestSuite
(
"routing-dsdv"
,
UNIT
)
214
{
215
AddTestCase
(
new
DsdvHeaderTestCase
(), TestCase::QUICK);
216
AddTestCase
(
new
DsdvTableTestCase
(), TestCase::QUICK);
217
}
218
}
g_dsdvTestSuite
;
ns3::dsdv::DsdvHeader::SetHopCount
void SetHopCount(uint32_t hopCount)
Set hop count.
Definition:
dsdv-packet.h:104
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::dsdv::DsdvHeader::GetHopCount
uint32_t GetHopCount() const
Get hop count.
Definition:
dsdv-packet.h:113
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition:
packet.h:852
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition:
packet.cc:256
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
g_dsdvTestSuite
DsdvTestSuite g_dsdvTestSuite
the test suite
ns3::dsdv::RoutingTableEntry
Routing table entry.
Definition:
dsdv-rtable.h:57
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:41
ns3::dsdv::DsdvHeader::SetDstSeqno
void SetDstSeqno(uint32_t sequenceNumber)
Set destination sequence number.
Definition:
dsdv-packet.h:122
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::dsdv::DsdvHeader::GetDstSeqno
uint32_t GetDstSeqno() const
Get destination sequence number.
Definition:
dsdv-packet.h:131
ns3::Ptr< Packet >
DsdvTableTestCase::DsdvTableTestCase
DsdvTableTestCase()
Definition:
dsdv-testcase.cc:127
DsdvTestSuite::DsdvTestSuite
DsdvTestSuite()
Definition:
dsdv-testcase.cc:213
ns3::dsdv::RoutingTableEntry::GetInterface
Ipv4InterfaceAddress GetInterface() const
Get interface address.
Definition:
dsdv-rtable.h:145
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition:
ipv4-interface-address.h:44
DsdvTestSuite
DSDV test suite.
Definition:
dsdv-testcase.cc:211
ns3::dsdv::RoutingTable
The Routing table used by DSDV protocol.
Definition:
dsdv-rtable.h:320
ns3::dsdv::RoutingTable::AddRoute
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition:
dsdv-rtable.cc:128
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:280
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition:
test.h:283
ns3::dsdv::DsdvHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Definition:
dsdv-packet.cc:68
DsdvTableTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
dsdv-testcase.cc:135
ns3::dsdv::DsdvHeader::GetDst
Ipv4Address GetDst() const
Get destination address.
Definition:
dsdv-packet.h:95
DsdvTableTestCase::~DsdvTableTestCase
~DsdvTableTestCase()
Definition:
dsdv-testcase.cc:131
ns3::dsdv::RoutingTable::RoutingTableSize
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition:
dsdv-rtable.cc:122
DsdvHeaderTestCase::DsdvHeaderTestCase
DsdvHeaderTestCase()
Definition:
dsdv-testcase.cc:70
ns3::dsdv::RoutingTableEntry::GetDestination
Ipv4Address GetDestination() const
Get destination IP address.
Definition:
dsdv-rtable.h:82
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition:
test.h:166
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1353
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1289
DsdvTableTestCase
DSDV routing table tests (adding and looking up routes)
Definition:
dsdv-testcase.cc:119
ns3::dsdv::RoutingTableEntry::GetSeqNo
uint32_t GetSeqNo() const
Get sequence number.
Definition:
dsdv-rtable.h:172
DsdvHeaderTestCase::~DsdvHeaderTestCase
~DsdvHeaderTestCase()
Definition:
dsdv-testcase.cc:74
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition:
ipv4-address.h:256
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal(void) const
Get the local address.
Definition:
ipv4-interface-address.cc:74
DsdvHeaderTestCase
DSDV test case to verify the DSDV header.
Definition:
dsdv-testcase.cc:63
ns3::dsdv::RoutingTableEntry::GetHop
uint32_t GetHop() const
Get hop.
Definition:
dsdv-rtable.h:190
DsdvHeaderTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
dsdv-testcase.cc:78
ns3::Ipv4InterfaceAddress::GetBroadcast
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
Definition:
ipv4-interface-address.cc:108
ns3::dsdv::DsdvHeader::SetDst
void SetDst(Ipv4Address destination)
Set destination address.
Definition:
dsdv-packet.h:86
ns3::dsdv::RoutingTable::LookupRoute
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition:
dsdv-rtable.cc:72
ns3::dsdv::DsdvHeader
DSDV Update Packet Format.
Definition:
dsdv-packet.h:59
src
dsdv
test
dsdv-testcase.cc
Generated on Fri Oct 1 2021 17:03:02 for ns-3 by
1.8.20