From a09c1311a8e8a8fd0366189f9691e9d363b2db2d Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Fri, 31 Jul 2009 17:08:42 +0400 Subject: [PATCH] Removed FindFirst from WifiInformationElement --- .../mesh/dot11s/ie-dot11s-peer-management.cc | 2 +- .../dot11s/peer-management-protocol-mac.cc | 2 +- src/devices/mesh/mesh-wifi-beacon.cc | 26 +----- src/devices/mesh/mesh-wifi-beacon.h | 29 +++---- ....cc => wifi-information-element-vector.cc} | 82 ++++++++++++++++++- ...or.h => wifi-information-element-vector.h} | 5 +- src/devices/mesh/wscript | 4 +- 7 files changed, 105 insertions(+), 45 deletions(-) rename src/devices/mesh/{ie-vector.cc => wifi-information-element-vector.cc} (68%) rename src/devices/mesh/{ie-vector.h => wifi-information-element-vector.h} (88%) diff --git a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc index 26ae0217f..bf1c28d1d 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc @@ -28,7 +28,7 @@ namespace ns3 { namespace dot11s { IePeerManagement::IePeerManagement () : - m_length (0), m_subtype (PEER_OPEN), m_localLinkId (0), m_peerLinkId (0), m_reasonCode (REASON11S_RESERVED) + m_length (3), m_subtype (PEER_OPEN), m_localLinkId (0), m_peerLinkId (0), m_reasonCode (REASON11S_RESERVED) { } WifiElementId diff --git a/src/devices/mesh/dot11s/peer-management-protocol-mac.cc b/src/devices/mesh/dot11s/peer-management-protocol-mac.cc index 6a23b9b75..7e6a28141 100644 --- a/src/devices/mesh/dot11s/peer-management-protocol-mac.cc +++ b/src/devices/mesh/dot11s/peer-management-protocol-mac.cc @@ -27,7 +27,7 @@ #include "ns3/mesh-wifi-interface-mac.h" #include "ns3/simulator.h" #include "ns3/wifi-mac-header.h" -#include "ns3/ie-vector.h" +#include "ns3/wifi-information-element-vector.h" #include "ns3/log.h" namespace ns3 { namespace dot11s { diff --git a/src/devices/mesh/mesh-wifi-beacon.cc b/src/devices/mesh/mesh-wifi-beacon.cc index 445c869b7..6efcbd816 100644 --- a/src/devices/mesh/mesh-wifi-beacon.cc +++ b/src/devices/mesh/mesh-wifi-beacon.cc @@ -19,7 +19,7 @@ */ #include "ns3/mesh-wifi-beacon.h" -#include + namespace ns3 { @@ -32,32 +32,14 @@ MeshWifiBeacon::MeshWifiBeacon (Ssid ssid, SupportedRates rates, uint64_t us) void MeshWifiBeacon::AddInformationElement (Ptr ie) { - m_elements.push_back (ie); -} -namespace { -/// aux sorter for Ptr -struct PIEComparator -{ - bool - operator () (Ptr a, Ptr b) const - { - return ((*PeekPointer (a)) < (*PeekPointer (b))); - } -}; + m_elements.AddInformationElement (ie); } + Ptr MeshWifiBeacon::CreatePacket () { - Ptr packet = Create (); - - std::sort (m_elements.begin (), m_elements.end (), PIEComparator ()); - - std::vector >::const_reverse_iterator i; - for (i = m_elements.rbegin (); i != m_elements.rend (); ++i) - { - packet->AddHeader (**i); - } + Ptr packet = m_elements.CreatePacket(); packet->AddHeader (BeaconHeader ()); return packet; } diff --git a/src/devices/mesh/mesh-wifi-beacon.h b/src/devices/mesh/mesh-wifi-beacon.h index 271160bbc..3a038f6b3 100644 --- a/src/devices/mesh/mesh-wifi-beacon.h +++ b/src/devices/mesh/mesh-wifi-beacon.h @@ -1,7 +1,7 @@ /* -*- 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; @@ -14,7 +14,7 @@ * 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 */ @@ -26,6 +26,7 @@ #include "ns3/wifi-information-element.h" #include "ns3/mgt-headers.h" // from wifi module #include "ns3/wifi-mac-header.h" +#include "ns3/wifi-information-element-vector.h" #include @@ -33,16 +34,16 @@ namespace ns3 { /** * \brief Beacon is beacon header + list of arbitrary information elements - * + * * It is supposed that distinct mesh protocols can use beacons to transport * their own information elements. */ class MeshWifiBeacon { public: - /** + /** * C-tor - * + * * \param ssid is SSID for beacon header * \param rates is a set of supported rates * \param us beacon interval in microseconds @@ -52,22 +53,22 @@ public: MgtBeaconHeader BeaconHeader () const { return m_header; } /// Add information element void AddInformationElement (Ptr ie); - - /** - * Create wifi header for beacon frame. - * - * \param address is sender address + + /** + * Create wifi header for beacon frame. + * + * \param address is sender address * \param mpAddress is mesh point address */ WifiMacHeader CreateHeader (Mac48Address address, Mac48Address mpAddress); /// Create frame = { beacon header + all information elements sorted by ElementId () } Ptr CreatePacket (); - + private: /// Beacon header MgtBeaconHeader m_header; - /// List of information elements added - std::vector< Ptr > m_elements; + /// List of information elements added + WifiInformationElementVector m_elements; }; } diff --git a/src/devices/mesh/ie-vector.cc b/src/devices/mesh/wifi-information-element-vector.cc similarity index 68% rename from src/devices/mesh/ie-vector.cc rename to src/devices/mesh/wifi-information-element-vector.cc index a12f3dacd..d9570dbf7 100644 --- a/src/devices/mesh/ie-vector.cc +++ b/src/devices/mesh/wifi-information-element-vector.cc @@ -18,9 +18,10 @@ * Author: Pavel Boyko */ -#include "ie-vector.h" +#include "wifi-information-element-vector.h" #include "ns3/test.h" #include "ns3/packet.h" +#include // All information elements: #include "dot11s/ie-dot11s-beacon-timing.h" #include "dot11s/ie-dot11s-configuration.h" @@ -120,6 +121,7 @@ WifiInformationElementVector::DeserializePacket (Ptr packet) break; default: NS_FATAL_ERROR ("Information element " << (uint16_t) ie.GetElementId () << " is not implemented"); + return retval; } packet->RemoveHeader (*newElement); if (!retval.AddInformationElement (newElement)) @@ -133,15 +135,26 @@ WifiInformationElementVector::DeserializePacket (Ptr packet) } return retval; } +namespace { +struct PIEComparator +{ + bool + operator () (Ptr a, Ptr b) const + { + return ((*PeekPointer (a)) < (*PeekPointer (b))); + } +}; +} Ptr -WifiInformationElementVector::MakePacket (bool sortByElementId) +WifiInformationElementVector::CreatePacket (bool sortByElementId) { if (sortByElementId) { - //TODO: sort + std::sort (m_elements.begin (), m_elements.end (), PIEComparator ()); } Ptr packet = Create (); - for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++) + std::vector >::const_reverse_iterator i; + for (i = m_elements.rbegin (); i != m_elements.rend (); ++i) { packet->AddHeader (**i); } @@ -209,4 +222,65 @@ void WifiInformationElementVector::EmptyIe::Print (std::ostream &os) const { } +bool +operator== (const WifiInformationElementVector & a, const WifiInformationElementVector & b) +{ + if (a.m_elements.size () != b.m_elements.size ()) + { + NS_ASSERT(false); + return false; + } + WifiInformationElementVector::IE_VECTOR::const_iterator j = b.m_elements.begin (); + for (WifiInformationElementVector::IE_VECTOR::const_iterator i = a.m_elements.begin (); i + != a.m_elements.end (); i++, j++) + { + if ((*i)->ElementId () != (*j)->ElementId ()) + { + return false; + } + if ((*i)->GetSerializedSize () != (*j)->GetSerializedSize ()) + { + return false; + } + } + return true; } +#ifdef RUN_SELF_TESTS + +/// Built-in self test for WifiInformationElementVector +struct WifiInformationElementVectorBist : public IeTest +{ + WifiInformationElementVectorBist () : + IeTest ("Mesh/WifiInformationElementVector") + { + }; + virtual bool + RunTests (); +}; + +/// Test instance +static WifiInformationElementVectorBist g_IePrepBist; + +bool +WifiInformationElementVectorBist::RunTests () +{ + bool result = true; + WifiInformationElementVector vector; + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + vector.AddInformationElement (Create ()); + Ptr packet = vector.CreatePacket (false); + WifiInformationElementVector resultVector = WifiInformationElementVector::DeserializePacket (packet); + NS_TEST_ASSERT (vector == resultVector); + + return result; +} + +#endif // RUN_SELF_TESTS +} //namespace ns3 diff --git a/src/devices/mesh/ie-vector.h b/src/devices/mesh/wifi-information-element-vector.h similarity index 88% rename from src/devices/mesh/ie-vector.h rename to src/devices/mesh/wifi-information-element-vector.h index f4004ca56..c0a513bb6 100644 --- a/src/devices/mesh/ie-vector.h +++ b/src/devices/mesh/wifi-information-element-vector.h @@ -44,7 +44,8 @@ public: bool AddInformationElement (Ptr element); Ptr FindFirst (enum WifiElementId id) const; static WifiInformationElementVector DeserializePacket (Ptr packet); - Ptr MakePacket (bool sortByElementId = true); + Ptr CreatePacket (bool sortByElementId = true); + void Print (std::ostream & os); private: uint32_t GetSize () const; /** @@ -72,6 +73,8 @@ private: IE_VECTOR m_elements; /// Size in bytes (actually, max packet length) uint16_t m_maxSize; + friend bool operator== (const WifiInformationElementVector & a, const WifiInformationElementVector & b); }; +bool operator== (const WifiInformationElementVector & a, const WifiInformationElementVector & b); } #endif diff --git a/src/devices/mesh/wscript b/src/devices/mesh/wscript index 6e5022a25..833db6b8a 100644 --- a/src/devices/mesh/wscript +++ b/src/devices/mesh/wscript @@ -5,7 +5,7 @@ def build(bld): obj.source = [ 'wifi-information-element.cc', - 'ie-vector.cc', + 'wifi-information-element-vector.cc', 'mesh-point-device.cc', 'mesh-l2-routing-protocol.cc', 'mesh-wifi-beacon.cc', @@ -15,7 +15,7 @@ def build(bld): headers.module = 'mesh' headers.source = [ 'wifi-information-element.h', - 'ie-vector.h', + 'wifi-information-element-vector.h', 'mesh-point-device.h', 'mesh-l2-routing-protocol.h', 'mesh-wifi-beacon.h',