29 #include <ns3/simulator.h> 31 #include <ns3/uinteger.h> 33 #include <ns3/packet.h> 34 #include <ns3/random-variable-stream.h> 35 #include <ns3/double.h> 37 #undef NS_LOG_APPEND_CONTEXT 38 #define NS_LOG_APPEND_CONTEXT \ 39 std::clog << "[address " << m_shortAddress << "] "; 54 .SetGroupName (
"LrWpan")
56 .AddAttribute (
"PanId",
"16-bit identifier of the associated PAN",
59 MakeUintegerChecker<uint16_t> ())
60 .AddTraceSource (
"MacTxEnqueue",
61 "Trace source indicating a packet has been " 62 "enqueued in the transaction queue",
64 "ns3::Packet::TracedCallback")
65 .AddTraceSource (
"MacTxDequeue",
66 "Trace source indicating a packet has was " 67 "dequeued from the transaction queue",
69 "ns3::Packet::TracedCallback")
70 .AddTraceSource (
"MacTx",
71 "Trace source indicating a packet has " 72 "arrived for transmission by this device",
74 "ns3::Packet::TracedCallback")
75 .AddTraceSource (
"MacTxOk",
76 "Trace source indicating a packet has been " 79 "ns3::Packet::TracedCallback")
80 .AddTraceSource (
"MacTxDrop",
81 "Trace source indicating a packet has been " 82 "dropped during transmission",
84 "ns3::Packet::TracedCallback")
85 .AddTraceSource (
"MacPromiscRx",
86 "A packet has been received by this device, " 87 "has been passed up from the physical layer " 88 "and is being forwarded up the local protocol stack. " 89 "This is a promiscuous trace,",
91 "ns3::Packet::TracedCallback")
92 .AddTraceSource (
"MacRx",
93 "A packet has been received by this device, " 94 "has been passed up from the physical layer " 95 "and is being forwarded up the local protocol stack. " 96 "This is a non-promiscuous trace,",
98 "ns3::Packet::TracedCallback")
99 .AddTraceSource (
"MacRxDrop",
100 "Trace source indicating a packet was received, " 101 "but dropped before being forwarded up the stack",
103 "ns3::Packet::TracedCallback")
104 .AddTraceSource (
"Sniffer",
105 "Trace source simulating a non-promiscuous " 106 "packet sniffer attached to the device",
108 "ns3::Packet::TracedCallback")
109 .AddTraceSource (
"PromiscSniffer",
110 "Trace source simulating a promiscuous " 111 "packet sniffer attached to the device",
113 "ns3::Packet::TracedCallback")
114 .AddTraceSource (
"MacStateValue",
115 "The state of LrWpan Mac",
117 "ns3::TracedValueCallback::LrWpanMacState")
118 .AddTraceSource (
"MacState",
119 "The state of LrWpan Mac",
121 "ns3::LrWpanMac::StateTracedCallback")
122 .AddTraceSource (
"MacSentPkt",
123 "Trace source reporting some information about " 126 "ns3::LrWpanMac::SentTracedCallback")
183 for (uint32_t i = 0; i <
m_txQueue.size (); i++)
281 NS_LOG_ERROR (
this <<
" Can not send packet with no Address field" );
293 macHdr.SetNoPanIdComp ();
296 NS_ABORT_MSG (
"Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
319 macHdr.SetNoPanIdComp ();
322 NS_ABORT_MSG (
"Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
342 macHdr.SetSecDisable ();
350 if (!(macHdr.GetDstAddrMode () ==
SHORT_ADDR && macHdr.GetShortDstAddr () ==
"ff:ff"))
357 macHdr.SetNoAckReq ();
362 NS_LOG_ERROR (
this <<
"Incorrect TxOptions bit 0 not 0/1");
383 NS_LOG_ERROR (
this <<
"Incorrect TxOptions bit 1 not 0/1");
396 NS_LOG_ERROR (
this <<
"for non-beacon-enables PAN, bit 1 should always be set to 0");
416 NS_LOG_ERROR (
this <<
"Incorrect TxOptions bit 2 not 0/1");
524 if (!receivedMacTrailer.
CheckFcs (p))
577 NS_LOG_ERROR (
this <<
" Data Indication Callback not initialised");
587 acceptFrame = (receivedMacHdr.
GetFrameVer () <= 1);
669 NS_LOG_DEBUG (
"PdDataIndication(): Packet is for me; forwarding up");
735 macTrailer.
SetFcs (ackPacket);
831 if (!macHdr.IsAcknowledgment ())
835 if (macHdr.IsAckReq ())
871 if (!macHdr.IsAcknowledgment ())
894 NS_FATAL_ERROR (
"Transmission attempt failed with PHY status " << status);
1066 return m_csmaCa->GetUnitBackoffPeriod () +
m_phy->aTurnaroundTime +
m_phy->GetPhySHRDuration ()
1067 + ceil (6 *
m_phy->GetPhySymbolsPerOctet ());
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
uint16_t m_dstPanId
Destination PAN identifier.
virtual void DoInitialize(void)
Initialize() implementation.
Simulation virtual time values and global simulation resolution.
void CheckQueue(void)
Check the transmission queue.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Class that implements the LR-WPAN Mac state machine.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, LrWpanPhyPibAttributes *attribute)
IEEE 802.15.4-2006 section 6.2.2.6 PLME-GET.confirm Get attributes per definition from Table 23 in se...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Mac16Address m_dstAddr
Destination address.
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission...
Mac64Address m_srcExtAddr
Source extended address.
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
static bool ChecksumEnabled(void)
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Mac16Address m_dstAddr
Destination address.
uint8_t m_dstAddrMode
Destination address mode.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Mac64Address m_dstExtAddr
Destination extended address.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Mac64Address m_dstExtAddr
Destination extended address.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Destructor implementation.
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
virtual void DoDispose(void)
Destructor implementation.
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
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. ...
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
uint8_t m_msduHandle
MSDU handle.
uint8_t m_msduHandle
MSDU handle.
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
uint16_t m_dstPanId
Destination PAN identifier.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
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_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
TracedCallback< Ptr< const Packet > > m_macTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Ptr< Packet > txQPkt
Queued packet.
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Hold an unsigned integer type.
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
uint16_t GetPanId(void) const
Get the PAN id used by this MAC.
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Helper structure for managing transmission queue elements.
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
MCPS-DATA.confirm params.
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_txOptions
Tx Options (bitfield)
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
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 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...
uint8_t m_srcAddrMode
Source address mode.
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
LrWpanAddressMode m_srcAddrMode
Source address mode.
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Mac64Address m_selfExt
The extended address used by this MAC.
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LrWpanAddressMode m_dstAddrMode
Destination address mode.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Mac16Address m_srcAddr
Source address.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
This class can contain 16 bit addresses.
uint8_t m_dsn
The DSN of the received data frame.
LrWpanMac(void)
Default constructor.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
uint8_t txQMsduHandle
MSDU Handle.
static TypeId GetTypeId(void)
Get the type ID.
Represent the Mac Trailer with the Frame Check Sequence field.
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
LrWpanMacState
MAC states.
LrWpanAssociationStatus
table 83 of 802.15.4
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
uint8_t GetMacMaxFrameRetries(void) const
Get the macMaxFrameRetries attribute value.
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
SequenceNumber< uint8_t, int8_t > SequenceNumber8
8 bit Sequence number.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
MCPS-DATA.request params.
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
A base class which provides memory management and object aggregation.
void AckWaitTimeout(void)
Handle an ACK timeout with a packet retransmission, if there are retransmission left, or a packet drop.
bool IsNull(void) const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Mac16Address m_shortAddress
The short address used by this MAC.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
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...
virtual void DoInitialize(void)
Initialize() implementation.
static Mac64Address Allocate(void)
Allocate a new Mac64Address.
void AddHeader(const Header &header)
Add header to this packet.
uint16_t m_srcPanId
Source PAN identifier.
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
MCPS-DATA.indication params.
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.