A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("RraaWifiManager");
32 
33 namespace ns3 {
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),
66  MakeBooleanAccessor (&RraaWifiManager::m_basic),
67  MakeBooleanChecker ())
68  .AddAttribute ("Timeout",
69  "Timeout for the RRAA BASIC loss estimaton block (s)",
70  TimeValue (Seconds (0.05)),
71  MakeTimeAccessor (&RraaWifiManager::m_timeout),
72  MakeTimeChecker ())
73  .AddAttribute ("ewndFor54mbps",
74  "ewnd parameter for 54 Mbs data mode",
75  UintegerValue (40),
76  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor54),
77  MakeUintegerChecker<uint32_t> ())
78  .AddAttribute ("ewndFor48mbps",
79  "ewnd parameter for 48 Mbs data mode",
80  UintegerValue (40),
81  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor48),
82  MakeUintegerChecker<uint32_t> ())
83  .AddAttribute ("ewndFor36mbps",
84  "ewnd parameter for 36 Mbs data mode",
85  UintegerValue (40),
86  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor36),
87  MakeUintegerChecker<uint32_t> ())
88  .AddAttribute ("ewndFor24mbps",
89  "ewnd parameter for 24 Mbs data mode",
90  UintegerValue (40),
91  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor24),
92  MakeUintegerChecker<uint32_t> ())
93  .AddAttribute ("ewndFor18mbps",
94  "ewnd parameter for 18 Mbs data mode",
95  UintegerValue (20),
96  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor18),
97  MakeUintegerChecker<uint32_t> ())
98  .AddAttribute ("ewndFor12mbps",
99  "ewnd parameter for 12 Mbs data mode",
100  UintegerValue (20),
101  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor12),
102  MakeUintegerChecker<uint32_t> ())
103  .AddAttribute ("ewndFor9mbps",
104  "ewnd parameter for 9 Mbs data mode",
105  UintegerValue (10),
106  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor9),
107  MakeUintegerChecker<uint32_t> ())
108  .AddAttribute ("ewndFor6mbps",
109  "ewnd parameter for 6 Mbs data mode",
110  UintegerValue (6),
111  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor6),
112  MakeUintegerChecker<uint32_t> ())
113  .AddAttribute ("poriFor48mbps",
114  "Pori parameter for 48 Mbs data mode",
115  DoubleValue (0.047),
116  MakeDoubleAccessor (&RraaWifiManager::m_porifor48),
117  MakeDoubleChecker<double> ())
118  .AddAttribute ("poriFor36mbps",
119  "Pori parameter for 36 Mbs data mode",
120  DoubleValue (0.115),
121  MakeDoubleAccessor (&RraaWifiManager::m_porifor36),
122  MakeDoubleChecker<double> ())
123  .AddAttribute ("poriFor24mbps",
124  "Pori parameter for 24 Mbs data mode",
125  DoubleValue (0.1681),
126  MakeDoubleAccessor (&RraaWifiManager::m_porifor24),
127  MakeDoubleChecker<double> ())
128  .AddAttribute ("poriFor18mbps",
129  "Pori parameter for 18 Mbs data mode",
130  DoubleValue (0.1325),
131  MakeDoubleAccessor (&RraaWifiManager::m_porifor18),
132  MakeDoubleChecker<double> ())
133  .AddAttribute ("poriFor12mbps",
134  "Pori parameter for 12 Mbs data mode",
135  DoubleValue (0.1861),
136  MakeDoubleAccessor (&RraaWifiManager::m_porifor12),
137  MakeDoubleChecker<double> ())
138  .AddAttribute ("poriFor9mbps",
139  "Pori parameter for 9 Mbs data mode",
140  DoubleValue (0.1434),
141  MakeDoubleAccessor (&RraaWifiManager::m_porifor9),
142  MakeDoubleChecker<double> ())
143  .AddAttribute ("poriFor6mbps",
144  "Pori parameter for 6 Mbs data mode",
145  DoubleValue (0.5),
146  MakeDoubleAccessor (&RraaWifiManager::m_porifor6),
147  MakeDoubleChecker<double> ())
148  .AddAttribute ("pmtlFor54mbps",
149  "Pmtl parameter for 54 Mbs data mode",
150  DoubleValue (0.094),
151  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor54),
152  MakeDoubleChecker<double> ())
153  .AddAttribute ("pmtlFor48mbps",
154  "Pmtl parameter for 48 Mbs data mode",
155  DoubleValue (0.23),
156  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor48),
157  MakeDoubleChecker<double> ())
158  .AddAttribute ("pmtlFor36mbps",
159  "Pmtl parameter for 36 Mbs data mode",
160  DoubleValue (0.3363),
161  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor36),
162  MakeDoubleChecker<double> ())
163  .AddAttribute ("pmtlFor24mbps",
164  "Pmtl parameter for 24 Mbs data mode",
165  DoubleValue (0.265),
166  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor24),
167  MakeDoubleChecker<double> ())
168  .AddAttribute ("pmtlFor18mbps",
169  "Pmtl parameter for 18 Mbs data mode",
170  DoubleValue (0.3722),
171  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor18),
172  MakeDoubleChecker<double> ())
173  .AddAttribute ("pmtlFor12mbps",
174  "Pmtl parameter for 12 Mbs data mode",
175  DoubleValue (0.2868),
176  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor12),
177  MakeDoubleChecker<double> ())
178  .AddAttribute ("pmtlFor9mbps",
179  "Pmtl parameter for 9 Mbs data mode",
180  DoubleValue (0.3932),
181  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor9),
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  }
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:79
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
Hold a bool native type.
Definition: boolean.h:38
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 the class in the ns-3 factory.
Definition: object-base.h:38
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
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:170
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:91
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
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:194
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be resetted.
hold objects of type ns3::Time
Definition: nstime.h:1008
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:46
hold a list of per-remote-station state.
Robust Rate Adaptation AlgorithmThis is an implementation of RRAA as described in "Robust rate adapta...
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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
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:213
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:441
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.
Hold a floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
hold per-remote-station state.