A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsdv-testcase.cc
Go to the documentation of this file.
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 using namespace ns3;
50 
52 {
53 public:
56  virtual void
57  DoRun (void);
58 };
60  : TestCase ("Verifying the DSDV header")
61 {
62 }
64 {
65 }
66 void
68 {
69  Ptr<Packet> packet = Create<Packet> ();
70 
71  {
72  dsdv::DsdvHeader hdr1;
73  hdr1.SetDst (Ipv4Address ("10.1.1.2"));
74  hdr1.SetDstSeqno (2);
75  hdr1.SetHopCount (2);
76  packet->AddHeader (hdr1);
77  dsdv::DsdvHeader hdr2;
78  hdr2.SetDst (Ipv4Address ("10.1.1.3"));
79  hdr2.SetDstSeqno (4);
80  hdr2.SetHopCount (1);
81  packet->AddHeader (hdr2);
82  NS_TEST_ASSERT_MSG_EQ (packet->GetSize (), 24, "001");
83  }
84 
85  {
86  dsdv::DsdvHeader hdr2;
87  packet->RemoveHeader (hdr2);
88  NS_TEST_ASSERT_MSG_EQ (hdr2.GetSerializedSize (),12,"002");
89  NS_TEST_ASSERT_MSG_EQ (hdr2.GetDst (),Ipv4Address ("10.1.1.3"),"003");
90  NS_TEST_ASSERT_MSG_EQ (hdr2.GetDstSeqno (),4,"004");
91  NS_TEST_ASSERT_MSG_EQ (hdr2.GetHopCount (),1,"005");
92  dsdv::DsdvHeader hdr1;
93  packet->RemoveHeader (hdr1);
94  NS_TEST_ASSERT_MSG_EQ (hdr1.GetSerializedSize (),12,"006");
95  NS_TEST_ASSERT_MSG_EQ (hdr1.GetDst (),Ipv4Address ("10.1.1.2"),"008");
96  NS_TEST_ASSERT_MSG_EQ (hdr1.GetDstSeqno (),2,"009");
97  NS_TEST_ASSERT_MSG_EQ (hdr1.GetHopCount (),2,"010");
98  }
99 }
100 
102 {
103 public:
106  virtual void
107  DoRun (void);
108 };
109 
111  : TestCase ("Dsdv Routing Table test case")
112 {
113 }
115 {
116 }
117 void
119 {
120  dsdv::RoutingTable rtable;
121  Ptr<NetDevice> dev;
122  {
123  dsdv::RoutingTableEntry rEntry1 (
124  /*device=*/ dev, /*dst=*/
125  Ipv4Address ("10.1.1.4"), /*seqno=*/ 2,
126  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
127  /*hops=*/ 2, /*next hop=*/
128  Ipv4Address ("10.1.1.2"),
129  /*lifetime=*/ Seconds (10));
130  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry1),true,"add route");
131  dsdv::RoutingTableEntry rEntry2 (
132  /*device=*/ dev, /*dst=*/
133  Ipv4Address ("10.1.1.2"), /*seqno=*/ 4,
134  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
135  /*hops=*/ 1, /*next hop=*/
136  Ipv4Address ("10.1.1.2"),
137  /*lifetime=*/ Seconds (10));
138  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry2),true,"add route");
139  dsdv::RoutingTableEntry rEntry3 (
140  /*device=*/ dev, /*dst=*/
141  Ipv4Address ("10.1.1.3"), /*seqno=*/ 4,
142  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
143  /*hops=*/ 1, /*next hop=*/
144  Ipv4Address ("10.1.1.3"),
145  /*lifetime=*/ Seconds (10));
146  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry3),true,"add route");
147  dsdv::RoutingTableEntry rEntry4 (
148  /*device=*/ dev, /*dst=*/
149  Ipv4Address ("10.1.1.255"), /*seqno=*/ 0,
150  /*iface=*/ Ipv4InterfaceAddress (Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")),
151  /*hops=*/ 0, /*next hop=*/
152  Ipv4Address ("10.1.1.255"),
153  /*lifetime=*/ Seconds (10));
154  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rEntry4),true,"add route");
155  }
156  {
158  if (rtable.LookupRoute (Ipv4Address ("10.1.1.4"), rEntry))
159  {
160  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.4"),"100");
161  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),2,"101");
162  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),2,"102");
163  }
164  if (rtable.LookupRoute (Ipv4Address ("10.1.1.2"), rEntry))
165  {
166  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.2"),"103");
167  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),4,"104");
168  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),1,"105");
169  }
170  if (rtable.LookupRoute (Ipv4Address ("10.1.1.3"), rEntry))
171  {
172  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.3"),"106");
173  NS_TEST_ASSERT_MSG_EQ (rEntry.GetSeqNo (),4,"107");
174  NS_TEST_ASSERT_MSG_EQ (rEntry.GetHop (),1,"108");
175  }
176  if (rtable.LookupRoute (Ipv4Address ("10.1.1.255"), rEntry))
177  {
178  NS_TEST_ASSERT_MSG_EQ (rEntry.GetDestination (),Ipv4Address ("10.1.1.255"),"109");
179  }
180  NS_TEST_ASSERT_MSG_EQ (rEntry.GetInterface ().GetLocal (),Ipv4Address ("10.1.1.1"),"110");
181  NS_TEST_ASSERT_MSG_EQ (rEntry.GetInterface ().GetBroadcast (),Ipv4Address ("10.1.1.255"),"111");
182  NS_TEST_ASSERT_MSG_EQ (rtable.RoutingTableSize (),4,"Rtable size incorrect");
183  }
184  Simulator::Destroy ();
185 }
186 
187 class DsdvTestSuite : public TestSuite
188 {
189 public:
190  DsdvTestSuite () : TestSuite ("routing-dsdv", UNIT)
191  {
192  AddTestCase (new DsdvHeaderTestCase (), TestCase::QUICK);
193  AddTestCase (new DsdvTableTestCase (), TestCase::QUICK);
194  }
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Routing table entry.
Definition: dsdv-rtable.h:56
void SetDst(Ipv4Address destination)
Definition: dsdv-packet.h:71
Ipv4Address GetLocal(void) const
Get the local address.
virtual uint32_t GetSerializedSize() const
Definition: dsdv-packet.cc:67
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
uint32_t GetHopCount() const
Definition: dsdv-packet.h:86
A suite of tests to run.
Definition: test.h:1105
void SetDstSeqno(uint32_t sequenceNumber)
Definition: dsdv-packet.h:91
uint32_t GetSeqNo() const
Definition: dsdv-rtable.h:116
#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:265
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
encapsulates test code
Definition: test.h:929
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetDstSeqno() const
Definition: dsdv-packet.h:96
Ipv4Address GetDst() const
Definition: dsdv-packet.h:76
The Routing table used by DSDV protocol.
Definition: dsdv-rtable.h:219
#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:148
DsdvTestSuite g_dsdvTestSuite
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
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 child TestCase case to this TestCase.
Definition: test.cc:184
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetHop() const
Definition: dsdv-rtable.h:126
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
a class to store IPv4 address information on an interface
Ipv4InterfaceAddress GetInterface() const
Definition: dsdv-rtable.h:101
void SetHopCount(uint32_t hopCount)
Definition: dsdv-packet.h:81
DSDV Update Packet Format.
Definition: dsdv-packet.h:58
Ipv4Address GetDestination() const
Definition: dsdv-rtable.h:66
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: dsdv-rtable.cc:71
This test suite implements a Unit Test.
Definition: test.h:1115
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253