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 
91 //-----------------------------------------------------------------------------
92 // PeerLink public interface
93 //-----------------------------------------------------------------------------
95  m_peerAddress (Mac48Address::GetBroadcast ()),
96  m_peerMeshPointAddress (Mac48Address::GetBroadcast ()),
97  m_localLinkId (0),
98  m_peerLinkId (0),
99  m_assocId (0),
100  m_peerAssocId (0),
101  m_lastBeacon (Seconds (0)),
102  m_beaconInterval (Seconds (0)),
103  m_packetFail (0),
104  m_state (IDLE),
105  m_retryCounter (0),
106  m_maxPacketFail (3)
107 {
108 }
110 {
111 }
112 void
114 {
115  m_retryTimer.Cancel ();
120 }
121 void
123 {
124  m_peerAddress = macaddr;
125 }
126 void
128 {
129  m_peerMeshPointAddress = macaddr;
130 }
131 void
132 PeerLink::SetInterface (uint32_t interface)
133 {
134  m_interface = interface;
135 }
136 void
138 {
139  m_localLinkId = id;
140 }
141 void
142 PeerLink::SetLocalAid (uint16_t aid)
143 {
144  m_assocId = aid;
145 }
146 void
147 PeerLink::SetBeaconInformation (Time lastBeacon, Time beaconInterval)
148 {
149  m_lastBeacon = lastBeacon;
150  m_beaconInterval = beaconInterval;
152  Time delay = Seconds (beaconInterval.GetSeconds () * m_maxBeaconLoss);
153  NS_ASSERT (delay.GetMicroSeconds () != 0);
155 }
156 void
158 {
160 }
161 void
163 {
164  StateMachine (CNCL);
165 }
166 void
168 {
169  m_packetFail = 0;
170 }
171 void
173 {
174  m_packetFail++;
176  {
177  StateMachine (CNCL);
178  m_packetFail = 0;
179  }
180 }
181 
182 void
184 {
185  m_beaconTiming = beaconTiming;
186 }
189 {
190  return m_peerAddress;
191 }
192 uint16_t
194 {
195  return m_assocId;
196 }
197 uint16_t
199 {
200  return m_peerAssocId;
201 }
202 
203 Time
205 {
206  return m_lastBeacon;
207 }
208 Time
210 {
211  return m_beaconInterval;
212 }
215 {
216  return m_beaconTiming;
217 }
218 void
220 {
221  StateMachine (CNCL, reason);
222 }
223 void
225 {
227 }
228 void
230 {
232 }
233 void
234 PeerLink::Close (uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reason)
235 {
236  if (peerLinkId != 0 && m_localLinkId != peerLinkId)
237  {
238  return;
239  }
240  if (m_peerLinkId == 0)
241  {
242  m_peerLinkId = localLinkId;
243  }
244  else
245  {
246  if (m_peerLinkId != localLinkId)
247  {
248  return;
249  }
250  }
251  StateMachine (CLS_ACPT, reason);
252 }
253 void
254 PeerLink::OpenAccept (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp)
255 {
256  m_peerLinkId = localLinkId;
257  m_configuration = conf;
259  {
260  NS_ASSERT (m_peerMeshPointAddress == peerMp);
261  }
262  else
263  {
264  m_peerMeshPointAddress = peerMp;
265  }
267 }
268 void
269 PeerLink::OpenReject (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp, PmpReasonCode reason)
270 {
271  if (m_peerLinkId == 0)
272  {
273  m_peerLinkId = localLinkId;
274  }
275  m_configuration = conf;
277  {
278  NS_ASSERT (m_peerMeshPointAddress == peerMp);
279  }
280  else
281  {
282  m_peerMeshPointAddress = peerMp;
283  }
284  StateMachine (OPN_RJCT, reason);
285 }
286 void
287 PeerLink::ConfirmAccept (uint16_t localLinkId, uint16_t peerLinkId, uint16_t peerAid, IeConfiguration conf,
288  Mac48Address peerMp)
289 {
290  if (m_localLinkId != peerLinkId)
291  {
292  return;
293  }
294  if (m_peerLinkId == 0)
295  {
296  m_peerLinkId = localLinkId;
297  }
298  else
299  {
300  if (m_peerLinkId != localLinkId)
301  {
302  return;
303  }
304  }
305  m_configuration = conf;
306  m_peerAssocId = peerAid;
308  {
309  NS_ASSERT (m_peerMeshPointAddress == peerMp);
310  }
311  else
312  {
313  m_peerMeshPointAddress = peerMp;
314  }
316 }
317 void
318 PeerLink::ConfirmReject (uint16_t localLinkId, uint16_t peerLinkId, IeConfiguration conf,
319  Mac48Address peerMp, PmpReasonCode reason)
320 {
321  if (m_localLinkId != peerLinkId)
322  {
323  return;
324  }
325  if (m_peerLinkId == 0)
326  {
327  m_peerLinkId = localLinkId;
328  }
329  else
330  {
331  if (m_peerLinkId != localLinkId)
332  {
333  return;
334  }
335  }
336  m_configuration = conf;
338  {
339  NS_ASSERT (m_peerMeshPointAddress == peerMp);
340  }
341  m_peerMeshPointAddress = peerMp;
342  StateMachine (CNF_RJCT, reason);
343 }
344 bool
346 {
347  return (m_state == ESTAB);
348 }
349 bool
351 {
352  return (m_state == IDLE);
353 }
354 void
356 {
357  m_macPlugin = plugin;
358 }
359 //-----------------------------------------------------------------------------
360 // Private
361 //-----------------------------------------------------------------------------
362 void
364 {
365  switch (m_state)
366  {
367  case IDLE:
368  switch (event)
369  {
370  case CNCL:
371  case CLS_ACPT:
372  m_state = IDLE;
374  break;
375  case REQ_RJCT:
376  SendPeerLinkClose (reasoncode);
377  break;
378  case ACTOPN:
379  m_state = OPN_SNT;
381  SendPeerLinkOpen ();
382  SetRetryTimer ();
383  break;
384  case OPN_ACPT:
385  m_state = OPN_RCVD;
388  SendPeerLinkOpen ();
389  SetRetryTimer ();
390  break;
391  default:
392  //11B.5.3.4 of 802.11s Draft D3.0
393  //All other events shall be ignored in this state
394  break;
395  }
396  break;
397  case OPN_SNT:
398  switch (event)
399  {
400  case TOR1:
401  SendPeerLinkOpen ();
402  m_retryCounter++;
403  SetRetryTimer ();
404  break;
405  case CNF_ACPT:
406  m_state = CNF_RCVD;
408  ClearRetryTimer ();
409  SetConfirmTimer ();
410  break;
411  case OPN_ACPT:
412  m_state = OPN_RCVD;
415  break;
416  case CLS_ACPT:
417  m_state = HOLDING;
419  ClearRetryTimer ();
421  SetHoldingTimer ();
422  break;
423  case OPN_RJCT:
424  case CNF_RJCT:
425  m_state = HOLDING;
427  ClearRetryTimer ();
428  SendPeerLinkClose (reasoncode);
429  SetHoldingTimer ();
430  break;
431  case TOR2:
432  m_state = HOLDING;
434  ClearRetryTimer ();
436  SetHoldingTimer ();
437  break;
438  case CNCL:
439  m_state = HOLDING;
441  ClearRetryTimer ();
443  SetHoldingTimer ();
444  break;
445  default:
446  //11B.5.3.5 of 802.11s Draft D3.0
447  //All other events shall be ignored in this state
448  break;
449  }
450  break;
451  case CNF_RCVD:
452  switch (event)
453  {
454  case CNF_ACPT:
455  break;
456  case OPN_ACPT:
457  m_state = ESTAB;
462  break;
463  case CLS_ACPT:
464  m_state = HOLDING;
468  SetHoldingTimer ();
469  break;
470  case CNF_RJCT:
471  case OPN_RJCT:
472  m_state = HOLDING;
475  SendPeerLinkClose (reasoncode);
476  SetHoldingTimer ();
477  break;
478  case CNCL:
479  m_state = HOLDING;
483  SetHoldingTimer ();
484  break;
485  case TOC:
486  m_state = HOLDING;
489  SetHoldingTimer ();
490  break;
491  default:
492  //11B.5.3.6 of 802.11s Draft D3.0
493  //All other events shall be ignored in this state
494  break;
495  }
496  break;
497  case OPN_RCVD:
498  switch (event)
499  {
500  case TOR1:
501  SendPeerLinkOpen ();
502  m_retryCounter++;
503  SetRetryTimer ();
504  break;
505  case CNF_ACPT:
506  m_state = ESTAB;
508  ClearRetryTimer ();
510  break;
511  case CLS_ACPT:
512  m_state = HOLDING;
514  ClearRetryTimer ();
516  SetHoldingTimer ();
517  break;
518  case OPN_RJCT:
519  case CNF_RJCT:
520  m_state = HOLDING;
522  ClearRetryTimer ();
523  SendPeerLinkClose (reasoncode);
524  SetHoldingTimer ();
525  break;
526  case TOR2:
527  m_state = HOLDING;
529  ClearRetryTimer ();
531  SetHoldingTimer ();
532  break;
533  case CNCL:
534  m_state = HOLDING;
536  ClearRetryTimer ();
538  SetHoldingTimer ();
539  break;
540  default:
541  //11B.5.3.7 of 802.11s Draft D3.0
542  //All other events shall be ignored in this state
543  break;
544  }
545  break;
546  case ESTAB:
547  switch (event)
548  {
549  case OPN_ACPT:
551  break;
552  case CLS_ACPT:
553  m_state = HOLDING;
556  SetHoldingTimer ();
557  break;
558  case OPN_RJCT:
559  case CNF_RJCT:
560  m_state = HOLDING;
562  ClearRetryTimer ();
563  SendPeerLinkClose (reasoncode);
564  SetHoldingTimer ();
565  break;
566  case CNCL:
567  m_state = HOLDING;
570  SetHoldingTimer ();
571  break;
572  default:
573  //11B.5.3.8 of 802.11s Draft D3.0
574  //All other events shall be ignored in this state
575  break;
576  }
577  break;
578  case HOLDING:
579  switch (event)
580  {
581  case CLS_ACPT:
583  // fall through:
584  case TOH:
585  m_state = IDLE;
587  break;
588  case OPN_ACPT:
589  case CNF_ACPT:
590  m_state = HOLDING;
592  // reason not spec in D2.0
594  break;
595  case OPN_RJCT:
596  case CNF_RJCT:
597  m_state = HOLDING;
599  SendPeerLinkClose (reasoncode);
600  break;
601  default:
602  //11B.5.3.9 of 802.11s Draft D3.0
603  //All other events shall be ignored in this state
604  break;
605  }
606  break;
607  }
608 }
609 void
611 {
612  m_retryTimer.Cancel ();
613 }
614 void
616 {
618 }
619 void
621 {
623 }
624 void
626 {
627  IePeerManagement peerElement;
628  peerElement.SetPeerClose (m_localLinkId, m_peerLinkId, reasoncode);
631 }
632 void
634 {
635  IePeerManagement peerElement;
636  peerElement.SetPeerOpen (m_localLinkId);
637  NS_ASSERT (m_macPlugin != 0);
640 }
641 void
643 {
644  IePeerManagement peerElement;
648 }
649 void
651 {
654 }
655 void
657 {
658  StateMachine (TOH);
659 }
660 void
662 {
665 }
666 void
668 {
670  {
671  StateMachine (TOR1);
672  }
673  else
674  {
675  StateMachine (TOR2);
676  }
677 }
678 void
680 {
683 }
684 void
686 {
687  StateMachine (TOC);
688 }
689 void
690 PeerLink::Report (std::ostream & os) const
691 {
692  if (m_state != ESTAB)
693  {
694  return;
695  }
696  os << "<PeerLink" << std::endl <<
697  "localAddress=\"" << m_macPlugin->GetAddress () << "\"" << std::endl <<
698  "peerInterfaceAddress=\"" << m_peerAddress << "\"" << std::endl <<
699  "peerMeshPointAddress=\"" << m_peerMeshPointAddress << "\"" << std::endl <<
700  "metric=\"" << m_macPlugin->GetLinkMetric (m_peerAddress) << "\"" << std::endl <<
701  "lastBeacon=\"" << m_lastBeacon.GetSeconds () << "\"" << std::endl <<
702  "localLinkId=\"" << m_localLinkId << "\"" << std::endl <<
703  "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl <<
704  "assocId=\"" << m_assocId << "\"" << std::endl <<
705  "/>" << std::endl;
706 }
707 } // namespace dot11s
708 } // namespace ns3
709 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
PeerLinkOpen_Reject.
Definition: peer-link.h:118
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
#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:201
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
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
Timeout of confirm timer.
Definition: peer-link.h:124
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:349
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetPeerClose(uint16_t localLinkID, uint16_t peerLinkId, PmpReasonCode reasonCode)
See 7.3.2.89 of 802.11s draft 2.07.
PeerLinkConfirm_Accept.
Definition: peer-link.h:120
static Mac48Address GetBroadcast(void)
uint32_t GetLinkMetric(Mac48Address peerAddress)
PeerLinkOpen_Accept.
Definition: peer-link.h:117
Timeout of holding (graceful closing) timer.
Definition: peer-link.h:125
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)
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:958
Mac48Address GetAddress() const
debug only, used to print established links
PeerLinkConfirm_Reject.
Definition: peer-link.h:121
Cancel peer link.
Definition: peer-link.h:114
also timeout of retry timer
Definition: peer-link.h:123
Active peer link open.
Definition: peer-link.h:115
void SetPeerConfirm(uint16_t localLinkID, uint16_t peerLinkId)
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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)
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
PeerEvent
Peer link events, see 802.11s draft 11B.3.3.2.
Definition: peer-link.h:112
A base class which provides memory management and object aggregation.
Definition: object.h:87
PeerLinkOpenReject by internal reason.
Definition: peer-link.h:119
PeerLinkClose_Accept.
Definition: peer-link.h:116
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:904
Timeout of retry timer.
Definition: peer-link.h:122