A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aarfcd-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 "aarfcd-wifi-manager.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/simulator.h"
25 #include "ns3/boolean.h"
26 #include "ns3/double.h"
27 #include "ns3/uinteger.h"
28 #include <algorithm>
29 
30 #define Min(a,b) ((a < b) ? a : b)
31 #define Max(a,b) ((a > b) ? a : b)
32 
33 NS_LOG_COMPONENT_DEFINE ("Aarfcd");
34 
35 namespace ns3 {
36 
38 {
39  uint32_t m_timer;
40  uint32_t m_success;
41  uint32_t m_failed;
42  bool m_recovery;
44  uint32_t m_retry;
45 
47  uint32_t m_timerTimeout;
48 
49  uint32_t m_rate;
50  bool m_rtsOn;
51  uint32_t m_rtsWnd;
52  uint32_t m_rtsCounter;
54 };
55 
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::AarfcdWifiManager")
63  .AddConstructor<AarfcdWifiManager> ()
64  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
65  DoubleValue (2.0),
66  MakeDoubleAccessor (&AarfcdWifiManager::m_successK),
67  MakeDoubleChecker<double> ())
68  .AddAttribute ("TimerK",
69  "Multiplication factor for the timer threshold in the AARF algorithm.",
70  DoubleValue (2.0),
71  MakeDoubleAccessor (&AarfcdWifiManager::m_timerK),
72  MakeDoubleChecker<double> ())
73  .AddAttribute ("MaxSuccessThreshold",
74  "Maximum value of the success threshold in the AARF algorithm.",
75  UintegerValue (60),
76  MakeUintegerAccessor (&AarfcdWifiManager::m_maxSuccessThreshold),
77  MakeUintegerChecker<uint32_t> ())
78  .AddAttribute ("MinTimerThreshold",
79  "The minimum value for the 'timer' threshold in the AARF algorithm.",
80  UintegerValue (15),
81  MakeUintegerAccessor (&AarfcdWifiManager::m_minTimerThreshold),
82  MakeUintegerChecker<uint32_t> ())
83  .AddAttribute ("MinSuccessThreshold",
84  "The minimum value for the success threshold in the AARF algorithm.",
85  UintegerValue (10),
86  MakeUintegerAccessor (&AarfcdWifiManager::m_minSuccessThreshold),
87  MakeUintegerChecker<uint32_t> ())
88  .AddAttribute ("MinRtsWnd",
89  "Minimum value for Rts window of Aarf-CD",
90  UintegerValue (1),
91  MakeUintegerAccessor (&AarfcdWifiManager::m_minRtsWnd),
92  MakeUintegerChecker<uint32_t> ())
93  .AddAttribute ("MaxRtsWnd",
94  "Maximum value for Rts window of Aarf-CD",
95  UintegerValue (40),
96  MakeUintegerAccessor (&AarfcdWifiManager::m_maxRtsWnd),
97  MakeUintegerChecker<uint32_t> ())
98  .AddAttribute ("TurnOffRtsAfterRateDecrease",
99  "If true the RTS mechanism will be turned off when the rate will be decreased",
100  BooleanValue (true),
102  MakeBooleanChecker ())
103  .AddAttribute ("TurnOnRtsAfterRateIncrease",
104  "If true the RTS mechanism will be turned on when the rate will be increased",
105  BooleanValue (true),
107  MakeBooleanChecker ())
108  ;
109  return tid;
110 }
113 {
114 }
116 {
117 }
120 {
122 
123  // aarf fields below
126  station->m_rate = 0;
127  station->m_success = 0;
128  station->m_failed = 0;
129  station->m_recovery = false;
130  station->m_retry = 0;
131  station->m_timer = 0;
132 
133  // aarf-cd specific fields below
134  station->m_rtsOn = false;
135  station->m_rtsWnd = m_minRtsWnd;
136  station->m_rtsCounter = 0;
137  station->m_justModifyRate = true;
138  station->m_haveASuccess = false;
139 
140  return station;
141 }
142 
143 void
145 {
146 }
156 void
158 {
159 
161  station->m_timer++;
162  station->m_failed++;
163  station->m_retry++;
164  station->m_success = 0;
165 
166  if (!station->m_rtsOn)
167  {
168  TurnOnRts (station);
169  if (!station->m_justModifyRate && !station->m_haveASuccess)
170  {
171  IncreaseRtsWnd (station);
172  }
173  else
174  {
175  ResetRtsWnd (station);
176  }
177  station->m_rtsCounter = station->m_rtsWnd;
178  if (station->m_retry >= 2)
179  {
180  station->m_timer = 0;
181  }
182  }
183  else if (station->m_recovery)
184  {
185  NS_ASSERT (station->m_retry >= 1);
186  station->m_justModifyRate = false;
187  station->m_rtsCounter = station->m_rtsWnd;
188  if (station->m_retry == 1)
189  {
190  // need recovery fallback
192  {
193  TurnOffRts (station);
194  }
195  station->m_justModifyRate = true;
196  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
198  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
200  if (station->m_rate != 0)
201  {
202  station->m_rate--;
203  }
204  }
205  station->m_timer = 0;
206  }
207  else
208  {
209  NS_ASSERT (station->m_retry >= 1);
210  station->m_justModifyRate = false;
211  station->m_rtsCounter = station->m_rtsWnd;
212  if (((station->m_retry - 1) % 2) == 1)
213  {
214  // need normal fallback
216  {
217  TurnOffRts (station);
218  }
219  station->m_justModifyRate = true;
222  if (station->m_rate != 0)
223  {
224  station->m_rate--;
225  }
226  }
227  if (station->m_retry >= 2)
228  {
229  station->m_timer = 0;
230  }
231  }
232  CheckRts (station);
233 }
234 void
236  double rxSnr, WifiMode txMode)
237 {
238 }
239 void
241  double ctsSnr, WifiMode ctsMode, double rtsSnr)
242 {
244  NS_LOG_DEBUG ("station=" << station << " rts ok");
245  station->m_rtsCounter--;
246 }
247 void
249  double ackSnr, WifiMode ackMode, double dataSnr)
250 {
252  station->m_timer++;
253  station->m_success++;
254  station->m_failed = 0;
255  station->m_recovery = false;
256  station->m_retry = 0;
257  station->m_justModifyRate = false;
258  station->m_haveASuccess = true;
259  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
260  if ((station->m_success == station->m_successThreshold
261  || station->m_timer == station->m_timerTimeout)
262  && (station->m_rate < (GetNSupported (station) - 1)))
263  {
264  NS_LOG_DEBUG ("station=" << station << " inc rate");
265  station->m_rate++;
266  station->m_timer = 0;
267  station->m_success = 0;
268  station->m_recovery = true;
269  station->m_justModifyRate = true;
271  {
272  TurnOnRts (station);
273  ResetRtsWnd (station);
274  station->m_rtsCounter = station->m_rtsWnd;
275  }
276  }
277  CheckRts (station);
278 }
279 void
281 {
282 }
283 void
285 {
286 }
287 
288 WifiMode
290 {
292  return GetSupported (station, station->m_rate);
293 }
294 WifiMode
296 {
297  // XXX: we could/should implement the Aarf algorithm for
298  // RTS only by picking a single rate within the BasicRateSet.
300  return GetSupported (station, 0);
301 }
302 
303 bool
305  Ptr<const Packet> packet, bool normally)
306 {
308  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
309  " rtsCounter=" << station->m_rtsCounter);
310  return station->m_rtsOn;
311 }
312 
313 bool
315 {
316  return true;
317 }
318 
319 void
321 {
322  if (station->m_rtsCounter == 0 && station->m_rtsOn)
323  {
324  TurnOffRts (station);
325  }
326 }
327 
328 void
330 {
331  station->m_rtsOn = false;
332  station->m_haveASuccess = false;
333 }
334 
335 void
337 {
338  station->m_rtsOn = true;
339 }
340 
341 void
343 {
344  if (station->m_rtsWnd == m_maxRtsWnd)
345  {
346  return;
347  }
348 
349  station->m_rtsWnd *= 2;
350  if (station->m_rtsWnd > m_maxRtsWnd)
351  {
352  station->m_rtsWnd = m_maxRtsWnd;
353  }
354 }
355 
356 void
358 {
359  station->m_rtsWnd = m_minRtsWnd;
360 }
361 
362 
363 } // namespace ns3