|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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"
50 static TypeId tid =
TypeId (
"ns3::dot11s::PeerManagementProtocol")
52 .SetGroupName (
"Mesh")
56 .AddAttribute (
"MaxNumberOfPeerLinks",
57 "Maximum number of peer links",
61 MakeUintegerChecker<uint8_t> ()
63 .AddAttribute (
"MaxBeaconShiftValue",
64 "Maximum number of TUs for beacon shifting",
68 MakeUintegerChecker<uint16_t> ()
70 .AddAttribute (
"EnableBeaconCollisionAvoidance",
71 "Enable/Disable Beacon collision avoidance.",
77 .AddTraceSource (
"LinkOpen",
78 "New peer link opened",
80 "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback"
82 .AddTraceSource (
"LinkClose",
83 "New peer link closed",
85 "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback"
92 m_lastAssocId (0), m_lastLocalLinkId (1), m_enableBca (true), m_maxBeaconShift (15)
107 for (PeerLinksOnInterface::iterator i = j->second.begin (); i != j->second.end (); i++)
120 std::vector<Ptr<NetDevice> >
interfaces = mp->GetInterfaces ();
134 mac->InstallPlugin (plugin);
141 mp->AggregateObject (
this);
153 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
155 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
159 if ((*i)->GetBeaconInterval () ==
Seconds (0))
164 retval->AddNeighboursTimingElementUnit ((*i)->GetLocalAid (), (*i)->GetLastBeacon (),
165 (*i)->GetBeaconInterval ());
174 for (PeerManagementProtocolMacMap::const_iterator i =
m_plugins.begin (); i !=
m_plugins.end (); i++)
176 if (i->second->GetAddress () == peerAddress)
187 peerLink->MLMEActivePeerLinkOpen ();
194 peerLink->SetBeaconInformation (
Simulator::Now (), beaconInterval);
197 peerLink->SetBeaconTimingElement (*
PeekPointer (timingElement));
213 peerLink =
InitiateLink (interface, peerAddress, peerMeshPointAddress);
217 peerLink->OpenAccept (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress);
221 peerLink->OpenReject (peerManagementElement.
GetLocalLinkId (), meshConfig, peerMeshPointAddress,
232 peerManagementElement.
GetPeerLinkId (), aid, meshConfig, peerMeshPointAddress);
252 NS_LOG_DEBUG (
"transmission failed between "<<
GetAddress () <<
" and " << peerAddress <<
" failed, link will be closed");
256 peerLink->TransmissionFailure ();
266 peerLink->TransmissionSuccess ();
280 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
282 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
285 new_link->SetInterface (interface);
287 new_link->SetPeerAddress (peerAddress);
288 new_link->SetPeerMeshPointAddress (peerMeshPointAddress);
289 new_link->SetMacPlugin (plugin->second);
291 iface->second.push_back (new_link);
298 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
300 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
302 if ((*i)->GetPeerAddress () == peerAddress)
304 if ((*i)->LinkIsIdle ())
307 (iface->second).erase (i);
325 std::vector<Mac48Address>
328 std::vector<Mac48Address> retval;
329 PeerLinksMap::const_iterator iface =
m_peerLinks.find (interface);
331 for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
333 if ((*i)->LinkIsEstab ())
335 retval.push_back ((*i)->GetPeerAddress ());
341 std::vector< Ptr<PeerLink> >
344 std::vector< Ptr<PeerLink> > links;
348 for (PeerLinksOnInterface::const_iterator i = iface->second.begin ();
349 i != iface->second.end (); i++)
350 if ((*i)->LinkIsEstab ())
351 links.push_back (*i);
361 return (peerLink->LinkIsEstab ());
390 PeerLinksMap::iterator iface =
m_peerLinks.find (interface);
394 std::map<uint32_t, Time>::const_iterator lastBeacon =
m_lastBeacon.find (interface);
395 std::map<uint32_t, Time>::const_iterator beaconInterval =
m_beaconInterval.find (interface);
401 uint16_t lastBeaconInTimeElement = (uint16_t) ((lastBeacon->second.GetMicroSeconds () >> 8) & 0xffff);
405 if (iface->second.size () == 0)
413 for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
415 bool myBeaconExists =
false;
417 for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbors.begin (); j != neighbors.end (); j++)
419 if ((*i)->GetPeerAid () == (*j)->GetAid ())
422 myBeaconExists =
true;
426 ((int16_t) ((*j)->GetLastBeacon () - lastBeaconInTimeElement) >= 0) &&
427 (((*j)->GetLastBeacon () - lastBeaconInTimeElement) % (4 *
TimeToTu (beaconInterval->second)) == 0)
453 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
455 plugin->second->SetBeaconShift (
TuToTime (shift));
466 return (
int)(
x.GetMicroSeconds () / 1024);
472 NS_LOG_LOGIC (
"link_open " << myIface <<
" " << peerIface);
485 NS_LOG_LOGIC (
"link_close " << myIface <<
" " << peerIface);
499 PeerManagementProtocolMacMap::iterator plugin =
m_plugins.find (interface);
502 << plugin->second->GetAddress ()
503 <<
" and peer mesh point:" << peerMeshPointAddress <<
" and its interface:" << peerAddress
508 NotifyLinkOpen (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
512 NotifyLinkClose (peerMeshPointAddress, peerAddress, plugin->second->GetAddress (), interface);
549 linksTotal (t), linksOpened (0), linksClosed (0)
556 "linksTotal=\"" << linksTotal <<
"\" "
557 "linksOpened=\"" << linksOpened <<
"\" "
558 "linksClosed=\"" << linksClosed <<
"\"/>" << std::endl;
563 os <<
"<PeerManagementProtocol>" << std::endl;
572 for (PeerLinksOnInterface::const_iterator i = iface->second.begin (); i != iface->second.end (); i++)
577 os <<
"</PeerManagementProtocol>" << std::endl;
585 plugins->second->ResetStats ();
Callback< void, Mac48Address, Mac48Address, uint32_t, bool > m_peerStatusCallback
Callback to notify about peer link changes: Mac48Address is peer address of mesh point,...
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
std::vector< Mac48Address > GetPeers(uint32_t interface) const
Get list of active peers of my given interface.
void SetPeerLinkStatusCallback(Callback< void, Mac48Address, Mac48Address, uint32_t, bool > cb)
Set peer link status change callback.
PmpReasonCode GetReasonCode() const
Get reason code function.
uint16_t m_maxBeaconShift
Beacon can be shifted at [-m_maxBeaconShift; +m_maxBeaconShift] TUs.
uint8_t m_maxNumberOfPeerLinks
maimum number of peer links
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
bool SubtypeIsOpen() const
Subtype is open function.
void ReceivePeerLinkFrame(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress, uint16_t aid, IePeerManagement peerManagementElement, IeConfiguration meshConfig)
Deliver Peer link management information to the protocol-part.
AttributeValue implementation for Boolean.
struct Statistics m_stats
statistics
void NotifyLinkClose(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux.
void NotifyLinkOpen(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux.
PeerLinksMap m_peerLinks
Simple link open/close trace source type. Addresses are: src interface, dst interface.
void SetMeshId(std::string s)
Set mesh ID to a string value.
void ReceiveBeacon(uint32_t interface, Mac48Address peerAddress, Time beaconInterval, Ptr< IeBeaconTiming > beaconTiming)
To initiate peer link we must notify about received beacon.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Mac48Address GetAddress()
Get mesh point address.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint16_t GetLocalLinkId() const
Get local link ID function.
LinkEventCallback m_linkCloseTraceSrc
LinkClose trace source.
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
Statistics(uint16_t t=0)
Constructor.
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
bool m_enableBca
Flag which enables BCA.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
bool GetBeaconCollisionAvoidance() const
Get beacon collision avoidance.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< PeerLink > InitiateLink(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress)
Initiate link function.
U * PeekPointer(const Ptr< U > &p)
virtual void DoInitialize()
Initialize() implementation.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress)
resets transmission failure statistics
uint16_t linksOpened
opened links
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void DoDispose()
Destructor implementation.
std::map< uint32_t, Time > m_beaconInterval
Beacon interval at each interface.
std::vector< Ptr< PeerLink > > GetPeerLinks() const
Get list of all active peer links.
uint16_t GetPeerLinkId() const
Get peer link ID function.
Hold together all Wifi-related objects.
LinkEventCallback m_linkOpenTraceSrc
LinkOpen trace source.
Ptr< IeBeaconTiming > GetBeaconTimingElement(uint32_t interface)
When we are sending a beacon - we fill beacon timing element.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static Mac48Address GetBroadcast(void)
void Print(std::ostream &os) const
Print function.
Ptr< IeMeshId > GetMeshId() const
Get mesh ID information element.
bool IsActiveLink(uint32_t interface, Mac48Address peerAddress)
Checks if there is established link.
void ConfigurationMismatch(uint32_t interface, Mac48Address peerAddress)
Cancels peer link due to broken configuration (Mesh ID or Supported rates)
A base class which provides memory management and object aggregation.
Ptr< IeMeshId > m_meshId
mesh ID
static Mac48Address ConvertFrom(const Address &address)
void Report(std::ostream &os) const
Report statistics.
Mac48Address m_address
address
bool ShouldAcceptOpen(uint32_t interface, Mac48Address peerAddress, PmpReasonCode &reasonCode)
External peer-chooser.
802.11s Peer Management Protocol model
uint16_t m_lastAssocId
last associated ID
Ptr< const AttributeChecker > MakeBooleanChecker(void)
PeerManagementProtocolMacMap m_plugins
plugins
Ptr< PeerLink > FindPeerLink(uint32_t interface, Mac48Address peerAddress)
Find active peer link by my interface and peer interface MAC.
Simulation virtual time values and global simulation resolution.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
~PeerManagementProtocol()
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
This type is a list of timing elements obtained from neighbours with their beacons:
uint16_t linksTotal
total links
@ REASON11S_MESH_MAX_PEERS
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
bool ShouldSendOpen(uint32_t interface, Mac48Address peerAddress)
External peer-chooser.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< UniformRandomVariable > m_beaconShift
Add randomness to beacon shift.
void TransmissionFailure(uint32_t interface, const Mac48Address peerAddress)
Cancels peer link due to successive transmission failures.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void ShiftOwnBeacon(uint32_t interface)
Shift own beacon function.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold an unsigned integer type.
uint16_t m_lastLocalLinkId
last local link ID
PeerState
Peer Link state:
static const char *const PeerStateNames[6]
Literal names of Mesh Peer Management states for use in log messages.
void CheckBeaconCollisions(uint32_t interface)
BCA.
Time TuToTime(int x)
Time<-->TU converters:
bool SubtypeIsConfirm() const
Subtype is confirm function.
std::map< uint32_t, Time > m_lastBeacon
Last beacon at each interface.
std::vector< Ptr< PeerLink > > PeerLinksOnInterface
We keep a vector of pointers to PeerLink class.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static TypeId GetTypeId()
Get the type ID.
int TimeToTu(Time x)
Time<-->TU converters:
@ REASON11S_MESH_CAPABILITY_POLICY_VIOLATION
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
according to IEEE 802.11 - 2012
uint8_t GetNumberOfLinks()
Get number of links.
bool Install(Ptr< MeshPointDevice > mp)
Install PMP on given mesh point.
void NotifyBeaconSent(uint32_t interface, Time beaconInterval)
Notify about beacon send event, needed to schedule BCA.
uint16_t linksClosed
links closed
bool SubtypeIsClose() const
Subtype is close function.
Ptr< WifiMac > GetMac(void) const
Basic MAC of mesh point Wi-Fi interface.
void ResetStats()
Reset statistics function.
void SetBeaconCollisionAvoidance(bool enable)
Enable or disable beacon collision avoidance.
void PeerLinkStatus(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddres, PeerLink::PeerState ostate, PeerLink::PeerState nstate)
Indicates changes in peer links.