A Discrete-Event Network Simulator
API
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
27namespace ns3 {
28namespace aodv {
29
36struct 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
58void
60{
61}
62
63void
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}
71void
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}
79void
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
88void
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
110}
111
119{
120 TypeHeaderTest () : TestCase ("AODV 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 (), AODVTYPE_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
145{
146 RreqHeaderTest () : TestCase ("AODV 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
198{
199 RrepHeaderTest () : TestCase ("AODV 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 ("AODV RREP-ACK")
252 {
253 }
254 virtual void DoRun ()
255 {
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
273{
274 RerrHeaderTest () : TestCase ("AODV 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
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));
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//-----------------------------------------------------------------------------
378{
379 AodvRqueueTest () : 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
411void
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");
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
459
460 Ipv4Header header2;
461 Ipv4Address dst2 ("1.2.3.4");
462 header2.SetDestination (dst2);
463
465
468}
469
470void
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
492void
494{
495 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "Must be empty now");
496}
497
505{
506 AodvRtableEntryTest () : TestCase ("RtableEntry")
507 {
508 }
509 virtual void DoRun ()
510 {
511 Ptr<NetDevice> dev;
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;
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");
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");
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
591{
592 AodvRtableTest () : 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;
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");
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
651{
652public:
653 AodvTestSuite () : TestSuite ("routing-aodv", UNIT)
654 {
665 }
667
668} // namespace aodv
669} // namespace ns3
Callback template class.
Definition: callback.h:1279
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:1521
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Packet header for IPv4.
Definition: ipv4-header.h:34
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
a class to store IPv4 address information on an interface
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
encapsulates test code
Definition: test.h:994
@ QUICK
Fast test.
Definition: test.h:999
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
maintain list of active neighbors
Definition: aodv-neighbor.h:52
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0.
void Update(Ipv4Address addr, Time expire)
Update expire time for entry with address addr, if it exists, else add new entry.
void SetCallback(Callback< void, Ipv4Address > cb)
Set link failure callback.
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
AODV Queue Entry.
Definition: aodv-rqueue.h:44
Time GetExpireTime() const
Get expire time.
Definition: aodv-rqueue.h:157
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
Definition: aodv-rqueue.h:109
ErrorCallback GetErrorCallback() const
Get error callback.
Definition: aodv-rqueue.h:101
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition: aodv-rqueue.h:93
void SetExpireTime(Time exp)
Set expire time.
Definition: aodv-rqueue.h:149
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Definition: aodv-rqueue.h:133
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: aodv-rqueue.h:117
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition: aodv-rqueue.h:85
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
Definition: aodv-rqueue.h:141
AODV route request queue.
Definition: aodv-rqueue.h:181
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition: aodv-rqueue.cc:90
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Definition: aodv-rqueue.h:238
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:106
Time GetQueueTimeout() const
Get queue timeout.
Definition: aodv-rqueue.h:246
void SetQueueTimeout(Time t)
Set queue timeout.
Definition: aodv-rqueue.h:254
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition: aodv-rqueue.cc:72
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:48
uint32_t GetMaxQueueLen() const
Get maximum queue length.
Definition: aodv-rqueue.h:230
Route Error (RERR) Message Format.
Definition: aodv-packet.h:558
uint8_t GetDestCount() const
Definition: aodv-packet.h:604
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:613
void SetNoDelete(bool f)
Set the no delete flag.
Definition: aodv-packet.cc:600
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Definition: aodv-packet.cc:619
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:546
Routing table entry.
Definition: aodv-rtable.h:60
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:121
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodv-rtable.h:229
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Definition: aodv-rtable.cc:128
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:70
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodv-rtable.h:173
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodv-rtable.h:285
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:181
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodv-rtable.h:149
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodv-rtable.h:245
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodv-rtable.h:308
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
Definition: aodv-rtable.cc:134
RouteFlags GetFlag() const
Get the route flags.
Definition: aodv-rtable.h:269
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodv-rtable.h:157
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodv-rtable.h:316
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodv-rtable.h:292
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:102
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:189
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodv-rtable.h:277
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
Definition: aodv-rtable.cc:161
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:85
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodv-rtable.h:165
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodv-rtable.h:125
uint16_t GetHop() const
Get the number of hops.
Definition: aodv-rtable.h:237
void SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodv-rtable.h:197
uint32_t GetSeqNo() const
Get the sequence number.
Definition: aodv-rtable.h:221
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodv-rtable.h:300
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodv-rtable.h:205
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodv-rtable.h:261
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-rtable.h:253
Ptr< Ipv4Route > GetRoute() const
Get route function.
Definition: aodv-rtable.h:133
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodv-rtable.h:324
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:390
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:327
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destination as follows:
Definition: aodv-rtable.cc:344
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:290
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:276
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:227
void SetBadLinkLifetime(Time t)
Set the lifetime of a bad link.
Definition: aodv-rtable.h:413
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:310
Time GetBadLinkLifetime() const
Get the lifetime of a bad link.
Definition: aodv-rtable.h:404
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:462
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:262
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:504
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:336
bool GetAckRequired() const
get the ack required flag
Definition: aodv-packet.cc:405
uint8_t GetPrefixSize() const
Set the pefix size.
Definition: aodv-packet.cc:417
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:399
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:423
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:431
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:375
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:415
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:367
void SetLifeTime(Time t)
Set the lifetime.
Definition: aodv-packet.cc:379
void SetAckRequired(bool f)
Set the ack required flag.
Definition: aodv-packet.cc:392
void SetPrefixSize(uint8_t sz)
Set the prefix size.
Definition: aodv-packet.cc:411
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-packet.cc:385
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:383
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:407
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:391
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:132
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:191
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:199
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:175
bool GetUnknownSeqno() const
Get the unknown sequence number flag.
Definition: aodv-packet.cc:281
void SetId(uint32_t id)
Set the request ID.
Definition: aodv-packet.h:183
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:255
void SetUnknownSeqno(bool f)
Set the unknown sequence number flag.
Definition: aodv-packet.cc:268
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:239
void SetGratuitousRrep(bool f)
Set the gratuitous RREP flag.
Definition: aodv-packet.cc:230
void SetDestinationOnly(bool f)
Set the Destination only flag.
Definition: aodv-packet.cc:249
bool GetDestinationOnly() const
Get the Destination only flag.
Definition: aodv-packet.cc:262
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:167
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:215
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:223
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:207
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:247
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
Definition: aodv-packet.cc:243
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:231
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:88
MessageType Get() const
Definition: aodv-packet.h:80
@ INVALID
INVALID.
Definition: aodv-rtable.h:51
@ IN_SEARCH
IN_SEARCH.
Definition: aodv-rtable.h:52
@ VALID
VALID.
Definition: aodv-rtable.h:50
@ AODVTYPE_RREP
AODVTYPE_RREP.
Definition: aodv-packet.h:48
@ AODVTYPE_RREQ
AODVTYPE_RREQ.
Definition: aodv-packet.h:47
#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:240
ns3::aodv::AodvTestSuite g_aodvTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
Unit test for RequestQueue.
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast test function.
RequestQueue q
Request queue.
void CheckTimeout()
Check timeout function.
virtual void DoRun()
Implementation to actually run this TestCase.
void Error(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error test function.
void CheckSizeLimit()
Check size limit function.
Unit test for AODV routing table entry.
AodvRtableEntryTest()
virtual void DoRun()
Implementation to actually run this TestCase.
Unit test for AODV routing table.
virtual void DoRun()
Implementation to actually run this TestCase.
Unit test for neighbors.
void CheckTimeout2()
Check timeout function 2.
Neighbors * neighbor
The Neighbors.
void Handler(Ipv4Address addr)
Handler test function.
void CheckTimeout1()
Check timeout function 1.
virtual void DoRun()
Implementation to actually run this TestCase.
void CheckTimeout3()
Check timeout function 3.
Unit test for AODV routing table entry.
void Error(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error test function.
void Unicast2(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast 2 testfunction.
virtual void DoRun()
Implementation to actually run this TestCase.
QueueEntryTest()
void Unicast(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Unicast test function.
void Error2(Ptr< const Packet > p, const Ipv4Header &h, Socket::SocketErrno e)
Error2 test function.
virtual void DoRun()
Implementation to actually run this TestCase.
Unit test for RREP-ACK.
virtual void DoRun()
Implementation to actually run this TestCase.
virtual void DoRun()
Implementation to actually run this TestCase.
virtual void DoRun()
Implementation to actually run this TestCase.
Type header test case.
virtual void DoRun()
Implementation to actually run this TestCase.