21 #include "ns3/aodv-neighbor.h"
22 #include "ns3/aodv-packet.h"
23 #include "ns3/aodv-rqueue.h"
24 #include "ns3/aodv-rtable.h"
25 #include "ns3/ipv4-route.h"
36 virtual void DoRun ();
38 void CheckTimeout1 ();
39 void CheckTimeout2 ();
40 void CheckTimeout3 ();
50 NeighborTest::CheckTimeout1 ()
58 NeighborTest::CheckTimeout2 ()
60 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"1.2.3.4")),
false,
"Neighbor doesn't exist");
61 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"1.1.1.1")),
false,
"Neighbor doesn't exist");
62 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"2.2.2.2")),
false,
"Neighbor doesn't exist");
63 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"3.3.3.3")),
true,
"Neighbor exists");
66 NeighborTest::CheckTimeout3 ()
68 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"1.2.3.4")),
false,
"Neighbor doesn't exist");
69 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"1.1.1.1")),
false,
"Neighbor doesn't exist");
70 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"2.2.2.2")),
false,
"Neighbor doesn't exist");
71 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (Ipv4Address (
"3.3.3.3")),
false,
"Neighbor doesn't exist");
79 neighbor->SetCallback (
MakeCallback (&NeighborTest::Handler,
this));
82 NS_TEST_EXPECT_MSG_EQ (neighbor->
IsNeighbor (
Ipv4Address (
"4.3.2.1")),
false,
"Neighbor doesn't exist");
106 NS_TEST_EXPECT_MSG_EQ (h.
IsValid (),
true,
"Default header is valid");
107 NS_TEST_EXPECT_MSG_EQ (h.
Get (), AODVTYPE_RREQ,
"Default header is RREQ");
112 uint32_t bytes = p->RemoveHeader (h2);
113 NS_TEST_EXPECT_MSG_EQ (bytes, 1,
"Type header is 1 byte long");
114 NS_TEST_EXPECT_MSG_EQ (h, h2,
"Round trip serialization works");
128 NS_TEST_EXPECT_MSG_EQ (h.GetGratiousRrep (),
false,
"trivial");
129 NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (),
false,
"trivial");
130 NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 6,
"trivial");
131 NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1,
"trivial");
132 NS_TEST_EXPECT_MSG_EQ (h.GetDst (),
Ipv4Address (
"1.2.3.4"),
"trivial");
133 NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 40,
"trivial");
134 NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (),
Ipv4Address (
"4.3.2.1"),
"trivial");
135 NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 10,
"trivial");
137 h.SetGratiousRrep (
true);
138 NS_TEST_EXPECT_MSG_EQ (h.GetGratiousRrep (),
true,
"trivial");
139 h.SetDestinationOnly (
true);
140 NS_TEST_EXPECT_MSG_EQ (h.GetDestinationOnly (),
true,
"trivial");
141 h.SetUnknownSeqno (
true);
142 NS_TEST_EXPECT_MSG_EQ (h.GetUnknownSeqno (),
true,
"trivial");
144 NS_TEST_EXPECT_MSG_EQ (h.GetDst (),
Ipv4Address (
"1.1.1.1"),
"trivial");
146 NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 5,
"trivial");
148 NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 7,
"trivial");
150 NS_TEST_EXPECT_MSG_EQ (h.GetId (), 55,
"trivial");
152 NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (),
Ipv4Address (
"4.4.4.4"),
"trivial");
153 h.SetOriginSeqno (23);
154 NS_TEST_EXPECT_MSG_EQ (h.GetOriginSeqno (), 23,
"trivial");
159 uint32_t bytes = p->RemoveHeader (h2);
160 NS_TEST_EXPECT_MSG_EQ (bytes, 23,
"RREP is 23 bytes long");
161 NS_TEST_EXPECT_MSG_EQ (h, h2,
"Round trip serialization works");
174 NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 0,
"trivial");
175 NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 12,
"trivial");
176 NS_TEST_EXPECT_MSG_EQ (h.GetDst (),
Ipv4Address (
"1.2.3.4"),
"trivial");
177 NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 2,
"trivial");
178 NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (),
Ipv4Address (
"4.3.2.1"),
"trivial");
179 NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (),
Seconds (3),
"trivial");
181 NS_TEST_EXPECT_MSG_EQ (h.GetDst (),
Ipv4Address (
"1.1.1.1"),
"trivial");
183 NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 123,
"trivial");
185 NS_TEST_EXPECT_MSG_EQ (h.GetOrigin (),
Ipv4Address (
"4.4.4.4"),
"trivial");
187 NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (),
MilliSeconds (1200),
"trivial");
188 h.SetAckRequired (
true);
189 NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (),
true,
"trivial");
190 h.SetAckRequired (
false);
191 NS_TEST_EXPECT_MSG_EQ (h.GetAckRequired (),
false,
"trivial");
193 NS_TEST_EXPECT_MSG_EQ (h.GetPrefixSize (), 2,
"trivial");
195 NS_TEST_EXPECT_MSG_EQ (h.GetHopCount (), 15,
"trivial");
198 NS_TEST_EXPECT_MSG_EQ (h.GetDst (), h.GetOrigin (),
"trivial");
199 NS_TEST_EXPECT_MSG_EQ (h.GetDstSeqno (), 9,
"trivial");
200 NS_TEST_EXPECT_MSG_EQ (h.GetLifeTime (),
Seconds (15),
"trivial");
205 uint32_t bytes = p->RemoveHeader (h2);
206 NS_TEST_EXPECT_MSG_EQ (bytes, 19,
"RREP is 19 bytes long");
207 NS_TEST_EXPECT_MSG_EQ (h, h2,
"Round trip serialization works");
224 NS_TEST_EXPECT_MSG_EQ (bytes, 1,
"ACK is 1 byte long");
225 NS_TEST_EXPECT_MSG_EQ (h, h2,
"Round trip serialization works");
238 h.SetNoDelete (
true);
239 NS_TEST_EXPECT_MSG_EQ (h.GetNoDelete (),
true,
"trivial");
242 NS_TEST_EXPECT_MSG_EQ (h.
GetDestCount (), 1,
"trivial");
246 NS_TEST_EXPECT_MSG_EQ (h.
GetDestCount (), 2,
"trivial");
251 uint32_t bytes = p->RemoveHeader (h2);
252 NS_TEST_EXPECT_MSG_EQ (bytes, h.
GetSerializedSize (),
"(De)Serialized size match");
253 NS_TEST_EXPECT_MSG_EQ (h, h2,
"Round trip serialization works");
274 NS_TEST_EXPECT_MSG_EQ (h.GetDestination (), entry.GetIpv4Header ().
GetDestination (),
"trivial");
275 NS_TEST_EXPECT_MSG_EQ (h.GetSource (), entry.GetIpv4Header ().
GetSource (),
"trivial");
276 NS_TEST_EXPECT_MSG_EQ (ucb.IsEqual (entry.GetUnicastForwardCallback ()),
true,
"trivial");
277 NS_TEST_EXPECT_MSG_EQ (ecb.IsEqual (entry.GetErrorCallback ()),
true,
"trivial");
278 NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (),
Seconds (1),
"trivial");
279 NS_TEST_EXPECT_MSG_EQ (entry.GetPacket (), packet,
"trivial");
280 entry.SetExpireTime (
Seconds (3));
281 NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (),
Seconds (3),
"trivial");
284 entry.SetIpv4Header (h2);
288 entry.SetErrorCallback (ecb2);
289 NS_TEST_EXPECT_MSG_EQ (ecb2.IsEqual (entry.GetErrorCallback ()),
true,
"trivial");
290 entry.SetUnicastForwardCallback (ucb2);
291 NS_TEST_EXPECT_MSG_EQ (ucb2.IsEqual (entry.GetUnicastForwardCallback ()),
true,
"trivial");
299 virtual void DoRun ();
302 void CheckSizeLimit ();
303 void CheckTimeout ();
311 NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 64,
"trivial");
312 q.SetMaxQueueLen (32);
313 NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32,
"trivial");
314 NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (),
Seconds (30),
"trivial");
315 q.SetQueueTimeout (
Seconds (10));
316 NS_TEST_EXPECT_MSG_EQ (q.GetQueueTimeout (),
Seconds (10),
"trivial");
328 NS_TEST_EXPECT_MSG_EQ (q.
Find (
Ipv4Address (
"1.2.3.4")),
true,
"trivial");
329 NS_TEST_EXPECT_MSG_EQ (q.
Find (
Ipv4Address (
"1.1.1.1")),
false,
"trivial");
330 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 1,
"trivial");
332 NS_TEST_EXPECT_MSG_EQ (q.
Find (
Ipv4Address (
"1.2.3.4")),
false,
"trivial");
333 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 0,
"trivial");
343 NS_TEST_EXPECT_MSG_EQ (q.
Find (
Ipv4Address (
"2.2.2.2")),
false,
"trivial");
346 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 2,
"trivial");
351 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 3,
"trivial");
353 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 1,
"trivial");
368 AodvRqueueTest::CheckSizeLimit ()
376 for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
378 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 2,
"trivial");
380 for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
382 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 2,
"trivial");
386 AodvRqueueTest::CheckTimeout ()
388 NS_TEST_EXPECT_MSG_EQ (q.
GetSize (), 0,
"Must be empty now");
401 NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev,
"trivial");
402 NS_TEST_EXPECT_MSG_EQ (rt.GetDestination (),
Ipv4Address (
"1.2.3.4"),
"trivial");
403 NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (),
true,
"trivial");
404 NS_TEST_EXPECT_MSG_EQ (rt.GetSeqNo (), 10,
"trivial");
405 NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface,
"trivial");
406 NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 5,
"trivial");
407 NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (),
Ipv4Address (
"3.3.3.3"),
"trivial");
408 NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (),
Seconds (10),
"trivial");
409 NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (),
VALID,
"trivial");
410 NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 0,
"trivial");
415 rt.SetOutputDevice (dev2);
416 NS_TEST_EXPECT_MSG_EQ (rt.GetOutputDevice (), dev2,
"trivial");
417 rt.SetInterface (iface2);
418 NS_TEST_EXPECT_MSG_EQ (rt.GetInterface (), iface2,
"trivial");
419 rt.SetValidSeqNo (
false);
420 NS_TEST_EXPECT_MSG_EQ (rt.GetValidSeqNo (),
false,
"trivial");
422 NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (),
INVALID,
"trivial");
424 NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (),
IN_SEARCH,
"trivial");
426 NS_TEST_EXPECT_MSG_EQ (rt.GetHop (), 12,
"trivial");
428 NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (),
Seconds (1),
"trivial");
430 NS_TEST_EXPECT_MSG_EQ (rt.GetNextHop (),
Ipv4Address (
"1.1.1.1"),
"trivial");
431 rt.SetUnidirectional (
true);
432 NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (),
true,
"trivial");
433 rt.SetBalcklistTimeout (
Seconds (7));
434 NS_TEST_EXPECT_MSG_EQ (rt.GetBlacklistTimeout (),
Seconds (7),
"trivial");
436 NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 2,
"trivial");
437 rt.IncrementRreqCnt ();
438 NS_TEST_EXPECT_MSG_EQ (rt.GetRreqCnt (), 3,
"trivial");
440 NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (),
INVALID,
"trivial");
441 NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (),
Seconds (13),
"trivial");
443 NS_TEST_EXPECT_MSG_EQ (rt.GetLifeTime (),
MilliSeconds (100),
"trivial");
445 NS_TEST_EXPECT_MSG_EQ (route->GetDestination (),
Ipv4Address (
"1.2.3.4"),
"trivial");
455 std::vector<Ipv4Address> prec;
457 NS_TEST_EXPECT_MSG_EQ (prec.size (), 1,
"trivial");
461 NS_TEST_EXPECT_MSG_EQ (prec.size (), 2,
"trivial");
465 NS_TEST_EXPECT_MSG_EQ (prec.size (), 2,
"trivial");
477 NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (),
Seconds (2),
"trivial");
478 rtable.SetBadLinkLifetime (
Seconds (1));
479 NS_TEST_EXPECT_MSG_EQ (rtable.GetBadLinkLifetime (),
Seconds (1),
"trivial");
484 NS_TEST_EXPECT_MSG_EQ (rtable.
AddRoute (rt),
true,
"trivial");
485 NS_TEST_EXPECT_MSG_EQ (rtable.
AddRoute (rt),
false,
"trivial");
488 NS_TEST_EXPECT_MSG_EQ (rtable.
AddRoute (rt2),
true,
"trivial");
489 NS_TEST_EXPECT_MSG_EQ (rtable.
LookupRoute (rt2.GetDestination (), rt),
true,
"trivial");
490 NS_TEST_EXPECT_MSG_EQ (rt2.GetDestination (), rt.GetDestination (),
"trivial");
493 NS_TEST_EXPECT_MSG_EQ (rtable.
Update (rt),
true,
"trivial");
496 NS_TEST_EXPECT_MSG_EQ (rtable.
Update (rt3),
false,
"trivial");
502 NS_TEST_EXPECT_MSG_EQ (rtable.
AddRoute (rt4),
true,
"trivial");
507 NS_TEST_EXPECT_MSG_EQ (rt.IsUnidirectional (),
true,
"trivial");
509 NS_TEST_EXPECT_MSG_EQ (rtable.
Update (rt),
true,
"trivial");
510 std::map<Ipv4Address, uint32_t> unreachable;
512 NS_TEST_EXPECT_MSG_EQ (unreachable.size (), 2,
"trivial");
513 unreachable.insert (std::make_pair (
Ipv4Address (
"4.3.2.1"), 3));
516 NS_TEST_EXPECT_MSG_EQ (rt.GetFlag (),
INVALID,
"trivial");
uint32_t RemoveHeader(Header &header)
maintain list of active neighbors
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Unit test for AODV routing table entry.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
AODV route request queue.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
virtual void DoRun()
Implementation to actually run this test case.
bool Update(RoutingTableEntry &rt)
Update routing table.
void GetPrecursors(std::vector< Ipv4Address > &prec) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void DoRun()
Implementation to actually run this test case.
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
Unit test for RequestQueue.
bool InsertPrecursor(Ipv4Address id)
bool IsPrecursorListEmpty() const
virtual void DoRun()
Implementation to actually run this test case.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
bool LookupPrecursor(Ipv4Address id)
virtual void DoRun()
Implementation to actually run this test case.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
bool IsNeighbor(Ipv4Address addr)
Check that node with address addr is neighbor.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
TestCase(std::string name)
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
void DeleteAllPrecursors()
Delete all precursors.
static void Destroy(void)
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
Unit test for AODV routing table.
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
uint32_t GetSize()
Number of entries.
void Update(Ipv4Address addr, Time expire)
Update expire time for entry with address addr, if it exists, else add new entry. ...
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
The Routing table used by AODV protocol.
Time GetExpireTime(Ipv4Address addr)
Return expire time for neighbor node with address addr, if exists, else return 0. ...
Ipv4 addresses are stored in host order in this class.
virtual void DoRun()
Implementation to actually run this test case.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
a class to store IPv4 address information on an interface
bool AddRoute(RoutingTableEntry &r)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Unit test for AODV routing table entry.
bool DeleteRoute(Ipv4Address dst)
void AddHeader(const Header &header)