27 #include "ns3/assert.h"
29 #include "ns3/mesh-point-device.h"
30 #include "ns3/mesh-wifi-interface-mac-plugin.h"
31 #include "ns3/mesh-wifi-interface-mac.h"
32 #include "ns3/random-variable-stream.h"
33 #include "ns3/simulator.h"
34 #include "ns3/trace-source-accessor.h"
35 #include "ns3/wifi-net-device.h"
54 TypeId(
"ns3::dot11s::PeerManagementProtocol")
60 .AddAttribute(
"MaxNumberOfPeerLinks",
61 "Maximum number of peer links",
64 MakeUintegerChecker<uint8_t>())
65 .AddAttribute(
"MaxBeaconShiftValue",
66 "Maximum number of TUs for beacon shifting",
69 MakeUintegerChecker<uint16_t>())
70 .AddAttribute(
"EnableBeaconCollisionAvoidance",
71 "Enable/Disable Beacon collision avoidance.",
76 .AddTraceSource(
"LinkOpen",
77 "New peer link opened",
79 "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback")
80 .AddTraceSource(
"LinkClose",
81 "New peer link closed",
83 "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback")
110 for (
auto i = j->second.begin(); i != j->second.end(); i++)
123 std::vector<Ptr<NetDevice>>
interfaces = mp->GetInterfaces();
137 Create<PeerManagementProtocolMac>((*i)->GetIfIndex(),
this);
138 mac->InstallPlugin(plugin);
145 mp->AggregateObject(
this);
159 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
163 if ((*i)->GetBeaconInterval() ==
Seconds(0))
168 retval->AddNeighboursTimingElementUnit((*i)->GetLocalAid(),
169 (*i)->GetLastBeacon(),
170 (*i)->GetBeaconInterval());
185 if (i->second->GetAddress() == peerAddress)
196 peerLink->MLMEActivePeerLinkOpen();
206 peerLink->SetBeaconTimingElement(*
PeekPointer(timingElement));
225 peerLink =
InitiateLink(interface, peerAddress, peerMeshPointAddress);
231 peerMeshPointAddress);
237 peerMeshPointAddress,
251 peerMeshPointAddress);
275 <<
" failed, link will be closed");
279 peerLink->TransmissionFailure();
290 peerLink->TransmissionSuccess();
311 new_link->SetInterface(interface);
313 new_link->SetPeerAddress(peerAddress);
314 new_link->SetPeerMeshPointAddress(peerMeshPointAddress);
315 new_link->SetMacPlugin(plugin->second);
316 new_link->MLMESetSignalStatusCallback(
318 iface->second.push_back(new_link);
327 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
329 if ((*i)->GetPeerAddress() == peerAddress)
331 if ((*i)->LinkIsIdle())
334 (iface->second).erase(i);
353 std::vector<Mac48Address>
356 std::vector<Mac48Address> retval;
359 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
361 if ((*i)->LinkIsEstab())
363 retval.push_back((*i)->GetPeerAddress());
369 std::vector<Ptr<PeerLink>>
372 std::vector<Ptr<PeerLink>> links;
376 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
378 if ((*i)->LinkIsEstab())
393 return peerLink->LinkIsEstab();
435 auto lastBeaconInTimeElement = (uint16_t)((lastBeacon->second.GetMicroSeconds() >> 8) & 0xffff);
438 "Wrong beacon shift parameters");
440 if (iface->second.empty())
448 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
450 bool myBeaconExists =
false;
452 (*i)->GetBeaconTimingElement().GetNeighboursTimingElementsList();
453 for (
auto j = neighbors.begin(); j != neighbors.end(); j++)
455 if ((*i)->GetPeerAid() == (*j)->GetAid())
458 myBeaconExists =
true;
461 if (((int16_t)((*j)->GetLastBeacon() - lastBeaconInTimeElement) >= 0) &&
462 (((*j)->GetLastBeacon() - lastBeaconInTimeElement) %
463 (4 *
TimeToTu(beaconInterval->second)) ==
487 }
while (shift == 0);
491 plugin->second->SetBeaconShift(
TuToTime(shift));
503 return (
int)(
x.GetMicroSeconds() / 1024);
512 NS_LOG_LOGIC(
"link_open " << myIface <<
" " << peerIface);
528 NS_LOG_LOGIC(
"link_close " << myIface <<
" " << peerIface);
548 <<
" and peer mesh point:" << peerMeshPointAddress
549 <<
" and its interface:" << peerAddress
550 <<
", at my interface ID:" << interface <<
". State movement:"
555 NotifyLinkOpen(peerMeshPointAddress, peerAddress, plugin->second->GetAddress(), interface);
559 NotifyLinkClose(peerMeshPointAddress, peerAddress, plugin->second->GetAddress(), interface);
622 << linksClosed <<
"\"/>" << std::endl;
628 os <<
"<PeerManagementProtocol>" << std::endl;
637 for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
642 os <<
"</PeerManagementProtocol>" << std::endl;
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
Basic MAC of mesh point Wi-Fi interface.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
A base class which provides memory management and object aggregation.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Hold together all Wifi-related objects.
Ptr< WifiMac > GetMac() const
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
according to IEEE 802.11 - 2012
bool SubtypeIsOpen() const
Subtype is open function.
bool SubtypeIsClose() const
Subtype is close function.
PmpReasonCode GetReasonCode() const
Get reason code function.
bool SubtypeIsConfirm() const
Subtype is confirm function.
uint16_t GetPeerLinkId() const
Get peer link ID function.
uint16_t GetLocalLinkId() const
Get local link ID function.
PeerState
Peer Link state:
static const char *const PeerStateNames[6]
Literal names of Mesh Peer Management states for use in log messages.
802.11s Peer Management Protocol model
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.
void DoDispose() override
Destructor implementation.
bool GetBeaconCollisionAvoidance() const
Get beacon collision avoidance.
bool ShouldSendOpen(uint32_t interface, Mac48Address peerAddress) const
External peer-chooser.
Callback< void, Mac48Address, Mac48Address, uint32_t, bool > m_peerStatusCallback
Callback to notify about peer link changes: Mac48Address is peer address of mesh point,...
void SetMeshId(std::string s)
Set mesh ID to a string value.
uint8_t m_maxNumberOfPeerLinks
maimum number of peer links
int TimeToTu(Time x)
Time<-->TU converters:
void Report(std::ostream &os) const
Report statistics.
void TransmissionFailure(uint32_t interface, const Mac48Address peerAddress)
Cancels peer link due to successive transmission failures.
uint16_t m_maxBeaconShift
Beacon can be shifted at [-m_maxBeaconShift; +m_maxBeaconShift] TUs.
Statistics m_stats
statistics
LinkEventCallback m_linkOpenTraceSrc
LinkOpen trace source.
void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress)
resets transmission failure statistics
bool ShouldAcceptOpen(uint32_t interface, Mac48Address peerAddress, PmpReasonCode &reasonCode) const
External peer-chooser.
std::vector< Ptr< PeerLink > > GetPeerLinks() const
Get list of all active peer links.
void ReceiveBeacon(uint32_t interface, Mac48Address peerAddress, Time beaconInterval, Ptr< IeBeaconTiming > beaconTiming)
To initiate peer link we must notify about received beacon.
void NotifyLinkClose(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux.
uint16_t m_lastAssocId
last associated ID
Ptr< PeerLink > InitiateLink(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress)
Initiate link function.
void DoInitialize() override
Initialize() implementation.
Ptr< IeMeshId > GetMeshId() const
Get mesh ID information element.
void SetPeerLinkStatusCallback(Callback< void, Mac48Address, Mac48Address, uint32_t, bool > cb)
Set peer link status change callback.
uint8_t GetNumberOfLinks() const
Get number of links.
static TypeId GetTypeId()
Get the type ID.
~PeerManagementProtocol() override
std::map< uint32_t, Time > m_lastBeacon
Last beacon at each interface.
bool Install(Ptr< MeshPointDevice > mp)
Install PMP on given mesh point.
PeerManagementProtocolMacMap m_plugins
plugins
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
std::map< uint32_t, Time > m_beaconInterval
Beacon interval at each interface.
void NotifyBeaconSent(uint32_t interface, Time beaconInterval)
Notify about beacon send event, needed to schedule BCA.
void ShiftOwnBeacon(uint32_t interface)
Shift own beacon function.
std::vector< Ptr< PeerLink > > PeerLinksOnInterface
We keep a vector of pointers to PeerLink class.
void ConfigurationMismatch(uint32_t interface, Mac48Address peerAddress)
Cancels peer link due to broken configuration (Mesh ID or Supported rates)
PeerLinksMap m_peerLinks
Simple link open/close trace source type. Addresses are: src interface, dst interface.
Ptr< UniformRandomVariable > m_beaconShift
Add randomness to beacon shift.
void PeerLinkStatus(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress, PeerLink::PeerState ostate, PeerLink::PeerState nstate)
Indicates changes in peer links.
bool IsActiveLink(uint32_t interface, Mac48Address peerAddress)
Checks if there is established link.
std::vector< Mac48Address > GetPeers(uint32_t interface) const
Get list of active peers of my given interface.
LinkEventCallback m_linkCloseTraceSrc
LinkClose trace source.
Mac48Address m_address
address
void CheckBeaconCollisions(uint32_t interface)
BCA.
Ptr< IeBeaconTiming > GetBeaconTimingElement(uint32_t interface)
When we are sending a beacon - we fill beacon timing element.
Ptr< IeMeshId > m_meshId
mesh ID
Mac48Address GetAddress()
Get mesh point address.
Ptr< PeerLink > FindPeerLink(uint32_t interface, Mac48Address peerAddress)
Find active peer link by my interface and peer interface MAC.
Time TuToTime(int x)
Time<-->TU converters:
uint16_t m_lastLocalLinkId
last local link ID
void NotifyLinkOpen(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux.
void ResetStats()
Reset statistics function.
bool m_enableBca
Flag which enables BCA.
void SetBeaconCollisionAvoidance(bool enable)
Enable or disable beacon collision avoidance.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
This type is a list of timing elements obtained from neighbours with their beacons:
@ REASON11S_MESH_CAPABILITY_POLICY_VIOLATION
@ REASON11S_MESH_MAX_PEERS
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
U * PeekPointer(const Ptr< U > &p)
uint16_t linksTotal
total links
void Print(std::ostream &os) const
Print function.
uint16_t linksOpened
opened links
uint16_t linksClosed
links closed
Statistics(uint16_t t=0)
Constructor.