Removed FindFirst from WifiInformationElement

This commit is contained in:
Kirill Andreev
2009-07-31 17:08:42 +04:00
parent 11fdc00dd7
commit a09c1311a8
7 changed files with 105 additions and 45 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -19,7 +19,7 @@
*/
#include "ns3/mesh-wifi-beacon.h"
#include <algorithm>
namespace ns3 {
@@ -32,32 +32,14 @@ MeshWifiBeacon::MeshWifiBeacon (Ssid ssid, SupportedRates rates, uint64_t us)
void
MeshWifiBeacon::AddInformationElement (Ptr<WifiInformationElement> ie)
{
m_elements.push_back (ie);
}
namespace {
/// aux sorter for Ptr<WifiInformationElement>
struct PIEComparator
{
bool
operator () (Ptr<WifiInformationElement> a, Ptr<WifiInformationElement> b) const
{
return ((*PeekPointer (a)) < (*PeekPointer (b)));
}
};
m_elements.AddInformationElement (ie);
}
Ptr<Packet>
MeshWifiBeacon::CreatePacket ()
{
Ptr<Packet> packet = Create<Packet> ();
std::sort (m_elements.begin (), m_elements.end (), PIEComparator ());
std::vector<Ptr<WifiInformationElement> >::const_reverse_iterator i;
for (i = m_elements.rbegin (); i != m_elements.rend (); ++i)
{
packet->AddHeader (**i);
}
Ptr<Packet> packet = m_elements.CreatePacket();
packet->AddHeader (BeaconHeader ());
return packet;
}

View File

@@ -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 <boyko@iitp.ru>
*/
@@ -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 <vector>
@@ -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<WifiInformationElement> 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<Packet> CreatePacket ();
private:
/// Beacon header
MgtBeaconHeader m_header;
/// List of information elements added
std::vector< Ptr<WifiInformationElement> > m_elements;
/// List of information elements added
WifiInformationElementVector m_elements;
};
}

View File

@@ -18,9 +18,10 @@
* Author: Pavel Boyko <boyko@iitp.ru>
*/
#include "ie-vector.h"
#include "wifi-information-element-vector.h"
#include "ns3/test.h"
#include "ns3/packet.h"
#include <algorithm>
// All information elements:
#include "dot11s/ie-dot11s-beacon-timing.h"
#include "dot11s/ie-dot11s-configuration.h"
@@ -120,6 +121,7 @@ WifiInformationElementVector::DeserializePacket (Ptr<Packet> 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> packet)
}
return retval;
}
namespace {
struct PIEComparator
{
bool
operator () (Ptr<WifiInformationElement> a, Ptr<WifiInformationElement> b) const
{
return ((*PeekPointer (a)) < (*PeekPointer (b)));
}
};
}
Ptr<Packet>
WifiInformationElementVector::MakePacket (bool sortByElementId)
WifiInformationElementVector::CreatePacket (bool sortByElementId)
{
if (sortByElementId)
{
//TODO: sort
std::sort (m_elements.begin (), m_elements.end (), PIEComparator ());
}
Ptr<Packet> packet = Create<Packet> ();
for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
std::vector<Ptr<WifiInformationElement> >::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<dot11s::IeMeshId> ());
vector.AddInformationElement (Create<dot11s::IeConfiguration> ());
vector.AddInformationElement (Create<dot11s::IeLinkMetricReport> ());
vector.AddInformationElement (Create<dot11s::IePeerManagement> ());
vector.AddInformationElement (Create<dot11s::IeBeaconTiming> ());
vector.AddInformationElement (Create<dot11s::IeRann> ());
vector.AddInformationElement (Create<dot11s::IePreq> ());
vector.AddInformationElement (Create<dot11s::IePrep> ());
vector.AddInformationElement (Create<dot11s::IePerr> ());
Ptr<Packet> packet = vector.CreatePacket (false);
WifiInformationElementVector resultVector = WifiInformationElementVector::DeserializePacket (packet);
NS_TEST_ASSERT (vector == resultVector);
return result;
}
#endif // RUN_SELF_TESTS
} //namespace ns3

View File

@@ -44,7 +44,8 @@ public:
bool AddInformationElement (Ptr<WifiInformationElement> element);
Ptr<WifiInformationElement> FindFirst (enum WifiElementId id) const;
static WifiInformationElementVector DeserializePacket (Ptr<Packet> packet);
Ptr<Packet> MakePacket (bool sortByElementId = true);
Ptr<Packet> 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

View File

@@ -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',