34 #include "ns3/boolean.h"
36 #include "ns3/ipv4-route.h"
37 #include "ns3/mesh-helper.h"
38 #include "ns3/simulator.h"
39 #include "ns3/double.h"
40 #include "ns3/uinteger.h"
41 #include "ns3/string.h"
42 #include "ns3/ipv4-address-helper.h"
44 #include "ns3/dsr-fs-header.h"
45 #include "ns3/dsr-option-header.h"
46 #include "ns3/dsr-rreq-table.h"
47 #include "ns3/dsr-rcache.h"
48 #include "ns3/dsr-rsendbuff.h"
49 #include "ns3/dsr-main-helper.h"
50 #include "ns3/dsr-helper.h"
65 DsrFsHeaderTest::DsrFsHeaderTest ()
69 DsrFsHeaderTest::~DsrFsHeaderTest ()
79 NS_TEST_EXPECT_MSG_EQ (header.
GetSerializedSize () % 2, 0,
"length of routing header is not a multiple of 4");
84 const uint8_t* data = buf.PeekData ();
85 NS_TEST_EXPECT_MSG_EQ (*(data + 8), rreqHeader.
GetType (),
"expect the rreqHeader after fixed size header");
97 DsrRreqHeaderTest::DsrRreqHeaderTest ()
101 DsrRreqHeaderTest::~DsrRreqHeaderTest ()
108 std::vector<Ipv4Address> nodeList;
120 NS_TEST_EXPECT_MSG_EQ (h.
GetId (), 1,
"trivial");
125 p->AddHeader (header);
126 p->RemoveAtStart (8);
129 uint32_t bytes = p->RemoveHeader (h2);
130 NS_TEST_EXPECT_MSG_EQ (bytes, 20,
"Total RREP is 20 bytes long");
142 DsrRrepHeaderTest::DsrRrepHeaderTest ()
146 DsrRrepHeaderTest::~DsrRrepHeaderTest ()
154 std::vector<Ipv4Address> nodeList;
166 p->AddHeader (header);
167 p->RemoveAtStart (8);
170 uint32_t bytes = p->RemoveHeader (h2);
171 NS_TEST_EXPECT_MSG_EQ (bytes, 16,
"Total RREP is 16 bytes long");
183 DsrSRHeaderTest::DsrSRHeaderTest ()
187 DsrSRHeaderTest::~DsrSRHeaderTest ()
194 std::vector<Ipv4Address> nodeList;
204 NS_TEST_EXPECT_MSG_EQ (h.GetSalvage (), 1,
"trivial");
205 h.SetSegmentsLeft (2);
206 NS_TEST_EXPECT_MSG_EQ (h.GetSegmentsLeft (), 2,
"trivial");
211 p->AddHeader (header);
212 p->RemoveAtStart (8);
215 uint32_t bytes = p->RemoveHeader (h2);
216 NS_TEST_EXPECT_MSG_EQ (bytes, 16,
"Total RREP is 16 bytes long");
228 DsrRerrHeaderTest::DsrRerrHeaderTest ()
232 DsrRerrHeaderTest::~DsrRerrHeaderTest ()
244 NS_TEST_EXPECT_MSG_EQ (h.
GetSalvage (), 1,
"trivial");
251 p->AddHeader (header);
252 p->RemoveAtStart (8);
254 uint32_t bytes = p->RemoveHeader (h2);
255 NS_TEST_EXPECT_MSG_EQ (bytes, 20,
"Total RREP is 20 bytes long");
267 DsrAckReqHeaderTest::DsrAckReqHeaderTest ()
271 DsrAckReqHeaderTest::~DsrAckReqHeaderTest ()
280 NS_TEST_EXPECT_MSG_EQ (h.
GetAckId (), 1,
"trivial");
285 p->AddHeader (header);
286 p->RemoveAtStart (8);
287 p->AddHeader (header);
289 p->RemoveAtStart (8);
290 uint32_t bytes = p->RemoveHeader (h2);
291 NS_TEST_EXPECT_MSG_EQ (bytes, 4,
"Total RREP is 4 bytes long");
303 DsrAckHeaderTest::DsrAckHeaderTest ()
307 DsrAckHeaderTest::~DsrAckHeaderTest ()
320 NS_TEST_EXPECT_MSG_EQ (h.
GetAckId (), 1,
"trivial");
325 p->AddHeader (header);
326 p->RemoveAtStart (8);
327 p->AddHeader (header);
329 p->RemoveAtStart (8);
330 uint32_t bytes = p->RemoveHeader (h2);
331 NS_TEST_EXPECT_MSG_EQ (bytes, 12,
"Total RREP is 12 bytes long");
343 DsrCacheEntryTest::DsrCacheEntryTest ()
347 DsrCacheEntryTest::~DsrCacheEntryTest ()
354 std::vector<Ipv4Address> ip;
359 NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 2,
"trivial");
360 NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (),
Ipv4Address (
"0.0.0.1"),
"trivial");
361 NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (),
Seconds (1),
"trivial");
363 entry.SetExpireTime (
Seconds (3));
364 NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (),
Seconds (3),
"trivial");
366 NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (),
Ipv4Address (
"1.1.1.1"),
"trivial");
368 entry.SetVector (ip);
369 NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 3,
"trivial");
371 NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry),
true,
"trivial");
373 std::vector<Ipv4Address> ip2;
379 NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry2),
true,
"trivial");
380 NS_TEST_EXPECT_MSG_EQ (rcache->LookupRoute (dst2, newEntry),
true,
"trivial");
381 NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (
Ipv4Address (
"2.2.2.2")),
false,
"trivial");
383 NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (
Ipv4Address (
"1.1.1.1")),
true,
"trivial");
384 NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (
Ipv4Address (
"1.1.1.1")),
false,
"trivial");
395 void CheckSizeLimit ();
396 void CheckTimeout ();
400 DsrSendBuffTest::DsrSendBuffTest ()
405 DsrSendBuffTest::~DsrSendBuffTest ()
411 q.SetMaxQueueLen (32);
412 NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32,
"trivial");
413 q.SetSendBufferTimeout (
Seconds (10));
414 NS_TEST_EXPECT_MSG_EQ (q.GetSendBufferTimeout (),
Seconds (10),
"trivial");
422 NS_TEST_EXPECT_MSG_EQ (q.Find (
Ipv4Address (
"0.0.0.1")),
true,
"trivial");
423 NS_TEST_EXPECT_MSG_EQ (q.Find (
Ipv4Address (
"1.1.1.1")),
false,
"trivial");
424 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1,
"trivial");
426 NS_TEST_EXPECT_MSG_EQ (q.Find (
Ipv4Address (
"0.0.0.1")),
false,
"trivial");
427 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0,
"trivial");
435 NS_TEST_EXPECT_MSG_EQ (q.Dequeue (
Ipv4Address (
"0.0.0.3"), e3),
false,
"trivial");
436 NS_TEST_EXPECT_MSG_EQ (q.Dequeue (
Ipv4Address (
"0.0.0.2"), e3),
true,
"trivial");
437 NS_TEST_EXPECT_MSG_EQ (q.Find (
Ipv4Address (
"0.0.0.2")),
false,
"trivial");
440 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2,
"trivial");
445 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3,
"trivial");
447 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2,
"trivial");
457 DsrSendBuffTest::CheckSizeLimit ()
463 for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
467 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3,
"trivial");
469 for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
473 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3,
"trivial");
476 DsrSendBuffTest::CheckTimeout ()
478 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0,
"Must be empty now");
490 DsrRreqTableTest::DsrRreqTableTest ()
494 DsrRreqTableTest::~DsrRreqTableTest ()
503 NS_TEST_EXPECT_MSG_EQ (rt.m_reqNo, 2,
"trivial");
automatically resized byte buffer
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
static void Destroy(void)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Ipv4 addresses are stored in host order in this class.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
virtual void DoRun(void)
Implementation to actually run this test case.
bool AddAtStart(uint32_t start)
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.