diff --git a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc index 37feb0492..cdb45fe64 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc @@ -21,6 +21,8 @@ #include "ie-dot11s-beacon-timing.h" #include "ns3/log.h" +#include "ns3/test.h" +#include "ns3/packet.h" namespace ns3 { namespace dot11s { /******************************************* @@ -52,23 +54,22 @@ IeBeaconTimingUnit::SetBeaconInterval (uint16_t beaconInterval) } uint8_t -IeBeaconTimingUnit::GetAid () +IeBeaconTimingUnit::GetAid () const { return m_aid; } uint16_t -IeBeaconTimingUnit::GetLastBeacon () +IeBeaconTimingUnit::GetLastBeacon () const { return m_lastBeacon; } uint16_t -IeBeaconTimingUnit::GetBeaconInterval () +IeBeaconTimingUnit::GetBeaconInterval () const { return m_beaconInterval; } - /******************************************* * IeBeaconTiming *******************************************/ @@ -153,8 +154,9 @@ IeBeaconTiming::GetInformationSize () const void IeBeaconTiming::PrintInformation (std::ostream& os) const { + os <<"Number of units: " << (uint16_t)m_numOfUnits << "\n"; for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j != m_neighbours.end(); j++) - os << "AID=" << (*j)->GetAid () << ", Last beacon was at " + os<< "AID=" << (uint16_t)(*j)->GetAid () << ", Last beacon was at " << (*j)->GetLastBeacon ()<<", with beacon interval " << (*j)->GetBeaconInterval () << "\n"; } @@ -201,7 +203,58 @@ IeBeaconTiming::AidToU8 (uint16_t x) { return (uint8_t) (x&0xff); }; - + +bool operator== (const IeBeaconTimingUnit & a, const IeBeaconTimingUnit & b) +{ + return ( + (a.GetAid () == b.GetAid ()) && + (a.GetLastBeacon () == b.GetLastBeacon()) && + (a.GetBeaconInterval () == b.GetBeaconInterval ()) + ); +} +bool operator== (const IeBeaconTiming & a, const IeBeaconTiming& b) +{ + if(a.m_numOfUnits != b.m_numOfUnits) + return false; + for(unsigned int i = 0; i < a.m_neighbours.size (); i ++) + if(!(*PeekPointer(a.m_neighbours[i]) == *PeekPointer(b.m_neighbours[i]))) + return false; + return true; +} + +#ifdef RUN_SELF_TESTS +struct IeBeaconTimingBist : public Test +{ + IeBeaconTimingBist () : Test ("Mesh/802.11s/IE/BeaconTiming") {} + virtual bool RunTests(); +}; + +/// Test instance +static IeBeaconTimingBist g_IePerrBist; + +bool IeBeaconTimingBist::RunTests () +{ + bool result(true); + // create test information element + IeBeaconTiming a; + a.IeBeaconTiming::AddNeighboursTimingElementUnit (1,Seconds(1.0), Seconds(4.0)); + a.IeBeaconTiming::AddNeighboursTimingElementUnit (2,Seconds(2.0), Seconds(3.0)); + a.IeBeaconTiming::AddNeighboursTimingElementUnit (3,Seconds(3.0), Seconds(2.0)); + a.IeBeaconTiming::AddNeighboursTimingElementUnit (4,Seconds(4.0), Seconds(1.0)); + Ptr packet = Create (); + packet->AddHeader(a); + IeBeaconTiming b; + packet->RemoveHeader(b); + NS_TEST_ASSERT_EQUAL (a, b); + //Test Find First + packet->AddHeader (a); + IeBeaconTiming c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + return result; +} +#endif } // namespace dot11s } //namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h index c51ae8b12..8d82b0f2b 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h +++ b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.h @@ -22,7 +22,7 @@ #ifndef WIFI_TIMING_ELEMENT_H #define WIFI_TIMING_ELEMENT_H -#include +#include #include "ns3/nstime.h" #include "ns3/wifi-information-element.h" @@ -40,9 +40,9 @@ public: void SetLastBeacon (uint16_t last_beacon); void SetBeaconInterval (uint16_t beacon_interval); - uint8_t GetAid (); - uint16_t GetLastBeacon (); - uint16_t GetBeaconInterval (); + uint8_t GetAid () const; + uint16_t GetLastBeacon () const; + uint16_t GetBeaconInterval () const; /** * \brief Least significant octet of AID: */ @@ -56,6 +56,7 @@ public: * \brief Beacon interval of remote mesh point: */ uint16_t m_beaconInterval; + friend bool operator== (const IeBeaconTimingUnit & a, const IeBeaconTimingUnit & b); }; /** @@ -69,7 +70,7 @@ public: * \ingroup dot11s * This type is a list of timing elements obtained from neigbours with their beacons: */ - typedef std::list< Ptr > NeighboursTimingUnitsList; + typedef std::vector< Ptr > NeighboursTimingUnitsList; IeBeaconTiming (); /** @@ -108,8 +109,10 @@ private: * Timing element parameters: */ uint16_t m_numOfUnits; + friend bool operator== (const IeBeaconTiming & a, const IeBeaconTiming & b); }; - +bool operator== (const IeBeaconTiming & a, const IeBeaconTiming & b); +bool operator== (const IeBeaconTimingUnit & a, const IeBeaconTimingUnit & b); } // namespace dot11s } //namespace ns3 #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-configuration.cc b/src/devices/mesh/dot11s/ie-dot11s-configuration.cc index e10267ffa..86d33fd0c 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-configuration.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-configuration.cc @@ -21,7 +21,8 @@ #include "ie-dot11s-configuration.h" - +#include "ns3/test.h" +#include "ns3/packet.h" namespace ns3 { namespace dot11s { @@ -29,8 +30,8 @@ dot11sMeshCapability::dot11sMeshCapability (): acceptPeerLinks (true), MDAEnabled (false), forwarding (true), - beaconTimingReport (false), - TBTTAdjustment (false), + beaconTimingReport (true), + TBTTAdjustment (true), powerSaveLevel (false) {} @@ -172,7 +173,58 @@ dot11sMeshCapability const& IeConfiguration::MeshCapability () { return m_meshCap; } - +bool operator== (const dot11sMeshCapability & a, const dot11sMeshCapability & b) +{ + return ( + (a.acceptPeerLinks == b.acceptPeerLinks) && + (a.MDAEnabled == b.MDAEnabled) && + (a.forwarding == b.forwarding) && + (a.beaconTimingReport == b.beaconTimingReport) && + (a.TBTTAdjustment == b.TBTTAdjustment) && + (a.powerSaveLevel == b.powerSaveLevel) + ); +} +bool operator== (const IeConfiguration & a, const IeConfiguration & b) +{ + return ( + (a.m_APSId == b.m_APSId) && + (a.m_APSMId == b.m_APSMId) && + (a.m_CCMId == b.m_CCMId) && + (a.m_CP == b.m_CP) && + (a.m_meshCap == b.m_meshCap) + ); +} +#ifdef RUN_SELF_TESTS + +/// Built-in self test for IePreq +struct IeConfigurationBist : public Test +{ + IeConfigurationBist () : Test ("Mesh/802.11s/IE/Configuration") {} + virtual bool RunTests(); +}; + +/// Test instance +static IeConfigurationBist g_IeConfigurationBist; + +bool IeConfigurationBist::RunTests () +{ + bool result(true); + IeConfiguration a; + Ptr packet = Create (); + packet->AddHeader (a); + IeConfiguration b; + packet->RemoveHeader (b); + NS_TEST_ASSERT_EQUAL (a, b); + // test FindFirst() + packet->AddHeader (a); + IeConfiguration c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + + return result; +} +#endif } // namespace dot11s } //namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-configuration.h b/src/devices/mesh/dot11s/ie-dot11s-configuration.h index fc6583423..96d674006 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-configuration.h +++ b/src/devices/mesh/dot11s/ie-dot11s-configuration.h @@ -80,8 +80,8 @@ public: bool beaconTimingReport; bool TBTTAdjustment; bool powerSaveLevel; - bool Is (uint16_t cap,uint8_t n) const; + friend bool operator== (const dot11sMeshCapability & a, const dot11sMeshCapability & b); }; /** @@ -111,6 +111,7 @@ private: void SerializeInformation (Buffer::Iterator i) const; uint8_t DeserializeInformation (Buffer::Iterator i, uint8_t length); void PrintInformation (std::ostream& os) const; +private: /** Active Path Selection Protocol ID */ dot11sPathSelectionProtocol m_APSId; /** Active Path Metric ID */ @@ -120,8 +121,10 @@ private: /* Channel Precedence */ dot11sChannelPrecedence m_CP; dot11sMeshCapability m_meshCap; + friend bool operator== (const IeConfiguration & a, const IeConfiguration & b); }; - +bool operator== (const IeConfiguration & a, const IeConfiguration & b); +bool operator== (const dot11sMeshCapability & a, const dot11sMeshCapability & b); } // namespace dot11s } //namespace ns3 #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc index d8faf36be..8c0801c38 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc @@ -22,8 +22,8 @@ #include "ie-dot11s-peer-management.h" #include "ns3/assert.h" - - +#include "ns3/test.h" +#include "ns3/packet.h" //NS_LOG_COMPONENT_DEFINE ("MeshPeerLinkManagementelement"); namespace ns3 { @@ -138,7 +138,74 @@ IePeerManagement::PrintInformation (std::ostream& os) const { //TODO } - +bool operator== (const IePeerManagement & a, const IePeerManagement & b) +{ + return ( + (a.m_length == b.m_length) && + (a.m_subtype == b.m_subtype) && + (a.m_localLinkId == b.m_localLinkId) && + (a.m_peerLinkId == b.m_peerLinkId) && + (a.m_reasonCode == b.m_reasonCode) + ); +} +#ifdef RUN_SELF_TESTS +struct IePeerManagementBist : public Test +{ + IePeerManagementBist () : Test ("Mesh/802.11s/IE/PeerManagement") {} + virtual bool RunTests(); +}; + +/// Test instance +static IePeerManagementBist g_IePerrBist; + +bool IePeerManagementBist::RunTests () +{ + bool result(true); + { + IePeerManagement a; + a.SetPeerOpen (1); + Ptr packet = Create (); + packet->AddHeader(a); + IePeerManagement b; + packet->RemoveHeader(b); + NS_TEST_ASSERT_EQUAL (a, b); + packet->AddHeader (a); + IePeerManagement c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + } + { + IePeerManagement a; + a.SetPeerConfirm (1,2); + Ptr packet = Create (); + packet->AddHeader(a); + IePeerManagement b; + packet->RemoveHeader(b); + NS_TEST_ASSERT_EQUAL (a, b); + packet->AddHeader (a); + IePeerManagement c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + } + { + IePeerManagement a; + a.SetPeerClose (1, 2, REASON11S_MESH_CONFIGURATION_POLICY_VIOLATION); + Ptr packet = Create (); + packet->AddHeader(a); + IePeerManagement b; + packet->RemoveHeader(b); + NS_TEST_ASSERT_EQUAL (a, b); + packet->AddHeader (a); + IePeerManagement c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + } + return result; +} +#endif } // namespace dot11s } //namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-peer-management.h b/src/devices/mesh/dot11s/ie-dot11s-peer-management.h index 5e7e89515..5da375545 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-peer-management.h +++ b/src/devices/mesh/dot11s/ie-dot11s-peer-management.h @@ -93,8 +93,9 @@ private: * Present only within close frame */ PmpReasonCode m_reasonCode; + friend bool operator== (const IePeerManagement & a, const IePeerManagement & b); }; - +bool operator== (const IePeerManagement & a, const IePeerManagement & b); } // namespace dot11s } //namespace ns3 #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-perr.cc b/src/devices/mesh/dot11s/ie-dot11s-perr.cc index 06551ebaf..1a6584f24 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-perr.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-perr.cc @@ -22,7 +22,8 @@ #include "ie-dot11s-perr.h" #include "ns3/address-utils.h" #include "ns3/node.h" - +#include "ns3/packet.h" +#include "ns3/test.h" namespace ns3 { namespace dot11s { IePerr::~IePerr () @@ -142,6 +143,63 @@ IePerr::ResetPerr () m_numOfDest = 0; m_addressUnits.clear (); } +bool operator== (const IePerr & a, const IePerr & b) +{ + if(a.m_numOfDest != b.m_numOfDest) + return false; + for(unsigned int i = 0; i < a.m_addressUnits.size(); i ++) + { + if(a.m_addressUnits[i].destination != b.m_addressUnits[i].destination) + return false; + if(a.m_addressUnits[i].seqnum != b.m_addressUnits[i].seqnum) + return false; + } + return true; +} +#ifdef RUN_SELF_TESTS + +/// Built-in self test for IePreq +struct IePerrBist : public Test +{ + IePerrBist () : Test ("Mesh/802.11s/IE/PERR") {} + virtual bool RunTests(); +}; + +/// Test instance +static IePerrBist g_IePerrBist; + +bool IePerrBist::RunTests () +{ + bool result(true); + // create test information element + IePerr a; + IePerr::FailedDestination dest; + dest.destination = Mac48Address("11:22:33:44:55:66"); + dest.seqnum = 1; + a.AddAddressUnit(dest); + dest.destination = Mac48Address("10:20:30:40:50:60"); + dest.seqnum = 2; + a.AddAddressUnit(dest); + dest.destination = Mac48Address("01:02:03:04:05:06"); + dest.seqnum = 3; + a.AddAddressUnit(dest); + Ptr packet = Create (); + packet->AddHeader (a); + IePerr b; + packet->RemoveHeader (b); + NS_TEST_ASSERT_EQUAL (a, b); + b.Merge(a); + NS_TEST_ASSERT_EQUAL (a, b); + // test FindFirst() + packet->AddHeader (a); + IePerr c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + return result; +} + +#endif // RUN_SELF_TESTS } // namespace dot11s } //namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-perr.h b/src/devices/mesh/dot11s/ie-dot11s-perr.h index 77f1155e0..9e14711db 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-perr.h +++ b/src/devices/mesh/dot11s/ie-dot11s-perr.h @@ -58,10 +58,12 @@ private: uint8_t DeserializeInformation (Buffer::Iterator start, uint8_t length); void PrintInformation (std::ostream& os) const; uint8_t GetInformationSize () const; +private: uint8_t m_numOfDest; std::vector m_addressUnits; + friend bool operator== (const IePerr & a, const IePerr & b); }; - + bool operator== (const IePerr & a, const IePerr & b); } // namespace dot11s } //namespace ns3 #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-prep.cc b/src/devices/mesh/dot11s/ie-dot11s-prep.cc index 6735f430b..3d9f8c351 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-prep.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-prep.cc @@ -23,6 +23,8 @@ #include "ns3/address-utils.h" #include "ns3/node.h" #include "ns3/assert.h" +#include "ns3/test.h" +#include "ns3/packet.h" namespace ns3 { namespace dot11s { /******************************** @@ -203,13 +205,70 @@ IePrep::GetInformationSize () const +1; //destination count return retval; }; - void IePrep::PrintInformation (std::ostream& os) const { //TODO } +bool operator== (const IePrep & a, const IePrep & b) +{ + return ( + (a.m_flags == b.m_flags) && + (a.m_hopcount == b.m_hopcount) && + (a.m_ttl == b.m_ttl) && + (a.m_destinationAddress == b.m_destinationAddress) && + (a.m_destSeqNumber == b.m_destSeqNumber) && + (a.m_lifetime == b.m_lifetime) && + (a.m_metric == b.m_metric) && + (a.m_originatorAddress == b.m_originatorAddress) && + (a.m_originatorSeqNumber == b.m_originatorSeqNumber) + ); +} + +#ifdef RUN_SELF_TESTS + +/// Built-in self test for IePrep +struct IePrepBist : public Test +{ + IePrepBist () : Test ("Mesh/802.11s/IE/PREP") {}; + virtual bool RunTests(); +}; + +/// Test instance +static IePrepBist g_IePrepBist; + +bool IePrepBist::RunTests () +{ + bool result(true); + // create test information element + IePrep a; + a.SetFlags (12); + a.SetHopcount (11); + a.SetTtl (10); + a.SetDestinationAddress (Mac48Address("11:22:33:44:55:66")); + a.SetDestinationSeqNumber (123); + a.SetLifetime (5000); + a.SetMetric (4321); + a.SetOriginatorAddress (Mac48Address("33:00:22:00:11:00")); + a.SetOriginatorSeqNumber (666); + // test roundtrip serialization + Ptr packet = Create (); + packet->AddHeader (a); + IePrep b; + packet->RemoveHeader (b); + NS_TEST_ASSERT_EQUAL (a, b); + // test FindFirst() + packet->AddHeader (a); + IePrep c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + return result; +} + +#endif // RUN_SELF_TESTS + } // namespace dot11s } //namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-prep.h b/src/devices/mesh/dot11s/ie-dot11s-prep.h index e253e6cd8..86167632c 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-prep.h +++ b/src/devices/mesh/dot11s/ie-dot11s-prep.h @@ -47,7 +47,7 @@ public: void SetLifetime (uint32_t lifetime); void SetMetric (uint32_t metric); void SetOriginatorAddress (Mac48Address originator_address); - void SetOriginatorSeqNumber (uint32_t originator_seg_number); + void SetOriginatorSeqNumber (uint32_t originator_seq_number); uint8_t GetFlags () const; uint8_t GetHopcount () const; @@ -69,6 +69,7 @@ private: uint8_t DeserializeInformation (Buffer::Iterator start, uint8_t length); uint8_t GetInformationSize () const; void PrintInformation (std::ostream& os) const; +private: uint8_t m_flags; uint8_t m_hopcount; uint8_t m_ttl; @@ -78,8 +79,9 @@ private: uint32_t m_metric; Mac48Address m_originatorAddress; uint32_t m_originatorSeqNumber; + friend bool operator== (const IePrep & a, const IePrep & b); }; - +bool operator== (const IePrep & a, const IePrep & b); } // namespace dot11s } //namespace ns3 #endif