some aodv unit tests ported to new framework. 4 left.
This commit is contained in:
@@ -162,80 +162,6 @@ Neighbors::ProcessTxError (WifiMacHeader const & hdr)
|
||||
i->close = true;
|
||||
Purge ();
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for neighbors
|
||||
struct NeighborTest : public Test
|
||||
{
|
||||
NeighborTest () : Test ("AODV/Neighbor"), neighbor (0), result (true) { }
|
||||
virtual bool RunTests ();
|
||||
void Handler (Ipv4Address addr);
|
||||
void CheckTimeout1 ();
|
||||
void CheckTimeout2 ();
|
||||
void CheckTimeout3 ();
|
||||
Neighbors * neighbor;
|
||||
bool result;
|
||||
};
|
||||
/// Test instance
|
||||
static NeighborTest g_NeighborTest;
|
||||
|
||||
void
|
||||
NeighborTest::Handler (Ipv4Address addr)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
NeighborTest::CheckTimeout1 ()
|
||||
{
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), true);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), true);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true);
|
||||
}
|
||||
void
|
||||
NeighborTest::CheckTimeout2 ()
|
||||
{
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), true);
|
||||
}
|
||||
void
|
||||
NeighborTest::CheckTimeout3 ()
|
||||
{
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.1.1.1")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("2.2.2.2")), false);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("3.3.3.3")), false);
|
||||
}
|
||||
|
||||
bool
|
||||
NeighborTest::RunTests ()
|
||||
{
|
||||
Neighbors nb (Seconds (1));
|
||||
neighbor = &nb;
|
||||
neighbor->SetCallback (MakeCallback (&NeighborTest::Handler, this));
|
||||
neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (1));
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("4.3.2.1")), false);
|
||||
neighbor->Update (Ipv4Address ("1.2.3.4"), Seconds (10));
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor (Ipv4Address ("1.2.3.4")), true);
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->GetExpireTime (Ipv4Address ("1.2.3.4")), Seconds (10));
|
||||
NS_TEST_ASSERT_EQUAL (neighbor->GetExpireTime (Ipv4Address ("4.3.2.1")), Seconds (0));
|
||||
neighbor->Update (Ipv4Address ("1.1.1.1"), Seconds (5));
|
||||
neighbor->Update (Ipv4Address ("2.2.2.2"), Seconds (10));
|
||||
neighbor->Update (Ipv4Address ("3.3.3.3"), Seconds (20));
|
||||
|
||||
Simulator::Schedule (Seconds (2), &NeighborTest::CheckTimeout1, this);
|
||||
Simulator::Schedule (Seconds (15), &NeighborTest::CheckTimeout2, this);
|
||||
Simulator::Schedule (Seconds (30), &NeighborTest::CheckTimeout3, this);
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,37 +135,6 @@ operator<< (std::ostream & os, TypeHeader const & h)
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for TypeHeader
|
||||
struct TypeHeaderTest : public Test
|
||||
{
|
||||
TypeHeaderTest () : Test ("AODV/TypeHeader")
|
||||
{}
|
||||
virtual bool RunTests ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static TypeHeaderTest g_TypeHeaderTest;
|
||||
|
||||
bool
|
||||
TypeHeaderTest::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
|
||||
TypeHeader h (AODVTYPE_RREQ);
|
||||
NS_TEST_ASSERT (h.IsValid ());
|
||||
NS_TEST_ASSERT_EQUAL (h.Get (), AODVTYPE_RREQ);
|
||||
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
p->AddHeader (h);
|
||||
TypeHeader h2 (AODVTYPE_RREP);
|
||||
uint32_t bytes = p->RemoveHeader (h2);
|
||||
NS_TEST_ASSERT_EQUAL (bytes, 1);
|
||||
NS_TEST_ASSERT_EQUAL (h, h2);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RREQ
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -291,63 +260,6 @@ RreqHeader::operator== (RreqHeader const & o) const
|
||||
m_origin == o.m_origin && m_originSeqNo == o.m_originSeqNo);
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for RREQ
|
||||
struct RreqHeaderTest : public Test
|
||||
{
|
||||
RreqHeaderTest () : Test ("AODV/RREQ") {}
|
||||
virtual bool
|
||||
RunTests ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static RreqHeaderTest g_RreqHeaderTest;
|
||||
|
||||
bool
|
||||
RreqHeaderTest::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
|
||||
RreqHeader h (/*flags*/0, /*reserved*/0, /*hopCount*/6, /*requestID*/1, /*dst*/Ipv4Address ("1.2.3.4"),
|
||||
/*dstSeqNo*/40, /*origin*/Ipv4Address ("4.3.2.1"), /*originSeqNo*/10);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetGratiousRrep (), false);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDestinationOnly (), false);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 6);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetId (), 1);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.2.3.4"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 40);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.3.2.1"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOriginSeqno (), 10);
|
||||
|
||||
h.SetGratiousRrep (true);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetGratiousRrep (), true);
|
||||
h.SetDestinationOnly (true);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDestinationOnly (), true);
|
||||
h.SetUnknownSeqno (true);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetUnknownSeqno (), true);
|
||||
h.SetDst (Ipv4Address ("1.1.1.1"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.1.1.1"));
|
||||
h.SetDstSeqno (5);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 5);
|
||||
h.SetHopCount (7);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 7);
|
||||
h.SetId (55);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetId (), 55);
|
||||
h.SetOrigin (Ipv4Address ("4.4.4.4"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.4.4.4"));
|
||||
h.SetOriginSeqno (23);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOriginSeqno (), 23);
|
||||
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
p->AddHeader (h);
|
||||
RreqHeader h2;
|
||||
uint32_t bytes = p->RemoveHeader (h2);
|
||||
NS_TEST_ASSERT_EQUAL (bytes, 23);
|
||||
NS_TEST_ASSERT_EQUAL (h, h2);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RREP
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -482,63 +394,6 @@ operator<< (std::ostream & os, RrepHeader const & h)
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for RREP
|
||||
struct RrepHeaderTest : public Test
|
||||
{
|
||||
RrepHeaderTest () : Test ("AODV/RREP") {}
|
||||
virtual bool
|
||||
RunTests ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static RrepHeaderTest g_RrepHeaderTest;
|
||||
|
||||
bool
|
||||
RrepHeaderTest::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
|
||||
RrepHeader h (/*prefixSize*/0, /*hopCount*/12, /*dst*/Ipv4Address ("1.2.3.4"), /*dstSeqNo*/2,
|
||||
/*origin*/Ipv4Address ("4.3.2.1"), /*lifetime*/Seconds (3));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 0);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 12);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.2.3.4"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 2);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.3.2.1"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), Seconds (3));
|
||||
h.SetDst (Ipv4Address ("1.1.1.1"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDst (), Ipv4Address ("1.1.1.1"));
|
||||
h.SetDstSeqno (123);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 123);
|
||||
h.SetOrigin (Ipv4Address ("4.4.4.4"));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetOrigin (), Ipv4Address ("4.4.4.4"));
|
||||
h.SetLifeTime (MilliSeconds (1200));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), MilliSeconds (1200));
|
||||
h.SetAckRequired (true);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetAckRequired (), true);
|
||||
h.SetAckRequired (false);
|
||||
NS_TEST_ASSERT (!h.GetAckRequired ());
|
||||
h.SetPrefixSize (2);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetPrefixSize (), 2);
|
||||
h.SetHopCount (15);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetHopCount (), 15);
|
||||
|
||||
h.SetHello (Ipv4Address ("10.0.0.2"), 9, Seconds (15));
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDst (), h.GetOrigin ());
|
||||
NS_TEST_ASSERT_EQUAL (h.GetDstSeqno (), 9);
|
||||
NS_TEST_ASSERT_EQUAL (h.GetLifeTime (), Seconds (15));
|
||||
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
p->AddHeader (h);
|
||||
RrepHeader h2;
|
||||
uint32_t bytes = p->RemoveHeader (h2);
|
||||
NS_TEST_ASSERT_EQUAL (bytes, 19);
|
||||
NS_TEST_ASSERT_EQUAL (h, h2);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RREP-ACK
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -594,33 +449,6 @@ operator<< (std::ostream & os, RrepAckHeader const & h )
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for RREP-ACK
|
||||
struct RrepAckHeaderTest : public Test
|
||||
{
|
||||
RrepAckHeaderTest () : Test ("AODV/RREP-ACK")
|
||||
{}
|
||||
virtual bool RunTests();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static RrepAckHeaderTest g_RrepAckHeaderTest;
|
||||
|
||||
bool RrepAckHeaderTest::RunTests ()
|
||||
{
|
||||
bool result(true);
|
||||
|
||||
RrepAckHeader h;
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
p->AddHeader (h);
|
||||
RrepAckHeader h2;
|
||||
uint32_t bytes = p->RemoveHeader(h2);
|
||||
NS_TEST_ASSERT_EQUAL (bytes, 1);
|
||||
NS_TEST_ASSERT_EQUAL (h, h2);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RERR
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -759,42 +587,5 @@ operator<< (std::ostream & os, RerrHeader const & h )
|
||||
h.Print (os);
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for RERR
|
||||
struct RerrHeaderTest : public Test
|
||||
{
|
||||
RerrHeaderTest () : Test ("AODV/RERR")
|
||||
{}
|
||||
virtual bool RunTests();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static RerrHeaderTest g_RerrHeaderTest;
|
||||
|
||||
bool RerrHeaderTest::RunTests ()
|
||||
{
|
||||
bool result(true);
|
||||
|
||||
RerrHeader h;
|
||||
h.SetNoDelete(true);
|
||||
NS_TEST_ASSERT(h.GetNoDelete());
|
||||
Ipv4Address dst = Ipv4Address("1.2.3.4");
|
||||
NS_TEST_ASSERT(h.AddUnDestination(dst, 12));
|
||||
NS_TEST_ASSERT_EQUAL(h.GetDestCount(),1);
|
||||
NS_TEST_ASSERT(h.AddUnDestination(dst, 13));
|
||||
Ipv4Address dst2 = Ipv4Address("4.3.2.1");
|
||||
NS_TEST_ASSERT(h.AddUnDestination(dst2, 12));
|
||||
NS_TEST_ASSERT_EQUAL(h.GetDestCount(), 2);
|
||||
|
||||
Ptr<Packet> p = Create<Packet> ();
|
||||
p->AddHeader (h);
|
||||
RerrHeader h2;
|
||||
uint32_t bytes = p->RemoveHeader(h2);
|
||||
NS_TEST_ASSERT_EQUAL (bytes, h.GetSerializedSize());
|
||||
NS_TEST_ASSERT_EQUAL (h, h2);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ def build(bld):
|
||||
'id-cache.cc',
|
||||
'aodv-neighbor.cc',
|
||||
'aodv-routing-protocol.cc',
|
||||
'aodv-test-suite.cc',
|
||||
]
|
||||
|
||||
headers = bld.new_task_gen('ns3header')
|
||||
|
||||
Reference in New Issue
Block a user