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 "ns3/log.h"
22 #include "ns3/simulator.h"
23 #include "amrr-wifi-manager.h"
24 #include "wifi-tx-vector.h"
25 
26 #define Min(a,b) ((a < b) ? a : b)
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("AmrrWifiManager");
31 
39 {
41  uint32_t m_tx_ok;
42  uint32_t m_tx_err;
43  uint32_t m_tx_retr;
44  uint32_t m_retry;
45  uint8_t m_txrate;
46  uint32_t m_successThreshold;
47  uint32_t m_success;
48  bool m_recovery;
49 };
50 
51 
53 
54 TypeId
56 {
57  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
59  .SetGroupName ("Wifi")
60  .AddConstructor<AmrrWifiManager> ()
61  .AddAttribute ("UpdatePeriod",
62  "The interval between decisions about rate control changes",
63  TimeValue (Seconds (1.0)),
65  MakeTimeChecker ())
66  .AddAttribute ("FailureRatio",
67  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
68  DoubleValue (1.0 / 3.0),
70  MakeDoubleChecker<double> (0.0, 1.0))
71  .AddAttribute ("SuccessRatio",
72  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
73  DoubleValue (1.0 / 10.0),
75  MakeDoubleChecker<double> (0.0, 1.0))
76  .AddAttribute ("MaxSuccessThreshold",
77  "Maximum number of consecutive success periods needed to switch to a higher rate",
78  UintegerValue (10),
80  MakeUintegerChecker<uint32_t> ())
81  .AddAttribute ("MinSuccessThreshold",
82  "Minimum number of consecutive success periods needed to switch to a higher rate",
83  UintegerValue (1),
85  MakeUintegerChecker<uint32_t> ())
86  .AddTraceSource ("Rate",
87  "Traced value for rate changes (b/s)",
89  "ns3::TracedValueCallback::Uint64")
90  ;
91  return tid;
92 }
93 
96  m_currentRate (0)
97 {
98  NS_LOG_FUNCTION (this);
99 }
100 
102 {
103  NS_LOG_FUNCTION (this);
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION (this);
110  if (GetHtSupported ())
111  {
112  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
113  }
114  if (GetVhtSupported ())
115  {
116  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
117  }
118  if (GetHeSupported ())
119  {
120  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
121  }
122 }
123 
126 {
127  NS_LOG_FUNCTION (this);
130  station->m_tx_ok = 0;
131  station->m_tx_err = 0;
132  station->m_tx_retr = 0;
133  station->m_retry = 0;
134  station->m_txrate = 0;
136  station->m_success = 0;
137  station->m_recovery = false;
138  return station;
139 }
140 
141 void
143  double rxSnr, WifiMode txMode)
144 {
145  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
146 }
147 
148 void
150 {
151  NS_LOG_FUNCTION (this << station);
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this << st);
159  station->m_retry++;
160  station->m_tx_retr++;
161 }
162 
163 void
165  double ctsSnr, WifiMode ctsMode, double rtsSnr)
166 {
167  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
168 }
169 
170 void
172  double ackSnr, WifiMode ackMode, double dataSnr)
173 {
174  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
176  station->m_retry = 0;
177  station->m_tx_ok++;
178 }
179 
180 void
182 {
183  NS_LOG_FUNCTION (this << station);
184 }
185 
186 void
188 {
189  NS_LOG_FUNCTION (this << st);
191  station->m_retry = 0;
192  station->m_tx_err++;
193 }
194 
195 bool
197 {
198  NS_LOG_FUNCTION (this << station);
199  return (station->m_txrate == 0);
200 }
201 
202 bool
204 {
205  NS_LOG_FUNCTION (this << station);
206  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
207  return (station->m_txrate + 1 == GetNSupported (station));
208 }
209 
210 bool
212 {
213  NS_LOG_FUNCTION (this << station);
214  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
215 }
216 
217 bool
219 {
220  NS_LOG_FUNCTION (this << station);
221  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
222 }
223 
224 bool
226 {
227  NS_LOG_FUNCTION (this << station);
228  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
229 }
230 
231 void
233 {
234  NS_LOG_FUNCTION (this << station);
235  station->m_tx_ok = 0;
236  station->m_tx_err = 0;
237  station->m_tx_retr = 0;
238 }
239 
240 void
242 {
243  NS_LOG_FUNCTION (this << station);
244  station->m_txrate++;
245  NS_ASSERT (station->m_txrate < GetNSupported (station));
246 }
247 
248 void
250 {
251  NS_LOG_FUNCTION (this << station);
252  station->m_txrate--;
253 }
254 
255 void
257 {
258  NS_LOG_FUNCTION (this << station);
259  if (Simulator::Now () < station->m_nextModeUpdate)
260  {
261  return;
262  }
264  NS_LOG_DEBUG ("Update");
265 
266  bool needChange = false;
267 
268  if (IsSuccess (station) && IsEnough (station))
269  {
270  station->m_success++;
271  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
272  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
273  " rate=" << +station->m_txrate << " n-supported-rates=" << +GetNSupported (station));
274  if (station->m_success >= station->m_successThreshold
275  && !IsMaxRate (station))
276  {
277  station->m_recovery = true;
278  station->m_success = 0;
279  IncreaseRate (station);
280  needChange = true;
281  }
282  else
283  {
284  station->m_recovery = false;
285  }
286  }
287  else if (IsFailure (station))
288  {
289  station->m_success = 0;
290  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
291  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
292  " rate=" << +station->m_txrate << " n-supported-rates=" << +GetNSupported (station));
293  if (!IsMinRate (station))
294  {
295  if (station->m_recovery)
296  {
297  station->m_successThreshold *= 2;
298  station->m_successThreshold = std::min (station->m_successThreshold,
300  }
301  else
302  {
304  }
305  station->m_recovery = false;
306  DecreaseRate (station);
307  needChange = true;
308  }
309  else
310  {
311  station->m_recovery = false;
312  }
313  }
314  if (IsEnough (station) || needChange)
315  {
316  NS_LOG_DEBUG ("Reset");
317  ResetCnt (station);
318  }
319 }
320 
323 {
324  NS_LOG_FUNCTION (this << st);
326  UpdateMode (station);
327  NS_ASSERT (station->m_txrate < GetNSupported (station));
328  uint8_t rateIndex;
329  if (station->m_retry < 1)
330  {
331  rateIndex = station->m_txrate;
332  }
333  else if (station->m_retry < 2)
334  {
335  if (station->m_txrate > 0)
336  {
337  rateIndex = station->m_txrate - 1;
338  }
339  else
340  {
341  rateIndex = station->m_txrate;
342  }
343  }
344  else if (station->m_retry < 3)
345  {
346  if (station->m_txrate > 1)
347  {
348  rateIndex = station->m_txrate - 2;
349  }
350  else
351  {
352  rateIndex = station->m_txrate;
353  }
354  }
355  else
356  {
357  if (station->m_txrate > 2)
358  {
359  rateIndex = station->m_txrate - 3;
360  }
361  else
362  {
363  rateIndex = station->m_txrate;
364  }
365  }
366  uint16_t channelWidth = GetChannelWidth (station);
367  if (channelWidth > 20 && channelWidth != 22)
368  {
369  channelWidth = 20;
370  }
371  WifiMode mode = GetSupported (station, rateIndex);
372  if (m_currentRate != mode.GetDataRate (channelWidth))
373  {
374  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
375  m_currentRate = mode.GetDataRate (channelWidth);
376  }
377  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
378 }
379 
382 {
383  NS_LOG_FUNCTION (this << st);
385  uint16_t channelWidth = GetChannelWidth (station);
386  if (channelWidth > 20 && channelWidth != 22)
387  {
388  channelWidth = 20;
389  }
390  UpdateMode (station);
391  WifiTxVector rtsTxVector;
392  WifiMode mode;
393  if (GetUseNonErpProtection () == false)
394  {
395  mode = GetSupported (station, 0);
396  }
397  else
398  {
399  mode = GetNonErpSupported (station, 0);
400  }
401  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
402  return rtsTxVector;
403 }
404 
405 bool
407 {
408  return true;
409 }
410 
411 } //namespace ns3
uint32_t m_minSuccessThreshold
mnimum success threshold
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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 "...
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool IsLowLatency(void) const
uint32_t m_successThreshold
success threshold
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time m_nextModeUpdate
next mode update time
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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:42
void ResetCnt(AmrrWifiRemoteStation *station)
Reset transmission statistics of the given station.
hold per-remote-station state for AMRR Wifi manager.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
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 DoInitialize(void)
Initialize() implementation.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool IsMinRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the minimum rate.
uint32_t m_tx_err
transmit error
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
Definition: wifi-utils.cc:128
Time m_updatePeriod
update period
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 DoReportRtsFailed(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.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP preambles.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
AttributeValue implementation for Time.
Definition: nstime.h:1124
Hold an unsigned integer type.
Definition: uinteger.h:44
uint8_t m_txrate
transmit rate
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DecreaseRate(AmrrWifiRemoteStation *station)
Decrease the transmission rate to the given station.
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:494
uint32_t m_tx_ok
transmit ok
void IncreaseRate(AmrrWifiRemoteStation *station)
Increase the transmission rate to the given station.
WifiRemoteStation * DoCreateStation(void) const
bool IsEnough(AmrrWifiRemoteStation *station) const
Check if the number of retransmission, transmission error, and successful transmission are greater th...
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.
bool UseGreenfieldForDestination(Mac48Address dest) const
double m_successRatio
success ratio
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
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...
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:1125
static TypeId GetTypeId(void)
Get the type ID.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
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 m_tx_retr
transmit retry
bool IsMaxRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the maximum rate.
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...
double m_failureRatio
failure ratio
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
uint32_t m_maxSuccessThreshold
maximum success threshold
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:272
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void UpdateMode(AmrrWifiRemoteStation *station)
Update the mode used to send to the given station.
bool IsFailure(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is greater than the number of successful...
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
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.