22#include <ns3/double.h>
25#include <ns3/packet.h>
26#include <ns3/random-variable-stream.h>
27#include <ns3/simulator.h>
28#include <ns3/uinteger.h>
30#undef NS_LOG_APPEND_CONTEXT
31#define NS_LOG_APPEND_CONTEXT \
32 std::clog << "[" << m_shortAddress << " | " << m_macExtendedAddress << "] ";
60 os <<
"CHANNEL_ACCESS_FAILURE";
66 os <<
"SET PHY to TX ON";
69 os <<
"MAC GTS PERIOD";
72 os <<
"SUPERFRAME INACTIVE PERIOD";
75 os <<
"CSMA DEFERRED TO NEXT PERIOD";
85 TypeId(
"ns3::lrwpan::LrWpanMac")
88 .SetGroupName(
"LrWpan")
90 .AddAttribute(
"PanId",
91 "16-bit identifier of the associated PAN",
95 .AddTraceSource(
"MacTxEnqueue",
96 "Trace source indicating a packet has been "
97 "enqueued in the transaction queue",
99 "ns3::Packet::TracedCallback")
100 .AddTraceSource(
"MacTxDequeue",
101 "Trace source indicating a packet has was "
102 "dequeued from the transaction queue",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource(
"MacIndTxEnqueue",
106 "Trace source indicating a packet has been "
107 "enqueued in the indirect transaction queue",
109 "ns3::Packet::TracedCallback")
110 .AddTraceSource(
"MacIndTxDequeue",
111 "Trace source indicating a packet has was "
112 "dequeued from the indirect transaction queue",
114 "ns3::Packet::TracedCallback")
115 .AddTraceSource(
"MacTx",
116 "Trace source indicating a packet has "
117 "arrived for transmission by this device",
119 "ns3::Packet::TracedCallback")
120 .AddTraceSource(
"MacTxOk",
121 "Trace source indicating a packet has been "
124 "ns3::Packet::TracedCallback")
125 .AddTraceSource(
"MacTxDrop",
126 "Trace source indicating a packet has been "
127 "dropped during transmission",
129 "ns3::Packet::TracedCallback")
130 .AddTraceSource(
"MacIndTxDrop",
131 "Trace source indicating a packet has been "
132 "dropped from the indirect transaction queue"
133 "(The pending transaction list)",
135 "ns3::Packet::TracedCallback")
136 .AddTraceSource(
"MacPromiscRx",
137 "A packet has been received by this device, "
138 "has been passed up from the physical layer "
139 "and is being forwarded up the local protocol stack. "
140 "This is a promiscuous trace,",
142 "ns3::Packet::TracedCallback")
143 .AddTraceSource(
"MacRx",
144 "A packet has been received by this device, "
145 "has been passed up from the physical layer "
146 "and is being forwarded up the local protocol stack. "
147 "This is a non-promiscuous trace,",
149 "ns3::Packet::TracedCallback")
150 .AddTraceSource(
"MacRxDrop",
151 "Trace source indicating a packet was received, "
152 "but dropped before being forwarded up the stack",
154 "ns3::Packet::TracedCallback")
155 .AddTraceSource(
"Sniffer",
156 "Trace source simulating a non-promiscuous "
157 "packet sniffer attached to the device",
159 "ns3::Packet::TracedCallback")
160 .AddTraceSource(
"PromiscSniffer",
161 "Trace source simulating a promiscuous "
162 "packet sniffer attached to the device",
164 "ns3::Packet::TracedCallback")
165 .AddTraceSource(
"MacStateValue",
166 "The state of LrWpan Mac",
168 "ns3::TracedValueCallback::LrWpanMacState")
169 .AddTraceSource(
"MacIncSuperframeStatus",
170 "The period status of the incoming superframe",
172 "ns3::TracedValueCallback::SuperframeState")
173 .AddTraceSource(
"MacOutSuperframeStatus",
174 "The period status of the outgoing superframe",
176 "ns3::TracedValueCallback::SuperframeState")
177 .AddTraceSource(
"MacState",
178 "The state of LrWpan Mac",
180 "ns3::lrwpan::LrWpanMac::StateTracedCallback")
181 .AddTraceSource(
"MacSentPkt",
182 "Trace source reporting some information about "
185 "ns3::lrwpan::LrWpanMac::SentTracedCallback")
186 .AddTraceSource(
"IfsEnd",
187 "Trace source reporting the end of an "
188 "Interframe space (IFS)",
190 "ns3::Packet::TracedCallback");
390 NS_LOG_ERROR(
this <<
" packet too big: " << p->GetSize());
401 NS_LOG_ERROR(
this <<
" Can not send packet with no Address field");
409 switch (params.m_srcAddrMode)
416 NS_ABORT_MSG(
"Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
427 NS_LOG_ERROR(
this <<
" Can not send packet with incorrect Source Address mode = "
428 << params.m_srcAddrMode);
436 switch (params.m_dstAddrMode)
443 NS_ABORT_MSG(
"Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
454 NS_LOG_ERROR(
this <<
" Can not send packet with incorrect Destination Address mode = "
455 << params.m_dstAddrMode);
488 NS_LOG_LOGIC(
"LrWpanMac::McpsDataRequest: requested an ACK on broadcast or "
489 "multicast destination ("
490 << shortAddr <<
") - forcefully removing it.");
525 p->AddHeader(macHdr);
534 p->AddTrailer(macTrailer);
536 NS_LOG_ERROR(
this <<
" Indirect transmissions not currently supported");
550 p->AddHeader(macHdr);
559 p->AddTrailer(macTrailer);
562 txQElement->txQMsduHandle = params.m_msduHandle;
563 txQElement->txQPkt = p;
588 if ((params.m_bcnOrd > 15) || (params.m_sfrmOrd > params.m_bcnOrd))
595 NS_LOG_ERROR(
this <<
"Incorrect superframe order or beacon order.");
615 confirmParams.
m_chPage = params.m_chPage;
624 NS_LOG_ERROR(
this <<
" A channel scan is already in progress");
635 NS_LOG_ERROR(
this <<
"Invalid scan duration or unsupported scan type");
664 pibAttr->phyCurrentPage = params.m_chPage;
678 bool invalidRequest =
false;
680 if (params.m_coordPanId == 0xffff)
682 invalidRequest =
true;
685 if (!invalidRequest && params.m_coordAddrMode ==
SHORT_ADDR)
690 invalidRequest =
true;
693 else if (!invalidRequest && params.m_coordAddrMode ==
EXT_ADDR)
695 if (params.m_coordExtAddr ==
Mac64Address(
"ff:ff:ff:ff:ff:ff:ff:ff") ||
696 params.m_coordExtAddr ==
Mac64Address(
"ff:ff:ff:ff:ff:ff:ff:ed"))
698 invalidRequest =
true;
706 NS_LOG_ERROR(
this <<
" Invalid PAN id in Association request");
718 pibAttr->phyCurrentPage = params.m_chPage;
772 commandPacket->AddHeader(macPayload);
773 commandPacket->AddHeader(macHdr);
779 macTrailer.
SetFcs(commandPacket);
782 commandPacket->AddTrailer(macTrailer);
816 if (params.m_assocMember)
830 commandPacket->AddHeader(macPayload);
831 commandPacket->AddHeader(macHdr);
837 macTrailer.
SetFcs(commandPacket);
840 commandPacket->AddTrailer(macTrailer);
843 txQElement->txQPkt = commandPacket;
854 auto symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
857 pibAttr->phyCurrentChannel = params.m_logCh;
863 uint64_t searchSymbols;
864 Time searchBeaconTime;
871 if (params.m_trackBcn)
877 searchBeaconTime =
Seconds((
double)searchSymbols / symbolRate);
951 pibAttr->phyCurrentChannel = attribute->pCurrentChannel;
957 pibAttr->phyCurrentPage = attribute->pCurrentPage;
969 confirmParams.
id = id;
1007 attributes->pCurrentChannel =
m_phy->GetCurrentChannelNum();
1010 attributes->pCurrentPage =
m_phy->GetCurrentPage();
1067 beaconPacket->AddHeader(macPayload);
1068 beaconPacket->AddHeader(macHdr);
1075 macTrailer.
SetFcs(beaconPacket);
1078 beaconPacket->AddTrailer(macTrailer);
1086 NS_LOG_DEBUG(
"Outgoing superframe Active Portion (Beacon + CAP + CFP): "
1098 txQElement->txQPkt = beaconPacket;
1128 commandPacket->AddHeader(macPayload);
1129 commandPacket->AddHeader(macHdr);
1135 macTrailer.
SetFcs(commandPacket);
1138 commandPacket->AddTrailer(macTrailer);
1141 txQElement->txQPkt = commandPacket;
1169 commandPacket->AddHeader(macPayload);
1170 commandPacket->AddHeader(macHdr);
1176 macTrailer.
SetFcs(commandPacket);
1179 commandPacket->AddTrailer(macTrailer);
1182 txQElement->txQPkt = commandPacket;
1218 commandPacket->AddHeader(macPayload);
1219 commandPacket->AddHeader(macHdr);
1225 macTrailer.
SetFcs(commandPacket);
1228 commandPacket->AddTrailer(macTrailer);
1231 txQElement->txQPkt = commandPacket;
1276 commandPacket->AddHeader(macPayload);
1277 commandPacket->AddHeader(macHdr);
1283 macTrailer.
SetFcs(commandPacket);
1286 commandPacket->AddTrailer(macTrailer);
1290 txQElement->txQPkt = commandPacket;
1299 rxDataReqPkt->RemoveHeader(receivedMacHdr);
1301 rxDataReqPkt->RemoveHeader(receivedMacPayload);
1311 txQElement->txQPkt = indTxQElement->txQPkt;
1316 NS_LOG_DEBUG(
"Requested element not found in pending list");
1347 NS_LOG_ERROR(
this <<
" Coordinator realignment request not supported");
1425 bool channelFound =
false;
1431 channelFound =
true;
1521 bool channelFound =
false;
1526 channelFound =
true;
1572 uint64_t capDuration;
1574 uint64_t symbolRate;
1576 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1583 endCapTime =
Seconds((
double)capDuration / symbolRate);
1587 NS_LOG_DEBUG(
"Outgoing superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1588 <<
" symbols (" << endCapTime.As(
Time::S)
1590 NS_LOG_DEBUG(
"Active Slots duration " << activeSlot <<
" symbols");
1600 endCapTime =
Seconds((
double)capDuration / symbolRate);
1604 NS_LOG_DEBUG(
"Incoming superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1605 <<
" symbols (" << endCapTime.As(
Time::S)
1607 NS_LOG_DEBUG(
"Active Slots duration " << activeSlot <<
" symbols");
1620 uint64_t cfpDuration;
1622 uint64_t symbolRate;
1624 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1630 endCfpTime =
Seconds((
double)cfpDuration / symbolRate);
1631 if (cfpDuration > 0)
1636 NS_LOG_DEBUG(
"Incoming superframe CFP duration " << cfpDuration <<
" symbols ("
1637 << endCfpTime.As(
Time::S) <<
")");
1648 endCfpTime =
Seconds((
double)cfpDuration / symbolRate);
1650 if (cfpDuration > 0)
1655 NS_LOG_DEBUG(
"Outgoing superframe CFP duration " << cfpDuration <<
" symbols ("
1656 << endCfpTime.As(
Time::S) <<
")");
1669 uint64_t inactiveDuration;
1670 Time endInactiveTime;
1671 uint64_t symbolRate;
1673 symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1678 endInactiveTime =
Seconds((
double)inactiveDuration / symbolRate);
1680 if (inactiveDuration > 0)
1685 NS_LOG_DEBUG(
"Incoming superframe Inactive Portion duration "
1686 << inactiveDuration <<
" symbols (" << endInactiveTime.
As(
Time::S) <<
")");
1692 endInactiveTime =
Seconds((
double)inactiveDuration / symbolRate);
1694 if (inactiveDuration > 0)
1699 NS_LOG_DEBUG(
"Outgoing superframe Inactive Portion duration "
1700 << inactiveDuration <<
" symbols (" << endInactiveTime.
As(
Time::S) <<
")");
1720 auto symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1738 uint64_t searchSymbols;
1739 Time searchBeaconTime;
1742 searchBeaconTime =
Seconds((
double)searchSymbols / symbolRate);
1757 (p->GetSize() *
m_phy->GetPhySymbolsPerOctet());
1760 auto symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
1763 NS_LOG_DEBUG(
"Beacon Received; forwarding up (m_macBeaconRxTime: "
1768 p->RemoveTrailer(receivedMacTrailer);
1771 p->RemoveHeader(receivedMacHdr);
1774 p->RemoveHeader(receivedMacPayload);
1823 m_csmaCa->SetBatteryLifeExtension(
true);
1827 m_csmaCa->SetBatteryLifeExtension(
false);
1850 NS_LOG_DEBUG(
this <<
" Device not associated, cannot process beacon");
1855 if (p->GetSize() > 0)
1864 beaconParams.
m_sdu = p;
1872 bool descriptorExists =
false;
1882 descriptor.m_coorPanId == panDescriptor.
m_coorPanId);
1888 descriptorExists = (descriptor.m_coorExtAddr == panDescriptor.
m_coorExtAddr &&
1889 descriptor.m_coorPanId == panDescriptor.
m_coorPanId);
1892 if (descriptorExists)
1898 if (!descriptorExists)
1915 uint64_t searchSymbols;
1916 Time searchBeaconTime;
1920 searchBeaconTime =
Seconds(
static_cast<double>(searchSymbols / symbolRate));
1946 beaconParams.
m_sdu = p;
1984 if (
m_csmaCa->GetBatteryLifeExtension())
2019 return pndAddrFields;
2058 auto symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
2065 p->RemoveTrailer(receivedMacTrailer);
2072 if (!receivedMacTrailer.
CheckFcs(p))
2079 p->RemoveHeader(receivedMacHdr);
2082 params.m_dsn = receivedMacHdr.
GetSeqNum();
2083 params.m_mpduLinkQuality = lqi;
2086 switch (params.m_srcAddrMode)
2099 switch (params.m_dstAddrMode)
2117 NS_LOG_DEBUG(
"Packet from [" << params.m_srcAddr <<
"] to [" << params.m_dstAddr
2123 NS_LOG_DEBUG(
"Packet from [" << params.m_srcExtAddr <<
"] to ["
2124 << params.m_dstExtAddr <<
"]");
2129 NS_LOG_DEBUG(
"Packet from [" << params.m_srcAddr <<
"] to [" << params.m_dstExtAddr
2135 NS_LOG_DEBUG(
"Packet from [" << params.m_srcExtAddr <<
"] to [" << params.m_dstAddr
2148 NS_LOG_ERROR(
this <<
" Data Indication Callback not initialized");
2158 acceptFrame = (receivedMacHdr.
GetFrameVer() <= 1);
2186 acceptFrame = !receivedMacHdr.
IsAckReq();
2190 acceptFrame =
false;
2203 acceptFrame =
false;
2210 acceptFrame =
false;
2216 acceptFrame =
false;
2226 p->PeekHeader(receivedMacPayload);
2232 acceptFrame =
false;
2242 ceil(6 *
m_phy->GetPhySymbolsPerOctet());
2243 Time ackTime =
Seconds((
double)ackSymbols / symbolRate);
2245 if (ackTime >= timeLeftInCap)
2247 NS_LOG_DEBUG(
"Command frame received but not enough time to transmit ACK "
2248 "before the end of CAP ");
2249 acceptFrame =
false;
2285 NS_LOG_DEBUG(
"Received a packet with ACK required while in CSMA. Cancel "
2295 m_rxPkt = originalPkt->Copy();
2300 p->PeekHeader(receivedMacPayload);
2304 NS_LOG_DEBUG(
"Data Request Command Received; processing ACK");
2307 NS_LOG_DEBUG(
"Association Request Command Received; processing ACK");
2311 NS_LOG_DEBUG(
"Association Response Command Received; processing ACK");
2325 NS_LOG_DEBUG(
"Packet from [" << params.m_srcAddr <<
"] to [" << params.m_dstAddr
2331 NS_LOG_DEBUG(
"Packet from [" << params.m_srcExtAddr <<
"] to ["
2332 << params.m_dstExtAddr <<
"]");
2337 NS_LOG_DEBUG(
"Packet from [" << params.m_srcAddr <<
"] to ["
2338 << params.m_dstExtAddr <<
"]");
2343 NS_LOG_DEBUG(
"Packet from [" << params.m_srcExtAddr <<
"] to ["
2344 << params.m_dstAddr <<
"]");
2356 p->PeekHeader(receivedMacPayload);
2454 pkt->RemoveHeader(macHdr);
2455 pkt->RemoveHeader(cmdPayload);
2460 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2504 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2550 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2608 ackPacket->AddHeader(macHdr);
2613 macTrailer.
SetFcs(ackPacket);
2615 ackPacket->AddTrailer(macTrailer);
2639 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2657 pkt->RemoveHeader(hdr);
2663 txQElement->txQPkt =
nullptr;
2664 txQElement =
nullptr;
2693 auto symbolRate = (uint64_t)
m_phy->GetDataOrSymbolRate(
false);
2697 if (ifsTime == lifsTime)
2702 else if (ifsTime == sifsTime)
2736 pkt->RemoveHeader(macHdr);
2737 pkt->RemoveHeader(cmdPayload);
2810 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
2833 p->PeekHeader(peekedMacHdr);
2846 indTxQElement->dstExtAddress = peekedMacHdr.
GetExtDstAddr();
2849 indTxQElement->seqNum = peekedMacHdr.
GetSeqNum();
2867 double symbolRate =
m_phy->GetDataOrSymbolRate(
false);
2870 indTxQElement->expireTime = expireTime;
2871 indTxQElement->txQPkt = p;
2880 indTxQElement->txQPkt->PeekHeader(peekedMacHdr);
2901 if ((*iter)->dstExtAddress == dst)
2938 else if (peekedMacHdr.
IsData())
2966 <<
" Sequence Number |"
2968 <<
" Expire time\n";
2972 transaction->txQPkt->PeekHeader(peekedMacHdr);
2973 os << transaction->dstExtAddress <<
" "
2974 <<
static_cast<uint32_t>(transaction->seqNum) <<
" ";
2978 os <<
" Command Frame ";
2980 else if (peekedMacHdr.
IsData())
2982 os <<
" Data Frame ";
2986 os <<
" Unknown Frame ";
2989 os << transaction->expireTime.As(
Time::S) <<
"\n";
3001 <<
" Sequence Number |"
3003 <<
" Frame type |\n";
3007 transaction->txQPkt->PeekHeader(peekedMacHdr);
3016 os <<
" Command Frame ";
3018 else if (peekedMacHdr.
IsData())
3020 os <<
" Data Frame ";
3024 os <<
" Unknown Frame ";
3037 m_csmaCa->AssignStreams(stream + 1);
3045 p->PeekHeader(peekedMacHdr);
3051 if (((*it)->dstExtAddress == peekedMacHdr.
GetExtDstAddr()) &&
3052 ((*it)->seqNum == peekedMacHdr.
GetSeqNum()))
3062 ((*it)->seqNum == peekedMacHdr.
GetSeqNum()))
3084 symbolRate =
m_phy->GetDataOrSymbolRate(
false);
3100 uint64_t beaconSymbols =
m_phy->GetPhySHRDuration() +
3101 1 *
m_phy->GetPhySymbolsPerOctet() +
3159 txOriginalPkt->RemoveHeader(txMacHdr);
3161 txOriginalPkt->RemoveHeader(txMacPayload);
3195 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
3211 recvOriginalPkt->RemoveHeader(receivedMacHdr);
3216 recvOriginalPkt->RemoveHeader(receivedMacPayload);
3304 confirmParams.
m_msduHandle = txQElement->txQMsduHandle;
3319 NS_FATAL_ERROR(
"Transmission attempt failed with PHY status " << status);
3322 if (!ifsWaitTime.
IsZero())
3353 m_phy->PlmeEdRequest();
3395 m_phy->PlmeEdRequest();
3425 bool channelFound =
false;
3430 channelFound =
true;
3454 NS_LOG_ERROR(
this <<
"Channel Scan: Invalid channel page");
3461 auto symbolRate =
static_cast<uint64_t
>(
m_phy->GetDataOrSymbolRate(
false));
3470 uint64_t scanDurationSym =
3473 nextScanTime =
Seconds(
static_cast<double>(scanDurationSym) / symbolRate);
3524 <<
" could not be set in the current page");
3561 NS_LOG_ERROR(
"Invalid channel parameter in MLME-start");
3590 NS_LOG_ERROR(
"Invalid page parameter in MLME-associate");
3618 NS_LOG_ERROR(
"Invalid channel parameter in MLME-associate");
3695 pkt->RemoveHeader(macHdr);
3700 pkt->RemoveHeader(cmdPayload);
3795 else if (macHdr.
IsData())
3834 NS_LOG_DEBUG(
"****** PACKET DEFERRED to the next superframe *****");
3886 ceil(6 *
m_phy->GetPhySymbolsPerOctet());
3926 NS_LOG_DEBUG(
"ERROR: Packet not for the coordinator!");
3963 return (
m_phy->GetPhySHRDuration() + 1 *
m_phy->GetPhySymbolsPerOctet() +
bool IsNull() const
Check for null implementation.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
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()
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.
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.
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 AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Implements the header for the MAC payload command frame according to the IEEE 802....
MacCommand GetCommandFrameType() const
Get the command frame type ID.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
uint16_t GetPanId() const
Get the PAN identifier.
void SetPage(uint8_t page)
Set the logical channel page number.
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
uint8_t GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
void SetCapabilityField(uint8_t cap)
Set the Capability Information Field to the command payload header (Association Request Command).
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ DATA_REQ
Data Request (RFD true: Tx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ BEACON_REQ
Beacon Request (RFD true: none )
void SetAssociationStatus(uint8_t status)
Set status resulting from the association attempt (Association Response Command).
uint8_t GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
void SetPanId(uint16_t id)
Get the PAN identifier.
void SetChannel(uint8_t channel)
Set the logical channel number.
Represent the GTS information fields.
bool GetGtsPermit() const
Get the GTS Specification Permit.
Lr-wpan MAC layer abstraction.
MlmeOrphanIndicationCallback m_mlmeOrphanIndicationCallback
This callback is used to indicate the reception of a orphan notification command.
MlmeGetConfirmCallback m_mlmeGetConfirmCallback
This callback is used to report the result of an attribute read request to the upper layers.
MlmeAssociateIndicationCallback m_mlmeAssociateIndicationCallback
This callback is used to indicate the reception of an association request command.
MlmeSetConfirmCallback m_mlmeSetConfirmCallback
This callback is used to report the result of an attribute writing request to the upper layers.
MlmePollConfirmCallback m_mlmePollConfirmCallback
This callback is used to report the status after a device send data command request to the coordinato...
MlmeCommStatusIndicationCallback m_mlmeCommStatusIndicationCallback
This callback is instigated through a response primitive.
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
MlmeScanConfirmCallback m_mlmeScanConfirmCallback
This callback is used to report the result of a scan on a group of channels for the selected channel ...
MlmeAssociateConfirmCallback m_mlmeAssociateConfirmCallback
This callback is used to report the status after a device request an association with a coordinator.
MlmeSyncLossIndicationCallback m_mlmeSyncLossIndicationCallback
This callback is used to indicate the loss of synchronization with a coordinator.
MlmeBeaconNotifyIndicationCallback m_mlmeBeaconNotifyIndicationCallback
This callback is used to notify incoming beacon packets to the upper layers.
MlmeStartConfirmCallback m_mlmeStartConfirmCallback
This callback is used to report the start of a new PAN or the begin of a new superframe configuration...
Class that implements the LR-WPAN MAC state machine.
Ptr< Packet > m_rxPkt
The command request packet received.
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
void RemovePendTxQElement(Ptr< Packet > p)
Remove an element from the pending transaction list.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
uint8_t m_deviceCapability
Indication of current device capability (FFD or RFD)
std::vector< uint8_t > m_macBeaconPayload
The set with the contents of the beacon payload.
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
TracedCallback< Ptr< const Packet > > m_macIndTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 indirect transmission queue (Pending ...
Ptr< LrWpanPhy > GetPhy()
Get the underlying PHY of the MAC.
uint32_t m_superframeDuration
Indication of the superframe duration in symbols.
void AwaitBeacon()
Called after the end of an INCOMING superframe to start the moment a device waits for a new incoming ...
void EndStartRequest()
Called to end a MLME-START.request after changing the page and channel number.
void MlmeAssociateResponse(MlmeAssociateResponseParams params) override
IEEE 802.15.4-2011, section 6.2.2.3 MLME-ASSOCIATE.response Primitive used to initiate a response to ...
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
MlmeStartRequestParams m_startParams
The parameters used during a MLME-START.request.
void PurgeInd()
Purge expired transactions from the pending transactions list.
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
EventId m_scanEvent
Scheduler event for the end of an ACTIVE or PASSIVE channel scan.
void PdDataConfirm(PhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
void SendOrphanNotificationCommand()
Called to send a orphan notification command.
Mac64Address m_macExtendedAddress
The extended 64 address (IEEE EUI-64) used by this MAC.
EventId m_scanEnergyEvent
Scheduler event for the end of a ED channel scan.
uint16_t m_macPanIdScan
Temporally stores the value of the current m_macPanId when a MLME-SCAN.request is performed.
EventId m_setMacState
Scheduler event for a deferred MAC state change.
uint32_t m_macBeaconPayloadLength
The length, in octets, of the beacon payload.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
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 ...
uint64_t m_assocRespCmdWaitTime
The maximum wait time for an association response command after the reception of data request command...
GtsFields GetGtsFields()
Constructs the Guaranteed Time Slots (GTS) Fields from local information.
void SetIndTxQMaxSize(uint32_t queueSize)
Set the max size of the indirect transmit queue (Pending Transaction list)
std::deque< Ptr< IndTxQueueElement > > m_indTxQueue
The indirect transmit queue used by the MAC pending messages (The pending transaction list).
uint8_t m_incomingSuperframeOrder
Used by all devices that have a parent.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
uint32_t m_macLIFSPeriod
The minimum time forming a Long InterFrame Spacing (LIFS) period.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
std::vector< uint8_t > m_unscannedChannels
The list of unscanned channels during a scan operation.
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
void PrintTransmitQueueSize()
Print the number of elements in the packet transmit queue.
uint16_t m_channelScanIndex
The channel list index used to obtain the current scanned channel.
void SendAssocRequestCommand()
Called to send an associate request command.
EventId m_beaconEvent
Scheduler event for generation of one beacon.
void BeaconSearchTimeout()
Called if the device is unable to locate a beacon in the time set by MLME-SYNC.request.
uint32_t m_macSIFSPeriod
The minimum time forming a Short InterFrame Spacing (SIFS) period.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
void MlmeSyncRequest(MlmeSyncRequestParams params) override
IEEE 802.15.4-2011, section 6.2.13.1 MLME-SYNC.request Request to synchronize with the coordinator by...
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
void ChangeMacState(MacState newState)
Change the current MAC state to the given new state.
Mac16Address m_macCoordShortAddress
The short address of the coordinator through which the device is associated.
Mac64Address GetCoordExtAddress() const
Get the coordinator extended address currently associated to this device.
void MlmeGetRequest(MacPibAttributeIdentifier id) override
IEEE 802.15.4-2006, section 7.1.6.1 MLME-GET.request Request information about a given PIB attribute.
std::deque< Ptr< TxQueueElement > > m_txQueue
The transmit queue used by the MAC.
uint8_t m_macSuperframeOrder
Used by a PAN coordinator or coordinator.
TracedValue< SuperframeStatus > m_incSuperframeStatus
The current period of the incoming superframe.
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
void MlmeStartRequest(MlmeStartRequestParams params) override
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
MlmeScanRequestParams m_scanParams
The parameters used during a MLME-SCAN.request.
void SetLrWpanMacState(MacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
uint8_t m_incomingBeaconOrder
The beaconOrder value of the INCOMING frame.
void PrintTxQueue(std::ostream &os) const
Print the Transmit Queue.
void CheckQueue()
Check the transmission queue.
uint32_t m_incomingSuperframeDuration
Indication of the superframe duration in symbols (e.g.
TracedCallback< Ptr< const Packet > > m_macIndTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
uint16_t m_macTransactionPersistenceTime
The maximum time (in UNIT periods) that a transaction is stored by a coordinator and indicated in its...
void MlmeOrphanResponse(MlmeOrphanResponseParams params) override
IEEE 802.15.4-2011, section 6.2.7.2 MLME-ORPHAN.response Primitive used to initiatte a response to an...
void AckWaitTimeout()
Handle an ACK timeout with a packet retransmission, if there are retransmission left,...
uint32_t m_maxTxQueueSize
The maximum size of the transmit queue.
TracedCallback< Ptr< const Packet > > m_macIndTxDropTrace
The trace source fired when packets are dropped due to indirect Tx queue overflows or expiration.
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
LrWpanMac()
Default constructor.
EventId m_incCfpEvent
Scheduler event for the end of the incoming superframe CFP.
std::vector< uint8_t > m_energyDetectList
The list of energy measurements, one for each channel searched during an ED scan.
SequenceNumber8 m_macBsn
Sequence number added to transmitted beacon frame, 00-ff.
TracedCallback< MacState, MacState > m_macStateLogger
A trace source that fires when the MAC changes states.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Mac64Address GetExtendedAddress() const
Get the extended address of this MAC.
void DoDispose() override
Destructor implementation.
uint8_t m_fnlCapSlot
Indication of the Slot where the CAP portion of the OUTGOING Superframe ends.
MlmeAssociateRequestParams m_associateParams
The parameters used during a MLME-ASSOCIATE.request.
uint32_t m_incomingBeaconInterval
Indication of the interval a node should receive a superframe expressed in symbols.
bool m_macAssociationPermit
Indication of whether a coordinator is currently allowing association.
static TypeId GetTypeId()
Get the type ID.
uint64_t GetMacAckWaitDuration() const
Get the macAckWaitDuration attribute value.
void SetTxQMaxSize(uint32_t queueSize)
Set the max size of the transmit queue.
TracedCallback< Time > m_macIfsEndTrace
The trace source is fired at the end of any Interframe Space (IFS).
void MlmeAssociateRequest(MlmeAssociateRequestParams params) override
IEEE 802.15.4-2011, section 6.2.2.1 MLME-ASSOCIATE.request Request primitive used by a device to requ...
bool GetRxOnWhenIdle() const
Check if the receiver will be enabled when the MAC is idle.
void ReceiveBeacon(uint8_t lqi, Ptr< Packet > p)
Used to process the reception of a beacon packet.
void EnqueueInd(Ptr< Packet > p)
Adds a packet to the pending transactions list (Indirect transmissions).
Time m_macBeaconTxTime
The time that the device transmitted its last beacon frame.
std::vector< PanDescriptor > m_panDescriptorList
The list of PAN descriptors accumulated during channel scans, used to select a PAN to associate.
uint8_t m_maxEnergyLevel
The maximum energy level detected during ED scan on the current channel.
Mac16Address GetShortAddress() const
Get the short address of this MAC.
bool m_macAutoRequest
Indication of whether a device automatically sends data request command if its address is listed in t...
PendingAddrFields GetPendingAddrFields()
Constructs Pending Address Fields from the local information, the Pending Address Fields are part of ...
uint64_t m_rxBeaconSymbols
The total size of the received beacon in symbols.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
EventId m_cfpEvent
Scheduler event for the end of the outgoing superframe CFP.
uint16_t GetPanId() const
Get the PAN id used by this MAC.
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
bool m_panCoor
Indication of whether the current device is the PAN coordinator.
void SendAssocResponseCommand(Ptr< Packet > rxDataReqPkt)
Called to send an associate response command.
Time m_macBeaconRxTime
The time that the device received its last bit of the beacon frame.
void SetAssociatedCoor(Mac16Address mac)
Check if the packet destination is its coordinator.
void StartCFP(SuperframeType superframeType)
Called to begin the Contention Free Period (CFP) in a beacon-enabled mode.
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
bool PrepareRetransmission()
Check for remaining retransmissions for the packet currently being sent.
void PrintPendingTxQueue(std::ostream &os) const
Print the Pending transaction list.
uint32_t m_ifs
The value of the necessary InterFrame Space after the transmission of a packet.
void MlmeSetRequest(MacPibAttributeIdentifier id, Ptr< MacPibAttributes > attribute) override
IEEE 802.15.4-2011, section 6.2.11.1 MLME-SET.request Attempts to write the given value to the indica...
bool m_beaconTrackingOn
Indication of whether the current device is tracking incoming beacons.
void SendBeaconRequestCommand()
Called to send a beacon request command.
uint32_t m_maxIndTxQueueSize
The maximum size of the indirect transmit queue (The pending transaction list).
void IfsWaitTimeout(Time ifsTime)
After a successful transmission of a frame (beacon, data) or an ack frame reception,...
EventId m_ifsEvent
Scheduler event for Interframe spacing wait time.
void MlmeScanRequest(MlmeScanRequestParams params) override
IEEE 802.15.4-2011, section 6.2.10.1 MLME-SCAN.request Request primitive used to initiate a channel s...
Ptr< UniformRandomVariable > m_uniformVar
The uniform random variable used in this mac layer.
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...