A Discrete-Event Network Simulator
API
peer-link.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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  * Pavel Boyko <boyko@iitp.ru>
21  */
22 
24 #include "ns3/peer-link.h"
25 #include "ns3/log.h"
26 #include "ns3/simulator.h"
27 #include "ns3/traced-value.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("Dot11sPeerManagementProtocol");
32 
33 namespace dot11s {
34 
35 NS_OBJECT_ENSURE_REGISTERED ( PeerLink);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::dot11s::PeerLink")
41  .SetParent<Object> ()
42  .SetGroupName ("Mesh")
43  .AddConstructor<PeerLink> ()
44  .AddAttribute ( "RetryTimeout",
45  "Retry timeout",
46  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
50  )
51  .AddAttribute ( "HoldingTimeout",
52  "Holding timeout",
53  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
57  )
58  .AddAttribute ( "ConfirmTimeout",
59  "Confirm timeout",
60  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
64  )
65  .AddAttribute ( "MaxRetries",
66  "Maximum number of retries",
67  UintegerValue (4),
70  MakeUintegerChecker<uint16_t> ()
71  )
72  .AddAttribute ( "MaxBeaconLoss",
73  "Maximum number of lost beacons before link will be closed",
74  UintegerValue (2),
77  MakeUintegerChecker<uint16_t> (1)
78  )
79  .AddAttribute ( "MaxPacketFailure",
80  "Maximum number of failed packets before link will be closed",
81  UintegerValue (2),
84  MakeUintegerChecker<uint16_t> (1)
85  )
86  ;
87  return tid;
88 }
89 
90 const char* const
91 PeerLink::PeerStateNames[6] = { "IDLE", "OPN_SNT", "CNF_RCVD", "OPN_RCVD", "ESTAB", "HOLDING" };
92 
93 //-----------------------------------------------------------------------------
94 // PeerLink public interface
95 //-----------------------------------------------------------------------------
97  m_peerAddress (Mac48Address::GetBroadcast ()),
98  m_peerMeshPointAddress (Mac48Address::GetBroadcast ()),
99  m_localLinkId (0),
100  m_peerLinkId (0),
101  m_assocId (0),
102  m_peerAssocId (0),
103  m_lastBeacon (Seconds (0)),
104  m_beaconInterval (Seconds (0)),
105  m_packetFail (0),
106  m_state (IDLE),
107  m_retryCounter (0),
108  m_maxPacketFail (3)
109 {
110  NS_LOG_FUNCTION (this);
111 }
113 {
114 }
115 void
117 {
118  NS_LOG_FUNCTION (this);
119  m_retryTimer.Cancel ();
124 }
125 void
127 {
128  m_peerAddress = macaddr;
129 }
130 void
132 {
133  m_peerMeshPointAddress = macaddr;
134 }
135 void
136 PeerLink::SetInterface (uint32_t interface)
137 {
138  m_interface = interface;
139 }
140 void
142 {
143  m_localLinkId = id;
144 }
145 void
146 PeerLink::SetLocalAid (uint16_t aid)
147 {
148  m_assocId = aid;
149 }
150 void
151 PeerLink::SetBeaconInformation (Time lastBeacon, Time beaconInterval)
152 {
153  m_lastBeacon = lastBeacon;
154  m_beaconInterval = beaconInterval;
156  Time delay = Seconds (beaconInterval.GetSeconds () * m_maxBeaconLoss);
157  NS_ASSERT (delay.GetMicroSeconds () != 0);
159 }
160 void
162 {
164 }
165 void
167 {
168  NS_LOG_FUNCTION (this);
169  StateMachine (CNCL);
170 }
171 void
173 {
174  m_packetFail = 0;
175 }
176 void
178 {
179  NS_LOG_FUNCTION (this);
180  m_packetFail++;
182  {
183  NS_LOG_DEBUG ("TransmissionFailure:: CNCL");
184  StateMachine (CNCL);
185  m_packetFail = 0;
186  }
187 }
188 
189 void
191 {
192  m_beaconTiming = beaconTiming;
193 }
196 {
197  return m_peerAddress;
198 }
199 uint16_t
201 {
202  return m_assocId;
203 }
204 uint16_t
206 {
207  return m_peerAssocId;
208 }
209 
210 Time
212 {
213  return m_lastBeacon;
214 }
215 Time
217 {
218  return m_beaconInterval;
219 }
222 {
223  return m_beaconTiming;
224 }
225 void
227 {
228  StateMachine (CNCL, reason);
229 }
230 void
232 {
234 }
235 void
237 {
239 }
240 void
241 PeerLink::Close (uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reason)
242 {
243  NS_LOG_FUNCTION (this << localLinkId << peerLinkId << reason);
244  if (peerLinkId != 0 && m_localLinkId != peerLinkId)
245  {
246  return;
247  }
248  if (m_peerLinkId == 0)
249  {
250  m_peerLinkId = localLinkId;
251  }
252  else
253  {
254  if (m_peerLinkId != localLinkId)
255  {
256  return;
257  }
258  }
259  StateMachine (CLS_ACPT, reason);
260 }
261 void
262 PeerLink::OpenAccept (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp)
263 {
264  NS_LOG_FUNCTION (this << localLinkId << peerMp);
265  m_peerLinkId = localLinkId;
268  {
269  NS_ASSERT (m_peerMeshPointAddress == peerMp);
270  }
271  else
272  {
273  m_peerMeshPointAddress = peerMp;
274  }
276 }
277 void
278 PeerLink::OpenReject (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp, PmpReasonCode reason)
279 {
280  NS_LOG_FUNCTION (this << localLinkId << peerMp << reason);
281  if (m_peerLinkId == 0)
282  {
283  m_peerLinkId = localLinkId;
284  }
287  {
288  NS_ASSERT (m_peerMeshPointAddress == peerMp);
289  }
290  else
291  {
292  m_peerMeshPointAddress = peerMp;
293  }
294  StateMachine (OPN_RJCT, reason);
295 }
296 void
297 PeerLink::ConfirmAccept (uint16_t localLinkId, uint16_t peerLinkId, uint16_t peerAid, IeConfiguration conf,
298  Mac48Address peerMp)
299 {
300  NS_LOG_FUNCTION (this << localLinkId << peerLinkId << peerAid << peerMp);
301  if (m_localLinkId != peerLinkId)
302  {
303  return;
304  }
305  if (m_peerLinkId == 0)
306  {
307  m_peerLinkId = localLinkId;
308  }
309  else
310  {
311  if (m_peerLinkId != localLinkId)
312  {
313  return;
314  }
315  }
317  m_peerAssocId = peerAid;
319  {
320  NS_ASSERT (m_peerMeshPointAddress == peerMp);
321  }
322  else
323  {
324  m_peerMeshPointAddress = peerMp;
325  }
327 }
328 void
329 PeerLink::ConfirmReject (uint16_t localLinkId, uint16_t peerLinkId, IeConfiguration conf,
330  Mac48Address peerMp, PmpReasonCode reason)
331 {
332  NS_LOG_FUNCTION (this << localLinkId << peerLinkId << peerMp << reason);
333  if (m_localLinkId != peerLinkId)
334  {
335  return;
336  }
337  if (m_peerLinkId == 0)
338  {
339  m_peerLinkId = localLinkId;
340  }
341  else
342  {
343  if (m_peerLinkId != localLinkId)
344  {
345  return;
346  }
347  }
350  {
351  NS_ASSERT (m_peerMeshPointAddress == peerMp);
352  }
353  m_peerMeshPointAddress = peerMp;
354  StateMachine (CNF_RJCT, reason);
355 }
356 bool
358 {
359  return (m_state == ESTAB);
360 }
361 bool
363 {
364  return (m_state == IDLE);
365 }
366 void
368 {
369  m_macPlugin = plugin;
370 }
371 //-----------------------------------------------------------------------------
372 // Private
373 //-----------------------------------------------------------------------------
374 void
376 {
377  switch (m_state)
378  {
379  case IDLE:
380  switch (event)
381  {
382  case CNCL:
383  case CLS_ACPT:
384  m_state = IDLE;
386  break;
387  case REQ_RJCT:
388  SendPeerLinkClose (reasoncode);
389  break;
390  case ACTOPN:
391  m_state = OPN_SNT;
393  SendPeerLinkOpen ();
394  SetRetryTimer ();
395  break;
396  case OPN_ACPT:
397  m_state = OPN_RCVD;
400  SendPeerLinkOpen ();
401  SetRetryTimer ();
402  break;
403  default:
404  //11B.5.3.4 of 802.11s Draft D3.0
405  //All other events shall be ignored in this state
406  break;
407  }
408  break;
409  case OPN_SNT:
410  switch (event)
411  {
412  case TOR1:
413  SendPeerLinkOpen ();
414  m_retryCounter++;
415  SetRetryTimer ();
416  break;
417  case CNF_ACPT:
418  m_state = CNF_RCVD;
420  ClearRetryTimer ();
421  SetConfirmTimer ();
422  break;
423  case OPN_ACPT:
424  m_state = OPN_RCVD;
427  break;
428  case CLS_ACPT:
429  m_state = HOLDING;
431  ClearRetryTimer ();
433  SetHoldingTimer ();
434  break;
435  case OPN_RJCT:
436  case CNF_RJCT:
437  m_state = HOLDING;
439  ClearRetryTimer ();
440  SendPeerLinkClose (reasoncode);
441  SetHoldingTimer ();
442  break;
443  case TOR2:
444  m_state = HOLDING;
446  ClearRetryTimer ();
448  SetHoldingTimer ();
449  break;
450  case CNCL:
451  m_state = HOLDING;
453  ClearRetryTimer ();
455  SetHoldingTimer ();
456  break;
457  default:
458  //11B.5.3.5 of 802.11s Draft D3.0
459  //All other events shall be ignored in this state
460  break;
461  }
462  break;
463  case CNF_RCVD:
464  switch (event)
465  {
466  case CNF_ACPT:
467  break;
468  case OPN_ACPT:
469  m_state = ESTAB;
474  break;
475  case CLS_ACPT:
476  m_state = HOLDING;
480  SetHoldingTimer ();
481  break;
482  case CNF_RJCT:
483  case OPN_RJCT:
484  m_state = HOLDING;
487  SendPeerLinkClose (reasoncode);
488  SetHoldingTimer ();
489  break;
490  case CNCL:
491  m_state = HOLDING;
495  SetHoldingTimer ();
496  break;
497  case TOC:
498  m_state = HOLDING;
501  SetHoldingTimer ();
502  break;
503  default:
504  //11B.5.3.6 of 802.11s Draft D3.0
505  //All other events shall be ignored in this state
506  break;
507  }
508  break;
509  case OPN_RCVD:
510  switch (event)
511  {
512  case TOR1:
513  SendPeerLinkOpen ();
514  m_retryCounter++;
515  SetRetryTimer ();
516  break;
517  case CNF_ACPT:
518  m_state = ESTAB;
520  ClearRetryTimer ();
522  break;
523  case CLS_ACPT:
524  m_state = HOLDING;
526  ClearRetryTimer ();
528  SetHoldingTimer ();
529  break;
530  case OPN_RJCT:
531  case CNF_RJCT:
532  m_state = HOLDING;
534  ClearRetryTimer ();
535  SendPeerLinkClose (reasoncode);
536  SetHoldingTimer ();
537  break;
538  case TOR2:
539  m_state = HOLDING;
541  ClearRetryTimer ();
543  SetHoldingTimer ();
544  break;
545  case CNCL:
546  m_state = HOLDING;
548  ClearRetryTimer ();
550  SetHoldingTimer ();
551  break;
552  default:
553  //11B.5.3.7 of 802.11s Draft D3.0
554  //All other events shall be ignored in this state
555  break;
556  }
557  break;
558  case ESTAB:
559  switch (event)
560  {
561  case OPN_ACPT:
563  break;
564  case CLS_ACPT:
565  m_state = HOLDING;
568  SetHoldingTimer ();
569  break;
570  case OPN_RJCT:
571  case CNF_RJCT:
572  m_state = HOLDING;
574  ClearRetryTimer ();
575  SendPeerLinkClose (reasoncode);
576  SetHoldingTimer ();
577  break;
578  case CNCL:
579  m_state = HOLDING;
582  SetHoldingTimer ();
583  break;
584  default:
585  //11B.5.3.8 of 802.11s Draft D3.0
586  //All other events shall be ignored in this state
587  break;
588  }
589  break;
590  case HOLDING:
591  switch (event)
592  {
593  case CLS_ACPT:
595  // fall through:
596  case TOH:
597  m_state = IDLE;
599  break;
600  case OPN_ACPT:
601  case CNF_ACPT:
602  m_state = HOLDING;
604  // reason not spec in D2.0
606  break;
607  case OPN_RJCT:
608  case CNF_RJCT:
609  m_state = HOLDING;
611  SendPeerLinkClose (reasoncode);
612  break;
613  default:
614  //11B.5.3.9 of 802.11s Draft D3.0
615  //All other events shall be ignored in this state
616  break;
617  }
618  break;
619  }
620 }
621 void
623 {
624  m_retryTimer.Cancel ();
625 }
626 void
628 {
630 }
631 void
633 {
635 }
636 void
638 {
639  IePeerManagement peerElement;
640  peerElement.SetPeerClose (m_localLinkId, m_peerLinkId, reasoncode);
643 }
644 void
646 {
647  IePeerManagement peerElement;
648  peerElement.SetPeerOpen (m_localLinkId);
649  NS_ASSERT (m_macPlugin != 0);
652 }
653 void
655 {
656  IePeerManagement peerElement;
660 }
661 void
663 {
666 }
667 void
669 {
670  NS_LOG_FUNCTION (this);
671  StateMachine (TOH);
672 }
673 void
675 {
678 }
679 void
681 {
682  NS_LOG_FUNCTION (this);
684  {
685  NS_LOG_LOGIC ("Retry timeout TOR1");
686  StateMachine (TOR1);
687  }
688  else
689  {
690  NS_LOG_LOGIC ("Retry timeout TOR2");
691  StateMachine (TOR2);
692  }
693 }
694 void
696 {
699 }
700 void
702 {
703  StateMachine (TOC);
704 }
705 void
706 PeerLink::Report (std::ostream & os) const
707 {
708  if (m_state != ESTAB)
709  {
710  return;
711  }
712  os << "<PeerLink" << std::endl <<
713  "localAddress=\"" << m_macPlugin->GetAddress () << "\"" << std::endl <<
714  "peerInterfaceAddress=\"" << m_peerAddress << "\"" << std::endl <<
715  "peerMeshPointAddress=\"" << m_peerMeshPointAddress << "\"" << std::endl <<
716  "metric=\"" << m_macPlugin->GetLinkMetric (m_peerAddress) << "\"" << std::endl <<
717  "lastBeacon=\"" << m_lastBeacon.GetSeconds () << "\"" << std::endl <<
718  "localLinkId=\"" << m_localLinkId << "\"" << std::endl <<
719  "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl <<
720  "assocId=\"" << m_assocId << "\"" << std::endl <<
721  "/>" << std::endl;
722 }
723 } // namespace dot11s
724 } // namespace ns3
725 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#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:45
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
Definition: conf.py:1
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
according to IEEE 802.11 - 2012
AttributeValue implementation for Time.
Definition: nstime.h:1124
void ClearTimingElement()
Clear timing element.
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetPeerClose(uint16_t localLinkID, uint16_t peerLinkId, PmpReasonCode reasonCode)
Set peer close function.
See 7.3.2.89 of 802.11s draft 2.07.
static Mac48Address GetBroadcast(void)
uint32_t GetLinkMetric(Mac48Address peerAddress)
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:363
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SendPeerLinkManagementFrame(Mac48Address peerAddress, Mac48Address peerMpAddress, uint16_t aid, IePeerManagement peerElement, IeConfiguration meshConfig)
Send peer link management frame function.
an EUI-48 address
Definition: mac48-address.h:43
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1125
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void SetPeerConfirm(uint16_t localLinkID, uint16_t peerLinkId)
Set peer confirm function.
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
void SetPeerOpen(uint16_t localLinkId)
Set peer open function.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
A base class which provides memory management and object aggregation.
Definition: object.h:87
Mac48Address GetAddress() const
debug only, used to print established links
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915