A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("Dot11sPeerManagementProtocol");
30 
31 namespace ns3 {
32 namespace dot11s {
33 
34 NS_OBJECT_ENSURE_REGISTERED ( PeerLink);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::dot11s::PeerLink")
40  .SetParent<Object> ()
41  .AddConstructor<PeerLink> ()
42  .AddAttribute ( "RetryTimeout",
43  "Retry timeout",
44  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
45  MakeTimeAccessor (
48  )
49  .AddAttribute ( "HoldingTimeout",
50  "Holding timeout",
51  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
52  MakeTimeAccessor (
55  )
56  .AddAttribute ( "ConfirmTimeout",
57  "Confirm timeout",
58  TimeValue (TimeValue (MicroSeconds (40 * 1024))),
59  MakeTimeAccessor (
62  )
63  .AddAttribute ( "MaxRetries",
64  "Maximum number of retries",
65  UintegerValue (4),
66  MakeUintegerAccessor (
68  MakeUintegerChecker<uint16_t> ()
69  )
70  .AddAttribute ( "MaxBeaconLoss",
71  "Maximum number of lost beacons before link will be closed",
72  UintegerValue (2),
73  MakeUintegerAccessor (
75  MakeUintegerChecker<uint16_t> (1)
76  )
77  .AddAttribute ( "MaxPacketFailure",
78  "Maximum number of failed packets before link will be closed",
79  UintegerValue (2),
80  MakeUintegerAccessor (
82  MakeUintegerChecker<uint16_t> (1)
83  )
84  ;
85  return tid;
86 }
87 
88 
89 //-----------------------------------------------------------------------------
90 // PeerLink public interface
91 //-----------------------------------------------------------------------------
93  m_peerAddress (Mac48Address::GetBroadcast ()),
94  m_peerMeshPointAddress (Mac48Address::GetBroadcast ()),
95  m_localLinkId (0),
96  m_peerLinkId (0),
97  m_assocId (0),
98  m_peerAssocId (0),
99  m_lastBeacon (Seconds (0)),
100  m_beaconInterval (Seconds (0)),
101  m_packetFail (0),
102  m_state (IDLE),
103  m_retryCounter (0),
104  m_maxPacketFail (3)
105 {
106 }
108 {
109 }
110 void
112 {
113  m_retryTimer.Cancel ();
118 }
119 void
121 {
122  m_peerAddress = macaddr;
123 }
124 void
126 {
127  m_peerMeshPointAddress = macaddr;
128 }
129 void
130 PeerLink::SetInterface (uint32_t interface)
131 {
132  m_interface = interface;
133 }
134 void
136 {
137  m_localLinkId = id;
138 }
139 void
140 PeerLink::SetLocalAid (uint16_t aid)
141 {
142  m_assocId = aid;
143 }
144 void
145 PeerLink::SetBeaconInformation (Time lastBeacon, Time beaconInterval)
146 {
147  m_lastBeacon = lastBeacon;
148  m_beaconInterval = beaconInterval;
150  Time delay = Seconds (beaconInterval.GetSeconds () * m_maxBeaconLoss);
151  NS_ASSERT (delay.GetMicroSeconds () != 0);
153 }
154 void
156 {
158 }
159 void
161 {
162  StateMachine (CNCL);
163 }
164 void
166 {
167  m_packetFail = 0;
168 }
169 void
171 {
172  m_packetFail++;
174  {
175  StateMachine (CNCL);
176  m_packetFail = 0;
177  }
178 }
179 
180 void
182 {
183  m_beaconTiming = beaconTiming;
184 }
187 {
188  return m_peerAddress;
189 }
190 uint16_t
192 {
193  return m_assocId;
194 }
195 uint16_t
197 {
198  return m_peerAssocId;
199 }
200 
201 Time
203 {
204  return m_lastBeacon;
205 }
206 Time
208 {
209  return m_beaconInterval;
210 }
213 {
214  return m_beaconTiming;
215 }
216 void
218 {
219  StateMachine (CNCL, reason);
220 }
221 void
223 {
225 }
226 void
228 {
230 }
231 void
232 PeerLink::Close (uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reason)
233 {
234  if (peerLinkId != 0 && m_localLinkId != peerLinkId)
235  {
236  return;
237  }
238  if (m_peerLinkId == 0)
239  {
240  m_peerLinkId = localLinkId;
241  }
242  else
243  {
244  if (m_peerLinkId != localLinkId)
245  {
246  return;
247  }
248  }
249  StateMachine (CLS_ACPT, reason);
250 }
251 void
252 PeerLink::OpenAccept (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp)
253 {
254  m_peerLinkId = localLinkId;
255  m_configuration = conf;
257  {
258  NS_ASSERT (m_peerMeshPointAddress == peerMp);
259  }
260  else
261  {
262  m_peerMeshPointAddress = peerMp;
263  }
265 }
266 void
267 PeerLink::OpenReject (uint16_t localLinkId, IeConfiguration conf, Mac48Address peerMp, PmpReasonCode reason)
268 {
269  if (m_peerLinkId == 0)
270  {
271  m_peerLinkId = localLinkId;
272  }
273  m_configuration = conf;
275  {
276  NS_ASSERT (m_peerMeshPointAddress == peerMp);
277  }
278  else
279  {
280  m_peerMeshPointAddress = peerMp;
281  }
282  StateMachine (OPN_RJCT, reason);
283 }
284 void
285 PeerLink::ConfirmAccept (uint16_t localLinkId, uint16_t peerLinkId, uint16_t peerAid, IeConfiguration conf,
286  Mac48Address peerMp)
287 {
288  if (m_localLinkId != peerLinkId)
289  {
290  return;
291  }
292  if (m_peerLinkId == 0)
293  {
294  m_peerLinkId = localLinkId;
295  }
296  else
297  {
298  if (m_peerLinkId != localLinkId)
299  {
300  return;
301  }
302  }
303  m_configuration = conf;
304  m_peerAssocId = peerAid;
306  {
307  NS_ASSERT (m_peerMeshPointAddress == peerMp);
308  }
309  else
310  {
311  m_peerMeshPointAddress = peerMp;
312  }
314 }
315 void
316 PeerLink::ConfirmReject (uint16_t localLinkId, uint16_t peerLinkId, IeConfiguration conf,
317  Mac48Address peerMp, PmpReasonCode reason)
318 {
319  if (m_localLinkId != peerLinkId)
320  {
321  return;
322  }
323  if (m_peerLinkId == 0)
324  {
325  m_peerLinkId = localLinkId;
326  }
327  else
328  {
329  if (m_peerLinkId != localLinkId)
330  {
331  return;
332  }
333  }
334  m_configuration = conf;
336  {
337  NS_ASSERT (m_peerMeshPointAddress == peerMp);
338  }
339  m_peerMeshPointAddress = peerMp;
340  StateMachine (CNF_RJCT, reason);
341 }
342 bool
344 {
345  return (m_state == ESTAB);
346 }
347 bool
349 {
350  return (m_state == IDLE);
351 }
352 void
354 {
355  m_macPlugin = plugin;
356 }
357 //-----------------------------------------------------------------------------
358 // Private
359 //-----------------------------------------------------------------------------
360 void
362 {
363  switch (m_state)
364  {
365  case IDLE:
366  switch (event)
367  {
368  case CNCL:
369  case CLS_ACPT:
370  m_state = IDLE;
372  break;
373  case REQ_RJCT:
374  SendPeerLinkClose (reasoncode);
375  break;
376  case ACTOPN:
377  m_state = OPN_SNT;
379  SendPeerLinkOpen ();
380  SetRetryTimer ();
381  break;
382  case OPN_ACPT:
383  m_state = OPN_RCVD;
386  SendPeerLinkOpen ();
387  SetRetryTimer ();
388  break;
389  default:
390  //11B.5.3.4 of 802.11s Draft D3.0
391  //All other events shall be ignored in this state
392  break;
393  }
394  break;
395  case OPN_SNT:
396  switch (event)
397  {
398  case TOR1:
399  SendPeerLinkOpen ();
400  m_retryCounter++;
401  SetRetryTimer ();
402  break;
403  case CNF_ACPT:
404  m_state = CNF_RCVD;
406  ClearRetryTimer ();
407  SetConfirmTimer ();
408  break;
409  case OPN_ACPT:
410  m_state = OPN_RCVD;
413  break;
414  case CLS_ACPT:
415  m_state = HOLDING;
417  ClearRetryTimer ();
419  SetHoldingTimer ();
420  break;
421  case OPN_RJCT:
422  case CNF_RJCT:
423  m_state = HOLDING;
425  ClearRetryTimer ();
426  SendPeerLinkClose (reasoncode);
427  SetHoldingTimer ();
428  break;
429  case TOR2:
430  m_state = HOLDING;
432  ClearRetryTimer ();
434  SetHoldingTimer ();
435  break;
436  case CNCL:
437  m_state = HOLDING;
439  ClearRetryTimer ();
441  SetHoldingTimer ();
442  break;
443  default:
444  //11B.5.3.5 of 802.11s Draft D3.0
445  //All other events shall be ignored in this state
446  break;
447  }
448  break;
449  case CNF_RCVD:
450  switch (event)
451  {
452  case CNF_ACPT:
453  break;
454  case OPN_ACPT:
455  m_state = ESTAB;
460  break;
461  case CLS_ACPT:
462  m_state = HOLDING;
466  SetHoldingTimer ();
467  break;
468  case CNF_RJCT:
469  case OPN_RJCT:
470  m_state = HOLDING;
473  SendPeerLinkClose (reasoncode);
474  SetHoldingTimer ();
475  break;
476  case CNCL:
477  m_state = HOLDING;
481  SetHoldingTimer ();
482  break;
483  case TOC:
484  m_state = HOLDING;
487  SetHoldingTimer ();
488  break;
489  default:
490  //11B.5.3.6 of 802.11s Draft D3.0
491  //All other events shall be ignored in this state
492  break;
493  }
494  break;
495  case OPN_RCVD:
496  switch (event)
497  {
498  case TOR1:
499  SendPeerLinkOpen ();
500  m_retryCounter++;
501  SetRetryTimer ();
502  break;
503  case CNF_ACPT:
504  m_state = ESTAB;
506  ClearRetryTimer ();
508  break;
509  case CLS_ACPT:
510  m_state = HOLDING;
512  ClearRetryTimer ();
514  SetHoldingTimer ();
515  break;
516  case OPN_RJCT:
517  case CNF_RJCT:
518  m_state = HOLDING;
520  ClearRetryTimer ();
521  SendPeerLinkClose (reasoncode);
522  SetHoldingTimer ();
523  break;
524  case TOR2:
525  m_state = HOLDING;
527  ClearRetryTimer ();
529  SetHoldingTimer ();
530  break;
531  case CNCL:
532  m_state = HOLDING;
534  ClearRetryTimer ();
536  SetHoldingTimer ();
537  break;
538  default:
539  //11B.5.3.7 of 802.11s Draft D3.0
540  //All other events shall be ignored in this state
541  break;
542  }
543  break;
544  case ESTAB:
545  switch (event)
546  {
547  case OPN_ACPT:
549  break;
550  case CLS_ACPT:
551  m_state = HOLDING;
554  SetHoldingTimer ();
555  break;
556  case OPN_RJCT:
557  case CNF_RJCT:
558  m_state = HOLDING;
560  ClearRetryTimer ();
561  SendPeerLinkClose (reasoncode);
562  SetHoldingTimer ();
563  break;
564  case CNCL:
565  m_state = HOLDING;
568  SetHoldingTimer ();
569  break;
570  default:
571  //11B.5.3.8 of 802.11s Draft D3.0
572  //All other events shall be ignored in this state
573  break;
574  }
575  break;
576  case HOLDING:
577  switch (event)
578  {
579  case CLS_ACPT:
581  // fall through:
582  case TOH:
583  m_state = IDLE;
585  break;
586  case OPN_ACPT:
587  case CNF_ACPT:
588  m_state = HOLDING;
590  // reason not spec in D2.0
592  break;
593  case OPN_RJCT:
594  case CNF_RJCT:
595  m_state = HOLDING;
597  SendPeerLinkClose (reasoncode);
598  break;
599  default:
600  //11B.5.3.9 of 802.11s Draft D3.0
601  //All other events shall be ignored in this state
602  break;
603  }
604  break;
605  }
606 }
607 void
609 {
610  m_retryTimer.Cancel ();
611 }
612 void
614 {
616 }
617 void
619 {
621 }
622 void
624 {
625  IePeerManagement peerElement;
626  peerElement.SetPeerClose (m_localLinkId, m_peerLinkId, reasoncode);
629 }
630 void
632 {
633  IePeerManagement peerElement;
634  peerElement.SetPeerOpen (m_localLinkId);
635  NS_ASSERT (m_macPlugin != 0);
638 }
639 void
641 {
642  IePeerManagement peerElement;
646 }
647 void
649 {
652 }
653 void
655 {
656  StateMachine (TOH);
657 }
658 void
660 {
663 }
664 void
666 {
668  {
669  StateMachine (TOR1);
670  }
671  else
672  {
673  StateMachine (TOR2);
674  }
675 }
676 void
678 {
681 }
682 void
684 {
685  StateMachine (TOC);
686 }
687 void
688 PeerLink::Report (std::ostream & os) const
689 {
690  if (m_state != ESTAB)
691  {
692  return;
693  }
694  os << "<PeerLink" << std::endl <<
695  "localAddress=\"" << m_macPlugin->GetAddress () << "\"" << std::endl <<
696  "peerInterfaceAddress=\"" << m_peerAddress << "\"" << std::endl <<
697  "peerMeshPointAddress=\"" << m_peerMeshPointAddress << "\"" << std::endl <<
698  "metric=\"" << m_macPlugin->GetLinkMetric (m_peerAddress) << "\"" << std::endl <<
699  "lastBeacon=\"" << m_lastBeacon.GetSeconds () << "\"" << std::endl <<
700  "localLinkId=\"" << m_localLinkId << "\"" << std::endl <<
701  "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl <<
702  "assocId=\"" << m_assocId << "\"" << std::endl <<
703  "/>" << std::endl;
704 }
705 } // namespace dot11s
706 } // namespace ns3
707 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:62
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
double GetSeconds(void) const
Definition: nstime.h:272
See 7.3.2.85 of draft 2.07.
int64_t GetMicroSeconds(void) const
Definition: nstime.h:289
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
void SetPeerClose(uint16_t localLinkID, uint16_t peerLinkId, PmpReasonCode reasonCode)
See 7.3.2.89 of 802.11s draft 2.07.
static Mac48Address GetBroadcast(void)
uint32_t GetLinkMetric(Mac48Address peerAddress)
void SendPeerLinkManagementFrame(Mac48Address peerAddress, Mac48Address peerMpAddress, uint16_t aid, IePeerManagement peerElement, IeConfiguration meshConfig)
an EUI-48 address
Definition: mac48-address.h:41
Mac48Address GetAddress() const
debug only, used to print established links
void SetPeerConfirm(uint16_t localLinkID, uint16_t peerLinkId)
PmpReasonCode
Codes used by 802.11s Peer Management Protocol.
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:47
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:441
void SetPeerOpen(uint16_t localLinkId)
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610