From ede41dc54da4f919ab30133dbb87103e8c70908f Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Fri, 22 May 2009 17:27:10 +0400 Subject: [PATCH] Mesh ID is made separately from SSID --- examples/mesh.cc | 2 +- src/devices/mesh/dot11s/dot11s-helper.cc | 16 +- src/devices/mesh/dot11s/dot11s-helper.h | 7 +- src/devices/mesh/dot11s/ie-dot11s-id.cc | 157 ++++++++++++++++++ src/devices/mesh/dot11s/ie-dot11s-id.h | 70 ++++++++ src/devices/mesh/dot11s/peer-link-frame.cc | 37 ++--- src/devices/mesh/dot11s/peer-link-frame.h | 9 +- .../mesh/dot11s/peer-management-plugin.cc | 12 +- .../mesh/dot11s/peer-management-protocol.cc | 10 ++ .../mesh/dot11s/peer-management-protocol.h | 4 + src/devices/mesh/dot11s/wscript | 1 + src/devices/mesh/mesh-wifi-interface-mac.cc | 5 - src/devices/mesh/mesh-wifi-interface-mac.h | 2 - 13 files changed, 271 insertions(+), 61 deletions(-) create mode 100644 src/devices/mesh/dot11s/ie-dot11s-id.cc create mode 100644 src/devices/mesh/dot11s/ie-dot11s-id.h diff --git a/examples/mesh.cc b/examples/mesh.cc index 3870a97cd..d99c91842 100644 --- a/examples/mesh.cc +++ b/examples/mesh.cc @@ -138,7 +138,7 @@ MeshTest::CreateNodes () mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (nodes); if (pcap) - wifiPhy.EnablePcapAll (std::string ("mp-") + mesh.GetSsid ().PeekString ()); + wifiPhy.EnablePcapAll (std::string ("mp-")); } void MeshTest::InstallInternetStack () diff --git a/src/devices/mesh/dot11s/dot11s-helper.cc b/src/devices/mesh/dot11s/dot11s-helper.cc index 0d1d2c051..9953b9ca1 100644 --- a/src/devices/mesh/dot11s/dot11s-helper.cc +++ b/src/devices/mesh/dot11s/dot11s-helper.cc @@ -34,23 +34,10 @@ namespace ns3 { namespace dot11s { MeshWifiHelper::MeshWifiHelper () : - m_ssid("mesh"), m_randomStartDelay (Seconds (0)), m_spreadInterfaceChannels (false) { } - -void -MeshWifiHelper::SetSsid (Ssid const & s) -{ - m_ssid = s; -} - -Ssid MeshWifiHelper::GetSsid () const -{ - return m_ssid; -} - void MeshWifiHelper::SetRandomStartDelay (Time t) { @@ -71,7 +58,7 @@ MeshWifiHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr node) // Creating MAC for this interface Ptr mac = CreateObject (); - mac->SetSsid (m_ssid); + mac->SetSsid (Ssid ()); if (m_randomStartDelay > Seconds (0)) mac->SetRandomStartDelay (m_randomStartDelay); Ptr manager = CreateObject (); @@ -130,6 +117,7 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c, std:: // Install 802.11s protocols Ptr pmp = CreateObject (); + pmp->SetMeshId("mesh",4); bool install_ok = pmp->Install (mp); NS_ASSERT (install_ok); diff --git a/src/devices/mesh/dot11s/dot11s-helper.h b/src/devices/mesh/dot11s/dot11s-helper.h index 7b7c9298a..d50c9f58a 100644 --- a/src/devices/mesh/dot11s/dot11s-helper.h +++ b/src/devices/mesh/dot11s/dot11s-helper.h @@ -24,10 +24,10 @@ #define _MESHWIFIHELPER_H #include "ns3/wifi-helper.h" -#include "ns3/ssid.h" #include "ns3/nstime.h" #include "ns3/peer-management-protocol.h" #include "ns3/hwmp-protocol.h" +#include "ie-dot11s-id.h" namespace ns3 { namespace dot11s { @@ -43,10 +43,6 @@ class MeshWifiHelper { public: MeshWifiHelper (); - /// Set mesh SSID - void SetSsid (const Ssid &); - /// Get mesh SSID - Ssid GetSsid () const; /// Set maximum random start delay void SetRandomStartDelay (Time delay); /** @@ -82,7 +78,6 @@ public: static void Report (const ns3::Ptr&, std::ostream&); static void ResetStats (const ns3::Ptr&); private: - Ssid m_ssid; Time m_randomStartDelay; bool m_spreadInterfaceChannels; diff --git a/src/devices/mesh/dot11s/ie-dot11s-id.cc b/src/devices/mesh/dot11s/ie-dot11s-id.cc new file mode 100644 index 000000000..c98eb2448 --- /dev/null +++ b/src/devices/mesh/dot11s/ie-dot11s-id.cc @@ -0,0 +1,157 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008,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: Kirill Andreev + */ + +#include "ie-dot11s-id.h" +#include "ns3/assert.h" + +namespace ns3 { +namespace dot11s { +IeMeshId::IeMeshId () +{ + for (uint8_t i = 0; i < 32; i++) + { + m_meshId[i] = 0; + } +} +IeMeshId::IeMeshId (char const meshId[32], uint8_t length) +{ + NS_ASSERT (length <= 32); + uint8_t len = 0; + while (len < length) + { + m_meshId[len] = meshId[len]; + len++; + } + while (len < 32) + { + m_meshId[len] = 0; + len++; + } +} +bool +IeMeshId::IsEqual (IeMeshId const &o) const +{ + uint8_t i = 0; + while (i < 32 && + m_meshId[i] == o.m_meshId[i] && + m_meshId[i] != 0) + { + i++; + } + if (m_meshId[i] != o.m_meshId[i]) + { + return false; + } + return true; +} +bool +IeMeshId::IsBroadcast (void) const +{ + if (m_meshId[0] == 0) + { + return true; + } + return false; +} +char * +IeMeshId::PeekString (void) const +{ + return (char *)m_meshId; +} +uint8_t +IeMeshId::GetInformationSize (void) const +{ + uint8_t size = 0; + while (m_meshId[size] != 0 && size < 32) + { + size++; + } + NS_ASSERT (size <= 32); + return size; +} +void +IeMeshId::SerializeInformation (Buffer::Iterator i) const +{ + uint8_t size = 0; + while (m_meshId[size] != 0 && size < 32) + { + i.WriteU8 (m_meshId [size]); + size ++; + } +} +uint8_t +IeMeshId::DeserializeInformation (Buffer::Iterator start, uint8_t length) +{ + Buffer::Iterator i = start; + NS_ASSERT (length <= 32); + i.Read (m_meshId, length); + m_meshId[length] = 0; + return i.GetDistanceFrom(start); +} +void +IeMeshId::PrintInformation (std::ostream& os) const +{ + //TODO +} +bool operator== (const IeMeshId & a, const IeMeshId & b) +{ + bool result (true); + uint8_t size = 0; + + while(size < 32) + { + result = result && (a.m_meshId[size] == b.m_meshId[size]); + if(a.m_meshId[size] == 0) + return result; + size ++; + } + return result; +}; + +std::ostream & +operator << (std::ostream &os, const IeMeshId &meshId) +{ + os << meshId.PeekString (); + return os; +} +#ifdef RUN_SELF_TESTS + +/// Built-in self test for IeMeshId +struct IeMeshIdBist : public IeTest +{ + IeMeshIdBist () : IeTest ("Mesh/802.11s/IE/MESH_ID") {} + virtual bool RunTests(); +}; + +/// Test instance +static IeMeshIdBist g_IeMeshIdBist; + +bool IeMeshIdBist::RunTests () +{ + bool result(true); + + // create test information element + IeMeshId a("qwerty",6); + result = result && TestRoundtripSerialization (a); + return result; +} +#endif // RUN_SELF_TESTS +} //namespace dot11s +} // namespace ns3 diff --git a/src/devices/mesh/dot11s/ie-dot11s-id.h b/src/devices/mesh/dot11s/ie-dot11s-id.h new file mode 100644 index 000000000..0be00e2de --- /dev/null +++ b/src/devices/mesh/dot11s/ie-dot11s-id.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008,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: Kirill Andreev + */ + +#ifndef MESH_ID_H +#define MESH_ID_H + +#include +#include "ns3/buffer.h" +#include "ns3/wifi-information-element.h" + +namespace ns3 { +namespace dot11s { +/** + * \brief a IEEE 802.11s Mesh ID 7.3.287 of 802.11s draft 3.0 + * + */ +class IeMeshId : public WifiInformationElement +{ +public: + // broadcast meshId + IeMeshId (); + //IeMeshId (char const meshId[32]); + IeMeshId (char const meshId[32], uint8_t length); + + bool IsEqual (IeMeshId const &o) const; + bool IsBroadcast (void) const; + + uint32_t GetLength (void) const; + char *PeekString (void) const; +private: + WifiElementId ElementId () const{ + return IE11S_MESH_ID; + }; + void SerializeInformation (Buffer::Iterator i) const; + uint8_t DeserializeInformation (Buffer::Iterator start, uint8_t length); + void PrintInformation (std::ostream& os) const; + uint8_t GetInformationSize () const; +private: + uint8_t m_meshId[33]; + friend bool operator== (const IeMeshId & a, const IeMeshId & b); +}; + +std::ostream &operator << (std::ostream &os, const IeMeshId &meshId); + +/** + * \class ns3::IeMeshIdValue + * \brief hold objects of type ns3::IeMeshId + */ + +ATTRIBUTE_HELPER_HEADER (IeMeshId); +} //namespace dot11s +} // namespace ns3 +#endif /* MESH_ID_H */ diff --git a/src/devices/mesh/dot11s/peer-link-frame.cc b/src/devices/mesh/dot11s/peer-link-frame.cc index 91fe4f924..8ada64758 100644 --- a/src/devices/mesh/dot11s/peer-link-frame.cc +++ b/src/devices/mesh/dot11s/peer-link-frame.cc @@ -33,7 +33,7 @@ PeerLinkFrameStart::PeerLinkFrameStart (): m_capability (0), m_aid (0), m_rates (SupportedRates()), - m_meshId (Ssid()), + m_meshId (IeMeshId()), m_config(IeConfiguration ()), m_reasonCode ((uint16_t)REASON11S_RESERVED) { @@ -61,7 +61,6 @@ PeerLinkFrameStart::SetPlinkFrameStart(PeerLinkFrameStart::PlinkFrameStartFields else m_reasonCode = fields.reasonCode; } - PeerLinkFrameStart::PlinkFrameStartFields PeerLinkFrameStart::GetFields () { @@ -76,18 +75,6 @@ PeerLinkFrameStart::GetFields () retval.reasonCode = m_reasonCode; return retval; } - -bool -PeerLinkFrameStart::CheckPlinkFrameStart(Ptr mac) -{ - bool retval; - retval = mac->CheckSupportedRates(m_rates); - if(! retval) - return retval; - retval = mac->CheckMeshId(m_meshId); - return true; -} - TypeId PeerLinkFrameStart::GetTypeId () { @@ -98,7 +85,6 @@ PeerLinkFrameStart::GetTypeId () ; return tid; } - TypeId PeerLinkFrameStart::GetInstanceTypeId () const { @@ -115,7 +101,6 @@ PeerLinkFrameStart::Print (std::ostream &os) const << "\nconfiguration = " << m_config << "\nreason code = " << m_reasonCode; } - uint32_t PeerLinkFrameStart::GetSerializedSize () const { @@ -135,7 +120,6 @@ PeerLinkFrameStart::GetSerializedSize () const size += 2; //reasonCode return size; } - void PeerLinkFrameStart::Serialize (Buffer::Iterator start) const { @@ -150,7 +134,10 @@ PeerLinkFrameStart::Serialize (Buffer::Iterator start) const if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CLOSE) != m_subtype) i = m_rates.Serialize (i); if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CONFIRM) != m_subtype) - i = m_meshId.Serialize (i); + { + m_meshId.Serialize (i); + i.Next(m_meshId.GetSerializedSize ()); + } if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CLOSE) != m_subtype) { m_config.Serialize (i); @@ -159,7 +146,6 @@ PeerLinkFrameStart::Serialize (Buffer::Iterator start) const else i.WriteHtolsbU16(m_reasonCode); } - uint32_t PeerLinkFrameStart::Deserialize (Buffer::Iterator start) { @@ -174,7 +160,10 @@ PeerLinkFrameStart::Deserialize (Buffer::Iterator start) if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CLOSE) != m_subtype) i = m_rates.Deserialize (i); if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CONFIRM) != m_subtype) - i = m_meshId.Deserialize (i); + { + m_meshId.Deserialize (i); + i.Next(m_meshId.GetSerializedSize ()); + } if ((uint8_t)(WifiMeshActionHeader::PEER_LINK_CLOSE) != m_subtype) { m_config.Deserialize (i); @@ -196,14 +185,12 @@ bool operator== (const PeerLinkFrameStart & a, const PeerLinkFrameStart & b) ); } #ifdef RUN_SELF_TESTS - /// Built-in self test for PeerLinkFrameStart struct PeerLinkFrameStartBist : public Test { PeerLinkFrameStartBist () : Test ("Mesh/802.11s/IE/PeerLinkFrameStart") {} virtual bool RunTests(); }; - /// Test instance static PeerLinkFrameStartBist g_PeerLinkFrameStartBist; @@ -216,7 +203,7 @@ bool PeerLinkFrameStartBist::RunTests () fields.subtype = (uint8_t)(WifiMeshActionHeader::PEER_LINK_OPEN); fields.aid = 101; fields.reasonCode = 12; - fields.meshId = Ssid("qwertyuiop"); + fields.meshId = IeMeshId("qwertyuiop", 10); a.SetPlinkFrameStart(fields); Ptr packet = Create (); packet->AddHeader (a); @@ -231,7 +218,7 @@ bool PeerLinkFrameStartBist::RunTests () fields.subtype = (uint8_t)(WifiMeshActionHeader::PEER_LINK_CONFIRM); fields.aid = 1234; fields.reasonCode = 12; - fields.meshId = Ssid("qwerty"); + fields.meshId = IeMeshId("qwerty", 6); a.SetPlinkFrameStart(fields); Ptr packet = Create (); packet->AddHeader (a); @@ -245,7 +232,7 @@ bool PeerLinkFrameStartBist::RunTests () PeerLinkFrameStart::PlinkFrameStartFields fields; fields.subtype = (uint8_t)(WifiMeshActionHeader::PEER_LINK_CLOSE); fields.aid = 10; - fields.meshId = Ssid("qqq"); + fields.meshId = IeMeshId("qqq", 3); fields.reasonCode = 12; a.SetPlinkFrameStart(fields); Ptr packet = Create (); diff --git a/src/devices/mesh/dot11s/peer-link-frame.h b/src/devices/mesh/dot11s/peer-link-frame.h index 738dd0905..733aa70e5 100644 --- a/src/devices/mesh/dot11s/peer-link-frame.h +++ b/src/devices/mesh/dot11s/peer-link-frame.h @@ -22,10 +22,10 @@ #define PEER_LINK_FRAME_START_H #include "ns3/header.h" #include "ns3/supported-rates.h" -#include "ns3/ssid.h" #include "dot11s-mac-header.h" #include "ie-dot11s-configuration.h" #include "ie-dot11s-peering-protocol.h" +#include "ie-dot11s-id.h" namespace ns3 { class MeshWifiInterfaceMac; namespace dot11s { @@ -38,7 +38,7 @@ namespace dot11s { * - Subtype field * - Association ID field * - Supported rates - * - SSID of mesh + * - Mesh ID of mesh */ class PeerLinkFrameStart : public Header { @@ -52,7 +52,7 @@ public: uint16_t capability; //open and confirm uint16_t aid; //confirm only SupportedRates rates; //open and confirm - Ssid meshId; //open and close + IeMeshId meshId; //open and close IeConfiguration config; //open and confirm uint16_t reasonCode; //close only }; @@ -61,7 +61,6 @@ public: void SetPlinkFrameSubtype(uint8_t subtype); void SetPlinkFrameStart(PlinkFrameStartFields); PlinkFrameStartFields GetFields (); - bool CheckPlinkFrameStart(Ptr mac); /** \name Inherited from header: * \{ */ @@ -80,7 +79,7 @@ private: uint16_t m_capability; uint16_t m_aid; SupportedRates m_rates; - Ssid m_meshId; + IeMeshId m_meshId; IeConfiguration m_config; uint16_t m_reasonCode; diff --git a/src/devices/mesh/dot11s/peer-management-plugin.cc b/src/devices/mesh/dot11s/peer-management-plugin.cc index 0ee2a906a..9f6f0d88a 100644 --- a/src/devices/mesh/dot11s/peer-management-plugin.cc +++ b/src/devices/mesh/dot11s/peer-management-plugin.cc @@ -54,11 +54,16 @@ PeerManagerMacPlugin::Receive (Ptr const_packet, const WifiMacHeader & h if(header.IsBeacon()) { IeBeaconTiming beaconTiming; + IeMeshId meshId; Ptr myBeacon = packet->Copy(); MgtBeaconHeader beacon_hdr; myBeacon->RemoveHeader(beacon_hdr); + meshId.FindFirst(myBeacon); bool meshBeacon = false; - if(beaconTiming.FindFirst(myBeacon)) + if ( + (beaconTiming.FindFirst(myBeacon)) && + (m_protocol->GetMeshId ()->IsEqual(meshId)) + ) meshBeacon = true; m_protocol->UpdatePeerBeaconTiming( m_ifIndex, @@ -103,7 +108,7 @@ PeerManagerMacPlugin::Receive (Ptr const_packet, const WifiMacHeader & h } if ( (actionValue.peerLink != WifiMeshActionHeader::PEER_LINK_CONFIRM) && - !fields.meshId.IsEqual(m_parent->GetSsid()) + !fields.meshId.IsEqual(*(m_protocol->GetMeshId())) ) { m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress); @@ -165,6 +170,7 @@ PeerManagerMacPlugin::UpdateBeacon (MeshWifiBeacon & beacon) const { Ptr beaconTiming = m_protocol->GetBeaconTimingElement(m_ifIndex); beacon.AddInformationElement(beaconTiming); + beacon.AddInformationElement(m_protocol->GetMeshId ()); } void @@ -182,7 +188,7 @@ PeerManagerMacPlugin::SendPeerLinkManagementFrame( packet->AddHeader (peerElement); PeerLinkFrameStart::PlinkFrameStartFields fields; fields.rates = m_parent->GetSupportedRates (); - fields.meshId = m_parent->GetSsid (); + fields.meshId = *(m_protocol->GetMeshId ()); fields.config = meshConfig; PeerLinkFrameStart plinkFrame; //Create an 802.11 frame header: diff --git a/src/devices/mesh/dot11s/peer-management-protocol.cc b/src/devices/mesh/dot11s/peer-management-protocol.cc index e171f8362..e9805a9fe 100644 --- a/src/devices/mesh/dot11s/peer-management-protocol.cc +++ b/src/devices/mesh/dot11s/peer-management-protocol.cc @@ -472,6 +472,16 @@ PeerManagementProtocol::GetNumberOfLinks () { return m_numberOfActivePeers; } +Ptr +PeerManagementProtocol::GetMeshId () const +{ + return m_meshId; +} +void +PeerManagementProtocol::SetMeshId(char const meshId[32], uint8_t length) +{ + m_meshId = Create (meshId, length); +} Mac48Address PeerManagementProtocol::GetAddress () { diff --git a/src/devices/mesh/dot11s/peer-management-protocol.h b/src/devices/mesh/dot11s/peer-management-protocol.h index f8d995450..e520ee842 100644 --- a/src/devices/mesh/dot11s/peer-management-protocol.h +++ b/src/devices/mesh/dot11s/peer-management-protocol.h @@ -29,6 +29,7 @@ #include "ns3/nstime.h" #include "ie-dot11s-beacon-timing.h" #include "ie-dot11s-peer-management.h" +#include "ie-dot11s-id.h" #include namespace ns3 { @@ -136,6 +137,8 @@ public: Mac48Address GetAddress (); ///\Needed to fill mesh configuration uint8_t GetNumberOfLinks (); + void SetMeshId (char const meshId[32], uint8_t length); + Ptr GetMeshId() const; ///\brief: Report statistics void Report (std::ostream &) const; void ResetStats (); @@ -192,6 +195,7 @@ private: private: PeerManagerPluginMap m_plugins; Mac48Address m_address; + Ptr m_meshId; /** * \name Information related to beacons: * \{ diff --git a/src/devices/mesh/dot11s/wscript b/src/devices/mesh/dot11s/wscript index ccf298f53..7629368c1 100644 --- a/src/devices/mesh/dot11s/wscript +++ b/src/devices/mesh/dot11s/wscript @@ -5,6 +5,7 @@ def build(bld): obj.source = [ 'ie-dot11s-beacon-timing.cc', 'ie-dot11s-configuration.cc', + 'ie-dot11s-id.cc', 'ie-dot11s-peer-management.cc', 'ie-dot11s-preq.cc', 'ie-dot11s-prep.cc', diff --git a/src/devices/mesh/mesh-wifi-interface-mac.cc b/src/devices/mesh/mesh-wifi-interface-mac.cc index 9b970cc78..9039cd5f3 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac.cc +++ b/src/devices/mesh/mesh-wifi-interface-mac.cc @@ -449,11 +449,6 @@ MeshWifiInterfaceMac::GetSupportedRates () const return rates; } bool -MeshWifiInterfaceMac::CheckMeshId(Ssid meshId) const -{ - return true; -} -bool MeshWifiInterfaceMac::CheckSupportedRates(SupportedRates rates) const { for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++) diff --git a/src/devices/mesh/mesh-wifi-interface-mac.h b/src/devices/mesh/mesh-wifi-interface-mac.h index b32e4595f..58f7d0bed 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac.h +++ b/src/devices/mesh/mesh-wifi-interface-mac.h @@ -145,8 +145,6 @@ public: /// To be used by plugins sending management frames. void SendManagementFrame(Ptr frame, const WifiMacHeader& hdr); - /// \return true if meshId is correct Ssid - bool CheckMeshId(Ssid meshId) const; /// \return true if rates are supported bool CheckSupportedRates(SupportedRates rates) const; /// \return list of supported bitrates