A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
peer-management-protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Kirill Andreev <andreev@iitp.ru>
18 * Aleksey Kovalenko <kovalenko@iitp.ru>
19 */
20
21#ifndef DOT11S_PEER_MAN_H
22#define DOT11S_PEER_MAN_H
23
26#include "peer-link.h"
27
28#include "ns3/event-id.h"
29#include "ns3/mac48-address.h"
30#include "ns3/net-device.h"
31#include "ns3/nstime.h"
32#include "ns3/traced-value.h"
33
34#include <map>
35
36namespace ns3
37{
38class MeshPointDevice;
39class UniformRandomVariable;
40
41namespace dot11s
42{
43class PeerManagementProtocolMac;
44class PeerLink;
45class IeMeshId;
46class IePeerManagement;
47class IeConfiguration;
48
49/**
50 * \ingroup dot11s
51 *
52 * \brief 802.11s Peer Management Protocol model
53 */
55{
56 public:
58 ~PeerManagementProtocol() override;
59
60 // Delete copy constructor and assignment operator to avoid misuse
63
64 /**
65 * \brief Get the type ID.
66 * \return the object TypeId
67 */
68 static TypeId GetTypeId();
69 void DoDispose() override;
70 /**
71 * \brief Install PMP on given mesh point.
72 * \param mp the MeshPointDevice to install onto
73 * \return true if successful
74 *
75 * Installing protocol causes installation of its interface MAC plugins.
76 *
77 * Also MP aggregates all installed protocols, PMP protocol can be accessed
78 * via MeshPointDevice::GetObject<PeerManagementProtocol>();
79 */
81 /**
82 * \brief Methods that handle beacon sending/receiving procedure.
83 *
84 * \name This methods interact with MAC_layer plug-in
85 */
86 ///@{
87 /**
88 * \brief When we are sending a beacon - we fill beacon timing
89 * element
90 * \return IeBeaconTiming is a beacon timing element that should be present in beacon
91 * \param interface is a interface sending a beacon
92 */
94 /**
95 * \brief To initiate peer link we must notify about received beacon
96 * \param interface the interface where a beacon was received from
97 * \param peerAddress address of station, which sent a beacon
98 * \param beaconInterval beacon interval (needed by beacon loss counter)
99 * \param beaconTiming beacon timing element (needed by BCA)
100 */
101 void ReceiveBeacon(uint32_t interface,
102 Mac48Address peerAddress,
103 Time beaconInterval,
104 Ptr<IeBeaconTiming> beaconTiming);
105 ///@}
106
107 /**
108 * \name Methods that handle Peer link management frames interaction:
109 */
110 ///@{
111 /**
112 * Deliver Peer link management information to the protocol-part
113 * \param interface is a interface ID of a given MAC (interfaceID rather than MAC address,
114 * because many interfaces may have the same MAC)
115 * \param peerAddress is address of peer
116 * \param peerMeshPointAddress is address of peer mesh point device (equal to peer address when
117 * only one interface)
118 * \param aid is association ID, which peer has assigned to us
119 * \param peerManagementElement is peer link management element
120 * \param meshConfig is mesh configuration element taken from the peer management frame
121 */
122 void ReceivePeerLinkFrame(uint32_t interface,
123 Mac48Address peerAddress,
124 Mac48Address peerMeshPointAddress,
125 uint16_t aid,
126 IePeerManagement peerManagementElement,
127 IeConfiguration meshConfig);
128 /**
129 * \brief Cancels peer link due to broken configuration (Mesh ID or Supported
130 * rates)
131 * \param interface interface of the link to cancel
132 * \param peerAddress peer address of the link to cancel
133 */
134 void ConfigurationMismatch(uint32_t interface, Mac48Address peerAddress);
135 /**
136 * \brief Cancels peer link due to successive transmission failures
137 * \param interface interface of the link to cancel
138 * \param peerAddress peer address of the link to cancel
139 */
140 void TransmissionFailure(uint32_t interface, const Mac48Address peerAddress);
141 /**
142 * \brief resets transmission failure statistics
143 * \param interface interface of the link to reset
144 * \param peerAddress peer address of the link to reset
145 */
146 void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress);
147 /**
148 * \brief Checks if there is established link
149 * \param interface interface of the link to check
150 * \param peerAddress peer address of the link to check
151 * \return true if the link is active
152 */
153 bool IsActiveLink(uint32_t interface, Mac48Address peerAddress);
154 ///@}
155
156 /// \name Interface to other protocols (MLME)
157 ///@{
158 /**
159 * Set peer link status change callback
160 * \param cb the callback
161 */
163 /**
164 * Find active peer link by my interface and peer interface MAC
165 * \param interface interface of the link to find
166 * \param peerAddress peer address of the link to find
167 * \return The peer link (null if not found)
168 */
169 Ptr<PeerLink> FindPeerLink(uint32_t interface, Mac48Address peerAddress);
170 /**
171 * Get list of all active peer links
172 * \return a list of all the active peer links
173 */
174 std::vector<Ptr<PeerLink>> GetPeerLinks() const;
175 /**
176 * Get list of active peers of my given interface
177 * \param interface the interface
178 * \return a list of all the active peer links on an interface
179 */
180 std::vector<Mac48Address> GetPeers(uint32_t interface) const;
181 /**
182 * Get mesh point address. \todo this used by plugins only. Now MAC plugins can ask MP address
183 * directly from main MAC
184 *
185 * \return Mac48Address
186 */
188 /**
189 * Get number of links
190 * \returns the number of links
191 */
192 uint8_t GetNumberOfLinks() const;
193 /**
194 * Set mesh ID to a string value
195 * \param s the mesh ID string value
196 */
197 void SetMeshId(std::string s);
198 /**
199 * Get mesh ID information element
200 * \returns the mesh ID information element
201 */
202 Ptr<IeMeshId> GetMeshId() const;
203 /**
204 * Enable or disable beacon collision avoidance
205 * \param enable true to enable beacon collision avoidance
206 */
207 void SetBeaconCollisionAvoidance(bool enable);
208 /**
209 * Get beacon collision avoidance
210 * \returns the beacon collision avoidance flag
211 */
212 bool GetBeaconCollisionAvoidance() const;
213 /**
214 * Notify about beacon send event, needed to schedule BCA
215 * \param interface the interface to use
216 * \param beaconInterval the beacon interval
217 */
218 void NotifyBeaconSent(uint32_t interface, Time beaconInterval);
219 ///@}
220
221 /**
222 * \brief Report statistics
223 * \param os the output stream
224 */
225 void Report(std::ostream& os) const;
226 /// Reset statistics function
227 void ResetStats();
228 /**
229 * Assign a fixed random variable stream number to the random variables
230 * used by this model. Return the number of streams (possibly zero) that
231 * have been assigned.
232 *
233 * \param stream first stream index to use
234 * \return the number of stream indices assigned by this model
235 */
236 int64_t AssignStreams(int64_t stream);
237
238 /**
239 * TracedCallback signature for link open/close events.
240 *
241 * \param [in] src MAC address of source interface.
242 * \param [in] dst MAC address of destination interface.
243 */
245
246 private:
247 void DoInitialize() override;
248
249 // Private structures
250 /// Keeps information about beacon of peer station: beacon interval, association ID, last time
251 /// we have received a beacon
253 {
254 uint16_t aid; ///< Assoc ID
255 Time referenceTbtt; ///< When one of my station's beacons was put into a beacon queue;
256 Time beaconInterval; ///< Beacon interval of my station;
257 };
258
259 /// We keep a vector of pointers to PeerLink class. This vector
260 /// keeps all peer links at a given interface.
261 typedef std::vector<Ptr<PeerLink>> PeerLinksOnInterface;
262 /// This map keeps all peer links.
263 typedef std::map<uint32_t, PeerLinksOnInterface> PeerLinksMap;
264 /// This map keeps relationship between peer address and its beacon information
265 typedef std::map<Mac48Address, BeaconInfo> BeaconsOnInterface;
266 ///\brief This map keeps beacon information on all interfaces
267 typedef std::map<uint32_t, BeaconsOnInterface> BeaconInfoMap;
268 ///\brief this vector keeps pointers to MAC-plugins
269 typedef std::map<uint32_t, Ptr<PeerManagementProtocolMac>> PeerManagementProtocolMacMap;
270
271 /**
272 * Initiate link function
273 *
274 * \param interface the interface to use
275 * \param peerAddress the peer address
276 * \param peerMeshPointAddress the peer mesh point address
277 * \returns the peer link
278 */
280 Mac48Address peerAddress,
281 Mac48Address peerMeshPointAddress);
282 /**
283 * \brief External peer-chooser
284 * \param interface the interface to use
285 * \param peerAddress the peer address
286 * \returns true is should send an open
287 */
288 bool ShouldSendOpen(uint32_t interface, Mac48Address peerAddress) const;
289 /**
290 * \brief External peer-chooser
291 * \param interface the interface to use
292 * \param peerAddress the peer address
293 * \param reasonCode reason code
294 * \returns true is should send an open
295 */
296 bool ShouldAcceptOpen(uint32_t interface,
297 Mac48Address peerAddress,
298 PmpReasonCode& reasonCode) const;
299 /**
300 * \brief Indicates changes in peer links
301 * \param interface the interface
302 * \param peerAddress the peer address
303 * \param peerMeshPointAddress the peer mesh point address
304 * \param ostate old state
305 * \param nstate new state
306 */
307 void PeerLinkStatus(uint32_t interface,
308 Mac48Address peerAddress,
309 Mac48Address peerMeshPointAddress,
310 PeerLink::PeerState ostate,
311 PeerLink::PeerState nstate);
312 /**
313 * \brief BCA
314 * \param interface interface
315 */
316 void CheckBeaconCollisions(uint32_t interface);
317 /**
318 * Shift own beacon function
319 * \param interface interface
320 */
321 void ShiftOwnBeacon(uint32_t interface);
322 /**
323 * \brief Time<-->TU converters:
324 * \param x TU
325 * \return Time
326 */
327 Time TuToTime(int x);
328 /**
329 * \brief Time<-->TU converters:
330 * \param x Time
331 * \return TU
332 */
333 int TimeToTu(Time x);
334
335 /**
336 * Aux. method to register open links
337 * \param peerMp peer mesh point address
338 * \param peerIface peer address
339 * \param myIface my address
340 * \param interface interface
341 */
342 void NotifyLinkOpen(Mac48Address peerMp,
343 Mac48Address peerIface,
344 Mac48Address myIface,
345 uint32_t interface);
346 /**
347 * Aux. method to register closed links
348 * \param peerMp peer mesh point address
349 * \param peerIface peer address
350 * \param myIface my address
351 * \param interface interface
352 */
353 void NotifyLinkClose(Mac48Address peerMp,
354 Mac48Address peerIface,
355 Mac48Address myIface,
356 uint32_t interface);
357
358 private:
362
363 uint16_t m_lastAssocId; ///< last associated ID
364 uint16_t m_lastLocalLinkId; ///< last local link ID
365 uint8_t m_maxNumberOfPeerLinks; ///< maimum number of peer links
366 /// Flag which enables BCA
368 /// Beacon can be shifted at [-m_maxBeaconShift; +m_maxBeaconShift] TUs
370 /// Last beacon at each interface
371 std::map<uint32_t, Time> m_lastBeacon;
372 /// Beacon interval at each interface
373 std::map<uint32_t, Time> m_beaconInterval;
374
375 /**
376 * \name Peer Links
377 */
379 /**
380 * \brief Callback to notify about peer link changes:
381 * Mac48Address is peer address of mesh point,
382 * Mac48Address is peer address of interface,
383 * uint32_t - interface ID,
384 * bool is status - true when new link has appeared, false - when link was closed,
385 */
387
388 /// Simple link open/close trace source type. Addresses are: src interface, dst interface
390 /// LinkOpen trace source
392 /// LinkClose trace source
394
395 /// Statistics structure
397 {
398 uint16_t linksTotal; ///< total links
399 uint16_t linksOpened; ///< opened links
400 uint16_t linksClosed; ///< links closed
401
402 /**
403 * Constructor
404 *
405 * \param t
406 */
407 Statistics(uint16_t t = 0);
408 /**
409 * Print function
410 * \param os the output stream to print to
411 */
412 void Print(std::ostream& os) const;
413 };
414
415 Statistics m_stats; ///< statistics
416
417 /// Add randomness to beacon shift
419};
420
421} // namespace dot11s
422} // namespace ns3
423#endif
Callback template class.
Definition: callback.h:438
an EUI-48 address
Definition: mac48-address.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
according to IEEE 802.11 - 2012
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.
std::map< Mac48Address, BeaconInfo > BeaconsOnInterface
This map keeps relationship between peer address and its beacon information.
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.
void(* LinkOpenCloseTracedCallback)(Mac48Address src, const Mac48Address dst)
TracedCallback signature for link open/close events.
std::map< uint32_t, Ptr< PeerManagementProtocolMac > > PeerManagementProtocolMacMap
this vector keeps pointers to MAC-plugins
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.
std::map< uint32_t, BeaconsOnInterface > BeaconInfoMap
This map keeps beacon information on all interfaces.
PeerManagementProtocol(const PeerManagementProtocol &)=delete
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.
std::map< uint32_t, PeerLinksOnInterface > PeerLinksMap
This map keeps all peer links.
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.
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.
TracedCallback< Mac48Address, Mac48Address > LinkEventCallback
Simple link open/close trace source type. Addresses are: src interface, dst interface.
void CheckBeaconCollisions(uint32_t interface)
BCA.
Ptr< IeBeaconTiming > GetBeaconTimingElement(uint32_t interface)
When we are sending a beacon - we fill beacon timing element.
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.
PeerManagementProtocol & operator=(const PeerManagementProtocol &)=delete
void SetBeaconCollisionAvoidance(bool enable)
Enable or disable beacon collision avoidance.
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Keeps information about beacon of peer station: beacon interval, association ID, last time we have re...
Time referenceTbtt
When one of my station's beacons was put into a beacon queue;.
Time beaconInterval
Beacon interval of my station;.
void Print(std::ostream &os) const
Print function.