16#include "ns3/assert.h" 
   18#include "ns3/mesh-point-device.h" 
   19#include "ns3/mesh-wifi-interface-mac-plugin.h" 
   20#include "ns3/mesh-wifi-interface-mac.h" 
   21#include "ns3/random-variable-stream.h" 
   22#include "ns3/simulator.h" 
   23#include "ns3/trace-source-accessor.h" 
   24#include "ns3/wifi-net-device.h" 
   43        TypeId(
"ns3::dot11s::PeerManagementProtocol")
 
   49            .AddAttribute(
"MaxNumberOfPeerLinks",
 
   50                          "Maximum number of peer links",
 
   54            .AddAttribute(
"MaxBeaconShiftValue",
 
   55                          "Maximum number of TUs for beacon shifting",
 
   59            .AddAttribute(
"EnableBeaconCollisionAvoidance",
 
   60                          "Enable/Disable Beacon collision avoidance.",
 
   65            .AddTraceSource(
"LinkOpen",
 
   66                            "New peer link opened",
 
   68                            "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback")
 
   69            .AddTraceSource(
"LinkClose",
 
   70                            "New peer link closed",
 
   72                            "ns3::PeerManagementProtocol::LinkOpenCloseTracedCallback")
 
 
   99        for (
auto i = j->second.begin(); i != j->second.end(); i++)
 
 
  112    std::vector<Ptr<NetDevice>> interfaces = mp->GetInterfaces();
 
  113    for (
auto i = interfaces.begin(); i != interfaces.end(); i++)
 
  127        mac->InstallPlugin(plugin);
 
  134    mp->AggregateObject(
this);
 
 
  148    for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  152        if ((*i)->GetBeaconInterval().IsZero())
 
  157        retval->AddNeighboursTimingElementUnit((*i)->GetLocalAid(),
 
  158                                               (*i)->GetLastBeacon(),
 
  159                                               (*i)->GetBeaconInterval());
 
 
  174        if (i->second->GetAddress() == peerAddress)
 
  185            peerLink->MLMEActivePeerLinkOpen();
 
  195        peerLink->SetBeaconTimingElement(*
PeekPointer(timingElement));
 
 
  214            peerLink = 
InitiateLink(interface, peerAddress, peerMeshPointAddress);
 
  220                                 peerMeshPointAddress);
 
  226                                 peerMeshPointAddress,
 
  240                                peerMeshPointAddress);
 
 
  264                                                << 
" failed, link will be closed");
 
  268        peerLink->TransmissionFailure();
 
 
  279        peerLink->TransmissionSuccess();
 
 
  300    new_link->SetInterface(interface);
 
  302    new_link->SetPeerAddress(peerAddress);
 
  303    new_link->SetPeerMeshPointAddress(peerMeshPointAddress);
 
  304    new_link->SetMacPlugin(plugin->second);
 
  305    new_link->MLMESetSignalStatusCallback(
 
  307    iface->second.push_back(new_link);
 
 
  316    for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  318        if ((*i)->GetPeerAddress() == peerAddress)
 
  320            if ((*i)->LinkIsIdle())
 
  323                (iface->second).erase(i);
 
 
  342std::vector<Mac48Address>
 
  345    std::vector<Mac48Address> retval;
 
  348    for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  350        if ((*i)->LinkIsEstab())
 
  352            retval.push_back((*i)->GetPeerAddress());
 
 
  358std::vector<Ptr<PeerLink>>
 
  361    std::vector<Ptr<PeerLink>> links;
 
  365        for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  367            if ((*i)->LinkIsEstab())
 
 
  382        return peerLink->LinkIsEstab();
 
 
  424    auto lastBeaconInTimeElement = (uint16_t)((lastBeacon->second.GetMicroSeconds() >> 8) & 0xffff);
 
  427                  "Wrong beacon shift parameters");
 
  429    if (iface->second.empty())
 
  437    for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  439        bool myBeaconExists = 
false;
 
  441            (*i)->GetBeaconTimingElement().GetNeighboursTimingElementsList();
 
  442        for (
auto j = neighbors.begin(); j != neighbors.end(); j++)
 
  444            if ((*i)->GetPeerAid() == (*j)->GetAid())
 
  447                myBeaconExists = 
true;
 
  450            if (((int16_t)((*j)->GetLastBeacon() - lastBeaconInTimeElement) >= 0) &&
 
  451                (((*j)->GetLastBeacon() - lastBeaconInTimeElement) %
 
  452                     (4 * 
TimeToTu(beaconInterval->second)) ==
 
 
  476    } 
while (shift == 0);
 
  480    plugin->second->SetBeaconShift(
TuToTime(shift));
 
 
  492    return (
int)(x.GetMicroSeconds() / 1024);
 
 
  501    NS_LOG_LOGIC(
"link_open " << myIface << 
" " << peerIface);
 
 
  517    NS_LOG_LOGIC(
"link_close " << myIface << 
" " << peerIface);
 
 
  537                                    << 
" and peer mesh point:" << peerMeshPointAddress
 
  538                                    << 
" and its interface:" << peerAddress
 
  539                                    << 
", at my interface ID:" << interface << 
". State movement:" 
  544        NotifyLinkOpen(peerMeshPointAddress, peerAddress, plugin->second->GetAddress(), interface);
 
  548        NotifyLinkClose(peerMeshPointAddress, peerAddress, plugin->second->GetAddress(), interface);
 
 
  617    os << 
"<PeerManagementProtocol>" << std::endl;
 
  622        plugins->second->Report(os);
 
  624        auto iface = 
m_peerLinks.find(plugins->second->m_ifIndex);
 
  626        for (
auto i = iface->second.begin(); i != iface->second.end(); i++)
 
  631    os << 
"</PeerManagementProtocol>" << std::endl;
 
 
  640        plugins->second->ResetStats();
 
 
AttributeValue implementation for Boolean.
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.
Smart pointer class similar to boost::intrusive_ptr.
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.
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...
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MicroSeconds(uint64_t 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.
U * PeekPointer(const Ptr< U > &p)
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...
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.