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  .AddConstructor<RraaWifiManager> ()
63  .AddAttribute ("Basic",
64  "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA wil be used",
65  BooleanValue (false),
68  .AddAttribute ("Timeout",
69  "Timeout for the RRAA BASIC loss estimaton block (s)",
70  TimeValue (Seconds (0.05)),
72  MakeTimeChecker ())
73  .AddAttribute ("ewndFor54mbps",
74  "ewnd parameter for 54 Mbs data mode",
75  UintegerValue (40),
77  MakeUintegerChecker<uint32_t> ())
78  .AddAttribute ("ewndFor48mbps",
79  "ewnd parameter for 48 Mbs data mode",
80  UintegerValue (40),
82  MakeUintegerChecker<uint32_t> ())
83  .AddAttribute ("ewndFor36mbps",
84  "ewnd parameter for 36 Mbs data mode",
85  UintegerValue (40),
87  MakeUintegerChecker<uint32_t> ())
88  .AddAttribute ("ewndFor24mbps",
89  "ewnd parameter for 24 Mbs data mode",
90  UintegerValue (40),
92  MakeUintegerChecker<uint32_t> ())
93  .AddAttribute ("ewndFor18mbps",
94  "ewnd parameter for 18 Mbs data mode",
95  UintegerValue (20),
97  MakeUintegerChecker<uint32_t> ())
98  .AddAttribute ("ewndFor12mbps",
99  "ewnd parameter for 12 Mbs data mode",
100  UintegerValue (20),
102  MakeUintegerChecker<uint32_t> ())
103  .AddAttribute ("ewndFor9mbps",
104  "ewnd parameter for 9 Mbs data mode",
105  UintegerValue (10),
107  MakeUintegerChecker<uint32_t> ())
108  .AddAttribute ("ewndFor6mbps",
109  "ewnd parameter for 6 Mbs data mode",
110  UintegerValue (6),
112  MakeUintegerChecker<uint32_t> ())
113  .AddAttribute ("poriFor48mbps",
114  "Pori parameter for 48 Mbs data mode",
115  DoubleValue (0.047),
117  MakeDoubleChecker<double> ())
118  .AddAttribute ("poriFor36mbps",
119  "Pori parameter for 36 Mbs data mode",
120  DoubleValue (0.115),
122  MakeDoubleChecker<double> ())
123  .AddAttribute ("poriFor24mbps",
124  "Pori parameter for 24 Mbs data mode",
125  DoubleValue (0.1681),
127  MakeDoubleChecker<double> ())
128  .AddAttribute ("poriFor18mbps",
129  "Pori parameter for 18 Mbs data mode",
130  DoubleValue (0.1325),
132  MakeDoubleChecker<double> ())
133  .AddAttribute ("poriFor12mbps",
134  "Pori parameter for 12 Mbs data mode",
135  DoubleValue (0.1861),
137  MakeDoubleChecker<double> ())
138  .AddAttribute ("poriFor9mbps",
139  "Pori parameter for 9 Mbs data mode",
140  DoubleValue (0.1434),
142  MakeDoubleChecker<double> ())
143  .AddAttribute ("poriFor6mbps",
144  "Pori parameter for 6 Mbs data mode",
145  DoubleValue (0.5),
147  MakeDoubleChecker<double> ())
148  .AddAttribute ("pmtlFor54mbps",
149  "Pmtl parameter for 54 Mbs data mode",
150  DoubleValue (0.094),
152  MakeDoubleChecker<double> ())
153  .AddAttribute ("pmtlFor48mbps",
154  "Pmtl parameter for 48 Mbs data mode",
155  DoubleValue (0.23),
157  MakeDoubleChecker<double> ())
158  .AddAttribute ("pmtlFor36mbps",
159  "Pmtl parameter for 36 Mbs data mode",
160  DoubleValue (0.3363),
162  MakeDoubleChecker<double> ())
163  .AddAttribute ("pmtlFor24mbps",
164  "Pmtl parameter for 24 Mbs data mode",
165  DoubleValue (0.265),
167  MakeDoubleChecker<double> ())
168  .AddAttribute ("pmtlFor18mbps",
169  "Pmtl parameter for 18 Mbs data mode",
170  DoubleValue (0.3722),
172  MakeDoubleChecker<double> ())
173  .AddAttribute ("pmtlFor12mbps",
174  "Pmtl parameter for 12 Mbs data mode",
175  DoubleValue (0.2868),
177  MakeDoubleChecker<double> ())
178  .AddAttribute ("pmtlFor9mbps",
179  "Pmtl parameter for 9 Mbs data mode",
180  DoubleValue (0.3932),
182  MakeDoubleChecker<double> ())
183  ;
184  return tid;
185 }
186 
187 
189 {
190 }
192 {
193 }
194 
195 
198 {
200  station->m_initialized = false;
201  station->m_rtsWnd = 0;
202  station->m_rtsCounter = 0;
203  station->m_rtsOn = false;
204  station->m_lastFrameFail = false;
205  return station;
206 }
207 
208 void
210 {
211  if (!station->m_initialized)
212  {
213  station->m_rate = GetMaxRate (station);
214  station->m_initialized = true;
215  }
216  station->m_failed = 0;
217  station->m_counter = GetThresholds (station, station->m_rate).ewnd;
218  station->m_lastReset = Simulator::Now ();
219 }
220 
221 uint32_t
223 {
224  return GetNSupported (station) - 1;
225 }
226 uint32_t
228 {
229  return 0;
230 }
231 
232 
233 void
235 {
236 }
237 
238 void
240 {
242  station->m_lastFrameFail = true;
243  CheckTimeout (station);
244  station->m_counter--;
245  station->m_failed++;
246  RunBasicAlgorithm (station);
247 }
248 void
250  double rxSnr, WifiMode txMode)
251 {
252 }
253 void
255  double ctsSnr, WifiMode ctsMode, double rtsSnr)
256 {
257  NS_LOG_DEBUG ("self=" << st << " rts ok");
258 }
259 void
261  double ackSnr, WifiMode ackMode, double dataSnr)
262 {
264  station->m_lastFrameFail = false;
265  CheckTimeout (station);
266  station->m_counter--;
267  RunBasicAlgorithm (station);
268 }
269 void
271 {
272 }
273 void
275 {
276 }
277 
280  uint32_t size)
281 {
283  if (!station->m_initialized)
284  {
285  ResetCountersBasic (station);
286  }
287  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas()), GetNess (station), GetStbc (station));
288 }
291 {
293 }
294 
295 bool
297  Ptr<const Packet> packet, bool normally)
298 {
300  if (m_basic)
301  {
302  return normally;
303  }
304  ARts (station);
305  return station->m_rtsOn;
306 }
307 
308 void
310 {
311  Time d = Simulator::Now () - station->m_lastReset;
312  if (station->m_counter == 0 || d > m_timeout)
313  {
314  ResetCountersBasic (station);
315  }
316 }
317 
318 void
320 {
321  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
322  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
323  if (station->m_counter == 0
324  || ploss > thresholds.pmtl)
325  {
326  if (station->m_rate > GetMinRate (station)
327  && ploss > thresholds.pmtl)
328  {
329  station->m_rate--;
330  }
331  else if (station->m_rate < GetMaxRate (station)
332  && ploss < thresholds.pori)
333  {
334  station->m_rate++;
335  }
336  ResetCountersBasic (station);
337  }
338 }
339 
340 void
342 {
343  if (!station->m_rtsOn
344  && station->m_lastFrameFail)
345  {
346  station->m_rtsWnd++;
347  station->m_rtsCounter = station->m_rtsWnd;
348  }
349  else if ((station->m_rtsOn && station->m_lastFrameFail)
350  || (!station->m_rtsOn && !station->m_lastFrameFail))
351  {
352  station->m_rtsWnd = station->m_rtsWnd / 2;
353  station->m_rtsCounter = station->m_rtsWnd;
354  }
355  if (station->m_rtsCounter > 0)
356  {
357  station->m_rtsOn = true;
358  station->m_rtsCounter--;
359  }
360  else
361  {
362  station->m_rtsOn = false;
363  }
364 }
365 
367 RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
368  uint32_t rate) const
369 {
370  WifiMode mode = GetSupported (station, rate);
371  return GetThresholds (mode);
372 }
373 
375 RraaWifiManager::GetThresholds (WifiMode mode) const
376 {
377  switch (mode.GetDataRate () / 1000000)
378  {
379  case 54:
380  {
381  ThresholdsItem mode54 = {
382  54000000,
383  0.0,
384  m_pmtlfor54,
386  };
387  return mode54;
388  } break;
389  case 48:
390  {
391  ThresholdsItem mode48 = {
392  48000000,
393  m_porifor48,
394  m_pmtlfor48,
396  };
397  return mode48;
398  } break;
399  case 36:
400  {
401  ThresholdsItem mode36 = {
402  36000000,
403  m_porifor36,
404  m_pmtlfor36,
406  };
407  return mode36;
408  } break;
409  case 24:
410  {
411  ThresholdsItem mode24 = {
412  24000000,
413  m_porifor24,
414  m_pmtlfor24,
416  };
417  return mode24;
418  } break;
419  case 18:
420  {
421  ThresholdsItem mode18 = {
422  18000000,
423  m_porifor18,
424  m_pmtlfor18,
426  };
427  return mode18;
428  } break;
429  case 12:
430  {
431  ThresholdsItem mode12 = {
432  12000000,
433  m_porifor12,
434  m_pmtlfor12,
436  };
437  return mode12;
438  } break;
439  case 9:
440  {
441  ThresholdsItem mode9 = {
442  9000000,
443  m_porifor9,
444  m_pmtlfor9,
445  m_ewndfor9
446  };
447  return mode9;
448  } break;
449  case 6:
450  {
451  ThresholdsItem mode6 = {
452  6000000,
453  m_porifor6,
454  1.0,
455  m_ewndfor6
456  };
457  return mode6;
458  } break;
459  }
460  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
461  return ThresholdsItem ();
462 }
463 
464 bool
466 {
467  return true;
468 }
469 
470 } // 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:95
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.
struct ThresholdsItem GetThresholds(WifiMode mode) const
Get a threshold for the given mode.
#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.
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:93
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
Return the number of receive antenna the station has.
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:439
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:191
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be resetted.
AttributeValue implementation for Time.
Definition: nstime.h:921
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.
uint32_t GetNess(const WifiRemoteStation *station) const
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:922
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:84
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:859
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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
hold per-remote-station state.