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  uint32_t size)
287 {
289  uint32_t channelWidth = GetChannelWidth (station);
290  if (channelWidth > 20 && channelWidth != 22)
291  {
292  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
293  channelWidth = 20;
294  }
295  if (!station->m_initialized)
296  {
297  ResetCountersBasic (station);
298  }
299  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
300 }
301 
304 {
306  uint32_t channelWidth = GetChannelWidth (station);
307  if (channelWidth > 20 && channelWidth != 22)
308  {
309  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
310  channelWidth = 20;
311  }
312  return WifiTxVector (GetSupported (st, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (st), false, 1, 0, channelWidth, GetAggregation (station), false);
313 }
314 
315 bool
317  Ptr<const Packet> packet, bool normally)
318 {
320  if (m_basic)
321  {
322  return normally;
323  }
324  ARts (station);
325  return station->m_rtsOn;
326 }
327 
328 void
330 {
331  Time d = Simulator::Now () - station->m_lastReset;
332  if (station->m_counter == 0 || d > m_timeout)
333  {
334  ResetCountersBasic (station);
335  }
336 }
337 
338 void
340 {
341  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
342  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
343  if (station->m_counter == 0
344  || ploss > thresholds.pmtl)
345  {
346  if (station->m_rate > GetMinRate (station)
347  && ploss > thresholds.pmtl)
348  {
349  station->m_rate--;
350  }
351  else if (station->m_rate < GetMaxRate (station)
352  && ploss < thresholds.pori)
353  {
354  station->m_rate++;
355  }
356  ResetCountersBasic (station);
357  }
358 }
359 
360 void
362 {
363  if (!station->m_rtsOn
364  && station->m_lastFrameFail)
365  {
366  station->m_rtsWnd++;
367  station->m_rtsCounter = station->m_rtsWnd;
368  }
369  else if ((station->m_rtsOn && station->m_lastFrameFail)
370  || (!station->m_rtsOn && !station->m_lastFrameFail))
371  {
372  station->m_rtsWnd = station->m_rtsWnd / 2;
373  station->m_rtsCounter = station->m_rtsWnd;
374  }
375  if (station->m_rtsCounter > 0)
376  {
377  station->m_rtsOn = true;
378  station->m_rtsCounter--;
379  }
380  else
381  {
382  station->m_rtsOn = false;
383  }
384 }
385 
387 RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
388  uint32_t rate) const
389 {
390  WifiMode mode = GetSupported (station, rate);
391  return GetThresholds (mode, station);
392 }
393 
395 RraaWifiManager::GetThresholds (WifiMode mode, RraaWifiRemoteStation *station) const
396 {
397  switch (mode.GetDataRate (GetChannelWidth (station), GetShortGuardInterval (station), 1) / 1000000)
398  {
399  case 54:
400  {
401  ThresholdsItem mode54 = {
402  54000000,
403  0.0,
404  m_pmtlfor54,
406  };
407  return mode54;
408  } break;
409  case 48:
410  {
411  ThresholdsItem mode48 = {
412  48000000,
413  m_porifor48,
414  m_pmtlfor48,
416  };
417  return mode48;
418  } break;
419  case 36:
420  {
421  ThresholdsItem mode36 = {
422  36000000,
423  m_porifor36,
424  m_pmtlfor36,
426  };
427  return mode36;
428  } break;
429  case 24:
430  {
431  ThresholdsItem mode24 = {
432  24000000,
433  m_porifor24,
434  m_pmtlfor24,
436  };
437  return mode24;
438  } break;
439  case 18:
440  {
441  ThresholdsItem mode18 = {
442  18000000,
443  m_porifor18,
444  m_pmtlfor18,
446  };
447  return mode18;
448  } break;
449  case 12:
450  {
451  ThresholdsItem mode12 = {
452  12000000,
453  m_porifor12,
454  m_pmtlfor12,
456  };
457  return mode12;
458  } break;
459  case 9:
460  {
461  ThresholdsItem mode9 = {
462  9000000,
463  m_porifor9,
464  m_pmtlfor9,
465  m_ewndfor9
466  };
467  return mode9;
468  } break;
469  case 6:
470  {
471  ThresholdsItem mode6 = {
472  6000000,
473  m_porifor6,
474  1.0,
475  m_ewndfor6
476  };
477  return mode6;
478  } break;
479  }
480  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
481  return ThresholdsItem ();
482 }
483 
484 bool
486 {
487  return true;
488 }
489 
490 } //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
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
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.
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)
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:97
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
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:223
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:826
hold per-remote-station state.