merge
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
#include "ns3/address-utils.h"
|
||||
#include "dot11s-mac-header.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/test.h"
|
||||
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
@@ -314,67 +313,6 @@ WifiMeshActionHeader::Deserialize (Buffer::Iterator start)
|
||||
m_actionValue = i.ReadU8 ();
|
||||
return i.GetDistanceFrom (start);
|
||||
}
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
/// Built-in self test for Dot11sMacHeader
|
||||
struct Dot11sMacHeaderBist : public Test
|
||||
{
|
||||
Dot11sMacHeaderBist () :
|
||||
Test ("Mesh/802.11s/MeshHeader")
|
||||
{
|
||||
}
|
||||
virtual bool
|
||||
RunTests ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static Dot11sMacHeaderBist g_Dot11sMacHeaderBist;
|
||||
|
||||
bool
|
||||
Dot11sMacHeaderBist::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (3);
|
||||
a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
|
||||
a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (2);
|
||||
a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
|
||||
a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (1);
|
||||
a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
} //namespace dot11s
|
||||
} // namespace ns3
|
||||
|
||||
292
src/devices/mesh/dot11s/dot11s-test-suite.cc
Normal file
292
src/devices/mesh/dot11s/dot11s-test-suite.cc
Normal file
@@ -0,0 +1,292 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 IITP RAS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Pavel Boyko <boyko@iitp.ru>
|
||||
*/
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "dot11s-mac-header.h"
|
||||
#include "hwmp-rtable.h"
|
||||
#include "peer-link-frame.h"
|
||||
#include "ie-dot11s-peer-management.h"
|
||||
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
|
||||
/// Built-in self test for FlameHeader
|
||||
struct MeshHeaderTest : public TestCase
|
||||
{
|
||||
MeshHeaderTest () :
|
||||
TestCase ("Dot11sMeshHeader roundtrip serialization")
|
||||
{
|
||||
}
|
||||
bool DoRun ();
|
||||
};
|
||||
|
||||
bool
|
||||
MeshHeaderTest::DoRun ()
|
||||
{
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (3);
|
||||
a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
|
||||
a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 3 addresses");
|
||||
}
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (2);
|
||||
a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
|
||||
a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 2 addresses");
|
||||
}
|
||||
{
|
||||
MeshHeader a;
|
||||
a.SetAddressExt (1);
|
||||
a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetMeshTtl (122);
|
||||
a.SetMeshSeqno (321);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
MeshHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 1 address");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Unit test for HwmpRtable
|
||||
class HwmpRtableTest : public TestCase
|
||||
{
|
||||
public:
|
||||
HwmpRtableTest ();
|
||||
virtual bool DoRun ();
|
||||
|
||||
private:
|
||||
/// 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:
|
||||
Mac48Address dst;
|
||||
Mac48Address hop;
|
||||
uint32_t iface;
|
||||
uint32_t metric;
|
||||
uint32_t seqnum;
|
||||
Time expire;
|
||||
Ptr<HwmpRtable> table;
|
||||
std::vector<Mac48Address> precursors;
|
||||
};
|
||||
|
||||
HwmpRtableTest::HwmpRtableTest () :
|
||||
TestCase ("HWMP routing table"),
|
||||
dst ("01:00:00:01:00:01"),
|
||||
hop ("01:00:00:01:00:03"),
|
||||
iface (8010),
|
||||
metric (10),
|
||||
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::TestLookup ()
|
||||
{
|
||||
HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
|
||||
|
||||
// Reactive path
|
||||
table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
|
||||
NS_TEST_EXPECT_MSG_EQ ((table->LookupReactive (dst) == correct), true, "Reactive lookup works");
|
||||
table->DeleteReactivePath (dst);
|
||||
NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive lookup works");
|
||||
|
||||
// Proactive
|
||||
table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
|
||||
NS_TEST_EXPECT_MSG_EQ ((table->LookupProactive () == correct), true, "Proactive lookup works");
|
||||
table->DeleteProactivePath (dst);
|
||||
NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive lookup works");
|
||||
}
|
||||
|
||||
void
|
||||
HwmpRtableTest::TestAddPath ()
|
||||
{
|
||||
table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
|
||||
table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
|
||||
}
|
||||
|
||||
void
|
||||
HwmpRtableTest::TestExpire ()
|
||||
{
|
||||
// this is assumed to be called when path records are already expired
|
||||
HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
|
||||
NS_TEST_EXPECT_MSG_EQ ((table->LookupReactiveExpired (dst) == correct), true, "Reactive expiration works");
|
||||
NS_TEST_EXPECT_MSG_EQ ((table->LookupProactiveExpired () == correct), true, "Proactive expiration works");
|
||||
|
||||
NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive expiration works");
|
||||
NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive expiration works");
|
||||
}
|
||||
|
||||
void
|
||||
HwmpRtableTest::TestPrecursorAdd ()
|
||||
{
|
||||
for (std::vector<Mac48Address>::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_EXPECT_MSG_EQ (precursors.size (), precursorList.size (), "Precursors size works");
|
||||
for (unsigned i = 0; i < precursors.size (); i++)
|
||||
{
|
||||
NS_TEST_EXPECT_MSG_EQ (precursorList[i].first, iface, "Precursors lookup works");
|
||||
NS_TEST_EXPECT_MSG_EQ (precursorList[i].second, precursors[i], "Precursors lookup works");
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
HwmpRtableTest::DoRun ()
|
||||
{
|
||||
table = CreateObject<HwmpRtable> ();
|
||||
|
||||
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 ();
|
||||
|
||||
return GetErrorStatus ();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Built-in self test for PeerLinkFrameStart
|
||||
struct PeerLinkFrameStartTest : public TestCase
|
||||
{
|
||||
PeerLinkFrameStartTest () :
|
||||
TestCase ("PeerLinkFrames (open, confirm, close) unit tests")
|
||||
{
|
||||
}
|
||||
virtual bool DoRun ();
|
||||
};
|
||||
|
||||
bool
|
||||
PeerLinkFrameStartTest::DoRun ()
|
||||
{
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN);
|
||||
fields.capability = 0;
|
||||
fields.aid = 101;
|
||||
fields.reasonCode = 12;
|
||||
fields.meshId = IeMeshId ("qwertyuiop");
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_OPEN works");
|
||||
}
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM);
|
||||
fields.capability = 0;
|
||||
fields.aid = 1234;
|
||||
fields.reasonCode = 12;
|
||||
fields.meshId = IeMeshId ("qwerty");
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CONFIRM works");
|
||||
}
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE);
|
||||
fields.capability = 0;
|
||||
fields.aid = 10;
|
||||
fields.meshId = IeMeshId ("qqq");
|
||||
fields.reasonCode = 12;
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CLOSE works");
|
||||
}
|
||||
return GetErrorStatus ();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
class Dot11sTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Dot11sTestSuite ();
|
||||
};
|
||||
|
||||
Dot11sTestSuite::Dot11sTestSuite ()
|
||||
: TestSuite ("devices-mesh-dot11s", UNIT)
|
||||
{
|
||||
AddTestCase (new MeshHeaderTest);
|
||||
AddTestCase (new HwmpRtableTest);
|
||||
AddTestCase (new PeerLinkFrameStartTest);
|
||||
}
|
||||
|
||||
Dot11sTestSuite g_dot11sTestSuite;
|
||||
}
|
||||
}
|
||||
@@ -263,131 +263,5 @@ HwmpRtable::LookupResult::IsValid () const
|
||||
return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && metric == MAX_METRIC
|
||||
&& seqnum == 0);
|
||||
}
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for HwmpRtable
|
||||
class HwmpRtableTest : public Test
|
||||
{
|
||||
public:
|
||||
HwmpRtableTest ();
|
||||
virtual bool
|
||||
RunTests ();
|
||||
|
||||
private:
|
||||
/// 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;
|
||||
|
||||
Mac48Address dst;
|
||||
Mac48Address hop;
|
||||
uint32_t iface;
|
||||
uint32_t metric;
|
||||
uint32_t seqnum;
|
||||
Time expire;
|
||||
Ptr<HwmpRtable> table;
|
||||
std::vector<Mac48Address> precursors;
|
||||
};
|
||||
/// Test instance
|
||||
static HwmpRtableTest g_HwmpRtableTest;
|
||||
|
||||
HwmpRtableTest::HwmpRtableTest () :
|
||||
Test ("Mesh/802.11s/HwmpRtable"), result (true), dst ("01:00:00:01:00:01"), hop ("01:00:00:01:00:03"),
|
||||
iface (8010), metric (10), 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::TestLookup ()
|
||||
{
|
||||
HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
|
||||
|
||||
// Reactive path
|
||||
table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
|
||||
NS_TEST_ASSERT (table->LookupReactive (dst) == correct);
|
||||
table->DeleteReactivePath (dst);
|
||||
NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ());
|
||||
|
||||
// Proactive
|
||||
table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
|
||||
NS_TEST_ASSERT (table->LookupProactive () == correct);
|
||||
table->DeleteProactivePath (dst);
|
||||
NS_TEST_ASSERT (!table->LookupProactive ().IsValid ());
|
||||
}
|
||||
void
|
||||
HwmpRtableTest::TestAddPath ()
|
||||
{
|
||||
table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
|
||||
table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
|
||||
}
|
||||
void
|
||||
HwmpRtableTest::TestExpire ()
|
||||
{
|
||||
// this is assumed to be called when path records are already expired
|
||||
HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
|
||||
NS_TEST_ASSERT (table->LookupReactiveExpired (dst) == correct);
|
||||
NS_TEST_ASSERT (table->LookupProactiveExpired () == correct);
|
||||
|
||||
NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ());
|
||||
NS_TEST_ASSERT (!table->LookupProactive ().IsValid ());
|
||||
}
|
||||
void
|
||||
HwmpRtableTest::TestPrecursorAdd ()
|
||||
{
|
||||
for (std::vector<Mac48Address>::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<HwmpRtable> ();
|
||||
|
||||
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 ();
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif // RUN_SELF_TESTS
|
||||
} //namespace dot11s
|
||||
} //namespace ns3
|
||||
|
||||
@@ -237,75 +237,6 @@ operator== (const PeerLinkFrameStart & a, const PeerLinkFrameStart & b)
|
||||
&& (a.m_meshId.IsEqual (b.m_meshId)) && (a.m_config == b.m_config)
|
||||
&& (a.m_reasonCode == b.m_reasonCode));
|
||||
}
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Built-in self test for PeerLinkFrameStart
|
||||
struct PeerLinkFrameStartBist : public Test
|
||||
{
|
||||
PeerLinkFrameStartBist () :
|
||||
Test ("Mesh/802.11s/PeerLinkFrameStart")
|
||||
{
|
||||
}
|
||||
virtual bool
|
||||
RunTests ();
|
||||
};
|
||||
/// Test instance
|
||||
static PeerLinkFrameStartBist g_PeerLinkFrameStartBist;
|
||||
|
||||
bool
|
||||
PeerLinkFrameStartBist::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN);
|
||||
fields.capability = 0;
|
||||
fields.aid = 101;
|
||||
fields.reasonCode = 12;
|
||||
fields.meshId = IeMeshId ("qwertyuiop");
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM);
|
||||
fields.capability = 0;
|
||||
fields.aid = 1234;
|
||||
fields.reasonCode = 12;
|
||||
fields.meshId = IeMeshId ("qwerty");
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
{
|
||||
PeerLinkFrameStart a;
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE);
|
||||
fields.capability = 0;
|
||||
fields.aid = 10;
|
||||
fields.meshId = IeMeshId ("qqq");
|
||||
fields.reasonCode = 12;
|
||||
a.SetPlinkFrameStart (fields);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
PeerLinkFrameStart b;
|
||||
b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE));
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
} // namespace dot11s
|
||||
} //namespace ns3
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ def build(bld):
|
||||
'hwmp-protocol-mac.cc',
|
||||
'hwmp-protocol.cc',
|
||||
'airtime-metric.cc',
|
||||
'dot11s-test-suite.cc',
|
||||
]
|
||||
headers = bld.new_task_gen('ns3header')
|
||||
headers.module = 'dot11s'
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/test.h"
|
||||
|
||||
#include "flame-header.h"
|
||||
|
||||
@@ -143,40 +142,5 @@ operator== (const FlameHeader & a, const FlameHeader & b)
|
||||
== b.m_origSrc) && (a.m_protocol == b.m_protocol));
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
/// Built-in self test for FlameHeader
|
||||
struct FlameHeaderBist : public Test
|
||||
{
|
||||
FlameHeaderBist () :
|
||||
Test ("Mesh/Flame/FlameHeader")
|
||||
{
|
||||
}
|
||||
virtual bool
|
||||
RunTests ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static FlameHeaderBist g_FlameHeaderBist;
|
||||
|
||||
bool
|
||||
FlameHeaderBist::RunTests ()
|
||||
{
|
||||
bool result (true);
|
||||
FlameHeader a;
|
||||
a.AddCost (123);
|
||||
a.SetSeqno (456);
|
||||
a.SetOrigDst (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetOrigSrc (Mac48Address ("00:11:22:33:44:55"));
|
||||
a.SetProtocol (0x806);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
FlameHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (b, a);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
} //namespace flame
|
||||
} // namespace ns3
|
||||
|
||||
@@ -109,85 +109,5 @@ FlameRtable::LookupResult::IsValid () const
|
||||
&& seqnum == 0);
|
||||
}
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for FlameRtable
|
||||
class FlameRtableTest : public Test
|
||||
{
|
||||
public:
|
||||
FlameRtableTest ();
|
||||
virtual bool
|
||||
RunTests ();
|
||||
|
||||
private:
|
||||
/// Test Add apth and lookup path;
|
||||
void
|
||||
TestLookup ();
|
||||
/**
|
||||
* \name Test add path and try to lookup after entry has expired
|
||||
* \{
|
||||
*/
|
||||
void
|
||||
TestAddPath ();
|
||||
void
|
||||
TestExpire ();
|
||||
///\}
|
||||
private:
|
||||
bool result;
|
||||
|
||||
Mac48Address dst;
|
||||
Mac48Address hop;
|
||||
uint32_t iface;
|
||||
uint8_t cost;
|
||||
uint16_t seqnum;
|
||||
Ptr<FlameRtable> table;
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static FlameRtableTest g_FlameRtableTest;
|
||||
|
||||
FlameRtableTest::FlameRtableTest () :
|
||||
Test ("Mesh/Flame/FlameRtable"), result (true), dst ("01:00:00:01:00:01"), hop ("01:00:00:01:00:03"),
|
||||
iface (8010), cost (10), seqnum (1)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestLookup ()
|
||||
{
|
||||
FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
|
||||
|
||||
table->AddPath (dst, hop, iface, cost, seqnum);
|
||||
NS_TEST_ASSERT (table->Lookup (dst) == correct);
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestAddPath ()
|
||||
{
|
||||
table->AddPath (dst, hop, iface, cost, seqnum);
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestExpire ()
|
||||
{
|
||||
// this is assumed to be called when path records are already expired
|
||||
FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
|
||||
NS_TEST_ASSERT (!table->Lookup (dst).IsValid ());
|
||||
}
|
||||
bool
|
||||
FlameRtableTest::RunTests ()
|
||||
{
|
||||
table = CreateObject<FlameRtable> ();
|
||||
|
||||
Simulator::Schedule (Seconds (0), &FlameRtableTest::TestLookup, this);
|
||||
Simulator::Schedule (Seconds (1), &FlameRtableTest::TestAddPath, this);
|
||||
Simulator::Schedule (Seconds (122), &FlameRtableTest::TestExpire, this);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // RUN_SELF_TESTS
|
||||
} //namespace flame
|
||||
} //namespace ns3
|
||||
|
||||
158
src/devices/mesh/flame/flame-test-suite.cc
Normal file
158
src/devices/mesh/flame/flame-test-suite.cc
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 IITP RAS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Pavel Boyko <boyko@iitp.ru>
|
||||
*/
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "flame-header.h"
|
||||
#include "flame-rtable.h"
|
||||
|
||||
namespace ns3 {
|
||||
namespace flame {
|
||||
|
||||
/// Built-in self test for FlameHeader
|
||||
struct FlameHeaderTest : public TestCase
|
||||
{
|
||||
FlameHeaderTest () :
|
||||
TestCase ("FlameHeader roundtrip serialization")
|
||||
{
|
||||
}
|
||||
bool DoRun ();
|
||||
};
|
||||
|
||||
bool
|
||||
FlameHeaderTest::DoRun ()
|
||||
{
|
||||
FlameHeader a;
|
||||
a.AddCost (123);
|
||||
a.SetSeqno (456);
|
||||
a.SetOrigDst (Mac48Address ("11:22:33:44:55:66"));
|
||||
a.SetOrigSrc (Mac48Address ("00:11:22:33:44:55"));
|
||||
a.SetProtocol (0x806);
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
FlameHeader b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_MSG_EQ (b, a, "FlameHeader roundtrip serialization works");
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Unit test for FlameRtable
|
||||
class FlameRtableTest : public TestCase
|
||||
{
|
||||
public:
|
||||
FlameRtableTest ();
|
||||
bool DoRun ();
|
||||
|
||||
private:
|
||||
/// Test Add apth and lookup path;
|
||||
void TestLookup ();
|
||||
/**
|
||||
* \name Test add path and try to lookup after entry has expired
|
||||
* \{
|
||||
*/
|
||||
void TestAddPath ();
|
||||
void TestExpire ();
|
||||
///\}
|
||||
private:
|
||||
bool error;
|
||||
|
||||
Mac48Address dst;
|
||||
Mac48Address hop;
|
||||
uint32_t iface;
|
||||
uint8_t cost;
|
||||
uint16_t seqnum;
|
||||
Ptr<FlameRtable> table;
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static FlameRtableTest g_FlameRtableTest;
|
||||
|
||||
FlameRtableTest::FlameRtableTest () :
|
||||
TestCase ("Mesh/Flame/FlameRtable"),
|
||||
error (false),
|
||||
dst ("01:00:00:01:00:01"),
|
||||
hop ("01:00:00:01:00:03"),
|
||||
iface (8010),
|
||||
cost (10),
|
||||
seqnum (1)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestLookup ()
|
||||
{
|
||||
FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
|
||||
|
||||
table->AddPath (dst, hop, iface, cost, seqnum);
|
||||
NS_TEST_EXPECT_MSG_EQ ((table->Lookup (dst) == correct), true, "Routing table lookup works");
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestAddPath ()
|
||||
{
|
||||
table->AddPath (dst, hop, iface, cost, seqnum);
|
||||
}
|
||||
|
||||
void
|
||||
FlameRtableTest::TestExpire ()
|
||||
{
|
||||
// this is assumed to be called when path records are already expired
|
||||
FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
|
||||
NS_TEST_EXPECT_MSG_EQ (table->Lookup (dst).IsValid (), false, "Routing table records expirations works");
|
||||
}
|
||||
|
||||
bool
|
||||
FlameRtableTest::DoRun ()
|
||||
{
|
||||
table = CreateObject<FlameRtable> ();
|
||||
|
||||
Simulator::Schedule (Seconds (0), &FlameRtableTest::TestLookup, this);
|
||||
Simulator::Schedule (Seconds (1), &FlameRtableTest::TestAddPath, this);
|
||||
Simulator::Schedule (Seconds (122), &FlameRtableTest::TestExpire, this);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return GetErrorStatus ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class FlameTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
FlameTestSuite ();
|
||||
};
|
||||
|
||||
FlameTestSuite::FlameTestSuite ()
|
||||
: TestSuite ("devices-mesh-flame", UNIT)
|
||||
{
|
||||
AddTestCase (new FlameHeaderTest);
|
||||
AddTestCase (new FlameRtableTest);
|
||||
}
|
||||
|
||||
FlameTestSuite g_flameTestSuite;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ def build(bld):
|
||||
'flame-rtable.cc',
|
||||
'flame-protocol-mac.cc',
|
||||
'flame-protocol.cc',
|
||||
'flame-test-suite.cc',
|
||||
]
|
||||
headers = bld.new_task_gen('ns3header')
|
||||
headers.module = 'flame'
|
||||
|
||||
@@ -365,26 +365,23 @@ operator== (const WifiInformationElementVector & a, const WifiInformationElement
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
/// Built-in self test for WifiInformationElementVector
|
||||
struct WifiInformationElementVectorBist : public Test
|
||||
//-----------------------------------------------------------------------------
|
||||
// Unit tests
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Built-in self test for WifiInformationElementVector and all IE
|
||||
struct WifiInformationElementVectorBist : public TestCase
|
||||
{
|
||||
WifiInformationElementVectorBist () :
|
||||
Test ("Mesh/WifiInformationElementVector")
|
||||
TestCase ("Serializarion test for all mesh information elements")
|
||||
{
|
||||
};
|
||||
virtual bool
|
||||
RunTests ();
|
||||
bool DoRun ();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static WifiInformationElementVectorBist g_IePrepBist;
|
||||
|
||||
bool
|
||||
WifiInformationElementVectorBist::RunTests ()
|
||||
WifiInformationElementVectorBist::DoRun ()
|
||||
{
|
||||
bool result = true;
|
||||
WifiInformationElementVector vector;
|
||||
{
|
||||
//Mesh ID test
|
||||
@@ -424,12 +421,12 @@ WifiInformationElementVectorBist::RunTests ()
|
||||
rann->SetHopcount (2);
|
||||
rann->SetTTL (4);
|
||||
rann->DecrementTtl ();
|
||||
NS_TEST_ASSERT_EQUAL (rann->GetTtl (), 3);
|
||||
NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
|
||||
rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
|
||||
rann->SetDestSeqNumber (5);
|
||||
rann->SetMetric (6);
|
||||
rann->IncrementMetric (2);
|
||||
NS_TEST_ASSERT_EQUAL (rann->GetMetric (), 8);
|
||||
NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
|
||||
vector.AddInformationElement (rann);
|
||||
}
|
||||
{
|
||||
@@ -475,10 +472,23 @@ WifiInformationElementVectorBist::RunTests ()
|
||||
packet->AddHeader (vector);
|
||||
WifiInformationElementVector resultVector;
|
||||
packet->RemoveHeader (resultVector);
|
||||
NS_TEST_ASSERT (vector == resultVector);
|
||||
NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
|
||||
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // RUN_SELF_TESTS
|
||||
class MeshTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
MeshTestSuite ();
|
||||
};
|
||||
|
||||
MeshTestSuite::MeshTestSuite ()
|
||||
: TestSuite ("devices-mesh", UNIT)
|
||||
{
|
||||
AddTestCase (new WifiInformationElementVectorBist);
|
||||
}
|
||||
|
||||
MeshTestSuite g_meshTestSuite;
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user