A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
51 typedef enum
52 {
58 
62 typedef enum
63 {
72 
76 typedef enum
77 {
83 
87 typedef enum
88 {
95 
99 typedef enum
100 {
114 
115 
120 {
124  m_dstPanId (0),
125  m_dstAddr (),
126  m_msduHandle (0),
127  m_txOptions (0)
128  {
129  }
132  uint16_t m_dstPanId;
134  uint8_t m_msduHandle;
135  uint8_t m_txOptions;
136 };
137 
142 {
143  uint8_t m_msduHandle;
145 };
146 
151 {
152  uint8_t m_srcAddrMode;
153  uint16_t m_srcPanId;
155  uint8_t m_dstAddrMode;
156  uint16_t m_dstPanId;
159  uint8_t m_dsn;
160 };
161 
168 
177 
178 
184 class LrWpanMac : public Object
185 {
186 public:
192  static TypeId GetTypeId (void);
193 
198  static const uint32_t aMinMPDUOverhead;
199 
203  LrWpanMac (void);
204  virtual ~LrWpanMac (void);
205 
211  bool GetRxOnWhenIdle (void);
212 
218  void SetRxOnWhenIdle (bool rxOnWhenIdle);
219 
220  // XXX these setters will become obsolete if we use the attribute system
227 
233  Mac16Address GetShortAddress (void) const;
234 
241 
247  Mac64Address GetExtendedAddress (void) const;
248 
254  void SetPanId (uint16_t panId);
255 
261  uint16_t GetPanId (void) const;
262 
272 
278  void SetCsmaCa (Ptr<LrWpanCsmaCa> csmaCa);
279 
285  void SetPhy (Ptr<LrWpanPhy> phy);
286 
292  Ptr<LrWpanPhy> GetPhy (void);
293 
302 
311 
312  // interfaces between MAC and PHY
321  void PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi);
322 
329  void PdDataConfirm (LrWpanPhyEnumeration status);
330 
336  void PlmeCcaConfirm (LrWpanPhyEnumeration status);
337 
344  void PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel);
345 
356  LrWpanPhyPibAttributes* attribute);
357 
365 
375 
381  void SetLrWpanMacState (LrWpanMacState macState);
382 
389 
396 
397  //MAC sublayer constants
404 
410 
417 
418  //MAC PIB attributes
425 
431 
438 
446 
453 
459  uint16_t m_macPanId;
460 
466 
472 
479 
485  uint64_t GetMacAckWaitDuration (void) const;
486 
492  uint8_t GetMacMaxFrameRetries (void) const;
493 
499  void SetMacMaxFrameRetries (uint8_t retries);
500 
501 protected:
502  // Inherited from Object.
503  virtual void DoInitialize (void);
504  virtual void DoDispose (void);
505 
506 private:
511  {
512  uint8_t txQMsduHandle;
514  };
515 
521  void SendAck (uint8_t seqno);
522 
527  void RemoveFirstTxQElement ();
528 
534  void ChangeMacState (LrWpanMacState newState);
535 
540  void AckWaitTimeout (void);
541 
548  bool PrepareRetransmission (void);
549 
555  void CheckQueue (void);
556 
568 
576 
584 
591 
600 
608 
617 
626 
635 
655 
675 
681 
686 
691 
697 
704 
709 
714 
718  Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet
719 
726 
732 
736  std::deque<TxQueueElement*> m_txQueue;
737 
743 
748 
754 
759 };
760 
761 
762 } // namespace ns3
763 
764 #endif /* LR_WPAN_MAC_H */
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:55
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:132
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:62
uint64_t m_aBaseSuperframeDuration
Length of a superframe in symbols.
Definition: lr-wpan-mac.h:416
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:87
void CheckQueue(void)
Check the transmission queue.
Definition: lr-wpan-mac.cc:394
Class that implements the LR-WPAN Mac state machine.
Definition: lr-wpan-mac.h:184
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:850
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:133
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission...
Definition: lr-wpan-mac.cc:682
virtual ~LrWpanMac(void)
Definition: lr-wpan-mac.cc:125
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:67
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:599
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
Definition: lr-wpan-mac.cc:963
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
Definition: lr-wpan-mac.h:703
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:736
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:157
uint8_t m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:155
LrWpanMacState m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:708
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:713
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lr-wpan-mac.cc:145
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:680
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:192
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:129
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:696
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:432
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:220
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:747
MAC_CSMA.
Definition: lr-wpan-mac.h:65
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:54
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:134
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:143
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:156
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:590
an EUI-64 address
Definition: mac64-address.h:41
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
Definition: lr-wpan-mac.h:718
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:176
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:167
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Definition: lr-wpan-mac.cc:903
uint64_t m_macBeaconOrder
Specification of how often the coordinator transmits its beacon.
Definition: lr-wpan-mac.h:437
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:214
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:843
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:674
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:575
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:625
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:56
uint64_t m_macSyncSymbolOffset
Symbol boundary is same as m_macBeaconTxTime.
Definition: lr-wpan-mac.h:430
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:513
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
Definition: lr-wpan-mac.cc:724
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Definition: lr-wpan-mac.cc:835
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h:753
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:607
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:758
LrWpanAddressMode
table 80 of 802.15.4
Definition: lr-wpan-mac.h:76
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:510
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:478
uint64_t m_macBeaconTxTime
The time that the device transmitted its last beacon frame, in symbol periods.
Definition: lr-wpan-mac.h:424
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:141
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:754
uint8_t m_txOptions
Tx Options (bitfield)
Definition: lr-wpan-mac.h:135
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
Definition: lr-wpan-mac.h:158
SET_PHY_TX_ON.
Definition: lr-wpan-mac.h:70
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Definition: lr-wpan-mac.cc:414
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:567
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:438
uint8_t m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:152
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:144
LrWpanAddressMode m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:130
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:742
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:731
LrWpanAddressMode m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:131
uint64_t m_macSuperframeOrder
The length of the active portion of the outgoing superframe, including the beacon frame...
Definition: lr-wpan-mac.h:445
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:634
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:173
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:616
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:452
Mac16Address m_srcAddr
Source address.
Definition: lr-wpan-mac.h:154
This class can contain 16 bit addresses.
Definition: mac16-address.h:39
uint8_t m_dsn
The DSN of the received data frame.
Definition: lr-wpan-mac.h:159
LrWpanMac(void)
Default constructor.
Definition: lr-wpan-mac.cc:101
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:654
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:199
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:471
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:512
LrWpanTxOption
Tx options.
Definition: lr-wpan-mac.h:51
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:685
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:465
an identifier for simulation events.
Definition: event-id.h:46
uint64_t m_aNumSuperframeSlots
Number of a superframe slots per superframe.
Definition: lr-wpan-mac.h:409
TX_OPTION_NONE.
Definition: lr-wpan-mac.h:53
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:198
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
Definition: lr-wpan-mac.cc:987
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:690
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:207
Callback< void, McpsDataConfirmParams > McpsDataConfirmCallback
This callback is called after a McpsDataRequest has been called from the higher layer.
Definition: lr-wpan-mac.h:167
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:583
MAC_IDLE.
Definition: lr-wpan-mac.h:64
MAC_SENDING.
Definition: lr-wpan-mac.h:66
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:459
LrWpanMcpsDataConfirmStatus
Table 42 of 802.15.4-2006.
Definition: lr-wpan-mac.h:99
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:858
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
Definition: lr-wpan-mac.cc:653
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:119
a base class which provides memory management and object aggregation
Definition: object.h:64
tuple address
Definition: first.py:37
uint16_t GetPanId(void) const
Get the PAN id used by this MAC.
Definition: lr-wpan-mac.cc:975
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:706
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Definition: lr-wpan-mac.cc:420
Mac16Address m_shortAddress
The short address used by this MAC.
Definition: lr-wpan-mac.h:725
a unique identifier for an interface.
Definition: type-id.h:49
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
Definition: lr-wpan-mac.cc:408
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:68
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
Definition: lr-wpan-mac.cc:981
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:896
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
Definition: lr-wpan-mac.cc:130
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
Definition: lr-wpan-mac.cc:997
uint64_t m_aBaseSlotDuration
Length of a superframe slot in symbols.
Definition: lr-wpan-mac.h:403
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:94
uint16_t m_srcPanId
Source PAN identifier.
Definition: lr-wpan-mac.h:153
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
Definition: lr-wpan-mac.cc:969
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:150
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:69
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:114
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:426