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 }
193 {
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 uint32_t
229 {
230  return 0;
231 }
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 void
251  double rxSnr, WifiMode txMode)
252 {
253 }
254 void
256  double ctsSnr, WifiMode ctsMode, double rtsSnr)
257 {
258  NS_LOG_DEBUG ("self=" << st << " rts ok");
259 }
260 void
262  double ackSnr, WifiMode ackMode, double dataSnr)
263 {
265  station->m_lastFrameFail = false;
266  CheckTimeout (station);
267  station->m_counter--;
268  RunBasicAlgorithm (station);
269 }
270 void
272 {
273 }
274 void
276 {
277 }
278 
281  uint32_t size)
282 {
284  if (!station->m_initialized)
285  {
286  ResetCountersBasic (station);
287  }
288  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas()), GetNess (station), GetStbc (station));
289 }
292 {
294 }
295 
296 bool
298  Ptr<const Packet> packet, bool normally)
299 {
301  if (m_basic)
302  {
303  return normally;
304  }
305  ARts (station);
306  return station->m_rtsOn;
307 }
308 
309 void
311 {
312  Time d = Simulator::Now () - station->m_lastReset;
313  if (station->m_counter == 0 || d > m_timeout)
314  {
315  ResetCountersBasic (station);
316  }
317 }
318 
319 void
321 {
322  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
323  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
324  if (station->m_counter == 0
325  || ploss > thresholds.pmtl)
326  {
327  if (station->m_rate > GetMinRate (station)
328  && ploss > thresholds.pmtl)
329  {
330  station->m_rate--;
331  }
332  else if (station->m_rate < GetMaxRate (station)
333  && ploss < thresholds.pori)
334  {
335  station->m_rate++;
336  }
337  ResetCountersBasic (station);
338  }
339 }
340 
341 void
343 {
344  if (!station->m_rtsOn
345  && station->m_lastFrameFail)
346  {
347  station->m_rtsWnd++;
348  station->m_rtsCounter = station->m_rtsWnd;
349  }
350  else if ((station->m_rtsOn && station->m_lastFrameFail)
351  || (!station->m_rtsOn && !station->m_lastFrameFail))
352  {
353  station->m_rtsWnd = station->m_rtsWnd / 2;
354  station->m_rtsCounter = station->m_rtsWnd;
355  }
356  if (station->m_rtsCounter > 0)
357  {
358  station->m_rtsOn = true;
359  station->m_rtsCounter--;
360  }
361  else
362  {
363  station->m_rtsOn = false;
364  }
365 }
366 
368 RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
369  uint32_t rate) const
370 {
371  WifiMode mode = GetSupported (station, rate);
372  return GetThresholds (mode);
373 }
374 
376 RraaWifiManager::GetThresholds (WifiMode mode) const
377 {
378  switch (mode.GetDataRate () / 1000000)
379  {
380  case 54:
381  {
382  ThresholdsItem mode54 = {
383  54000000,
384  0.0,
385  m_pmtlfor54,
387  };
388  return mode54;
389  } break;
390  case 48:
391  {
392  ThresholdsItem mode48 = {
393  48000000,
394  m_porifor48,
395  m_pmtlfor48,
397  };
398  return mode48;
399  } break;
400  case 36:
401  {
402  ThresholdsItem mode36 = {
403  36000000,
404  m_porifor36,
405  m_pmtlfor36,
407  };
408  return mode36;
409  } break;
410  case 24:
411  {
412  ThresholdsItem mode24 = {
413  24000000,
414  m_porifor24,
415  m_pmtlfor24,
417  };
418  return mode24;
419  } break;
420  case 18:
421  {
422  ThresholdsItem mode18 = {
423  18000000,
424  m_porifor18,
425  m_pmtlfor18,
427  };
428  return mode18;
429  } break;
430  case 12:
431  {
432  ThresholdsItem mode12 = {
433  12000000,
434  m_porifor12,
435  m_pmtlfor12,
437  };
438  return mode12;
439  } break;
440  case 9:
441  {
442  ThresholdsItem mode9 = {
443  9000000,
444  m_porifor9,
445  m_pmtlfor9,
446  m_ewndfor9
447  };
448  return mode9;
449  } break;
450  case 6:
451  {
452  ThresholdsItem mode6 = {
453  6000000,
454  m_porifor6,
455  1.0,
456  m_ewndfor6
457  };
458  return mode6;
459  } break;
460  }
461  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
462  return ThresholdsItem ();
463 }
464 
465 bool
467 {
468  return true;
469 }
470 
471 } // 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.
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:446
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:197
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be resetted.
AttributeValue implementation for Time.
Definition: nstime.h:928
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:929
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:866
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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
hold per-remote-station state.