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 "ns3/log.h"
22 #include "ns3/packet.h"
23 #include "aarfcd-wifi-manager.h"
24 #include "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 NS_LOG_COMPONENT_DEFINE ("AarfcdWifiManager");
32 
40 {
41  uint32_t m_timer;
42  uint32_t m_success;
43  uint32_t m_failed;
44  bool m_recovery;
46  uint32_t m_retry;
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 = TypeId ("ns3::AarfcdWifiManager")
63  .SetGroupName ("Wifi")
64  .AddConstructor<AarfcdWifiManager> ()
65  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
66  DoubleValue (2.0),
68  MakeDoubleChecker<double> ())
69  .AddAttribute ("TimerK",
70  "Multiplication factor for the timer threshold in the AARF algorithm.",
71  DoubleValue (2.0),
73  MakeDoubleChecker<double> ())
74  .AddAttribute ("MaxSuccessThreshold",
75  "Maximum value of the success threshold in the AARF algorithm.",
76  UintegerValue (60),
78  MakeUintegerChecker<uint32_t> ())
79  .AddAttribute ("MinTimerThreshold",
80  "The minimum value for the 'timer' threshold in the AARF algorithm.",
81  UintegerValue (15),
83  MakeUintegerChecker<uint32_t> ())
84  .AddAttribute ("MinSuccessThreshold",
85  "The minimum value for the success threshold in the AARF algorithm.",
86  UintegerValue (10),
88  MakeUintegerChecker<uint32_t> ())
89  .AddAttribute ("MinRtsWnd",
90  "Minimum value for Rts window of Aarf-CD",
91  UintegerValue (1),
93  MakeUintegerChecker<uint32_t> ())
94  .AddAttribute ("MaxRtsWnd",
95  "Maximum value for Rts window of Aarf-CD",
96  UintegerValue (40),
98  MakeUintegerChecker<uint32_t> ())
99  .AddAttribute ("TurnOffRtsAfterRateDecrease",
100  "If true the RTS mechanism will be turned off when the rate will be decreased",
101  BooleanValue (true),
104  .AddAttribute ("TurnOnRtsAfterRateIncrease",
105  "If true the RTS mechanism will be turned on when the rate will be increased",
106  BooleanValue (true),
109  .AddTraceSource ("Rate",
110  "Traced value for rate changes (b/s)",
112  "ns3::TracedValueCallback::Uint64")
113  ;
114  return tid;
115 }
116 
119  m_currentRate (0)
120 {
121  NS_LOG_FUNCTION (this);
122 }
123 
125 {
126  NS_LOG_FUNCTION (this);
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION (this);
133  if (GetHtSupported ())
134  {
135  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
136  }
137  if (GetVhtSupported ())
138  {
139  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
140  }
141  if (GetHeSupported ())
142  {
143  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
144  }
145 }
146 
149 {
150  NS_LOG_FUNCTION (this);
152 
153  //aarf fields below
156  station->m_rate = 0;
157  station->m_success = 0;
158  station->m_failed = 0;
159  station->m_recovery = false;
160  station->m_retry = 0;
161  station->m_timer = 0;
162 
163  //aarf-cd specific fields below
164  station->m_rtsOn = false;
165  station->m_rtsWnd = m_minRtsWnd;
166  station->m_rtsCounter = 0;
167  station->m_justModifyRate = true;
168  station->m_haveASuccess = false;
169 
170  return station;
171 }
172 
173 void
175 {
176  NS_LOG_FUNCTION (this << station);
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION (this << st);
184  station->m_timer++;
185  station->m_failed++;
186  station->m_retry++;
187  station->m_success = 0;
188 
189  if (!station->m_rtsOn)
190  {
191  TurnOnRts (station);
192  if (!station->m_justModifyRate && !station->m_haveASuccess)
193  {
194  IncreaseRtsWnd (station);
195  }
196  else
197  {
198  ResetRtsWnd (station);
199  }
200  station->m_rtsCounter = station->m_rtsWnd;
201  if (station->m_retry >= 2)
202  {
203  station->m_timer = 0;
204  }
205  }
206  else if (station->m_recovery)
207  {
208  NS_ASSERT (station->m_retry >= 1);
209  station->m_justModifyRate = false;
210  station->m_rtsCounter = station->m_rtsWnd;
211  if (station->m_retry == 1)
212  {
213  //need recovery fallback
215  {
216  TurnOffRts (station);
217  }
218  station->m_justModifyRate = true;
219  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
221  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
223  if (station->m_rate != 0)
224  {
225  station->m_rate--;
226  }
227  }
228  station->m_timer = 0;
229  }
230  else
231  {
232  NS_ASSERT (station->m_retry >= 1);
233  station->m_justModifyRate = false;
234  station->m_rtsCounter = station->m_rtsWnd;
235  if (((station->m_retry - 1) % 2) == 1)
236  {
237  //need normal fallback
239  {
240  TurnOffRts (station);
241  }
242  station->m_justModifyRate = true;
245  if (station->m_rate != 0)
246  {
247  station->m_rate--;
248  }
249  }
250  if (station->m_retry >= 2)
251  {
252  station->m_timer = 0;
253  }
254  }
255  CheckRts (station);
256 }
257 
258 void
260  double rxSnr, WifiMode txMode)
261 {
262  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
263 }
264 
265 void
267  double ctsSnr, WifiMode ctsMode, double rtsSnr)
268 {
269  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
271  NS_LOG_DEBUG ("station=" << station << " rts ok");
272  station->m_rtsCounter--;
273 }
274 
275 void
277  double ackSnr, WifiMode ackMode, double dataSnr)
278 {
279  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
281  station->m_timer++;
282  station->m_success++;
283  station->m_failed = 0;
284  station->m_recovery = false;
285  station->m_retry = 0;
286  station->m_justModifyRate = false;
287  station->m_haveASuccess = true;
288  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
289  if ((station->m_success == station->m_successThreshold
290  || station->m_timer == station->m_timerTimeout)
291  && (station->m_rate < (GetNSupported (station) - 1)))
292  {
293  NS_LOG_DEBUG ("station=" << station << " inc rate");
294  station->m_rate++;
295  station->m_timer = 0;
296  station->m_success = 0;
297  station->m_recovery = true;
298  station->m_justModifyRate = true;
300  {
301  TurnOnRts (station);
302  ResetRtsWnd (station);
303  station->m_rtsCounter = station->m_rtsWnd;
304  }
305  }
306  CheckRts (station);
307 }
308 
309 void
311 {
312  NS_LOG_FUNCTION (this << station);
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION (this << station);
319 }
320 
323 {
324  NS_LOG_FUNCTION (this << st);
326  uint16_t channelWidth = GetChannelWidth (station);
327  if (channelWidth > 20 && channelWidth != 22)
328  {
329  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
330  channelWidth = 20;
331  }
332  WifiMode mode = GetSupported (station, station->m_rate);
333  if (m_currentRate != mode.GetDataRate (channelWidth))
334  {
335  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
336  m_currentRate = mode.GetDataRate (channelWidth);
337  }
338  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
339 }
340 
343 {
344  NS_LOG_FUNCTION (this << st);
348  uint16_t channelWidth = GetChannelWidth (station);
349  if (channelWidth > 20 && channelWidth != 22)
350  {
351  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
352  channelWidth = 20;
353  }
354  WifiTxVector rtsTxVector;
355  WifiMode mode;
356  if (GetUseNonErpProtection () == false)
357  {
358  mode = GetSupported (station, 0);
359  }
360  else
361  {
362  mode = GetNonErpSupported (station, 0);
363  }
364  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
365  return rtsTxVector;
366 }
367 
368 bool
370  Ptr<const Packet> packet, bool normally)
371 {
372  NS_LOG_FUNCTION (this << st << packet << normally);
374  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
375  " rtsCounter=" << station->m_rtsCounter);
376  return station->m_rtsOn;
377 }
378 
379 bool
381 {
382  return true;
383 }
384 
385 void
387 {
388  NS_LOG_FUNCTION (this << station);
389  if (station->m_rtsCounter == 0 && station->m_rtsOn)
390  {
391  TurnOffRts (station);
392  }
393 }
394 
395 void
397 {
398  NS_LOG_FUNCTION (this << station);
399  station->m_rtsOn = false;
400  station->m_haveASuccess = false;
401 }
402 
403 void
405 {
406  NS_LOG_FUNCTION (this << station);
407  station->m_rtsOn = true;
408 }
409 
410 void
412 {
413  NS_LOG_FUNCTION (this << station);
414  if (station->m_rtsWnd == m_maxRtsWnd)
415  {
416  return;
417  }
418 
419  station->m_rtsWnd *= 2;
420  if (station->m_rtsWnd > m_maxRtsWnd)
421  {
422  station->m_rtsWnd = m_maxRtsWnd;
423  }
424 }
425 
426 void
428 {
429  NS_LOG_FUNCTION (this << station);
430  station->m_rtsWnd = m_minRtsWnd;
431 }
432 
433 } //namespace ns3
WifiRemoteStation * DoCreateStation(void) const
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
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
#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)
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given 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
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
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
#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:204
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:280
#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
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
Definition: wifi-utils.cc:128
bool m_turnOnRtsAfterRateIncrease
turn on RTS after rate increase
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
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.
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.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP preambles.
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
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
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.
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:494
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 UseGreenfieldForDestination(Mac48Address dest) const
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
void DoInitialize(void)
Initialize() implementation.
void DoReportRtsFailed(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.
uint32_t m_minSuccessThreshold
minimum success threshold
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.
uint32_t m_minTimerThreshold
minimum timer threshold
bool m_turnOffRtsAfterRateDecrease
turn off RTS after rate decrease
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
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:272
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 &#39;double&#39; or &#39;float&#39;...
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:915
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:150
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)