A Discrete-Event Network Simulator
API
lr-wpan-csmaca.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 The Boeing Company
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author:
18  * kwong yin <kwong-sang.yin@boeing.com>
19  * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
20  * Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
21  */
22 
23 #ifndef LR_WPAN_CSMACA_H
24 #define LR_WPAN_CSMACA_H
25 
26 #include "lr-wpan-mac.h"
27 
28 #include <ns3/event-id.h>
29 #include <ns3/object.h>
30 
31 namespace ns3
32 {
33 
34 class UniformRandomVariable;
35 
51 
58 class LrWpanCsmaCa : public Object
59 {
60  public:
66  static TypeId GetTypeId();
70  LrWpanCsmaCa();
71  ~LrWpanCsmaCa() override;
72 
73  // Delete copy constructor and assignment operator to avoid misuse
74  LrWpanCsmaCa(const LrWpanCsmaCa&) = delete;
75  LrWpanCsmaCa& operator=(const LrWpanCsmaCa&) = delete;
76 
88  Ptr<LrWpanMac> GetMac() const;
89 
93  void SetSlottedCsmaCa();
97  void SetUnSlottedCsmaCa();
103  bool IsSlottedCsmaCa() const;
109  bool IsUnSlottedCsmaCa() const;
116  void SetMacMinBE(uint8_t macMinBE);
123  uint8_t GetMacMinBE() const;
130  void SetMacMaxBE(uint8_t macMaxBE);
137  uint8_t GetMacMaxBE() const;
144  void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs);
145 
152  uint8_t GetMacMaxCSMABackoffs() const;
159  Time GetTimeToNextSlot() const;
164  void Start();
168  void Cancel();
172  void RandomBackoffDelay();
180  void CanProceed();
184  void RequestCCA();
189  void DeferCsmaTimeout();
223  void SetBatteryLifeExtension(bool batteryLifeExtension);
231  int64_t AssignStreams(int64_t stream);
237  uint8_t GetNB() const;
243  bool GetBatteryLifeExtension() const;
244 
245  private:
246  void DoDispose() override;
271  uint8_t m_NB;
275  uint8_t m_CW;
279  uint8_t m_BE;
287  uint8_t m_macMinBE;
291  uint8_t m_macMaxBE;
332 };
333 
334 } // namespace ns3
335 
336 // namespace ns-3
337 
338 #endif /* LR_WPAN_CSMACA_H */
An identifier for simulation events.
Definition: event-id.h:55
This class is a helper for the LrWpanMac to manage the Csma/CA state machine according to IEEE 802....
Ptr< LrWpanMac > m_mac
The MAC instance for which this CSMA/CA implementation is configured.
void SetBatteryLifeExtension(bool batteryLifeExtension)
Set the value of the Battery Life Extension.
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
LrWpanCsmaCa()
Default constructor.
void RequestCCA()
Request the Phy to perform CCA (Step 3)
uint8_t GetMacMinBE() const
Get the minimum backoff exponent value.
bool m_isSlotted
Beacon-enabled slotted or nonbeacon-enabled unslotted CSMA-CA.
uint8_t m_BE
Backoff exponent.
EventId m_canProceedEvent
Scheduler event for checking if we can complete the transmission before the end of the CAP.
static TypeId GetTypeId()
Get the type ID.
EventId m_randomBackoffEvent
Scheduler event for the start of the next random backoff/slot.
LrWpanCsmaCa & operator=(const LrWpanCsmaCa &)=delete
void SetUnSlottedCsmaCa()
Configure for the use of the unslotted CSMA/CA version.
void DeferCsmaTimeout()
The CSMA algorithm call this function at the end of the CAP to return the MAC state back to to IDLE a...
bool IsUnSlottedCsmaCa() const
Check if the unslotted CSMA/CA version is being used.
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to which this CSMA/CA implementation is attached to.
uint8_t GetNB() const
Get the number of CSMA retries.
LrWpanMacStateCallback m_lrWpanMacStateCallback
The callback to inform the configured MAC of the CSMA/CA result.
Ptr< LrWpanMac > GetMac() const
Get the MAC to which this CSMA/CA implementation is attached to.
LrWpanMacTransCostCallback m_lrWpanMacTransCostCallback
The callback to inform the cost of a transaction in slotted CSMA-CA.
void Cancel()
Cancel CSMA-CA algorithm.
LrWpanCsmaCa(const LrWpanCsmaCa &)=delete
EventId m_requestCcaEvent
Scheduler event when to start the CCA after a random backoff.
bool m_coorDest
Indicates whether the CSMA procedure is targeted for a message to be sent to the coordinator.
bool IsSlottedCsmaCa() const
Check if the slotted CSMA/CA version is being used.
void SetLrWpanMacTransCostCallback(LrWpanMacTransCostCallback trans)
Set the callback function to report a transaction cost in slotted CSMA-CA.
void SetMacMaxBE(uint8_t macMaxBE)
Set the maximum backoff exponent value.
void RandomBackoffDelay()
In step 2 of the CSMA-CA, perform a random backoff in the range of 0 to 2^BE -1.
uint8_t m_macMaxBE
Maximum backoff exponent.
void SetMacMinBE(uint8_t macMinBE)
Set the minimum backoff exponent value.
bool GetBatteryLifeExtension() const
Get the value of the Battery Life Extension.
uint8_t m_CW
Contention window length (used in slotted ver only).
uint8_t m_macMinBE
Minimum backoff exponent.
uint8_t GetMacMaxCSMABackoffs() const
Get the maximum number of backoffs.
bool m_macBattLifeExt
Battery Life Extension.
Time GetTimeToNextSlot() const
Locates the time to the next backoff period boundary in the SUPERFRAME and returns the amount of time...
uint8_t GetMacMaxBE() const
Get the maximum backoff exponent value.
void SetSlottedCsmaCa()
Configure for the use of the slotted CSMA/CA version.
EventId m_endCapEvent
Scheduler event for the end of the current CAP.
void CanProceed()
In the slotted CSMA-CA, after random backoff, determine if the remaining CSMA-CA operation can procee...
uint64_t m_randomBackoffPeriodsLeft
Count the number of remaining random backoff periods left to delay.
Time GetTimeLeftInCap()
Get the time left in the CAP portion of the Outgoing or Incoming superframe.
~LrWpanCsmaCa() override
bool m_ccaRequestRunning
Flag indicating that the PHY is currently running a CCA.
void SetLrWpanMacStateCallback(LrWpanMacStateCallback macState)
Set the callback function to the MAC.
void DoDispose() override
Destructor implementation.
void Start()
Start CSMA-CA algorithm (step 1), initialize NB, BE for both slotted and unslotted CSMA-CA.
uint8_t m_NB
Number of backoffs for the current transmission.
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs)
Set the maximum number of backoffs.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint8_t m_macMaxCSMABackoffs
Maximum number of backoffs.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Callback< void, uint32_t > LrWpanMacTransCostCallback
This method informs the transaction cost in a slotted CSMA-CA data transmission.
Callback< void, LrWpanMacState > LrWpanMacStateCallback
This method informs the MAC whether the channel is idle or busy.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:111
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:92