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 * 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
34using 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 */
49{
50 public:
52 ~DsdvHeaderTestCase() override;
53 void DoRun() override;
54};
55
57 : TestCase("Verifying the DSDV header")
58{
59}
60
64
65void
67{
68 Ptr<Packet> packet = Create<Packet>();
69
70 {
72 hdr1.SetDst(Ipv4Address("10.1.1.2"));
73 hdr1.SetDstSeqno(2);
74 hdr1.SetHopCount(2);
75 packet->AddHeader(hdr1);
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 {
86 packet->RemoveHeader(hdr2);
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");
92 packet->RemoveHeader(hdr1);
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 */
106{
107 public:
109 ~DsdvTableTestCase() override;
110 void DoRun() override;
111};
112
114 : TestCase("Dsdv Routing Table test case")
115{
116}
117
121
122void
124{
125 dsdv::RoutingTable rtable;
126 Ptr<NetDevice> dev;
127 {
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
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
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
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 {
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");
194 Ipv4Address("10.1.1.255"),
195 "111");
196 NS_TEST_ASSERT_MSG_EQ(rtable.RoutingTableSize(), 4, "Rtable size incorrect");
197 }
199}
200
201/**
202 * \ingroup dsdv-test
203 *
204 * \brief DSDV test suite
205 */
207{
208 public:
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
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.
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
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
DSDV Update Packet Format.
Definition dsdv-packet.h:50
Ipv4Address GetDst() const
Get destination address.
Definition dsdv-packet.h:85
void SetDstSeqno(uint32_t sequenceNumber)
Set destination sequence number.
uint32_t GetHopCount() const
Get hop count.
uint32_t GetDstSeqno() const
Get destination sequence number.
void SetDst(Ipv4Address destination)
Set destination address.
Definition dsdv-packet.h:76
uint32_t GetSerializedSize() const override
void SetHopCount(uint32_t hopCount)
Set hop count.
Definition dsdv-packet.h:94
Routing table entry.
Definition dsdv-rtable.h:48
Ipv4Address GetDestination() const
Get destination IP address.
Definition dsdv-rtable.h:79
Ipv4InterfaceAddress GetInterface() const
Get interface address.
uint32_t GetSeqNo() const
Get sequence number.
uint32_t GetHop() const
Get hop.
The Routing table used by DSDV protocol.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
DsdvTestSuite g_dsdvTestSuite
the test suite
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.