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 * 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
31namespace ns3
32{
33
34class UniformRandomVariable;
35
36namespace lrwpan
37{
38
39/**
40 * \ingroup lr-wpan
41 *
42 * This method informs the MAC whether the channel is idle or busy.
43 */
45/**
46 * \ingroup lr-wpan
47 *
48 * This method informs the transaction cost in a slotted CSMA-CA data transmission.
49 * i.e. Reports number of symbols (time) it would take slotted CSMA-CA to process the current
50 * transaction. 1 Transaction = 2 CCA + frame transmission (PPDU) + turnaroudtime or Ack time
51 * (optional) + IFS See IEEE 802.15.4-2011 (Sections 5.1.1.1 and 5.1.1.4)
52 */
54
55/**
56 * \ingroup lr-wpan
57 *
58 * This class is a helper for the LrWpanMac to manage the Csma/CA
59 * state machine according to IEEE 802.15.4-2006, section 7.5.1.4.
60 */
61class LrWpanCsmaCa : public Object
62{
63 public:
64 /**
65 * Get the type ID.
66 *
67 * \return the object TypeId
68 */
69 static TypeId GetTypeId();
70 /**
71 * Default constructor.
72 */
74 ~LrWpanCsmaCa() override;
75
76 // Delete copy constructor and assignment operator to avoid misuse
77 LrWpanCsmaCa(const LrWpanCsmaCa&) = delete;
79
80 /**
81 * Set the MAC to which this CSMA/CA implementation is attached to.
82 *
83 * \param mac the used MAC
84 */
85 void SetMac(Ptr<LrWpanMac> mac);
86 /**
87 * Get the MAC to which this CSMA/CA implementation is attached to.
88 *
89 * \return the used MAC
90 */
91 Ptr<LrWpanMac> GetMac() const;
92
93 /**
94 * Configure for the use of the slotted CSMA/CA version.
95 */
96 void SetSlottedCsmaCa();
97 /**
98 * Configure for the use of the unslotted CSMA/CA version.
99 */
100 void SetUnSlottedCsmaCa();
101 /**
102 * Check if the slotted CSMA/CA version is being used.
103 *
104 * \return true, if slotted CSMA/CA is used, false otherwise.
105 */
106 bool IsSlottedCsmaCa() const;
107 /**
108 * Check if the unslotted CSMA/CA version is being used.
109 *
110 * \return true, if unslotted CSMA/CA is used, false otherwise.
111 */
112 bool IsUnSlottedCsmaCa() const;
113 /**
114 * Set the minimum backoff exponent value.
115 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
116 *
117 * \param macMinBE the minimum backoff exponent value
118 */
119 void SetMacMinBE(uint8_t macMinBE);
120 /**
121 * Get the minimum backoff exponent value.
122 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
123 *
124 * \return the minimum backoff exponent value
125 */
126 uint8_t GetMacMinBE() const;
127 /**
128 * Set the maximum backoff exponent value.
129 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
130 *
131 * \param macMaxBE the maximum backoff exponent value
132 */
133 void SetMacMaxBE(uint8_t macMaxBE);
134 /**
135 * Get the maximum backoff exponent value.
136 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
137 *
138 * \return the maximum backoff exponent value
139 */
140 uint8_t GetMacMaxBE() const;
141 /**
142 * Set the maximum number of backoffs.
143 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
144 *
145 * \param macMaxCSMABackoffs the maximum number of backoffs
146 */
147 void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs);
148
149 /**
150 * Get the maximum number of backoffs.
151 * See IEEE 802.15.4-2006, section 7.4.2, Table 86.
152 *
153 * \return the maximum number of backoffs
154 */
155 uint8_t GetMacMaxCSMABackoffs() const;
156 /**
157 * Locates the time to the next backoff period boundary in the SUPERFRAME
158 * and returns the amount of time left to this moment.
159 *
160 * \return time offset to the next slot
161 */
162 Time GetTimeToNextSlot() const;
163 /**
164 * Start CSMA-CA algorithm (step 1), initialize NB, BE for both slotted and unslotted
165 * CSMA-CA. For slotted CSMA-CA initializes CW and starts the backoff slot count.
166 */
167 void Start();
168 /**
169 * Cancel CSMA-CA algorithm.
170 */
171 void Cancel();
172 /**
173 * In step 2 of the CSMA-CA, perform a random backoff in the range of 0 to 2^BE -1
174 */
175 void RandomBackoffDelay();
176 /**
177 * In the slotted CSMA-CA, after random backoff, determine if the remaining
178 * CSMA-CA operation can proceed, i.e. can the entire transactions can be
179 * transmitted before the end of the CAP. This step is performed between step
180 * 2 and 3. This step is NOT performed for the unslotted CSMA-CA. If it can
181 * proceed function RequestCCA() is called.
182 */
183 void CanProceed();
184 /**
185 * Request the Phy to perform CCA (Step 3)
186 */
187 void RequestCCA();
188 /**
189 * The CSMA algorithm call this function at the end of the CAP to return the MAC state
190 * back to to IDLE after a transmission was deferred due to the lack of time in the CAP.
191 */
192 void DeferCsmaTimeout();
193 /**
194 * IEEE 802.15.4-2006 section 6.2.2.2
195 * PLME-CCA.confirm status
196 * \param status TRX_OFF, BUSY or IDLE
197 *
198 * When Phy has completed CCA, it calls back here which in turn execute the final steps
199 * of the CSMA-CA algorithm.
200 * It checks to see if the Channel is idle, if so check the Contention window before
201 * permitting transmission (step 5). If channel is busy, either backoff and perform CCA again or
202 * treat as channel access failure (step 4).
203 */
204 void PlmeCcaConfirm(PhyEnumeration status);
205 /**
206 * Set the callback function to report a transaction cost in slotted CSMA-CA. The callback is
207 * triggered in CanProceed() after calculating the transaction cost (2 CCA checks,transmission
208 * cost, turnAroundTime, ifs) in the boundary of an Active Period.
209 *
210 * \param trans the transaction cost callback
211 */
213 /**
214 * Set the callback function to the MAC. Used at the end of a Channel Assessment, as part of the
215 * interconnections between the CSMA-CA and the MAC. The callback
216 * lets MAC know a channel is either idle or busy.
217 *
218 * \param macState the mac state callback
219 */
221 /**
222 * Set the value of the Battery Life Extension
223 *
224 * \param batteryLifeExtension the Battery Life Extension value active or inactive
225 */
226 void SetBatteryLifeExtension(bool batteryLifeExtension);
227 /**
228 * Assign a fixed random variable stream number to the random variables
229 * used by this model. Return the number of streams that have been assigned.
230 *
231 * \param stream first stream index to use
232 * \return the number of stream indices assigned by this model
233 */
234 int64_t AssignStreams(int64_t stream);
235 /**
236 * Get the number of CSMA retries
237 *
238 * \returns the number of CSMA retries
239 */
240 uint8_t GetNB() const;
241 /**
242 * Get the value of the Battery Life Extension
243 *
244 * \returns true or false to Battery Life Extension support
245 */
246 bool GetBatteryLifeExtension() const;
247
248 private:
249 void DoDispose() override;
250 /**
251 * \brief Get the time left in the CAP portion of the Outgoing or Incoming superframe.
252 * \return the time left in the CAP
253 */
255 /**
256 * The callback to inform the cost of a transaction in slotted CSMA-CA.
257 */
259 /**
260 * The callback to inform the configured MAC of the CSMA/CA result.
261 */
263 /**
264 * Beacon-enabled slotted or nonbeacon-enabled unslotted CSMA-CA.
265 */
267 /**
268 * The MAC instance for which this CSMA/CA implementation is configured.
269 */
271 /**
272 * Number of backoffs for the current transmission.
273 */
274 uint8_t m_NB;
275 /**
276 * Contention window length (used in slotted ver only).
277 */
278 uint8_t m_CW;
279 /**
280 * Backoff exponent.
281 */
282 uint8_t m_BE;
283 /**
284 * Battery Life Extension.
285 */
287 /**
288 * Minimum backoff exponent. 0 - macMaxBE, default 3
289 */
290 uint8_t m_macMinBE;
291 /**
292 * Maximum backoff exponent. 3 - 8, default 5
293 */
294 uint8_t m_macMaxBE;
295 /**
296 * Maximum number of backoffs. 0 - 5, default 4
297 */
299 /**
300 * Count the number of remaining random backoff periods left to delay.
301 */
303 /**
304 * Uniform random variable stream.
305 */
307 /**
308 * Scheduler event for the start of the next random backoff/slot.
309 */
311 /**
312 * Scheduler event for the end of the current CAP
313 */
315 /**
316 * Scheduler event when to start the CCA after a random backoff.
317 */
319 /**
320 * Scheduler event for checking if we can complete the transmission before the
321 * end of the CAP.
322 */
324 /**
325 * Flag indicating that the PHY is currently running a CCA. Used to prevent
326 * reporting the channel status to the MAC while canceling the CSMA algorithm.
327 */
329 /**
330 * Indicates whether the CSMA procedure is targeted for a message to be sent to the coordinator.
331 * Used to run slotted CSMA/CA on the incoming or outgoing superframe
332 * according to the target.
333 */
335};
336
337} // namespace lrwpan
338} // namespace ns3
339
340// namespace ns-3
341
342#endif /* LR_WPAN_CSMACA_H */
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
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
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.
Definition: lr-wpan-phy.h:115
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.