A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aodv-test-suite.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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  * Authors: Pavel Boyko <boyko@iitp.ru>
19  */
20 #include "ns3/test.h"
21 #include "ns3/aodv-neighbor.h"
22 #include "ns3/aodv-packet.h"
23 #include "ns3/aodv-rqueue.h"
24 #include "ns3/aodv-rtable.h"
25 #include "ns3/ipv4-route.h"
26 
27 namespace ns3
28 {
29 namespace aodv
30 {
31 
33 struct NeighborTest : public TestCase
34 {
35  NeighborTest () : TestCase ("Neighbor"), neighbor (0) { }
36  virtual void DoRun ();
37  void Handler (Ipv4Address addr);
38  void CheckTimeout1 ();
39  void CheckTimeout2 ();
40  void CheckTimeout3 ();
41  Neighbors * neighbor;
42 };
43 
44 void
45 NeighborTest::Handler (Ipv4Address addr)
46 {
47 }
48 
49 void
50 NeighborTest::CheckTimeout1 ()
51 {
52  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
53  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), true, "Neighbor exists");
54  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), true, "Neighbor exists");
55  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true, "Neighbor exists");
56 }
57 void
58 NeighborTest::CheckTimeout2 ()
59 {
60  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false, "Neighbor doesn't exist");
61  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false, "Neighbor doesn't exist");
62  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false, "Neighbor doesn't exist");
63  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true, "Neighbor exists");
64 }
65 void
66 NeighborTest::CheckTimeout3 ()
67 {
68  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false, "Neighbor doesn't exist");
69  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false, "Neighbor doesn't exist");
70  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false, "Neighbor doesn't exist");
71  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), false, "Neighbor doesn't exist");
72 }
73 
74 void
76 {
77  Neighbors nb (Seconds (1));
78  neighbor = &nb;
79  neighbor->SetCallback (MakeCallback (&NeighborTest::Handler, this));
80  neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (1));
81  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
82  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("4.3.2.1")), false, "Neighbor doesn't exist");
83  neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (10));
84  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
85  NS_TEST_EXPECT_MSG_EQ (neighbor->GetExpireTime (Ipv4Address ("1.2.3.4")), Seconds (10), "Known expire time");
86  NS_TEST_EXPECT_MSG_EQ (neighbor->GetExpireTime (Ipv4Address ("4.3.2.1")), Seconds (0), "Known expire time");
87  neighbor->Update (Ipv4Address ("1.1.1.1"), Seconds (5));
88  neighbor->Update (Ipv4Address ("2.2.2.2"), Seconds (10));
89  neighbor->Update (Ipv4Address ("3.3.3.3"), Seconds (20));
90 
91  Simulator::Schedule (Seconds (2), &NeighborTest::CheckTimeout1, this);
92  Simulator::Schedule (Seconds (15), &NeighborTest::CheckTimeout2, this);
93  Simulator::Schedule (Seconds (30), &NeighborTest::CheckTimeout3, this);
94  Simulator::Run ();
96 }
97 //-----------------------------------------------------------------------------
98 struct TypeHeaderTest : public TestCase
99 {
100  TypeHeaderTest () : TestCase ("AODV TypeHeader")
101  {
102  }
103  virtual void DoRun ()
104  {
105  TypeHeader h (AODVTYPE_RREQ);
106  NS_TEST_EXPECT_MSG_EQ (h.IsValid (), true, "Default header is valid");
107  NS_TEST_EXPECT_MSG_EQ (h.Get (), AODVTYPE_RREQ, "Default header is RREQ");
108 
109  Ptr<Packet> p = Create<Packet> ();
110  p->AddHeader (h);
111  TypeHeader h2 (AODVTYPE_RREP);
112  uint32_t bytes = p->RemoveHeader (h2);
113  NS_TEST_EXPECT_MSG_EQ (bytes, 1, "Type header is 1 byte long");
114  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
115  }
116 };
117 //-----------------------------------------------------------------------------
119 struct RreqHeaderTest : public TestCase
120 {
121  RreqHeaderTest () : TestCase ("AODV RREQ")
122  {
123  }
124  virtual void DoRun ()
125  {
126  RreqHeader h (/*flags*/ 0, /*reserved*/ 0, /*hopCount*/ 6, /*requestID*/ 1, /*dst*/ Ipv4Address ("1.2.3.4"),
127  /*dstSeqNo*/ 40, /*origin*/ Ipv4Address ("4.3.2.1"), /*originSeqNo*/ 10);
128  NS_TEST_EXPECT_MSG_EQ (h.GetGratiousRrep (), false, "trivial");
129  NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (), false, "trivial");
130  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 6, "trivial");
131  NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial");
132  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.2.3.4"), "trivial");
133  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 40, "trivial");
134  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.3.2.1"), "trivial");
135  NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 10, "trivial");
136 
137  h.SetGratiousRrep (true);
138  NS_TEST_EXPECT_MSG_EQ (h.GetGratiousRrep (), true, "trivial");
139  h.SetDestinationOnly (true);
140  NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (), true, "trivial");
141  h.SetUnknownSeqno (true);
142  NS_TEST_EXPECT_MSG_EQ (h.GetUnknownSeqno (), true, "trivial");
143  h.SetDst (Ipv4Address ("1.1.1.1"));
144  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.1.1.1"), "trivial");
145  h.SetDstSeqno (5);
146  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 5, "trivial");
147  h.SetHopCount (7);
148  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 7, "trivial");
149  h.SetId (55);
150  NS_TEST_EXPECT_MSG_EQ (h.GetId (), 55, "trivial");
151  h.SetOrigin (Ipv4Address ("4.4.4.4"));
152  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.4.4.4"), "trivial");
153  h.SetOriginSeqno (23);
154  NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 23, "trivial");
155 
156  Ptr<Packet> p = Create<Packet> ();
157  p->AddHeader (h);
158  RreqHeader h2;
159  uint32_t bytes = p->RemoveHeader (h2);
160  NS_TEST_EXPECT_MSG_EQ (bytes, 23, "RREP is 23 bytes long");
161  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
162 
163  }
164 };
165 //-----------------------------------------------------------------------------
167 struct RrepHeaderTest : public TestCase
168 {
169  RrepHeaderTest () : TestCase ("AODV RREP") {}
170  virtual void DoRun ()
171  {
172  RrepHeader h (/*prefixSize*/ 0, /*hopCount*/ 12, /*dst*/ Ipv4Address ("1.2.3.4"), /*dstSeqNo*/ 2,
173  /*origin*/ Ipv4Address ("4.3.2.1"), /*lifetime*/ Seconds (3));
174  NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 0, "trivial");
175  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 12, "trivial");
176  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.2.3.4"), "trivial");
177  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 2, "trivial");
178  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.3.2.1"), "trivial");
179  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), Seconds (3), "trivial");
180  h.SetDst (Ipv4Address ("1.1.1.1"));
181  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.1.1.1"), "trivial");
182  h.SetDstSeqno (123);
183  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 123, "trivial");
184  h.SetOrigin (Ipv4Address ("4.4.4.4"));
185  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.4.4.4"), "trivial");
186  h.SetLifeTime (MilliSeconds (1200));
187  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), MilliSeconds (1200), "trivial");
188  h.SetAckRequired (true);
189  NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (), true, "trivial");
190  h.SetAckRequired (false);
191  NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (), false, "trivial");
192  h.SetPrefixSize (2);
193  NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 2, "trivial");
194  h.SetHopCount (15);
195  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 15, "trivial");
196 
197  h.SetHello (Ipv4Address ("10.0.0.2"), 9, Seconds (15));
198  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), h.GetOrigin (), "trivial");
199  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 9, "trivial");
200  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), Seconds (15), "trivial");
201 
202  Ptr<Packet> p = Create<Packet> ();
203  p->AddHeader (h);
204  RrepHeader h2;
205  uint32_t bytes = p->RemoveHeader (h2);
206  NS_TEST_EXPECT_MSG_EQ (bytes, 19, "RREP is 19 bytes long");
207  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
208  }
209 };
210 //-----------------------------------------------------------------------------
213 {
214  RrepAckHeaderTest () : TestCase ("AODV RREP-ACK")
215  {
216  }
217  virtual void DoRun ()
218  {
219  RrepAckHeader h;
220  Ptr<Packet> p = Create<Packet> ();
221  p->AddHeader (h);
222  RrepAckHeader h2;
223  uint32_t bytes = p->RemoveHeader (h2);
224  NS_TEST_EXPECT_MSG_EQ (bytes, 1, "ACK is 1 byte long");
225  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
226  }
227 };
228 //-----------------------------------------------------------------------------
230 struct RerrHeaderTest : public TestCase
231 {
232  RerrHeaderTest () : TestCase ("AODV RERR")
233  {
234  }
235  virtual void DoRun ()
236  {
237  RerrHeader h;
238  h.SetNoDelete (true);
239  NS_TEST_EXPECT_MSG_EQ (h.GetNoDelete (), true, "trivial");
240  Ipv4Address dst = Ipv4Address ("1.2.3.4");
241  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst, 12), true, "trivial");
242  NS_TEST_EXPECT_MSG_EQ (h.GetDestCount (), 1, "trivial");
243  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst, 13), true, "trivial");
244  Ipv4Address dst2 = Ipv4Address ("4.3.2.1");
245  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst2, 12), true, "trivial");
246  NS_TEST_EXPECT_MSG_EQ (h.GetDestCount (), 2, "trivial");
247 
248  Ptr<Packet> p = Create<Packet> ();
249  p->AddHeader (h);
250  RerrHeader h2;
251  uint32_t bytes = p->RemoveHeader (h2);
252  NS_TEST_EXPECT_MSG_EQ (bytes, h.GetSerializedSize (), "(De)Serialized size match");
253  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
254  }
255 };
256 //-----------------------------------------------------------------------------
258 struct QueueEntryTest : public TestCase
259 {
260  QueueEntryTest () : TestCase ("QueueEntry") {}
261  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
262  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
263  void Unicast2 (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
264  void Error2 (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
265  virtual void DoRun ()
266  {
267  Ptr<const Packet> packet = Create<Packet> ();
268  Ipv4Header h;
269  h.SetDestination (Ipv4Address ("1.2.3.4"));
270  h.SetSource (Ipv4Address ("4.3.2.1"));
271  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&QueueEntryTest::Unicast, this);
272  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&QueueEntryTest::Error, this);
273  QueueEntry entry (packet, h, ucb, ecb, Seconds (1));
274  NS_TEST_EXPECT_MSG_EQ (h.GetDestination (), entry.GetIpv4Header ().GetDestination (), "trivial");
275  NS_TEST_EXPECT_MSG_EQ (h.GetSource (), entry.GetIpv4Header ().GetSource (), "trivial");
276  NS_TEST_EXPECT_MSG_EQ (ucb.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
277  NS_TEST_EXPECT_MSG_EQ (ecb.IsEqual (entry.GetErrorCallback ()), true, "trivial");
278  NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (1), "trivial");
279  NS_TEST_EXPECT_MSG_EQ (entry.GetPacket (), packet, "trivial");
280  entry.SetExpireTime (Seconds (3));
281  NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (3), "trivial");
282  Ipv4Header h2;
283  h2.SetDestination (Ipv4Address ("1.1.1.1"));
284  entry.SetIpv4Header (h2);
285  NS_TEST_EXPECT_MSG_EQ (entry.GetIpv4Header ().GetDestination (), Ipv4Address ("1.1.1.1"), "trivial");
286  Ipv4RoutingProtocol::UnicastForwardCallback ucb2 = MakeCallback (&QueueEntryTest::Unicast2, this);
287  Ipv4RoutingProtocol::ErrorCallback ecb2 = MakeCallback (&QueueEntryTest::Error2, this);
288  entry.SetErrorCallback (ecb2);
289  NS_TEST_EXPECT_MSG_EQ (ecb2.IsEqual (entry.GetErrorCallback ()), true, "trivial");
290  entry.SetUnicastForwardCallback (ucb2);
291  NS_TEST_EXPECT_MSG_EQ (ucb2.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
292  }
293 };
294 //-----------------------------------------------------------------------------
296 struct AodvRqueueTest : public TestCase
297 {
298  AodvRqueueTest () : TestCase ("Rqueue"), q (64, Seconds (30)) {}
299  virtual void DoRun ();
300  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
301  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
302  void CheckSizeLimit ();
303  void CheckTimeout ();
304 
305  RequestQueue q;
306 };
307 
308 void
310 {
311  NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 64, "trivial");
312  q.SetMaxQueueLen (32);
313  NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32, "trivial");
314  NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (), Seconds (30), "trivial");
315  q.SetQueueTimeout (Seconds (10));
316  NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (), Seconds (10), "trivial");
317 
318  Ptr<const Packet> packet = Create<Packet> ();
319  Ipv4Header h;
320  h.SetDestination (Ipv4Address ("1.2.3.4"));
321  h.SetSource (Ipv4Address ("4.3.2.1"));
322  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
323  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
324  QueueEntry e1 (packet, h, ucb, ecb, Seconds (1));
325  q.Enqueue (e1);
326  q.Enqueue (e1);
327  q.Enqueue (e1);
328  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.2.3.4")), true, "trivial");
329  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.1.1.1")), false, "trivial");
330  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial");
331  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
332  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.2.3.4")), false, "trivial");
333  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial");
334 
335  h.SetDestination (Ipv4Address ("2.2.2.2"));
336  QueueEntry e2 (packet, h, ucb, ecb, Seconds (1));
337  q.Enqueue (e1);
338  q.Enqueue (e2);
339  Ptr<Packet> packet2 = Create<Packet> ();
340  QueueEntry e3 (packet2, h, ucb, ecb, Seconds (1));
341  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("3.3.3.3"), e3), false, "trivial");
342  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("2.2.2.2"), e3), true, "trivial");
343  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("2.2.2.2")), false, "trivial");
344  q.Enqueue (e2);
345  q.Enqueue (e3);
346  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
347  Ptr<Packet> packet4 = Create<Packet> ();
348  h.SetDestination (Ipv4Address ("1.2.3.4"));
349  QueueEntry e4 (packet4, h, ucb, ecb, Seconds (20));
350  q.Enqueue (e4);
351  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
352  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
353  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial");
354 
355  CheckSizeLimit ();
356 
357  Ipv4Header header2;
358  Ipv4Address dst2 ("1.2.3.4");
359  header2.SetDestination (dst2);
360 
361  Simulator::Schedule (q.GetQueueTimeout () + Seconds (1), &AodvRqueueTest::CheckTimeout, this);
362 
363  Simulator::Run ();
365 }
366 
367 void
368 AodvRqueueTest::CheckSizeLimit ()
369 {
370  Ptr<Packet> packet = Create<Packet> ();
371  Ipv4Header header;
372  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
373  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
374  QueueEntry e1 (packet, header, ucb, ecb, Seconds (1));
375 
376  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
377  q.Enqueue (e1);
378  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
379 
380  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
381  q.Enqueue (e1);
382  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
383 }
384 
385 void
386 AodvRqueueTest::CheckTimeout ()
387 {
388  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "Must be empty now");
389 }
390 //-----------------------------------------------------------------------------
393 {
394  AodvRtableEntryTest () : TestCase ("RtableEntry") {}
395  virtual void DoRun ()
396  {
397  Ptr<NetDevice> dev;
398  Ipv4InterfaceAddress iface;
399  RoutingTableEntry rt (/*output device*/ dev, /*dst*/ Ipv4Address ("1.2.3.4"), /*validSeqNo*/ true, /*seqNo*/ 10,
400  /*interface*/ iface, /*hop*/ 5, /*next hop*/ Ipv4Address ("3.3.3.3"), /*lifetime*/ Seconds (10));
401  NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev, "trivial");
402  NS_TEST_EXPECT_MSG_EQ (rt.GetDestination (), Ipv4Address ("1.2.3.4"), "trivial");
403  NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (), true, "trivial");
404  NS_TEST_EXPECT_MSG_EQ (rt.GetSeqNo (), 10, "trivial");
405  NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface, "trivial");
406  NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 5, "trivial");
407  NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (), Ipv4Address ("3.3.3.3"), "trivial");
408  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (10), "trivial");
409  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), VALID, "trivial");
410  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 0, "trivial");
411  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), true, "trivial");
412 
413  Ptr<NetDevice> dev2;
414  Ipv4InterfaceAddress iface2;
415  rt.SetOutputDevice (dev2);
416  NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev2, "trivial");
417  rt.SetInterface (iface2);
418  NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface2, "trivial");
419  rt.SetValidSeqNo (false);
420  NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (), false, "trivial");
421  rt.SetFlag (INVALID);
422  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
423  rt.SetFlag (IN_SEARCH);
424  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), IN_SEARCH, "trivial");
425  rt.SetHop (12);
426  NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 12, "trivial");
427  rt.SetLifeTime (Seconds (1));
428  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (1), "trivial");
429  rt.SetNextHop (Ipv4Address ("1.1.1.1"));
430  NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (), Ipv4Address ("1.1.1.1"), "trivial");
431  rt.SetUnidirectional (true);
432  NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (), true, "trivial");
433  rt.SetBalcklistTimeout (Seconds (7));
434  NS_TEST_EXPECT_MSG_EQ (rt.GetBlacklistTimeout (), Seconds (7), "trivial");
435  rt.SetRreqCnt (2);
436  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 2, "trivial");
437  rt.IncrementRreqCnt ();
438  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 3, "trivial");
439  rt.Invalidate (Seconds (13));
440  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
441  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (13), "trivial");
442  rt.SetLifeTime (MilliSeconds (100));
443  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), MilliSeconds (100), "trivial");
444  Ptr<Ipv4Route> route = rt.GetRoute ();
445  NS_TEST_EXPECT_MSG_EQ (route->GetDestination (), Ipv4Address ("1.2.3.4"), "trivial");
446 
447  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.1")), true, "trivial");
448  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), false, "trivial");
449  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), true, "trivial");
450  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), false, "trivial");
451  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.3")), false, "trivial");
452  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.1")), true, "trivial");
453  NS_TEST_EXPECT_MSG_EQ (rt.DeletePrecursor (Ipv4Address ("10.0.0.2")), true, "trivial");
454  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.2")), false, "trivial");
455  std::vector<Ipv4Address> prec;
456  rt.GetPrecursors (prec);
457  NS_TEST_EXPECT_MSG_EQ (prec.size (), 1, "trivial");
458  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.4")), true, "trivial");
459  NS_TEST_EXPECT_MSG_EQ (rt.DeletePrecursor (Ipv4Address ("10.0.0.5")), false, "trivial");
460  rt.GetPrecursors (prec);
461  NS_TEST_EXPECT_MSG_EQ (prec.size (), 2, "trivial");
462  rt.DeleteAllPrecursors ();
463  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), true, "trivial");
464  rt.GetPrecursors (prec);
465  NS_TEST_EXPECT_MSG_EQ (prec.size (), 2, "trivial");
467  }
468 };
469 //-----------------------------------------------------------------------------
471 struct AodvRtableTest : public TestCase
472 {
473  AodvRtableTest () : TestCase ("Rtable") {}
474  virtual void DoRun ()
475  {
476  RoutingTable rtable (Seconds (2));
477  NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (), Seconds (2), "trivial");
478  rtable.SetBadLinkLifetime (Seconds (1));
479  NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (), Seconds (1), "trivial");
480  Ptr<NetDevice> dev;
481  Ipv4InterfaceAddress iface;
482  RoutingTableEntry rt (/*output device*/ dev, /*dst*/ Ipv4Address ("1.2.3.4"), /*validSeqNo*/ true, /*seqNo*/ 10,
483  /*interface*/ iface, /*hop*/ 5, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (10));
484  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt), true, "trivial");
485  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt), false, "trivial");
486  RoutingTableEntry rt2 (/*output device*/ dev, /*dst*/ Ipv4Address ("4.3.2.1"), /*validSeqNo*/ false, /*seqNo*/ 0,
487  /*interface*/ iface, /*hop*/ 15, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (1));
488  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt2), true, "trivial");
489  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (rt2.GetDestination (), rt), true, "trivial");
490  NS_TEST_EXPECT_MSG_EQ (rt2.GetDestination (), rt.GetDestination (), "trivial");
491  rt.SetHop (20);
492  rt.InsertPrecursor (Ipv4Address ("10.0.0.3"));
493  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt), true, "trivial");
494  RoutingTableEntry rt3;
495  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("10.0.0.1"), rt), false, "trivial");
496  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt3), false, "trivial");
497  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("10.0.0.1"), INVALID), false, "trivial");
498  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("1.2.3.4"), IN_SEARCH), true, "trivial");
499  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("5.5.5.5")), false, "trivial");
500  RoutingTableEntry rt4 (/*output device*/ dev, /*dst*/ Ipv4Address ("5.5.5.5"), /*validSeqNo*/ false, /*seqNo*/ 0,
501  /*interface*/ iface, /*hop*/ 15, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (-10));
502  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt4), true, "trivial");
503  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("5.5.5.5"), INVALID), true, "trivial");
504  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("5.5.5.5"), rt), false, "trivial");
505  NS_TEST_EXPECT_MSG_EQ (rtable.MarkLinkAsUnidirectional (Ipv4Address ("1.2.3.4"), Seconds (2)), true, "trivial");
506  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("1.2.3.4"), rt), true, "trivial");
507  NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (), true, "trivial");
508  rt.SetLifeTime (Seconds (-5));
509  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt), true, "trivial");
510  std::map<Ipv4Address, uint32_t> unreachable;
511  rtable.GetListOfDestinationWithNextHop (Ipv4Address ("1.1.1.1"), unreachable);
512  NS_TEST_EXPECT_MSG_EQ (unreachable.size (), 2, "trivial");
513  unreachable.insert (std::make_pair (Ipv4Address ("4.3.2.1"), 3));
514  rtable.InvalidateRoutesWithDst (unreachable);
515  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("4.3.2.1"), rt), true, "trivial");
516  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
517  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), true, "trivial");
518  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), false, "trivial");
520  }
521 };
522 //-----------------------------------------------------------------------------
523 class AodvTestSuite : public TestSuite
524 {
525 public:
526  AodvTestSuite () : TestSuite ("routing-aodv", UNIT)
527  {
528  AddTestCase (new NeighborTest, TestCase::QUICK);
529  AddTestCase (new TypeHeaderTest, TestCase::QUICK);
530  AddTestCase (new RreqHeaderTest, TestCase::QUICK);
531  AddTestCase (new RrepHeaderTest, TestCase::QUICK);
532  AddTestCase (new RrepAckHeaderTest, TestCase::QUICK);
533  AddTestCase (new RerrHeaderTest, TestCase::QUICK);
534  AddTestCase (new QueueEntryTest, TestCase::QUICK);
535  AddTestCase (new AodvRqueueTest, TestCase::QUICK);
536  AddTestCase (new AodvRtableEntryTest, TestCase::QUICK);
537  AddTestCase (new AodvRtableTest, TestCase::QUICK);
538  }
539 } g_aodvTestSuite;
540 
541 }
542 }
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:285
maintain list of active neighbors
Definition: aodv-neighbor.h:49
Unit test for RREP-ACK.
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Definition: aodv-rtable.cc:316
Unit test for AODV routing table entry.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Definition: aodv-rtable.cc:422
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:297
Callback template class.
Definition: callback.h:369
AODV route request queue.
Definition: aodv-rqueue.h:95
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Definition: aodv-rtable.cc:201
virtual void DoRun()
Implementation to actually run this test case.
Route Error (RERR) Message Format.
Definition: aodv-packet.h:295
A suite of tests to run.
Definition: test.h:962
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:262
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:303
static void Run(void)
Definition: simulator.cc:157
virtual void DoRun()
Implementation to actually run this test case.
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:290
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Definition: aodv-rtable.cc:129
virtual void DoRun()
Implementation to actually run this test case.
encapsulates test code
Definition: test.h:834
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
virtual void DoRun()
Implementation to actually run this test case.
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:102
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
Definition: aodv-rqueue.cc:49
virtual void DoRun()
Implementation to actually run this test case.
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:520
Unit test for RequestQueue.
Unit test for RREP.
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:72
bool InsertPrecursor(Ipv4Address id)
Definition: aodv-rtable.cc:67
Packet header for IPv4.
Definition: ipv4-header.h:31
Unit test for neighbors.
bool IsPrecursorListEmpty() const
Definition: aodv-rtable.cc:123
virtual void DoRun()
Implementation to actually run this test case.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:282
bool LookupPrecursor(Ipv4Address id)
Definition: aodv-rtable.cc:80
uint8_t GetDestCount() const
Return number of unreachable destinations in RERR message.
Definition: aodv-packet.h:329
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Definition: aodv-packet.cc:589
virtual void DoRun()
Implementation to actually run this test case.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:97
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
Unit test for RERR.
TestCase(std::string name)
Definition: test.cc:147
Unit test for RREQ.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition: aodv-rqueue.cc:71
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:116
static void Destroy(void)
Definition: simulator.cc:121
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:183
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
Definition: aodv-rtable.cc:299
AODV Queue Entry.
Definition: aodv-rqueue.h:43
Unit test for AODV routing table.
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:409
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: aodv-rtable.cc:150
uint32_t GetSize()
Number of entries.
Definition: aodv-rqueue.cc:42
void Update(Ipv4Address addr, Time expire)
Update expire time for entry with address addr, if it exists, else add new entry. ...
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:193
virtual void DoRun()
Implementation to actually run this test case.
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:253
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0. ...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual void DoRun()
Implementation to actually run this test case.
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
bool AddRoute(RoutingTableEntry &r)
Definition: aodv-rtable.cc:250
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Definition: nstime.h:601
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:104
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition: aodv-rqueue.cc:88
Unit test for AODV routing table entry.
virtual void DoRun()
Implementation to actually run this test case.
bool DeleteRoute(Ipv4Address dst)
Definition: aodv-rtable.cc:236
MessageType Get() const
Return type.
Definition: aodv-packet.h:70
void AddHeader(const Header &header)
Definition: packet.cc:270