A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aodv-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/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 ();
42 };
43 
44 void
46 {
47 }
48 
49 void
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
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
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;
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 
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  {
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);
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) {}
263  void Unicast2 (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
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"));
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");
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) {}
302  void CheckSizeLimit ();
303  void CheckTimeout ();
304 
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"));
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 
362 
363  Simulator::Run ();
365 }
366 
367 void
369 {
370  Ptr<Packet> packet = Create<Packet> ();
371  Ipv4Header header;
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
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  {
538  }
540 
541 }
542 }
UnicastForwardCallback GetUnicastForwardCallback() const
Definition: aodv-rqueue.h:66
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
maintain list of active neighbors
Definition: aodv-neighbor.h:49
Unit test for RREP-ACK.
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destinations as follows:
Definition: aodv-rtable.cc:314
Unit test for AODV routing table entry.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:420
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
void SetOutputDevice(Ptr< NetDevice > dev)
RREP_ACK timer.
Definition: aodv-rtable.h:111
void SetOrigin(Ipv4Address a)
Definition: aodv-packet.h:205
Callback template class.
Definition: callback.h:920
AODV route request queue.
Definition: aodv-rqueue.h:95
bool GetUnknownSeqno() const
Definition: aodv-packet.cc:264
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:199
Ipv4Header GetIpv4Header() const
Definition: aodv-rqueue.h:72
void SetId(uint32_t id)
Definition: aodv-packet.h:125
virtual void DoRun()
Implementation to actually run this TestCase.
bool GetAckRequired() const
Definition: aodv-packet.cc:380
Route Error (RERR) Message Format.
Definition: aodv-packet.h:288
void Unicast2(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
void SetNoDelete(bool f)
Definition: aodv-packet.cc:574
A suite of tests to run.
Definition: test.h:1025
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:260
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
void IncrementRreqCnt()
RREP_ACK timer.
Definition: aodv-rtable.h:127
void Error(Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno)
void SetMaxQueueLen(uint32_t len)
Definition: aodv-rqueue.h:116
void SetDst(Ipv4Address a)
Definition: aodv-packet.h:127
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
uint32_t GetDstSeqno() const
Definition: aodv-packet.h:204
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Definition: aodv-rqueue.h:67
virtual void DoRun()
Implementation to actually run this TestCase.
Ptr< NetDevice > GetOutputDevice() const
RREP_ACK timer.
Definition: aodv-rtable.h:112
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
void Error2(Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno)
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in vector prec if they does not yet exist in vector.
Definition: aodv-rtable.cc:127
virtual void DoRun()
Implementation to actually run this TestCase.
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
virtual void DoRun()
Implementation to actually run this TestCase.
void SetExpireTime(Time exp)
Definition: aodv-rqueue.h:74
void SetLifeTime(Time lt)
RREP_ACK timer.
Definition: aodv-rtable.h:121
void SetBalcklistTimeout(Time t)
RREP_ACK timer.
Definition: aodv-rtable.h:130
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:102
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
ns3::aodv::AodvTestSuite g_aodvTestSuite
void SetDstSeqno(uint32_t s)
Definition: aodv-packet.h:203
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 TestCase.
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)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:65
Packet header for IPv4.
Definition: ipv4-header.h:31
Unit test for neighbors.
Time GetLifeTime() const
RREP_ACK timer.
Definition: aodv-rtable.h:122
void SetRreqCnt(uint8_t n)
RREP_ACK timer.
Definition: aodv-rtable.h:125
bool IsPrecursorListEmpty() const
Check that precursor list empty.
Definition: aodv-rtable.cc:121
virtual void DoRun()
Implementation to actually run this TestCase.
void SetHopCount(uint8_t count)
Definition: aodv-packet.h:199
void Error(Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno)
void SetErrorCallback(ErrorCallback ecb)
Definition: aodv-rqueue.h:69
void SetPrefixSize(uint8_t sz)
Definition: aodv-packet.cc:386
bool GetGratiousRrep() const
Definition: aodv-packet.cc:234
Time GetQueueTimeout() const
Definition: aodv-rqueue.h:117
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:280
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:78
void SetIpv4Header(Ipv4Header h)
Definition: aodv-rqueue.h:73
uint8_t GetDestCount() const
Return number of unreachable destinations in RERR message.
Definition: aodv-packet.h:322
Ipv4Address GetNextHop() const
RREP_ACK timer.
Definition: aodv-rtable.h:110
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Definition: aodv-packet.cc:589
Ipv4Address GetDst() const
Definition: aodv-packet.h:128
virtual void DoRun()
Implementation to actually run this TestCase.
#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:244
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:95
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
void SetValidSeqNo(bool s)
RREP_ACK timer.
Definition: aodv-rtable.h:115
void SetOriginSeqno(uint32_t s)
Definition: aodv-packet.h:133
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1238
uint8_t GetHopCount() const
Definition: aodv-packet.h:124
void SetDestinationOnly(bool f)
Definition: aodv-packet.cc:240
Time GetBlacklistTimeout() const
RREP_ACK timer.
Definition: aodv-rtable.h:131
Unit test for RERR.
uint32_t GetMaxQueueLen() const
Definition: aodv-rqueue.h:115
AODVTYPE_RREP.
Definition: aodv-packet.h:44
Ptr< const Packet > GetPacket() const
Definition: aodv-rqueue.h:70
Ipv4InterfaceAddress GetInterface() const
RREP_ACK timer.
Definition: aodv-rtable.h:113
Unit test for RREQ.
Time GetBadLinkLifetime() const
Definition: aodv-rtable.h:195
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:114
AodvRtableEntryTest()
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDstSeqno(uint32_t s)
Definition: aodv-packet.h:129
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:180
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:297
uint8_t GetPrefixSize() const
Definition: aodv-packet.cc:392
void SetInterface(Ipv4InterfaceAddress iface)
RREP_ACK timer.
Definition: aodv-rtable.h:114
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:406
void SetFlag(RouteFlags flag)
RREP_ACK timer.
Definition: aodv-rtable.h:123
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: aodv-rtable.cc:148
Ipv4Address GetOrigin() const
Definition: aodv-packet.h:206
uint16_t GetHop() const
RREP_ACK timer.
Definition: aodv-rtable.h:120
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:1137
ErrorCallback GetErrorCallback() const
Definition: aodv-rqueue.h:68
uint32_t GetSize()
Number of entries.
Definition: aodv-rqueue.cc:42
void SetBadLinkLifetime(Time t)
Definition: aodv-rtable.h:196
void SetOrigin(Ipv4Address a)
Definition: aodv-packet.h:131
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 child TestCase case to this TestCase.
Definition: test.cc:173
Time GetLifeTime() const
Definition: aodv-packet.cc:364
AODVTYPE_RREQ.
Definition: aodv-packet.h:43
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Ipv4Address GetDst() const
Definition: aodv-packet.h:202
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:188
virtual void DoRun()
Implementation to actually run this TestCase.
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:246
Time GetExpireTime() const
Definition: aodv-rqueue.h:75
void SetUnidirectional(bool u)
RREP_ACK timer.
Definition: aodv-rtable.h:128
Fast test.
Definition: test.h:857
uint32_t GetDstSeqno() const
Definition: aodv-packet.h:130
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0. ...
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
void SetHop(uint16_t hop)
RREP_ACK timer.
Definition: aodv-rtable.h:119
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual void DoRun()
Implementation to actually run this TestCase.
a class to store IPv4 address information on an interface
uint32_t GetSeqNo() const
RREP_ACK timer.
Definition: aodv-rtable.h:118
void SetQueueTimeout(Time t)
Definition: aodv-rqueue.h:118
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:248
void Handler(Ipv4Address addr)
QueueEntryTest()
Ipv4Address GetOrigin() const
Definition: aodv-packet.h:132
void SetCallback(Callback< void, Ipv4Address > cb)
Definition: aodv-neighbor.h:90
void SetAckRequired(bool f)
Definition: aodv-packet.cc:371
uint32_t GetOriginSeqno() const
Definition: aodv-packet.h:134
void SetNextHop(Ipv4Address nextHop)
RREP_ACK timer.
Definition: aodv-rtable.h:109
bool GetDestinationOnly() const
Definition: aodv-packet.cc:249
Ptr< Ipv4Route > GetRoute() const
RREP_ACK timer.
Definition: aodv-rtable.h:107
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:104
void SetGratiousRrep(bool f)
Definition: aodv-packet.cc:225
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.
This test suite implements a Unit Test.
Definition: test.h:1035
virtual void DoRun()
Implementation to actually run this TestCase.
bool IsUnidirectional() const
RREP_ACK timer.
Definition: aodv-rtable.h:129
uint32_t GetId() const
Definition: aodv-packet.h:126
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:234
RouteFlags GetFlag() const
RREP_ACK timer.
Definition: aodv-rtable.h:124
Ipv4Address GetDestination() const
RREP_ACK timer.
Definition: aodv-rtable.h:106
MessageType Get() const
Return type.
Definition: aodv-packet.h:70
uint8_t GetHopCount() const
Definition: aodv-packet.h:200
uint8_t GetRreqCnt() const
RREP_ACK timer.
Definition: aodv-rtable.h:126
void SetUnknownSeqno(bool f)
Definition: aodv-packet.cc:255
void SetDst(Ipv4Address a)
Definition: aodv-packet.h:201
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
bool GetValidSeqNo() const
RREP_ACK timer.
Definition: aodv-rtable.h:116
bool GetNoDelete() const
Definition: aodv-packet.cc:583
void SetLifeTime(Time t)
Definition: aodv-packet.cc:358
void SetHopCount(uint8_t count)
Definition: aodv-packet.h:123