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-routing-protocol.h"
11#include "ns3/aodv-rqueue.h"
12#include "ns3/aodv-rtable.h"
13#include "ns3/ipv4-route.h"
14#include "ns3/node.h"
15#include "ns3/simulator.h"
16#include "ns3/test.h"
17
18namespace ns3
19{
20namespace aodv
21{
22
23/**
24 * @ingroup aodv-test
25 *
26 * @brief Unit test for neighbors
27 */
28struct NeighborTest : public TestCase
29{
31 : TestCase("Neighbor"),
32 neighbor(nullptr)
33 {
34 }
35
36 void DoRun() override;
37 /**
38 * Handler test function
39 * @param addr the IPv4 address of the neighbor
40 */
41 void Handler(Ipv4Address addr);
42 /// Check timeout function 1
43 void CheckTimeout1();
44 /// Check timeout function 2
45 void CheckTimeout2();
46 /// Check timeout function 3
47 void CheckTimeout3();
48 /// The Neighbors
50};
51
52void
56
57void
59{
60 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
61 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), true, "Neighbor exists");
62 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), true, "Neighbor exists");
63 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
64}
65
66void
68{
69 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")),
70 false,
71 "Neighbor doesn't exist");
72 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")),
73 false,
74 "Neighbor doesn't exist");
75 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")),
76 false,
77 "Neighbor doesn't exist");
78 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
79}
80
81void
83{
84 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")),
85 false,
86 "Neighbor doesn't exist");
87 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")),
88 false,
89 "Neighbor doesn't exist");
90 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")),
91 false,
92 "Neighbor doesn't exist");
93 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")),
94 false,
95 "Neighbor doesn't exist");
96}
97
98void
100{
101 Neighbors nb(Seconds(1));
102 neighbor = &nb;
103 neighbor->SetCallback(MakeCallback(&NeighborTest::Handler, this));
104 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(1));
105 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
106 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("4.3.2.1")),
107 false,
108 "Neighbor doesn't exist");
109 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(10));
110 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
111 NS_TEST_EXPECT_MSG_EQ(neighbor->GetExpireTime(Ipv4Address("1.2.3.4")),
112 Seconds(10),
113 "Known expire time");
114 NS_TEST_EXPECT_MSG_EQ(neighbor->GetExpireTime(Ipv4Address("4.3.2.1")),
115 Seconds(0),
116 "Known expire time");
117 neighbor->Update(Ipv4Address("1.1.1.1"), Seconds(5));
118 neighbor->Update(Ipv4Address("2.2.2.2"), Seconds(10));
119 neighbor->Update(Ipv4Address("3.3.3.3"), Seconds(20));
120
126}
127
128/**
129 * @ingroup aodv-test
130 *
131 * @brief Type header test case
132 */
134{
136 : TestCase("AODV TypeHeader")
137 {
138 }
139
140 void DoRun() override
141 {
143 NS_TEST_EXPECT_MSG_EQ(h.IsValid(), true, "Default header is valid");
144 NS_TEST_EXPECT_MSG_EQ(h.Get(), AODVTYPE_RREQ, "Default header is RREQ");
145
147 p->AddHeader(h);
149 uint32_t bytes = p->RemoveHeader(h2);
150 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "Type header is 1 byte long");
151 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
152 }
153};
154
155/**
156 * @ingroup aodv-test
157 *
158 * @brief Unit test for RREQ
159 */
161{
163 : TestCase("AODV RREQ")
164 {
165 }
166
167 void DoRun() override
168 {
169 RreqHeader h(/*flags*/ 0,
170 /*reserved*/ 0,
171 /*hopCount*/ 6,
172 /*requestID*/ 1,
173 /*dst*/ Ipv4Address("1.2.3.4"),
174 /*dstSeqNo*/ 40,
175 /*origin*/ Ipv4Address("4.3.2.1"),
176 /*originSeqNo*/ 10);
177 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), false, "trivial");
178 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), false, "trivial");
179 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 6, "trivial");
180 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 1, "trivial");
181 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
182 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 40, "trivial");
183 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
184 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 10, "trivial");
185
186 h.SetGratuitousRrep(true);
187 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), true, "trivial");
188 h.SetDestinationOnly(true);
189 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), true, "trivial");
190 h.SetUnknownSeqno(true);
191 NS_TEST_EXPECT_MSG_EQ(h.GetUnknownSeqno(), true, "trivial");
192 h.SetDst(Ipv4Address("1.1.1.1"));
193 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
194 h.SetDstSeqno(5);
195 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 5, "trivial");
196 h.SetHopCount(7);
197 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 7, "trivial");
198 h.SetId(55);
199 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 55, "trivial");
200 h.SetOrigin(Ipv4Address("4.4.4.4"));
201 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
202 h.SetOriginSeqno(23);
203 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 23, "trivial");
204
206 p->AddHeader(h);
207 RreqHeader h2;
208 uint32_t bytes = p->RemoveHeader(h2);
209 NS_TEST_EXPECT_MSG_EQ(bytes, 23, "RREP is 23 bytes long");
210 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
211 }
212};
213
214/**
215 * @ingroup aodv-test
216 *
217 * @brief Unit test for RREP
218 */
220{
222 : TestCase("AODV RREP")
223 {
224 }
225
226 void DoRun() override
227 {
228 RrepHeader h(/*prefixSize*/ 0,
229 /*hopCount*/ 12,
230 /*dst*/ Ipv4Address("1.2.3.4"),
231 /*dstSeqNo*/ 2,
232 /*origin*/ Ipv4Address("4.3.2.1"),
233 /*lifetime*/ Seconds(3));
234 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 0, "trivial");
235 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 12, "trivial");
236 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
237 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 2, "trivial");
238 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
239 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(3), "trivial");
240 h.SetDst(Ipv4Address("1.1.1.1"));
241 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
242 h.SetDstSeqno(123);
243 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 123, "trivial");
244 h.SetOrigin(Ipv4Address("4.4.4.4"));
245 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
246 h.SetLifeTime(MilliSeconds(1200));
247 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), MilliSeconds(1200), "trivial");
248 h.SetAckRequired(true);
249 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), true, "trivial");
250 h.SetAckRequired(false);
251 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), false, "trivial");
252 h.SetPrefixSize(2);
253 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 2, "trivial");
254 h.SetHopCount(15);
255 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 15, "trivial");
256
257 h.SetHello(Ipv4Address("10.0.0.2"), 9, Seconds(15));
258 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), h.GetOrigin(), "trivial");
259 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 9, "trivial");
260 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(15), "trivial");
261
263 p->AddHeader(h);
264 RrepHeader h2;
265 uint32_t bytes = p->RemoveHeader(h2);
266 NS_TEST_EXPECT_MSG_EQ(bytes, 19, "RREP is 19 bytes long");
267 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
268 }
269};
270
271/**
272 * @ingroup aodv-test
273 *
274 * @brief Unit test for RREP-ACK
275 */
277{
279 : TestCase("AODV RREP-ACK")
280 {
281 }
282
283 void DoRun() override
284 {
287 p->AddHeader(h);
288 RrepAckHeader h2;
289 uint32_t bytes = p->RemoveHeader(h2);
290 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "ACK is 1 byte long");
291 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
292 }
293};
294
295/**
296 * @ingroup aodv-test
297 *
298 * @brief Unit test for RERR
299 */
301{
303 : TestCase("AODV RERR")
304 {
305 }
306
307 void DoRun() override
308 {
309 RerrHeader h;
310 h.SetNoDelete(true);
311 NS_TEST_EXPECT_MSG_EQ(h.GetNoDelete(), true, "trivial");
312 Ipv4Address dst("1.2.3.4");
313 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 12), true, "trivial");
314 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 1, "trivial");
315 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 13), true, "trivial");
316 Ipv4Address dst2("4.3.2.1");
317 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst2, 12), true, "trivial");
318 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 2, "trivial");
319
321 p->AddHeader(h);
322 RerrHeader h2;
323 uint32_t bytes = p->RemoveHeader(h2);
324 NS_TEST_EXPECT_MSG_EQ(bytes, h.GetSerializedSize(), "(De)Serialized size match");
325 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
326 }
327};
328
329/**
330 * @ingroup aodv-test
331 *
332 * @brief Unit test for AODV routing table entry
333 */
335{
337 : TestCase("QueueEntry")
338 {
339 }
340
341 /**
342 * Unicast test function
343 * @param route the IPv4 route
344 * @param packet the packet
345 * @param header the IPv4 header
346 */
347 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
348 {
349 }
350
351 /**
352 * Error test function
353 * @param p The packet
354 * @param h The header
355 * @param e the socket error
356 */
358 {
359 }
360
361 /**
362 * Unicast 2 testfunction
363 * @param route The IPv4 route
364 * @param packet The packet
365 * @param header The header
366 */
367 void Unicast2(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
368 {
369 }
370
371 /**
372 * Error2 test function
373 * @param p The packet
374 * @param h The header
375 * @param e the socket error
376 */
378 {
379 }
380
381 void DoRun() override
382 {
384 Ipv4Header h;
385 h.SetDestination(Ipv4Address("1.2.3.4"));
386 h.SetSource(Ipv4Address("4.3.2.1"));
390 QueueEntry entry(packet, h, ucb, ecb, Seconds(1));
393 "trivial");
394 NS_TEST_EXPECT_MSG_EQ(h.GetSource(), entry.GetIpv4Header().GetSource(), "trivial");
395 NS_TEST_EXPECT_MSG_EQ(ucb.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
396 NS_TEST_EXPECT_MSG_EQ(ecb.IsEqual(entry.GetErrorCallback()), true, "trivial");
397 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(1), "trivial");
398 NS_TEST_EXPECT_MSG_EQ(entry.GetPacket(), packet, "trivial");
399 entry.SetExpireTime(Seconds(3));
400 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(3), "trivial");
401 Ipv4Header h2;
402 h2.SetDestination(Ipv4Address("1.1.1.1"));
403 entry.SetIpv4Header(h2);
405 Ipv4Address("1.1.1.1"),
406 "trivial");
410 entry.SetErrorCallback(ecb2);
411 NS_TEST_EXPECT_MSG_EQ(ecb2.IsEqual(entry.GetErrorCallback()), true, "trivial");
412 entry.SetUnicastForwardCallback(ucb2);
413 NS_TEST_EXPECT_MSG_EQ(ucb2.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
414 }
415};
416
417//-----------------------------------------------------------------------------
418/// Unit test for RequestQueue
420{
422 : TestCase("Rqueue"),
423 q(64, Seconds(30))
424 {
425 }
426
427 void DoRun() override;
428
429 /**
430 * Unicast test function
431 * @param route the IPv4 route
432 * @param packet the packet
433 * @param header the IPv4 header
434 */
435 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
436 {
437 }
438
439 /**
440 * Error test function
441 * @param p The packet
442 * @param h The header
443 * @param e the socket error
444 */
446 {
447 }
448
449 /// Check size limit function
450 void CheckSizeLimit();
451 /// Check timeout function
452 void CheckTimeout();
453
454 /// Request queue
456};
457
458void
460{
461 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 64, "trivial");
462 q.SetMaxQueueLen(32);
463 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 32, "trivial");
464 NS_TEST_EXPECT_MSG_EQ(q.GetQueueTimeout(), Seconds(30), "trivial");
465 q.SetQueueTimeout(Seconds(10));
466 NS_TEST_EXPECT_MSG_EQ(q.GetQueueTimeout(), Seconds(10), "trivial");
467
469 Ipv4Header h;
470 h.SetDestination(Ipv4Address("1.2.3.4"));
471 h.SetSource(Ipv4Address("4.3.2.1"));
474 QueueEntry e1(packet, h, ucb, ecb, Seconds(1));
475 q.Enqueue(e1);
476 q.Enqueue(e1);
477 q.Enqueue(e1);
478 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), true, "trivial");
479 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.1.1.1")), false, "trivial");
480 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
481 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
482 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), false, "trivial");
483 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "trivial");
484
485 h.SetDestination(Ipv4Address("2.2.2.2"));
486 QueueEntry e2(packet, h, ucb, ecb, Seconds(1));
487 q.Enqueue(e1);
488 q.Enqueue(e2);
489 Ptr<Packet> packet2 = Create<Packet>();
490 QueueEntry e3(packet2, h, ucb, ecb, Seconds(1));
491 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("3.3.3.3"), e3), false, "trivial");
492 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("2.2.2.2"), e3), true, "trivial");
493 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("2.2.2.2")), false, "trivial");
494 q.Enqueue(e2);
495 q.Enqueue(e3);
496 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
497 Ptr<Packet> packet4 = Create<Packet>();
498 h.SetDestination(Ipv4Address("1.2.3.4"));
499 QueueEntry e4(packet4, h, ucb, ecb, Seconds(20));
500 q.Enqueue(e4);
501 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 3, "trivial");
502 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
503 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
504
506
507 Ipv4Header header2;
508 Ipv4Address dst2("1.2.3.4");
509 header2.SetDestination(dst2);
510
511 Simulator::Schedule(q.GetQueueTimeout() + Seconds(1), &AodvRqueueTest::CheckTimeout, this);
512
515}
516
517void
519{
520 Ptr<Packet> packet = Create<Packet>();
521 Ipv4Header header;
524 QueueEntry e1(packet, header, ucb, ecb, Seconds(1));
525
526 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
527 {
528 q.Enqueue(e1);
529 }
530 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
531
532 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
533 {
534 q.Enqueue(e1);
535 }
536 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
537}
538
539void
541{
542 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "Must be empty now");
543}
544
545/**
546 * @ingroup aodv-test
547 *
548 * @brief Unit test for AODV routing table entry
549 */
551{
553 : TestCase("RtableEntry")
554 {
555 }
556
557 void DoRun() override
558 {
559 Ptr<NetDevice> dev;
561 RoutingTableEntry rt(/*output device*/ dev,
562 /*dst*/ Ipv4Address("1.2.3.4"),
563 /*validSeqNo*/ true,
564 /*seqNo*/ 10,
565 /*interface*/ iface,
566 /*hop*/ 5,
567 /*next hop*/ Ipv4Address("3.3.3.3"),
568 /*lifetime*/ Seconds(10));
569 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev, "trivial");
570 NS_TEST_EXPECT_MSG_EQ(rt.GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
571 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), true, "trivial");
572 NS_TEST_EXPECT_MSG_EQ(rt.GetSeqNo(), 10, "trivial");
573 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface, "trivial");
574 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 5, "trivial");
575 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("3.3.3.3"), "trivial");
576 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(10), "trivial");
577 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), VALID, "trivial");
578 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 0, "trivial");
579 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
580
581 Ptr<NetDevice> dev2;
583 rt.SetOutputDevice(dev2);
584 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev2, "trivial");
585 rt.SetInterface(iface2);
586 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface2, "trivial");
587 rt.SetValidSeqNo(false);
588 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), false, "trivial");
589 rt.SetFlag(INVALID);
590 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
591 rt.SetFlag(IN_SEARCH);
592 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), IN_SEARCH, "trivial");
593 rt.SetHop(12);
594 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 12, "trivial");
595 rt.SetLifeTime(Seconds(1));
596 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(1), "trivial");
597 rt.SetNextHop(Ipv4Address("1.1.1.1"));
598 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("1.1.1.1"), "trivial");
599 rt.SetUnidirectional(true);
600 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
603 rt.SetRreqCnt(2);
604 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 2, "trivial");
605 rt.IncrementRreqCnt();
606 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 3, "trivial");
607 rt.Invalidate(Seconds(13));
608 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
609 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(13), "trivial");
610 rt.SetLifeTime(MilliSeconds(100));
611 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), MilliSeconds(100), "trivial");
612 Ptr<Ipv4Route> route = rt.GetRoute();
613 NS_TEST_EXPECT_MSG_EQ(route->GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
614
615 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
616 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), false, "trivial");
617 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
618 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
619 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.3")), false, "trivial");
620 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
621 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
622 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
623 std::vector<Ipv4Address> prec;
624 rt.GetPrecursors(prec);
625 NS_TEST_EXPECT_MSG_EQ(prec.size(), 1, "trivial");
626 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.4")), true, "trivial");
627 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.5")), false, "trivial");
628 rt.GetPrecursors(prec);
629 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
631 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
632 rt.GetPrecursors(prec);
633 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
635 }
636};
637
638/**
639 * @ingroup aodv-test
640 *
641 * @brief Unit test for AODV routing table
642 */
644{
646 : TestCase("Rtable")
647 {
648 }
649
650 void DoRun() override
651 {
652 RoutingTable rtable(Seconds(2));
653 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(2), "trivial");
654 rtable.SetBadLinkLifetime(Seconds(1));
655 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(1), "trivial");
656 Ptr<NetDevice> dev;
658 RoutingTableEntry rt(/*output device*/ dev,
659 /*dst*/ Ipv4Address("1.2.3.4"),
660 /*validSeqNo*/ true,
661 /*seqNo*/ 10,
662 /*interface*/ iface,
663 /*hop*/ 5,
664 /*next hop*/ Ipv4Address("1.1.1.1"),
665 /*lifetime*/ Seconds(10));
666 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), true, "trivial");
667 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), false, "trivial");
668 RoutingTableEntry rt2(/*output device*/ dev,
669 /*dst*/ Ipv4Address("4.3.2.1"),
670 /*validSeqNo*/ false,
671 /*seqNo*/ 0,
672 /*interface*/ iface,
673 /*hop*/ 15,
674 /*next hop*/ Ipv4Address("1.1.1.1"),
675 /*lifetime*/ Seconds(1));
676 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt2), true, "trivial");
677 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(rt2.GetDestination(), rt), true, "trivial");
679 rt.SetHop(20);
680 rt.InsertPrecursor(Ipv4Address("10.0.0.3"));
681 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
683 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("10.0.0.1"), rt), false, "trivial");
684 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt3), false, "trivial");
686 false,
687 "trivial");
689 true,
690 "trivial");
691 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("5.5.5.5")), false, "trivial");
692 RoutingTableEntry rt4(/*output device*/ dev,
693 /*dst*/ Ipv4Address("5.5.5.5"),
694 /*validSeqNo*/ false,
695 /*seqNo*/ 0,
696 /*interface*/ iface,
697 /*hop*/ 15,
698 /*next hop*/ Ipv4Address("1.1.1.1"),
699 /*lifetime*/ Seconds(-10));
700 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt4), true, "trivial");
702 true,
703 "trivial");
704 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false, "trivial");
706 true,
707 "trivial");
708 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("1.2.3.4"), rt), true, "trivial");
709 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
710 rt.SetLifeTime(Seconds(-5));
711 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
712 std::map<Ipv4Address, uint32_t> unreachable;
713 rtable.GetListOfDestinationWithNextHop(Ipv4Address("1.1.1.1"), unreachable);
714 NS_TEST_EXPECT_MSG_EQ(unreachable.size(), 2, "trivial");
715 unreachable.insert(std::make_pair(Ipv4Address("4.3.2.1"), 3));
716 rtable.InvalidateRoutesWithDst(unreachable);
717 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("4.3.2.1"), rt), true, "trivial");
718 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
719 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), true, "trivial");
720 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), false, "trivial");
722 }
723};
724
725/**
726 * @ingroup aodv-test
727 * @brief Test case for AODV parameter validation guardrails and defaults.
728 */
730{
731 public:
733 : TestCase("AODV Parameter Validation Check")
734 {
735 }
736
738 {
739 }
740
741 private:
742 void DoRun() override
743 {
744 // Test B: Default Configuration -> Must Initialize Safely Without Aborts
747 nodeB->AggregateObject(aodvB);
748
749 // A standard default configuration must execute safely without triggering aborts
750 nodeB->Initialize();
751
753 }
754};
755
756/**
757 * @ingroup aodv-test
758 *
759 * @brief AODV test suite
760 */
780
781} // namespace aodv
782} // namespace ns3
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition callback.h:589
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
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Test case for AODV parameter validation guardrails and defaults.
void DoRun() override
Implementation to actually run this TestCase.
maintain list of active neighbors
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.
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
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:690
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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.