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#include "ns3/v4ping-helper.h"
45
46using namespace ns3;
47
61{
62 public:
64 ~DsdvHeaderTestCase() override;
65 void DoRun() override;
66};
67
69 : TestCase("Verifying the DSDV header")
70{
71}
72
74{
75}
76
77void
79{
80 Ptr<Packet> packet = Create<Packet>();
81
82 {
84 hdr1.SetDst(Ipv4Address("10.1.1.2"));
85 hdr1.SetDstSeqno(2);
86 hdr1.SetHopCount(2);
87 packet->AddHeader(hdr1);
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 {
98 packet->RemoveHeader(hdr2);
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{
119 public:
121 ~DsdvTableTestCase() override;
122 void DoRun() override;
123};
124
126 : TestCase("Dsdv Routing Table test case")
127{
128}
129
131{
132}
133
134void
136{
137 dsdv::RoutingTable rtable;
138 Ptr<NetDevice> dev;
139 {
141 /*dev=*/dev,
142 /*dst=*/Ipv4Address("10.1.1.4"),
143 /*seqNo=*/2,
144 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
145 /*hops=*/2,
146 /*nextHop=*/Ipv4Address("10.1.1.2"),
147 /*lifetime=*/Seconds(10));
148 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry1), true, "add route");
149
151 /*dev=*/dev,
152 /*dst=*/Ipv4Address("10.1.1.2"),
153 /*seqNo=*/4,
154 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
155 /*hops=*/1,
156 /*nextHop=*/Ipv4Address("10.1.1.2"),
157 /*lifetime=*/Seconds(10));
158 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry2), true, "add route");
159
161 /*dev=*/dev,
162 /*dst=*/Ipv4Address("10.1.1.3"),
163 /*seqNo=*/4,
164 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
165 /*hops=*/1,
166 /*nextHop=*/Ipv4Address("10.1.1.3"),
167 /*lifetime=*/Seconds(10));
168 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry3), true, "add route");
169
171 /*dev=*/dev,
172 /*dst=*/Ipv4Address("10.1.1.255"),
173 /*seqNo=*/0,
174 /*iface=*/Ipv4InterfaceAddress(Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")),
175 /*hops=*/0,
176 /*nextHop=*/Ipv4Address("10.1.1.255"),
177 /*lifetime=*/Seconds(10));
178 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rEntry4), true, "add route");
179 }
180 {
182 if (rtable.LookupRoute(Ipv4Address("10.1.1.4"), rEntry))
183 {
184 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.4"), "100");
185 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 2, "101");
186 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 2, "102");
187 }
188 if (rtable.LookupRoute(Ipv4Address("10.1.1.2"), rEntry))
189 {
190 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.2"), "103");
191 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 4, "104");
192 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 1, "105");
193 }
194 if (rtable.LookupRoute(Ipv4Address("10.1.1.3"), rEntry))
195 {
196 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.3"), "106");
197 NS_TEST_ASSERT_MSG_EQ(rEntry.GetSeqNo(), 4, "107");
198 NS_TEST_ASSERT_MSG_EQ(rEntry.GetHop(), 1, "108");
199 }
200 if (rtable.LookupRoute(Ipv4Address("10.1.1.255"), rEntry))
201 {
202 NS_TEST_ASSERT_MSG_EQ(rEntry.GetDestination(), Ipv4Address("10.1.1.255"), "109");
203 }
204 NS_TEST_ASSERT_MSG_EQ(rEntry.GetInterface().GetLocal(), Ipv4Address("10.1.1.1"), "110");
206 Ipv4Address("10.1.1.255"),
207 "111");
208 NS_TEST_ASSERT_MSG_EQ(rtable.RoutingTableSize(), 4, "Rtable size incorrect");
209 }
211}
212
219{
220 public:
222 : TestSuite("routing-dsdv", UNIT)
223 {
226 }
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:78
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
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:144
#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:251
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.