A Discrete-Event Network Simulator
API
rraa-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 "ns3/simulator.h"
24 #include "rraa-wifi-manager.h"
25 #include "wifi-phy.h"
26 #include "wifi-mac.h"
27 
28 #define Min(a,b) ((a < b) ? a : b)
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("RraaWifiManager");
33 
41 {
42  uint32_t m_counter;
43  uint32_t m_nFailed;
44  uint32_t m_adaptiveRtsWnd;
45  uint32_t m_rtsCounter;
50  uint8_t m_nRate;
51  uint8_t m_rateIndex;
52 
54 };
55 
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::RraaWifiManager")
63  .SetGroupName ("Wifi")
64  .AddConstructor<RraaWifiManager> ()
65  .AddAttribute ("Basic",
66  "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA will be used",
67  BooleanValue (false),
70  .AddAttribute ("Timeout",
71  "Timeout for the RRAA BASIC loss estimation block",
72  TimeValue (Seconds (0.05)),
74  MakeTimeChecker ())
75  .AddAttribute ("FrameLength",
76  "The Data frame length (in bytes) used for calculating mode TxTime.",
77  UintegerValue (1420),
79  MakeUintegerChecker <uint32_t> ())
80  .AddAttribute ("AckFrameLength",
81  "The Ack frame length (in bytes) used for calculating mode TxTime.",
82  UintegerValue (14),
84  MakeUintegerChecker <uint32_t> ())
85  .AddAttribute ("Alpha",
86  "Constant for calculating the MTL threshold.",
87  DoubleValue (1.25),
89  MakeDoubleChecker<double> (1))
90  .AddAttribute ("Beta",
91  "Constant for calculating the ORI threshold.",
92  DoubleValue (2),
94  MakeDoubleChecker<double> (1))
95  .AddAttribute ("Tau",
96  "Constant for calculating the EWND size.",
97  DoubleValue (0.012),
99  MakeDoubleChecker<double> (0))
100  .AddTraceSource ("Rate",
101  "Traced value for rate changes (b/s)",
103  "ns3::TracedValueCallback::Uint64")
104  ;
105  return tid;
106 }
107 
110  m_currentRate (0)
111 {
112  NS_LOG_FUNCTION (this);
113 }
114 
116 {
117  NS_LOG_FUNCTION (this);
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION (this << phy);
124  m_sifs = phy->GetSifs ();
125  m_difs = m_sifs + 2 * phy->GetSlot ();
126  uint8_t nModes = phy->GetNModes ();
127  for (uint8_t i = 0; i < nModes; i++)
128  {
129  WifiMode mode = phy->GetMode (i);
130  WifiTxVector txVector;
131  txVector.SetMode (mode);
133  /* Calculate the TX Time of the Data and the corresponding Ack */
134  Time dataTxTime = phy->CalculateTxDuration (m_frameLength, txVector, phy->GetFrequency ());
135  Time ackTxTime = phy->CalculateTxDuration (m_ackLength, txVector, phy->GetFrequency ());
136  NS_LOG_DEBUG ("Calculating TX times: Mode= " << mode << " DataTxTime= " << dataTxTime << " AckTxTime= " << ackTxTime);
137  AddCalcTxTime (mode, dataTxTime + ackTxTime);
138  }
140 }
141 
142 void
144 {
145  NS_LOG_FUNCTION (this);
147 }
148 
149 void
151 {
152  NS_LOG_FUNCTION (this);
153  if (GetHtSupported ())
154  {
155  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
156  }
157  if (GetVhtSupported ())
158  {
159  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
160  }
161  if (GetHeSupported ())
162  {
163  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
164  }
165 }
166 
167 Time
169 {
170  NS_LOG_FUNCTION (this << mode);
171  for (TxTime::const_iterator i = m_calcTxTime.begin (); i != m_calcTxTime.end (); i++)
172  {
173  if (mode == i->second)
174  {
175  return i->first;
176  }
177  }
178  NS_ASSERT (false);
179  return Seconds (0);
180 }
181 
182 void
184 {
185  NS_LOG_FUNCTION (this << mode << t);
186  m_calcTxTime.push_back (std::make_pair (t, mode));
187 }
188 
191 {
192  NS_LOG_FUNCTION (this << station << mode);
193  struct WifiRraaThresholds threshold;
194  for (RraaThresholdsTable::const_iterator i = station->m_thresholds.begin (); i != station->m_thresholds.end (); i++)
195  {
196  if (mode == i->second)
197  {
198  return i->first;
199  }
200  }
201  NS_ABORT_MSG ("No thresholds for mode " << mode << " found");
202  return threshold; // Silence compiler warning
203 }
204 
207 {
209  station->m_initialized = false;
210  station->m_adaptiveRtsWnd = 0;
211  station->m_rtsCounter = 0;
212  station->m_adaptiveRtsOn = false;
213  station->m_lastFrameFail = false;
214  return station;
215 }
216 
217 void
219 {
220  NS_LOG_FUNCTION (this << station);
221  if (!station->m_initialized)
222  {
223  //Note: we appear to be doing late initialization of the table
224  //to make sure that the set of supported rates has been initialized
225  //before we perform our own initialization.
226  station->m_nRate = GetNSupported (station);
227  //Initialize at maximal rate
228  station->m_rateIndex = GetMaxRate (station);
229 
230  station->m_initialized = true;
231 
232  station->m_thresholds = RraaThresholdsTable (station->m_nRate);
233  InitThresholds (station);
234  ResetCountersBasic (station);
235  }
236 }
237 
238 void
240 {
241  NS_LOG_FUNCTION (this << station);
242  NS_LOG_DEBUG ("InitThresholds = " << station);
243 
244  double nextCritical = 0;
245  double nextMtl = 0;
246  double mtl = 0;
247  double ori = 0;
248  for (uint8_t i = 0; i < station->m_nRate; i++)
249  {
250  WifiMode mode = GetSupported (station, i);
251  Time totalTxTime = GetCalcTxTime (mode) + m_sifs + m_difs;
252  if (i == GetMaxRate (station))
253  {
254  ori = 0;
255  }
256  else
257  {
258  WifiMode nextMode = GetSupported (station, i + 1);
259  Time nextTotalTxTime = GetCalcTxTime (nextMode) + m_sifs + m_difs;
260  nextCritical = 1 - (nextTotalTxTime.GetSeconds () / totalTxTime.GetSeconds ());
261  nextMtl = m_alpha * nextCritical;
262  ori = nextMtl / m_beta;
263  }
264  if (i == 0)
265  {
266  mtl = 1;
267  }
269  th.m_ewnd = static_cast<uint32_t> (ceil (m_tau / totalTxTime.GetSeconds ()));
270  th.m_ori = ori;
271  th.m_mtl = mtl;
272  station->m_thresholds.push_back (std::make_pair (th, mode));
273  mtl = nextMtl;
274  NS_LOG_DEBUG (mode << " " << th.m_ewnd << " " << th.m_mtl << " " << th.m_ori);
275  }
276 }
277 
278 void
280 {
281  NS_LOG_FUNCTION (this << station);
282  station->m_nFailed = 0;
283  station->m_counter = GetThresholds (station, station->m_rateIndex).m_ewnd;
284  station->m_lastReset = Simulator::Now ();
285 }
286 
287 uint8_t
289 {
290  return station->m_nRate - 1;
291 }
292 
293 void
295 {
296  NS_LOG_FUNCTION (this << st);
297 }
298 
299 void
301 {
302  NS_LOG_FUNCTION (this << st);
303  RraaWifiRemoteStation *station = static_cast<RraaWifiRemoteStation*> (st);
304  station->m_lastFrameFail = true;
305  CheckTimeout (station);
306  station->m_counter--;
307  station->m_nFailed++;
308  RunBasicAlgorithm (station);
309 }
310 
311 void
313  double rxSnr, WifiMode txMode)
314 {
315  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
316 }
317 
318 void
320  double ctsSnr, WifiMode ctsMode, double rtsSnr)
321 {
322  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
323 }
324 
325 void
327  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
328 {
329  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
330  RraaWifiRemoteStation *station = static_cast<RraaWifiRemoteStation*> (st);
331  station->m_lastFrameFail = false;
332  CheckTimeout (station);
333  station->m_counter--;
334  RunBasicAlgorithm (station);
335 }
336 
337 void
339 {
340  NS_LOG_FUNCTION (this << st);
341 }
342 
343 void
345 {
346  NS_LOG_FUNCTION (this << st);
347 }
348 
351 {
352  NS_LOG_FUNCTION (this << st);
353  RraaWifiRemoteStation *station = static_cast<RraaWifiRemoteStation*> (st);
354  uint16_t channelWidth = GetChannelWidth (station);
355  if (channelWidth > 20 && channelWidth != 22)
356  {
357  channelWidth = 20;
358  }
359  CheckInit (station);
360  WifiMode mode = GetSupported (station, station->m_rateIndex);
361  if (m_currentRate != mode.GetDataRate (channelWidth))
362  {
363  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
364  m_currentRate = mode.GetDataRate (channelWidth);
365  }
366  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
367 }
368 
371 {
372  NS_LOG_FUNCTION (this << st);
373  RraaWifiRemoteStation *station = static_cast<RraaWifiRemoteStation*> (st);
374  uint16_t channelWidth = GetChannelWidth (station);
375  if (channelWidth > 20 && channelWidth != 22)
376  {
377  channelWidth = 20;
378  }
379  WifiTxVector rtsTxVector;
380  WifiMode mode;
381  if (GetUseNonErpProtection () == false)
382  {
383  mode = GetSupported (station, 0);
384  }
385  else
386  {
387  mode = GetNonErpSupported (station, 0);
388  }
389  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
390  return rtsTxVector;
391 }
392 
393 bool
395  uint32_t size, bool normally)
396 {
397  NS_LOG_FUNCTION (this << st << size << normally);
398  RraaWifiRemoteStation *station = static_cast<RraaWifiRemoteStation*> (st);
399  CheckInit (station);
400  if (m_basic)
401  {
402  return normally;
403  }
404  ARts (station);
405  return station->m_adaptiveRtsOn;
406 }
407 
408 void
410 {
411  NS_LOG_FUNCTION (this << station);
412  Time d = Simulator::Now () - station->m_lastReset;
413  if (station->m_counter == 0 || d > m_timeout)
414  {
415  ResetCountersBasic (station);
416  }
417 }
418 
419 void
421 {
422  NS_LOG_FUNCTION (this << station);
423  WifiRraaThresholds thresholds = GetThresholds (station, station->m_rateIndex);
424  double ploss = (station->m_nFailed / thresholds.m_ewnd);
425  if (station->m_counter == 0
426  || ploss > thresholds.m_mtl)
427  {
428  if (ploss > thresholds.m_mtl)
429  {
430  station->m_rateIndex--;
431  }
432  else if (station->m_rateIndex < GetMaxRate (station)
433  && ploss < thresholds.m_ori)
434  {
435  station->m_rateIndex++;
436  }
437  ResetCountersBasic (station);
438  }
439 }
440 
441 void
443 {
444  if (!station->m_adaptiveRtsOn
445  && station->m_lastFrameFail)
446  {
447  station->m_adaptiveRtsWnd++;
448  station->m_rtsCounter = station->m_adaptiveRtsWnd;
449  }
450  else if ((station->m_adaptiveRtsOn && station->m_lastFrameFail)
451  || (!station->m_adaptiveRtsOn && !station->m_lastFrameFail))
452  {
453  station->m_adaptiveRtsWnd = station->m_adaptiveRtsWnd / 2;
454  station->m_rtsCounter = station->m_adaptiveRtsWnd;
455  }
456  if (station->m_rtsCounter > 0)
457  {
458  station->m_adaptiveRtsOn = true;
459  station->m_rtsCounter--;
460  }
461  else
462  {
463  station->m_adaptiveRtsOn = false;
464  }
465 }
466 
469 {
470  NS_LOG_FUNCTION (this << station << +index);
471  WifiMode mode = GetSupported (station, index);
472  return GetThresholds (station, mode);
473 }
474 
475 } //namespace ns3
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
void DoInitialize(void)
Initialize() implementation.
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 "...
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
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
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
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 > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:85
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
double m_tau
Tau value for RRAA (value for calculating EWND size).
static TypeId GetTypeId(void)
Get the type ID.
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.
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:205
void RunBasicAlgorithm(RraaWifiRemoteStation *station)
Find an appropriate rate for the given station, using a basic algorithm.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint32_t m_ewnd
Evaluation Window.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
Definition: wifi-utils.cc:128
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
Time GetCalcTxTime(WifiMode mode) const
Get the estimated TxTime of a packet with a given mode.
void ResetCountersBasic(RraaWifiRemoteStation *station)
Reset the counters of the given station.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
WifiRemoteStation * DoCreateStation(void) const
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
phy
Definition: third.py:93
bool m_adaptiveRtsOn
Check if Adaptive RTS mechanism is on.
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
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 PHY preambles.
void CheckInit(RraaWifiRemoteStation *station)
Check for initializations.
uint32_t m_frameLength
Data frame length used for calculate mode TxTime.
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be reset.
double m_beta
Beta value for RRAA (value for calculating ORI threshold).
AttributeValue implementation for Time.
Definition: nstime.h:1124
void DoReportDataFailed(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
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
uint32_t m_counter
Counter for transmission attempts.
uint8_t m_nRate
Number of supported rates.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
mac
Definition: third.py:99
uint32_t m_rtsCounter
Counter for RTS transmission attempts.
std::vector< std::pair< WifiRraaThresholds, WifiMode > > RraaThresholdsTable
List of thresholds for each mode.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:463
Robust Rate Adaptation AlgorithmThis is an implementation of RRAA as described in "Robust rate adapta...
RraaThresholdsTable m_thresholds
RRAA thresholds for this station.
double m_alpha
Alpha value for RRAA (value for calculating MTL threshold)
bool m_initialized
For initializing variables.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
bool UseGreenfieldForDestination(Mac48Address dest) const
TxTime m_calcTxTime
To hold all the calculated TxTime for all modes.
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...
uint32_t m_ackLength
Ack frame length used for calculate mode TxTime.
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 Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
double m_ori
Opportunistic Rate Increase threshold.
void ARts(RraaWifiRemoteStation *station)
Activate the use of RTS for the given station if the conditions are met.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
WifiRraaThresholds GetThresholds(RraaWifiRemoteStation *station, WifiMode mode) const
Get the thresholds for the given station and mode.
Time m_sifs
Value of SIFS configured in the device.
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
Time m_difs
Value of DIFS configured in the device.
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
WifiRraaThresholds structure.
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
uint8_t m_rateIndex
Current rate index.
Time m_lastReset
Time of the last reset.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
uint32_t m_adaptiveRtsWnd
Window size for the Adaptive RTS mechanism.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void InitThresholds(RraaWifiRemoteStation *station)
Initialize the thresholds internal list for the given station.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:449
uint8_t GetMaxRate(RraaWifiRemoteStation *station) const
Return the index for the maximum transmission rate for the given station.
hold per-remote-station state for RRAA Wifi manager.
bool m_lastFrameFail
Flag if the last frame sent has failed.
double m_mtl
Maximum Tolerable Loss threshold.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalRtsFailed(WifiRemoteStation *station)
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
bool DoNeedRts(WifiRemoteStation *st, uint32_t size, bool normally)
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:923
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:119
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
uint32_t m_nFailed
Number of failed transmission attempts.