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 "rraa-wifi-manager.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/boolean.h"
25 #include "ns3/double.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/simulator.h"
28 
29 #define Min(a,b) ((a < b) ? a : b)
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("RraaWifiManager");
34 
42 {
43  uint32_t m_counter;
44  uint32_t m_failed;
45  uint32_t m_rtsWnd;
46  uint32_t m_rtsCounter;
48  bool m_rtsOn;
51 
52  uint32_t m_rate;
53 };
54 
56 
57 TypeId
59 {
60  static TypeId tid = TypeId ("ns3::RraaWifiManager")
62  .SetGroupName ("Wifi")
63  .AddConstructor<RraaWifiManager> ()
64  .AddAttribute ("Basic",
65  "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA wil be used",
66  BooleanValue (false),
69  .AddAttribute ("Timeout",
70  "Timeout for the RRAA BASIC loss estimaton block (s)",
71  TimeValue (Seconds (0.05)),
73  MakeTimeChecker ())
74  .AddAttribute ("ewndFor54mbps",
75  "ewnd parameter for 54 Mbs data mode",
76  UintegerValue (40),
78  MakeUintegerChecker<uint32_t> ())
79  .AddAttribute ("ewndFor48mbps",
80  "ewnd parameter for 48 Mbs data mode",
81  UintegerValue (40),
83  MakeUintegerChecker<uint32_t> ())
84  .AddAttribute ("ewndFor36mbps",
85  "ewnd parameter for 36 Mbs data mode",
86  UintegerValue (40),
88  MakeUintegerChecker<uint32_t> ())
89  .AddAttribute ("ewndFor24mbps",
90  "ewnd parameter for 24 Mbs data mode",
91  UintegerValue (40),
93  MakeUintegerChecker<uint32_t> ())
94  .AddAttribute ("ewndFor18mbps",
95  "ewnd parameter for 18 Mbs data mode",
96  UintegerValue (20),
98  MakeUintegerChecker<uint32_t> ())
99  .AddAttribute ("ewndFor12mbps",
100  "ewnd parameter for 12 Mbs data mode",
101  UintegerValue (20),
103  MakeUintegerChecker<uint32_t> ())
104  .AddAttribute ("ewndFor9mbps",
105  "ewnd parameter for 9 Mbs data mode",
106  UintegerValue (10),
108  MakeUintegerChecker<uint32_t> ())
109  .AddAttribute ("ewndFor6mbps",
110  "ewnd parameter for 6 Mbs data mode",
111  UintegerValue (6),
113  MakeUintegerChecker<uint32_t> ())
114  .AddAttribute ("poriFor48mbps",
115  "Pori parameter for 48 Mbs data mode",
116  DoubleValue (0.047),
118  MakeDoubleChecker<double> ())
119  .AddAttribute ("poriFor36mbps",
120  "Pori parameter for 36 Mbs data mode",
121  DoubleValue (0.115),
123  MakeDoubleChecker<double> ())
124  .AddAttribute ("poriFor24mbps",
125  "Pori parameter for 24 Mbs data mode",
126  DoubleValue (0.1681),
128  MakeDoubleChecker<double> ())
129  .AddAttribute ("poriFor18mbps",
130  "Pori parameter for 18 Mbs data mode",
131  DoubleValue (0.1325),
133  MakeDoubleChecker<double> ())
134  .AddAttribute ("poriFor12mbps",
135  "Pori parameter for 12 Mbs data mode",
136  DoubleValue (0.1861),
138  MakeDoubleChecker<double> ())
139  .AddAttribute ("poriFor9mbps",
140  "Pori parameter for 9 Mbs data mode",
141  DoubleValue (0.1434),
143  MakeDoubleChecker<double> ())
144  .AddAttribute ("poriFor6mbps",
145  "Pori parameter for 6 Mbs data mode",
146  DoubleValue (0.5),
148  MakeDoubleChecker<double> ())
149  .AddAttribute ("pmtlFor54mbps",
150  "Pmtl parameter for 54 Mbs data mode",
151  DoubleValue (0.094),
153  MakeDoubleChecker<double> ())
154  .AddAttribute ("pmtlFor48mbps",
155  "Pmtl parameter for 48 Mbs data mode",
156  DoubleValue (0.23),
158  MakeDoubleChecker<double> ())
159  .AddAttribute ("pmtlFor36mbps",
160  "Pmtl parameter for 36 Mbs data mode",
161  DoubleValue (0.3363),
163  MakeDoubleChecker<double> ())
164  .AddAttribute ("pmtlFor24mbps",
165  "Pmtl parameter for 24 Mbs data mode",
166  DoubleValue (0.265),
168  MakeDoubleChecker<double> ())
169  .AddAttribute ("pmtlFor18mbps",
170  "Pmtl parameter for 18 Mbs data mode",
171  DoubleValue (0.3722),
173  MakeDoubleChecker<double> ())
174  .AddAttribute ("pmtlFor12mbps",
175  "Pmtl parameter for 12 Mbs data mode",
176  DoubleValue (0.2868),
178  MakeDoubleChecker<double> ())
179  .AddAttribute ("pmtlFor9mbps",
180  "Pmtl parameter for 9 Mbs data mode",
181  DoubleValue (0.3932),
183  MakeDoubleChecker<double> ())
184  ;
185  return tid;
186 }
187 
188 
190 {
191 }
192 
194 {
195 }
196 
199 {
201  station->m_initialized = false;
202  station->m_rtsWnd = 0;
203  station->m_rtsCounter = 0;
204  station->m_rtsOn = false;
205  station->m_lastFrameFail = false;
206  return station;
207 }
208 
209 void
211 {
212  if (!station->m_initialized)
213  {
214  station->m_rate = GetMaxRate (station);
215  station->m_initialized = true;
216  }
217  station->m_failed = 0;
218  station->m_counter = GetThresholds (station, station->m_rate).ewnd;
219  station->m_lastReset = Simulator::Now ();
220 }
221 
222 uint32_t
224 {
225  return GetNSupported (station) - 1;
226 }
227 
228 uint32_t
230 {
231  return 0;
232 }
233 
234 void
236 {
237 }
238 
239 void
241 {
243  station->m_lastFrameFail = true;
244  CheckTimeout (station);
245  station->m_counter--;
246  station->m_failed++;
247  RunBasicAlgorithm (station);
248 }
249 
250 void
252  double rxSnr, WifiMode txMode)
253 {
254 }
255 
256 void
258  double ctsSnr, WifiMode ctsMode, double rtsSnr)
259 {
260  NS_LOG_DEBUG ("self=" << st << " rts ok");
261 }
262 
263 void
265  double ackSnr, WifiMode ackMode, double dataSnr)
266 {
268  station->m_lastFrameFail = false;
269  CheckTimeout (station);
270  station->m_counter--;
271  RunBasicAlgorithm (station);
272 }
273 
274 void
276 {
277 }
278 
279 void
281 {
282 }
283 
286 {
288  uint32_t channelWidth = GetChannelWidth (station);
289  if (channelWidth > 20 && channelWidth != 22)
290  {
291  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
292  channelWidth = 20;
293  }
294  if (!station->m_initialized)
295  {
296  ResetCountersBasic (station);
297  }
298  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
299 }
300 
303 {
305  uint32_t channelWidth = GetChannelWidth (station);
306  if (channelWidth > 20 && channelWidth != 22)
307  {
308  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
309  channelWidth = 20;
310  }
311  WifiTxVector rtsTxVector;
312  if (GetUseNonErpProtection () == false)
313  {
314  rtsTxVector = WifiTxVector (GetSupported (st, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (st), false, 1, 0, channelWidth, GetAggregation (station), false);
315  }
316  else
317  {
318  rtsTxVector = WifiTxVector (GetNonErpSupported (st, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (st), false, 1, 0, channelWidth, GetAggregation (station), false);
319  }
320  return rtsTxVector;
321 }
322 
323 bool
325  Ptr<const Packet> packet, bool normally)
326 {
328  if (m_basic)
329  {
330  return normally;
331  }
332  ARts (station);
333  return station->m_rtsOn;
334 }
335 
336 void
338 {
339  Time d = Simulator::Now () - station->m_lastReset;
340  if (station->m_counter == 0 || d > m_timeout)
341  {
342  ResetCountersBasic (station);
343  }
344 }
345 
346 void
348 {
349  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
350  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
351  if (station->m_counter == 0
352  || ploss > thresholds.pmtl)
353  {
354  if (station->m_rate > GetMinRate (station)
355  && ploss > thresholds.pmtl)
356  {
357  station->m_rate--;
358  }
359  else if (station->m_rate < GetMaxRate (station)
360  && ploss < thresholds.pori)
361  {
362  station->m_rate++;
363  }
364  ResetCountersBasic (station);
365  }
366 }
367 
368 void
370 {
371  if (!station->m_rtsOn
372  && station->m_lastFrameFail)
373  {
374  station->m_rtsWnd++;
375  station->m_rtsCounter = station->m_rtsWnd;
376  }
377  else if ((station->m_rtsOn && station->m_lastFrameFail)
378  || (!station->m_rtsOn && !station->m_lastFrameFail))
379  {
380  station->m_rtsWnd = station->m_rtsWnd / 2;
381  station->m_rtsCounter = station->m_rtsWnd;
382  }
383  if (station->m_rtsCounter > 0)
384  {
385  station->m_rtsOn = true;
386  station->m_rtsCounter--;
387  }
388  else
389  {
390  station->m_rtsOn = false;
391  }
392 }
393 
395 RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
396  uint32_t rate) const
397 {
398  WifiMode mode = GetSupported (station, rate);
399  return GetThresholds (mode, station);
400 }
401 
403 RraaWifiManager::GetThresholds (WifiMode mode, RraaWifiRemoteStation *station) const
404 {
405  uint8_t nss = 1; // This RAA only supports 1 spatial stream
406  switch (mode.GetDataRate (GetChannelWidth (station), GetShortGuardInterval (station), nss) / 1000000)
407  {
408  case 54:
409  {
410  ThresholdsItem mode54 = {
411  54000000,
412  0.0,
413  m_pmtlfor54,
415  };
416  return mode54;
417  } break;
418  case 48:
419  {
420  ThresholdsItem mode48 = {
421  48000000,
422  m_porifor48,
423  m_pmtlfor48,
425  };
426  return mode48;
427  } break;
428  case 36:
429  {
430  ThresholdsItem mode36 = {
431  36000000,
432  m_porifor36,
433  m_pmtlfor36,
435  };
436  return mode36;
437  } break;
438  case 24:
439  {
440  ThresholdsItem mode24 = {
441  24000000,
442  m_porifor24,
443  m_pmtlfor24,
445  };
446  return mode24;
447  } break;
448  case 18:
449  {
450  ThresholdsItem mode18 = {
451  18000000,
452  m_porifor18,
453  m_pmtlfor18,
455  };
456  return mode18;
457  } break;
458  case 12:
459  {
460  ThresholdsItem mode12 = {
461  12000000,
462  m_porifor12,
463  m_pmtlfor12,
465  };
466  return mode12;
467  } break;
468  case 9:
469  {
470  ThresholdsItem mode9 = {
471  9000000,
472  m_porifor9,
473  m_pmtlfor9,
474  m_ewndfor9
475  };
476  return mode9;
477  } break;
478  case 6:
479  {
480  ThresholdsItem mode6 = {
481  6000000,
482  m_porifor6,
483  1.0,
484  m_ewndfor6
485  };
486  return mode6;
487  } break;
488  }
489  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
490  return ThresholdsItem ();
491 }
492 
493 bool
495 {
496  return true;
497 }
498 
499 void
501 {
502  //HT is not supported by this algorithm.
503  if (enable)
504  {
505  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
506  }
507 }
508 
509 void
511 {
512  //VHT is not supported by this algorithm.
513  if (enable)
514  {
515  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
516  }
517 }
518 
519 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
uint32_t GetMaxRate(RraaWifiRemoteStation *station)
Return the index for the maximum transmission rate for the given station.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
AttributeValue implementation for Boolean.
Definition: boolean.h:34
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 DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
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:81
static TypeId GetTypeId(void)
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void RunBasicAlgorithm(RraaWifiRemoteStation *station)
Find an appropriate rate for the given station, using a basic algorithm.
struct ThresholdsItem GetThresholds(WifiMode mode, RraaWifiRemoteStation *station) const
Get a threshold for the given mode.
virtual bool DoNeedRts(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual bool IsLowLatency(void) const
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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:99
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. ...
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
virtual WifiRemoteStation * DoCreateStation(void) const
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be resetted.
AttributeValue implementation for Time.
Definition: nstime.h:957
virtual 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
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
hold a list of per-remote-station state.
Robust Rate Adaptation AlgorithmThis is an implementation of RRAA as described in "Robust rate adapta...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
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
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
virtual void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
void ARts(RraaWifiRemoteStation *station)
Activate the use of RTS for the given station if the conditions are met.
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
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
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:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
hold per-remote-station state for RRAA Wifi manager.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
uint32_t GetMinRate(RraaWifiRemoteStation *station)
Return the index for the minimum transmission rate for the given station.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
virtual 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 '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.