A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
peer-management-protocol.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Kirill Andreev <andreev@iitp.ru>
19  * Aleksey Kovalenko <kovalenko@iitp.ru>
20  */
21 
22 #ifndef DOT11S_PEER_MAN_H
23 #define DOT11S_PEER_MAN_H
24 
25 #include "ns3/mac48-address.h"
26 #include "ns3/net-device.h"
27 #include "ns3/event-id.h"
28 #include "ns3/nstime.h"
29 #include "ns3/traced-value.h"
30 #include "ie-dot11s-beacon-timing.h"
31 #include "ie-dot11s-peer-management.h"
32 #include "peer-link.h"
33 
34 #include <map>
35 namespace ns3 {
36 class MeshPointDevice;
37 class UniformRandomVariable;
38 namespace dot11s {
39 class PeerManagementProtocolMac;
40 class PeerLink;
41 class IeMeshId;
42 class IePeerManagement;
43 class IeConfiguration;
50 {
51 public:
54  static TypeId GetTypeId ();
55  void DoDispose ();
77  Ptr<IeBeaconTiming> GetBeaconTimingElement (uint32_t interface);
85  void ReceiveBeacon (uint32_t interface, Mac48Address peerAddress, Time beaconInterval, Ptr<IeBeaconTiming> beaconTiming);
86  // \}
104  void ReceivePeerLinkFrame (
105  uint32_t interface,
106  Mac48Address peerAddress,
107  Mac48Address peerMeshPointAddress,
108  uint16_t aid,
109  IePeerManagement peerManagementElement,
110  IeConfiguration meshConfig
111  );
116  void ConfigurationMismatch (uint32_t interface, Mac48Address peerAddress);
120  void TransmissionFailure (uint32_t interface, const Mac48Address peerAddress);
124  void TransmissionSuccess (uint32_t interface, const Mac48Address peerAddress);
128  bool IsActiveLink (uint32_t interface, Mac48Address peerAddress);
129  // \}
131  // \{
135  Ptr<PeerLink> FindPeerLink (uint32_t interface, Mac48Address peerAddress);
137  std::vector < Ptr<PeerLink> > GetPeerLinks () const;
139  std::vector<Mac48Address> GetPeers (uint32_t interface) const;
142  uint8_t GetNumberOfLinks ();
143  void SetMeshId (std::string s);
144  Ptr<IeMeshId> GetMeshId () const;
146  void SetBeaconCollisionAvoidance (bool enable);
147  bool GetBeaconCollisionAvoidance () const;
149  void NotifyBeaconSent (uint32_t interface, Time beaconInterval);
151  void Report (std::ostream &) const;
152  void ResetStats ();
161  int64_t AssignStreams (int64_t stream);
162 
163 private:
164  virtual void DoInitialize ();
169  struct BeaconInfo
171  {
172  uint16_t aid; //Assoc ID
173  Time referenceTbtt; //When one of my station's beacons was put into a beacon queue;
174  Time beaconInterval; //Beacon interval of my station;
175  };
178  typedef std::vector<Ptr<PeerLink> > PeerLinksOnInterface;
180  typedef std::map<uint32_t, PeerLinksOnInterface> PeerLinksMap;
182  typedef std::map<Mac48Address, BeaconInfo> BeaconsOnInterface;
184  typedef std::map<uint32_t, BeaconsOnInterface> BeaconInfoMap;
186  typedef std::map<uint32_t, Ptr<PeerManagementProtocolMac> > PeerManagementProtocolMacMap;
187  // \}
188 private:
189  PeerManagementProtocol& operator= (const PeerManagementProtocol &);
191 
192  Ptr<PeerLink> InitiateLink (
193  uint32_t interface,
194  Mac48Address peerAddress,
195  Mac48Address peerMeshPointAddress
196  );
201  bool ShouldSendOpen (uint32_t interface, Mac48Address peerAddress);
202  bool ShouldAcceptOpen (uint32_t interface, Mac48Address peerAddress, PmpReasonCode & reasonCode);
207  void PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddres, PeerLink::PeerState ostate, PeerLink::PeerState nstate);
209  void CheckBeaconCollisions (uint32_t interface);
210  void ShiftOwnBeacon (uint32_t interface);
215  Time TuToTime (int x);
216  int TimeToTu (Time x);
217  // \}
218 
220  void NotifyLinkOpen (Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface);
222  void NotifyLinkClose (Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface);
223 private:
225  Mac48Address m_address;
226  Ptr<IeMeshId> m_meshId;
227 
228  uint16_t m_lastAssocId;
229  uint16_t m_lastLocalLinkId;
230  uint8_t m_maxNumberOfPeerLinks;
236  std::map<uint32_t, Time> m_lastBeacon;
238  std::map<uint32_t, Time> m_beaconInterval;
239 
244  PeerLinksMap m_peerLinks;
256 
263 
265  // \{
266  struct Statistics {
267  uint16_t linksTotal;
268  uint16_t linksOpened;
269  uint16_t linksClosed;
270 
271  Statistics (uint16_t t = 0);
272  void Print (std::ostream & os) const;
273  };
274  struct Statistics m_stats;
275  // \}
278 };
279 
280 } // namespace dot11s
281 } // namespace ns3
282 #endif
keep track of time unit.
Definition: nstime.h:149
void NotifyLinkClose(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux. method to register closed links.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Callback template class.
Definition: callback.h:369
void NotifyLinkOpen(Mac48Address peerMp, Mac48Address peerIface, Mac48Address myIface, uint32_t interface)
Aux. method to register open links.
Ptr< UniformRandomVariable > m_beaconShift
Add randomness to beacon shift.
void Report(std::ostream &) const
: Report statistics
Ptr< PeerLink > FindPeerLink(uint32_t interface, Mac48Address peerAddress)
Find active peer link by my interface and peer interface MAC.
LinkEventCallback m_linkCloseTraceSrc
LinkClose trace source.
TracedCallback< Mac48Address, Mac48Address > LinkEventCallback
Simple link open/close trace source type. Addresses are: src interface, dst interface.
bool IsActiveLink(uint32_t interface, Mac48Address peerAddress)
Checks if there is established link.
std::vector< Ptr< PeerLink > > PeerLinksOnInterface
std::vector< Mac48Address > GetPeers(uint32_t interface) const
Get list of active peers of my given interface.
See 7.3.2.85 of draft 2.07.
void NotifyBeaconSent(uint32_t interface, Time beaconInterval)
Notify about beacon send event, needed to schedule BCA.
Mac48Address GetAddress()
Get mesh point address. TODO this used by plugins only. Now MAC plugins can ask MP addrress directly ...
void SetPeerLinkStatusCallback(Callback< void, Mac48Address, Mac48Address, uint32_t, bool > cb)
Set peer link status change callback.
std::vector< Ptr< PeerLink > > GetPeerLinks() const
Get list of all active peer links.
std::map< uint32_t, PeerLinksOnInterface > PeerLinksMap
This map keeps all peer links.
an EUI-48 address
Definition: mac48-address.h:41
LinkEventCallback m_linkOpenTraceSrc
LinkOpen trace source.
void ReceivePeerLinkFrame(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress, uint16_t aid, IePeerManagement peerManagementElement, IeConfiguration meshConfig)
Methods that handle Peer link management frames interaction:
Ptr< IeBeaconTiming > GetBeaconTimingElement(uint32_t interface)
When we are sending a beacon - we fill beacon timing element.
void PeerLinkStatus(uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddres, PeerLink::PeerState ostate, PeerLink::PeerState nstate)
Indicates changes in peer links.
std::map< Mac48Address, BeaconInfo > BeaconsOnInterface
This map keeps relationship between peer address and its beacon information.
void ConfigurationMismatch(uint32_t interface, Mac48Address peerAddress)
Cancels peer link due to broken configuration (Mesh ID or Supported rates)
void TransmissionFailure(uint32_t interface, const Mac48Address peerAddress)
Cancels peer link due to successive transmission failures.
void CheckBeaconCollisions(uint32_t interface)
BCA.
std::map< uint32_t, Time > m_lastBeacon
Last beacon at each interface.
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
bool m_enableBca
Flag which enables BCA.
void ReceiveBeacon(uint32_t interface, Mac48Address peerAddress, Time beaconInterval, Ptr< IeBeaconTiming > beaconTiming)
To initiate peer link we must notify about received beacon.
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
std::map< uint32_t, Time > m_beaconInterval
Beacon interval at each interface.
void SetBeaconCollisionAvoidance(bool enable)
Enable or disable beacon collision avoidance.
a base class which provides memory management and object aggregation
Definition: object.h:63
std::map< uint32_t, Ptr< PeerManagementProtocolMac > > PeerManagementProtocolMacMap
this vector keeps pointers to MAC-plugins
Keeps information about beacon of peer station: beacon interval, association ID, last time we have re...
uint16_t m_maxBeaconShift
Beacon can be shifted at [-m_maxBeaconShift; +m_maxBeaconShift] TUs.
Callback< void, Mac48Address, Mac48Address, uint32_t, bool > m_peerStatusCallback
Callback to notify about peer link changes: Mac48Address is peer address of mesh point, Mac48Address is peer address of interface, uint32_t - interface ID, bool is status - true when new link has appeared, false - when link was closed,.
std::map< uint32_t, BeaconsOnInterface > BeaconInfoMap
This map keeps beacon information on all interfaces.
a unique identifier for an interface.
Definition: type-id.h:44
bool Install(Ptr< MeshPointDevice >)
Install PMP on given mesh point.
void TransmissionSuccess(uint32_t interface, const Mac48Address peerAddress)
resets transmission failure statistics
802.11s Peer Management Protocol model