A Discrete-Event Network Simulator
API
amrr-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) 2003,2007 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 "amrr-wifi-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/double.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("AmrrWifiRemoteStation");
32 
40 {
42  uint32_t m_tx_ok;
43  uint32_t m_tx_err;
44  uint32_t m_tx_retr;
45  uint32_t m_retry;
46  uint32_t m_txrate;
48  uint32_t m_success;
49  bool m_recovery;
50 };
51 
52 
54 
55 TypeId
57 {
58  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
60  .SetGroupName ("Wifi")
61  .AddConstructor<AmrrWifiManager> ()
62  .AddAttribute ("UpdatePeriod",
63  "The interval between decisions about rate control changes",
64  TimeValue (Seconds (1.0)),
66  MakeTimeChecker ())
67  .AddAttribute ("FailureRatio",
68  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
69  DoubleValue (1.0 / 3.0),
71  MakeDoubleChecker<double> (0.0, 1.0))
72  .AddAttribute ("SuccessRatio",
73  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
74  DoubleValue (1.0 / 10.0),
76  MakeDoubleChecker<double> (0.0, 1.0))
77  .AddAttribute ("MaxSuccessThreshold",
78  "Maximum number of consecutive success periods needed to switch to a higher rate",
79  UintegerValue (10),
81  MakeUintegerChecker<uint32_t> ())
82  .AddAttribute ("MinSuccessThreshold",
83  "Minimum number of consecutive success periods needed to switch to a higher rate",
84  UintegerValue (1),
86  MakeUintegerChecker<uint32_t> ())
87  ;
88  return tid;
89 }
90 
92 {
93  NS_LOG_FUNCTION (this);
94 }
95 
98 {
99  NS_LOG_FUNCTION (this);
102  station->m_tx_ok = 0;
103  station->m_tx_err = 0;
104  station->m_tx_retr = 0;
105  station->m_retry = 0;
106  station->m_txrate = 0;
108  station->m_success = 0;
109  station->m_recovery = false;
110  return station;
111 }
112 
113 void
115  double rxSnr, WifiMode txMode)
116 {
117  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION (this << station);
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << st);
131  station->m_retry++;
132  station->m_tx_retr++;
133 }
134 
135 void
137  double ctsSnr, WifiMode ctsMode, double rtsSnr)
138 {
139  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
140 }
141 
142 void
144  double ackSnr, WifiMode ackMode, double dataSnr)
145 {
146  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
148  station->m_retry = 0;
149  station->m_tx_ok++;
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this << station);
156 }
157 
158 void
160 {
161  NS_LOG_FUNCTION (this << st);
163  station->m_retry = 0;
164  station->m_tx_err++;
165 }
166 
167 bool
169 {
170  NS_LOG_FUNCTION (this << station);
171  return (station->m_txrate == 0);
172 }
173 
174 bool
176 {
177  NS_LOG_FUNCTION (this << station);
178  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
179  return (station->m_txrate + 1 == GetNSupported (station));
180 }
181 
182 bool
184 {
185  NS_LOG_FUNCTION (this << station);
186  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
187 }
188 
189 bool
191 {
192  NS_LOG_FUNCTION (this << station);
193  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
194 }
195 
196 bool
198 {
199  NS_LOG_FUNCTION (this << station);
200  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
201 }
202 
203 void
205 {
206  NS_LOG_FUNCTION (this << station);
207  station->m_tx_ok = 0;
208  station->m_tx_err = 0;
209  station->m_tx_retr = 0;
210 }
211 
212 void
214 {
215  NS_LOG_FUNCTION (this << station);
216  station->m_txrate++;
217  NS_ASSERT (station->m_txrate < GetNSupported (station));
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION (this << station);
224  station->m_txrate--;
225 }
226 
227 void
229 {
230  NS_LOG_FUNCTION (this << station);
231  if (Simulator::Now () < station->m_nextModeUpdate)
232  {
233  return;
234  }
236  NS_LOG_DEBUG ("Update");
237 
238  bool needChange = false;
239 
240  if (IsSuccess (station) && IsEnough (station))
241  {
242  station->m_success++;
243  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
244  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
245  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
246  if (station->m_success >= station->m_successThreshold
247  && !IsMaxRate (station))
248  {
249  station->m_recovery = true;
250  station->m_success = 0;
251  IncreaseRate (station);
252  needChange = true;
253  }
254  else
255  {
256  station->m_recovery = false;
257  }
258  }
259  else if (IsFailure (station))
260  {
261  station->m_success = 0;
262  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
263  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
264  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
265  if (!IsMinRate (station))
266  {
267  if (station->m_recovery)
268  {
269  station->m_successThreshold *= 2;
270  station->m_successThreshold = std::min (station->m_successThreshold,
272  }
273  else
274  {
276  }
277  station->m_recovery = false;
278  DecreaseRate (station);
279  needChange = true;
280  }
281  else
282  {
283  station->m_recovery = false;
284  }
285  }
286  if (IsEnough (station) || needChange)
287  {
288  NS_LOG_DEBUG ("Reset");
289  ResetCnt (station);
290  }
291 }
292 
295 {
296  NS_LOG_FUNCTION (this << st);
298  UpdateMode (station);
299  NS_ASSERT (station->m_txrate < GetNSupported (station));
300  uint32_t rateIndex;
301  if (station->m_retry < 1)
302  {
303  rateIndex = station->m_txrate;
304  }
305  else if (station->m_retry < 2)
306  {
307  if (station->m_txrate > 0)
308  {
309  rateIndex = station->m_txrate - 1;
310  }
311  else
312  {
313  rateIndex = station->m_txrate;
314  }
315  }
316  else if (station->m_retry < 3)
317  {
318  if (station->m_txrate > 1)
319  {
320  rateIndex = station->m_txrate - 2;
321  }
322  else
323  {
324  rateIndex = station->m_txrate;
325  }
326  }
327  else
328  {
329  if (station->m_txrate > 2)
330  {
331  rateIndex = station->m_txrate - 3;
332  }
333  else
334  {
335  rateIndex = station->m_txrate;
336  }
337  }
338  uint32_t channelWidth = GetChannelWidth (station);
339  if (channelWidth > 20 && channelWidth != 22)
340  {
341  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
342  channelWidth = 20;
343  }
344  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
345 }
346 
349 {
350  NS_LOG_FUNCTION (this << st);
352  uint32_t channelWidth = GetChannelWidth (station);
353  if (channelWidth > 20 && channelWidth != 22)
354  {
355  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
356  channelWidth = 20;
357  }
358  UpdateMode (station);
359  WifiTxVector rtsTxVector;
360  if (GetUseNonErpProtection () == false)
361  {
362  rtsTxVector = WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
363  }
364  else
365  {
366  rtsTxVector = WifiTxVector (GetNonErpSupported (station, 0), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
367  }
368  return rtsTxVector;
369 }
370 
371 bool
373 {
374  NS_LOG_FUNCTION (this);
375  return true;
376 }
377 
378 void
380 {
381  //HT is not supported by this algorithm.
382  if (enable)
383  {
384  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
385  }
386 }
387 
388 void
390 {
391  //VHT is not supported by this algorithm.
392  if (enable)
393  {
394  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
395  }
396 }
397 
398 
399 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool IsMinRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the minimum rate.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
virtual WifiRemoteStation * DoCreateStation(void) const
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:44
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
#define min(a, b)
Definition: 80211b.c:44
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
void ResetCnt(AmrrWifiRemoteStation *station)
Reset transmission statistics of the given station.
hold per-remote-station state for AMRR Wifi manager.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
#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:99
virtual 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.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
virtual bool IsLowLatency(void) const
bool IsFailure(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is greater than the number of successful...
AttributeValue implementation for Time.
Definition: nstime.h:957
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...
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
void DecreaseRate(AmrrWifiRemoteStation *station)
Decrease the transmission rate to the given station.
hold a list of per-remote-station state.
void IncreaseRate(AmrrWifiRemoteStation *station)
Increase the transmission rate to the given station.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:958
static TypeId GetTypeId(void)
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
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.
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
bool IsSuccess(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is less than the number of successful tr...
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void UpdateMode(AmrrWifiRemoteStation *station)
Update the mode used to send to the given station.
bool IsMaxRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the maximum rate.
bool IsEnough(AmrrWifiRemoteStation *station) const
Check if the number of retransmission, transmission error, and successful transmission are greater th...
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
virtual 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
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.