A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
dsdv-testcase.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Hemanth Narra
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Hemanth Narra <hemanth@ittc.ku.com>
7
*
8
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9
* ResiliNets Research Group https://resilinets.org/
10
* Information and Telecommunication Technology Center (ITTC)
11
* and Department of Electrical Engineering and Computer Science
12
* The University of Kansas Lawrence, KS USA.
13
*
14
* Work supported in part by NSF FIND (Future Internet Design) Program
15
* under grant CNS-0626918 (Postmodern Internet Architecture),
16
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17
* US Department of Defense (DoD), and ITTC at The University of Kansas.
18
*/
19
#include "ns3/boolean.h"
20
#include "ns3/double.h"
21
#include "ns3/dsdv-helper.h"
22
#include "ns3/dsdv-packet.h"
23
#include "ns3/dsdv-rtable.h"
24
#include "ns3/internet-stack-helper.h"
25
#include "ns3/ipv4-address-helper.h"
26
#include "ns3/mesh-helper.h"
27
#include "ns3/mobility-helper.h"
28
#include "ns3/pcap-file.h"
29
#include "ns3/simulator.h"
30
#include "ns3/string.h"
31
#include "ns3/test.h"
32
#include "ns3/uinteger.h"
33
34
using namespace
ns3
;
35
36
/**
37
* @ingroup dsdv
38
* @ingroup tests
39
* @defgroup dsdv-test DSDV module tests
40
*/
41
42
/**
43
* @ingroup dsdv-test
44
*
45
* @brief DSDV test case to verify the DSDV header
46
*
47
*/
48
class
DsdvHeaderTestCase
:
public
TestCase
49
{
50
public
:
51
DsdvHeaderTestCase
();
52
~DsdvHeaderTestCase
()
override
;
53
void
DoRun
()
override
;
54
};
55
56
DsdvHeaderTestCase::DsdvHeaderTestCase
()
57
:
TestCase
(
"Verifying the DSDV header"
)
58
{
59
}
60
61
DsdvHeaderTestCase::~DsdvHeaderTestCase
()
62
{
63
}
64
65
void
66
DsdvHeaderTestCase::DoRun
()
67
{
68
Ptr<Packet>
packet =
Create<Packet>
();
69
70
{
71
dsdv::DsdvHeader
hdr1
;
72
hdr1
.
SetDst
(
Ipv4Address
(
"10.1.1.2"
));
73
hdr1
.SetDstSeqno(2);
74
hdr1
.SetHopCount(2);
75
packet->AddHeader(
hdr1
);
76
dsdv::DsdvHeader
hdr2
;
77
hdr2
.
SetDst
(
Ipv4Address
(
"10.1.1.3"
));
78
hdr2
.SetDstSeqno(4);
79
hdr2
.SetHopCount(1);
80
packet->AddHeader(
hdr2
);
81
NS_TEST_ASSERT_MSG_EQ
(packet->GetSize(), 24,
"001"
);
82
}
83
84
{
85
dsdv::DsdvHeader
hdr2
;
86
packet->RemoveHeader(
hdr2
);
87
NS_TEST_ASSERT_MSG_EQ
(
hdr2
.GetSerializedSize(), 12,
"002"
);
88
NS_TEST_ASSERT_MSG_EQ
(
hdr2
.GetDst(),
Ipv4Address
(
"10.1.1.3"
),
"003"
);
89
NS_TEST_ASSERT_MSG_EQ
(
hdr2
.GetDstSeqno(), 4,
"004"
);
90
NS_TEST_ASSERT_MSG_EQ
(
hdr2
.GetHopCount(), 1,
"005"
);
91
dsdv::DsdvHeader
hdr1
;
92
packet->RemoveHeader(
hdr1
);
93
NS_TEST_ASSERT_MSG_EQ
(
hdr1
.GetSerializedSize(), 12,
"006"
);
94
NS_TEST_ASSERT_MSG_EQ
(
hdr1
.GetDst(),
Ipv4Address
(
"10.1.1.2"
),
"008"
);
95
NS_TEST_ASSERT_MSG_EQ
(
hdr1
.GetDstSeqno(), 2,
"009"
);
96
NS_TEST_ASSERT_MSG_EQ
(
hdr1
.GetHopCount(), 2,
"010"
);
97
}
98
}
99
100
/**
101
* @ingroup dsdv-test
102
*
103
* @brief DSDV routing table tests (adding and looking up routes)
104
*/
105
class
DsdvTableTestCase
:
public
TestCase
106
{
107
public
:
108
DsdvTableTestCase
();
109
~DsdvTableTestCase
()
override
;
110
void
DoRun
()
override
;
111
};
112
113
DsdvTableTestCase::DsdvTableTestCase
()
114
:
TestCase
(
"Dsdv Routing Table test case"
)
115
{
116
}
117
118
DsdvTableTestCase::~DsdvTableTestCase
()
119
{
120
}
121
122
void
123
DsdvTableTestCase::DoRun
()
124
{
125
dsdv::RoutingTable
rtable
;
126
Ptr<NetDevice>
dev;
127
{
128
dsdv::RoutingTableEntry
rEntry1
(
129
/*dev=*/
dev,
130
/*dst=*/
Ipv4Address
(
"10.1.1.4"
),
131
/*seqNo=*/
2,
132
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
133
/*hops=*/
2,
134
/*nextHop=*/
Ipv4Address
(
"10.1.1.2"
),
135
/*lifetime=*/
Seconds
(10));
136
NS_TEST_EXPECT_MSG_EQ
(
rtable
.AddRoute(
rEntry1
),
true
,
"add route"
);
137
138
dsdv::RoutingTableEntry
rEntry2
(
139
/*dev=*/
dev,
140
/*dst=*/
Ipv4Address
(
"10.1.1.2"
),
141
/*seqNo=*/
4,
142
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
143
/*hops=*/
1,
144
/*nextHop=*/
Ipv4Address
(
"10.1.1.2"
),
145
/*lifetime=*/
Seconds
(10));
146
NS_TEST_EXPECT_MSG_EQ
(
rtable
.AddRoute(
rEntry2
),
true
,
"add route"
);
147
148
dsdv::RoutingTableEntry
rEntry3
(
149
/*dev=*/
dev,
150
/*dst=*/
Ipv4Address
(
"10.1.1.3"
),
151
/*seqNo=*/
4,
152
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
153
/*hops=*/
1,
154
/*nextHop=*/
Ipv4Address
(
"10.1.1.3"
),
155
/*lifetime=*/
Seconds
(10));
156
NS_TEST_EXPECT_MSG_EQ
(
rtable
.AddRoute(
rEntry3
),
true
,
"add route"
);
157
158
dsdv::RoutingTableEntry
rEntry4
(
159
/*dev=*/
dev,
160
/*dst=*/
Ipv4Address
(
"10.1.1.255"
),
161
/*seqNo=*/
0,
162
/*iface=*/
Ipv4InterfaceAddress
(
Ipv4Address
(
"10.1.1.1"
),
Ipv4Mask
(
"255.255.255.0"
)),
163
/*hops=*/
0,
164
/*nextHop=*/
Ipv4Address
(
"10.1.1.255"
),
165
/*lifetime=*/
Seconds
(10));
166
NS_TEST_EXPECT_MSG_EQ
(
rtable
.AddRoute(
rEntry4
),
true
,
"add route"
);
167
}
168
{
169
dsdv::RoutingTableEntry
rEntry
;
170
if
(
rtable
.LookupRoute(
Ipv4Address
(
"10.1.1.4"
),
rEntry
))
171
{
172
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetDestination(),
Ipv4Address
(
"10.1.1.4"
),
"100"
);
173
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetSeqNo(), 2,
"101"
);
174
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetHop(), 2,
"102"
);
175
}
176
if
(
rtable
.LookupRoute(
Ipv4Address
(
"10.1.1.2"
),
rEntry
))
177
{
178
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetDestination(),
Ipv4Address
(
"10.1.1.2"
),
"103"
);
179
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetSeqNo(), 4,
"104"
);
180
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetHop(), 1,
"105"
);
181
}
182
if
(
rtable
.LookupRoute(
Ipv4Address
(
"10.1.1.3"
),
rEntry
))
183
{
184
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetDestination(),
Ipv4Address
(
"10.1.1.3"
),
"106"
);
185
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetSeqNo(), 4,
"107"
);
186
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetHop(), 1,
"108"
);
187
}
188
if
(
rtable
.LookupRoute(
Ipv4Address
(
"10.1.1.255"
),
rEntry
))
189
{
190
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetDestination(),
Ipv4Address
(
"10.1.1.255"
),
"109"
);
191
}
192
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetInterface().GetLocal(),
Ipv4Address
(
"10.1.1.1"
),
"110"
);
193
NS_TEST_ASSERT_MSG_EQ
(
rEntry
.GetInterface().GetBroadcast(),
194
Ipv4Address
(
"10.1.1.255"
),
195
"111"
);
196
NS_TEST_ASSERT_MSG_EQ
(
rtable
.RoutingTableSize(), 4,
"Rtable size incorrect"
);
197
}
198
Simulator::Destroy
();
199
}
200
201
/**
202
* @ingroup dsdv-test
203
*
204
* @brief DSDV test suite
205
*/
206
class
DsdvTestSuite
:
public
TestSuite
207
{
208
public
:
209
DsdvTestSuite
()
210
:
TestSuite
(
"routing-dsdv"
,
Type
::
UNIT
)
211
{
212
AddTestCase
(
new
DsdvHeaderTestCase
(), TestCase::Duration::QUICK);
213
AddTestCase
(
new
DsdvTableTestCase
(), TestCase::Duration::QUICK);
214
}
215
}
g_dsdvTestSuite
;
///< the test suite
DsdvHeaderTestCase
DSDV test case to verify the DSDV header.
Definition
dsdv-testcase.cc:49
DsdvHeaderTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
dsdv-testcase.cc:66
DsdvHeaderTestCase::DsdvHeaderTestCase
DsdvHeaderTestCase()
Definition
dsdv-testcase.cc:56
DsdvHeaderTestCase::~DsdvHeaderTestCase
~DsdvHeaderTestCase() override
Definition
dsdv-testcase.cc:61
DsdvTableTestCase
DSDV routing table tests (adding and looking up routes)
Definition
dsdv-testcase.cc:106
DsdvTableTestCase::DsdvTableTestCase
DsdvTableTestCase()
Definition
dsdv-testcase.cc:113
DsdvTableTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
dsdv-testcase.cc:123
DsdvTableTestCase::~DsdvTableTestCase
~DsdvTableTestCase() override
Definition
dsdv-testcase.cc:118
DsdvTestSuite
DSDV test suite.
Definition
dsdv-testcase.cc:207
DsdvTestSuite::DsdvTestSuite
DsdvTestSuite()
Definition
dsdv-testcase.cc:209
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition
ipv4-interface-address.h:34
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:246
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::dsdv::DsdvHeader
DSDV Update Packet Format.
Definition
dsdv-packet.h:50
ns3::dsdv::DsdvHeader::SetDst
void SetDst(Ipv4Address destination)
Set destination address.
Definition
dsdv-packet.h:76
ns3::dsdv::RoutingTableEntry
Routing table entry.
Definition
dsdv-rtable.h:48
ns3::dsdv::RoutingTable
The Routing table used by DSDV protocol.
Definition
dsdv-rtable.h:317
g_dsdvTestSuite
DsdvTestSuite g_dsdvTestSuite
the test suite
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
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:134
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:241
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
dsdv
test
dsdv-testcase.cc
Generated on Mon Dec 15 2025 15:21:51 for ns-3 by
1.9.8