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++)
115 for (std::vector<
Ptr<NetDevice> >::iterator i = interfaces.begin (); i != interfaces.end (); i++)
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 ();