A Discrete-Event Network Simulator
API
aarf-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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "aarf-wifi-manager.h"
22 #include "ns3/double.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/log.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 ("AarfWifiManager");
32 
40 {
41  uint32_t m_timer;
42  uint32_t m_success;
43  uint32_t m_failed;
44  bool m_recovery;
45  uint32_t m_retry;
46  uint32_t m_timerTimeout;
47  uint32_t m_successThreshold;
48  uint32_t m_rate;
49 };
50 
52 
53 TypeId
55 {
56  static TypeId tid = TypeId ("ns3::AarfWifiManager")
58  .SetGroupName ("Wifi")
59  .AddConstructor<AarfWifiManager> ()
60  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
61  DoubleValue (2.0),
63  MakeDoubleChecker<double> ())
64  .AddAttribute ("TimerK",
65  "Multiplication factor for the timer threshold in the AARF algorithm.",
66  DoubleValue (2.0),
68  MakeDoubleChecker<double> ())
69  .AddAttribute ("MaxSuccessThreshold",
70  "Maximum value of the success threshold in the AARF algorithm.",
71  UintegerValue (60),
73  MakeUintegerChecker<uint32_t> ())
74  .AddAttribute ("MinTimerThreshold",
75  "The minimum value for the 'timer' threshold in the AARF algorithm.",
76  UintegerValue (15),
78  MakeUintegerChecker<uint32_t> ())
79  .AddAttribute ("MinSuccessThreshold",
80  "The minimum value for the success threshold in the AARF algorithm.",
81  UintegerValue (10),
83  MakeUintegerChecker<uint32_t> ())
84  .AddTraceSource ("Rate",
85  "Traced value for rate changes (b/s)",
87  "ns3::TracedValueCallback::Uint64")
88  ;
89  return tid;
90 }
91 
94  m_currentRate (0)
95 {
96  NS_LOG_FUNCTION (this);
97 }
98 
100 {
101  NS_LOG_FUNCTION (this);
102 }
103 
106 {
107  NS_LOG_FUNCTION (this);
109 
112  station->m_rate = 0;
113  station->m_success = 0;
114  station->m_failed = 0;
115  station->m_recovery = false;
116  station->m_retry = 0;
117  station->m_timer = 0;
118 
119  return station;
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << station);
126 }
138 void
140 {
141  NS_LOG_FUNCTION (this << st);
143  station->m_timer++;
144  station->m_failed++;
145  station->m_retry++;
146  station->m_success = 0;
147 
148  if (station->m_recovery)
149  {
150  NS_ASSERT (station->m_retry >= 1);
151  if (station->m_retry == 1)
152  {
153  //need recovery fallback
154  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
156  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
158  if (station->m_rate != 0)
159  {
160  station->m_rate--;
161  }
162  }
163  station->m_timer = 0;
164  }
165  else
166  {
167  NS_ASSERT (station->m_retry >= 1);
168  if (((station->m_retry - 1) % 2) == 1)
169  {
170  //need normal fallback
173  if (station->m_rate != 0)
174  {
175  station->m_rate--;
176  }
177  }
178  if (station->m_retry >= 2)
179  {
180  station->m_timer = 0;
181  }
182  }
183 }
184 
185 void
187  double rxSnr, WifiMode txMode)
188 {
189  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
190 }
191 
192 void
194  double ctsSnr, WifiMode ctsMode, double rtsSnr)
195 {
196  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
197  NS_LOG_DEBUG ("station=" << station << " rts ok");
198 }
199 
200 void
202  double ackSnr, WifiMode ackMode, double dataSnr)
203 {
204  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
206  station->m_timer++;
207  station->m_success++;
208  station->m_failed = 0;
209  station->m_recovery = false;
210  station->m_retry = 0;
211  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
212  if ((station->m_success == station->m_successThreshold
213  || station->m_timer == station->m_timerTimeout)
214  && (station->m_rate < (GetNSupported (station) - 1)))
215  {
216  NS_LOG_DEBUG ("station=" << station << " inc rate");
217  station->m_rate++;
218  station->m_timer = 0;
219  station->m_success = 0;
220  station->m_recovery = true;
221  }
222 }
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << station);
228 }
229 
230 void
232 {
233  NS_LOG_FUNCTION (this << station);
234 }
235 
238 {
239  NS_LOG_FUNCTION (this << st);
241  uint32_t channelWidth = GetChannelWidth (station);
242  if (channelWidth > 20 && channelWidth != 22)
243  {
244  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
245  channelWidth = 20;
246  }
247  WifiMode mode = GetSupported (station, station->m_rate);
248  if (m_currentRate != mode.GetDataRate (channelWidth))
249  {
250  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
251  m_currentRate = mode.GetDataRate (channelWidth);
252  }
253  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
254 }
255 
258 {
259  NS_LOG_FUNCTION (this << st);
263  uint32_t channelWidth = GetChannelWidth (station);
264  if (channelWidth > 20 && channelWidth != 22)
265  {
266  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
267  channelWidth = 20;
268  }
269  WifiTxVector rtsTxVector;
270  WifiMode mode;
271  if (GetUseNonErpProtection () == false)
272  {
273  mode = GetSupported (station, 0);
274  }
275  else
276  {
277  mode = GetNonErpSupported (station, 0);
278  }
279  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
280  return rtsTxVector;
281 }
282 
283 bool
285 {
286  NS_LOG_FUNCTION (this);
287  return true;
288 }
289 
290 void
292 {
293  //HT is not supported by this algorithm.
294  if (enable)
295  {
296  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
297  }
298 }
299 
300 void
302 {
303  //VHT is not supported by this algorithm.
304  if (enable)
305  {
306  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
307  }
308 }
309 
310 void
312 {
313  //HE is not supported by this algorithm.
314  if (enable)
315  {
316  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
317  }
318 }
319 
320 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
uint32_t m_minSuccessThreshold
minimum success threshold
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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_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
#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:97
void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
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 DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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...
bool IsLowLatency(void) const
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
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
uint32_t m_minTimerThreshold
minimum timer threshold
hold a list of per-remote-station state.
AARF Rate control algorithmThis class implements the AARF rate control algorithm which was initially ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_timerK
Multiplication factor for the timer threshold.
void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t m_successThreshold
success threshold
void SetHeSupported(bool enable)
Enable or disable HE capability support.
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 Wifi manager.
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.
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:269
TracedValue< uint64_t > m_currentRate
Trace rate changes.
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_timerTimeout
timer timeout
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
WifiRemoteStation * DoCreateStation(void) const
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
uint32_t m_maxSuccessThreshold
maximum success threshold
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
hold per-remote-station state.
static TypeId GetTypeId(void)
Get the type ID.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)