A Discrete-Event Network Simulator
API
aodv-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Pavel Boyko <boyko@iitp.ru>
18 */
19#include "ns3/aodv-neighbor.h"
20#include "ns3/aodv-packet.h"
21#include "ns3/aodv-rqueue.h"
22#include "ns3/aodv-rtable.h"
23#include "ns3/ipv4-route.h"
24#include "ns3/test.h"
25
26namespace ns3
27{
28namespace aodv
29{
30
37struct NeighborTest : public TestCase
38{
40 : TestCase("Neighbor"),
41 neighbor(nullptr)
42 {
43 }
44
45 void DoRun() override;
50 void Handler(Ipv4Address addr);
52 void CheckTimeout1();
54 void CheckTimeout2();
56 void CheckTimeout3();
59};
60
61void
63{
64}
65
66void
68{
69 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
70 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), true, "Neighbor exists");
71 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), true, "Neighbor exists");
72 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
73}
74
75void
77{
79 false,
80 "Neighbor doesn't exist");
82 false,
83 "Neighbor doesn't exist");
85 false,
86 "Neighbor doesn't exist");
87 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
88}
89
90void
92{
94 false,
95 "Neighbor doesn't exist");
97 false,
98 "Neighbor doesn't exist");
100 false,
101 "Neighbor doesn't exist");
103 false,
104 "Neighbor doesn't exist");
105}
106
107void
109{
110 Neighbors nb(Seconds(1));
111 neighbor = &nb;
113 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(1));
114 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
116 false,
117 "Neighbor doesn't exist");
118 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(10));
119 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
121 Seconds(10),
122 "Known expire time");
124 Seconds(0),
125 "Known expire time");
126 neighbor->Update(Ipv4Address("1.1.1.1"), Seconds(5));
127 neighbor->Update(Ipv4Address("2.2.2.2"), Seconds(10));
128 neighbor->Update(Ipv4Address("3.3.3.3"), Seconds(20));
129
135}
136
144{
146 : TestCase("AODV TypeHeader")
147 {
148 }
149
150 void DoRun() override
151 {
153 NS_TEST_EXPECT_MSG_EQ(h.IsValid(), true, "Default header is valid");
154 NS_TEST_EXPECT_MSG_EQ(h.Get(), AODVTYPE_RREQ, "Default header is RREQ");
155
156 Ptr<Packet> p = Create<Packet>();
157 p->AddHeader(h);
159 uint32_t bytes = p->RemoveHeader(h2);
160 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "Type header is 1 byte long");
161 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
162 }
163};
164
172{
174 : TestCase("AODV RREQ")
175 {
176 }
177
178 void DoRun() override
179 {
180 RreqHeader h(/*flags*/ 0,
181 /*reserved*/ 0,
182 /*hopCount*/ 6,
183 /*requestID*/ 1,
184 /*dst*/ Ipv4Address("1.2.3.4"),
185 /*dstSeqNo*/ 40,
186 /*origin*/ Ipv4Address("4.3.2.1"),
187 /*originSeqNo*/ 10);
188 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), false, "trivial");
189 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), false, "trivial");
190 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 6, "trivial");
191 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 1, "trivial");
192 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
193 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 40, "trivial");
194 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
195 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 10, "trivial");
196
197 h.SetGratuitousRrep(true);
198 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), true, "trivial");
199 h.SetDestinationOnly(true);
200 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), true, "trivial");
201 h.SetUnknownSeqno(true);
202 NS_TEST_EXPECT_MSG_EQ(h.GetUnknownSeqno(), true, "trivial");
203 h.SetDst(Ipv4Address("1.1.1.1"));
204 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
205 h.SetDstSeqno(5);
206 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 5, "trivial");
207 h.SetHopCount(7);
208 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 7, "trivial");
209 h.SetId(55);
210 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 55, "trivial");
211 h.SetOrigin(Ipv4Address("4.4.4.4"));
212 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
213 h.SetOriginSeqno(23);
214 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 23, "trivial");
215
216 Ptr<Packet> p = Create<Packet>();
217 p->AddHeader(h);
218 RreqHeader h2;
219 uint32_t bytes = p->RemoveHeader(h2);
220 NS_TEST_EXPECT_MSG_EQ(bytes, 23, "RREP is 23 bytes long");
221 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
222 }
223};
224
232{
234 : TestCase("AODV RREP")
235 {
236 }
237
238 void DoRun() override
239 {
240 RrepHeader h(/*prefixSize*/ 0,
241 /*hopCount*/ 12,
242 /*dst*/ Ipv4Address("1.2.3.4"),
243 /*dstSeqNo*/ 2,
244 /*origin*/ Ipv4Address("4.3.2.1"),
245 /*lifetime*/ Seconds(3));
246 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 0, "trivial");
247 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 12, "trivial");
248 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
249 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 2, "trivial");
250 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
251 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(3), "trivial");
252 h.SetDst(Ipv4Address("1.1.1.1"));
253 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
254 h.SetDstSeqno(123);
255 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 123, "trivial");
256 h.SetOrigin(Ipv4Address("4.4.4.4"));
257 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
258 h.SetLifeTime(MilliSeconds(1200));
259 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), MilliSeconds(1200), "trivial");
260 h.SetAckRequired(true);
261 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), true, "trivial");
262 h.SetAckRequired(false);
263 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), false, "trivial");
264 h.SetPrefixSize(2);
265 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 2, "trivial");
266 h.SetHopCount(15);
267 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 15, "trivial");
268
269 h.SetHello(Ipv4Address("10.0.0.2"), 9, Seconds(15));
270 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), h.GetOrigin(), "trivial");
271 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 9, "trivial");
272 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(15), "trivial");
273
274 Ptr<Packet> p = Create<Packet>();
275 p->AddHeader(h);
276 RrepHeader h2;
277 uint32_t bytes = p->RemoveHeader(h2);
278 NS_TEST_EXPECT_MSG_EQ(bytes, 19, "RREP is 19 bytes long");
279 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
280 }
281};
282
290{
292 : TestCase("AODV RREP-ACK")
293 {
294 }
295
296 void DoRun() override
297 {
299 Ptr<Packet> p = Create<Packet>();
300 p->AddHeader(h);
301 RrepAckHeader h2;
302 uint32_t bytes = p->RemoveHeader(h2);
303 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "ACK is 1 byte long");
304 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
305 }
306};
307
315{
317 : TestCase("AODV RERR")
318 {
319 }
320
321 void DoRun() override
322 {
323 RerrHeader h;
324 h.SetNoDelete(true);
325 NS_TEST_EXPECT_MSG_EQ(h.GetNoDelete(), true, "trivial");
326 Ipv4Address dst = Ipv4Address("1.2.3.4");
327 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 12), true, "trivial");
328 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 1, "trivial");
329 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 13), true, "trivial");
330 Ipv4Address dst2 = Ipv4Address("4.3.2.1");
331 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst2, 12), true, "trivial");
332 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 2, "trivial");
333
334 Ptr<Packet> p = Create<Packet>();
335 p->AddHeader(h);
336 RerrHeader h2;
337 uint32_t bytes = p->RemoveHeader(h2);
338 NS_TEST_EXPECT_MSG_EQ(bytes, h.GetSerializedSize(), "(De)Serialized size match");
339 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
340 }
341};
342
350{
352 : TestCase("QueueEntry")
353 {
354 }
355
362 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
363 {
364 }
365
373 {
374 }
375
382 void Unicast2(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
383 {
384 }
385
393 {
394 }
395
396 void DoRun() override
397 {
398 Ptr<const Packet> packet = Create<Packet>();
399 Ipv4Header h;
400 h.SetDestination(Ipv4Address("1.2.3.4"));
401 h.SetSource(Ipv4Address("4.3.2.1"));
405 QueueEntry entry(packet, h, ucb, ecb, Seconds(1));
408 "trivial");
409 NS_TEST_EXPECT_MSG_EQ(h.GetSource(), entry.GetIpv4Header().GetSource(), "trivial");
410 NS_TEST_EXPECT_MSG_EQ(ucb.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
411 NS_TEST_EXPECT_MSG_EQ(ecb.IsEqual(entry.GetErrorCallback()), true, "trivial");
412 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(1), "trivial");
413 NS_TEST_EXPECT_MSG_EQ(entry.GetPacket(), packet, "trivial");
414 entry.SetExpireTime(Seconds(3));
415 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(3), "trivial");
416 Ipv4Header h2;
417 h2.SetDestination(Ipv4Address("1.1.1.1"));
418 entry.SetIpv4Header(h2);
420 Ipv4Address("1.1.1.1"),
421 "trivial");
425 entry.SetErrorCallback(ecb2);
426 NS_TEST_EXPECT_MSG_EQ(ecb2.IsEqual(entry.GetErrorCallback()), true, "trivial");
427 entry.SetUnicastForwardCallback(ucb2);
428 NS_TEST_EXPECT_MSG_EQ(ucb2.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
429 }
430};
431
432//-----------------------------------------------------------------------------
435{
437 : TestCase("Rqueue"),
438 q(64, Seconds(30))
439 {
440 }
441
442 void DoRun() override;
443
450 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
451 {
452 }
453
461 {
462 }
463
465 void CheckSizeLimit();
467 void CheckTimeout();
468
471};
472
473void
475{
476 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 64, "trivial");
477 q.SetMaxQueueLen(32);
478 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 32, "trivial");
482
483 Ptr<const Packet> packet = Create<Packet>();
484 Ipv4Header h;
485 h.SetDestination(Ipv4Address("1.2.3.4"));
486 h.SetSource(Ipv4Address("4.3.2.1"));
489 QueueEntry e1(packet, h, ucb, ecb, Seconds(1));
490 q.Enqueue(e1);
491 q.Enqueue(e1);
492 q.Enqueue(e1);
493 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), true, "trivial");
494 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.1.1.1")), false, "trivial");
495 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
496 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
497 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), false, "trivial");
498 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "trivial");
499
500 h.SetDestination(Ipv4Address("2.2.2.2"));
501 QueueEntry e2(packet, h, ucb, ecb, Seconds(1));
502 q.Enqueue(e1);
503 q.Enqueue(e2);
504 Ptr<Packet> packet2 = Create<Packet>();
505 QueueEntry e3(packet2, h, ucb, ecb, Seconds(1));
506 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("3.3.3.3"), e3), false, "trivial");
507 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("2.2.2.2"), e3), true, "trivial");
508 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("2.2.2.2")), false, "trivial");
509 q.Enqueue(e2);
510 q.Enqueue(e3);
511 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
512 Ptr<Packet> packet4 = Create<Packet>();
513 h.SetDestination(Ipv4Address("1.2.3.4"));
514 QueueEntry e4(packet4, h, ucb, ecb, Seconds(20));
515 q.Enqueue(e4);
516 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 3, "trivial");
517 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
518 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
519
521
522 Ipv4Header header2;
523 Ipv4Address dst2("1.2.3.4");
524 header2.SetDestination(dst2);
525
527
530}
531
532void
534{
535 Ptr<Packet> packet = Create<Packet>();
536 Ipv4Header header;
539 QueueEntry e1(packet, header, ucb, ecb, Seconds(1));
540
541 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
542 {
543 q.Enqueue(e1);
544 }
545 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
546
547 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
548 {
549 q.Enqueue(e1);
550 }
551 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
552}
553
554void
556{
557 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "Must be empty now");
558}
559
567{
569 : TestCase("RtableEntry")
570 {
571 }
572
573 void DoRun() override
574 {
575 Ptr<NetDevice> dev;
577 RoutingTableEntry rt(/*output device*/ dev,
578 /*dst*/ Ipv4Address("1.2.3.4"),
579 /*validSeqNo*/ true,
580 /*seqNo*/ 10,
581 /*interface*/ iface,
582 /*hop*/ 5,
583 /*next hop*/ Ipv4Address("3.3.3.3"),
584 /*lifetime*/ Seconds(10));
585 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev, "trivial");
586 NS_TEST_EXPECT_MSG_EQ(rt.GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
587 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), true, "trivial");
588 NS_TEST_EXPECT_MSG_EQ(rt.GetSeqNo(), 10, "trivial");
589 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface, "trivial");
590 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 5, "trivial");
591 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("3.3.3.3"), "trivial");
592 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(10), "trivial");
593 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), VALID, "trivial");
594 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 0, "trivial");
595 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
596
597 Ptr<NetDevice> dev2;
599 rt.SetOutputDevice(dev2);
600 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev2, "trivial");
601 rt.SetInterface(iface2);
602 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface2, "trivial");
603 rt.SetValidSeqNo(false);
604 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), false, "trivial");
605 rt.SetFlag(INVALID);
606 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
607 rt.SetFlag(IN_SEARCH);
608 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), IN_SEARCH, "trivial");
609 rt.SetHop(12);
610 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 12, "trivial");
611 rt.SetLifeTime(Seconds(1));
612 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(1), "trivial");
613 rt.SetNextHop(Ipv4Address("1.1.1.1"));
614 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("1.1.1.1"), "trivial");
615 rt.SetUnidirectional(true);
616 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
619 rt.SetRreqCnt(2);
620 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 2, "trivial");
621 rt.IncrementRreqCnt();
622 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 3, "trivial");
623 rt.Invalidate(Seconds(13));
624 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
625 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(13), "trivial");
626 rt.SetLifeTime(MilliSeconds(100));
627 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), MilliSeconds(100), "trivial");
628 Ptr<Ipv4Route> route = rt.GetRoute();
629 NS_TEST_EXPECT_MSG_EQ(route->GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
630
631 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
632 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), false, "trivial");
633 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
634 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
635 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.3")), false, "trivial");
636 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
637 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
638 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
639 std::vector<Ipv4Address> prec;
640 rt.GetPrecursors(prec);
641 NS_TEST_EXPECT_MSG_EQ(prec.size(), 1, "trivial");
642 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.4")), true, "trivial");
643 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.5")), false, "trivial");
644 rt.GetPrecursors(prec);
645 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
647 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
648 rt.GetPrecursors(prec);
649 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
651 }
652};
653
661{
663 : TestCase("Rtable")
664 {
665 }
666
667 void DoRun() override
668 {
669 RoutingTable rtable(Seconds(2));
670 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(2), "trivial");
671 rtable.SetBadLinkLifetime(Seconds(1));
672 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(1), "trivial");
673 Ptr<NetDevice> dev;
675 RoutingTableEntry rt(/*output device*/ dev,
676 /*dst*/ Ipv4Address("1.2.3.4"),
677 /*validSeqNo*/ true,
678 /*seqNo*/ 10,
679 /*interface*/ iface,
680 /*hop*/ 5,
681 /*next hop*/ Ipv4Address("1.1.1.1"),
682 /*lifetime*/ Seconds(10));
683 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), true, "trivial");
684 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), false, "trivial");
685 RoutingTableEntry rt2(/*output device*/ dev,
686 /*dst*/ Ipv4Address("4.3.2.1"),
687 /*validSeqNo*/ false,
688 /*seqNo*/ 0,
689 /*interface*/ iface,
690 /*hop*/ 15,
691 /*next hop*/ Ipv4Address("1.1.1.1"),
692 /*lifetime*/ Seconds(1));
693 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt2), true, "trivial");
694 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(rt2.GetDestination(), rt), true, "trivial");
696 rt.SetHop(20);
697 rt.InsertPrecursor(Ipv4Address("10.0.0.3"));
698 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
700 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("10.0.0.1"), rt), false, "trivial");
701 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt3), false, "trivial");
703 false,
704 "trivial");
706 true,
707 "trivial");
708 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("5.5.5.5")), false, "trivial");
709 RoutingTableEntry rt4(/*output device*/ dev,
710 /*dst*/ Ipv4Address("5.5.5.5"),
711 /*validSeqNo*/ false,
712 /*seqNo*/ 0,
713 /*interface*/ iface,
714 /*hop*/ 15,
715 /*next hop*/ Ipv4Address("1.1.1.1"),
716 /*lifetime*/ Seconds(-10));
717 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt4), true, "trivial");
719 true,
720 "trivial");
721 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false, "trivial");
723 true,
724 "trivial");
725 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("1.2.3.4"), rt), true, "trivial");
726 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
727 rt.SetLifeTime(Seconds(-5));
728 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
729 std::map<Ipv4Address, uint32_t> unreachable;
730 rtable.GetListOfDestinationWithNextHop(Ipv4Address("1.1.1.1"), unreachable);
731 NS_TEST_EXPECT_MSG_EQ(unreachable.size(), 2, "trivial");
732 unreachable.insert(std::make_pair(Ipv4Address("4.3.2.1"), 3));
733 rtable.InvalidateRoutesWithDst(unreachable);
734 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("4.3.2.1"), rt), true, "trivial");
735 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
736 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), true, "trivial");
737 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), false, "trivial");
739 }
740};
741
749{
750 public:
752 : TestSuite("routing-aodv", UNIT)
753 {
764 }
766
767} // namespace aodv
768} // namespace ns3
Callback template class.
Definition: callback.h:443
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:584
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Packet header for IPv4.
Definition: ipv4-header.h:34
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:309
Ipv4Address GetSource() const
Definition: ipv4-header.cc:302
Ipv4Address GetDestination() const
Definition: ipv4-header.cc:316
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:295
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:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
maintain list of active neighbors
Definition: aodv-neighbor.h:54
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:45
Time GetExpireTime() const
Get expire time.
Definition: aodv-rqueue.h:172
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
Definition: aodv-rqueue.h:118
ErrorCallback GetErrorCallback() const
Get error callback.
Definition: aodv-rqueue.h:109
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition: aodv-rqueue.h:100
void SetExpireTime(Time exp)
Set expire time.
Definition: aodv-rqueue.h:163
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Definition: aodv-rqueue.h:145
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: aodv-rqueue.h:127
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition: aodv-rqueue.h:91
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
Definition: aodv-rqueue.h:154
AODV route request queue.
Definition: aodv-rqueue.h:197
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition: aodv-rqueue.cc:91
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Definition: aodv-rqueue.h:257
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:107
Time GetQueueTimeout() const
Get queue timeout.
Definition: aodv-rqueue.h:266
void SetQueueTimeout(Time t)
Set queue timeout.
Definition: aodv-rqueue.h:275
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition: aodv-rqueue.cc:73
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:51
uint32_t GetMaxQueueLen() const
Get maximum queue length.
Definition: aodv-rqueue.h:248
Route Error (RERR) Message Format.
Definition: aodv-packet.h:591
uint8_t GetDestCount() const
Definition: aodv-packet.h:639
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:613
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:546
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
Routing table entry.
Definition: aodv-rtable.h:62
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:131
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodv-rtable.h:249
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Definition: aodv-rtable.cc:138
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:79
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodv-rtable.h:186
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodv-rtable.h:312
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:195
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodv-rtable.h:159
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodv-rtable.h:267
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodv-rtable.h:338
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:144
RouteFlags GetFlag() const
Get the route flags.
Definition: aodv-rtable.h:294
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodv-rtable.h:168
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodv-rtable.h:347
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodv-rtable.h:320
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:112
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:204
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodv-rtable.h:303
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
Definition: aodv-rtable.cc:171
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:94
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodv-rtable.h:177
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodv-rtable.h:132
uint16_t GetHop() const
Get the number of hops.
Definition: aodv-rtable.h:258
void SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodv-rtable.h:213
uint32_t GetSeqNo() const
Get the sequence number.
Definition: aodv-rtable.h:240
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodv-rtable.h:329
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodv-rtable.h:222
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodv-rtable.h:285
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-rtable.h:276
Ptr< Ipv4Route > GetRoute() const
Get route function.
Definition: aodv-rtable.h:141
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodv-rtable.h:356
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:424
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:336
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:300
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:286
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:237
void SetBadLinkLifetime(Time t)
Set the lifetime of a bad link.
Definition: aodv-rtable.h:449
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:320
Time GetBadLinkLifetime() const
Get the lifetime of a bad link.
Definition: aodv-rtable.h:439
void InvalidateRoutesWithDst(const std::map< Ipv4Address, uint32_t > &unreachable)
Update routing entries with this destination as follows:
Definition: aodv-rtable.cc:355
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:474
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:272
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:537
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:357
bool GetAckRequired() const
get the ack required flag
Definition: aodv-packet.cc:407
uint8_t GetPrefixSize() const
Set the pefix size.
Definition: aodv-packet.cc:419
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:427
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:454
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:433
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:400
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:445
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:391
void SetLifeTime(Time t)
Set the lifetime.
Definition: aodv-packet.cc:381
void SetAckRequired(bool f)
Set the ack required flag.
Definition: aodv-packet.cc:394
void SetPrefixSize(uint8_t sz)
Set the prefix size.
Definition: aodv-packet.cc:413
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-packet.cc:387
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:409
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:436
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:418
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:137
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:203
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:212
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:185
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:194
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:275
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:257
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:176
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:230
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:239
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:221
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:266
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:248
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:91
MessageType Get() const
Definition: aodv-packet.h:82
@ INVALID
INVALID.
Definition: aodv-rtable.h:53
@ IN_SEARCH
IN_SEARCH.
Definition: aodv-rtable.h:54
@ VALID
VALID.
Definition: aodv-rtable.h:52
@ AODVTYPE_RREP
AODVTYPE_RREP.
Definition: aodv-packet.h:50
@ AODVTYPE_RREQ
AODVTYPE_RREQ.
Definition: aodv-packet.h:49
#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:251
ns3::aodv::AodvTestSuite g_aodvTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
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.
void DoRun() override
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()
void DoRun() override
Implementation to actually run this TestCase.
Unit test for AODV routing table.
void DoRun() override
Implementation to actually run this TestCase.
Unit test for neighbors.
void CheckTimeout2()
Check timeout function 2.
Neighbors * neighbor
The Neighbors.
void DoRun() override
Implementation to actually run this TestCase.
void Handler(Ipv4Address addr)
Handler test function.
void CheckTimeout1()
Check timeout function 1.
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.
void DoRun() override
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.
void DoRun() override
Implementation to actually run this TestCase.
Unit test for RREP-ACK.
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Type header test case.
void DoRun() override
Implementation to actually run this TestCase.