A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsdv-testcase.cc
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/nqos-wifi-mac-helper.h"
36 #include "ns3/dsdv-helper.h"
37 #include "ns3/double.h"
38 #include "ns3/uinteger.h"
39 #include "ns3/v4ping-helper.h"
40 #include "ns3/string.h"
41 #include "ns3/boolean.h"
42 #include "ns3/yans-wifi-helper.h"
43 #include "ns3/pcap-file.h"
44 #include "ns3/internet-stack-helper.h"
45 #include "ns3/ipv4-address-helper.h"
46 #include "ns3/dsdv-packet.h"
47 #include "ns3/dsdv-rtable.h"
48 
49 namespace ns3 {
51 {
52 public:
55  virtual void
56  DoRun (void);
57 };
58 DsdvHeaderTestCase::DsdvHeaderTestCase ()
59  : TestCase ("Verifying the DSDV header")
60 {
61 }
62 DsdvHeaderTestCase::~DsdvHeaderTestCase ()
63 {
64 }
65 void
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, "XXX");
82  }
83 
84  {
85  dsdv::DsdvHeader hdr2;
86  packet->RemoveHeader (hdr2);
87  NS_TEST_ASSERT_MSG_EQ (hdr2.GetSerializedSize (),12,"XXX");
88  NS_TEST_ASSERT_MSG_EQ (hdr2.GetDst (),Ipv4Address ("10.1.1.3"),"XXX");
89  NS_TEST_ASSERT_MSG_EQ (hdr2.GetDstSeqno (),4,"XXX");
90  NS_TEST_ASSERT_MSG_EQ (hdr2.GetHopCount (),1,"XXX");
91  dsdv::DsdvHeader hdr1;
92  packet->RemoveHeader (hdr1);
93  NS_TEST_ASSERT_MSG_EQ (hdr1.GetSerializedSize (),12,"XXX");
94  NS_TEST_ASSERT_MSG_EQ (hdr1.GetDst (),Ipv4Address ("10.1.1.2"),"XXX");
95  NS_TEST_ASSERT_MSG_EQ (hdr1.GetDstSeqno (),2,"XXX");
96  NS_TEST_ASSERT_MSG_EQ (hdr1.GetHopCount (),2,"XXX");
97  }
98 }
99 
101 {
102 public:
104  ~DsdvTableTestCase ();
105  virtual void
106  DoRun (void);
107 };
108 
109 DsdvTableTestCase::DsdvTableTestCase ()
110  : TestCase ("Dsdv Routing Table test case")
111 {
112 }
113 DsdvTableTestCase::~DsdvTableTestCase ()
114 {
115 }
116 void
118 {
119  dsdv::RoutingTable rtable;
120  Ptr<NetDevice> dev;
121  {
122  dsdv::RoutingTableEntry rEntry1 (
123  /*device=*/ dev, /*dst=*/
124  Ipv4Address ("10.1.1.4"), /*seqno=*/ 2,
125  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
126  /*hops=*/ 2, /*next hop=*/
127  Ipv4Address ("10.1.1.2"),
128  /*lifetime=*/ Seconds (10));
129  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry1),true,"add route");
130  dsdv::RoutingTableEntry rEntry2 (
131  /*device=*/ dev, /*dst=*/
132  Ipv4Address ("10.1.1.2"), /*seqno=*/ 4,
133  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
134  /*hops=*/ 1, /*next hop=*/
135  Ipv4Address ("10.1.1.2"),
136  /*lifetime=*/ Seconds (10));
137  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry2),true,"add route");
138  dsdv::RoutingTableEntry rEntry3 (
139  /*device=*/ dev, /*dst=*/
140  Ipv4Address ("10.1.1.3"), /*seqno=*/ 4,
141  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
142  /*hops=*/ 1, /*next hop=*/
143  Ipv4Address ("10.1.1.3"),
144  /*lifetime=*/ Seconds (10));
145  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry3),true,"add route");
146  dsdv::RoutingTableEntry rEntry4 (
147  /*device=*/ dev, /*dst=*/
148  Ipv4Address ("10.1.1.255"), /*seqno=*/ 0,
149  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
150  /*hops=*/ 0, /*next hop=*/
151  Ipv4Address ("10.1.1.255"),
152  /*lifetime=*/ Seconds (10));
153  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry4),true,"add route");
154  }
155  {
157  if (rtable.LookupRoute (Ipv4Address ("10.1.1.4"), rEntry))
158  {
159  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.4"),"XXX");
160  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),2,"XXX");
161  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),2,"XXX");
162  }
163  if (rtable.LookupRoute (Ipv4Address ("10.1.1.2"), rEntry))
164  {
165  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.2"),"XXX");
166  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),4,"XXX");
167  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),1,"XXX");
168  }
169  if (rtable.LookupRoute (Ipv4Address ("10.1.1.3"), rEntry))
170  {
171  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.3"),"XXX");
172  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),4,"XXX");
173  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),1,"XXX");
174  }
175  if (rtable.LookupRoute (Ipv4Address ("10.1.1.255"), rEntry))
176  {
177  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.255"),"XXX");
178  }
179  NS_TEST_ASSERT_MSG_EQ (rEntry.GetInterface ().GetLocal (),Ipv4Address ("10.1.1.1"),"XXX");
180  NS_TEST_ASSERT_MSG_EQ (rEntry.GetInterface ().GetBroadcast (),Ipv4Address ("10.1.1.255"),"XXX");
181  NS_TEST_ASSERT_MSG_EQ (rtable.RoutingTableSize (),4,"Rtable size incorrect");
182  }
184 }
185 
186 class DsdvTestSuite : public TestSuite
187 {
188 public:
189  DsdvTestSuite () : TestSuite ("routing-dsdv", UNIT)
190  {
191  AddTestCase (new DsdvHeaderTestCase (), TestCase::QUICK);
192  AddTestCase (new DsdvTableTestCase (), TestCase::QUICK);
193  }
194 } g_dsdvTestSuite;
195 }
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:285
Routing table entry.
Definition: dsdv-rtable.h:56
virtual uint32_t GetSerializedSize() const
Definition: dsdv-packet.cc:65
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
A suite of tests to run.
Definition: test.h:962
uint32_t GetSize(void) const
Definition: packet.h:620
encapsulates test code
Definition: test.h:834
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:219
virtual void DoRun(void)
Implementation to actually run this test case.
static void Destroy(void)
Definition: simulator.cc:121
bool AddRoute(RoutingTableEntry &r)
Definition: dsdv-rtable.cc:127
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
Definition: dsdv-rtable.cc:121
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
a class to store IPv4 address information on an interface
DSDV Update Packet Format.
Definition: dsdv-packet.h:58
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Definition: dsdv-rtable.cc:71
void AddHeader(const Header &header)
Definition: packet.cc:270
virtual void DoRun(void)
Implementation to actually run this test case.