33#include <ns3/double.h>
36#include <ns3/packet.h>
37#include <ns3/random-variable-stream.h>
38#include <ns3/simulator.h>
39#include <ns3/uinteger.h>
41#undef NS_LOG_APPEND_CONTEXT
42#define NS_LOG_APPEND_CONTEXT \
43 std::clog << "[address " << m_shortAddress << " | " << m_selfExt << "] ";
57 .SetGroupName(
"LrWpan")
59 .AddAttribute(
"PanId",
60 "16-bit identifier of the associated PAN",
63 MakeUintegerChecker<uint16_t>())
64 .AddTraceSource(
"MacTxEnqueue",
65 "Trace source indicating a packet has been "
66 "enqueued in the transaction queue",
68 "ns3::Packet::TracedCallback")
69 .AddTraceSource(
"MacTxDequeue",
70 "Trace source indicating a packet has was "
71 "dequeued from the transaction queue",
73 "ns3::Packet::TracedCallback")
74 .AddTraceSource(
"MacIndTxEnqueue",
75 "Trace source indicating a packet has been "
76 "enqueued in the indirect transaction queue",
78 "ns3::Packet::TracedCallback")
79 .AddTraceSource(
"MacIndTxDequeue",
80 "Trace source indicating a packet has was "
81 "dequeued from the indirect transaction queue",
83 "ns3::Packet::TracedCallback")
84 .AddTraceSource(
"MacTx",
85 "Trace source indicating a packet has "
86 "arrived for transmission by this device",
88 "ns3::Packet::TracedCallback")
89 .AddTraceSource(
"MacTxOk",
90 "Trace source indicating a packet has been "
93 "ns3::Packet::TracedCallback")
94 .AddTraceSource(
"MacTxDrop",
95 "Trace source indicating a packet has been "
96 "dropped during transmission",
98 "ns3::Packet::TracedCallback")
99 .AddTraceSource(
"MacIndTxDrop",
100 "Trace source indicating a packet has been "
101 "dropped from the indirect transaction queue"
102 "(The pending transaction list)",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource(
"MacPromiscRx",
106 "A packet has been received by this device, "
107 "has been passed up from the physical layer "
108 "and is being forwarded up the local protocol stack. "
109 "This is a promiscuous trace,",
111 "ns3::Packet::TracedCallback")
112 .AddTraceSource(
"MacRx",
113 "A packet has been received by this device, "
114 "has been passed up from the physical layer "
115 "and is being forwarded up the local protocol stack. "
116 "This is a non-promiscuous trace,",
118 "ns3::Packet::TracedCallback")
119 .AddTraceSource(
"MacRxDrop",
120 "Trace source indicating a packet was received, "
121 "but dropped before being forwarded up the stack",
123 "ns3::Packet::TracedCallback")
124 .AddTraceSource(
"Sniffer",
125 "Trace source simulating a non-promiscuous "
126 "packet sniffer attached to the device",
128 "ns3::Packet::TracedCallback")
129 .AddTraceSource(
"PromiscSniffer",
130 "Trace source simulating a promiscuous "
131 "packet sniffer attached to the device",
133 "ns3::Packet::TracedCallback")
134 .AddTraceSource(
"MacStateValue",
135 "The state of LrWpan Mac",
137 "ns3::TracedValueCallback::LrWpanMacState")
138 .AddTraceSource(
"MacIncSuperframeStatus",
139 "The period status of the incoming superframe",
141 "ns3::TracedValueCallback::SuperframeState")
142 .AddTraceSource(
"MacOutSuperframeStatus",
143 "The period status of the outgoing superframe",
145 "ns3::TracedValueCallback::SuperframeState")
146 .AddTraceSource(
"MacState",
147 "The state of LrWpan Mac",
149 "ns3::LrWpanMac::StateTracedCallback")
150 .AddTraceSource(
"MacSentPkt",
151 "Trace source reporting some information about "
154 "ns3::LrWpanMac::SentTracedCallback")
155 .AddTraceSource(
"IfsEnd",
156 "Trace source reporting the end of an "
157 "Interframe space (IFS)",
159 "ns3::Packet::TracedCallback");
216 uniformVar->SetAttribute(
"Max",
DoubleValue(255.0));
274 MakeNullCallback<void, MlmeBeaconNotifyIndicationParams>();
369 NS_LOG_ERROR(
this <<
" packet too big: " << p->GetSize());
380 NS_LOG_ERROR(
this <<
" Can not send packet with no Address field");
388 switch (params.m_srcAddrMode)
395 NS_ABORT_MSG(
"Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
406 NS_LOG_ERROR(
this <<
" Can not send packet with incorrect Source Address mode = "
407 << params.m_srcAddrMode);
415 switch (params.m_dstAddrMode)
422 NS_ABORT_MSG(
"Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
433 NS_LOG_ERROR(
this <<
" Can not send packet with incorrect Destination Address mode = "
434 << params.m_dstAddrMode);
467 NS_LOG_LOGIC(
"LrWpanMac::McpsDataRequest: requested an ACK on broadcast or "
468 "multicast destination ("
469 << shortAddr <<
") - forcefully removing it.");
504 p->AddHeader(macHdr);
513 p->AddTrailer(macTrailer);
515 NS_LOG_ERROR(
this <<
" Indirect transmissions not currently supported");
529 p->AddHeader(macHdr);
538 p->AddTrailer(macTrailer);
541 txQElement->txQMsduHandle = params.m_msduHandle;
542 txQElement->txQPkt = p;
567 if ((params.m_bcnOrd > 15) || (params.m_sfrmOrd > params.m_bcnOrd))
574 NS_LOG_ERROR(
this <<
"Incorrect superframe order or beacon order.");
594 confirmParams.
m_chPage = params.m_chPage;
603 NS_LOG_ERROR(
this <<
" A channel scan is already in progress");
614 NS_LOG_ERROR(
this <<
"Invalid scan duration or unsupported scan type");
643 pibAttr->phyCurrentPage = params.m_chPage;
657 bool invalidRequest =
false;
659 if (params.m_coordPanId == 0xffff)
661 invalidRequest =
true;
664 if (!invalidRequest && params.m_coordAddrMode ==
SHORT_ADDR)
669 invalidRequest =
true;
672 else if (!invalidRequest && params.m_coordAddrMode ==
EXT_ADDR)
674 if (params.m_coordExtAddr ==
Mac64Address(
"ff:ff:ff:ff:ff:ff:ff:ff") ||
675 params.m_coordExtAddr ==
Mac64Address(
"ff:ff:ff:ff:ff:ff:ff:ed"))
677 invalidRequest =
true;
685 NS_LOG_ERROR(
this <<
" Invalid PAN id in Association request");
697 pibAttr->phyCurrentPage = params.m_chPage;
746 switch (params.m_status)
768 commandPacket->AddHeader(macPayload);
769 commandPacket->AddHeader(macHdr);
775 macTrailer.
SetFcs(commandPacket);
778 commandPacket->AddTrailer(macTrailer);
812 if (params.m_assocMember)
826 commandPacket->AddHeader(macPayload);
827 commandPacket->AddHeader(macHdr);
833 macTrailer.
SetFcs(commandPacket);
836 commandPacket->AddTrailer(macTrailer);
839 txQElement->txQPkt = commandPacket;
850 uint64_t symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
853 pibAttr->phyCurrentChannel = params.m_logCh;
859 uint64_t searchSymbols;
860 Time searchBeaconTime;
867 if (params.m_trackBcn)
873 searchBeaconTime =
Seconds((
double)searchSymbols / symbolRate);
938 confirmParams.
id = id;
961 attributes->macExtendedAddress =
m_selfExt;
991 beaconPacket = Create<Packet>();
1020 beaconPacket->AddHeader(macPayload);
1021 beaconPacket->AddHeader(macHdr);
1027 macTrailer.
SetFcs(beaconPacket);
1030 beaconPacket->AddTrailer(macTrailer);
1038 NS_LOG_DEBUG(
"Outgoing superframe Active Portion (Beacon + CAP + CFP): "
1070 commandPacket->AddHeader(macPayload);
1071 commandPacket->AddHeader(macHdr);
1077 macTrailer.
SetFcs(commandPacket);
1080 commandPacket->AddTrailer(macTrailer);
1083 txQElement->txQPkt = commandPacket;
1111 commandPacket->AddHeader(macPayload);
1112 commandPacket->AddHeader(macHdr);
1118 macTrailer.
SetFcs(commandPacket);
1121 commandPacket->AddTrailer(macTrailer);
1124 txQElement->txQPkt = commandPacket;
1160 commandPacket->AddHeader(macPayload);
1161 commandPacket->AddHeader(macHdr);
1167 macTrailer.
SetFcs(commandPacket);
1170 commandPacket->AddTrailer(macTrailer);
1173 txQElement->txQPkt = commandPacket;
1218 commandPacket->AddHeader(macPayload);
1219 commandPacket->AddHeader(macHdr);
1225 macTrailer.
SetFcs(commandPacket);
1228 commandPacket->AddTrailer(macTrailer);
1232 txQElement->txQPkt = commandPacket;
1241 rxDataReqPkt->RemoveHeader(receivedMacHdr);
1243 rxDataReqPkt->RemoveHeader(receivedMacPayload);
1253 txQElement->txQPkt = indTxQElement->txQPkt;
1258 NS_LOG_DEBUG(
"Requested element not found in pending list");
1289 NS_LOG_ERROR(
this <<
" Coordinator realignment request not supported");
1367 bool channelFound =
false;
1373 channelFound =
true;
1463 bool channelFound =
false;
1468 channelFound =
true;
1514 uint64_t capDuration;
1516 uint64_t symbolRate;
1518 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1525 endCapTime =
Seconds((
double)capDuration / symbolRate);
1529 NS_LOG_DEBUG(
"Outgoing superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1530 <<
" symbols (" << endCapTime.As(
Time::S)
1532 NS_LOG_DEBUG(
"Active Slots duration " << activeSlot <<
" symbols");
1542 endCapTime =
Seconds((
double)capDuration / symbolRate);
1546 NS_LOG_DEBUG(
"Incoming superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1547 <<
" symbols (" << endCapTime.As(
Time::S)
1549 NS_LOG_DEBUG(
"Active Slots duration " << activeSlot <<
" symbols");
1562 uint64_t cfpDuration;
1564 uint64_t symbolRate;
1566 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1572 endCfpTime =
Seconds((
double)cfpDuration / symbolRate);
1573 if (cfpDuration > 0)
1578 NS_LOG_DEBUG(
"Incoming superframe CFP duration " << cfpDuration <<
" symbols ("
1579 << endCfpTime.As(
Time::S) <<
")");
1590 endCfpTime =
Seconds((
double)cfpDuration / symbolRate);
1592 if (cfpDuration > 0)
1597 NS_LOG_DEBUG(
"Outgoing superframe CFP duration " << cfpDuration <<
" symbols ("
1598 << endCfpTime.As(
Time::S) <<
")");
1611 uint64_t inactiveDuration;
1612 Time endInactiveTime;
1613 uint64_t symbolRate;
1615 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1620 endInactiveTime =
Seconds((
double)inactiveDuration / symbolRate);
1622 if (inactiveDuration > 0)
1627 NS_LOG_DEBUG(
"Incoming superframe Inactive Portion duration "
1628 << inactiveDuration <<
" symbols (" << endInactiveTime.
As(
Time::S) <<
")");
1634 endInactiveTime =
Seconds((
double)inactiveDuration / symbolRate);
1636 if (inactiveDuration > 0)
1641 NS_LOG_DEBUG(
"Outgoing superframe Inactive Portion duration "
1642 << inactiveDuration <<
" symbols (" << endInactiveTime.
As(
Time::S) <<
")");
1662 uint64_t symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1680 uint64_t searchSymbols;
1681 Time searchBeaconTime;
1684 searchBeaconTime =
Seconds((
double)searchSymbols / symbolRate);
1722 if (
m_csmaCa->GetBatteryLifeExtension())
1757 return pndAddrFields;
1875 uint64_t symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1882 p->RemoveTrailer(receivedMacTrailer);
1889 if (!receivedMacTrailer.
CheckFcs(p))
1896 p->RemoveHeader(receivedMacHdr);
1899 params.m_dsn = receivedMacHdr.
GetSeqNum();
1900 params.m_mpduLinkQuality = lqi;
1903 switch (params.m_srcAddrMode)
1916 switch (params.m_dstAddrMode)
1951 NS_LOG_ERROR(
this <<
" Data Indication Callback not initialized");
1961 acceptFrame = (receivedMacHdr.
GetFrameVer() <= 1);
2004 acceptFrame = !receivedMacHdr.
IsAckReq();
2008 acceptFrame =
false;
2021 acceptFrame =
false;
2028 acceptFrame =
false;
2034 acceptFrame =
false;
2044 p->PeekHeader(receivedMacPayload);
2050 acceptFrame =
false;
2060 ceil(6 *
m_phy->GetPhySymbolsPerOctet());
2061 Time ackTime =
Seconds((
double)ackSymbols / symbolRate);
2063 if (ackTime >= timeLeftInCap)
2065 NS_LOG_DEBUG(
"Command frame received but not enough time to transmit ACK "
2066 "before the end of CAP ");
2067 acceptFrame =
false;
2103 NS_LOG_DEBUG(
"Received a packet with ACK required while in CSMA. Cancel "
2113 m_rxPkt = originalPkt->Copy();
2117 p->PeekHeader(receivedMacPayload);
2121 NS_LOG_DEBUG(
"Data Request Command Received; processing ACK");
2124 NS_LOG_DEBUG(
"Association Request Command Received; processing ACK");
2128 NS_LOG_DEBUG(
"Association Response Command Received; processing ACK");
2156 1 *
m_phy->GetPhySymbolsPerOctet() +
2157 (originalPkt->GetSize() *
m_phy->GetPhySymbolsPerOctet());
2164 NS_LOG_DEBUG(
"Beacon Received; forwarding up (m_macBeaconRxTime: "
2168 p->RemoveHeader(receivedMacPayload);
2216 m_csmaCa->SetBatteryLifeExtension(
true);
2220 m_csmaCa->SetBatteryLifeExtension(
false);
2223 if (m_incomingBeaconOrder < 15 && !m_csmaCa->IsSlottedCsmaCa())
2231 NS_LOG_DEBUG(
"Incoming superframe Active Portion (Beacon + CAP + CFP): "
2241 NS_LOG_DEBUG(
this <<
" Device not associated, cannot process beacon");
2246 if (p->GetSize() > 0)
2255 beaconParams.
m_sdu = p;
2263 bool descriptorExists =
false;
2272 (descriptor.m_coorShortAddr ==
2274 descriptor.m_coorPanId == panDescriptor.
m_coorPanId);
2282 descriptor.m_coorPanId == panDescriptor.
m_coorPanId);
2285 if (descriptorExists)
2291 if (!descriptorExists)
2308 uint64_t searchSymbols;
2309 Time searchBeaconTime;
2315 Seconds(
static_cast<double>(searchSymbols / symbolRate));
2343 beaconParams.
m_sdu = p;
2353 p->PeekHeader(receivedMacPayload);
2441 pkt->RemoveHeader(macHdr);
2442 pkt->RemoveHeader(cmdPayload);
2447 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2492 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2540 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2598 ackPacket->AddHeader(macHdr);
2603 macTrailer.
SetFcs(ackPacket);
2605 ackPacket->AddTrailer(macTrailer);
2629 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2647 pkt->RemoveHeader(hdr);
2653 txQElement->txQPkt =
nullptr;
2654 txQElement =
nullptr;
2683 uint64_t symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
2687 if (ifsTime == lifsTime)
2692 else if (ifsTime == sifsTime)
2726 pkt->RemoveHeader(macHdr);
2727 pkt->RemoveHeader(cmdPayload);
2800 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2823 p->PeekHeader(peekedMacHdr);
2836 indTxQElement->dstExtAddress = peekedMacHdr.
GetExtDstAddr();
2839 indTxQElement->seqNum = peekedMacHdr.
GetSeqNum();
2857 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2860 indTxQElement->expireTime = expireTime;
2861 indTxQElement->txQPkt = p;
2870 indTxQElement->txQPkt->PeekHeader(peekedMacHdr);
2891 if ((*iter)->dstExtAddress == dst)
2929 else if (peekedMacHdr.
IsData())
2956 <<
" Destination | Sequence Number | Frame type | Expire time\n";
2968 else if (peekedMacHdr.
IsData())
2970 os <<
"Data Frame ";
2988 <<
" Destination | Sequence Number | Dst PAN id | Frame type |\n";
2992 m_txQueue[i]->txQPkt->PeekHeader(peekedMacHdr);
3003 else if (peekedMacHdr.
IsData())
3005 os <<
"Data Frame ";
3021 p->PeekHeader(peekedMacHdr);
3027 if (((*it)->dstExtAddress == peekedMacHdr.
GetExtDstAddr()) &&
3028 ((*it)->seqNum == peekedMacHdr.
GetSeqNum()))
3038 ((*it)->seqNum == peekedMacHdr.
GetSeqNum()))
3060 symbolRate =
m_phy->GetDataOrSymbolRate(
false);
3076 uint64_t beaconSymbols =
m_phy->GetPhySHRDuration() +
3077 1 *
m_phy->GetPhySymbolsPerOctet() +
3124 txOriginalPkt->RemoveHeader(txMacHdr);
3126 txOriginalPkt->RemoveHeader(txMacPayload);
3160 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
3176 recvOriginalPkt->RemoveHeader(receivedMacHdr);
3181 recvOriginalPkt->RemoveHeader(receivedMacPayload);
3269 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
3284 NS_FATAL_ERROR(
"Transmission attempt failed with PHY status " << status);
3287 if (!ifsWaitTime.
IsZero())
3318 m_phy->PlmeEdRequest();
3360 m_phy->PlmeEdRequest();
3390 bool channelFound =
false;
3395 channelFound =
true;
3419 NS_LOG_ERROR(
this <<
"Channel Scan: Invalid channel page");
3427 uint64_t symbolRate =
static_cast<uint64_t
>(
m_phy->GetDataOrSymbolRate(
false));
3436 uint64_t scanDurationSym =
3439 nextScanTime =
Seconds(
static_cast<double>(scanDurationSym) / symbolRate);
3490 <<
" could not be set in the current page");
3529 NS_LOG_ERROR(
"Invalid channel parameter in MLME-start");
3560 NS_LOG_ERROR(
"Invalid page parameter in MLME-associate");
3588 NS_LOG_ERROR(
"Invalid channel parameter in MLME-associate");
3639 pkt->RemoveHeader(macHdr);
3644 pkt->RemoveHeader(cmdPayload);
3742 else if (macHdr.
IsData())
3781 NS_LOG_DEBUG(
"****** PACKET DEFERRED to the next superframe *****");
3846 ceil(6 *
m_phy->GetPhySymbolsPerOctet());
3886 NS_LOG_DEBUG(
"ERROR: Packet not for the coordinator!");
3923 return (
m_phy->GetPhySHRDuration() + 1 *
m_phy->GetPhySymbolsPerOctet() +
bool IsNull() const
Check for null implementation.
Implements the header for the MAC payload command frame according to the IEEE 802....
void SetPage(uint8_t page)
Set the logical channel page number.
@ FULL_CAPACITY
PAN at capacity.
@ ACCESS_DENIED
PAN access denied.
@ SUCCESSFUL
Association successful.
CapabilityField GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetPanId(uint16_t id)
Get the PAN identifier.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
void SetCapabilityField(CapabilityField cap)
Set the Capability Information Field to the command payload header (Association Request Command).
AssocStatus GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
void SetAssociationStatus(AssocStatus status)
Set status resulting from the association attempt (Association Response Command).
MacCommand GetCommandFrameType() const
Get the command frame type ID.
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ BEACON_REQ
Beacon Request (RFD true: none )
@ DATA_REQ
Data Request (RFD true: Tx)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
uint16_t GetPanId() const
Get the PAN identifier.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
void SetChannel(uint8_t channel)
Set the logical channel number.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Represent the GTS information fields.
bool GetGtsPermit() const
Get the GTS Specification Permit.
Class that implements the LR-WPAN MAC state machine.
uint32_t m_incomingBeaconInterval
Indication of the interval a node should receive a superframe expressed in symbols.
uint32_t GetIfsSize()
Get the size of the Interframe Space according to MPDU size (m_txPkt).
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
uint64_t m_assocRespCmdWaitTime
The maximum wait time for an association response command after the reception of data request command...
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
uint64_t GetMacAckWaitDuration() const
Get the macAckWaitDuration attribute value.
Time m_macBeaconRxTime
The time that the device received its last bit of the beacon frame.
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
bool m_macAssociationPermit
Indication of whether a coordinator is currently allowing association.
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
void SetMlmeBeaconNotifyIndicationCallback(MlmeBeaconNotifyIndicationCallback c)
Set the callback for the indication of an incoming beacon packet.
uint64_t m_rxBeaconSymbols
The total size of the received beacon in symbols.
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
uint64_t GetTxPacketSymbols()
Obtain the number of symbols in the packet which is currently being sent by the MAC layer.
void MlmeGetRequest(LrWpanMacPibAttributeIdentifier id)
IEEE 802.15.4-2011, section 6.2.5.1 MLME-GET.request Request information about a given PIB attribute.
bool m_panCoor
Indication of whether the current device is the PAN coordinator.
void SetMlmeAssociateIndicationCallback(MlmeAssociateIndicationCallback c)
Set the callback for the indication of an incoming associate request command.
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
void MlmeSyncRequest(MlmeSyncRequestParams params)
IEEE 802.15.4-2011, section 6.2.13.1 MLME-SYNC.request Request to synchronize with the coordinator by...
static TypeId GetTypeId()
Get the type ID.
MlmeStartConfirmCallback m_mlmeStartConfirmCallback
This callback is used to report the start of a new PAN or the begin of a new superframe configuration...
uint8_t m_deviceCapability
Indication of current device capability (FFD or RFD)
void AwaitBeacon()
Called after the end of an INCOMING superframe to start the moment a device waits for a new incoming ...
bool m_coor
Indicates if the current device is a coordinator type.
void LostAssocRespCommand()
Called after m_assocRespCmdWaitTime timeout while waiting for an association response command.
bool isCoordDest()
Check if the packet destination is its coordinator.
EventId m_trackingEvent
Scheduler event to track the incoming beacons.
void SetMlmeScanConfirmCallback(MlmeScanConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
uint32_t m_maxIndTxQueueSize
The maximum size of the indirect transmit queue (The pending transaction list).
EventId m_assocResCmdWaitTimeout
Scheduler event for the lost of a association response command frame.
void PurgeInd()
Purge expired transactions from the pending transactions list.
void SetMlmePollConfirmCallback(MlmePollConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission.
void PlmeEdConfirm(LrWpanPhyEnumeration status, uint8_t energyLevel)
IEEE 802.15.4-2006 section 6.2.2.4 PLME-ED.confirm status and energy level.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
void MlmeStartRequest(MlmeStartRequestParams params)
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
uint32_t m_macLIFSPeriod
The minimum time forming a Long InterFrame Spacing (LIFS) period.
void StartInactivePeriod(SuperframeType superframeType)
Start the Inactive Period in a beacon-enabled mode.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
TracedCallback< Ptr< const Packet > > m_macIndTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 indirect transmission queue (Pending ...
TracedCallback< Ptr< const Packet > > m_macIndTxDropTrace
The trace source fired when packets are dropped due to indirect Tx queue overflows or expiration.
void SetMlmeAssociateConfirmCallback(MlmeAssociateConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
MlmeScanConfirmCallback m_mlmeScanConfirmCallback
This callback is used to report the result of a scan on a group of channels for the selected channel ...
Mac16Address GetShortAddress() const
Get the short address of this MAC.
void SendDataRequestCommand()
Used to send a data request command (i.e.
void SetMlmeStartConfirmCallback(MlmeStartConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
SuperframeField GetSuperframeField()
Constructs a Superframe specification field from the local information, the superframe Specification ...
EventId m_cfpEvent
Scheduler event for the end of the outgoing superframe CFP.
void PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, Ptr< LrWpanPhyPibAttributes > attribute)
IEEE 802.15.4-2006 section 6.2.2.6 PLME-GET.confirm Get attributes per definition from Table 23 in se...
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Mac64Address m_macCoordExtendedAddress
The extended address of the coordinator through which the device is associated.
MlmeSyncLossIndicationCallback m_mlmeSyncLossIndicationCallback
This callback is used to indicate the loss of synchronization with a coordinator.
PendingPrimitiveStatus m_pendPrimitive
Indicates the pending primitive when PLME.SET operation (page or channel switch) is called from withi...
MlmePollConfirmCallback m_mlmePollConfirmCallback
This callback is used to report the status after a device send data command request to the coordinato...
uint8_t GetMacMaxFrameRetries() const
Get the macMaxFrameRetries attribute value.
uint16_t m_channelScanIndex
The channel list index used to obtain the current scanned channel.
uint16_t GetPanId() const
Get the PAN id used by this MAC.
PendingAddrFields GetPendingAddrFields()
Constructs Pending Address Fields from the local information, the Pending Address Fields are part of ...
std::vector< PanDescriptor > m_panDescriptorList
The list of PAN descriptors accumulated during channel scans, used to select a PAN to associate.
void SendBeaconRequestCommand()
Called to send a beacon request command.
EventId m_respWaitTimeout
Scheduler event for a response to a request command frame.
uint32_t m_maxTxQueueSize
The maximum size of the transmit queue.
Ptr< Packet > m_macBeaconPayload
The contents of the beacon payload.
std::deque< Ptr< TxQueueElement > > m_txQueue
The transmit queue used by the MAC.
SequenceNumber8 m_macBsn
Sequence number added to transmitted beacon frame, 00-ff.
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Ptr< Packet > m_rxPkt
The command request packet received.
TracedCallback< Ptr< const Packet > > m_macIndTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Mac16Address m_shortAddress
The short address (16 bit address) used by this MAC.
uint8_t m_macSuperframeOrder
Used by a PAN coordinator or coordinator.
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
void BeaconSearchTimeout()
Called if the device is unable to locate a beacon in the time set by MLME-SYNC.request.
bool isTxAckReq()
Check if the packet to transmit requires acknowledgment.
std::vector< uint8_t > m_energyDetectList
The list of energy measurements, one for each channel searched during an ED scan.
void PdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
IEEE 802.15.4-2006 section 6.2.1.3 PD-DATA.indication Indicates the transfer of an MPDU from PHY to M...
void SendOneBeacon()
Called to send a single beacon frame.
Time m_macBeaconTxTime
The time that the device transmitted its last beacon frame.
MlmeBeaconNotifyIndicationCallback m_mlmeBeaconNotifyIndicationCallback
This callback is used to notify incoming beacon packets to the upper layers.
void EndStartRequest()
Called to end a MLME-START.request after changing the page and channel number.
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Mac64Address GetExtendedAddress() const
Get the extended address of this MAC.
EventId m_setMacState
Scheduler event for a deferred MAC state change.
uint64_t m_macResponseWaitTime
The maximum time, in multiples of aBaseSuperframeDuration, a device shall wait for a response command...
void EnqueueInd(Ptr< Packet > p)
Adds a packet to the pending transactions list (Indirect transmissions).
void SendAssocResponseCommand(Ptr< Packet > rxDataReqPkt)
Called to send an associate response command.
void SetMlmeSetConfirmCallback(MlmeSetConfirmCallback c)
Set the callback for the confirmation of an attempt to write an attribute.
void StartCFP(SuperframeType superframeType)
Called to begin the Contention Free Period (CFP) in a beacon-enabled mode.
EventId m_scanEnergyEvent
Scheduler event for the end of a ED channel scan.
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
bool PrepareRetransmission()
Check for remaining retransmissions for the packet currently being sent.
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
void MlmeAssociateRequest(MlmeAssociateRequestParams params)
IEEE 802.15.4-2011, section 6.2.2.1 MLME-ASSOCIATE.request Request primitive used by a device to requ...
void EnqueueTxQElement(Ptr< TxQueueElement > txQElement)
Add an element to the transmission queue.
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
EventId m_scanEvent
Scheduler event for the end of an ACTIVE or PASSIVE channel scan.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
uint8_t m_incomingBeaconOrder
The beaconOrder value of the INCOMING frame.
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
void SetMlmeSyncLossIndicationCallback(MlmeSyncLossIndicationCallback c)
Set the callback for the loss of synchronization with a coordinator.
void SendOrphanNotificationCommand()
Called to send a orphan notification command.
uint32_t m_ifs
The value of the necessary InterFrame Space after the transmission of a packet.
uint16_t m_macTransactionPersistenceTime
The maximum time (in UNIT periods) that a transaction is stored by a coordinator and indicated in its...
Mac16Address GetCoordShortAddress() const
Get the coordinator short address currently associated to this device.
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
MlmeStartRequestParams m_startParams
The parameters used during a MLME-START.request.
void AckWaitTimeout()
Handle an ACK timeout with a packet retransmission, if there are retransmission left,...
void MlmeScanRequest(MlmeScanRequestParams params)
IEEE 802.15.4-2011, section 6.2.10.1 MLME-SCAN.request Request primitive used to initiate a channel s...
LrWpanAssociationStatus GetAssociationStatus() const
Get the current association status.
std::vector< uint8_t > m_unscannedChannels
The list of unscanned channels during a scan operation.
Mac64Address GetCoordExtAddress() const
Get the coordinator extended address currently associated to this device.
uint8_t m_macBeaconOrder
Used by a PAN coordinator or coordinator.
TracedCallback< Time > m_macIfsEndTrace
The trace source is fired at the end of any Interframe Space (IFS).
void SetMlmeGetConfirmCallback(MlmeGetConfirmCallback c)
Set the callback for the confirmation of an attempt to read an attribute.
TracedValue< SuperframeStatus > m_outSuperframeStatus
The current period of the outgoing superframe.
void PlmeSetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id)
IEEE 802.15.4-2006 section 6.2.2.10 PLME-SET.confirm Set attributes per definition from Table 23 in s...
MlmeOrphanIndicationCallback m_mlmeOrphanIndicationCallback
This callback is used to indicate the reception of a orphan notification command.
void SetMlmeCommStatusIndicationCallback(MlmeCommStatusIndicationCallback c)
Set the callback for the indication to a response primitive.
bool DequeueInd(Mac64Address dst, Ptr< IndTxQueueElement > entry)
Extracts a packet from pending transactions list (Indirect transmissions).
MlmeAssociateRequestParams m_associateParams
The parameters used during a MLME-ASSOCIATE.request.
LrWpanMac()
Default constructor.
void CheckQueue()
Check the transmission queue.
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
MlmeAssociateConfirmCallback m_mlmeAssociateConfirmCallback
This callback is used to report the status after a device request an association with a coordinator.
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
uint8_t m_fnlCapSlot
Indication of the Slot where the CAP portion of the OUTGOING Superframe ends.
uint32_t m_macSIFSPeriod
The minimum time forming a Short InterFrame Spacing (SIFS) period.
void IfsWaitTimeout(Time ifsTime)
After a successful transmission of a frame (beacon, data) or an ack frame reception,...
std::deque< Ptr< IndTxQueueElement > > m_indTxQueue
The indirect transmit queue used by the MAC pending messages (The pending transaction list).
uint32_t m_beaconInterval
Indication of the Interval used by the coordinator to transmit beacon frames expressed in symbols.
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
TracedCallback< Ptr< const Packet > > m_macTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
EventId m_capEvent
Scheduler event for the end of the outgoing superframe CAP.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
void EndChannelScan()
Called at the end of the current channel scan (Active or Passive) for a given duration.
void DoInitialize() override
Initialize() implementation.
void MlmeAssociateResponse(MlmeAssociateResponseParams params)
IEEE 802.15.4-2011, section 6.2.2.3 MLME-ASSOCIATE.response Primitive used to initiate a response to ...
void PrintTxQueue(std::ostream &os) const
Print the Transmit Queue.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
bool m_macAutoRequest
Indication of whether a device automatically sends data request command if its address is listed in t...
uint8_t m_incomingSuperframeOrder
Used by all devices that have a parent.
uint16_t m_macPanIdScan
Temporally stores the value of the current m_macPanId when a MLME-SCAN.request is performed.
uint32_t m_macBeaconPayloadLength
The length, in octets, of the beacon payload.
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
uint8_t m_numLostBeacons
The number of consecutive loss beacons in a beacon tracking operation.
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p)
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
void SendAssocRequestCommand()
Called to send an associate request command.
uint8_t m_maxEnergyLevel
The maximum energy level detected during ED scan on the current channel.
void DoDispose() override
Destructor implementation.
MlmeScanRequestParams m_scanParams
The parameters used during a MLME-SCAN.request.
MlmeAssociateIndicationCallback m_mlmeAssociateIndicationCallback
This callback is used to indicate the reception of an association request command.
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Ptr< LrWpanPhy > GetPhy()
Get the underlying PHY of the MAC.
EventId m_scanOrphanEvent
Scheduler event for the end of an ORPHAN channel scan.
void EndAssociateRequest()
Called to end an MLME-ASSOCIATE.request after changing the page and channel number.
MlmeSetConfirmCallback m_mlmeSetConfirmCallback
This callback is used to report the result of an attribute writing request to the upper layers.
Mac64Address m_selfExt
The extended 64 address (IEEE EUI-64) used by this MAC.
MlmeGetConfirmCallback m_mlmeGetConfirmCallback
This callback is used to report the result of an attribute read request to the upper layers.
EventId m_incCapEvent
Scheduler event for the end of the incoming superframe CAP.
void SetTxQMaxSize(uint32_t queueSize)
Set the max size of the transmit queue.
void SetIndTxQMaxSize(uint32_t queueSize)
Set the max size of the indirect transmit queue (Pending Transaction list)
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
bool m_beaconTrackingOn
Indication of whether the current device is tracking incoming beacons.
uint32_t m_superframeDuration
Indication of the superframe duration in symbols.
bool GetRxOnWhenIdle() const
Check if the receiver will be enabled when the MAC is idle.
Mac16Address m_macCoordShortAddress
The short address of the coordinator through which the device is associated.
GtsFields GetGtsFields()
Constructs the Guaranteed Time Slots (GTS) Fields from local information.
void MlmeOrphanResponse(MlmeOrphanResponseParams params)
IEEE 802.15.4-2011, section 6.2.7.2 MLME-ORPHAN.response Primitive used to initiatte a response to an...
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
void EndChannelEnergyScan()
Called at the end of one ED channel scan.
void PrintTransmitQueueSize()
Print the number of elements in the packet transmit queue.
void PrintPendTxQ(std::ostream &os) const
Print the Pending transaction list.
void MlmeSetRequest(LrWpanMacPibAttributeIdentifier id, Ptr< LrWpanMacPibAttributes > attribute)
IEEE 802.15.4-2011, section 6.2.11.1 MLME-SET.request Attempts to write the given value to the indica...
void StartCAP(SuperframeType superframeType)
Called to begin the Contention Access Period (CAP) in a beacon-enabled mode.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
void MlmePollRequest(MlmePollRequestParams params)
IEEE 802.15.4-2011, section 6.2.14.2 MLME-POLL.request Prompts the device to request data from the co...
EventId m_ifsEvent
Scheduler event for Interframe spacing wait time.
EventId m_beaconEvent
Scheduler event for generation of one beacon.
uint32_t m_incomingSuperframeDuration
Indication of the superframe duration in symbols (e.g.
TracedCallback< Ptr< const Packet >, uint8_t, uint8_t > m_sentPktTrace
The trace source fired when packets are considered as successfully sent or the transmission has been ...
void RemovePendTxQElement(Ptr< Packet > p)
Remove an element from the pending transaction list.
void SetMlmeOrphanIndicationCallback(MlmeOrphanIndicationCallback c)
Set the callback for the indication to the reception of an orphan notification.
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
EventId m_incCfpEvent
Scheduler event for the end of the incoming superframe CFP.
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
uint8_t m_incomingFnlCapSlot
Indication of the Slot where the CAP portion of the INCOMING Superframe ends.
MlmeCommStatusIndicationCallback m_mlmeCommStatusIndicationCallback
This callback is instigated through a response primitive.
TracedValue< SuperframeStatus > m_incSuperframeStatus
The current period of the incoming superframe.
void SetAssociatedCoor(Mac16Address mac)
Check if the packet destination is its coordinator.
Represent the Mac Trailer with the Frame Check Sequence field.
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
This class can contain 16 bit addresses.
bool IsMulticast() const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
bool IsBroadcast() const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
static Mac64Address Allocate()
Allocate a new Mac64Address.
static bool ChecksumEnabled()
A base class which provides memory management and object aggregation.
virtual void DoInitialize()
Initialize() implementation.
virtual void DoDispose()
Destructor implementation.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > Copy() const
performs a COW copy of the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Represent the Pending Address Specification field.
Smart pointer class similar to boost::intrusive_ptr.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Represent the Superframe Specification information field.
uint8_t GetFinalCapSlot() const
Get the the Final CAP Slot.
void SetAssocPermit(bool assocPermit)
Set the Superframe Specification Association Permit field.
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
uint8_t GetBeaconOrder() const
Get the Superframe Specification Beacon Order field.
bool IsBattLifeExt() const
Check if the Battery Life Extension bit is enabled.
void SetFinalCapSlot(uint8_t capSlot)
Set the superframe specification Final CAP slot field.
void SetSuperframeOrder(uint8_t frmOrder)
Set the superframe specification Superframe Order field.
void SetPanCoor(bool panCoor)
Set the Superframe Specification PAN coordinator field.
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
uint8_t GetFrameOrder() const
Get the Superframe Specification Frame Order field.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
bool IsZero() const
Exactly equivalent to t == 0.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
constexpr uint32_t aMaxSIFSFrameSize
The maximum size of an MPDU, in octets, that can be followed by a Short InterFrame Spacing (SIFS) per...
constexpr uint32_t aMaxLostBeacons
The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to decl...
constexpr uint32_t aMaxBeaconPayloadLength
The maximum size, in octets, of a beacon payload.
constexpr uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.