Unit test for RANN information element
This commit is contained in:
@@ -110,7 +110,7 @@ private:
|
||||
|
||||
#define NS_TEST_ASSERT_EQUAL_FILELINE(got, expected, file, line) \
|
||||
do { \
|
||||
if ((got) != (expected)) \
|
||||
if (! ((got) == (expected))) \
|
||||
{ \
|
||||
Failure () << file << ":" <<line \
|
||||
<< ": expected " << (expected) \
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
/**
|
||||
* \ingroup mesh
|
||||
* \ingroup dot11s
|
||||
*
|
||||
* \brief Hwmp tag implements interaction between HWMP
|
||||
* protocol and MeshWifiMac
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/test.h"
|
||||
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
@@ -92,7 +94,7 @@ IeRann::GetHopcount ()
|
||||
return m_hopcount;
|
||||
}
|
||||
uint8_t
|
||||
IeRann::GetTTL ()
|
||||
IeRann::GetTtl ()
|
||||
{
|
||||
return m_ttl;
|
||||
}
|
||||
@@ -106,6 +108,18 @@ IeRann::GetMetric ()
|
||||
{
|
||||
return m_metric;
|
||||
}
|
||||
void
|
||||
IeRann::DecrementTtl ()
|
||||
{
|
||||
m_ttl--;
|
||||
}
|
||||
|
||||
void
|
||||
IeRann::IncrementMetric (uint32_t m)
|
||||
{
|
||||
m_metric += m;
|
||||
}
|
||||
|
||||
Mac48Address
|
||||
IeRann::GetOriginatorAddress ()
|
||||
{
|
||||
@@ -145,8 +159,73 @@ IeRann::GetInformationSize () const
|
||||
+4;//Metric
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
IeRann::PrintInformation (std::ostream &os) const
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
bool
|
||||
operator== (const IeRann & a, const IeRann & b)
|
||||
{
|
||||
return (a.m_flags == b.m_flags
|
||||
&& a.m_hopcount == b.m_hopcount
|
||||
&& a.m_ttl == b.m_ttl
|
||||
&& a.m_originatorAddress == b.m_originatorAddress
|
||||
&& a.m_destSeqNumber == b.m_destSeqNumber
|
||||
&& a.m_metric == b.m_metric
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace dot11s
|
||||
} //namespace ns3
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
/// Built-in self test for IeRann
|
||||
struct IeRannBist : public Test
|
||||
{
|
||||
IeRannBist () : Test ("Mesh/802.11s/IeRann") {}
|
||||
virtual bool RunTests();
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static IeRannBist g_IeRannBist;
|
||||
|
||||
bool IeRannBist::RunTests ()
|
||||
{
|
||||
bool result(true);
|
||||
|
||||
// create test information element
|
||||
IeRann a;
|
||||
|
||||
a.SetFlags (1);
|
||||
a.SetHopcount (2);
|
||||
a.SetTTL (4);
|
||||
a.DecrementTtl ();
|
||||
NS_TEST_ASSERT_EQUAL (a.GetTtl(), 3);
|
||||
a.SetOriginatorAddress (Mac48Address());
|
||||
a.SetDestSeqNumber (5);
|
||||
a.SetMetric (6);
|
||||
a.IncrementMetric (2);
|
||||
NS_TEST_ASSERT_EQUAL (a.GetMetric(), 8);
|
||||
|
||||
// test roundtrip serialization
|
||||
Ptr<Packet> packet = Create<Packet> ();
|
||||
packet->AddHeader (a);
|
||||
IeRann b;
|
||||
packet->RemoveHeader (b);
|
||||
NS_TEST_ASSERT_EQUAL (a, b); // using default operator==
|
||||
|
||||
// test FindFirst()
|
||||
packet->AddHeader (a);
|
||||
IeRann c;
|
||||
bool ok = c.FindFirst(packet);
|
||||
NS_TEST_ASSERT (ok);
|
||||
NS_TEST_ASSERT_EQUAL (a, c);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif // RUN_SELF_TESTS
|
||||
|
||||
}} // namespace ns3::dot11s
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace dot11s {
|
||||
* \ingroup dot11s
|
||||
* \brief See 7.3.2.95 of 802.11s draft 2.07
|
||||
*/
|
||||
class IeRann
|
||||
class IeRann : public WifiInformationElement
|
||||
{
|
||||
public:
|
||||
IeRann ();
|
||||
@@ -46,12 +46,13 @@ public:
|
||||
void SetMetric (uint32_t metric);
|
||||
uint8_t GetFlags ();
|
||||
uint8_t GetHopcount ();
|
||||
uint8_t GetTTL ();
|
||||
uint8_t GetTtl ();
|
||||
Mac48Address GetOriginatorAddress ();
|
||||
uint32_t GetDestSeqNumber ();
|
||||
uint32_t GetMetric ();
|
||||
void DecrementTtl ();
|
||||
void IncrementMetric (uint32_t metric);
|
||||
|
||||
private:
|
||||
WifiElementId ElementId () const{
|
||||
return IE11S_RANN;
|
||||
@@ -59,14 +60,21 @@ private:
|
||||
void SerializeInformation (Buffer::Iterator i) const;
|
||||
uint8_t DeserializeInformation (Buffer::Iterator start, uint8_t length);
|
||||
uint8_t GetInformationSize () const;
|
||||
void PrintInformation (std::ostream &os) const;
|
||||
|
||||
uint8_t m_flags;
|
||||
uint8_t m_hopcount;
|
||||
uint8_t m_ttl;
|
||||
Mac48Address m_originatorAddress;
|
||||
uint32_t m_destSeqNumber;
|
||||
uint32_t m_metric;
|
||||
};
|
||||
|
||||
friend bool operator== (const IeRann & a, const IeRann & b);
|
||||
};
|
||||
|
||||
bool operator== (const IeRann & a, const IeRann & b);
|
||||
|
||||
} // namespace dot11s
|
||||
} //namespace ns3
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user