From ac436ea5d36fce0d80de5480e5c30b644cfa0833 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Mon, 15 Jun 2009 18:02:09 +0400 Subject: [PATCH] Fixed tests, removes NS_ASSERT (false) --- src/devices/mesh/dot11s/dot11s-mac-header.cc | 2 +- src/devices/mesh/dot11s/hwmp-protocol.cc | 2 +- src/devices/mesh/dot11s/hwmp-rtable.cc | 59 +++++++++++++++----- src/devices/mesh/dot11s/peer-link.cc | 2 +- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/devices/mesh/dot11s/dot11s-mac-header.cc b/src/devices/mesh/dot11s/dot11s-mac-header.cc index c88e965e9..835db8588 100644 --- a/src/devices/mesh/dot11s/dot11s-mac-header.cc +++ b/src/devices/mesh/dot11s/dot11s-mac-header.cc @@ -229,7 +229,7 @@ WifiMeshActionHeader::GetCategory () case MESH_PROXY_FORWARDING: return MESH_PROXY_FORWARDING; default: - NS_ASSERT (false); + NS_FATAL_ERROR ("Unknown action value"); return MESH_PEERING_MGT; } } diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index 2ffae8a84..ec577706d 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -748,7 +748,7 @@ HwmpProtocol::QueuedPacket HwmpProtocol::DequeueFirstPacket () { QueuedPacket retval; - retval.pkt = NULL; + retval.pkt = 0; if(m_rqueue.size () != 0) { retval = m_rqueue[0]; diff --git a/src/devices/mesh/dot11s/hwmp-rtable.cc b/src/devices/mesh/dot11s/hwmp-rtable.cc index d436cae3e..198b66d12 100644 --- a/src/devices/mesh/dot11s/hwmp-rtable.cc +++ b/src/devices/mesh/dot11s/hwmp-rtable.cc @@ -277,11 +277,22 @@ public: virtual bool RunTests(); private: - void Test1 (); - void Test2 (); - void Test3 (); - void Test4 (); - + /// Test Add apth and lookup path; + void TestLookup (); + /** + * \name Test add path and try to lookup after entry has expired + * \{ + */ + void TestAddPath (); + void TestExpire (); + ///\} + /** + * \name Test add precursors and find precursor list in rtable + * \{ + */ + void TestPrecursorAdd (); + void TestPrecursorFind (); + ///\} private: bool result; @@ -292,6 +303,7 @@ private: uint32_t seqnum; Time expire; Ptr table; + std::vector precursors; }; /// Test instance @@ -306,9 +318,12 @@ HwmpRtableTest::HwmpRtableTest () : Test ("Mesh/802.11s/HwmpRtable"), seqnum (1), expire (Seconds (10)) { + precursors.push_back (Mac48Address ("00:10:20:30:40:50")); + precursors.push_back (Mac48Address ("00:11:22:33:44:55")); + precursors.push_back (Mac48Address ("00:01:02:03:04:05")); } -void HwmpRtableTest::Test1 () +void HwmpRtableTest::TestLookup () { HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); @@ -325,13 +340,13 @@ void HwmpRtableTest::Test1 () NS_TEST_ASSERT (! table->LookupProactive ().IsValid ()); } -void HwmpRtableTest::Test2 () +void HwmpRtableTest::TestAddPath () { table->AddReactivePath (dst, hop, iface, metric, expire, seqnum); table->AddProactivePath (metric, dst, hop, iface, expire, seqnum); } -void HwmpRtableTest::Test3 () +void HwmpRtableTest::TestExpire () { // this is assumed to be called when path records are already expired HwmpRtable::LookupResult correct (hop, iface, metric, seqnum); @@ -342,19 +357,35 @@ void HwmpRtableTest::Test3 () NS_TEST_ASSERT (! table->LookupProactive ().IsValid ()); } -void HwmpRtableTest::Test4 () +void HwmpRtableTest::TestPrecursorAdd () { - // TODO: test AddPrecursor and GetPrecursors + for (std::vector::const_iterator i = precursors.begin (); i != precursors.end (); i ++) + { + table->AddPrecursor (dst, iface, *i); + // Check that duplicates are filtered + table->AddPrecursor (dst, iface, *i); + } } +void HwmpRtableTest::TestPrecursorFind () +{ + HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst); + NS_TEST_ASSERT(precursors.size () == precursorList.size ()); + for(unsigned int i = 0; i < precursors.size (); i ++) + { + NS_TEST_ASSERT(precursorList[i].first == iface); + NS_TEST_ASSERT(precursorList[i].second == precursors[i]); + } +} bool HwmpRtableTest::RunTests () { table = CreateObject (); - Simulator::Schedule (Seconds (0), & HwmpRtableTest::Test1, this); - Simulator::Schedule (Seconds (1), & HwmpRtableTest::Test2, this); - Simulator::Schedule (expire + Seconds (2), & HwmpRtableTest::Test3, this); - Simulator::Schedule (expire + Seconds (3), & HwmpRtableTest::Test4, this); + Simulator::Schedule (Seconds (0), & HwmpRtableTest::TestLookup, this); + Simulator::Schedule (Seconds (1), & HwmpRtableTest::TestAddPath, this); + Simulator::Schedule (Seconds (2), & HwmpRtableTest::TestPrecursorAdd, this); + Simulator::Schedule (expire + Seconds (2), & HwmpRtableTest::TestExpire, this); + Simulator::Schedule (expire + Seconds (3), & HwmpRtableTest::TestPrecursorFind, this); Simulator::Run (); Simulator::Destroy (); diff --git a/src/devices/mesh/dot11s/peer-link.cc b/src/devices/mesh/dot11s/peer-link.cc index 06cee25df..746127383 100644 --- a/src/devices/mesh/dot11s/peer-link.cc +++ b/src/devices/mesh/dot11s/peer-link.cc @@ -536,7 +536,7 @@ PeerLink::SendPeerLinkOpen () { IePeerManagement peerElement; peerElement.SetPeerOpen (m_localLinkId); - NS_ASSERT (m_macPlugin != NULL); + NS_ASSERT (m_macPlugin != 0); m_macPlugin->SendPeerLinkManagementFrame (m_peerAddress, m_peerMeshPointAddress, m_assocId, peerElement, m_configuration); } void