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
29namespace ns3 {
30
31NS_LOG_COMPONENT_DEFINE ("Dot11sPeerManagementProtocol");
32
33namespace dot11s {
34
36
37TypeId
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
90const char* const
91PeerLink::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}
115void
117{
118 NS_LOG_FUNCTION (this);
124}
125void
127{
128 m_peerAddress = macaddr;
129}
130void
132{
133 m_peerMeshPointAddress = macaddr;
134}
135void
137{
138 m_interface = interface;
139}
140void
142{
143 m_localLinkId = id;
144}
145void
147{
148 m_assocId = aid;
149}
150void
151PeerLink::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}
160void
162{
164}
165void
167{
168 NS_LOG_FUNCTION (this);
170}
171void
173{
174 m_packetFail = 0;
175}
176void
178{
179 NS_LOG_FUNCTION (this);
180 m_packetFail++;
182 {
183 NS_LOG_DEBUG ("TransmissionFailure:: CNCL");
185 m_packetFail = 0;
186 }
187}
188
189void
191{
192 m_beaconTiming = beaconTiming;
193}
196{
197 return m_peerAddress;
198}
199uint16_t
201{
202 return m_assocId;
203}
204uint16_t
206{
207 return m_peerAssocId;
208}
209
210Time
212{
213 return m_lastBeacon;
214}
215Time
217{
218 return m_beaconInterval;
219}
222{
223 return m_beaconTiming;
224}
225void
227{
228 StateMachine (CNCL, reason);
229}
230void
232{
234}
235void
237{
239}
240void
241PeerLink::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}
261void
263{
264 NS_LOG_FUNCTION (this << localLinkId << peerMp);
265 m_peerLinkId = localLinkId;
268 {
270 }
271 else
272 {
273 m_peerMeshPointAddress = peerMp;
274 }
276}
277void
279{
280 NS_LOG_FUNCTION (this << localLinkId << peerMp << reason);
281 if (m_peerLinkId == 0)
282 {
283 m_peerLinkId = localLinkId;
284 }
287 {
289 }
290 else
291 {
292 m_peerMeshPointAddress = peerMp;
293 }
294 StateMachine (OPN_RJCT, reason);
295}
296void
297PeerLink::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 {
321 }
322 else
323 {
324 m_peerMeshPointAddress = peerMp;
325 }
327}
328void
329PeerLink::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 {
352 }
353 m_peerMeshPointAddress = peerMp;
354 StateMachine (CNF_RJCT, reason);
355}
356bool
358{
359 return (m_state == ESTAB);
360}
361bool
363{
364 return (m_state == IDLE);
365}
366void
368{
369 m_macPlugin = plugin;
370}
371//-----------------------------------------------------------------------------
372// Private
373//-----------------------------------------------------------------------------
374void
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:
394 SetRetryTimer ();
395 break;
396 case OPN_ACPT:
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:
415 SetRetryTimer ();
416 break;
417 case CNF_ACPT:
422 break;
423 case OPN_ACPT:
427 break;
428 case CLS_ACPT:
434 break;
435 case OPN_RJCT:
436 case CNF_RJCT:
440 SendPeerLinkClose (reasoncode);
442 break;
443 case TOR2:
449 break;
450 case CNCL:
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:
481 break;
482 case CNF_RJCT:
483 case OPN_RJCT:
487 SendPeerLinkClose (reasoncode);
489 break;
490 case CNCL:
496 break;
497 case TOC:
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:
515 SetRetryTimer ();
516 break;
517 case CNF_ACPT:
518 m_state = ESTAB;
522 break;
523 case CLS_ACPT:
529 break;
530 case OPN_RJCT:
531 case CNF_RJCT:
535 SendPeerLinkClose (reasoncode);
537 break;
538 case TOR2:
544 break;
545 case CNCL:
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:
569 break;
570 case OPN_RJCT:
571 case CNF_RJCT:
575 SendPeerLinkClose (reasoncode);
577 break;
578 case CNCL:
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:
604 // reason not spec in D2.0
606 break;
607 case OPN_RJCT:
608 case CNF_RJCT:
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}
621void
623{
625}
626void
628{
630}
631void
633{
635}
636void
638{
639 IePeerManagement peerElement;
640 peerElement.SetPeerClose (m_localLinkId, m_peerLinkId, reasoncode);
643}
644void
646{
647 IePeerManagement peerElement;
648 peerElement.SetPeerOpen (m_localLinkId);
649 NS_ASSERT (m_macPlugin != 0);
652}
653void
655{
656 IePeerManagement peerElement;
660}
661void
663{
666}
667void
669{
670 NS_LOG_FUNCTION (this);
672}
673void
675{
678}
679void
681{
682 NS_LOG_FUNCTION (this);
684 {
685 NS_LOG_LOGIC ("Retry timeout TOR1");
687 }
688 else
689 {
690 NS_LOG_LOGIC ("Retry timeout TOR2");
692 }
693}
694void
696{
699}
700void
702{
704}
705void
706PeerLink::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
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetBroadcast(void)
A base class which provides memory management and object aggregation.
Definition: object.h:88
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
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:67
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
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:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Definition: conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:536
@ IDLE
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:75