A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aarfcd-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004,2005,2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Federico Maguolo <maguolof@dei.unipd.it>
7 */
8
10
11#include "ns3/log.h"
12#include "ns3/packet.h"
13#include "ns3/wifi-tx-vector.h"
14
15#define Min(a, b) ((a < b) ? a : b)
16#define Max(a, b) ((a > b) ? a : b)
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("AarfcdWifiManager");
22
23/**
24 * \brief hold per-remote-station state for AARF-CD Wifi manager.
25 *
26 * This struct extends from WifiRemoteStation struct to hold additional
27 * information required by the AARF-CD Wifi manager
28 */
30{
31 uint32_t m_timer; ///< timer
32 uint32_t m_success; ///< success
33 uint32_t m_failed; ///< failed
34 bool m_recovery; ///< recovery
35 bool m_justModifyRate; ///< just modify rate
36 uint32_t m_successThreshold; ///< success threshold
37 uint32_t m_timerTimeout; ///< timer timeout
38 uint8_t m_rate; ///< rate
39 bool m_rtsOn; ///< RTS on
40 uint32_t m_rtsWnd; ///< RTS window
41 uint32_t m_rtsCounter; ///< RTS counter
42 bool m_haveASuccess; ///< have a success
43};
44
46
49{
50 static TypeId tid =
51 TypeId("ns3::AarfcdWifiManager")
53 .SetGroupName("Wifi")
54 .AddConstructor<AarfcdWifiManager>()
55 .AddAttribute("SuccessK",
56 "Multiplication factor for the success threshold in the AARF algorithm.",
57 DoubleValue(2.0),
60 .AddAttribute("TimerK",
61 "Multiplication factor for the timer threshold in the AARF algorithm.",
62 DoubleValue(2.0),
65 .AddAttribute("MaxSuccessThreshold",
66 "Maximum value of the success threshold in the AARF algorithm.",
67 UintegerValue(60),
70 .AddAttribute("MinTimerThreshold",
71 "The minimum value for the 'timer' threshold in the AARF algorithm.",
72 UintegerValue(15),
75 .AddAttribute("MinSuccessThreshold",
76 "The minimum value for the success threshold in the AARF algorithm.",
77 UintegerValue(10),
80 .AddAttribute("MinRtsWnd",
81 "Minimum value for RTS window of AARF-CD",
85 .AddAttribute("MaxRtsWnd",
86 "Maximum value for RTS window of AARF-CD",
87 UintegerValue(40),
90 .AddAttribute(
91 "TurnOffRtsAfterRateDecrease",
92 "If true the RTS mechanism will be turned off when the rate will be decreased",
93 BooleanValue(true),
96 .AddAttribute(
97 "TurnOnRtsAfterRateIncrease",
98 "If true the RTS mechanism will be turned on when the rate will be increased",
99 BooleanValue(true),
102 .AddTraceSource("Rate",
103 "Traced value for rate changes (b/s)",
105 "ns3::TracedValueCallback::Uint64");
106 return tid;
107}
108
111 m_currentRate(0)
112{
113 NS_LOG_FUNCTION(this);
114}
115
120
121void
123{
124 NS_LOG_FUNCTION(this);
125 if (GetHtSupported())
126 {
127 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
128 }
129 if (GetVhtSupported())
130 {
131 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
132 }
133 if (GetHeSupported())
134 {
135 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
136 }
137}
138
141{
142 NS_LOG_FUNCTION(this);
143 auto station = new AarfcdWifiRemoteStation();
144
145 // AARF fields below
146 station->m_successThreshold = m_minSuccessThreshold;
147 station->m_timerTimeout = m_minTimerThreshold;
148 station->m_rate = 0;
149 station->m_success = 0;
150 station->m_failed = 0;
151 station->m_recovery = false;
152 station->m_timer = 0;
153
154 // AARF-CD specific fields below
155 station->m_rtsOn = false;
156 station->m_rtsWnd = m_minRtsWnd;
157 station->m_rtsCounter = 0;
158 station->m_justModifyRate = true;
159 station->m_haveASuccess = false;
160
161 return station;
162}
163
164void
169
170void
172{
173 NS_LOG_FUNCTION(this << st);
174 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
175 station->m_timer++;
176 station->m_failed++;
177 station->m_success = 0;
178
179 if (!station->m_rtsOn)
180 {
181 TurnOnRts(station);
182 if (!station->m_justModifyRate && !station->m_haveASuccess)
183 {
184 IncreaseRtsWnd(station);
185 }
186 else
187 {
188 ResetRtsWnd(station);
189 }
190 station->m_rtsCounter = station->m_rtsWnd;
191 if (station->m_failed >= 2)
192 {
193 station->m_timer = 0;
194 }
195 }
196 else if (station->m_recovery)
197 {
198 NS_ASSERT(station->m_failed >= 1);
199 station->m_justModifyRate = false;
200 station->m_rtsCounter = station->m_rtsWnd;
201 if (station->m_failed == 1)
202 {
203 // need recovery fallback
205 {
206 TurnOffRts(station);
207 }
208 station->m_justModifyRate = true;
209 station->m_successThreshold =
210 (int)(Min(station->m_successThreshold * m_successK, m_maxSuccessThreshold));
211 station->m_timerTimeout =
212 (int)(Max(station->m_timerTimeout * m_timerK, m_minSuccessThreshold));
213 if (station->m_rate != 0)
214 {
215 station->m_rate--;
216 }
217 }
218 station->m_timer = 0;
219 }
220 else
221 {
222 NS_ASSERT(station->m_failed >= 1);
223 station->m_justModifyRate = false;
224 station->m_rtsCounter = station->m_rtsWnd;
225 if (((station->m_failed - 1) % 2) == 1)
226 {
227 // need normal fallback
229 {
230 TurnOffRts(station);
231 }
232 station->m_justModifyRate = true;
233 station->m_timerTimeout = m_minTimerThreshold;
234 station->m_successThreshold = m_minSuccessThreshold;
235 if (station->m_rate != 0)
236 {
237 station->m_rate--;
238 }
239 }
240 if (station->m_failed >= 2)
241 {
242 station->m_timer = 0;
243 }
244 }
245 CheckRts(station);
246}
247
248void
250{
251 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
252}
253
254void
256 double ctsSnr,
257 WifiMode ctsMode,
258 double rtsSnr)
259{
260 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
261 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
262 NS_LOG_DEBUG("station=" << station << " rts ok");
263 station->m_rtsCounter--;
264}
265
266void
268 double ackSnr,
269 WifiMode ackMode,
270 double dataSnr,
271 MHz_u dataChannelWidth,
272 uint8_t dataNss)
273{
274 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
275 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
276 station->m_timer++;
277 station->m_success++;
278 station->m_failed = 0;
279 station->m_recovery = false;
280 station->m_justModifyRate = false;
281 station->m_haveASuccess = true;
282 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
283 << ", timer=" << station->m_timer);
284 if ((station->m_success == station->m_successThreshold ||
285 station->m_timer == station->m_timerTimeout) &&
286 (station->m_rate < (GetNSupported(station) - 1)))
287 {
288 NS_LOG_DEBUG("station=" << station << " inc rate");
289 station->m_rate++;
290 station->m_timer = 0;
291 station->m_success = 0;
292 station->m_recovery = true;
293 station->m_justModifyRate = true;
295 {
296 TurnOnRts(station);
297 ResetRtsWnd(station);
298 station->m_rtsCounter = station->m_rtsWnd;
299 }
300 }
301 CheckRts(station);
302}
303
304void
309
310void
315
318{
319 NS_LOG_FUNCTION(this << st << allowedWidth);
320 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
321 auto channelWidth = GetChannelWidth(station);
322 if (channelWidth > 20 && channelWidth != 22)
323 {
324 channelWidth = 20;
325 }
326 WifiMode mode = GetSupported(station, station->m_rate);
327 uint64_t rate = mode.GetDataRate(channelWidth);
328 if (m_currentRate != rate)
329 {
330 NS_LOG_DEBUG("New datarate: " << rate);
331 m_currentRate = rate;
332 }
333 return WifiTxVector(
334 mode,
337 NanoSeconds(800),
338 1,
339 1,
340 0,
341 channelWidth,
342 GetAggregation(station));
343}
344
347{
348 NS_LOG_FUNCTION(this << st);
349 /// \todo we could/should implement the AARF algorithm for
350 /// RTS only by picking a single rate within the BasicRateSet.
351 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
352 auto channelWidth = GetChannelWidth(station);
353 if (channelWidth > 20 && channelWidth != 22)
354 {
355 channelWidth = 20;
356 }
357 WifiMode mode;
359 {
360 mode = GetSupported(station, 0);
361 }
362 else
363 {
364 mode = GetNonErpSupported(station, 0);
365 }
366 return WifiTxVector(
367 mode,
370 NanoSeconds(800),
371 1,
372 1,
373 0,
374 channelWidth,
375 GetAggregation(station));
376}
377
378bool
380{
381 NS_LOG_FUNCTION(this << st << size << normally);
382 auto station = static_cast<AarfcdWifiRemoteStation*>(st);
383 NS_LOG_INFO("" << station << " rate=" << station->m_rate
384 << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC")
385 << " rtsCounter=" << station->m_rtsCounter);
386 return station->m_rtsOn;
387}
388
389void
391{
392 NS_LOG_FUNCTION(this << station);
393 if (station->m_rtsCounter == 0 && station->m_rtsOn)
394 {
395 TurnOffRts(station);
396 }
397}
398
399void
401{
402 NS_LOG_FUNCTION(this << station);
403 station->m_rtsOn = false;
404 station->m_haveASuccess = false;
405}
406
407void
409{
410 NS_LOG_FUNCTION(this << station);
411 station->m_rtsOn = true;
412}
413
414void
416{
417 NS_LOG_FUNCTION(this << station);
418 if (station->m_rtsWnd == m_maxRtsWnd)
419 {
420 return;
421 }
422
423 station->m_rtsWnd *= 2;
424 if (station->m_rtsWnd > m_maxRtsWnd)
425 {
426 station->m_rtsWnd = m_maxRtsWnd;
427 }
428}
429
430void
432{
433 NS_LOG_FUNCTION(this << station);
434 station->m_rtsWnd = m_minRtsWnd;
435}
436
437} // namespace ns3
#define Max(a, b)
#define Min(a, b)
an implementation of the AARF-CD algorithm
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
Reset the RTS window of the given station.
bool m_turnOnRtsAfterRateIncrease
turn on RTS after rate increase
double m_timerK
Multiplication factor for the timer threshold.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint32_t m_maxSuccessThreshold
maximum success threshold
bool DoNeedRts(WifiRemoteStation *station, uint32_t size, bool normally) override
WifiRemoteStation * DoCreateStation() const override
uint32_t m_minTimerThreshold
minimum timer threshold
uint32_t m_minSuccessThreshold
minimum success threshold
uint32_t m_minRtsWnd
minimum RTS window
bool m_turnOffRtsAfterRateDecrease
turn off RTS after rate decrease
uint32_t m_maxRtsWnd
maximum RTS window
void TurnOffRts(AarfcdWifiRemoteStation *station)
Turn off RTS for the given station.
double m_successK
Multiplication factor for the success threshold.
void DoInitialize() override
Initialize() implementation.
void TurnOnRts(AarfcdWifiRemoteStation *station)
Turn on RTS for the given station.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station) override
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
static TypeId GetTypeId()
Get the type ID.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
void CheckRts(AarfcdWifiRemoteStation *station)
Check if the use of RTS for the given station can be turned off.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void IncreaseRtsWnd(AarfcdWifiRemoteStation *station)
Increase the RTS window size of the given station.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
represent a single transmission mode
Definition wifi-mode.h:40
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:111
hold a list of per-remote-station state.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
MHz_u GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled on the link this manager is associated wi...
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled on the link this manager is associated w...
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
hold per-remote-station state for AARF-CD Wifi manager.
uint32_t m_successThreshold
success threshold
bool m_justModifyRate
just modify rate
uint32_t m_timerTimeout
timer timeout
hold per-remote-station state.