A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
peer-link.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Kirill Andreev <andreev@iitp.ru>
7 * Aleksey Kovalenko <kovalenko@iitp.ru>
8 * Pavel Boyko <boyko@iitp.ru>
9 */
10
11#include "peer-link.h"
12
14
15#include "ns3/log.h"
16#include "ns3/simulator.h"
17#include "ns3/traced-value.h"
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("Dot11sPeerManagementProtocol");
23
24namespace dot11s
25{
26
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::dot11s::PeerLink")
35 .SetGroupName("Mesh")
36 .AddConstructor<PeerLink>()
37 .AddAttribute("RetryTimeout",
38 "Retry timeout",
39 TimeValue(TimeValue(MicroSeconds(40 * 1024))),
42 .AddAttribute("HoldingTimeout",
43 "Holding timeout",
44 TimeValue(TimeValue(MicroSeconds(40 * 1024))),
47 .AddAttribute("ConfirmTimeout",
48 "Confirm timeout",
49 TimeValue(TimeValue(MicroSeconds(40 * 1024))),
52 .AddAttribute("MaxRetries",
53 "Maximum number of retries",
57 .AddAttribute("MaxBeaconLoss",
58 "Maximum number of lost beacons before link will be closed",
62 .AddAttribute("MaxPacketFailure",
63 "Maximum number of failed packets before link will be closed",
67 return tid;
68}
69
70const char* const PeerLink::PeerStateNames[6] =
71 {"IDLE", "OPN_SNT", "CNF_RCVD", "OPN_RCVD", "ESTAB", "HOLDING"};
72
73//-----------------------------------------------------------------------------
74// PeerLink public interface
75//-----------------------------------------------------------------------------
77 : m_peerAddress(Mac48Address::GetBroadcast()),
78 m_peerMeshPointAddress(Mac48Address::GetBroadcast()),
79 m_localLinkId(0),
80 m_peerLinkId(0),
81 m_assocId(0),
82 m_peerAssocId(0),
83 m_lastBeacon(Seconds(0)),
84 m_beaconInterval(Seconds(0)),
85 m_packetFail(0),
86 m_state(IDLE),
87 m_retryCounter(0),
88 m_maxPacketFail(3)
89{
90 NS_LOG_FUNCTION(this);
91}
92
96
97void
107
108void
110{
111 m_peerAddress = macaddr;
112}
113
114void
119
120void
122{
123 m_interface = interface;
124}
125
126void
128{
129 m_localLinkId = id;
130}
131
132void
134{
135 m_assocId = aid;
136}
137
138void
139PeerLink::SetBeaconInformation(Time lastBeacon, Time beaconInterval)
140{
141 m_lastBeacon = lastBeacon;
142 m_beaconInterval = beaconInterval;
144 Time delay = Seconds(beaconInterval.GetSeconds() * m_maxBeaconLoss);
145 NS_ASSERT(delay.GetMicroSeconds() != 0);
147}
148
149void
154
155void
161
162void
167
168void
170{
171 NS_LOG_FUNCTION(this);
172 m_packetFail++;
174 {
175 NS_LOG_DEBUG("TransmissionFailure:: CNCL");
177 m_packetFail = 0;
178 }
179}
180
181void
183{
184 m_beaconTiming = beaconTiming;
185}
186
189{
190 return m_peerAddress;
191}
192
193uint16_t
195{
196 return m_assocId;
197}
198
199uint16_t
201{
202 return m_peerAssocId;
203}
204
205Time
207{
208 return m_lastBeacon;
209}
210
211Time
213{
214 return m_beaconInterval;
215}
216
222
223void
228
229void
234
235void
240
241void
242PeerLink::Close(uint16_t localLinkId, uint16_t peerLinkId, PmpReasonCode reason)
243{
244 NS_LOG_FUNCTION(this << localLinkId << peerLinkId << reason);
245 if (peerLinkId != 0 && m_localLinkId != peerLinkId)
246 {
247 return;
248 }
249 if (m_peerLinkId == 0)
250 {
251 m_peerLinkId = localLinkId;
252 }
253 else
254 {
255 if (m_peerLinkId != localLinkId)
256 {
257 return;
258 }
259 }
260 StateMachine(CLS_ACPT, reason);
261}
262
263void
265{
266 NS_LOG_FUNCTION(this << localLinkId << peerMp);
267 m_peerLinkId = localLinkId;
270 {
272 }
273 else
274 {
275 m_peerMeshPointAddress = peerMp;
276 }
278}
279
280void
281PeerLink::OpenReject(uint16_t localLinkId,
283 Mac48Address peerMp,
284 PmpReasonCode reason)
285{
286 NS_LOG_FUNCTION(this << localLinkId << peerMp << reason);
287 if (m_peerLinkId == 0)
288 {
289 m_peerLinkId = localLinkId;
290 }
293 {
295 }
296 else
297 {
298 m_peerMeshPointAddress = peerMp;
299 }
300 StateMachine(OPN_RJCT, reason);
301}
302
303void
304PeerLink::ConfirmAccept(uint16_t localLinkId,
305 uint16_t peerLinkId,
306 uint16_t peerAid,
308 Mac48Address peerMp)
309{
310 NS_LOG_FUNCTION(this << localLinkId << peerLinkId << peerAid << peerMp);
311 if (m_localLinkId != peerLinkId)
312 {
313 return;
314 }
315 if (m_peerLinkId == 0)
316 {
317 m_peerLinkId = localLinkId;
318 }
319 else
320 {
321 if (m_peerLinkId != localLinkId)
322 {
323 return;
324 }
325 }
327 m_peerAssocId = peerAid;
329 {
331 }
332 else
333 {
334 m_peerMeshPointAddress = peerMp;
335 }
337}
338
339void
340PeerLink::ConfirmReject(uint16_t localLinkId,
341 uint16_t peerLinkId,
343 Mac48Address peerMp,
344 PmpReasonCode reason)
345{
346 NS_LOG_FUNCTION(this << localLinkId << peerLinkId << peerMp << reason);
347 if (m_localLinkId != peerLinkId)
348 {
349 return;
350 }
351 if (m_peerLinkId == 0)
352 {
353 m_peerLinkId = localLinkId;
354 }
355 else
356 {
357 if (m_peerLinkId != localLinkId)
358 {
359 return;
360 }
361 }
364 {
366 }
367 m_peerMeshPointAddress = peerMp;
368 StateMachine(CNF_RJCT, reason);
369}
370
371bool
373{
374 return (m_state == ESTAB);
375}
376
377bool
379{
380 return (m_state == IDLE);
381}
382
383void
388
389//-----------------------------------------------------------------------------
390// Private
391//-----------------------------------------------------------------------------
392void
394{
395 switch (m_state)
396 {
397 case IDLE:
398 switch (event)
399 {
400 case CNCL:
401 case CLS_ACPT:
402 m_state = IDLE;
404 break;
405 case REQ_RJCT:
406 SendPeerLinkClose(reasoncode);
407 break;
408 case ACTOPN:
413 break;
414 case OPN_ACPT:
419 IDLE,
420 OPN_RCVD);
424 break;
425 default:
426 // 11B.5.3.4 of 802.11s Draft D3.0
427 // All other events shall be ignored in this state
428 break;
429 }
430 break;
431 case OPN_SNT:
432 switch (event)
433 {
434 case TOR1:
438 break;
439 case CNF_ACPT:
444 OPN_SNT,
445 CNF_RCVD);
448 break;
449 case OPN_ACPT:
454 OPN_SNT,
455 OPN_RCVD);
457 break;
458 case CLS_ACPT:
463 OPN_SNT,
464 HOLDING);
468 break;
469 case OPN_RJCT:
470 case CNF_RJCT:
475 OPN_SNT,
476 HOLDING);
478 SendPeerLinkClose(reasoncode);
480 break;
481 case TOR2:
486 OPN_SNT,
487 HOLDING);
491 break;
492 case CNCL:
497 OPN_SNT,
498 HOLDING);
502 break;
503 default:
504 // 11B.5.3.5 of 802.11s Draft D3.0
505 // All other events shall be ignored in this state
506 break;
507 }
508 break;
509 case CNF_RCVD:
510 switch (event)
511 {
512 case CNF_ACPT:
513 break;
514 case OPN_ACPT:
515 m_state = ESTAB;
519 CNF_RCVD,
520 ESTAB);
524 break;
525 case CLS_ACPT:
530 CNF_RCVD,
531 HOLDING);
535 break;
536 case CNF_RJCT:
537 case OPN_RJCT:
542 CNF_RCVD,
543 HOLDING);
545 SendPeerLinkClose(reasoncode);
547 break;
548 case CNCL:
553 CNF_RCVD,
554 HOLDING);
558 break;
559 case TOC:
564 CNF_RCVD,
565 HOLDING);
568 break;
569 default:
570 // 11B.5.3.6 of 802.11s Draft D3.0
571 // All other events shall be ignored in this state
572 break;
573 }
574 break;
575 case OPN_RCVD:
576 switch (event)
577 {
578 case TOR1:
582 break;
583 case CNF_ACPT:
584 m_state = ESTAB;
588 OPN_RCVD,
589 ESTAB);
592 break;
593 case CLS_ACPT:
598 OPN_RCVD,
599 HOLDING);
603 break;
604 case OPN_RJCT:
605 case CNF_RJCT:
610 OPN_RCVD,
611 HOLDING);
613 SendPeerLinkClose(reasoncode);
615 break;
616 case TOR2:
621 OPN_RCVD,
622 HOLDING);
626 break;
627 case CNCL:
632 OPN_RCVD,
633 HOLDING);
637 break;
638 default:
639 // 11B.5.3.7 of 802.11s Draft D3.0
640 // All other events shall be ignored in this state
641 break;
642 }
643 break;
644 case ESTAB:
645 switch (event)
646 {
647 case OPN_ACPT:
649 break;
650 case CLS_ACPT:
655 ESTAB,
656 HOLDING);
659 break;
660 case OPN_RJCT:
661 case CNF_RJCT:
666 ESTAB,
667 HOLDING);
669 SendPeerLinkClose(reasoncode);
671 break;
672 case CNCL:
677 ESTAB,
678 HOLDING);
681 break;
682 default:
683 // 11B.5.3.8 of 802.11s Draft D3.0
684 // All other events shall be ignored in this state
685 break;
686 }
687 break;
688 case HOLDING:
689 switch (event)
690 {
691 case CLS_ACPT:
693 // fall through:
694 case TOH:
695 m_state = IDLE;
697 break;
698 case OPN_ACPT:
699 case CNF_ACPT:
704 HOLDING,
705 HOLDING);
706 // reason not spec in D2.0
708 break;
709 case OPN_RJCT:
710 case CNF_RJCT:
715 HOLDING,
716 HOLDING);
717 SendPeerLinkClose(reasoncode);
718 break;
719 default:
720 // 11B.5.3.9 of 802.11s Draft D3.0
721 // All other events shall be ignored in this state
722 break;
723 }
724 break;
725 }
726}
727
728void
733
734void
739
740void
745
746void
757
758void
770
771void
782
783void
790
791void
797
798void
804
805void
807{
808 NS_LOG_FUNCTION(this);
810 {
811 NS_LOG_LOGIC("Retry timeout TOR1");
813 }
814 else
815 {
816 NS_LOG_LOGIC("Retry timeout TOR2");
818 }
819}
820
821void
828
829void
834
835void
836PeerLink::Report(std::ostream& os) const
837{
838 if (m_state != ESTAB)
839 {
840 return;
841 }
842 os << "<PeerLink" << std::endl
843 << "localAddress=\"" << m_macPlugin->GetAddress() << "\"" << std::endl
844 << "peerInterfaceAddress=\"" << m_peerAddress << "\"" << std::endl
845 << "peerMeshPointAddress=\"" << m_peerMeshPointAddress << "\"" << std::endl
846 << "metric=\"" << m_macPlugin->GetLinkMetric(m_peerAddress) << "\"" << std::endl
847 << "lastBeacon=\"" << m_lastBeacon.GetSeconds() << "\"" << std::endl
848 << "localLinkId=\"" << m_localLinkId << "\"" << std::endl
849 << "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl
850 << "assocId=\"" << m_assocId << "\"" << std::endl
851 << "/>" << std::endl;
852}
853} // namespace dot11s
854} // namespace ns3
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
an EUI-48 address
static Mac48Address GetBroadcast()
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:402
AttributeValue implementation for Time.
Definition nstime.h:1395
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
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:55
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:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:35
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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Definition conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ IDLE
Channel is IDLE, no packet is being transmitted.