A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Pavel Boyko <boyko@iitp.ru>
7 */
8#include "ns3/aodv-neighbor.h"
9#include "ns3/aodv-packet.h"
10#include "ns3/aodv-rqueue.h"
11#include "ns3/aodv-rtable.h"
12#include "ns3/ipv4-route.h"
13#include "ns3/test.h"
14
15namespace ns3
16{
17namespace aodv
18{
19
20/**
21 * @ingroup aodv-test
22 *
23 * @brief Unit test for neighbors
24 */
25struct NeighborTest : public TestCase
26{
28 : TestCase("Neighbor"),
29 neighbor(nullptr)
30 {
31 }
32
33 void DoRun() override;
34 /**
35 * Handler test function
36 * @param addr the IPv4 address of the neighbor
37 */
38 void Handler(Ipv4Address addr);
39 /// Check timeout function 1
40 void CheckTimeout1();
41 /// Check timeout function 2
42 void CheckTimeout2();
43 /// Check timeout function 3
44 void CheckTimeout3();
45 /// The Neighbors
47};
48
49void
53
54void
56{
57 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
58 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), true, "Neighbor exists");
59 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), true, "Neighbor exists");
60 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
61}
62
63void
65{
67 false,
68 "Neighbor doesn't exist");
70 false,
71 "Neighbor doesn't exist");
73 false,
74 "Neighbor doesn't exist");
75 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
76}
77
78void
80{
82 false,
83 "Neighbor doesn't exist");
85 false,
86 "Neighbor doesn't exist");
88 false,
89 "Neighbor doesn't exist");
91 false,
92 "Neighbor doesn't exist");
93}
94
95void
97{
99 neighbor = &nb;
101 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(1));
102 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
104 false,
105 "Neighbor doesn't exist");
106 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(10));
107 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
109 Seconds(10),
110 "Known expire time");
112 Seconds(0),
113 "Known expire time");
114 neighbor->Update(Ipv4Address("1.1.1.1"), Seconds(5));
115 neighbor->Update(Ipv4Address("2.2.2.2"), Seconds(10));
116 neighbor->Update(Ipv4Address("3.3.3.3"), Seconds(20));
117
123}
124
125/**
126 * @ingroup aodv-test
127 *
128 * @brief Type header test case
129 */
131{
133 : TestCase("AODV TypeHeader")
134 {
135 }
136
137 void DoRun() override
138 {
140 NS_TEST_EXPECT_MSG_EQ(h.IsValid(), true, "Default header is valid");
141 NS_TEST_EXPECT_MSG_EQ(h.Get(), AODVTYPE_RREQ, "Default header is RREQ");
142
144 p->AddHeader(h);
146 uint32_t bytes = p->RemoveHeader(h2);
147 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "Type header is 1 byte long");
148 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
149 }
150};
151
152/**
153 * @ingroup aodv-test
154 *
155 * @brief Unit test for RREQ
156 */
158{
160 : TestCase("AODV RREQ")
161 {
162 }
163
164 void DoRun() override
165 {
166 RreqHeader h(/*flags*/ 0,
167 /*reserved*/ 0,
168 /*hopCount*/ 6,
169 /*requestID*/ 1,
170 /*dst*/ Ipv4Address("1.2.3.4"),
171 /*dstSeqNo*/ 40,
172 /*origin*/ Ipv4Address("4.3.2.1"),
173 /*originSeqNo*/ 10);
174 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), false, "trivial");
175 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), false, "trivial");
176 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 6, "trivial");
177 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 1, "trivial");
178 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
179 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 40, "trivial");
180 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
181 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 10, "trivial");
182
183 h.SetGratuitousRrep(true);
184 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), true, "trivial");
185 h.SetDestinationOnly(true);
186 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), true, "trivial");
187 h.SetUnknownSeqno(true);
188 NS_TEST_EXPECT_MSG_EQ(h.GetUnknownSeqno(), true, "trivial");
189 h.SetDst(Ipv4Address("1.1.1.1"));
190 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
191 h.SetDstSeqno(5);
192 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 5, "trivial");
193 h.SetHopCount(7);
194 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 7, "trivial");
195 h.SetId(55);
196 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 55, "trivial");
197 h.SetOrigin(Ipv4Address("4.4.4.4"));
198 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
199 h.SetOriginSeqno(23);
200 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 23, "trivial");
201
203 p->AddHeader(h);
205 uint32_t bytes = p->RemoveHeader(h2);
206 NS_TEST_EXPECT_MSG_EQ(bytes, 23, "RREP is 23 bytes long");
207 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
208 }
209};
210
211/**
212 * @ingroup aodv-test
213 *
214 * @brief Unit test for RREP
215 */
217{
219 : TestCase("AODV RREP")
220 {
221 }
222
223 void DoRun() override
224 {
225 RrepHeader h(/*prefixSize*/ 0,
226 /*hopCount*/ 12,
227 /*dst*/ Ipv4Address("1.2.3.4"),
228 /*dstSeqNo*/ 2,
229 /*origin*/ Ipv4Address("4.3.2.1"),
230 /*lifetime*/ Seconds(3));
231 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 0, "trivial");
232 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 12, "trivial");
233 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
234 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 2, "trivial");
235 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
236 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(3), "trivial");
237 h.SetDst(Ipv4Address("1.1.1.1"));
238 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
239 h.SetDstSeqno(123);
240 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 123, "trivial");
241 h.SetOrigin(Ipv4Address("4.4.4.4"));
242 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
243 h.SetLifeTime(MilliSeconds(1200));
244 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), MilliSeconds(1200), "trivial");
245 h.SetAckRequired(true);
246 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), true, "trivial");
247 h.SetAckRequired(false);
248 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), false, "trivial");
249 h.SetPrefixSize(2);
250 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 2, "trivial");
251 h.SetHopCount(15);
252 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 15, "trivial");
253
254 h.SetHello(Ipv4Address("10.0.0.2"), 9, Seconds(15));
255 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), h.GetOrigin(), "trivial");
256 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 9, "trivial");
257 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(15), "trivial");
258
260 p->AddHeader(h);
262 uint32_t bytes = p->RemoveHeader(h2);
263 NS_TEST_EXPECT_MSG_EQ(bytes, 19, "RREP is 19 bytes long");
264 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
265 }
266};
267
268/**
269 * @ingroup aodv-test
270 *
271 * @brief Unit test for RREP-ACK
272 */
274{
276 : TestCase("AODV RREP-ACK")
277 {
278 }
279
280 void DoRun() override
281 {
284 p->AddHeader(h);
286 uint32_t bytes = p->RemoveHeader(h2);
287 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "ACK is 1 byte long");
288 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
289 }
290};
291
292/**
293 * @ingroup aodv-test
294 *
295 * @brief Unit test for RERR
296 */
298{
300 : TestCase("AODV RERR")
301 {
302 }
303
304 void DoRun() override
305 {
307 h.SetNoDelete(true);
308 NS_TEST_EXPECT_MSG_EQ(h.GetNoDelete(), true, "trivial");
309 Ipv4Address dst("1.2.3.4");
310 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 12), true, "trivial");
311 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 1, "trivial");
312 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 13), true, "trivial");
313 Ipv4Address dst2("4.3.2.1");
314 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst2, 12), true, "trivial");
315 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 2, "trivial");
316
318 p->AddHeader(h);
320 uint32_t bytes = p->RemoveHeader(h2);
321 NS_TEST_EXPECT_MSG_EQ(bytes, h.GetSerializedSize(), "(De)Serialized size match");
322 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
323 }
324};
325
326/**
327 * @ingroup aodv-test
328 *
329 * @brief Unit test for AODV routing table entry
330 */
332{
334 : TestCase("QueueEntry")
335 {
336 }
337
338 /**
339 * Unicast test function
340 * @param route the IPv4 route
341 * @param packet the packet
342 * @param header the IPv4 header
343 */
345 {
346 }
347
348 /**
349 * Error test function
350 * @param p The packet
351 * @param h The header
352 * @param e the socket error
353 */
357
358 /**
359 * Unicast 2 testfunction
360 * @param route The IPv4 route
361 * @param packet The packet
362 * @param header The header
363 */
365 {
366 }
367
368 /**
369 * Error2 test function
370 * @param p The packet
371 * @param h The header
372 * @param e the socket error
373 */
377
378 void DoRun() override
379 {
382 h.SetDestination(Ipv4Address("1.2.3.4"));
383 h.SetSource(Ipv4Address("4.3.2.1"));
387 QueueEntry entry(packet, h, ucb, ecb, Seconds(1));
388 NS_TEST_EXPECT_MSG_EQ(h.GetDestination(),
389 entry.GetIpv4Header().GetDestination(),
390 "trivial");
391 NS_TEST_EXPECT_MSG_EQ(h.GetSource(), entry.GetIpv4Header().GetSource(), "trivial");
392 NS_TEST_EXPECT_MSG_EQ(ucb.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
393 NS_TEST_EXPECT_MSG_EQ(ecb.IsEqual(entry.GetErrorCallback()), true, "trivial");
394 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(1), "trivial");
395 NS_TEST_EXPECT_MSG_EQ(entry.GetPacket(), packet, "trivial");
396 entry.SetExpireTime(Seconds(3));
397 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(3), "trivial");
399 h2.SetDestination(Ipv4Address("1.1.1.1"));
400 entry.SetIpv4Header(h2);
401 NS_TEST_EXPECT_MSG_EQ(entry.GetIpv4Header().GetDestination(),
402 Ipv4Address("1.1.1.1"),
403 "trivial");
407 entry.SetErrorCallback(ecb2);
408 NS_TEST_EXPECT_MSG_EQ(ecb2.IsEqual(entry.GetErrorCallback()), true, "trivial");
409 entry.SetUnicastForwardCallback(ucb2);
410 NS_TEST_EXPECT_MSG_EQ(ucb2.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
411 }
412};
413
414//-----------------------------------------------------------------------------
415/// Unit test for RequestQueue
417{
419 : TestCase("Rqueue"),
420 q(64, Seconds(30))
421 {
422 }
423
424 void DoRun() override;
425
426 /**
427 * Unicast test function
428 * @param route the IPv4 route
429 * @param packet the packet
430 * @param header the IPv4 header
431 */
433 {
434 }
435
436 /**
437 * Error test function
438 * @param p The packet
439 * @param h The header
440 * @param e the socket error
441 */
445
446 /// Check size limit function
447 void CheckSizeLimit();
448 /// Check timeout function
449 void CheckTimeout();
450
451 /// Request queue
453};
454
455void
457{
458 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 64, "trivial");
459 q.SetMaxQueueLen(32);
460 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 32, "trivial");
464
467 h.SetDestination(Ipv4Address("1.2.3.4"));
468 h.SetSource(Ipv4Address("4.3.2.1"));
471 QueueEntry e1(packet, h, ucb, ecb, Seconds(1));
472 q.Enqueue(e1);
473 q.Enqueue(e1);
474 q.Enqueue(e1);
475 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), true, "trivial");
476 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.1.1.1")), false, "trivial");
477 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
478 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
479 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), false, "trivial");
480 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "trivial");
481
482 h.SetDestination(Ipv4Address("2.2.2.2"));
483 QueueEntry e2(packet, h, ucb, ecb, Seconds(1));
484 q.Enqueue(e1);
485 q.Enqueue(e2);
488 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("3.3.3.3"), e3), false, "trivial");
489 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("2.2.2.2"), e3), true, "trivial");
490 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("2.2.2.2")), false, "trivial");
491 q.Enqueue(e2);
492 q.Enqueue(e3);
493 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
495 h.SetDestination(Ipv4Address("1.2.3.4"));
497 q.Enqueue(e4);
498 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 3, "trivial");
499 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
500 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
501
503
505 Ipv4Address dst2("1.2.3.4");
506 header2.SetDestination(dst2);
507
509
512}
513
514void
516{
517 Ptr<Packet> packet = Create<Packet>();
518 Ipv4Header header;
521 QueueEntry e1(packet, header, ucb, ecb, Seconds(1));
522
523 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
524 {
525 q.Enqueue(e1);
526 }
527 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
528
529 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
530 {
531 q.Enqueue(e1);
532 }
533 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
534}
535
536void
538{
539 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "Must be empty now");
540}
541
542/**
543 * @ingroup aodv-test
544 *
545 * @brief Unit test for AODV routing table entry
546 */
548{
550 : TestCase("RtableEntry")
551 {
552 }
553
554 void DoRun() override
555 {
556 Ptr<NetDevice> dev;
558 RoutingTableEntry rt(/*output device*/ dev,
559 /*dst*/ Ipv4Address("1.2.3.4"),
560 /*validSeqNo*/ true,
561 /*seqNo*/ 10,
562 /*interface*/ iface,
563 /*hop*/ 5,
564 /*next hop*/ Ipv4Address("3.3.3.3"),
565 /*lifetime*/ Seconds(10));
566 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev, "trivial");
567 NS_TEST_EXPECT_MSG_EQ(rt.GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
568 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), true, "trivial");
569 NS_TEST_EXPECT_MSG_EQ(rt.GetSeqNo(), 10, "trivial");
570 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface, "trivial");
571 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 5, "trivial");
572 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("3.3.3.3"), "trivial");
573 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(10), "trivial");
574 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), VALID, "trivial");
575 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 0, "trivial");
576 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
577
580 rt.SetOutputDevice(dev2);
581 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev2, "trivial");
582 rt.SetInterface(iface2);
583 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface2, "trivial");
584 rt.SetValidSeqNo(false);
585 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), false, "trivial");
586 rt.SetFlag(INVALID);
587 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
588 rt.SetFlag(IN_SEARCH);
589 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), IN_SEARCH, "trivial");
590 rt.SetHop(12);
591 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 12, "trivial");
592 rt.SetLifeTime(Seconds(1));
593 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(1), "trivial");
594 rt.SetNextHop(Ipv4Address("1.1.1.1"));
595 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("1.1.1.1"), "trivial");
596 rt.SetUnidirectional(true);
597 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
598 rt.SetBlacklistTimeout(Seconds(7));
599 NS_TEST_EXPECT_MSG_EQ(rt.GetBlacklistTimeout(), Seconds(7), "trivial");
600 rt.SetRreqCnt(2);
601 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 2, "trivial");
602 rt.IncrementRreqCnt();
603 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 3, "trivial");
604 rt.Invalidate(Seconds(13));
605 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
606 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(13), "trivial");
607 rt.SetLifeTime(MilliSeconds(100));
608 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), MilliSeconds(100), "trivial");
609 Ptr<Ipv4Route> route = rt.GetRoute();
610 NS_TEST_EXPECT_MSG_EQ(route->GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
611
612 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
613 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), false, "trivial");
614 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
615 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
616 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.3")), false, "trivial");
617 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
618 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
619 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
620 std::vector<Ipv4Address> prec;
621 rt.GetPrecursors(prec);
622 NS_TEST_EXPECT_MSG_EQ(prec.size(), 1, "trivial");
623 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.4")), true, "trivial");
624 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.5")), false, "trivial");
625 rt.GetPrecursors(prec);
626 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
627 rt.DeleteAllPrecursors();
628 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
629 rt.GetPrecursors(prec);
630 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
632 }
633};
634
635/**
636 * @ingroup aodv-test
637 *
638 * @brief Unit test for AODV routing table
639 */
641{
643 : TestCase("Rtable")
644 {
645 }
646
647 void DoRun() override
648 {
650 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(2), "trivial");
651 rtable.SetBadLinkLifetime(Seconds(1));
652 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(1), "trivial");
653 Ptr<NetDevice> dev;
655 RoutingTableEntry rt(/*output device*/ dev,
656 /*dst*/ Ipv4Address("1.2.3.4"),
657 /*validSeqNo*/ true,
658 /*seqNo*/ 10,
659 /*interface*/ iface,
660 /*hop*/ 5,
661 /*next hop*/ Ipv4Address("1.1.1.1"),
662 /*lifetime*/ Seconds(10));
663 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), true, "trivial");
664 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), false, "trivial");
665 RoutingTableEntry rt2(/*output device*/ dev,
666 /*dst*/ Ipv4Address("4.3.2.1"),
667 /*validSeqNo*/ false,
668 /*seqNo*/ 0,
669 /*interface*/ iface,
670 /*hop*/ 15,
671 /*next hop*/ Ipv4Address("1.1.1.1"),
672 /*lifetime*/ Seconds(1));
673 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt2), true, "trivial");
674 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(rt2.GetDestination(), rt), true, "trivial");
675 NS_TEST_EXPECT_MSG_EQ(rt2.GetDestination(), rt.GetDestination(), "trivial");
676 rt.SetHop(20);
677 rt.InsertPrecursor(Ipv4Address("10.0.0.3"));
678 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
680 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("10.0.0.1"), rt), false, "trivial");
681 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt3), false, "trivial");
682 NS_TEST_EXPECT_MSG_EQ(rtable.SetEntryState(Ipv4Address("10.0.0.1"), INVALID),
683 false,
684 "trivial");
685 NS_TEST_EXPECT_MSG_EQ(rtable.SetEntryState(Ipv4Address("1.2.3.4"), IN_SEARCH),
686 true,
687 "trivial");
688 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("5.5.5.5")), false, "trivial");
689 RoutingTableEntry rt4(/*output device*/ dev,
690 /*dst*/ Ipv4Address("5.5.5.5"),
691 /*validSeqNo*/ false,
692 /*seqNo*/ 0,
693 /*interface*/ iface,
694 /*hop*/ 15,
695 /*next hop*/ Ipv4Address("1.1.1.1"),
696 /*lifetime*/ Seconds(-10));
697 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt4), true, "trivial");
698 NS_TEST_EXPECT_MSG_EQ(rtable.SetEntryState(Ipv4Address("5.5.5.5"), INVALID),
699 true,
700 "trivial");
701 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false, "trivial");
702 NS_TEST_EXPECT_MSG_EQ(rtable.MarkLinkAsUnidirectional(Ipv4Address("1.2.3.4"), Seconds(2)),
703 true,
704 "trivial");
705 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("1.2.3.4"), rt), true, "trivial");
706 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
707 rt.SetLifeTime(Seconds(-5));
708 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
709 std::map<Ipv4Address, uint32_t> unreachable;
710 rtable.GetListOfDestinationWithNextHop(Ipv4Address("1.1.1.1"), unreachable);
711 NS_TEST_EXPECT_MSG_EQ(unreachable.size(), 2, "trivial");
712 unreachable.insert(std::make_pair(Ipv4Address("4.3.2.1"), 3));
713 rtable.InvalidateRoutesWithDst(unreachable);
714 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("4.3.2.1"), rt), true, "trivial");
715 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
716 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), true, "trivial");
717 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), false, "trivial");
719 }
720};
721
722/**
723 * @ingroup aodv-test
724 *
725 * @brief AODV test suite
726 */
745
746} // namespace aodv
747} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
a class to store IPv4 address information on an interface
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
maintain list of active neighbors
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:34
AODV route request queue.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Time GetQueueTimeout() const
Get queue timeout.
void SetQueueTimeout(Time t)
Set queue timeout.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
Route Error (RERR) Message Format.
void SetNoDelete(bool f)
Set the no delete flag.
Routing table entry.
Definition aodv-rtable.h:51
The Routing table used by AODV protocol.
Route Reply Acknowledgment (RREP-ACK) Message Format.
Route Reply (RREP) Message Format.
Route Request (RREQ) Message Format.
ns3::aodv::AodvTestSuite g_aodvTestSuite
the test suite
@ INVALID
INVALID.
Definition aodv-rtable.h:42
@ IN_SEARCH
IN_SEARCH.
Definition aodv-rtable.h:43
@ VALID
VALID.
Definition aodv-rtable.h:41
@ AODVTYPE_RREP
AODVTYPE_RREP.
Definition aodv-packet.h:39
@ AODVTYPE_RREQ
AODVTYPE_RREQ.
Definition aodv-packet.h:38
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
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:684
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.