A Discrete-Event Network Simulator
API
peer-link.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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  * Pavel Boyko <boyko@iitp.ru>
20  */
21 
22 #include "peer-link.h"
23 
25 
26 #include "ns3/log.h"
27 #include "ns3/simulator.h"
28 #include "ns3/traced-value.h"
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("Dot11sPeerManagementProtocol");
34 
35 namespace dot11s
36 {
37 
39 
40 TypeId
42 {
43  static TypeId tid =
44  TypeId("ns3::dot11s::PeerLink")
45  .SetParent<Object>()
46  .SetGroupName("Mesh")
47  .AddConstructor<PeerLink>()
48  .AddAttribute("RetryTimeout",
49  "Retry timeout",
50  TimeValue(TimeValue(MicroSeconds(40 * 1024))),
53  .AddAttribute("HoldingTimeout",
54  "Holding timeout",
55  TimeValue(TimeValue(MicroSeconds(40 * 1024))),
58  .AddAttribute("ConfirmTimeout",
59  "Confirm timeout",
60  TimeValue(TimeValue(MicroSeconds(40 * 1024))),
63  .AddAttribute("MaxRetries",
64  "Maximum number of retries",
65  UintegerValue(4),
67  MakeUintegerChecker<uint16_t>())
68  .AddAttribute("MaxBeaconLoss",
69  "Maximum number of lost beacons before link will be closed",
70  UintegerValue(2),
72  MakeUintegerChecker<uint16_t>(1))
73  .AddAttribute("MaxPacketFailure",
74  "Maximum number of failed packets before link will be closed",
75  UintegerValue(2),
77  MakeUintegerChecker<uint16_t>(1));
78  return tid;
79 }
80 
81 const char* const PeerLink::PeerStateNames[6] =
82  {"IDLE", "OPN_SNT", "CNF_RCVD", "OPN_RCVD", "ESTAB", "HOLDING"};
83 
84 //-----------------------------------------------------------------------------
85 // PeerLink public interface
86 //-----------------------------------------------------------------------------
88  : m_peerAddress(Mac48Address::GetBroadcast()),
89  m_peerMeshPointAddress(Mac48Address::GetBroadcast()),
90  m_localLinkId(0),
91  m_peerLinkId(0),
92  m_assocId(0),
93  m_peerAssocId(0),
94  m_lastBeacon(Seconds(0)),
95  m_beaconInterval(Seconds(0)),
96  m_packetFail(0),
97  m_state(IDLE),
98  m_retryCounter(0),
99  m_maxPacketFail(3)
100 {
101  NS_LOG_FUNCTION(this);
102 }
103 
105 {
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION(this);
117 }
118 
119 void
121 {
122  m_peerAddress = macaddr;
123 }
124 
125 void
127 {
128  m_peerMeshPointAddress = macaddr;
129 }
130 
131 void
132 PeerLink::SetInterface(uint32_t interface)
133 {
134  m_interface = interface;
135 }
136 
137 void
139 {
140  m_localLinkId = id;
141 }
142 
143 void
145 {
146  m_assocId = aid;
147 }
148 
149 void
150 PeerLink::SetBeaconInformation(Time lastBeacon, Time beaconInterval)
151 {
152  m_lastBeacon = lastBeacon;
153  m_beaconInterval = beaconInterval;
155  Time delay = Seconds(beaconInterval.GetSeconds() * m_maxBeaconLoss);
156  NS_ASSERT(delay.GetMicroSeconds() != 0);
158 }
159 
160 void
162 {
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION(this);
171 }
172 
173 void
175 {
176  m_packetFail = 0;
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION(this);
183  m_packetFail++;
185  {
186  NS_LOG_DEBUG("TransmissionFailure:: CNCL");
188  m_packetFail = 0;
189  }
190 }
191 
192 void
194 {
195  m_beaconTiming = beaconTiming;
196 }
197 
200 {
201  return m_peerAddress;
202 }
203 
204 uint16_t
206 {
207  return m_assocId;
208 }
209 
210 uint16_t
212 {
213  return m_peerAssocId;
214 }
215 
216 Time
218 {
219  return m_lastBeacon;
220 }
221 
222 Time
224 {
225  return m_beaconInterval;
226 }
227 
230 {
231  return m_beaconTiming;
232 }
233 
234 void
236 {
237  StateMachine(CNCL, reason);
238 }
239 
240 void
242 {
244 }
245 
246 void
248 {
250 }
251 
252 void
253 PeerLink::Close(uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reason)
254 {
255  NS_LOG_FUNCTION(this << localLinkId << peerLinkId << reason);
256  if (peerLinkId != 0 && m_localLinkId != peerLinkId)
257  {
258  return;
259  }
260  if (m_peerLinkId == 0)
261  {
262  m_peerLinkId = localLinkId;
263  }
264  else
265  {
266  if (m_peerLinkId != localLinkId)
267  {
268  return;
269  }
270  }
271  StateMachine(CLS_ACPT, reason);
272 }
273 
274 void
276 {
277  NS_LOG_FUNCTION(this << localLinkId << peerMp);
278  m_peerLinkId = localLinkId;
281  {
283  }
284  else
285  {
286  m_peerMeshPointAddress = peerMp;
287  }
289 }
290 
291 void
292 PeerLink::OpenReject(uint16_t localLinkId,
294  Mac48Address peerMp,
295  PmpReasonCode reason)
296 {
297  NS_LOG_FUNCTION(this << localLinkId << peerMp << reason);
298  if (m_peerLinkId == 0)
299  {
300  m_peerLinkId = localLinkId;
301  }
304  {
306  }
307  else
308  {
309  m_peerMeshPointAddress = peerMp;
310  }
311  StateMachine(OPN_RJCT, reason);
312 }
313 
314 void
315 PeerLink::ConfirmAccept(uint16_t localLinkId,
316  uint16_t peerLinkId,
317  uint16_t peerAid,
319  Mac48Address peerMp)
320 {
321  NS_LOG_FUNCTION(this << localLinkId << peerLinkId << peerAid << peerMp);
322  if (m_localLinkId != peerLinkId)
323  {
324  return;
325  }
326  if (m_peerLinkId == 0)
327  {
328  m_peerLinkId = localLinkId;
329  }
330  else
331  {
332  if (m_peerLinkId != localLinkId)
333  {
334  return;
335  }
336  }
338  m_peerAssocId = peerAid;
340  {
342  }
343  else
344  {
345  m_peerMeshPointAddress = peerMp;
346  }
348 }
349 
350 void
351 PeerLink::ConfirmReject(uint16_t localLinkId,
352  uint16_t peerLinkId,
354  Mac48Address peerMp,
355  PmpReasonCode reason)
356 {
357  NS_LOG_FUNCTION(this << localLinkId << peerLinkId << peerMp << reason);
358  if (m_localLinkId != peerLinkId)
359  {
360  return;
361  }
362  if (m_peerLinkId == 0)
363  {
364  m_peerLinkId = localLinkId;
365  }
366  else
367  {
368  if (m_peerLinkId != localLinkId)
369  {
370  return;
371  }
372  }
375  {
377  }
378  m_peerMeshPointAddress = peerMp;
379  StateMachine(CNF_RJCT, reason);
380 }
381 
382 bool
384 {
385  return (m_state == ESTAB);
386 }
387 
388 bool
390 {
391  return (m_state == IDLE);
392 }
393 
394 void
396 {
397  m_macPlugin = plugin;
398 }
399 
400 //-----------------------------------------------------------------------------
401 // Private
402 //-----------------------------------------------------------------------------
403 void
405 {
406  switch (m_state)
407  {
408  case IDLE:
409  switch (event)
410  {
411  case CNCL:
412  case CLS_ACPT:
413  m_state = IDLE;
415  break;
416  case REQ_RJCT:
417  SendPeerLinkClose(reasoncode);
418  break;
419  case ACTOPN:
420  m_state = OPN_SNT;
423  SetRetryTimer();
424  break;
425  case OPN_ACPT:
426  m_state = OPN_RCVD;
430  IDLE,
431  OPN_RCVD);
434  SetRetryTimer();
435  break;
436  default:
437  // 11B.5.3.4 of 802.11s Draft D3.0
438  // All other events shall be ignored in this state
439  break;
440  }
441  break;
442  case OPN_SNT:
443  switch (event)
444  {
445  case TOR1:
447  m_retryCounter++;
448  SetRetryTimer();
449  break;
450  case CNF_ACPT:
451  m_state = CNF_RCVD;
455  OPN_SNT,
456  CNF_RCVD);
457  ClearRetryTimer();
458  SetConfirmTimer();
459  break;
460  case OPN_ACPT:
461  m_state = OPN_RCVD;
465  OPN_SNT,
466  OPN_RCVD);
468  break;
469  case CLS_ACPT:
470  m_state = HOLDING;
474  OPN_SNT,
475  HOLDING);
476  ClearRetryTimer();
478  SetHoldingTimer();
479  break;
480  case OPN_RJCT:
481  case CNF_RJCT:
482  m_state = HOLDING;
486  OPN_SNT,
487  HOLDING);
488  ClearRetryTimer();
489  SendPeerLinkClose(reasoncode);
490  SetHoldingTimer();
491  break;
492  case TOR2:
493  m_state = HOLDING;
497  OPN_SNT,
498  HOLDING);
499  ClearRetryTimer();
501  SetHoldingTimer();
502  break;
503  case CNCL:
504  m_state = HOLDING;
508  OPN_SNT,
509  HOLDING);
510  ClearRetryTimer();
512  SetHoldingTimer();
513  break;
514  default:
515  // 11B.5.3.5 of 802.11s Draft D3.0
516  // All other events shall be ignored in this state
517  break;
518  }
519  break;
520  case CNF_RCVD:
521  switch (event)
522  {
523  case CNF_ACPT:
524  break;
525  case OPN_ACPT:
526  m_state = ESTAB;
530  CNF_RCVD,
531  ESTAB);
535  break;
536  case CLS_ACPT:
537  m_state = HOLDING;
541  CNF_RCVD,
542  HOLDING);
545  SetHoldingTimer();
546  break;
547  case CNF_RJCT:
548  case OPN_RJCT:
549  m_state = HOLDING;
553  CNF_RCVD,
554  HOLDING);
556  SendPeerLinkClose(reasoncode);
557  SetHoldingTimer();
558  break;
559  case CNCL:
560  m_state = HOLDING;
564  CNF_RCVD,
565  HOLDING);
568  SetHoldingTimer();
569  break;
570  case TOC:
571  m_state = HOLDING;
575  CNF_RCVD,
576  HOLDING);
578  SetHoldingTimer();
579  break;
580  default:
581  // 11B.5.3.6 of 802.11s Draft D3.0
582  // All other events shall be ignored in this state
583  break;
584  }
585  break;
586  case OPN_RCVD:
587  switch (event)
588  {
589  case TOR1:
591  m_retryCounter++;
592  SetRetryTimer();
593  break;
594  case CNF_ACPT:
595  m_state = ESTAB;
599  OPN_RCVD,
600  ESTAB);
601  ClearRetryTimer();
603  break;
604  case CLS_ACPT:
605  m_state = HOLDING;
609  OPN_RCVD,
610  HOLDING);
611  ClearRetryTimer();
613  SetHoldingTimer();
614  break;
615  case OPN_RJCT:
616  case CNF_RJCT:
617  m_state = HOLDING;
621  OPN_RCVD,
622  HOLDING);
623  ClearRetryTimer();
624  SendPeerLinkClose(reasoncode);
625  SetHoldingTimer();
626  break;
627  case TOR2:
628  m_state = HOLDING;
632  OPN_RCVD,
633  HOLDING);
634  ClearRetryTimer();
636  SetHoldingTimer();
637  break;
638  case CNCL:
639  m_state = HOLDING;
643  OPN_RCVD,
644  HOLDING);
645  ClearRetryTimer();
647  SetHoldingTimer();
648  break;
649  default:
650  // 11B.5.3.7 of 802.11s Draft D3.0
651  // All other events shall be ignored in this state
652  break;
653  }
654  break;
655  case ESTAB:
656  switch (event)
657  {
658  case OPN_ACPT:
660  break;
661  case CLS_ACPT:
662  m_state = HOLDING;
666  ESTAB,
667  HOLDING);
669  SetHoldingTimer();
670  break;
671  case OPN_RJCT:
672  case CNF_RJCT:
673  m_state = HOLDING;
677  ESTAB,
678  HOLDING);
679  ClearRetryTimer();
680  SendPeerLinkClose(reasoncode);
681  SetHoldingTimer();
682  break;
683  case CNCL:
684  m_state = HOLDING;
688  ESTAB,
689  HOLDING);
691  SetHoldingTimer();
692  break;
693  default:
694  // 11B.5.3.8 of 802.11s Draft D3.0
695  // All other events shall be ignored in this state
696  break;
697  }
698  break;
699  case HOLDING:
700  switch (event)
701  {
702  case CLS_ACPT:
704  // fall through:
705  case TOH:
706  m_state = IDLE;
708  break;
709  case OPN_ACPT:
710  case CNF_ACPT:
711  m_state = HOLDING;
715  HOLDING,
716  HOLDING);
717  // reason not spec in D2.0
719  break;
720  case OPN_RJCT:
721  case CNF_RJCT:
722  m_state = HOLDING;
726  HOLDING,
727  HOLDING);
728  SendPeerLinkClose(reasoncode);
729  break;
730  default:
731  // 11B.5.3.9 of 802.11s Draft D3.0
732  // All other events shall be ignored in this state
733  break;
734  }
735  break;
736  }
737 }
738 
739 void
741 {
743 }
744 
745 void
747 {
749 }
750 
751 void
753 {
755 }
756 
757 void
759 {
760  IePeerManagement peerElement;
761  peerElement.SetPeerClose(m_localLinkId, m_peerLinkId, reasoncode);
764  m_assocId,
765  peerElement,
767 }
768 
769 void
771 {
772  IePeerManagement peerElement;
773  peerElement.SetPeerOpen(m_localLinkId);
777  m_assocId,
778  peerElement,
780 }
781 
782 void
784 {
785  IePeerManagement peerElement;
789  m_assocId,
790  peerElement,
792 }
793 
794 void
796 {
800 }
801 
802 void
804 {
805  NS_LOG_FUNCTION(this);
806  StateMachine(TOH);
807 }
808 
809 void
811 {
814 }
815 
816 void
818 {
819  NS_LOG_FUNCTION(this);
821  {
822  NS_LOG_LOGIC("Retry timeout TOR1");
824  }
825  else
826  {
827  NS_LOG_LOGIC("Retry timeout TOR2");
829  }
830 }
831 
832 void
834 {
838 }
839 
840 void
842 {
843  StateMachine(TOC);
844 }
845 
846 void
847 PeerLink::Report(std::ostream& os) const
848 {
849  if (m_state != ESTAB)
850  {
851  return;
852  }
853  os << "<PeerLink" << std::endl
854  << "localAddress=\"" << m_macPlugin->GetAddress() << "\"" << std::endl
855  << "peerInterfaceAddress=\"" << m_peerAddress << "\"" << std::endl
856  << "peerMeshPointAddress=\"" << m_peerMeshPointAddress << "\"" << std::endl
857  << "metric=\"" << m_macPlugin->GetLinkMetric(m_peerAddress) << "\"" << std::endl
858  << "lastBeacon=\"" << m_lastBeacon.GetSeconds() << "\"" << std::endl
859  << "localLinkId=\"" << m_localLinkId << "\"" << std::endl
860  << "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl
861  << "assocId=\"" << m_assocId << "\"" << std::endl
862  << "/>" << std::endl;
863 }
864 } // namespace dot11s
865 } // namespace ns3
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition: object.h:89
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:413
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
See 7.3.2.89 of 802.11s draft 2.07.
void ClearTimingElement()
Clear timing element.
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
according to IEEE 802.11 - 2012
void SetPeerConfirm(uint16_t localLinkID, uint16_t peerLinkId)
Set peer confirm function.
void SetPeerOpen(uint16_t localLinkId)
Set peer open function.
void SetPeerClose(uint16_t localLinkID, uint16_t peerLinkId, PmpReasonCode reasonCode)
Set peer close function.
Mac48Address GetAddress() const
debug only, used to print established links
void SendPeerLinkManagementFrame(Mac48Address peerAddress, Mac48Address peerMpAddress, uint16_t aid, IePeerManagement peerElement, IeConfiguration meshConfig)
Send peer link management frame function.
uint32_t GetLinkMetric(Mac48Address peerAddress)
Get the link metric.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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.
Definition: object-base.h:46
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Definition: conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
@ IDLE
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:76