From ab4bb7cc72c7d916417cb2b7f8727700aa0575ba Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Thu, 19 Mar 2009 20:09:50 +0300 Subject: [PATCH] Peer manager restructure - unfinished --- examples/mesh.cc | 2 + src/devices/mesh/mesh-wifi-helper.cc | 33 +++++++++++-- src/devices/mesh/mesh-wifi-helper.h | 13 +++++ src/devices/mesh/peer-manager-plugin.cc | 21 +++++++- src/devices/mesh/peer-manager-plugin.h | 3 ++ src/devices/mesh/peer-manager-protocol.cc | 50 +++++++++++++++++++- src/devices/mesh/peer-manager-protocol.h | 26 +++++----- src/devices/mesh/wifi-information-element.cc | 25 +++++++++- src/devices/mesh/wifi-information-element.h | 7 ++- 9 files changed, 160 insertions(+), 20 deletions(-) diff --git a/examples/mesh.cc b/examples/mesh.cc index 9b9487055..256ec2537 100644 --- a/examples/mesh.cc +++ b/examples/mesh.cc @@ -67,6 +67,8 @@ main (int argc, char *argv[]) "Ssid", SsidValue (ssid), "RandomStart", TimeValue (Seconds (randomStart)) ); + //wifi.SetPeerManager("ns3::WifiPeerManager"); + wifi.SetPeerManager("ns3::Dot11sPeerManagerProtocol"); wifi.SetL2RoutingNetDevice ("ns3::MeshPointDevice"); meshDevices = wifi.Install (wifiPhy,nodes); // Installing Mobility. diff --git a/src/devices/mesh/mesh-wifi-helper.cc b/src/devices/mesh/mesh-wifi-helper.cc index 710d9c8fa..6f5e173df 100644 --- a/src/devices/mesh/mesh-wifi-helper.cc +++ b/src/devices/mesh/mesh-wifi-helper.cc @@ -27,7 +27,7 @@ #include "ns3/wifi-channel.h" #include "ns3/wifi-remote-station-manager.h" #include "ns3/mesh-wifi-interface-mac.h" -#include "ns3/peer-manager-plugin.h" +//#include "ns3/peer-manager-plugin.h" namespace ns3 { @@ -84,6 +84,29 @@ MeshWifiHelper::SetMac (std::string type, m_meshMac.Set (n6, v6); m_meshMac.Set (n7, v7); } +void +MeshWifiHelper::SetPeerManager (std::string type, + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) +{ + m_peerMan = ObjectFactory (); + m_peerMan.SetTypeId (type); + m_peerMan.Set (n0, v0); + m_peerMan.Set (n1, v1); + m_peerMan.Set (n2, v2); + m_peerMan.Set (n3, v3); + m_peerMan.Set (n4, v4); + m_peerMan.Set (n5, v5); + m_peerMan.Set (n6, v6); + m_peerMan.Set (n7, v7); +} + void MeshWifiHelper::SetL2RoutingNetDevice (std::string type, std::string n0, const AttributeValue &v0, @@ -115,17 +138,21 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const { Ptr node = *i; Ptr mp = m_deviceFactory.Create (); + std::vector >ports; devices.Add (mp); std::vector > nodeDevices; Ptr device = CreateObject (); + ports.push_back(device); Ptr mac = m_meshMac.Create (); - Ptr peer_plugin = Create(); - mac->InstallPlugin(peer_plugin); + // Ptr peer_plugin = Create(); + // mac->InstallPlugin(peer_plugin); Ptr manager = m_stationManager.Create (); Ptr phy = phyHelper.Create (node, device); mac->SetAddress (Mac48Address::Allocate ()); device->SetMac (mac); device->SetPhy (phy); + Ptr peerMan = m_peerMan.Create (); + NS_ASSERT(peerMan->AttachPorts(ports)); device->SetRemoteStationManager (manager); node->AddDevice (device); nodeDevices.push_back (device); diff --git a/src/devices/mesh/mesh-wifi-helper.h b/src/devices/mesh/mesh-wifi-helper.h index 5f93d3346..33190d531 100644 --- a/src/devices/mesh/mesh-wifi-helper.h +++ b/src/devices/mesh/mesh-wifi-helper.h @@ -22,6 +22,7 @@ #ifndef _MESHWIFIHELPER_H #define _MESHWIFIHELPER_H #include "wifi-helper.h" +#include "ns3/peer-manager-protocol.h" namespace ns3 { @@ -73,6 +74,17 @@ class MeshWifiHelper std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue () ); + void SetPeerManager (std::string type, + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue () + ); + void SetL2RoutingNetDevice (std::string type, std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), @@ -88,6 +100,7 @@ class MeshWifiHelper private: ObjectFactory m_stationManager; ObjectFactory m_meshMac; + ObjectFactory m_peerMan; ObjectFactory m_deviceFactory; }; }//namespace ns3 diff --git a/src/devices/mesh/peer-manager-plugin.cc b/src/devices/mesh/peer-manager-plugin.cc index a7a1af902..ed28d3b9c 100644 --- a/src/devices/mesh/peer-manager-plugin.cc +++ b/src/devices/mesh/peer-manager-plugin.cc @@ -18,11 +18,11 @@ * Author: Kirill Andreev */ -#include "ns3/peer-manager-plugin.h" #include "ns3/ie-dot11s-configuration.h" #include "ns3/ie-dot11s-peer-management.h" #include "ns3/mesh-wifi-interface-mac.h" +#include "ns3/peer-manager-plugin.h" #include "ns3/log.h" NS_LOG_COMPONENT_DEFINE("PeerManager"); namespace ns3 { @@ -48,8 +48,16 @@ Dot11sPeerManagerMacPlugin::Receive (Ptr packet, const WifiMacHeader & h if(header.IsBeacon()) { NS_LOG_UNCOND("Beacon recevied by PM from"< myBeacon = packet->Copy (); + Ptr myBeacon = packet->Copy(); + MgtBeaconHeader beacon_hdr; + myBeacon->RemoveHeader(beacon_hdr); + if(myBeacon->GetSize () == 0) + NS_LOG_UNCOND("Empty"); + if(beaconTiming.FindMyInformationElement(myBeacon)) + NS_LOG_UNCOND("BEACON TIMING"); + #if 0 packet->RemoveHeader (beacon); m_peerManager->SetReceivedBeaconTimers ( @@ -74,5 +82,14 @@ void Dot11sPeerManagerMacPlugin::UpdateBeacon (MeshWifiBeacon & beacon) const { NS_LOG_UNCOND("I am sending a beacon"); + Ptr beaconTiming = Create (); + beacon.AddInformationElement(beaconTiming); } +bool +Dot11sPeerManagerMacPlugin::BindWithProtocol(Ptr protocol) +{ + m_protocol = protocol; + return true; +} + }//namespace ns3 diff --git a/src/devices/mesh/peer-manager-plugin.h b/src/devices/mesh/peer-manager-plugin.h index 0809f8d60..1c88a6609 100644 --- a/src/devices/mesh/peer-manager-plugin.h +++ b/src/devices/mesh/peer-manager-plugin.h @@ -22,6 +22,7 @@ #define PEER_MANAGER_MAC_PLUGIN_H_ #include "ns3/mesh-wifi-interface-mac-plugin.h" +#include "ns3/peer-manager-protocol.h" namespace ns3 { class MeshWifiInterfaceMac; @@ -52,6 +53,7 @@ class Dot11sPeerManagerMacPlugin : public MeshWifiInterfaceMacPlugin /** * \} */ + bool BindWithProtocol(Ptr); void SetPeerManagerProtcol(Ptr protocol); /** * Deliver Peer link management information to the protocol-part @@ -78,6 +80,7 @@ class Dot11sPeerManagerMacPlugin : public MeshWifiInterfaceMacPlugin Callback m_deliverPeerManFrame; Callback m_beaconCallback; Ptr m_parent; + Ptr m_protocol; /** * Create peer link management frames: * \{ diff --git a/src/devices/mesh/peer-manager-protocol.cc b/src/devices/mesh/peer-manager-protocol.cc index abe5eaf85..0d4c9b3b8 100644 --- a/src/devices/mesh/peer-manager-protocol.cc +++ b/src/devices/mesh/peer-manager-protocol.cc @@ -26,6 +26,7 @@ #include "ns3/assert.h" #include "ns3/log.h" #include "ns3/random-variable.h" +#include "ns3/mesh-wifi-interface-mac.h" NS_LOG_COMPONENT_DEFINE ("Dot11sPeerManagerProtocol"); namespace ns3 { /*************************************************** @@ -544,7 +545,7 @@ void WifiPeerLinkDescriptor::ConfirmTimeout () /*************************************************** * PeerManager ***************************************************/ -//NS_OBJECT_ENSURE_REGISTERED (Dot11sPeerManagerProtocol); +NS_OBJECT_ENSURE_REGISTERED (Dot11sPeerManagerProtocol); TypeId Dot11sPeerManagerProtocol::GetTypeId (void) @@ -609,6 +610,53 @@ Dot11sPeerManagerProtocol::~Dot11sPeerManagerProtocol () m_peerDescriptors.clear (); #endif } +//----------------------------------------------------- +// UNFINISHED +//----------------------------------------------------- +bool +Dot11sPeerManagerProtocol::AttachPorts(std::vector > ports) +{ + NS_LOG_UNCOND("Peer manager attach ports started!"); + for(std::vector >::iterator i = ports.begin(); i != ports.end(); i ++) + { + MeshWifiInterfaceMac * mac = dynamic_cast (PeekPointer ((*i)->GetMac ())); + if (mac == NULL) + return false; + Ptr peerPlugin = Create(); + mac->InstallPlugin(peerPlugin); + NS_ASSERT(peerPlugin->BindWithProtocol(this)); + } + return true; +} + +IeDot11sBeaconTiming +Dot11sPeerManagerProtocol::SendBeacon(uint32_t port, Time currentTbtt, Time beaconInterval) +{ + IeDot11sBeaconTiming retval; + return retval; +} + +void +Dot11sPeerManagerProtocol::ReceiveBeacon( + uint32_t port, + IeDot11sBeaconTiming timingElement, + Mac48Address peerAddress, + Time receivingTime, + Time beaconInterval) +{ +} + +void +Dot11sPeerManagerProtocol::ReceivePeerLinkFrame( + uint32_t port, + Mac48Address peerAddress, + uint16_t aid, + IeDot11sConfiguration meshConfig, + IeDot11sPeerManagement peerManagementElement + ) +{ +} + #if 0 void Dot11sPeerManagerProtocol::SetSentBeaconTimers ( diff --git a/src/devices/mesh/peer-manager-protocol.h b/src/devices/mesh/peer-manager-protocol.h index 59427ada0..583faae2a 100644 --- a/src/devices/mesh/peer-manager-protocol.h +++ b/src/devices/mesh/peer-manager-protocol.h @@ -20,20 +20,20 @@ */ -#ifndef WIFI_PEER_MAN_H -#define WIFI_PEER_MAN_H +#ifndef DOT11S_PEER_MAN_H +#define DOT11S_PEER_MAN_H #include "ns3/mac48-address.h" #include "ns3/wifi-net-device.h" #include "ns3/ie-dot11s-peer-management.h" #include "ns3/ie-dot11s-beacon-timing.h" -#include "ns3/peer-manager-plugin.h" #include "ns3/ie-dot11s-configuration.h" #include "ns3/event-id.h" +#include "ns3/peer-manager-plugin.h" #include namespace ns3 { -class EventId; +class Dot11sPeerManagerMacPlugin; /** * \ingroup mesh */ @@ -189,6 +189,7 @@ public: Dot11sPeerManagerProtocol (); ~Dot11sPeerManagerProtocol (); static TypeId GetTypeId (); + bool AttachPorts(std::vector >); /** \brief Methods that handle beacon sending/receiving procedure. * This methods interact with MAC_layer plug-in * \{ @@ -251,14 +252,15 @@ private: * * pointers to proper plugins * \{ */ - struct BeaconInfo - { - Time referenceTbtt; //When one of my station's beacons was put into a beacon queue; - Time beaconInterval; //Beacon interval of my station; - }; - typedef std::map >, std::less > PeerDescriptorsMap; - typedef std::map > BeaconInfoMap; - typedef std::map,std::less > MeshMacMap; +// struct BeaconInfo +// { +// Time referenceTbtt; //When one of my station's beacons was put into a beacon queue; +// Time beaconInterval; //Beacon interval of my station; + // uint16_t aid; //Assoc ID + //}; + typedef std::map > > PeerDescriptorsMap; +// typedef std::map BeaconInfoMap; + typedef std::map > PeerManagerPluginMap; /** * \} */ diff --git a/src/devices/mesh/wifi-information-element.cc b/src/devices/mesh/wifi-information-element.cc index 8df0d9fdd..4072312aa 100644 --- a/src/devices/mesh/wifi-information-element.cc +++ b/src/devices/mesh/wifi-information-element.cc @@ -19,6 +19,8 @@ */ #include "ns3/wifi-information-element.h" +#include "ns3/packet.h" +#include "ns3/log.h" namespace ns3 { @@ -49,7 +51,8 @@ void WifiInformationElement::Serialize (Buffer::Iterator i) const uint32_t WifiInformationElement::Deserialize (Buffer::Iterator i) { - NS_ASSERT (i.ReadU8 () == ElementId()); + if(i.ReadU8 () != ElementId()) + return 0; uint8_t length = i.ReadU8 (); return (DeserializeInformation (i, length) + 2); @@ -61,6 +64,26 @@ void WifiInformationElement::Print (std::ostream &os) const PrintInformation (os); os << "\n"; } +bool WifiInformationElement::FindMyInformationElement(Ptr packet) +{ + const uint8_t * data = packet->PeekData(); + uint32_t position = 0; + while(position <= packet->GetSize ()) + { + if(data[position] == ElementId()) + { + return true; + } + else + { + NS_LOG_UNCOND("not found"<<(uint16_t)data[position+1]); + position +=data[position+1]; + if(data[position + 1] == 0) + return false; + } + } + return false; +} bool operator< (WifiInformationElement const & a, WifiInformationElement const & b) { diff --git a/src/devices/mesh/wifi-information-element.h b/src/devices/mesh/wifi-information-element.h index de53517c7..21f7c915b 100644 --- a/src/devices/mesh/wifi-information-element.h +++ b/src/devices/mesh/wifi-information-element.h @@ -25,7 +25,7 @@ #include "ns3/ref-count-base.h" namespace ns3 { - +class Packet; /** * \ingroup mesh * @@ -128,6 +128,11 @@ public: * i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 */ virtual void Print (std::ostream &os) const; + /** + * This method takes a packet which must be a list of information + * elements and looks for an information element of MINE Element ID + */ + bool FindMyInformationElement(Ptr packet); //\} protected: