22 #include "ns3/peer-management-protocol.h" 
   26 #include "ns3/mesh-point-device.h" 
   27 #include "ns3/simulator.h" 
   28 #include "ns3/assert.h" 
   30 #include "ns3/random-variable-stream.h" 
   31 #include "ns3/mesh-wifi-interface-mac.h" 
   32 #include "ns3/mesh-wifi-interface-mac-plugin.h" 
   33 #include "ns3/wifi-net-device.h" 
   34 #include "ns3/trace-source-accessor.h" 
   47   static TypeId tid = 
TypeId (
"ns3::dot11s::PeerManagementProtocol")
 
   49     .AddConstructor<PeerManagementProtocol> ()
 
   52     .AddAttribute ( 
"MaxNumberOfPeerLinks",
 
   53                     "Maximum number of peer links",
 
   55                     MakeUintegerAccessor (
 
   57                     MakeUintegerChecker<uint8_t> ()
 
   59     .AddAttribute ( 
"MaxBeaconShiftValue",
 
   60                     "Maximum number of TUs for beacon shifting",
 
   62                     MakeUintegerAccessor (
 
   64                     MakeUintegerChecker<uint16_t> ()
 
   66     .AddAttribute ( 
"EnableBeaconCollisionAvoidance",
 
   67                     "Enable/Disable Beacon collision avoidance.",
 
   73     .AddTraceSource (
"LinkOpen",
 
   74                      "New peer link opened",
 
   77     .AddTraceSource (
"LinkClose",
 
   78                      "New peer link closed",
 
   86   m_lastAssocId (0), m_lastLocalLinkId (1), m_enableBca (true), m_maxBeaconShift (15)
 
  101       for (PeerLinksOnInterface::iterator i = j->second.begin (); i != j->second.end (); i++)
 
  114   std::vector<Ptr<NetDevice> > 
interfaces = mp->GetInterfaces ();
 
  115   for (std::vector<
Ptr<NetDevice> >::iterator i = interfaces.begin (); i != interfaces.end (); i++)
 
  128       mac->InstallPlugin (plugin);
 
  135   mp->AggregateObject (
this);
 
  147   PeerLinksMap::iterator iface = 
m_peerLinks.find (interface);
 
  149   for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
 
  153       if ((*i)->GetBeaconInterval () == Seconds (0))
 
  158       retval->AddNeighboursTimingElementUnit ((*i)->GetLocalAid (), (*i)->GetLastBeacon (),
 
  159                                               (*i)->GetBeaconInterval ());
 
  168   for (PeerManagementProtocolMacMap::const_iterator i = 
m_plugins.begin (); i != 
m_plugins.end (); i++)
 
  170       if (i->second->GetAddress () == peerAddress)
 
  181           peerLink->MLMEActivePeerLinkOpen ();
 
  188   peerLink->SetBeaconInformation (
Simulator::Now (), beaconInterval);
 
  191       peerLink->SetBeaconTimingElement (*
PeekPointer (timingElement));
 
  207           peerLink = 
InitiateLink (interface, peerAddress, peerMeshPointAddress);
 
  211           peerLink->OpenAccept (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress);
 
  215           peerLink->OpenReject (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress,
 
  226                                peerManagementElement.
GetPeerLinkId (), aid, meshConfig, peerMeshPointAddress);
 
  246   NS_LOG_DEBUG (
"transmission failed between "<<
GetAddress () << 
" and " << peerAddress << 
" failed, link will be closed");
 
  250       peerLink->TransmissionFailure ();
 
  260       peerLink->TransmissionSuccess ();
 
  274   PeerManagementProtocolMacMap::iterator plugin = 
m_plugins.find (interface);
 
  276   PeerLinksMap::iterator iface = 
m_peerLinks.find (interface);
 
  279   new_link->SetInterface (interface);
 
  281   new_link->SetPeerAddress (peerAddress);
 
  282   new_link->SetPeerMeshPointAddress (peerMeshPointAddress);
 
  283   new_link->SetMacPlugin (plugin->second);
 
  285   iface->second.push_back (new_link);
 
  292   PeerLinksMap::iterator iface = 
m_peerLinks.find (interface);
 
  294   for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
 
  296       if ((*i)->GetPeerAddress () == peerAddress)
 
  298           if ((*i)->LinkIsIdle ())
 
  301               (iface->second).erase (i);
 
  319 std::vector<Mac48Address>
 
  322   std::vector<Mac48Address> retval;
 
  323   PeerLinksMap::const_iterator iface = 
m_peerLinks.find (interface);
 
  325   for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
 
  327       if ((*i)->LinkIsEstab ())
 
  329           retval.push_back ((*i)->GetPeerAddress ());
 
  335 std::vector< Ptr<PeerLink> >
 
  338   std::vector< Ptr<PeerLink> > links;
 
  342       for (PeerLinksOnInterface::const_iterator i = iface->second.begin ();
 
  343            i != iface->second.end (); i++)
 
  344         if ((*i)->LinkIsEstab ())
 
  345           links.push_back (*i);
 
  355       return (peerLink->LinkIsEstab ());
 
  384   PeerLinksMap::iterator iface = 
m_peerLinks.find (interface);
 
  388   std::map<uint32_t, Time>::const_iterator lastBeacon = 
m_lastBeacon.find (interface);
 
  389   std::map<uint32_t, Time>::const_iterator beaconInterval = 
m_beaconInterval.find (interface);
 
  395   uint16_t lastBeaconInTimeElement = (uint16_t) ((lastBeacon->second.GetMicroSeconds () >> 8) & 0xffff);
 
  399   if (iface->second.size () == 0)
 
  407   for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
 
  409       bool myBeaconExists = 
false;
 
  411       for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbors.begin (); j != neighbors.end (); j++)
 
  413           if ((*i)->GetPeerAid () == (*j)->GetAid ())
 
  416               myBeaconExists = 
true;
 
  420             ((int16_t) ((*j)->GetLastBeacon () - lastBeaconInTimeElement) >= 0) &&
 
  421             (((*j)->GetLastBeacon () - lastBeaconInTimeElement) % (4 * 
TimeToTu (beaconInterval->second)) == 0)
 
  447   PeerManagementProtocolMacMap::iterator plugin = 
m_plugins.find (interface);
 
  449   plugin->second->SetBeaconShift (
TuToTime (shift));
 
  455   return MicroSeconds (x * 1024);
 
  466   NS_LOG_LOGIC (
"link_open " << myIface << 
" " << peerIface);
 
  479   NS_LOG_LOGIC (
"link_close " << myIface << 
" " << peerIface);
 
  493   PeerManagementProtocolMacMap::iterator plugin = 
m_plugins.find (interface);
 
  496                                    << 
" and peer mesh point:" << peerMeshPointAddress << 
" and its interface:" << peerAddress
 
  497                                    << 
", at my interface ID:" << 
interface << ". State movement:" << ostate << " -> " << nstate);
 
  498   if ((nstate == PeerLink::ESTAB) && (ostate != PeerLink::ESTAB))
 
  500       NotifyLinkOpen (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
 
  502   if ((ostate == PeerLink::ESTAB) && (nstate != PeerLink::ESTAB))
 
  504       NotifyLinkClose (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
 
  506   if (nstate == PeerLink::IDLE)
 
  541   linksTotal (t), linksOpened (0), linksClosed (0)
 
  548   "linksTotal=\"" << linksTotal << 
"\" " 
  549   "linksOpened=\"" << linksOpened << 
"\" " 
  550   "linksClosed=\"" << linksClosed << 
"\"/>" << std::endl;
 
  555   os << 
"<PeerManagementProtocol>" << std::endl;
 
  564       for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
 
  569   os << 
"</PeerManagementProtocol>" << std::endl;
 
  577       plugins->second->ResetStats ();
 
keep track of time values and allow control of global simulation resolution 
void NotifyLinkClose(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux. method to register closed links. 
virtual void DoInitialize()
Set peer link status change callback. 
smart pointer class similar to boost::intrusive_ptr 
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream. 
uint16_t GetLocalLinkId() const 
uint8_t m_maxNumberOfPeerLinks
#define NS_ASSERT(condition)
void NotifyLinkOpen(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux. method to register open links. 
Ptr< UniformRandomVariable > m_beaconShift
Add randomness to beacon shift. 
void Report(std::ostream &) const 
: Report statistics 
static TypeId GetTypeId()
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Ptr< PeerLink > FindPeerLink(uint32_t interface, Mac48Address peerAddress)
Find active peer link by my interface and peer interface MAC. 
NS_OBJECT_ENSURE_REGISTERED(AirtimeLinkMetricCalculator)
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
#define NS_FATAL_ERROR(msg)
fatal error handling 
LinkEventCallback m_linkCloseTraceSrc
LinkClose trace source. 
PeerState
Peer Link state: 
uint16_t m_lastLocalLinkId
bool SubtypeIsOpen() const 
bool IsActiveLink(uint32_t interface, Mac48Address peerAddress)
Checks if there is established link. 
std::vector< Ptr< PeerLink > > PeerLinksOnInterface
std::vector< Mac48Address > GetPeers(uint32_t interface) const 
Get list of active peers of my given interface. 
See 7.3.2.85 of draft 2.07. 
int64_t GetMicroSeconds(void) const 
Hold an unsigned integer type. 
void SetMeshId(std::string s)
Set peer link status change callback. 
void Print(std::ostream &os) const 
T * PeekPointer(const Ptr< T > &p)
Hold together all Wifi-related objects.This class holds together ns3::WifiChannel, ns3::WifiPhy, ns3::WifiMac, and, ns3::WifiRemoteStationManager. 
static Mac48Address GetBroadcast(void)
void NotifyBeaconSent(uint32_t interface, Time beaconInterval)
Notify about beacon send event, needed to schedule BCA. 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Mac48Address GetAddress()
void SetPeerLinkStatusCallback(Callback< void, Mac48Address, Mac48Address, uint32_t, bool > cb)
Set peer link status change callback. 
#define NS_LOG_LOGIC(msg)
std::vector< Ptr< PeerLink > > GetPeerLinks() const 
Get list of all active peer links. 
static Mac48Address ConvertFrom(const Address &address)
uint8_t GetNumberOfLinks()
Set peer link status change callback. 
~PeerManagementProtocol()
Ptr< IeMeshId > GetMeshId() const 
Set peer link status change callback. 
uint16_t GetPeerLinkId() const 
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
PeerManagementProtocolMacMap m_plugins
LinkEventCallback m_linkOpenTraceSrc
LinkOpen trace source. 
void ShiftOwnBeacon(uint32_t interface)
void ReceivePeerLinkFrame(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress, uint16_t aid, IePeerManagement peerManagementElement, IeConfiguration meshConfig)
Methods that handle Peer link management frames interaction: 
void ResetStats()
Set peer link status change callback. 
Ptr< IeBeaconTiming > GetBeaconTimingElement(uint32_t interface)
When we are sending a beacon - we fill beacon timing element. 
void PeerLinkStatus(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddres, PeerLink::PeerState ostate, PeerLink::PeerState nstate)
Indicates changes in peer links. 
#define NS_ASSERT_MSG(condition, message)
bool ShouldSendOpen(uint32_t interface, Mac48Address peerAddress)
void ConfigurationMismatch(uint32_t interface, Mac48Address peerAddress)
Cancels peer link due to broken configuration (Mesh ID or Supported rates) 
struct Statistics m_stats
void TransmissionFailure(uint32_t interface, const Mac48Address peerAddress)
Cancels peer link due to successive transmission failures. 
void CheckBeaconCollisions(uint32_t interface)
BCA. 
std::map< uint32_t, Time > m_lastBeacon
Last beacon at each interface. 
bool GetBeaconCollisionAvoidance() const 
Set peer link status change callback. 
bool SubtypeIsClose() const 
PmpReasonCode
Codes used by 802.11s Peer Management Protocol. 
bool ShouldAcceptOpen(uint32_t interface, Mac48Address peerAddress, PmpReasonCode &reasonCode)
#define NS_LOG_DEBUG(msg)
bool m_enableBca
Flag which enables BCA. 
void ReceiveBeacon(uint32_t interface, Mac48Address peerAddress, Time beaconInterval, Ptr< IeBeaconTiming > beaconTiming)
To initiate peer link we must notify about received beacon. 
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0. 
std::map< uint32_t, Time > m_beaconInterval
Beacon interval at each interface. 
void SetBeaconCollisionAvoidance(bool enable)
Enable or disable beacon collision avoidance. 
a base class which provides memory management and object aggregation 
int64_t AssignStreams(int64_t stream)
Hold an floating point type. 
uint16_t m_maxBeaconShift
Beacon can be shifted at [-m_maxBeaconShift; +m_maxBeaconShift] TUs. 
void SetAttribute(std::string name, const AttributeValue &value)
Callback< void, Mac48Address, Mac48Address, uint32_t, bool > m_peerStatusCallback
Callback to notify about peer link changes: Mac48Address is peer address of mesh point, Mac48Address is peer address of interface, uint32_t - interface ID, bool is status - true when new link has appeared, false - when link was closed,. 
a unique identifier for an interface. 
Ptr< PeerLink > InitiateLink(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress)
TypeId SetParent(TypeId tid)
Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins mechanism...
bool Install(Ptr< MeshPointDevice >)
Install PMP on given mesh point. 
PmpReasonCode GetReasonCode() const 
NS_LOG_COMPONENT_DEFINE("PeerManagementProtocol")
void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress)
resets transmission failure statistics 
bool SubtypeIsConfirm() const