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