A Discrete-Event Network Simulator
API
aodvq-test-suite.cc
Go to the documentation of this file.
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/aodvq-neighbor.h"
22 #include "ns3/aodvq-packet.h"
23 #include "ns3/aodvq-rqueue.h"
24 #include "ns3/aodvq-rtable.h"
25 #include "ns3/ipv4-route.h"
26 
27 namespace ns3 {
28 namespace aodvq {
29 
36 struct NeighborTest : public TestCase
37 {
38  NeighborTest () : TestCase ("Neighbor"),
39  neighbor (0)
40  {
41  }
42  virtual void DoRun ();
47  void Handler (Ipv4Address addr);
49  void CheckTimeout1 ();
51  void CheckTimeout2 ();
53  void CheckTimeout3 ();
56 };
57 
58 void
60 {
61 }
62 
63 void
65 {
66  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
67  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), true, "Neighbor exists");
68  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), true, "Neighbor exists");
69  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true, "Neighbor exists");
70 }
71 void
73 {
74  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false, "Neighbor doesn't exist");
75  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false, "Neighbor doesn't exist");
76  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false, "Neighbor doesn't exist");
77  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true, "Neighbor exists");
78 }
79 void
81 {
82  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false, "Neighbor doesn't exist");
83  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false, "Neighbor doesn't exist");
84  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false, "Neighbor doesn't exist");
85  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), false, "Neighbor doesn't exist");
86 }
87 
88 void
90 {
91  Neighbors nb (Seconds (1));
92  neighbor = &nb;
94  neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (1));
95  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
96  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("4.3.2.1")), false, "Neighbor doesn't exist");
97  neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (10));
98  NS_TEST_EXPECT_MSG_EQ (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true, "Neighbor exists");
99  NS_TEST_EXPECT_MSG_EQ (neighbor->GetExpireTime (Ipv4Address ("1.2.3.4")), Seconds (10), "Known expire time");
100  NS_TEST_EXPECT_MSG_EQ (neighbor->GetExpireTime (Ipv4Address ("4.3.2.1")), Seconds (0), "Known expire time");
101  neighbor->Update (Ipv4Address ("1.1.1.1"), Seconds (5));
102  neighbor->Update (Ipv4Address ("2.2.2.2"), Seconds (10));
103  neighbor->Update (Ipv4Address ("3.3.3.3"), Seconds (20));
104 
108  Simulator::Run ();
110 }
111 
118 struct TypeHeaderTest : public TestCase
119 {
120  TypeHeaderTest () : TestCase ("AODVQ TypeHeader")
121  {
122  }
123  virtual void DoRun ()
124  {
126  NS_TEST_EXPECT_MSG_EQ (h.IsValid (), true, "Default header is valid");
127  NS_TEST_EXPECT_MSG_EQ (h.Get (), AODVQTYPE_RREQ, "Default header is RREQ");
128 
129  Ptr<Packet> p = Create<Packet> ();
130  p->AddHeader (h);
132  uint32_t bytes = p->RemoveHeader (h2);
133  NS_TEST_EXPECT_MSG_EQ (bytes, 1, "Type header is 1 byte long");
134  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
135  }
136 };
137 
144 struct RreqHeaderTest : public TestCase
145 {
146  RreqHeaderTest () : TestCase ("AODVQ RREQ")
147  {
148  }
149  virtual void DoRun ()
150  {
151  RreqHeader h (/*flags*/ 0, /*reserved*/ 0, /*hopCount*/ 6, /*requestID*/ 1, /*dst*/ Ipv4Address ("1.2.3.4"),
152  /*dstSeqNo*/ 40, /*origin*/ Ipv4Address ("4.3.2.1"), /*originSeqNo*/ 10);
153  NS_TEST_EXPECT_MSG_EQ (h.GetGratuitousRrep (), false, "trivial");
154  NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (), false, "trivial");
155  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 6, "trivial");
156  NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial");
157  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.2.3.4"), "trivial");
158  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 40, "trivial");
159  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.3.2.1"), "trivial");
160  NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 10, "trivial");
161 
162  h.SetGratuitousRrep (true);
163  NS_TEST_EXPECT_MSG_EQ (h.GetGratuitousRrep (), true, "trivial");
164  h.SetDestinationOnly (true);
165  NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (), true, "trivial");
166  h.SetUnknownSeqno (true);
167  NS_TEST_EXPECT_MSG_EQ (h.GetUnknownSeqno (), true, "trivial");
168  h.SetDst (Ipv4Address ("1.1.1.1"));
169  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.1.1.1"), "trivial");
170  h.SetDstSeqno (5);
171  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 5, "trivial");
172  h.SetHopCount (7);
173  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 7, "trivial");
174  h.SetId (55);
175  NS_TEST_EXPECT_MSG_EQ (h.GetId (), 55, "trivial");
176  h.SetOrigin (Ipv4Address ("4.4.4.4"));
177  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.4.4.4"), "trivial");
178  h.SetOriginSeqno (23);
179  NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 23, "trivial");
180 
181  Ptr<Packet> p = Create<Packet> ();
182  p->AddHeader (h);
183  RreqHeader h2;
184  uint32_t bytes = p->RemoveHeader (h2);
185  NS_TEST_EXPECT_MSG_EQ (bytes, 23, "RREP is 23 bytes long");
186  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
187 
188  }
189 };
190 
197 struct RrepHeaderTest : public TestCase
198 {
199  RrepHeaderTest () : TestCase ("AODVQ RREP")
200  {
201  }
202  virtual void DoRun ()
203  {
204  RrepHeader h (/*prefixSize*/ 0, /*hopCount*/ 12, /*dst*/ Ipv4Address ("1.2.3.4"), /*dstSeqNo*/ 2,
205  /*origin*/ Ipv4Address ("4.3.2.1"), /*lifetime*/ Seconds (3));
206  NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 0, "trivial");
207  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 12, "trivial");
208  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.2.3.4"), "trivial");
209  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 2, "trivial");
210  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.3.2.1"), "trivial");
211  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), Seconds (3), "trivial");
212  h.SetDst (Ipv4Address ("1.1.1.1"));
213  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), Ipv4Address ("1.1.1.1"), "trivial");
214  h.SetDstSeqno (123);
215  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 123, "trivial");
216  h.SetOrigin (Ipv4Address ("4.4.4.4"));
217  NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (), Ipv4Address ("4.4.4.4"), "trivial");
218  h.SetLifeTime (MilliSeconds (1200));
219  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), MilliSeconds (1200), "trivial");
220  h.SetAckRequired (true);
221  NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (), true, "trivial");
222  h.SetAckRequired (false);
223  NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (), false, "trivial");
224  h.SetPrefixSize (2);
225  NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 2, "trivial");
226  h.SetHopCount (15);
227  NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 15, "trivial");
228 
229  h.SetHello (Ipv4Address ("10.0.0.2"), 9, Seconds (15));
230  NS_TEST_EXPECT_MSG_EQ (h.GetDst (), h.GetOrigin (), "trivial");
231  NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 9, "trivial");
232  NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (), Seconds (15), "trivial");
233 
234  Ptr<Packet> p = Create<Packet> ();
235  p->AddHeader (h);
236  RrepHeader h2;
237  uint32_t bytes = p->RemoveHeader (h2);
238  NS_TEST_EXPECT_MSG_EQ (bytes, 19, "RREP is 19 bytes long");
239  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
240  }
241 };
242 
250 {
251  RrepAckHeaderTest () : TestCase ("AODVQ RREP-ACK")
252  {
253  }
254  virtual void DoRun ()
255  {
256  RrepAckHeader h;
257  Ptr<Packet> p = Create<Packet> ();
258  p->AddHeader (h);
259  RrepAckHeader h2;
260  uint32_t bytes = p->RemoveHeader (h2);
261  NS_TEST_EXPECT_MSG_EQ (bytes, 1, "ACK is 1 byte long");
262  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
263  }
264 };
265 
272 struct RerrHeaderTest : public TestCase
273 {
274  RerrHeaderTest () : TestCase ("AODVQ RERR")
275  {
276  }
277  virtual void DoRun ()
278  {
279  RerrHeader h;
280  h.SetNoDelete (true);
281  NS_TEST_EXPECT_MSG_EQ (h.GetNoDelete (), true, "trivial");
282  Ipv4Address dst = Ipv4Address ("1.2.3.4");
283  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst, 12), true, "trivial");
284  NS_TEST_EXPECT_MSG_EQ (h.GetDestCount (), 1, "trivial");
285  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst, 13), true, "trivial");
286  Ipv4Address dst2 = Ipv4Address ("4.3.2.1");
287  NS_TEST_EXPECT_MSG_EQ (h.AddUnDestination (dst2, 12), true, "trivial");
288  NS_TEST_EXPECT_MSG_EQ (h.GetDestCount (), 2, "trivial");
289 
290  Ptr<Packet> p = Create<Packet> ();
291  p->AddHeader (h);
292  RerrHeader h2;
293  uint32_t bytes = p->RemoveHeader (h2);
294  NS_TEST_EXPECT_MSG_EQ (bytes, h.GetSerializedSize (), "(De)Serialized size match");
295  NS_TEST_EXPECT_MSG_EQ (h, h2, "Round trip serialization works");
296  }
297 };
298 
305 struct QueueEntryTest : public TestCase
306 {
307  QueueEntryTest () : TestCase ("QueueEntry")
308  {
309  }
316  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header)
317  {
318  }
326  {
327  }
334  void Unicast2 (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header)
335  {
336  }
344  {
345  }
346  virtual void DoRun ()
347  {
348  Ptr<const Packet> packet = Create<Packet> ();
349  Ipv4Header h;
350  h.SetDestination (Ipv4Address ("1.2.3.4"));
351  h.SetSource (Ipv4Address ("4.3.2.1"));
354  QueueEntry entry (packet, h, ucb, ecb, Seconds (1));
355  NS_TEST_EXPECT_MSG_EQ (h.GetDestination (), entry.GetIpv4Header ().GetDestination (), "trivial");
356  NS_TEST_EXPECT_MSG_EQ (h.GetSource (), entry.GetIpv4Header ().GetSource (), "trivial");
357  NS_TEST_EXPECT_MSG_EQ (ucb.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
358  NS_TEST_EXPECT_MSG_EQ (ecb.IsEqual (entry.GetErrorCallback ()), true, "trivial");
359  NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (1), "trivial");
360  NS_TEST_EXPECT_MSG_EQ (entry.GetPacket (), packet, "trivial");
361  entry.SetExpireTime (Seconds (3));
362  NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (3), "trivial");
363  Ipv4Header h2;
364  h2.SetDestination (Ipv4Address ("1.1.1.1"));
365  entry.SetIpv4Header (h2);
366  NS_TEST_EXPECT_MSG_EQ (entry.GetIpv4Header ().GetDestination (), Ipv4Address ("1.1.1.1"), "trivial");
369  entry.SetErrorCallback (ecb2);
370  NS_TEST_EXPECT_MSG_EQ (ecb2.IsEqual (entry.GetErrorCallback ()), true, "trivial");
371  entry.SetUnicastForwardCallback (ucb2);
372  NS_TEST_EXPECT_MSG_EQ (ucb2.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
373  }
374 };
375 //-----------------------------------------------------------------------------
377 struct AodvqRqueueTest : public TestCase
378 {
379  AodvqRqueueTest () : TestCase ("Rqueue"),
380  q (64, Seconds (30))
381  {
382  }
383  virtual void DoRun ();
390  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header)
391  {
392  }
400  {
401  }
403  void CheckSizeLimit ();
405  void CheckTimeout ();
406 
409 };
410 
411 void
413 {
414  NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 64, "trivial");
415  q.SetMaxQueueLen (32);
416  NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32, "trivial");
417  NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (), Seconds (30), "trivial");
418  q.SetQueueTimeout (Seconds (10));
419  NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (), Seconds (10), "trivial");
420 
421  Ptr<const Packet> packet = Create<Packet> ();
422  Ipv4Header h;
423  h.SetDestination (Ipv4Address ("1.2.3.4"));
424  h.SetSource (Ipv4Address ("4.3.2.1"));
427  QueueEntry e1 (packet, h, ucb, ecb, Seconds (1));
428  q.Enqueue (e1);
429  q.Enqueue (e1);
430  q.Enqueue (e1);
431  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.2.3.4")), true, "trivial");
432  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.1.1.1")), false, "trivial");
433  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial");
434  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
435  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.2.3.4")), false, "trivial");
436  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial");
437 
438  h.SetDestination (Ipv4Address ("2.2.2.2"));
439  QueueEntry e2 (packet, h, ucb, ecb, Seconds (1));
440  q.Enqueue (e1);
441  q.Enqueue (e2);
442  Ptr<Packet> packet2 = Create<Packet> ();
443  QueueEntry e3 (packet2, h, ucb, ecb, Seconds (1));
444  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("3.3.3.3"), e3), false, "trivial");
445  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("2.2.2.2"), e3), true, "trivial");
446  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("2.2.2.2")), false, "trivial");
447  q.Enqueue (e2);
448  q.Enqueue (e3);
449  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
450  Ptr<Packet> packet4 = Create<Packet> ();
451  h.SetDestination (Ipv4Address ("1.2.3.4"));
452  QueueEntry e4 (packet4, h, ucb, ecb, Seconds (20));
453  q.Enqueue (e4);
454  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
455  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
456  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial");
457 
458  CheckSizeLimit ();
459 
460  Ipv4Header header2;
461  Ipv4Address dst2 ("1.2.3.4");
462  header2.SetDestination (dst2);
463 
464  Simulator::Schedule (q.GetQueueTimeout () + Seconds (1), &AodvqRqueueTest::CheckTimeout, this);
465 
466  Simulator::Run ();
468 }
469 
470 void
472 {
473  Ptr<Packet> packet = Create<Packet> ();
474  Ipv4Header header;
477  QueueEntry e1 (packet, header, ucb, ecb, Seconds (1));
478 
479  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
480  {
481  q.Enqueue (e1);
482  }
483  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
484 
485  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
486  {
487  q.Enqueue (e1);
488  }
489  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
490 }
491 
492 void
494 {
495  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "Must be empty now");
496 }
497 
505 {
506  AodvqRtableEntryTest () : TestCase ("RtableEntry")
507  {
508  }
509  virtual void DoRun ()
510  {
511  Ptr<NetDevice> dev;
512  Ipv4InterfaceAddress iface;
513  RoutingTableEntry rt (/*output device*/ dev, /*dst*/ Ipv4Address ("1.2.3.4"), /*validSeqNo*/ true, /*seqNo*/ 10,
514  /*interface*/ iface, /*hop*/ 5, /*next hop*/ Ipv4Address ("3.3.3.3"), /*lifetime*/ Seconds (10));
515  NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev, "trivial");
516  NS_TEST_EXPECT_MSG_EQ (rt.GetDestination (), Ipv4Address ("1.2.3.4"), "trivial");
517  NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (), true, "trivial");
518  NS_TEST_EXPECT_MSG_EQ (rt.GetSeqNo (), 10, "trivial");
519  NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface, "trivial");
520  NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 5, "trivial");
521  NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (), Ipv4Address ("3.3.3.3"), "trivial");
522  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (10), "trivial");
523  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), VALID, "trivial");
524  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 0, "trivial");
525  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), true, "trivial");
526 
527  Ptr<NetDevice> dev2;
528  Ipv4InterfaceAddress iface2;
529  rt.SetOutputDevice (dev2);
530  NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev2, "trivial");
531  rt.SetInterface (iface2);
532  NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface2, "trivial");
533  rt.SetValidSeqNo (false);
534  NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (), false, "trivial");
535  rt.SetFlag (INVALID);
536  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
537  rt.SetFlag (IN_SEARCH);
538  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), IN_SEARCH, "trivial");
539  rt.SetHop (12);
540  NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 12, "trivial");
541  rt.SetLifeTime (Seconds (1));
542  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (1), "trivial");
543  rt.SetNextHop (Ipv4Address ("1.1.1.1"));
544  NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (), Ipv4Address ("1.1.1.1"), "trivial");
545  rt.SetUnidirectional (true);
546  NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (), true, "trivial");
547  rt.SetBlacklistTimeout (Seconds (7));
548  NS_TEST_EXPECT_MSG_EQ (rt.GetBlacklistTimeout (), Seconds (7), "trivial");
549  rt.SetRreqCnt (2);
550  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 2, "trivial");
551  rt.IncrementRreqCnt ();
552  NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 3, "trivial");
553  rt.Invalidate (Seconds (13));
554  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
555  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), Seconds (13), "trivial");
556  rt.SetLifeTime (MilliSeconds (100));
557  NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (), MilliSeconds (100), "trivial");
558  Ptr<Ipv4Route> route = rt.GetRoute ();
559  NS_TEST_EXPECT_MSG_EQ (route->GetDestination (), Ipv4Address ("1.2.3.4"), "trivial");
560 
561  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.1")), true, "trivial");
562  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), false, "trivial");
563  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), true, "trivial");
564  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.2")), false, "trivial");
565  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.3")), false, "trivial");
566  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.1")), true, "trivial");
567  NS_TEST_EXPECT_MSG_EQ (rt.DeletePrecursor (Ipv4Address ("10.0.0.2")), true, "trivial");
568  NS_TEST_EXPECT_MSG_EQ (rt.LookupPrecursor (Ipv4Address ("10.0.0.2")), false, "trivial");
569  std::vector<Ipv4Address> prec;
570  rt.GetPrecursors (prec);
571  NS_TEST_EXPECT_MSG_EQ (prec.size (), 1, "trivial");
572  NS_TEST_EXPECT_MSG_EQ (rt.InsertPrecursor (Ipv4Address ("10.0.0.4")), true, "trivial");
573  NS_TEST_EXPECT_MSG_EQ (rt.DeletePrecursor (Ipv4Address ("10.0.0.5")), false, "trivial");
574  rt.GetPrecursors (prec);
575  NS_TEST_EXPECT_MSG_EQ (prec.size (), 2, "trivial");
576  rt.DeleteAllPrecursors ();
577  NS_TEST_EXPECT_MSG_EQ (rt.IsPrecursorListEmpty (), true, "trivial");
578  rt.GetPrecursors (prec);
579  NS_TEST_EXPECT_MSG_EQ (prec.size (), 2, "trivial");
581  }
582 };
583 
590 struct AodvqRtableTest : public TestCase
591 {
592  AodvqRtableTest () : TestCase ("Rtable")
593  {
594  }
595  virtual void DoRun ()
596  {
597  RoutingTable rtable (Seconds (2));
598  NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (), Seconds (2), "trivial");
599  rtable.SetBadLinkLifetime (Seconds (1));
600  NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (), Seconds (1), "trivial");
601  Ptr<NetDevice> dev;
602  Ipv4InterfaceAddress iface;
603  RoutingTableEntry rt (/*output device*/ dev, /*dst*/ Ipv4Address ("1.2.3.4"), /*validSeqNo*/ true, /*seqNo*/ 10,
604  /*interface*/ iface, /*hop*/ 5, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (10));
605  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt), true, "trivial");
606  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt), false, "trivial");
607  RoutingTableEntry rt2 (/*output device*/ dev, /*dst*/ Ipv4Address ("4.3.2.1"), /*validSeqNo*/ false, /*seqNo*/ 0,
608  /*interface*/ iface, /*hop*/ 15, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (1));
609  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt2), true, "trivial");
610  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (rt2.GetDestination (), rt), true, "trivial");
611  NS_TEST_EXPECT_MSG_EQ (rt2.GetDestination (), rt.GetDestination (), "trivial");
612  rt.SetHop (20);
613  rt.InsertPrecursor (Ipv4Address ("10.0.0.3"));
614  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt), true, "trivial");
615  RoutingTableEntry rt3;
616  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("10.0.0.1"), rt), false, "trivial");
617  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt3), false, "trivial");
618  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("10.0.0.1"), INVALID), false, "trivial");
619  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("1.2.3.4"), IN_SEARCH), true, "trivial");
620  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("5.5.5.5")), false, "trivial");
621  RoutingTableEntry rt4 (/*output device*/ dev, /*dst*/ Ipv4Address ("5.5.5.5"), /*validSeqNo*/ false, /*seqNo*/ 0,
622  /*interface*/ iface, /*hop*/ 15, /*next hop*/ Ipv4Address ("1.1.1.1"), /*lifetime*/ Seconds (-10));
623  NS_TEST_EXPECT_MSG_EQ (rtable.AddRoute (rt4), true, "trivial");
624  NS_TEST_EXPECT_MSG_EQ (rtable.SetEntryState (Ipv4Address ("5.5.5.5"), INVALID), true, "trivial");
625  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("5.5.5.5"), rt), false, "trivial");
626  NS_TEST_EXPECT_MSG_EQ (rtable.MarkLinkAsUnidirectional (Ipv4Address ("1.2.3.4"), Seconds (2)), true, "trivial");
627  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("1.2.3.4"), rt), true, "trivial");
628  NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (), true, "trivial");
629  rt.SetLifeTime (Seconds (-5));
630  NS_TEST_EXPECT_MSG_EQ (rtable.Update (rt), true, "trivial");
631  std::map<Ipv4Address, uint32_t> unreachable;
632  rtable.GetListOfDestinationWithNextHop (Ipv4Address ("1.1.1.1"), unreachable);
633  NS_TEST_EXPECT_MSG_EQ (unreachable.size (), 2, "trivial");
634  unreachable.insert (std::make_pair (Ipv4Address ("4.3.2.1"), 3));
635  rtable.InvalidateRoutesWithDst (unreachable);
636  NS_TEST_EXPECT_MSG_EQ (rtable.LookupRoute (Ipv4Address ("4.3.2.1"), rt), true, "trivial");
637  NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (), INVALID, "trivial");
638  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), true, "trivial");
639  NS_TEST_EXPECT_MSG_EQ (rtable.DeleteRoute (Ipv4Address ("1.2.3.4")), false, "trivial");
641  }
642 };
643 
650 class AodvqTestSuite : public TestSuite
651 {
652 public:
653  AodvqTestSuite () : TestSuite ("routing-aodvq", UNIT)
654  {
665  }
667 
668 } // namespace aodvq
669 } // namespace ns3
virtual void DoRun()
Implementation to actually run this TestCase.
Time GetLifeTime() const
Get the lifetime.
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodvq-packet.h:508
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
Ipv4Address GetDst() const
Get the destination address.
Definition: aodvq-packet.h:396
MessageType Get() const
Definition: aodvq-packet.h:85
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodvq-rtable.h:189
Unit test for RREP-ACK.
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodvq-packet.h:372
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
RequestQueue q
Request queue.
Unit test for AODVQ routing table entry.
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
Definition: aodvq-rqueue.h:141
Callback template class.
Definition: callback.h:1176
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn&#39;t yet exist in the list.
Definition: aodvq-rtable.cc:70
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodvq-packet.h:220
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodvq-rtable.h:125
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition: aodvq-rqueue.h:93
Routing table entry.
Definition: aodvq-rtable.h:59
A suite of tests to run.
Definition: test.h:1342
Time GetLifeTime() const
Get the lifetime.
Definition: aodvq-rtable.h:253
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodvq-rtable.cc:85
void SetBadLinkLifetime(Time t)
Definition: aodvq-rtable.h:402
Unit test for neighbors.
bool GetNoDelete() const
Get the no delete flag.
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition: aodvq-rqueue.h:85
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast test function.
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1015
Ipv4Address GetDst() const
Get the destination address.
Definition: aodvq-packet.h:212
Time GetBadLinkLifetime() const
Definition: aodvq-rtable.h:398
#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:285
Unit test for AODVQ routing table entry.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn&#39;t yet exist in routing table.
Route Error (RERR) Message Format.
Definition: aodvq-packet.h:562
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
virtual void DoRun()
Implementation to actually run this TestCase.
encapsulates test code
Definition: test.h:1155
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodvq-packet.h:404
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
bool GetAckRequired() const
get the ack required flag
void SetDestinationOnly(bool f)
Set the Destination only flag.
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodvq-rtable.h:316
void SetCallback(Callback< void, Ipv4Address > cb)
Set link failure callback.
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodvq-rtable.h:261
Unit test for AODVQ routing table.
virtual void DoRun()
Implementation to actually run this TestCase.
AODVQ route request queue.
Definition: aodvq-rqueue.h:180
The Routing table used by AODVQ protocol.
Definition: aodvq-rtable.h:388
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Packet header for IPv4.
Definition: ipv4-header.h:33
void SetLifeTime(Time t)
Set the lifetime.
virtual void DoRun()
Implementation to actually run this TestCase.
void SetNoDelete(bool f)
Set the no delete flag.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
virtual void DoRun()
Implementation to actually run this TestCase.
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodvq-rtable.h:300
void Handler(Ipv4Address addr)
Handler test function.
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast test function.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodvq-packet.h:420
uint8_t GetHopCount() const
Get the hop count.
Definition: aodvq-packet.h:180
RouteFlags GetFlag() const
Get the route flags.
Definition: aodvq-rtable.h:269
uint32_t GetId() const
Get the request ID.
Definition: aodvq-packet.h:196
maintain list of active neighbors
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: aodvq-rqueue.h:117
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destination as follows:
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Type header test case.
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
virtual void DoRun()
Implementation to actually run this TestCase.
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodvq-packet.h:204
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodvq-rtable.h:277
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
uint16_t GetHop() const
Get the number of hops.
Definition: aodvq-rtable.h:237
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodvq-rtable.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
void CheckSizeLimit()
Check size limit function.
Route Request (RREQ) Message Format.
Definition: aodvq-packet.h:136
Ptr< Ipv4Route > GetRoute() const
Get route function.
Definition: aodvq-rtable.h:133
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSerializedSize() const
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodvq-rtable.h:165
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:1393
void Unicast2(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast 2 testfunction.
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodvq-packet.h:412
void Update(Ipv4Address addr, Time expire)
Update expire time for entry with address addr, if it exists, else add new entry. ...
void DeleteAllPrecursors()
Delete all precursors.
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodvq-packet.h:428
void Error(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error test function.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
void CheckTimeout()
Check timeout function.
void CheckTimeout3()
Check timeout function 3.
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodvq-rtable.h:229
void Error(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error test function.
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodvq-packet.h:236
Fast test.
Definition: test.h:1160
void SetGratuitousRrep(bool f)
Set the gratuitous RREP flag.
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodvq-rtable.h:157
void SetPrefixSize(uint8_t sz)
Set the prefix size.
QueueEntryTest()
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
void SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodvq-rtable.h:197
AodvqRtableEntryTest()
a class to store IPv4 address information on an interface
virtual void DoRun()
Implementation to actually run this TestCase.
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodvq-rtable.h:245
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodvq-rtable.h:173
uint8_t GetHopCount() const
Get the hop count.
Definition: aodvq-packet.h:380
Neighbors * neighbor
The Neighbors.
void SetUnknownSeqno(bool f)
Set the unknown sequence number flag.
void SetExpireTime(Time exp)
Set expire time.
Definition: aodvq-rqueue.h:149
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodvq-packet.h:244
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
void CheckTimeout1()
Check timeout function 1.
void Error2(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error2 test function.
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodvq-packet.h:228
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodvq-rtable.h:292
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
uint32_t GetSeqNo() const
Get the sequence number.
Definition: aodvq-rtable.h:221
Time GetExpireTime() const
Get expire time.
Definition: aodvq-rqueue.h:157
void SetId(uint32_t id)
Set the request ID.
Definition: aodvq-packet.h:188
uint8_t GetPrefixSize() const
Set the pefix size.
virtual void DoRun()
Implementation to actually run this TestCase.
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodvq-rtable.h:324
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodvq-rtable.h:285
bool Update(RoutingTableEntry &rt)
Update routing table.
void SetAckRequired(bool f)
Set the ack required flag.
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Definition: aodvq-rqueue.h:133
AODVQ Queue Entry.
Definition: aodvq-rqueue.h:43
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodvq-rtable.h:149
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodvq-packet.h:252
virtual void DoRun()
Implementation to actually run this TestCase.
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0. ...
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
Definition: aodvq-rqueue.h:109
uint8_t GetDestCount() const
Definition: aodvq-packet.h:609
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
Unit test for RequestQueue.
bool GetDestinationOnly() const
Get the Destination only flag.
ErrorCallback GetErrorCallback() const
Get error callback.
Definition: aodvq-rqueue.h:101
bool IsValid() const
Check that type if valid.
Definition: aodvq-packet.h:93
bool GetUnknownSeqno() const
Get the unknown sequence number flag.
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
void CheckTimeout2()
Check timeout function 2.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodvq-packet.h:260
ns3::aodvq::AodvqTestSuite g_aodvqTestSuite
the test suite
virtual void DoRun()
Implementation to actually run this TestCase.
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodvq-rtable.h:181
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodvq-packet.h:388
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodvq-packet.h:172
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodvq-rtable.h:308
Route Reply (RREP) Message Format.
Definition: aodvq-packet.h:340