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 
47 typedef enum
48 {
54 
55 typedef enum
56 {
65 
69 typedef enum
70 {
76 
80 typedef enum
81 {
88 
89 /*
90  * Table 42 of 802.15.4-2006
91  */
92 typedef enum
93 {
107 
109 {
113  m_dstPanId (0),
114  m_dstAddr (),
115  m_msduHandle (0),
116  m_txOptions (0)
117  {
118  }
121  uint16_t m_dstPanId;
123  uint8_t m_msduHandle;
124  uint8_t m_txOptions; // bitmap
125 };
126 
128 {
129  uint8_t m_msduHandle;
131 };
132 
134 {
135  uint8_t m_srcAddrMode;
136  uint16_t m_srcPanId;
138  uint8_t m_dstAddrMode;
139  uint16_t m_dstPanId;
142  uint8_t m_dsn;
143 };
144 
145 // This callback is called after a McpsDataRequest has been called from
146 // the higher layer. It returns a status of the outcome of the
147 // transmission request
149 
150 // This callback is called after a Mcps has successfully received a
151 // frame and wants to deliver it to the higher layer.
152 //
153 // XXX for now, we do not deliver all of the parameters in section
154 // 7.1.1.3.1 but just send up the packet.
156 
157 
163 class LrWpanMac : public Object
164 {
165 public:
171  static TypeId GetTypeId (void);
172 
177  static const uint32_t aMinMPDUOverhead;
178 
182  LrWpanMac (void);
183  virtual ~LrWpanMac (void);
184 
190  bool GetRxOnWhenIdle (void);
191 
197  void SetRxOnWhenIdle (bool rxOnWhenIdle);
198 
199  // XXX these setters will become obsolete if we use the attribute system
206 
212  Mac16Address GetShortAddress (void) const;
213 
220 
226  Mac64Address GetExtendedAddress (void) const;
227 
233  void SetPanId (uint16_t panId);
234 
240  uint16_t GetPanId (void) const;
241 
251 
257  void SetCsmaCa (Ptr<LrWpanCsmaCa> csmaCa);
258 
264  void SetPhy (Ptr<LrWpanPhy> phy);
265 
271  Ptr<LrWpanPhy> GetPhy (void);
272 
281 
290 
291  // interfaces between MAC and PHY
300  void PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi);
301 
308  void PdDataConfirm (LrWpanPhyEnumeration status);
309 
315  void PlmeCcaConfirm (LrWpanPhyEnumeration status);
316 
323  void PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel);
324 
335  LrWpanPhyPibAttributes* attribute);
336 
344 
354 
360  void SetLrWpanMacState (LrWpanMacState macState);
361 
368 
375 
376  //MAC sublayer constants
383 
389 
396 
397  //MAC PIB attributes
404 
410 
417 
425 
432 
438  uint16_t m_macPanId;
439 
445 
451 
458 
464  uint64_t GetMacAckWaitDuration (void) const;
465 
471  uint8_t GetMacMaxFrameRetries (void) const;
472 
478  void SetMacMaxFrameRetries (uint8_t retries);
479 
480 protected:
481  // Inherited from Object.
482  virtual void DoInitialize (void);
483  virtual void DoDispose (void);
484 
485 private:
490  {
491  uint8_t txQMsduHandle;
493  };
494 
500  void SendAck (uint8_t seqno);
501 
506  void RemoveFirstTxQElement ();
507 
513  void ChangeMacState (LrWpanMacState newState);
514 
519  void AckWaitTimeout (void);
520 
527  bool PrepareRetransmission (void);
528 
534  void CheckQueue (void);
535 
547 
555 
563 
570 
579 
587 
596 
605 
614 
634 
654 
655  /*
656  * A trace source that fires when the LrWpanMac changes states.
657  * Parameters are the old mac state and the new mac state.
658  */
660 
665 
670 
676 
683 
688 
693 
697  Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet
698 
705 
711 
715  std::deque<TxQueueElement*> m_txQueue;
716 
722 
727 
733 
738 };
739 
740 
741 } // namespace ns3
742 
743 #endif /* LR_WPAN_MAC_H */
LrWpanMacState
Definition: lr-wpan-mac.h:55
uint64_t m_aBaseSuperframeDuration
Length of a superframe in symbols.
Definition: lr-wpan-mac.h:395
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:80
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:163
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
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
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:578
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:682
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:715
LrWpanMacState m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:687
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:692
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
Definition: lr-wpan-mac.h:659
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:128
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:675
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:726
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:569
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:697
Callback< void, McpsDataIndicationParams, Ptr< Packet > > McpsDataIndicationCallback
Definition: lr-wpan-mac.h:155
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:416
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:653
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:554
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:604
uint64_t m_macSyncSymbolOffset
Symbol boundary is same as m_macBeaconTxTime.
Definition: lr-wpan-mac.h:409
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:732
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:586
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:737
LrWpanAddressMode
table 80 of 802.15.4
Definition: lr-wpan-mac.h:69
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:489
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:457
uint64_t m_macBeaconTxTime
The time that the device transmitted its last beacon frame, in symbol periods.
Definition: lr-wpan-mac.h:403
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
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:546
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
LrWpanMcpsDataConfirmStatus m_status
Definition: lr-wpan-mac.h:130
LrWpanAddressMode m_srcAddrMode
Definition: lr-wpan-mac.h:119
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:721
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:710
LrWpanAddressMode m_dstAddrMode
Definition: lr-wpan-mac.h:120
uint64_t m_macSuperframeOrder
The length of the active portion of the outgoing superframe, including the beacon frame...
Definition: lr-wpan-mac.h:424
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:613
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:595
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:431
This class can contain 16 bit addresses.
Definition: mac16-address.h:39
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:633
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:450
LrWpanTxOption
Definition: lr-wpan-mac.h:47
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:664
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:444
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:388
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:177
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:669
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:207
Callback< void, McpsDataConfirmParams > McpsDataConfirmCallback
Definition: lr-wpan-mac.h:148
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:562
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:438
LrWpanMcpsDataConfirmStatus
Definition: lr-wpan-mac.h:92
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
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:704
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
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:382
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:93
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
Definition: lr-wpan-mac.cc:969
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:113
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:426