A Discrete-Event Network Simulator
API
aarfcd-wifi-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004,2005,2006 INRIA
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: Federico Maguolo <maguolof@dei.unipd.it>
18  */
19 
20 #include "aarfcd-wifi-manager.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/packet.h"
24 #include "ns3/wifi-tx-vector.h"
25 
26 #define Min(a, b) ((a < b) ? a : b)
27 #define Max(a, b) ((a > b) ? a : b)
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("AarfcdWifiManager");
33 
41 {
42  uint32_t m_timer;
43  uint32_t m_success;
44  uint32_t m_failed;
45  bool m_recovery;
47  uint32_t m_successThreshold;
48  uint32_t m_timerTimeout;
49  uint8_t m_rate;
50  bool m_rtsOn;
51  uint32_t m_rtsWnd;
52  uint32_t m_rtsCounter;
54 };
55 
57 
58 TypeId
60 {
61  static TypeId tid =
62  TypeId("ns3::AarfcdWifiManager")
64  .SetGroupName("Wifi")
65  .AddConstructor<AarfcdWifiManager>()
66  .AddAttribute("SuccessK",
67  "Multiplication factor for the success threshold in the AARF algorithm.",
68  DoubleValue(2.0),
70  MakeDoubleChecker<double>())
71  .AddAttribute("TimerK",
72  "Multiplication factor for the timer threshold in the AARF algorithm.",
73  DoubleValue(2.0),
75  MakeDoubleChecker<double>())
76  .AddAttribute("MaxSuccessThreshold",
77  "Maximum value of the success threshold in the AARF algorithm.",
78  UintegerValue(60),
80  MakeUintegerChecker<uint32_t>())
81  .AddAttribute("MinTimerThreshold",
82  "The minimum value for the 'timer' threshold in the AARF algorithm.",
83  UintegerValue(15),
85  MakeUintegerChecker<uint32_t>())
86  .AddAttribute("MinSuccessThreshold",
87  "The minimum value for the success threshold in the AARF algorithm.",
88  UintegerValue(10),
90  MakeUintegerChecker<uint32_t>())
91  .AddAttribute("MinRtsWnd",
92  "Minimum value for RTS window of AARF-CD",
93  UintegerValue(1),
95  MakeUintegerChecker<uint32_t>())
96  .AddAttribute("MaxRtsWnd",
97  "Maximum value for RTS window of AARF-CD",
98  UintegerValue(40),
100  MakeUintegerChecker<uint32_t>())
101  .AddAttribute(
102  "TurnOffRtsAfterRateDecrease",
103  "If true the RTS mechanism will be turned off when the rate will be decreased",
104  BooleanValue(true),
107  .AddAttribute(
108  "TurnOnRtsAfterRateIncrease",
109  "If true the RTS mechanism will be turned on when the rate will be increased",
110  BooleanValue(true),
113  .AddTraceSource("Rate",
114  "Traced value for rate changes (b/s)",
116  "ns3::TracedValueCallback::Uint64");
117  return tid;
118 }
119 
122  m_currentRate(0)
123 {
124  NS_LOG_FUNCTION(this);
125 }
126 
128 {
129  NS_LOG_FUNCTION(this);
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION(this);
136  if (GetHtSupported())
137  {
138  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
139  }
140  if (GetVhtSupported())
141  {
142  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
143  }
144  if (GetHeSupported())
145  {
146  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
147  }
148 }
149 
152 {
153  NS_LOG_FUNCTION(this);
154  auto station = new AarfcdWifiRemoteStation();
155 
156  // AARF fields below
157  station->m_successThreshold = m_minSuccessThreshold;
158  station->m_timerTimeout = m_minTimerThreshold;
159  station->m_rate = 0;
160  station->m_success = 0;
161  station->m_failed = 0;
162  station->m_recovery = false;
163  station->m_timer = 0;
164 
165  // AARF-CD specific fields below
166  station->m_rtsOn = false;
167  station->m_rtsWnd = m_minRtsWnd;
168  station->m_rtsCounter = 0;
169  station->m_justModifyRate = true;
170  station->m_haveASuccess = false;
171 
172  return station;
173 }
174 
175 void
177 {
178  NS_LOG_FUNCTION(this << station);
179 }
180 
181 void
183 {
184  NS_LOG_FUNCTION(this << st);
185  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
186  station->m_timer++;
187  station->m_failed++;
188  station->m_success = 0;
189 
190  if (!station->m_rtsOn)
191  {
192  TurnOnRts(station);
193  if (!station->m_justModifyRate && !station->m_haveASuccess)
194  {
195  IncreaseRtsWnd(station);
196  }
197  else
198  {
199  ResetRtsWnd(station);
200  }
201  station->m_rtsCounter = station->m_rtsWnd;
202  if (station->m_failed >= 2)
203  {
204  station->m_timer = 0;
205  }
206  }
207  else if (station->m_recovery)
208  {
209  NS_ASSERT(station->m_failed >= 1);
210  station->m_justModifyRate = false;
211  station->m_rtsCounter = station->m_rtsWnd;
212  if (station->m_failed == 1)
213  {
214  // need recovery fallback
216  {
217  TurnOffRts(station);
218  }
219  station->m_justModifyRate = true;
220  station->m_successThreshold =
221  (int)(Min(station->m_successThreshold * m_successK, m_maxSuccessThreshold));
222  station->m_timerTimeout =
223  (int)(Max(station->m_timerTimeout * m_timerK, m_minSuccessThreshold));
224  if (station->m_rate != 0)
225  {
226  station->m_rate--;
227  }
228  }
229  station->m_timer = 0;
230  }
231  else
232  {
233  NS_ASSERT(station->m_failed >= 1);
234  station->m_justModifyRate = false;
235  station->m_rtsCounter = station->m_rtsWnd;
236  if (((station->m_failed - 1) % 2) == 1)
237  {
238  // need normal fallback
240  {
241  TurnOffRts(station);
242  }
243  station->m_justModifyRate = true;
244  station->m_timerTimeout = m_minTimerThreshold;
245  station->m_successThreshold = m_minSuccessThreshold;
246  if (station->m_rate != 0)
247  {
248  station->m_rate--;
249  }
250  }
251  if (station->m_failed >= 2)
252  {
253  station->m_timer = 0;
254  }
255  }
256  CheckRts(station);
257 }
258 
259 void
261 {
262  NS_LOG_FUNCTION(this << station << rxSnr << txMode);
263 }
264 
265 void
267  double ctsSnr,
268  WifiMode ctsMode,
269  double rtsSnr)
270 {
271  NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
272  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
273  NS_LOG_DEBUG("station=" << station << " rts ok");
274  station->m_rtsCounter--;
275 }
276 
277 void
279  double ackSnr,
280  WifiMode ackMode,
281  double dataSnr,
282  uint16_t dataChannelWidth,
283  uint8_t dataNss)
284 {
285  NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
286  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
287  station->m_timer++;
288  station->m_success++;
289  station->m_failed = 0;
290  station->m_recovery = false;
291  station->m_justModifyRate = false;
292  station->m_haveASuccess = true;
293  NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
294  << ", timer=" << station->m_timer);
295  if ((station->m_success == station->m_successThreshold ||
296  station->m_timer == station->m_timerTimeout) &&
297  (station->m_rate < (GetNSupported(station) - 1)))
298  {
299  NS_LOG_DEBUG("station=" << station << " inc rate");
300  station->m_rate++;
301  station->m_timer = 0;
302  station->m_success = 0;
303  station->m_recovery = true;
304  station->m_justModifyRate = true;
306  {
307  TurnOnRts(station);
308  ResetRtsWnd(station);
309  station->m_rtsCounter = station->m_rtsWnd;
310  }
311  }
312  CheckRts(station);
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION(this << station);
319 }
320 
321 void
323 {
324  NS_LOG_FUNCTION(this << station);
325 }
326 
329 {
330  NS_LOG_FUNCTION(this << st << allowedWidth);
331  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
332  uint16_t channelWidth = GetChannelWidth(station);
333  if (channelWidth > 20 && channelWidth != 22)
334  {
335  channelWidth = 20;
336  }
337  WifiMode mode = GetSupported(station, station->m_rate);
338  uint64_t rate = mode.GetDataRate(channelWidth);
339  if (m_currentRate != rate)
340  {
341  NS_LOG_DEBUG("New datarate: " << rate);
342  m_currentRate = rate;
343  }
344  return WifiTxVector(
345  mode,
348  800,
349  1,
350  1,
351  0,
352  channelWidth,
353  GetAggregation(station));
354 }
355 
358 {
359  NS_LOG_FUNCTION(this << st);
362  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
363  uint16_t channelWidth = GetChannelWidth(station);
364  if (channelWidth > 20 && channelWidth != 22)
365  {
366  channelWidth = 20;
367  }
368  WifiMode mode;
369  if (!GetUseNonErpProtection())
370  {
371  mode = GetSupported(station, 0);
372  }
373  else
374  {
375  mode = GetNonErpSupported(station, 0);
376  }
377  return WifiTxVector(
378  mode,
381  800,
382  1,
383  1,
384  0,
385  channelWidth,
386  GetAggregation(station));
387 }
388 
389 bool
390 AarfcdWifiManager::DoNeedRts(WifiRemoteStation* st, uint32_t size, bool normally)
391 {
392  NS_LOG_FUNCTION(this << st << size << normally);
393  auto station = static_cast<AarfcdWifiRemoteStation*>(st);
394  NS_LOG_INFO("" << station << " rate=" << station->m_rate
395  << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC")
396  << " rtsCounter=" << station->m_rtsCounter);
397  return station->m_rtsOn;
398 }
399 
400 void
402 {
403  NS_LOG_FUNCTION(this << station);
404  if (station->m_rtsCounter == 0 && station->m_rtsOn)
405  {
406  TurnOffRts(station);
407  }
408 }
409 
410 void
412 {
413  NS_LOG_FUNCTION(this << station);
414  station->m_rtsOn = false;
415  station->m_haveASuccess = false;
416 }
417 
418 void
420 {
421  NS_LOG_FUNCTION(this << station);
422  station->m_rtsOn = true;
423 }
424 
425 void
427 {
428  NS_LOG_FUNCTION(this << station);
429  if (station->m_rtsWnd == m_maxRtsWnd)
430  {
431  return;
432  }
433 
434  station->m_rtsWnd *= 2;
435  if (station->m_rtsWnd > m_maxRtsWnd)
436  {
437  station->m_rtsWnd = m_maxRtsWnd;
438  }
439 }
440 
441 void
443 {
444  NS_LOG_FUNCTION(this << station);
445  station->m_rtsWnd = m_minRtsWnd;
446 }
447 
448 } // namespace ns3
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 ...
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
static TypeId GetTypeId()
Get the type ID.
void DoReportRtsFailed(WifiRemoteStation *station) 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 DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) 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:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:51
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given 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.
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.
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:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:243
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:229
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
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:124
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
hold per-remote-station state for AARF-CD Wifi manager.
uint32_t m_rtsCounter
RTS counter.
uint32_t m_successThreshold
success threshold
bool m_justModifyRate
just modify rate
uint32_t m_timerTimeout
timer timeout
hold per-remote-station state.