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/traced-value.h>
30 #include <ns3/mac16-address.h>
31 #include <ns3/mac64-address.h>
32 #include <ns3/sequence-number.h>
33 #include <ns3/lr-wpan-phy.h>
34 #include <ns3/event-id.h>
35 #include <deque>
36 
37 
38 namespace ns3 {
39 
40 class Packet;
41 class LrWpanCsmaCa;
42 
54 typedef enum
55 {
61 
67 typedef enum
68 {
77 
78 namespace TracedValueCallback {
79 
87  typedef void (* LrWpanMacState)(LrWpanMacState oldValue,
88  LrWpanMacState newValue);
89 
90 } // namespace TracedValueCallback
91 
97 typedef enum
98 {
104 
110 typedef enum
111 {
118 
124 typedef enum
125 {
139 
140 
147 {
151  m_dstPanId (0),
152  m_dstAddr (),
153  m_msduHandle (0),
154  m_txOptions (0)
155  {
156  }
159  uint16_t m_dstPanId;
161  uint8_t m_msduHandle;
162  uint8_t m_txOptions;
163 };
164 
171 {
172  uint8_t m_msduHandle;
174 };
175 
182 {
183  uint8_t m_srcAddrMode;
184  uint16_t m_srcPanId;
186  uint8_t m_dstAddrMode;
187  uint16_t m_dstPanId;
190  uint8_t m_dsn;
191 };
192 
201 
212 
213 
219 class LrWpanMac : public Object
220 {
221 public:
227  static TypeId GetTypeId (void);
228 
233  static const uint32_t aMinMPDUOverhead;
234 
238  LrWpanMac (void);
239  virtual ~LrWpanMac (void);
240 
246  bool GetRxOnWhenIdle (void);
247 
253  void SetRxOnWhenIdle (bool rxOnWhenIdle);
254 
255  // XXX these setters will become obsolete if we use the attribute system
262 
268  Mac16Address GetShortAddress (void) const;
269 
276 
282  Mac64Address GetExtendedAddress (void) const;
283 
289  void SetPanId (uint16_t panId);
290 
296  uint16_t GetPanId (void) const;
297 
307 
313  void SetCsmaCa (Ptr<LrWpanCsmaCa> csmaCa);
314 
320  void SetPhy (Ptr<LrWpanPhy> phy);
321 
327  Ptr<LrWpanPhy> GetPhy (void);
328 
336  void SetMcpsDataIndicationCallback (McpsDataIndicationCallback c);
337 
345  void SetMcpsDataConfirmCallback (McpsDataConfirmCallback c);
346 
347  // interfaces between MAC and PHY
356  void PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi);
357 
364  void PdDataConfirm (LrWpanPhyEnumeration status);
365 
371  void PlmeCcaConfirm (LrWpanPhyEnumeration status);
372 
379  void PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel);
380 
391  LrWpanPhyPibAttributes* attribute);
392 
400 
410 
416  void SetLrWpanMacState (LrWpanMacState macState);
417 
424 
431 
432  //MAC sublayer constants
439 
445 
452 
453  //MAC PIB attributes
460 
466 
473 
481 
488 
494  uint16_t m_macPanId;
495 
501 
507 
514 
520  uint64_t GetMacAckWaitDuration (void) const;
521 
527  uint8_t GetMacMaxFrameRetries (void) const;
528 
534  void SetMacMaxFrameRetries (uint8_t retries);
535 
543  typedef void (* SentTracedCallback)
544  (Ptr<const Packet> packet, uint8_t retries, uint8_t backoffs);
545 
555  typedef void (* StateTracedCallback)
556  (LrWpanMacState oldState, LrWpanMacState newState);
557 
558 protected:
559  // Inherited from Object.
560  virtual void DoInitialize (void);
561  virtual void DoDispose (void);
562 
563 private:
568  {
569  uint8_t txQMsduHandle;
571  };
572 
578  void SendAck (uint8_t seqno);
579 
584  void RemoveFirstTxQElement ();
585 
591  void ChangeMacState (LrWpanMacState newState);
592 
597  void AckWaitTimeout (void);
598 
605  bool PrepareRetransmission (void);
606 
612  void CheckQueue (void);
613 
625 
633 
641 
648 
657 
665 
674 
683 
692 
712 
732 
742 
747 
752 
757  McpsDataIndicationCallback m_mcpsDataIndicationCallback;
758 
764  McpsDataConfirmCallback m_mcpsDataConfirmCallback;
765 
770 
775 
779  Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet
780 
787 
793 
797  std::deque<TxQueueElement*> m_txQueue;
798 
804 
809 
815 
820 };
821 
822 
823 } // namespace ns3
824 
825 #endif /* LR_WPAN_MAC_H */
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:769
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:159
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:59
uint64_t m_aBaseSuperframeDuration
Length of a superframe in symbols.
Definition: lr-wpan-mac.h:451
void CheckQueue(void)
Check the transmission queue.
Definition: lr-wpan-mac.cc:424
Class that implements the LR-WPAN Mac state machine.
Definition: lr-wpan-mac.h:219
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:880
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:160
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission...
Definition: lr-wpan-mac.cc:712
virtual ~LrWpanMac(void)
Definition: lr-wpan-mac.cc:155
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:656
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:140
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
Definition: lr-wpan-mac.cc:993
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:74
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:764
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:797
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:188
uint8_t m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:186
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:774
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-mac.cc:175
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:741
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:222
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:157
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:757
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:462
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:250
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:808
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:161
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:172
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:187
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:647
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:779
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:197
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Definition: lr-wpan-mac.cc:933
uint64_t m_macBeaconOrder
Specification of how often the coordinator transmits its beacon.
Definition: lr-wpan-mac.h:472
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:244
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:873
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:731
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:57
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:632
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:682
tuple phy
Definition: third.py:86
uint64_t m_macSyncSymbolOffset
Symbol boundary is same as m_macBeaconTxTime.
Definition: lr-wpan-mac.h:465
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:570
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
Definition: lr-wpan-mac.cc:754
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Definition: lr-wpan-mac.cc:865
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h:814
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:664
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:819
LrWpanMcpsDataConfirmStatus
Table 42 of 802.15.4-2006.
Definition: lr-wpan-mac.h:124
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:567
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:513
uint64_t m_macBeaconTxTime
The time that the device transmitted its last beacon frame, in symbol periods.
Definition: lr-wpan-mac.h:459
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:170
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:784
uint8_t m_txOptions
Tx Options (bitfield)
Definition: lr-wpan-mac.h:162
SET_PHY_TX_ON.
Definition: lr-wpan-mac.h:75
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
Definition: lr-wpan-mac.h:189
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Definition: lr-wpan-mac.cc:444
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:624
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:468
uint8_t m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:183
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:173
LrWpanAddressMode m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:157
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:803
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:211
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:792
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LrWpanAddressMode m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:158
LrWpanAddressMode
table 80 of 802.15.4
Definition: lr-wpan-mac.h:97
uint64_t m_macSuperframeOrder
The length of the active portion of the outgoing superframe, including the beacon frame...
Definition: lr-wpan-mac.h:480
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:691
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:58
Callback< void, McpsDataConfirmParams > McpsDataConfirmCallback
This callback is called after a McpsDataRequest has been called from the higher layer.
Definition: lr-wpan-mac.h:200
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:203
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:673
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:487
Mac16Address m_srcAddr
Source address.
Definition: lr-wpan-mac.h:185
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:190
LrWpanMac(void)
Default constructor.
Definition: lr-wpan-mac.cc:131
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:711
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:229
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:506
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:569
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:746
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:73
MAC_CSMA.
Definition: lr-wpan-mac.h:70
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:500
An identifier for simulation events.
Definition: event-id.h:53
uint64_t m_aNumSuperframeSlots
Number of a superframe slots per superframe.
Definition: lr-wpan-mac.h:444
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:72
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:233
LrWpanTxOption
Tx options.
Definition: lr-wpan-mac.h:54
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:751
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:67
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:110
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:237
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:640
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:494
void(* StateTracedCallback)(LrWpanMacState oldState, LrWpanMacState newState)
TracedCallback signature for LrWpanMacState change events.
Definition: lr-wpan-mac.h:556
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:888
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:105
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
Definition: lr-wpan-mac.cc:683
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:146
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:736
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Definition: lr-wpan-mac.cc:450
Mac16Address m_shortAddress
The short address used by this MAC.
Definition: lr-wpan-mac.h:786
TX_OPTION_NONE.
Definition: lr-wpan-mac.h:56
a unique identifier for an interface.
Definition: type-id.h:58
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
Definition: lr-wpan-mac.cc:438
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:926
virtual void DoInitialize(void)
Initialize() implementation.
Definition: lr-wpan-mac.cc:160
void(* SentTracedCallback)(Ptr< const Packet > packet, uint8_t retries, uint8_t backoffs)
TracedCallback signature for sent packets.
Definition: lr-wpan-mac.h:544
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
MAC_SENDING.
Definition: lr-wpan-mac.h:71
uint64_t m_aBaseSlotDuration
Length of a superframe slot in symbols.
Definition: lr-wpan-mac.h:438
uint16_t m_srcPanId
Source PAN identifier.
Definition: lr-wpan-mac.h:184
MAC_IDLE.
Definition: lr-wpan-mac.h:69
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
Definition: lr-wpan-mac.cc:999
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:181
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:456