A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-csmaca.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author:
7 * kwong yin <kwong-sang.yin@boeing.com>
8 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
9 * Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
10 */
11
12#ifndef LR_WPAN_CSMACA_H
13#define LR_WPAN_CSMACA_H
14
15#include "lr-wpan-mac.h"
16
17#include <ns3/event-id.h>
18#include <ns3/object.h>
19
20namespace ns3
21{
22
23class UniformRandomVariable;
24
25namespace lrwpan
26{
27
28/**
29 * \ingroup lr-wpan
30 *
31 * This method informs the MAC whether the channel is idle or busy.
32 */
34/**
35 * \ingroup lr-wpan
36 *
37 * This method informs the transaction cost in a slotted CSMA-CA data transmission.
38 * i.e. Reports number of symbols (time) it would take slotted CSMA-CA to process the current
39 * transaction. 1 Transaction = 2 CCA + frame transmission (PPDU) + turnaroudtime or Ack time
40 * (optional) + IFS See IEEE 802.15.4-2011 (Sections 5.1.1.1 and 5.1.1.4)
41 */
43
44/**
45 * \ingroup lr-wpan
46 *
47 * This class is a helper for the LrWpanMac to manage the Csma/CA
48 * state machine according to IEEE 802.15.4-2006, section 7.5.1.4.
49 */
50class LrWpanCsmaCa : public Object
51{
52 public:
53 /**
54 * Get the type ID.
55 *
56 * \return the object TypeId
57 */
58 static TypeId GetTypeId();
59 /**
60 * Default constructor.
61 */
63 ~LrWpanCsmaCa() override;
64
65 // Delete copy constructor and assignment operator to avoid misuse
66 LrWpanCsmaCa(const LrWpanCsmaCa&) = delete;
68
69 /**
70 * Set the MAC to which this CSMA/CA implementation is attached to.
71 *
72 * \param mac the used MAC
73 */
74 void SetMac(Ptr<LrWpanMac> mac);
75 /**
76 * Get the MAC to which this CSMA/CA implementation is attached to.
77 *
78 * \return the used MAC
79 */
80 Ptr<LrWpanMac> GetMac() const;
81
82 /**
83 * Configure for the use of the slotted CSMA/CA version.
84 */
85 void SetSlottedCsmaCa();
86 /**
87 * Configure for the use of the unslotted CSMA/CA version.
88 */
89 void SetUnSlottedCsmaCa();
90 /**
91 * Check if the slotted CSMA/CA version is being used.
92 *
93 * \return true, if slotted CSMA/CA is used, false otherwise.
94 */
95 bool IsSlottedCsmaCa() const;
96 /**
97 * Check if the unslotted CSMA/CA version is being used.
98 *
99 * \return true, if unslotted CSMA/CA is used, false otherwise.
100 */
101 bool IsUnSlottedCsmaCa() const;
102 /**
103 * Set the minimum backoff exponent value.
104 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
105 *
106 * \param macMinBE the minimum backoff exponent value
107 */
108 void SetMacMinBE(uint8_t macMinBE);
109 /**
110 * Get the minimum backoff exponent value.
111 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
112 *
113 * \return the minimum backoff exponent value
114 */
115 uint8_t GetMacMinBE() const;
116 /**
117 * Set the maximum backoff exponent value.
118 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
119 *
120 * \param macMaxBE the maximum backoff exponent value
121 */
122 void SetMacMaxBE(uint8_t macMaxBE);
123 /**
124 * Get the maximum backoff exponent value.
125 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
126 *
127 * \return the maximum backoff exponent value
128 */
129 uint8_t GetMacMaxBE() const;
130 /**
131 * Set the maximum number of backoffs.
132 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
133 *
134 * \param macMaxCSMABackoffs the maximum number of backoffs
135 */
136 void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs);
137
138 /**
139 * Get the maximum number of backoffs.
140 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
141 *
142 * \return the maximum number of backoffs
143 */
144 uint8_t GetMacMaxCSMABackoffs() const;
145 /**
146 * Locates the time to the next backoff period boundary in the SUPERFRAME
147 * and returns the amount of time left to this moment.
148 *
149 * \return time offset to the next slot
150 */
151 Time GetTimeToNextSlot() const;
152 /**
153 * Start CSMA-CA algorithm (step 1), initialize NB, BE for both slotted and unslotted
154 * CSMA-CA. For slotted CSMA-CA initializes CW and starts the backoff slot count.
155 */
156 void Start();
157 /**
158 * Cancel CSMA-CA algorithm.
159 */
160 void Cancel();
161 /**
162 * In step 2 of the CSMA-CA, perform a random backoff in the range of 0 to 2^BE -1
163 */
164 void RandomBackoffDelay();
165 /**
166 * In the slotted CSMA-CA, after random backoff, determine if the remaining
167 * CSMA-CA operation can proceed, i.e. can the entire transactions can be
168 * transmitted before the end of the CAP. This step is performed between step
169 * 2 and 3. This step is NOT performed for the unslotted CSMA-CA. If it can
170 * proceed function RequestCCA() is called.
171 */
172 void CanProceed();
173 /**
174 * Request the Phy to perform CCA (Step 3)
175 */
176 void RequestCCA();
177 /**
178 * The CSMA algorithm call this function at the end of the CAP to return the MAC state
179 * back to to IDLE after a transmission was deferred due to the lack of time in the CAP.
180 */
181 void DeferCsmaTimeout();
182 /**
183 * IEEE 802.15.4-2006 section 6.2.2.2
184 * PLME-CCA.confirm status
185 * \param status TRX_OFF, BUSY or IDLE
186 *
187 * When Phy has completed CCA, it calls back here which in turn execute the final steps
188 * of the CSMA-CA algorithm.
189 * It checks to see if the Channel is idle, if so check the Contention window before
190 * permitting transmission (step 5). If channel is busy, either backoff and perform CCA again or
191 * treat as channel access failure (step 4).
192 */
193 void PlmeCcaConfirm(PhyEnumeration status);
194 /**
195 * Set the callback function to report a transaction cost in slotted CSMA-CA. The callback is
196 * triggered in CanProceed() after calculating the transaction cost (2 CCA checks,transmission
197 * cost, turnAroundTime, ifs) in the boundary of an Active Period.
198 *
199 * \param trans the transaction cost callback
200 */
202 /**
203 * Set the callback function to the MAC. Used at the end of a Channel Assessment, as part of the
204 * interconnections between the CSMA-CA and the MAC. The callback
205 * lets MAC know a channel is either idle or busy.
206 *
207 * \param macState the mac state callback
208 */
210 /**
211 * Set the value of the Battery Life Extension
212 *
213 * \param batteryLifeExtension the Battery Life Extension value active or inactive
214 */
215 void SetBatteryLifeExtension(bool batteryLifeExtension);
216 /**
217 * Assign a fixed random variable stream number to the random variables
218 * used by this model. Return the number of streams that have been assigned.
219 *
220 * \param stream first stream index to use
221 * \return the number of stream indices assigned by this model
222 */
223 int64_t AssignStreams(int64_t stream);
224 /**
225 * Get the number of CSMA retries
226 *
227 * \returns the number of CSMA retries
228 */
229 uint8_t GetNB() const;
230 /**
231 * Get the value of the Battery Life Extension
232 *
233 * \returns true or false to Battery Life Extension support
234 */
235 bool GetBatteryLifeExtension() const;
236
237 private:
238 void DoDispose() override;
239 /**
240 * \brief Get the time left in the CAP portion of the Outgoing or Incoming superframe.
241 * \return the time left in the CAP
242 */
244 /**
245 * The callback to inform the cost of a transaction in slotted CSMA-CA.
246 */
248 /**
249 * The callback to inform the configured MAC of the CSMA/CA result.
250 */
252 /**
253 * Beacon-enabled slotted or nonbeacon-enabled unslotted CSMA-CA.
254 */
256 /**
257 * The MAC instance for which this CSMA/CA implementation is configured.
258 */
260 /**
261 * Number of backoffs for the current transmission.
262 */
263 uint8_t m_NB;
264 /**
265 * Contention window length (used in slotted ver only).
266 */
267 uint8_t m_CW;
268 /**
269 * Backoff exponent.
270 */
271 uint8_t m_BE;
272 /**
273 * Battery Life Extension.
274 */
276 /**
277 * Minimum backoff exponent. 0 - macMaxBE, default 3
278 */
279 uint8_t m_macMinBE;
280 /**
281 * Maximum backoff exponent. 3 - 8, default 5
282 */
283 uint8_t m_macMaxBE;
284 /**
285 * Maximum number of backoffs. 0 - 5, default 4
286 */
288 /**
289 * Count the number of remaining random backoff periods left to delay.
290 */
292 /**
293 * Uniform random variable stream.
294 */
296 /**
297 * Scheduler event for the start of the next random backoff/slot.
298 */
300 /**
301 * Scheduler event for the end of the current CAP
302 */
304 /**
305 * Scheduler event when to start the CCA after a random backoff.
306 */
308 /**
309 * Scheduler event for checking if we can complete the transmission before the
310 * end of the CAP.
311 */
313 /**
314 * Flag indicating that the PHY is currently running a CCA. Used to prevent
315 * reporting the channel status to the MAC while canceling the CSMA algorithm.
316 */
318 /**
319 * Indicates whether the CSMA procedure is targeted for a message to be sent to the coordinator.
320 * Used to run slotted CSMA/CA on the incoming or outgoing superframe
321 * according to the target.
322 */
324};
325
326} // namespace lrwpan
327} // namespace ns3
328
329// namespace ns-3
330
331#endif /* LR_WPAN_CSMACA_H */
Callback template class.
Definition callback.h:422
An identifier for simulation events.
Definition event-id.h:45
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
This class is a helper for the LrWpanMac to manage the Csma/CA state machine according to IEEE 802....
uint8_t m_macMaxCSMABackoffs
Maximum number of backoffs.
bool m_coorDest
Indicates whether the CSMA procedure is targeted for a message to be sent to the coordinator.
EventId m_randomBackoffEvent
Scheduler event for the start of the next random backoff/slot.
LrWpanMacStateCallback m_lrWpanMacStateCallback
The callback to inform the configured MAC of the CSMA/CA result.
LrWpanMacTransCostCallback m_lrWpanMacTransCostCallback
The callback to inform the cost of a transaction in slotted CSMA-CA.
uint8_t m_CW
Contention window length (used in slotted ver only).
void SetUnSlottedCsmaCa()
Configure for the use of the unslotted CSMA/CA version.
void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs)
Set the maximum number of backoffs.
void Cancel()
Cancel CSMA-CA algorithm.
void Start()
Start CSMA-CA algorithm (step 1), initialize NB, BE for both slotted and unslotted CSMA-CA.
static TypeId GetTypeId()
Get the type ID.
EventId m_canProceedEvent
Scheduler event for checking if we can complete the transmission before the end of the CAP.
EventId m_requestCcaEvent
Scheduler event when to start the CCA after a random backoff.
Ptr< LrWpanMac > GetMac() const
Get the MAC to which this CSMA/CA implementation is attached to.
void RandomBackoffDelay()
In step 2 of the CSMA-CA, perform a random backoff in the range of 0 to 2^BE -1.
void CanProceed()
In the slotted CSMA-CA, after random backoff, determine if the remaining CSMA-CA operation can procee...
uint8_t GetNB() const
Get the number of CSMA retries.
bool IsUnSlottedCsmaCa() const
Check if the unslotted CSMA/CA version is being used.
uint8_t m_BE
Backoff exponent.
Time GetTimeToNextSlot() const
Locates the time to the next backoff period boundary in the SUPERFRAME and returns the amount of time...
void PlmeCcaConfirm(PhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
bool GetBatteryLifeExtension() const
Get the value of the Battery Life Extension.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint64_t m_randomBackoffPeriodsLeft
Count the number of remaining random backoff periods left to delay.
uint8_t GetMacMaxBE() const
Get the maximum backoff exponent value.
uint8_t GetMacMaxCSMABackoffs() const
Get the maximum number of backoffs.
uint8_t GetMacMinBE() const
Get the minimum backoff exponent value.
void SetLrWpanMacTransCostCallback(LrWpanMacTransCostCallback trans)
Set the callback function to report a transaction cost in slotted CSMA-CA.
uint8_t m_macMaxBE
Maximum backoff exponent.
LrWpanCsmaCa(const LrWpanCsmaCa &)=delete
void SetSlottedCsmaCa()
Configure for the use of the slotted CSMA/CA version.
bool m_ccaRequestRunning
Flag indicating that the PHY is currently running a CCA.
bool m_macBattLifeExt
Battery Life Extension.
bool IsSlottedCsmaCa() const
Check if the slotted CSMA/CA version is being used.
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
bool m_isSlotted
Beacon-enabled slotted or nonbeacon-enabled unslotted CSMA-CA.
void SetMacMinBE(uint8_t macMinBE)
Set the minimum backoff exponent value.
uint8_t m_NB
Number of backoffs for the current transmission.
EventId m_endCapEvent
Scheduler event for the end of the current CAP.
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to which this CSMA/CA implementation is attached to.
Time GetTimeLeftInCap()
Get the time left in the CAP portion of the Outgoing or Incoming superframe.
void SetBatteryLifeExtension(bool batteryLifeExtension)
Set the value of the Battery Life Extension.
void SetMacMaxBE(uint8_t macMaxBE)
Set the maximum backoff exponent value.
void DoDispose() override
Destructor implementation.
void RequestCCA()
Request the Phy to perform CCA (Step 3)
void DeferCsmaTimeout()
The CSMA algorithm call this function at the end of the CAP to return the MAC state back to to IDLE a...
uint8_t m_macMinBE
Minimum backoff exponent.
LrWpanCsmaCa & operator=(const LrWpanCsmaCa &)=delete
Ptr< LrWpanMac > m_mac
The MAC instance for which this CSMA/CA implementation is configured.
LrWpanCsmaCa()
Default constructor.
void SetLrWpanMacStateCallback(LrWpanMacStateCallback macState)
Set the callback function to the MAC.
Callback< void, MacState > LrWpanMacStateCallback
This method informs the MAC whether the channel is idle or busy.
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Callback< void, uint32_t > LrWpanMacTransCostCallback
This method informs the transaction cost in a slotted CSMA-CA data transmission.
@ macMinBE
The minimum value of the backoff exponent (BE) in the CSMA-CA algorithm.
Every class exported by the ns3 library is enclosed in the ns3 namespace.