A Discrete-Event Network Simulator
API
lr-wpan-mac.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors:
19  * Gary Pei <guangyu.pei@boeing.com>
20  * kwong yin <kwong-sang.yin@boeing.com>
21  * Tom Henderson <thomas.r.henderson@boeing.com>
22  * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
23  */
24 #ifndef LR_WPAN_MAC_H
25 #define LR_WPAN_MAC_H
26 
27 #include <ns3/object.h>
28 #include <ns3/traced-callback.h>
29 #include <ns3/mac16-address.h>
30 #include <ns3/mac64-address.h>
31 #include <ns3/sequence-number.h>
32 #include <ns3/lr-wpan-phy.h>
33 #include <ns3/event-id.h>
34 #include <deque>
35 
36 
37 namespace ns3 {
38 
39 class Packet;
40 class LrWpanCsmaCa;
41 
53 typedef enum
54 {
60 
66 typedef enum
67 {
76 
82 typedef enum
83 {
89 
95 typedef enum
96 {
103 
109 typedef enum
110 {
124 
125 
132 {
136  m_dstPanId (0),
137  m_dstAddr (),
138  m_msduHandle (0),
139  m_txOptions (0)
140  {
141  }
144  uint16_t m_dstPanId;
146  uint8_t m_msduHandle;
147  uint8_t m_txOptions;
148 };
149 
156 {
157  uint8_t m_msduHandle;
159 };
160 
167 {
168  uint8_t m_srcAddrMode;
169  uint16_t m_srcPanId;
171  uint8_t m_dstAddrMode;
172  uint16_t m_dstPanId;
175  uint8_t m_dsn;
176 };
177 
186 
197 
198 
204 class LrWpanMac : public Object
205 {
206 public:
212  static TypeId GetTypeId (void);
213 
218  static const uint32_t aMinMPDUOverhead;
219 
223  LrWpanMac (void);
224  virtual ~LrWpanMac (void);
225 
231  bool GetRxOnWhenIdle (void);
232 
238  void SetRxOnWhenIdle (bool rxOnWhenIdle);
239 
240  // XXX these setters will become obsolete if we use the attribute system
247 
253  Mac16Address GetShortAddress (void) const;
254 
261 
267  Mac64Address GetExtendedAddress (void) const;
268 
274  void SetPanId (uint16_t panId);
275 
281  uint16_t GetPanId (void) const;
282 
292 
298  void SetCsmaCa (Ptr<LrWpanCsmaCa> csmaCa);
299 
305  void SetPhy (Ptr<LrWpanPhy> phy);
306 
312  Ptr<LrWpanPhy> GetPhy (void);
313 
321  void SetMcpsDataIndicationCallback (McpsDataIndicationCallback c);
322 
330  void SetMcpsDataConfirmCallback (McpsDataConfirmCallback c);
331 
332  // interfaces between MAC and PHY
341  void PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi);
342 
349  void PdDataConfirm (LrWpanPhyEnumeration status);
350 
356  void PlmeCcaConfirm (LrWpanPhyEnumeration status);
357 
364  void PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel);
365 
376  LrWpanPhyPibAttributes* attribute);
377 
385 
395 
401  void SetLrWpanMacState (LrWpanMacState macState);
402 
409 
416 
417  //MAC sublayer constants
424 
430 
437 
438  //MAC PIB attributes
445 
451 
458 
466 
473 
479  uint16_t m_macPanId;
480 
486 
492 
499 
505  uint64_t GetMacAckWaitDuration (void) const;
506 
512  uint8_t GetMacMaxFrameRetries (void) const;
513 
519  void SetMacMaxFrameRetries (uint8_t retries);
520 
528  typedef void (* SentTracedCallback)
529  (const Ptr<const Packet> packet, const uint8_t retries,
530  const uint8_t backoffs);
531 
538  typedef void (* StateTracedCallback)
539  (const LrWpanMacState oldState, const LrWpanMacState newState);
540 
541 protected:
542  // Inherited from Object.
543  virtual void DoInitialize (void);
544  virtual void DoDispose (void);
545 
546 private:
551  {
552  uint8_t txQMsduHandle;
554  };
555 
561  void SendAck (uint8_t seqno);
562 
567  void RemoveFirstTxQElement ();
568 
574  void ChangeMacState (LrWpanMacState newState);
575 
580  void AckWaitTimeout (void);
581 
588  bool PrepareRetransmission (void);
589 
595  void CheckQueue (void);
596 
608 
616 
624 
631 
640 
648 
657 
666 
675 
695 
715 
723 
728 
733 
738  McpsDataIndicationCallback m_mcpsDataIndicationCallback;
739 
745  McpsDataConfirmCallback m_mcpsDataConfirmCallback;
746 
751 
756 
760  Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet
761 
768 
774 
778  std::deque<TxQueueElement*> m_txQueue;
779 
785 
790 
796 
801 };
802 
803 
804 } // namespace ns3
805 
806 #endif /* LR_WPAN_MAC_H */
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:144
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:58
uint64_t m_aBaseSuperframeDuration
Length of a superframe in symbols.
Definition: lr-wpan-mac.h:436
void CheckQueue(void)
Check the transmission queue.
Definition: lr-wpan-mac.cc:419
Class that implements the LR-WPAN Mac state machine.
Definition: lr-wpan-mac.h:204
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...
Definition: lr-wpan-mac.cc:875
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:145
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission...
Definition: lr-wpan-mac.cc:707
virtual ~LrWpanMac(void)
Definition: lr-wpan-mac.cc:150
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
Definition: lr-wpan-mac.h:639
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:126
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
Definition: lr-wpan-mac.cc:988
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:73
Forward calls to a chain of Callback.
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
Definition: lr-wpan-mac.h:745
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:778
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:173
uint8_t m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:171
LrWpanMacState m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:750
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:755
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-mac.cc:170
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:722
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:217
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:143
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:738
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:457
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. ...
Definition: lr-wpan-mac.cc:245
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:789
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:146
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:157
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:172
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:630
an EUI-64 address
Definition: mac64-address.h:43
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
Definition: lr-wpan-mac.h:760
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:192
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Definition: lr-wpan-mac.cc:928
uint64_t m_macBeaconOrder
Specification of how often the coordinator transmits its beacon.
Definition: lr-wpan-mac.h:457
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:239
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.
Definition: lr-wpan-mac.cc:868
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
Definition: lr-wpan-mac.h:714
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:56
TracedCallback< Ptr< const Packet > > m_macTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
Definition: lr-wpan-mac.h:615
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:665
uint64_t m_macSyncSymbolOffset
Symbol boundary is same as m_macBeaconTxTime.
Definition: lr-wpan-mac.h:450
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:553
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
Definition: lr-wpan-mac.cc:749
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Definition: lr-wpan-mac.cc:860
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h:795
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
Definition: lr-wpan-mac.h:647
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:800
LrWpanMcpsDataConfirmStatus
Table 42 of 802.15.4-2006.
Definition: lr-wpan-mac.h:109
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:550
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:498
uint64_t m_macBeaconTxTime
The time that the device transmitted its last beacon frame, in symbol periods.
Definition: lr-wpan-mac.h:444
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:155
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
Definition: lr-wpan-mac.cc:779
uint8_t m_txOptions
Tx Options (bitfield)
Definition: lr-wpan-mac.h:147
SET_PHY_TX_ON.
Definition: lr-wpan-mac.h:74
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
Definition: lr-wpan-mac.h:174
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Definition: lr-wpan-mac.cc:439
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 ...
Definition: lr-wpan-mac.h:607
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...
Definition: lr-wpan-mac.cc:463
uint8_t m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:168
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:158
LrWpanAddressMode m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:142
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:784
Callback< void, McpsDataIndicationParams, Ptr< Packet > > McpsDataIndicationCallback
This callback is called after a Mcps has successfully received a frame and wants to deliver it to the...
Definition: lr-wpan-mac.h:196
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:773
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LrWpanAddressMode m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:143
LrWpanAddressMode
table 80 of 802.15.4
Definition: lr-wpan-mac.h:82
uint64_t m_macSuperframeOrder
The length of the active portion of the outgoing superframe, including the beacon frame...
Definition: lr-wpan-mac.h:465
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Definition: lr-wpan-mac.h:674
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:57
Callback< void, McpsDataConfirmParams > McpsDataConfirmCallback
This callback is called after a McpsDataRequest has been called from the higher layer.
Definition: lr-wpan-mac.h:185
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:198
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:656
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:472
Mac16Address m_srcAddr
Source address.
Definition: lr-wpan-mac.h:170
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
uint8_t m_dsn
The DSN of the received data frame.
Definition: lr-wpan-mac.h:175
LrWpanMac(void)
Default constructor.
Definition: lr-wpan-mac.cc:126
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Definition: lr-wpan-mac.h:694
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:224
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:491
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:552
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-mac.cc:50
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
Definition: lr-wpan-mac.h:727
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:72
MAC_CSMA.
Definition: lr-wpan-mac.h:69
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:485
An identifier for simulation events.
Definition: event-id.h:53
void(* StateTracedCallback)(const LrWpanMacState oldState, const LrWpanMacState newState)
TracedCallback signature for LrWpanMacState change events.
Definition: lr-wpan-mac.h:539
uint64_t m_aNumSuperframeSlots
Number of a superframe slots per superframe.
Definition: lr-wpan-mac.h:429
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:71
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:218
LrWpanTxOption
Tx options.
Definition: lr-wpan-mac.h:53
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
uint8_t GetMacMaxFrameRetries(void) const
Get the macMaxFrameRetries attribute value.
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
Definition: lr-wpan-mac.h:732
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:66
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:95
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:232
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
Definition: lr-wpan-mac.h:623
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:479
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
Definition: lr-wpan-mac.cc:883
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:104
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
Definition: lr-wpan-mac.cc:678
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:131
A base class which provides memory management and object aggregation.
Definition: object.h:87
tuple address
Definition: first.py:37
uint16_t GetPanId(void) const
Get the PAN id used by this MAC.
void AckWaitTimeout(void)
Handle an ACK timeout with a packet retransmission, if there are retransmission left, or a packet drop.
Definition: lr-wpan-mac.cc:731
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Definition: lr-wpan-mac.cc:445
Mac16Address m_shortAddress
The short address used by this MAC.
Definition: lr-wpan-mac.h:767
TX_OPTION_NONE.
Definition: lr-wpan-mac.h:55
a unique identifier for an interface.
Definition: type-id.h:51
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
Definition: lr-wpan-mac.cc:433
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...
Definition: lr-wpan-mac.cc:921
virtual void DoInitialize(void)
Initialize() implementation.
Definition: lr-wpan-mac.cc:155
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
MAC_SENDING.
Definition: lr-wpan-mac.h:70
uint64_t m_aBaseSlotDuration
Length of a superframe slot in symbols.
Definition: lr-wpan-mac.h:423
void(* SentTracedCallback)(const Ptr< const Packet > packet, const uint8_t retries, const uint8_t backoffs)
TracedCallback signature for sent packets.
Definition: lr-wpan-mac.h:529
uint16_t m_srcPanId
Source PAN identifier.
Definition: lr-wpan-mac.h:169
MAC_IDLE.
Definition: lr-wpan-mac.h:68
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
Definition: lr-wpan-mac.cc:994
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:166
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:451