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 
36 {
37  uint32_t m_counter;
38  uint32_t m_failed;
39  uint32_t m_rtsWnd;
40  uint32_t m_rtsCounter;
42  bool m_rtsOn;
45 
46  uint32_t m_rate;
47 };
48 
50 
51 TypeId
53 {
54  static TypeId tid = TypeId ("ns3::RraaWifiManager")
56  .AddConstructor<RraaWifiManager> ()
57  .AddAttribute ("Basic",
58  "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA wil be used",
59  BooleanValue (false),
60  MakeBooleanAccessor (&RraaWifiManager::m_basic),
61  MakeBooleanChecker ())
62  .AddAttribute ("Timeout",
63  "Timeout for the RRAA BASIC loss estimaton block (s)",
64  TimeValue (Seconds (0.05)),
65  MakeTimeAccessor (&RraaWifiManager::m_timeout),
66  MakeTimeChecker ())
67  .AddAttribute ("ewndFor54mbps",
68  "ewnd parameter for 54 Mbs data mode",
69  UintegerValue (40),
70  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor54),
71  MakeUintegerChecker<uint32_t> ())
72  .AddAttribute ("ewndFor48mbps",
73  "ewnd parameter for 48 Mbs data mode",
74  UintegerValue (40),
75  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor48),
76  MakeUintegerChecker<uint32_t> ())
77  .AddAttribute ("ewndFor36mbps",
78  "ewnd parameter for 36 Mbs data mode",
79  UintegerValue (40),
80  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor36),
81  MakeUintegerChecker<uint32_t> ())
82  .AddAttribute ("ewndFor24mbps",
83  "ewnd parameter for 24 Mbs data mode",
84  UintegerValue (40),
85  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor24),
86  MakeUintegerChecker<uint32_t> ())
87  .AddAttribute ("ewndFor18mbps",
88  "ewnd parameter for 18 Mbs data mode",
89  UintegerValue (20),
90  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor18),
91  MakeUintegerChecker<uint32_t> ())
92  .AddAttribute ("ewndFor12mbps",
93  "ewnd parameter for 12 Mbs data mode",
94  UintegerValue (20),
95  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor12),
96  MakeUintegerChecker<uint32_t> ())
97  .AddAttribute ("ewndFor9mbps",
98  "ewnd parameter for 9 Mbs data mode",
99  UintegerValue (10),
100  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor9),
101  MakeUintegerChecker<uint32_t> ())
102  .AddAttribute ("ewndFor6mbps",
103  "ewnd parameter for 6 Mbs data mode",
104  UintegerValue (6),
105  MakeUintegerAccessor (&RraaWifiManager::m_ewndfor6),
106  MakeUintegerChecker<uint32_t> ())
107  .AddAttribute ("poriFor48mbps",
108  "Pori parameter for 48 Mbs data mode",
109  DoubleValue (0.047),
110  MakeDoubleAccessor (&RraaWifiManager::m_porifor48),
111  MakeDoubleChecker<double> ())
112  .AddAttribute ("poriFor36mbps",
113  "Pori parameter for 36 Mbs data mode",
114  DoubleValue (0.115),
115  MakeDoubleAccessor (&RraaWifiManager::m_porifor36),
116  MakeDoubleChecker<double> ())
117  .AddAttribute ("poriFor24mbps",
118  "Pori parameter for 24 Mbs data mode",
119  DoubleValue (0.1681),
120  MakeDoubleAccessor (&RraaWifiManager::m_porifor24),
121  MakeDoubleChecker<double> ())
122  .AddAttribute ("poriFor18mbps",
123  "Pori parameter for 18 Mbs data mode",
124  DoubleValue (0.1325),
125  MakeDoubleAccessor (&RraaWifiManager::m_porifor18),
126  MakeDoubleChecker<double> ())
127  .AddAttribute ("poriFor12mbps",
128  "Pori parameter for 12 Mbs data mode",
129  DoubleValue (0.1861),
130  MakeDoubleAccessor (&RraaWifiManager::m_porifor12),
131  MakeDoubleChecker<double> ())
132  .AddAttribute ("poriFor9mbps",
133  "Pori parameter for 9 Mbs data mode",
134  DoubleValue (0.1434),
135  MakeDoubleAccessor (&RraaWifiManager::m_porifor9),
136  MakeDoubleChecker<double> ())
137  .AddAttribute ("poriFor6mbps",
138  "Pori parameter for 6 Mbs data mode",
139  DoubleValue (0.5),
140  MakeDoubleAccessor (&RraaWifiManager::m_porifor6),
141  MakeDoubleChecker<double> ())
142  .AddAttribute ("pmtlFor54mbps",
143  "Pmtl parameter for 54 Mbs data mode",
144  DoubleValue (0.094),
145  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor54),
146  MakeDoubleChecker<double> ())
147  .AddAttribute ("pmtlFor48mbps",
148  "Pmtl parameter for 48 Mbs data mode",
149  DoubleValue (0.23),
150  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor48),
151  MakeDoubleChecker<double> ())
152  .AddAttribute ("pmtlFor36mbps",
153  "Pmtl parameter for 36 Mbs data mode",
154  DoubleValue (0.3363),
155  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor36),
156  MakeDoubleChecker<double> ())
157  .AddAttribute ("pmtlFor24mbps",
158  "Pmtl parameter for 24 Mbs data mode",
159  DoubleValue (0.265),
160  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor24),
161  MakeDoubleChecker<double> ())
162  .AddAttribute ("pmtlFor18mbps",
163  "Pmtl parameter for 18 Mbs data mode",
164  DoubleValue (0.3722),
165  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor18),
166  MakeDoubleChecker<double> ())
167  .AddAttribute ("pmtlFor12mbps",
168  "Pmtl parameter for 12 Mbs data mode",
169  DoubleValue (0.2868),
170  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor12),
171  MakeDoubleChecker<double> ())
172  .AddAttribute ("pmtlFor9mbps",
173  "Pmtl parameter for 9 Mbs data mode",
174  DoubleValue (0.3932),
175  MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor9),
176  MakeDoubleChecker<double> ())
177  ;
178  return tid;
179 }
180 
181 
183 {
184 }
186 {
187 }
188 
189 
192 {
194  station->m_initialized = false;
195  station->m_rtsWnd = 0;
196  station->m_rtsCounter = 0;
197  station->m_rtsOn = false;
198  station->m_lastFrameFail = false;
199  return station;
200 }
201 
202 void
204 {
205  if (!station->m_initialized)
206  {
207  station->m_rate = GetMaxRate (station);
208  station->m_initialized = true;
209  }
210  station->m_failed = 0;
211  station->m_counter = GetThresholds (station, station->m_rate).ewnd;
212  station->m_lastReset = Simulator::Now ();
213 }
214 
215 uint32_t
217 {
218  return GetNSupported (station) - 1;
219 }
220 uint32_t
222 {
223  return 0;
224 }
225 
226 
227 void
229 {
230 }
231 
232 void
234 {
236  station->m_lastFrameFail = true;
237  CheckTimeout (station);
238  station->m_counter--;
239  station->m_failed++;
240  RunBasicAlgorithm (station);
241 }
242 void
244  double rxSnr, WifiMode txMode)
245 {
246 }
247 void
249  double ctsSnr, WifiMode ctsMode, double rtsSnr)
250 {
251  NS_LOG_DEBUG ("self=" << st << " rts ok");
252 }
253 void
255  double ackSnr, WifiMode ackMode, double dataSnr)
256 {
258  station->m_lastFrameFail = false;
259  CheckTimeout (station);
260  station->m_counter--;
261  RunBasicAlgorithm (station);
262 }
263 void
265 {
266 }
267 void
269 {
270 }
271 
274  uint32_t size)
275 {
277  if (!station->m_initialized)
278  {
279  ResetCountersBasic (station);
280  }
282 }
285 {
287 }
288 
289 bool
291  Ptr<const Packet> packet, bool normally)
292 {
294  if (m_basic)
295  {
296  return normally;
297  }
298  ARts (station);
299  return station->m_rtsOn;
300 }
301 
302 void
304 {
305  Time d = Simulator::Now () - station->m_lastReset;
306  if (station->m_counter == 0 || d > m_timeout)
307  {
308  ResetCountersBasic (station);
309  }
310 }
311 
312 void
314 {
315  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
316  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
317  if (station->m_counter == 0
318  || ploss > thresholds.pmtl)
319  {
320  if (station->m_rate > GetMinRate (station)
321  && ploss > thresholds.pmtl)
322  {
323  station->m_rate--;
324  }
325  else if (station->m_rate < GetMaxRate (station)
326  && ploss < thresholds.pori)
327  {
328  station->m_rate++;
329  }
330  ResetCountersBasic (station);
331  }
332 }
333 
334 void
336 {
337  if (!station->m_rtsOn
338  && station->m_lastFrameFail)
339  {
340  station->m_rtsWnd++;
341  station->m_rtsCounter = station->m_rtsWnd;
342  }
343  else if ((station->m_rtsOn && station->m_lastFrameFail)
344  || (!station->m_rtsOn && !station->m_lastFrameFail))
345  {
346  station->m_rtsWnd = station->m_rtsWnd / 2;
347  station->m_rtsCounter = station->m_rtsWnd;
348  }
349  if (station->m_rtsCounter > 0)
350  {
351  station->m_rtsOn = true;
352  station->m_rtsCounter--;
353  }
354  else
355  {
356  station->m_rtsOn = false;
357  }
358 }
359 
361 RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
362  uint32_t rate) const
363 {
364  WifiMode mode = GetSupported (station, rate);
365  return GetThresholds (mode);
366 }
367 
369 RraaWifiManager::GetThresholds (WifiMode mode) const
370 {
371  switch (mode.GetDataRate () / 1000000)
372  {
373  case 54:
374  {
375  ThresholdsItem mode54 = {
376  54000000,
377  0.0,
378  m_pmtlfor54,
380  };
381  return mode54;
382  } break;
383  case 48:
384  {
385  ThresholdsItem mode48 = {
386  48000000,
387  m_porifor48,
388  m_pmtlfor48,
390  };
391  return mode48;
392  } break;
393  case 36:
394  {
395  ThresholdsItem mode36 = {
396  36000000,
397  m_porifor36,
398  m_pmtlfor36,
400  };
401  return mode36;
402  } break;
403  case 24:
404  {
405  ThresholdsItem mode24 = {
406  24000000,
407  m_porifor24,
408  m_pmtlfor24,
410  };
411  return mode24;
412  } break;
413  case 18:
414  {
415  ThresholdsItem mode18 = {
416  18000000,
417  m_porifor18,
418  m_pmtlfor18,
420  };
421  return mode18;
422  } break;
423  case 12:
424  {
425  ThresholdsItem mode12 = {
426  12000000,
427  m_porifor12,
428  m_pmtlfor12,
430  };
431  return mode12;
432  } break;
433  case 9:
434  {
435  ThresholdsItem mode9 = {
436  9000000,
437  m_porifor9,
438  m_pmtlfor9,
439  m_ewndfor9
440  };
441  return mode9;
442  } break;
443  case 6:
444  {
445  ThresholdsItem mode6 = {
446  6000000,
447  m_porifor6,
448  1.0,
449  m_ewndfor6
450  };
451  return mode6;
452  } break;
453  }
454  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
455  return ThresholdsItem ();
456 }
457 
458 bool
460 {
461  return true;
462 }
463 
464 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
uint32_t GetMaxRate(RraaWifiRemoteStation *station)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
Hold a bool native type.
Definition: boolean.h:38
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
static TypeId GetTypeId(void)
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
struct ThresholdsItem GetThresholds(WifiMode mode) const
void RunBasicAlgorithm(RraaWifiRemoteStation *station)
virtual bool DoNeedRts(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
virtual bool IsLowLatency(void) const
virtual void DoReportRtsFailed(WifiRemoteStation *station)
void ResetCountersBasic(RraaWifiRemoteStation *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
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
virtual WifiRemoteStation * DoCreateStation(void) const
bool GetStbc(const WifiRemoteStation *station) const
void CheckTimeout(RraaWifiRemoteStation *station)
NS_LOG_COMPONENT_DEFINE("RraaWifiManager")
hold objects of type ns3::Time
Definition: nstime.h:828
virtual void DoReportDataFailed(WifiRemoteStation *station)
Hold an unsigned integer type.
Definition: uinteger.h:46
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
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
static Time Now(void)
Definition: simulator.cc:180
void ARts(RraaWifiRemoteStation *station)
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range. Both limits are inclusive.
Definition: time.cc:404
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
uint32_t GetMinRate(RraaWifiRemoteStation *station)
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
Hold an 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.