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"
48 static TypeId tid =
TypeId (
"ns3::dot11s::PeerManagementProtocol")
50 .AddConstructor<PeerManagementProtocol> ()
53 .AddAttribute (
"MaxNumberOfPeerLinks",
54 "Maximum number of peer links",
56 MakeUintegerAccessor (
58 MakeUintegerChecker<uint8_t> ()
60 .AddAttribute (
"MaxBeaconShiftValue",
61 "Maximum number of TUs for beacon shifting",
63 MakeUintegerAccessor (
65 MakeUintegerChecker<uint16_t> ()
67 .AddAttribute (
"EnableBeaconCollisionAvoidance",
68 "Enable/Disable Beacon collision avoidance.",
74 .AddTraceSource (
"LinkOpen",
75 "New peer link opened",
78 .AddTraceSource (
"LinkClose",
79 "New peer link closed",
87 m_lastAssocId (0), m_lastLocalLinkId (1), m_enableBca (true), m_maxBeaconShift (15)
102 for (PeerLinksOnInterface::iterator i = j->second.begin (); i != j->second.end (); i++)
115 std::vector<Ptr<NetDevice> >
interfaces = mp->GetInterfaces ();
116 for (std::vector<
Ptr<NetDevice> >::iterator i = interfaces.begin (); i != interfaces.end (); i++)
129 mac->InstallPlugin (plugin);
136 mp->AggregateObject (
this);
148 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
150 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
154 if ((*i)->GetBeaconInterval () == Seconds (0))
159 retval->AddNeighboursTimingElementUnit ((*i)->GetLocalAid (), (*i)->GetLastBeacon (),
160 (*i)->GetBeaconInterval ());
169 for (PeerManagementProtocolMacMap::const_iterator i =
m_plugins.begin (); i !=
m_plugins.end (); i++)
171 if (i->second->GetAddress () == peerAddress)
182 peerLink->MLMEActivePeerLinkOpen ();
189 peerLink->SetBeaconInformation (
Simulator::Now (), beaconInterval);
192 peerLink->SetBeaconTimingElement (*
PeekPointer (timingElement));
208 peerLink =
InitiateLink (interface, peerAddress, peerMeshPointAddress);
212 peerLink->OpenAccept (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress);
216 peerLink->OpenReject (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress,
227 peerManagementElement.
GetPeerLinkId (), aid, meshConfig, peerMeshPointAddress);
247 NS_LOG_DEBUG (
"transmission failed between "<<
GetAddress () <<
" and " << peerAddress <<
" failed, link will be closed");
251 peerLink->TransmissionFailure ();
261 peerLink->TransmissionSuccess ();
275 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
277 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
280 new_link->SetInterface (interface);
282 new_link->SetPeerAddress (peerAddress);
283 new_link->SetPeerMeshPointAddress (peerMeshPointAddress);
284 new_link->SetMacPlugin (plugin->second);
286 iface->second.push_back (new_link);
293 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
295 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
297 if ((*i)->GetPeerAddress () == peerAddress)
299 if ((*i)->LinkIsIdle ())
302 (iface->second).erase (i);
320 std::vector<Mac48Address>
323 std::vector<Mac48Address> retval;
324 PeerLinksMap::const_iterator iface =
m_peerLinks.find (interface);
326 for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
328 if ((*i)->LinkIsEstab ())
330 retval.push_back ((*i)->GetPeerAddress ());
336 std::vector< Ptr<PeerLink> >
339 std::vector< Ptr<PeerLink> > links;
343 for (PeerLinksOnInterface::const_iterator i = iface->second.begin ();
344 i != iface->second.end (); i++)
345 if ((*i)->LinkIsEstab ())
346 links.push_back (*i);
356 return (peerLink->LinkIsEstab ());
385 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
389 std::map<uint32_t, Time>::const_iterator lastBeacon =
m_lastBeacon.find (interface);
390 std::map<uint32_t, Time>::const_iterator beaconInterval =
m_beaconInterval.find (interface);
396 uint16_t lastBeaconInTimeElement = (uint16_t) ((lastBeacon->second.GetMicroSeconds () >> 8) & 0xffff);
400 if (iface->second.size () == 0)
408 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
410 bool myBeaconExists =
false;
412 for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbors.begin (); j != neighbors.end (); j++)
414 if ((*i)->GetPeerAid () == (*j)->GetAid ())
417 myBeaconExists =
true;
421 ((int16_t) ((*j)->GetLastBeacon () - lastBeaconInTimeElement) >= 0) &&
422 (((*j)->GetLastBeacon () - lastBeaconInTimeElement) % (4 *
TimeToTu (beaconInterval->second)) == 0)
448 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
450 plugin->second->SetBeaconShift (
TuToTime (shift));
456 return MicroSeconds (x * 1024);
467 NS_LOG_LOGIC (
"link_open " << myIface <<
" " << peerIface);
480 NS_LOG_LOGIC (
"link_close " << myIface <<
" " << peerIface);
494 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
497 <<
" and peer mesh point:" << peerMeshPointAddress <<
" and its interface:" << peerAddress
498 <<
", at my interface ID:" <<
interface << ". State movement:" << ostate << " -> " << nstate);
499 if ((nstate == PeerLink::ESTAB) && (ostate != PeerLink::ESTAB))
501 NotifyLinkOpen (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
503 if ((ostate == PeerLink::ESTAB) && (nstate != PeerLink::ESTAB))
505 NotifyLinkClose (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
507 if (nstate == PeerLink::IDLE)
542 linksTotal (t), linksOpened (0), linksClosed (0)
549 "linksTotal=\"" << linksTotal <<
"\" "
550 "linksOpened=\"" << linksOpened <<
"\" "
551 "linksClosed=\"" << linksClosed <<
"\"/>" << std::endl;
556 os <<
"<PeerManagementProtocol>" << std::endl;
565 for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
570 os <<
"</PeerManagementProtocol>" << std::endl;
578 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)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_COMPONENT_DEFINE(name)
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)
Schedule an event to expire at the relative time "time" is reached.
Ptr< PeerLink > FindPeerLink(uint32_t interface, Mac48Address peerAddress)
Find active peer link by my interface and peer interface MAC.
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
This type is a list of timing elements obtained from neighbours with their beacons: ...
#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
We keep a vector of pointers to PeerLink class.
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)
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Hold together all Wifi-related objects.
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()
Get mesh point address.
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.
static Time Now(void)
Return the "current simulation time".
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)
Assign a fixed random variable stream number to the random variables used by this model...
Hold a 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.
bool Install(Ptr< MeshPointDevice >)
Install PMP on given mesh point.
PmpReasonCode GetReasonCode() const
void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress)
resets transmission failure statistics
bool SubtypeIsConfirm() const