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 * 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
31/**
32 * \ingroup aodv-test
33 *
34 * \brief Unit test for neighbors
35 */
36struct NeighborTest : public TestCase
37{
39 : TestCase("Neighbor"),
40 neighbor(nullptr)
41 {
42 }
43
44 void DoRun() override;
45 /**
46 * Handler test function
47 * \param addr the IPv4 address of the neighbor
48 */
49 void Handler(Ipv4Address addr);
50 /// Check timeout function 1
51 void CheckTimeout1();
52 /// Check timeout function 2
53 void CheckTimeout2();
54 /// Check timeout function 3
55 void CheckTimeout3();
56 /// The Neighbors
58};
59
60void
62{
63}
64
65void
67{
68 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
69 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), true, "Neighbor exists");
70 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), true, "Neighbor exists");
71 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
72}
73
74void
76{
78 false,
79 "Neighbor doesn't exist");
81 false,
82 "Neighbor doesn't exist");
84 false,
85 "Neighbor doesn't exist");
86 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true, "Neighbor exists");
87}
88
89void
91{
93 false,
94 "Neighbor doesn't exist");
96 false,
97 "Neighbor doesn't exist");
99 false,
100 "Neighbor doesn't exist");
102 false,
103 "Neighbor doesn't exist");
104}
105
106void
108{
109 Neighbors nb(Seconds(1));
110 neighbor = &nb;
112 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(1));
113 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
115 false,
116 "Neighbor doesn't exist");
117 neighbor->Update(Ipv4Address("1.2.3.4"), Seconds(10));
118 NS_TEST_EXPECT_MSG_EQ(neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true, "Neighbor exists");
120 Seconds(10),
121 "Known expire time");
123 Seconds(0),
124 "Known expire time");
125 neighbor->Update(Ipv4Address("1.1.1.1"), Seconds(5));
126 neighbor->Update(Ipv4Address("2.2.2.2"), Seconds(10));
127 neighbor->Update(Ipv4Address("3.3.3.3"), Seconds(20));
128
134}
135
136/**
137 * \ingroup aodv-test
138 *
139 * \brief Type header test case
140 */
142{
144 : TestCase("AODV TypeHeader")
145 {
146 }
147
148 void DoRun() override
149 {
151 NS_TEST_EXPECT_MSG_EQ(h.IsValid(), true, "Default header is valid");
152 NS_TEST_EXPECT_MSG_EQ(h.Get(), AODVTYPE_RREQ, "Default header is RREQ");
153
154 Ptr<Packet> p = Create<Packet>();
155 p->AddHeader(h);
157 uint32_t bytes = p->RemoveHeader(h2);
158 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "Type header is 1 byte long");
159 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
160 }
161};
162
163/**
164 * \ingroup aodv-test
165 *
166 * \brief Unit test for RREQ
167 */
169{
171 : TestCase("AODV RREQ")
172 {
173 }
174
175 void DoRun() override
176 {
177 RreqHeader h(/*flags*/ 0,
178 /*reserved*/ 0,
179 /*hopCount*/ 6,
180 /*requestID*/ 1,
181 /*dst*/ Ipv4Address("1.2.3.4"),
182 /*dstSeqNo*/ 40,
183 /*origin*/ Ipv4Address("4.3.2.1"),
184 /*originSeqNo*/ 10);
185 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), false, "trivial");
186 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), false, "trivial");
187 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 6, "trivial");
188 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 1, "trivial");
189 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
190 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 40, "trivial");
191 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
192 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 10, "trivial");
193
194 h.SetGratuitousRrep(true);
195 NS_TEST_EXPECT_MSG_EQ(h.GetGratuitousRrep(), true, "trivial");
196 h.SetDestinationOnly(true);
197 NS_TEST_EXPECT_MSG_EQ(h.GetDestinationOnly(), true, "trivial");
198 h.SetUnknownSeqno(true);
199 NS_TEST_EXPECT_MSG_EQ(h.GetUnknownSeqno(), true, "trivial");
200 h.SetDst(Ipv4Address("1.1.1.1"));
201 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
202 h.SetDstSeqno(5);
203 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 5, "trivial");
204 h.SetHopCount(7);
205 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 7, "trivial");
206 h.SetId(55);
207 NS_TEST_EXPECT_MSG_EQ(h.GetId(), 55, "trivial");
208 h.SetOrigin(Ipv4Address("4.4.4.4"));
209 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
210 h.SetOriginSeqno(23);
211 NS_TEST_EXPECT_MSG_EQ(h.GetOriginSeqno(), 23, "trivial");
212
213 Ptr<Packet> p = Create<Packet>();
214 p->AddHeader(h);
215 RreqHeader h2;
216 uint32_t bytes = p->RemoveHeader(h2);
217 NS_TEST_EXPECT_MSG_EQ(bytes, 23, "RREP is 23 bytes long");
218 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
219 }
220};
221
222/**
223 * \ingroup aodv-test
224 *
225 * \brief Unit test for RREP
226 */
228{
230 : TestCase("AODV RREP")
231 {
232 }
233
234 void DoRun() override
235 {
236 RrepHeader h(/*prefixSize*/ 0,
237 /*hopCount*/ 12,
238 /*dst*/ Ipv4Address("1.2.3.4"),
239 /*dstSeqNo*/ 2,
240 /*origin*/ Ipv4Address("4.3.2.1"),
241 /*lifetime*/ Seconds(3));
242 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 0, "trivial");
243 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 12, "trivial");
244 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.2.3.4"), "trivial");
245 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 2, "trivial");
246 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.3.2.1"), "trivial");
247 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(3), "trivial");
248 h.SetDst(Ipv4Address("1.1.1.1"));
249 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), Ipv4Address("1.1.1.1"), "trivial");
250 h.SetDstSeqno(123);
251 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 123, "trivial");
252 h.SetOrigin(Ipv4Address("4.4.4.4"));
253 NS_TEST_EXPECT_MSG_EQ(h.GetOrigin(), Ipv4Address("4.4.4.4"), "trivial");
254 h.SetLifeTime(MilliSeconds(1200));
255 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), MilliSeconds(1200), "trivial");
256 h.SetAckRequired(true);
257 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), true, "trivial");
258 h.SetAckRequired(false);
259 NS_TEST_EXPECT_MSG_EQ(h.GetAckRequired(), false, "trivial");
260 h.SetPrefixSize(2);
261 NS_TEST_EXPECT_MSG_EQ(h.GetPrefixSize(), 2, "trivial");
262 h.SetHopCount(15);
263 NS_TEST_EXPECT_MSG_EQ(h.GetHopCount(), 15, "trivial");
264
265 h.SetHello(Ipv4Address("10.0.0.2"), 9, Seconds(15));
266 NS_TEST_EXPECT_MSG_EQ(h.GetDst(), h.GetOrigin(), "trivial");
267 NS_TEST_EXPECT_MSG_EQ(h.GetDstSeqno(), 9, "trivial");
268 NS_TEST_EXPECT_MSG_EQ(h.GetLifeTime(), Seconds(15), "trivial");
269
270 Ptr<Packet> p = Create<Packet>();
271 p->AddHeader(h);
272 RrepHeader h2;
273 uint32_t bytes = p->RemoveHeader(h2);
274 NS_TEST_EXPECT_MSG_EQ(bytes, 19, "RREP is 19 bytes long");
275 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
276 }
277};
278
279/**
280 * \ingroup aodv-test
281 *
282 * \brief Unit test for RREP-ACK
283 */
285{
287 : TestCase("AODV RREP-ACK")
288 {
289 }
290
291 void DoRun() override
292 {
294 Ptr<Packet> p = Create<Packet>();
295 p->AddHeader(h);
296 RrepAckHeader h2;
297 uint32_t bytes = p->RemoveHeader(h2);
298 NS_TEST_EXPECT_MSG_EQ(bytes, 1, "ACK is 1 byte long");
299 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
300 }
301};
302
303/**
304 * \ingroup aodv-test
305 *
306 * \brief Unit test for RERR
307 */
309{
311 : TestCase("AODV RERR")
312 {
313 }
314
315 void DoRun() override
316 {
317 RerrHeader h;
318 h.SetNoDelete(true);
319 NS_TEST_EXPECT_MSG_EQ(h.GetNoDelete(), true, "trivial");
320 Ipv4Address dst("1.2.3.4");
321 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 12), true, "trivial");
322 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 1, "trivial");
323 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst, 13), true, "trivial");
324 Ipv4Address dst2("4.3.2.1");
325 NS_TEST_EXPECT_MSG_EQ(h.AddUnDestination(dst2, 12), true, "trivial");
326 NS_TEST_EXPECT_MSG_EQ(h.GetDestCount(), 2, "trivial");
327
328 Ptr<Packet> p = Create<Packet>();
329 p->AddHeader(h);
330 RerrHeader h2;
331 uint32_t bytes = p->RemoveHeader(h2);
332 NS_TEST_EXPECT_MSG_EQ(bytes, h.GetSerializedSize(), "(De)Serialized size match");
333 NS_TEST_EXPECT_MSG_EQ(h, h2, "Round trip serialization works");
334 }
335};
336
337/**
338 * \ingroup aodv-test
339 *
340 * \brief Unit test for AODV routing table entry
341 */
343{
345 : TestCase("QueueEntry")
346 {
347 }
348
349 /**
350 * Unicast test function
351 * \param route the IPv4 route
352 * \param packet the packet
353 * \param header the IPv4 header
354 */
355 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
356 {
357 }
358
359 /**
360 * Error test function
361 * \param p The packet
362 * \param h The header
363 * \param e the socket error
364 */
366 {
367 }
368
369 /**
370 * Unicast 2 testfunction
371 * \param route The IPv4 route
372 * \param packet The packet
373 * \param header The header
374 */
375 void Unicast2(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
376 {
377 }
378
379 /**
380 * Error2 test function
381 * \param p The packet
382 * \param h The header
383 * \param e the socket error
384 */
386 {
387 }
388
389 void DoRun() override
390 {
391 Ptr<const Packet> packet = Create<Packet>();
392 Ipv4Header h;
393 h.SetDestination(Ipv4Address("1.2.3.4"));
394 h.SetSource(Ipv4Address("4.3.2.1"));
398 QueueEntry entry(packet, h, ucb, ecb, Seconds(1));
401 "trivial");
402 NS_TEST_EXPECT_MSG_EQ(h.GetSource(), entry.GetIpv4Header().GetSource(), "trivial");
403 NS_TEST_EXPECT_MSG_EQ(ucb.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
404 NS_TEST_EXPECT_MSG_EQ(ecb.IsEqual(entry.GetErrorCallback()), true, "trivial");
405 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(1), "trivial");
406 NS_TEST_EXPECT_MSG_EQ(entry.GetPacket(), packet, "trivial");
407 entry.SetExpireTime(Seconds(3));
408 NS_TEST_EXPECT_MSG_EQ(entry.GetExpireTime(), Seconds(3), "trivial");
409 Ipv4Header h2;
410 h2.SetDestination(Ipv4Address("1.1.1.1"));
411 entry.SetIpv4Header(h2);
413 Ipv4Address("1.1.1.1"),
414 "trivial");
418 entry.SetErrorCallback(ecb2);
419 NS_TEST_EXPECT_MSG_EQ(ecb2.IsEqual(entry.GetErrorCallback()), true, "trivial");
420 entry.SetUnicastForwardCallback(ucb2);
421 NS_TEST_EXPECT_MSG_EQ(ucb2.IsEqual(entry.GetUnicastForwardCallback()), true, "trivial");
422 }
423};
424
425//-----------------------------------------------------------------------------
426/// Unit test for RequestQueue
428{
430 : TestCase("Rqueue"),
431 q(64, Seconds(30))
432 {
433 }
434
435 void DoRun() override;
436
437 /**
438 * Unicast test function
439 * \param route the IPv4 route
440 * \param packet the packet
441 * \param header the IPv4 header
442 */
443 void Unicast(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header)
444 {
445 }
446
447 /**
448 * Error test function
449 * \param p The packet
450 * \param h The header
451 * \param e the socket error
452 */
454 {
455 }
456
457 /// Check size limit function
458 void CheckSizeLimit();
459 /// Check timeout function
460 void CheckTimeout();
461
462 /// Request queue
464};
465
466void
468{
469 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 64, "trivial");
470 q.SetMaxQueueLen(32);
471 NS_TEST_EXPECT_MSG_EQ(q.GetMaxQueueLen(), 32, "trivial");
475
476 Ptr<const Packet> packet = Create<Packet>();
477 Ipv4Header h;
478 h.SetDestination(Ipv4Address("1.2.3.4"));
479 h.SetSource(Ipv4Address("4.3.2.1"));
482 QueueEntry e1(packet, h, ucb, ecb, Seconds(1));
483 q.Enqueue(e1);
484 q.Enqueue(e1);
485 q.Enqueue(e1);
486 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), true, "trivial");
487 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.1.1.1")), false, "trivial");
488 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
489 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
490 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("1.2.3.4")), false, "trivial");
491 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "trivial");
492
493 h.SetDestination(Ipv4Address("2.2.2.2"));
494 QueueEntry e2(packet, h, ucb, ecb, Seconds(1));
495 q.Enqueue(e1);
496 q.Enqueue(e2);
497 Ptr<Packet> packet2 = Create<Packet>();
498 QueueEntry e3(packet2, h, ucb, ecb, Seconds(1));
499 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("3.3.3.3"), e3), false, "trivial");
500 NS_TEST_EXPECT_MSG_EQ(q.Dequeue(Ipv4Address("2.2.2.2"), e3), true, "trivial");
501 NS_TEST_EXPECT_MSG_EQ(q.Find(Ipv4Address("2.2.2.2")), false, "trivial");
502 q.Enqueue(e2);
503 q.Enqueue(e3);
504 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
505 Ptr<Packet> packet4 = Create<Packet>();
506 h.SetDestination(Ipv4Address("1.2.3.4"));
507 QueueEntry e4(packet4, h, ucb, ecb, Seconds(20));
508 q.Enqueue(e4);
509 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 3, "trivial");
510 q.DropPacketWithDst(Ipv4Address("1.2.3.4"));
511 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 1, "trivial");
512
514
515 Ipv4Header header2;
516 Ipv4Address dst2("1.2.3.4");
517 header2.SetDestination(dst2);
518
520
523}
524
525void
527{
528 Ptr<Packet> packet = Create<Packet>();
529 Ipv4Header header;
532 QueueEntry e1(packet, header, ucb, ecb, Seconds(1));
533
534 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
535 {
536 q.Enqueue(e1);
537 }
538 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
539
540 for (uint32_t i = 0; i < q.GetMaxQueueLen(); ++i)
541 {
542 q.Enqueue(e1);
543 }
544 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 2, "trivial");
545}
546
547void
549{
550 NS_TEST_EXPECT_MSG_EQ(q.GetSize(), 0, "Must be empty now");
551}
552
553/**
554 * \ingroup aodv-test
555 *
556 * \brief Unit test for AODV routing table entry
557 */
559{
561 : TestCase("RtableEntry")
562 {
563 }
564
565 void DoRun() override
566 {
567 Ptr<NetDevice> dev;
569 RoutingTableEntry rt(/*output device*/ dev,
570 /*dst*/ Ipv4Address("1.2.3.4"),
571 /*validSeqNo*/ true,
572 /*seqNo*/ 10,
573 /*interface*/ iface,
574 /*hop*/ 5,
575 /*next hop*/ Ipv4Address("3.3.3.3"),
576 /*lifetime*/ Seconds(10));
577 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev, "trivial");
578 NS_TEST_EXPECT_MSG_EQ(rt.GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
579 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), true, "trivial");
580 NS_TEST_EXPECT_MSG_EQ(rt.GetSeqNo(), 10, "trivial");
581 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface, "trivial");
582 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 5, "trivial");
583 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("3.3.3.3"), "trivial");
584 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(10), "trivial");
585 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), VALID, "trivial");
586 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 0, "trivial");
587 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
588
589 Ptr<NetDevice> dev2;
591 rt.SetOutputDevice(dev2);
592 NS_TEST_EXPECT_MSG_EQ(rt.GetOutputDevice(), dev2, "trivial");
593 rt.SetInterface(iface2);
594 NS_TEST_EXPECT_MSG_EQ(rt.GetInterface(), iface2, "trivial");
595 rt.SetValidSeqNo(false);
596 NS_TEST_EXPECT_MSG_EQ(rt.GetValidSeqNo(), false, "trivial");
597 rt.SetFlag(INVALID);
598 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
599 rt.SetFlag(IN_SEARCH);
600 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), IN_SEARCH, "trivial");
601 rt.SetHop(12);
602 NS_TEST_EXPECT_MSG_EQ(rt.GetHop(), 12, "trivial");
603 rt.SetLifeTime(Seconds(1));
604 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(1), "trivial");
605 rt.SetNextHop(Ipv4Address("1.1.1.1"));
606 NS_TEST_EXPECT_MSG_EQ(rt.GetNextHop(), Ipv4Address("1.1.1.1"), "trivial");
607 rt.SetUnidirectional(true);
608 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
611 rt.SetRreqCnt(2);
612 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 2, "trivial");
613 rt.IncrementRreqCnt();
614 NS_TEST_EXPECT_MSG_EQ(rt.GetRreqCnt(), 3, "trivial");
615 rt.Invalidate(Seconds(13));
616 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
617 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), Seconds(13), "trivial");
618 rt.SetLifeTime(MilliSeconds(100));
619 NS_TEST_EXPECT_MSG_EQ(rt.GetLifeTime(), MilliSeconds(100), "trivial");
620 Ptr<Ipv4Route> route = rt.GetRoute();
621 NS_TEST_EXPECT_MSG_EQ(route->GetDestination(), Ipv4Address("1.2.3.4"), "trivial");
622
623 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
624 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), false, "trivial");
625 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
626 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
627 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.3")), false, "trivial");
628 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.1")), true, "trivial");
629 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.2")), true, "trivial");
630 NS_TEST_EXPECT_MSG_EQ(rt.LookupPrecursor(Ipv4Address("10.0.0.2")), false, "trivial");
631 std::vector<Ipv4Address> prec;
632 rt.GetPrecursors(prec);
633 NS_TEST_EXPECT_MSG_EQ(prec.size(), 1, "trivial");
634 NS_TEST_EXPECT_MSG_EQ(rt.InsertPrecursor(Ipv4Address("10.0.0.4")), true, "trivial");
635 NS_TEST_EXPECT_MSG_EQ(rt.DeletePrecursor(Ipv4Address("10.0.0.5")), false, "trivial");
636 rt.GetPrecursors(prec);
637 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
639 NS_TEST_EXPECT_MSG_EQ(rt.IsPrecursorListEmpty(), true, "trivial");
640 rt.GetPrecursors(prec);
641 NS_TEST_EXPECT_MSG_EQ(prec.size(), 2, "trivial");
643 }
644};
645
646/**
647 * \ingroup aodv-test
648 *
649 * \brief Unit test for AODV routing table
650 */
652{
654 : TestCase("Rtable")
655 {
656 }
657
658 void DoRun() override
659 {
660 RoutingTable rtable(Seconds(2));
661 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(2), "trivial");
662 rtable.SetBadLinkLifetime(Seconds(1));
663 NS_TEST_EXPECT_MSG_EQ(rtable.GetBadLinkLifetime(), Seconds(1), "trivial");
664 Ptr<NetDevice> dev;
666 RoutingTableEntry rt(/*output device*/ dev,
667 /*dst*/ Ipv4Address("1.2.3.4"),
668 /*validSeqNo*/ true,
669 /*seqNo*/ 10,
670 /*interface*/ iface,
671 /*hop*/ 5,
672 /*next hop*/ Ipv4Address("1.1.1.1"),
673 /*lifetime*/ Seconds(10));
674 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), true, "trivial");
675 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt), false, "trivial");
676 RoutingTableEntry rt2(/*output device*/ dev,
677 /*dst*/ Ipv4Address("4.3.2.1"),
678 /*validSeqNo*/ false,
679 /*seqNo*/ 0,
680 /*interface*/ iface,
681 /*hop*/ 15,
682 /*next hop*/ Ipv4Address("1.1.1.1"),
683 /*lifetime*/ Seconds(1));
684 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt2), true, "trivial");
685 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(rt2.GetDestination(), rt), true, "trivial");
687 rt.SetHop(20);
688 rt.InsertPrecursor(Ipv4Address("10.0.0.3"));
689 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
691 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("10.0.0.1"), rt), false, "trivial");
692 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt3), false, "trivial");
694 false,
695 "trivial");
697 true,
698 "trivial");
699 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("5.5.5.5")), false, "trivial");
700 RoutingTableEntry rt4(/*output device*/ dev,
701 /*dst*/ Ipv4Address("5.5.5.5"),
702 /*validSeqNo*/ false,
703 /*seqNo*/ 0,
704 /*interface*/ iface,
705 /*hop*/ 15,
706 /*next hop*/ Ipv4Address("1.1.1.1"),
707 /*lifetime*/ Seconds(-10));
708 NS_TEST_EXPECT_MSG_EQ(rtable.AddRoute(rt4), true, "trivial");
710 true,
711 "trivial");
712 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("5.5.5.5"), rt), false, "trivial");
714 true,
715 "trivial");
716 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("1.2.3.4"), rt), true, "trivial");
717 NS_TEST_EXPECT_MSG_EQ(rt.IsUnidirectional(), true, "trivial");
718 rt.SetLifeTime(Seconds(-5));
719 NS_TEST_EXPECT_MSG_EQ(rtable.Update(rt), true, "trivial");
720 std::map<Ipv4Address, uint32_t> unreachable;
721 rtable.GetListOfDestinationWithNextHop(Ipv4Address("1.1.1.1"), unreachable);
722 NS_TEST_EXPECT_MSG_EQ(unreachable.size(), 2, "trivial");
723 unreachable.insert(std::make_pair(Ipv4Address("4.3.2.1"), 3));
724 rtable.InvalidateRoutesWithDst(unreachable);
725 NS_TEST_EXPECT_MSG_EQ(rtable.LookupRoute(Ipv4Address("4.3.2.1"), rt), true, "trivial");
726 NS_TEST_EXPECT_MSG_EQ(rt.GetFlag(), INVALID, "trivial");
727 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), true, "trivial");
728 NS_TEST_EXPECT_MSG_EQ(rtable.DeleteRoute(Ipv4Address("1.2.3.4")), false, "trivial");
730 }
731};
732
733/**
734 * \ingroup aodv-test
735 *
736 * \brief AODV test suite
737 */
739{
740 public:
742 : TestSuite("routing-aodv", Type::UNIT)
743 {
754 }
755} g_aodvTestSuite; ///< the test suite
756
757} // namespace aodv
758} // namespace ns3
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:597
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
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:592
uint8_t GetDestCount() const
Definition: aodv-packet.h:640
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:611
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:546
void SetNoDelete(bool f)
Set the no delete flag.
Definition: aodv-packet.cc:598
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Definition: aodv-packet.cc:617
Routing table entry.
Definition: aodv-rtable.h:62
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:128
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:135
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:141
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:110
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:167
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:330
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:295
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:282
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:233
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:314
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:347
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:460
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:268
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:538
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:358
bool GetAckRequired() const
get the ack required flag
Definition: aodv-packet.cc:407
uint8_t GetPrefixSize() const
Set the prefix size.
Definition: aodv-packet.cc:419
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:428
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:455
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:401
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:446
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:392
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:410
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:437
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:419
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:138
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:204
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:213
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:186
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:195
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:276
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:258
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:177
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:231
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:240
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:222
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:267
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:249
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:91
MessageType Get() const
Definition: aodv-packet.h:82
ns3::aodv::AodvTestSuite g_aodvTestSuite
the test suite
@ 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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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:704
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.