A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsdv-testcase.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Hemanth Narra
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Hemanth Narra <hemanth@ittc.ku.com>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30#include "ns3/boolean.h"
31#include "ns3/double.h"
32#include "ns3/dsdv-helper.h"
33#include "ns3/dsdv-packet.h"
34#include "ns3/dsdv-rtable.h"
35#include "ns3/internet-stack-helper.h"
36#include "ns3/ipv4-address-helper.h"
37#include "ns3/mesh-helper.h"
38#include "ns3/mobility-helper.h"
39#include "ns3/pcap-file.h"
40#include "ns3/simulator.h"
41#include "ns3/string.h"
42#include "ns3/test.h"
43#include "ns3/uinteger.h"
44
45using namespace ns3;
46
47/**
48 * \ingroup dsdv
49 * \ingroup tests
50 * \defgroup dsdv-test DSDV module tests
51 */
52
53/**
54 * \ingroup dsdv-test
55 *
56 * \brief DSDV test case to verify the DSDV header
57 *
58 */
60{
61 public:
63 ~DsdvHeaderTestCase() override;
64 void DoRun() override;
65};
66
68 : TestCase("Verifying the DSDV header")
69{
70}
71
73{
74}
75
76void
78{
79 Ptr<Packet> packet = Create<Packet>();
80
81 {
83 hdr1.SetDst(Ipv4Address("10.1.1.2"));
84 hdr1.SetDstSeqno(2);
85 hdr1.SetHopCount(2);
86 packet->AddHeader(hdr1);
88 hdr2.SetDst(Ipv4Address("10.1.1.3"));
89 hdr2.SetDstSeqno(4);
90 hdr2.SetHopCount(1);
91 packet->AddHeader(hdr2);
92 NS_TEST_ASSERT_MSG_EQ(packet->GetSize(), 24, "001");
93 }
94
95 {
97 packet->RemoveHeader(hdr2);
99 NS_TEST_ASSERT_MSG_EQ(hdr2.GetDst(), Ipv4Address("10.1.1.3"), "003");
100 NS_TEST_ASSERT_MSG_EQ(hdr2.GetDstSeqno(), 4, "004");
101 NS_TEST_ASSERT_MSG_EQ(hdr2.GetHopCount(), 1, "005");
102 dsdv::DsdvHeader hdr1;
103 packet->RemoveHeader(hdr1);
104 NS_TEST_ASSERT_MSG_EQ(hdr1.GetSerializedSize(), 12, "006");
105 NS_TEST_ASSERT_MSG_EQ(hdr1.GetDst(), Ipv4Address("10.1.1.2"), "008");
106 NS_TEST_ASSERT_MSG_EQ(hdr1.GetDstSeqno(), 2, "009");
107 NS_TEST_ASSERT_MSG_EQ(hdr1.GetHopCount(), 2, "010");
108 }
109}
110
111/**
112 * \ingroup dsdv-test
113 *
114 * \brief DSDV routing table tests (adding and looking up routes)
115 */
117{
118 public:
120 ~DsdvTableTestCase() override;
121 void DoRun() override;
122};
123
125 : TestCase("Dsdv Routing Table test case")
126{
127}
128
130{
131}
132
133void
135{
136 dsdv::RoutingTable rtable;
137 Ptr<NetDevice> dev;
138 {
140 /*dev=*/dev,
141 /*dst=*/Ipv4Address("10.1.1.4"),
142 /*seqNo=*/2,
143 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
144 /*hops=*/2,
145 /*nextHop=*/Ipv4Address("10.1.1.2"),
146 /*lifetime=*/Seconds(10));
147 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry1), true, "add route");
148
150 /*dev=*/dev,
151 /*dst=*/Ipv4Address("10.1.1.2"),
152 /*seqNo=*/4,
153 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
154 /*hops=*/1,
155 /*nextHop=*/Ipv4Address("10.1.1.2"),
156 /*lifetime=*/Seconds(10));
157 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry2), true, "add route");
158
160 /*dev=*/dev,
161 /*dst=*/Ipv4Address("10.1.1.3"),
162 /*seqNo=*/4,
163 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
164 /*hops=*/1,
165 /*nextHop=*/Ipv4Address("10.1.1.3"),
166 /*lifetime=*/Seconds(10));
167 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry3), true, "add route");
168
170 /*dev=*/dev,
171 /*dst=*/Ipv4Address("10.1.1.255"),
172 /*seqNo=*/0,
173 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
174 /*hops=*/0,
175 /*nextHop=*/Ipv4Address("10.1.1.255"),
176 /*lifetime=*/Seconds(10));
177 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry4), true, "add route");
178 }
179 {
181 if (rtable.LookupRoute(Ipv4Address("10.1.1.4"), rEntry))
182 {
183 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.4"), "100");
184 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 2, "101");
185 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 2, "102");
186 }
187 if (rtable.LookupRoute(Ipv4Address("10.1.1.2"), rEntry))
188 {
189 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.2"), "103");
190 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 4, "104");
191 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 1, "105");
192 }
193 if (rtable.LookupRoute(Ipv4Address("10.1.1.3"), rEntry))
194 {
195 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.3"), "106");
196 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 4, "107");
197 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 1, "108");
198 }
199 if (rtable.LookupRoute(Ipv4Address("10.1.1.255"), rEntry))
200 {
201 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.255"), "109");
202 }
203 NS_TEST_ASSERT_MSG_EQ(rEntry.GetInterface().GetLocal(), Ipv4Address("10.1.1.1"), "110");
205 Ipv4Address("10.1.1.255"),
206 "111");
207 NS_TEST_ASSERT_MSG_EQ(rtable.RoutingTableSize(), 4, "Rtable size incorrect");
208 }
210}
211
212/**
213 * \ingroup dsdv-test
214 *
215 * \brief DSDV test suite
216 */
218{
219 public:
221 : TestSuite("routing-dsdv", Type::UNIT)
222 {
223 AddTestCase(new DsdvHeaderTestCase(), TestCase::Duration::QUICK);
224 AddTestCase(new DsdvTableTestCase(), TestCase::Duration::QUICK);
225 }
226} g_dsdvTestSuite; ///< the test suite
DSDV test case to verify the DSDV header.
void DoRun() override
Implementation to actually run this TestCase.
~DsdvHeaderTestCase() override
DSDV routing table tests (adding and looking up routes)
void DoRun() override
Implementation to actually run this TestCase.
~DsdvTableTestCase() override
DSDV test suite.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to store IPv4 address information on an interface
Ipv4Address GetLocal() const
Get the local address.
Ipv4Address GetBroadcast() const
Get the broadcast address.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
DSDV Update Packet Format.
Definition: dsdv-packet.h:61
Ipv4Address GetDst() const
Get destination address.
Definition: dsdv-packet.h:96
void SetDstSeqno(uint32_t sequenceNumber)
Set destination sequence number.
Definition: dsdv-packet.h:123
uint32_t GetHopCount() const
Get hop count.
Definition: dsdv-packet.h:114
uint32_t GetDstSeqno() const
Get destination sequence number.
Definition: dsdv-packet.h:132
void SetDst(Ipv4Address destination)
Set destination address.
Definition: dsdv-packet.h:87
uint32_t GetSerializedSize() const override
Definition: dsdv-packet.cc:70
void SetHopCount(uint32_t hopCount)
Set hop count.
Definition: dsdv-packet.h:105
Routing table entry.
Definition: dsdv-rtable.h:59
Ipv4Address GetDestination() const
Get destination IP address.
Definition: dsdv-rtable.h:90
Ipv4InterfaceAddress GetInterface() const
Get interface address.
Definition: dsdv-rtable.h:153
uint32_t GetSeqNo() const
Get sequence number.
Definition: dsdv-rtable.h:180
uint32_t GetHop() const
Get hop.
Definition: dsdv-rtable.h:198
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:328
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:77
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: dsdv-rtable.cc:125
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition: dsdv-rtable.cc:119
DsdvTestSuite g_dsdvTestSuite
the test suite
#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:145
#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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.