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{
98 Neighbors nb(Seconds(1));
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);
204 RreqHeader h2;
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);
261 RrepHeader h2;
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);
285 RrepAckHeader h2;
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 {
306 RerrHeader h;
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);
319 RerrHeader h2;
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 */
344 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
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 */
355 {
356 }
357
358 /**
359 * Unicast 2 testfunction
360 * @param route The IPv4 route
361 * @param packet The packet
362 * @param header The header
363 */
364 void Unicast2(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
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 */
375 {
376 }
377
378 void DoRun() override
379 {
381 Ipv4Header h;
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));
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");
398 Ipv4Header h2;
399 h2.SetDestination(Ipv4Address("1.1.1.1"));
400 entry.SetIpv4Header(h2);
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 */
432 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
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 */
443 {
444 }
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
466 Ipv4Header h;
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);
486 Ptr<Packet> packet2 = Create<Packet>();
487 QueueEntry e3(packet2, h, ucb, ecb, Seconds(1));
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");
494 Ptr<Packet> packet4 = Create<Packet>();
495 h.SetDestination(Ipv4Address("1.2.3.4"));
496 QueueEntry e4(packet4, h, ucb, ecb, Seconds(20));
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
504 Ipv4Header header2;
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
578 Ptr<NetDevice> dev2;
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");
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");
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 {
649 RoutingTable rtable(Seconds(2));
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");
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");
683 false,
684 "trivial");
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");
699 true,
700 "trivial");
701 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false, "trivial");
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
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition callback.h:583
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
Ipv4Address GetSource() const
Ipv4Address GetDestination() const
void SetSource(Ipv4Address source)
a class to store IPv4 address information on an interface
Smart pointer class similar to boost::intrusive_ptr.
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
Time GetExpireTime() const
Get expire time.
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
ErrorCallback GetErrorCallback() const
Get error callback.
Definition aodv-rqueue.h:98
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition aodv-rqueue.h:89
void SetExpireTime(Time exp)
Set expire time.
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Ptr< const Packet > GetPacket() const
Get packet from entry.
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition aodv-rqueue.h:80
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
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.
uint8_t GetDestCount() const
bool GetNoDelete() const
Get the no delete flag.
uint32_t GetSerializedSize() const override
void SetNoDelete(bool f)
Set the no delete flag.
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Routing table entry.
Definition aodv-rtable.h:51
void DeleteAllPrecursors()
Delete all precursors.
void SetHop(uint16_t hop)
Set the number of hops.
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Ptr< NetDevice > GetOutputDevice() const
Get output device.
uint8_t GetRreqCnt() const
Get the RREQ count.
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
void SetLifeTime(Time lt)
Set the lifetime.
bool IsUnidirectional() const
Get the unidirectional flag.
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
RouteFlags GetFlag() const
Get the route flags.
Ipv4Address GetNextHop() const
Get next hop address.
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
void IncrementRreqCnt()
Increment the RREQ count.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
void SetRreqCnt(uint8_t n)
Set the RREQ count.
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Ipv4Address GetDestination() const
Get destination address function.
uint16_t GetHop() const
Get the number of hops.
void SetValidSeqNo(bool s)
Set the valid sequence number.
uint32_t GetSeqNo() const
Get the sequence number.
void SetUnidirectional(bool u)
Set the unidirectional flag.
bool GetValidSeqNo() const
Get the valid sequence number.
void SetFlag(RouteFlags flag)
Set the route flags.
Time GetLifeTime() const
Get the lifetime.
Ptr< Ipv4Route > GetRoute() const
Get route function.
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
The Routing table used by AODV protocol.
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
bool Update(RoutingTableEntry &rt)
Update routing table.
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
void SetBadLinkLifetime(Time t)
Set the lifetime of a bad link.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Time GetBadLinkLifetime() const
Get the lifetime of a bad link.
void InvalidateRoutesWithDst(const std::map< Ipv4Address, uint32_t > &unreachable)
Update routing entries with this destination as follows:
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Route Reply Acknowledgment (RREP-ACK) Message Format.
Route Reply (RREP) Message Format.
bool GetAckRequired() const
get the ack required flag
uint8_t GetPrefixSize() const
Set the prefix size.
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Ipv4Address GetOrigin() const
Get the origin address.
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
uint8_t GetHopCount() const
Get the hop count.
void SetOrigin(Ipv4Address a)
Set the origin address.
void SetHopCount(uint8_t count)
Set the hop count.
void SetLifeTime(Time t)
Set the lifetime.
void SetAckRequired(bool f)
Set the ack required flag.
void SetPrefixSize(uint8_t sz)
Set the prefix size.
Time GetLifeTime() const
Get the lifetime.
void SetDst(Ipv4Address a)
Set the destination address.
uint32_t GetDstSeqno() const
Get the destination sequence number.
Ipv4Address GetDst() const
Get the destination address.
Route Request (RREQ) Message Format.
uint32_t GetId() const
Get the request ID.
void SetDst(Ipv4Address a)
Set the destination address.
uint8_t GetHopCount() const
Get the hop count.
bool GetUnknownSeqno() const
Get the unknown sequence number flag.
void SetId(uint32_t id)
Set the request ID.
uint32_t GetOriginSeqno() const
Get the origin sequence number.
void SetUnknownSeqno(bool f)
Set the unknown sequence number flag.
Ipv4Address GetOrigin() const
Get the origin address.
void SetGratuitousRrep(bool f)
Set the gratuitous RREP flag.
void SetDestinationOnly(bool f)
Set the Destination only flag.
bool GetDestinationOnly() const
Get the Destination only flag.
void SetHopCount(uint8_t count)
Set the hop count.
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
uint32_t GetDstSeqno() const
Get the destination sequence number.
Ipv4Address GetDst() const
Get the destination address.
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
void SetOrigin(Ipv4Address a)
Set the origin address.
bool IsValid() const
Check that type if valid.
Definition aodv-packet.h:80
MessageType Get() const
Definition aodv-packet.h:71
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.