A Discrete-Event Network Simulator
API
aarfcd-wifi-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2004,2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Federico Maguolo <maguolof@dei.unipd.it>
19  */
20 
21 #include "aarfcd-wifi-manager.h"
22 #include "ns3/log.h"
23 #include "ns3/boolean.h"
24 #include "ns3/double.h"
25 #include "ns3/uinteger.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 #define Max(a,b) ((a > b) ? a : b)
29 
30 namespace ns3 {
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_retry;
48  uint32_t m_successThreshold;
49  uint32_t m_timerTimeout;
50  uint32_t m_rate;
51  bool m_rtsOn;
52  uint32_t m_rtsWnd;
53  uint32_t m_rtsCounter;
55 };
56 
58 
59 TypeId
61 {
62  static TypeId tid = TypeId ("ns3::AarfcdWifiManager")
64  .SetGroupName ("Wifi")
65  .AddConstructor<AarfcdWifiManager> ()
66  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
67  DoubleValue (2.0),
69  MakeDoubleChecker<double> ())
70  .AddAttribute ("TimerK",
71  "Multiplication factor for the timer threshold in the AARF algorithm.",
72  DoubleValue (2.0),
74  MakeDoubleChecker<double> ())
75  .AddAttribute ("MaxSuccessThreshold",
76  "Maximum value of the success threshold in the AARF algorithm.",
77  UintegerValue (60),
79  MakeUintegerChecker<uint32_t> ())
80  .AddAttribute ("MinTimerThreshold",
81  "The minimum value for the 'timer' threshold in the AARF algorithm.",
82  UintegerValue (15),
84  MakeUintegerChecker<uint32_t> ())
85  .AddAttribute ("MinSuccessThreshold",
86  "The minimum value for the success threshold in the AARF algorithm.",
87  UintegerValue (10),
89  MakeUintegerChecker<uint32_t> ())
90  .AddAttribute ("MinRtsWnd",
91  "Minimum value for Rts window of Aarf-CD",
92  UintegerValue (1),
94  MakeUintegerChecker<uint32_t> ())
95  .AddAttribute ("MaxRtsWnd",
96  "Maximum value for Rts window of Aarf-CD",
97  UintegerValue (40),
99  MakeUintegerChecker<uint32_t> ())
100  .AddAttribute ("TurnOffRtsAfterRateDecrease",
101  "If true the RTS mechanism will be turned off when the rate will be decreased",
102  BooleanValue (true),
105  .AddAttribute ("TurnOnRtsAfterRateIncrease",
106  "If true the RTS mechanism will be turned on when the rate will be increased",
107  BooleanValue (true),
110  .AddTraceSource ("Rate",
111  "Traced value for rate changes (b/s)",
113  "ns3::TracedValueCallback::Uint64")
114  ;
115  return tid;
116 }
117 
120  m_currentRate (0)
121 
122 {
123  NS_LOG_FUNCTION (this);
124 }
125 
127 {
128  NS_LOG_FUNCTION (this);
129 }
130 
133 {
134  NS_LOG_FUNCTION (this);
136 
137  //aarf fields below
140  station->m_rate = 0;
141  station->m_success = 0;
142  station->m_failed = 0;
143  station->m_recovery = false;
144  station->m_retry = 0;
145  station->m_timer = 0;
146 
147  //aarf-cd specific fields below
148  station->m_rtsOn = false;
149  station->m_rtsWnd = m_minRtsWnd;
150  station->m_rtsCounter = 0;
151  station->m_justModifyRate = true;
152  station->m_haveASuccess = false;
153 
154  return station;
155 }
156 
157 void
159 {
160  NS_LOG_FUNCTION (this << station);
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this << st);
168  station->m_timer++;
169  station->m_failed++;
170  station->m_retry++;
171  station->m_success = 0;
172 
173  if (!station->m_rtsOn)
174  {
175  TurnOnRts (station);
176  if (!station->m_justModifyRate && !station->m_haveASuccess)
177  {
178  IncreaseRtsWnd (station);
179  }
180  else
181  {
182  ResetRtsWnd (station);
183  }
184  station->m_rtsCounter = station->m_rtsWnd;
185  if (station->m_retry >= 2)
186  {
187  station->m_timer = 0;
188  }
189  }
190  else if (station->m_recovery)
191  {
192  NS_ASSERT (station->m_retry >= 1);
193  station->m_justModifyRate = false;
194  station->m_rtsCounter = station->m_rtsWnd;
195  if (station->m_retry == 1)
196  {
197  //need recovery fallback
199  {
200  TurnOffRts (station);
201  }
202  station->m_justModifyRate = true;
203  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
205  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
207  if (station->m_rate != 0)
208  {
209  station->m_rate--;
210  }
211  }
212  station->m_timer = 0;
213  }
214  else
215  {
216  NS_ASSERT (station->m_retry >= 1);
217  station->m_justModifyRate = false;
218  station->m_rtsCounter = station->m_rtsWnd;
219  if (((station->m_retry - 1) % 2) == 1)
220  {
221  //need normal fallback
223  {
224  TurnOffRts (station);
225  }
226  station->m_justModifyRate = true;
229  if (station->m_rate != 0)
230  {
231  station->m_rate--;
232  }
233  }
234  if (station->m_retry >= 2)
235  {
236  station->m_timer = 0;
237  }
238  }
239  CheckRts (station);
240 }
241 
242 void
244  double rxSnr, WifiMode txMode)
245 {
246  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
247 }
248 
249 void
251  double ctsSnr, WifiMode ctsMode, double rtsSnr)
252 {
253  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
255  NS_LOG_DEBUG ("station=" << station << " rts ok");
256  station->m_rtsCounter--;
257 }
258 
259 void
261  double ackSnr, WifiMode ackMode, double dataSnr)
262 {
263  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
265  station->m_timer++;
266  station->m_success++;
267  station->m_failed = 0;
268  station->m_recovery = false;
269  station->m_retry = 0;
270  station->m_justModifyRate = false;
271  station->m_haveASuccess = true;
272  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
273  if ((station->m_success == station->m_successThreshold
274  || station->m_timer == station->m_timerTimeout)
275  && (station->m_rate < (GetNSupported (station) - 1)))
276  {
277  NS_LOG_DEBUG ("station=" << station << " inc rate");
278  station->m_rate++;
279  station->m_timer = 0;
280  station->m_success = 0;
281  station->m_recovery = true;
282  station->m_justModifyRate = true;
284  {
285  TurnOnRts (station);
286  ResetRtsWnd (station);
287  station->m_rtsCounter = station->m_rtsWnd;
288  }
289  }
290  CheckRts (station);
291 }
292 
293 void
295 {
296  NS_LOG_FUNCTION (this << station);
297 }
298 
299 void
301 {
302  NS_LOG_FUNCTION (this << station);
303 }
304 
307 {
308  NS_LOG_FUNCTION (this << st);
310  uint32_t channelWidth = GetChannelWidth (station);
311  if (channelWidth > 20 && channelWidth != 22)
312  {
313  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
314  channelWidth = 20;
315  }
316  WifiMode mode = GetSupported (station, station->m_rate);
317  if (m_currentRate != mode.GetDataRate (channelWidth))
318  {
319  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
320  m_currentRate = mode.GetDataRate (channelWidth);
321  }
322  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
323 }
324 
327 {
328  NS_LOG_FUNCTION (this << st);
332  uint32_t channelWidth = GetChannelWidth (station);
333  if (channelWidth > 20 && channelWidth != 22)
334  {
335  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
336  channelWidth = 20;
337  }
338  WifiTxVector rtsTxVector;
339  WifiMode mode;
340  if (GetUseNonErpProtection () == false)
341  {
342  mode = GetSupported (station, 0);
343  }
344  else
345  {
346  mode = GetNonErpSupported (station, 0);
347  }
348  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetShortRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
349  return rtsTxVector;
350 }
351 
352 bool
354  Ptr<const Packet> packet, bool normally)
355 {
356  NS_LOG_FUNCTION (this << st << packet << normally);
358  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
359  " rtsCounter=" << station->m_rtsCounter);
360  return station->m_rtsOn;
361 }
362 
363 bool
365 {
366  NS_LOG_FUNCTION (this);
367  return true;
368 }
369 
370 void
372 {
373  NS_LOG_FUNCTION (this << station);
374  if (station->m_rtsCounter == 0 && station->m_rtsOn)
375  {
376  TurnOffRts (station);
377  }
378 }
379 
380 void
382 {
383  NS_LOG_FUNCTION (this << station);
384  station->m_rtsOn = false;
385  station->m_haveASuccess = false;
386 }
387 
388 void
390 {
391  NS_LOG_FUNCTION (this << station);
392  station->m_rtsOn = true;
393 }
394 
395 void
397 {
398  NS_LOG_FUNCTION (this << station);
399  if (station->m_rtsWnd == m_maxRtsWnd)
400  {
401  return;
402  }
403 
404  station->m_rtsWnd *= 2;
405  if (station->m_rtsWnd > m_maxRtsWnd)
406  {
407  station->m_rtsWnd = m_maxRtsWnd;
408  }
409 }
410 
411 void
413 {
414  NS_LOG_FUNCTION (this << station);
415  station->m_rtsWnd = m_minRtsWnd;
416 }
417 
418 void
420 {
421  //HT is not supported by this algorithm.
422  if (enable)
423  {
424  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
425  }
426 }
427 
428 void
430 {
431  //VHT is not supported by this algorithm.
432  if (enable)
433  {
434  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
435  }
436 }
437 
438 void
440 {
441  //HE is not supported by this algorithm.
442  if (enable)
443  {
444  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
445  }
446 }
447 
448 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
uint32_t m_successThreshold
success threshold
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
AttributeValue implementation for Boolean.
Definition: boolean.h:36
double m_timerK
Multiplication factor for the timer threshold.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
bool m_justModifyRate
just modify rate
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t m_rtsCounter
RTS counter.
bool m_haveASuccess
have a success
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
uint32_t m_maxSuccessThreshold
maximum success threshold
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
uint32_t m_maxRtsWnd
maximum RTS window
uint32_t m_minRtsWnd
minimum RTS window
bool m_turnOnRtsAfterRateIncrease
turn on RTS after rate increase
void SetHeSupported(bool enable)
Enable or disable HE capability support.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void TurnOnRts(AarfcdWifiRemoteStation *station)
Turn on RTS for the given station.
void TurnOffRts(AarfcdWifiRemoteStation *station)
Turn off RTS for the given station.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
uint8_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
TracedValue< uint64_t > m_currentRate
Trace rate changes.
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
Reset the RTS window of the given station.
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
hold a list of per-remote-station state.
void CheckRts(AarfcdWifiRemoteStation *station)
Check if the use of RTS for the given station can be turned off.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
bool IsLowLatency(void) const
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_minSuccessThreshold
minimum success threshold
WifiRemoteStation * DoCreateStation(void) const
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
hold per-remote-station state for AARF-CD Wifi manager.
void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t m_minTimerThreshold
minimum timer threshold
bool m_turnOffRtsAfterRateDecrease
turn off RTS after rate decrease
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
double m_successK
Multiplication factor for the success threshold.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
static TypeId GetTypeId(void)
Get the type ID.
an implementation of the AARF-CD algorithmThis algorithm was first described in "Efficient Collision ...
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
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)
This method is a pure virtual method that must be implemented by the sub-class.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void IncreaseRtsWnd(AarfcdWifiRemoteStation *station)
Increase the RTS window size of the given station.
uint32_t m_timerTimeout
timer timeout
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
hold per-remote-station state.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)