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/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/simulator.h"
25 #include "ns3/boolean.h"
26 #include "ns3/double.h"
27 #include "ns3/uinteger.h"
28 #include <algorithm>
29 
30 #define Min(a,b) ((a < b) ? a : b)
31 #define Max(a,b) ((a > b) ? a : b)
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("Aarfcd");
36 
44 {
45  uint32_t m_timer;
46  uint32_t m_success;
47  uint32_t m_failed;
48  bool m_recovery;
50  uint32_t m_retry;
52  uint32_t m_timerTimeout;
53  uint32_t m_rate;
54  bool m_rtsOn;
55  uint32_t m_rtsWnd;
56  uint32_t m_rtsCounter;
58 };
59 
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::AarfcdWifiManager")
67  .SetGroupName ("Wifi")
68  .AddConstructor<AarfcdWifiManager> ()
69  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
70  DoubleValue (2.0),
72  MakeDoubleChecker<double> ())
73  .AddAttribute ("TimerK",
74  "Multiplication factor for the timer threshold in the AARF algorithm.",
75  DoubleValue (2.0),
77  MakeDoubleChecker<double> ())
78  .AddAttribute ("MaxSuccessThreshold",
79  "Maximum value of the success threshold in the AARF algorithm.",
80  UintegerValue (60),
82  MakeUintegerChecker<uint32_t> ())
83  .AddAttribute ("MinTimerThreshold",
84  "The minimum value for the 'timer' threshold in the AARF algorithm.",
85  UintegerValue (15),
87  MakeUintegerChecker<uint32_t> ())
88  .AddAttribute ("MinSuccessThreshold",
89  "The minimum value for the success threshold in the AARF algorithm.",
90  UintegerValue (10),
92  MakeUintegerChecker<uint32_t> ())
93  .AddAttribute ("MinRtsWnd",
94  "Minimum value for Rts window of Aarf-CD",
95  UintegerValue (1),
97  MakeUintegerChecker<uint32_t> ())
98  .AddAttribute ("MaxRtsWnd",
99  "Maximum value for Rts window of Aarf-CD",
100  UintegerValue (40),
102  MakeUintegerChecker<uint32_t> ())
103  .AddAttribute ("TurnOffRtsAfterRateDecrease",
104  "If true the RTS mechanism will be turned off when the rate will be decreased",
105  BooleanValue (true),
108  .AddAttribute ("TurnOnRtsAfterRateIncrease",
109  "If true the RTS mechanism will be turned on when the rate will be increased",
110  BooleanValue (true),
113  ;
114  return tid;
115 }
116 
119 {
120  NS_LOG_FUNCTION (this);
121 }
122 
124 {
125  NS_LOG_FUNCTION (this);
126 }
127 
130 {
131  NS_LOG_FUNCTION (this);
133 
134  //aarf fields below
137  station->m_rate = 0;
138  station->m_success = 0;
139  station->m_failed = 0;
140  station->m_recovery = false;
141  station->m_retry = 0;
142  station->m_timer = 0;
143 
144  //aarf-cd specific fields below
145  station->m_rtsOn = false;
146  station->m_rtsWnd = m_minRtsWnd;
147  station->m_rtsCounter = 0;
148  station->m_justModifyRate = true;
149  station->m_haveASuccess = false;
150 
151  return station;
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this << station);
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION (this << st);
165  station->m_timer++;
166  station->m_failed++;
167  station->m_retry++;
168  station->m_success = 0;
169 
170  if (!station->m_rtsOn)
171  {
172  TurnOnRts (station);
173  if (!station->m_justModifyRate && !station->m_haveASuccess)
174  {
175  IncreaseRtsWnd (station);
176  }
177  else
178  {
179  ResetRtsWnd (station);
180  }
181  station->m_rtsCounter = station->m_rtsWnd;
182  if (station->m_retry >= 2)
183  {
184  station->m_timer = 0;
185  }
186  }
187  else if (station->m_recovery)
188  {
189  NS_ASSERT (station->m_retry >= 1);
190  station->m_justModifyRate = false;
191  station->m_rtsCounter = station->m_rtsWnd;
192  if (station->m_retry == 1)
193  {
194  //need recovery fallback
196  {
197  TurnOffRts (station);
198  }
199  station->m_justModifyRate = true;
200  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
202  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
204  if (station->m_rate != 0)
205  {
206  station->m_rate--;
207  }
208  }
209  station->m_timer = 0;
210  }
211  else
212  {
213  NS_ASSERT (station->m_retry >= 1);
214  station->m_justModifyRate = false;
215  station->m_rtsCounter = station->m_rtsWnd;
216  if (((station->m_retry - 1) % 2) == 1)
217  {
218  //need normal fallback
220  {
221  TurnOffRts (station);
222  }
223  station->m_justModifyRate = true;
226  if (station->m_rate != 0)
227  {
228  station->m_rate--;
229  }
230  }
231  if (station->m_retry >= 2)
232  {
233  station->m_timer = 0;
234  }
235  }
236  CheckRts (station);
237 }
238 
239 void
241  double rxSnr, WifiMode txMode)
242 {
243  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
244 }
245 
246 void
248  double ctsSnr, WifiMode ctsMode, double rtsSnr)
249 {
250  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
252  NS_LOG_DEBUG ("station=" << station << " rts ok");
253  station->m_rtsCounter--;
254 }
255 
256 void
258  double ackSnr, WifiMode ackMode, double dataSnr)
259 {
260  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
262  station->m_timer++;
263  station->m_success++;
264  station->m_failed = 0;
265  station->m_recovery = false;
266  station->m_retry = 0;
267  station->m_justModifyRate = false;
268  station->m_haveASuccess = true;
269  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
270  if ((station->m_success == station->m_successThreshold
271  || station->m_timer == station->m_timerTimeout)
272  && (station->m_rate < (GetNSupported (station) - 1)))
273  {
274  NS_LOG_DEBUG ("station=" << station << " inc rate");
275  station->m_rate++;
276  station->m_timer = 0;
277  station->m_success = 0;
278  station->m_recovery = true;
279  station->m_justModifyRate = true;
281  {
282  TurnOnRts (station);
283  ResetRtsWnd (station);
284  station->m_rtsCounter = station->m_rtsWnd;
285  }
286  }
287  CheckRts (station);
288 }
289 
290 void
292 {
293  NS_LOG_FUNCTION (this << station);
294 }
295 
296 void
298 {
299  NS_LOG_FUNCTION (this << station);
300 }
301 
304 {
305  NS_LOG_FUNCTION (this << st);
307  uint32_t channelWidth = GetChannelWidth (station);
308  if (channelWidth > 20 && channelWidth != 22)
309  {
310  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
311  channelWidth = 20;
312  }
313  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
314 }
315 
318 {
319  NS_LOG_FUNCTION (this << st);
323  uint32_t channelWidth = GetChannelWidth (station);
324  if (channelWidth > 20 && channelWidth != 22)
325  {
326  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
327  channelWidth = 20;
328  }
329  WifiTxVector rtsTxVector;
330  if (GetUseNonErpProtection () == false)
331  {
332  rtsTxVector = WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
333  }
334  else
335  {
336  rtsTxVector = WifiTxVector (GetNonErpSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
337  }
338  return rtsTxVector;
339 }
340 
341 bool
343  Ptr<const Packet> packet, bool normally)
344 {
345  NS_LOG_FUNCTION (this << st << packet << normally);
347  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
348  " rtsCounter=" << station->m_rtsCounter);
349  return station->m_rtsOn;
350 }
351 
352 bool
354 {
355  NS_LOG_FUNCTION (this);
356  return true;
357 }
358 
359 void
361 {
362  NS_LOG_FUNCTION (this << station);
363  if (station->m_rtsCounter == 0 && station->m_rtsOn)
364  {
365  TurnOffRts (station);
366  }
367 }
368 
369 void
371 {
372  NS_LOG_FUNCTION (this << station);
373  station->m_rtsOn = false;
374  station->m_haveASuccess = false;
375 }
376 
377 void
379 {
380  NS_LOG_FUNCTION (this << station);
381  station->m_rtsOn = true;
382 }
383 
384 void
386 {
387  NS_LOG_FUNCTION (this << station);
388  if (station->m_rtsWnd == m_maxRtsWnd)
389  {
390  return;
391  }
392 
393  station->m_rtsWnd *= 2;
394  if (station->m_rtsWnd > m_maxRtsWnd)
395  {
396  station->m_rtsWnd = m_maxRtsWnd;
397  }
398 }
399 
400 void
402 {
403  NS_LOG_FUNCTION (this << station);
404  station->m_rtsWnd = m_minRtsWnd;
405 }
406 
407 void
409 {
410  //HT is not supported by this algorithm.
411  if (enable)
412  {
413  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
414  }
415 }
416 
417 void
419 {
420  //VHT is not supported by this algorithm.
421  if (enable)
422  {
423  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
424  }
425 }
426 
427 
428 
429 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
virtual void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
AttributeValue implementation for Boolean.
Definition: boolean.h:34
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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:81
#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
virtual 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:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
virtual 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. ...
virtual 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...
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
Reset the RTS window of the given 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
virtual bool IsLowLatency(void) const
virtual void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
virtual 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.
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
static TypeId GetTypeId(void)
an implementation of the AARF-CD algorithmThis algorithm was first described in "Efficient Collision ...
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
virtual 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.
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:904
hold per-remote-station state.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)