A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aarfcd-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 "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;
43  bool m_justModifyRate;
44  uint32_t m_retry;
45 
46  uint32_t m_successThreshold;
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;
53  bool m_haveASuccess;
54 };
55 
56 NS_OBJECT_ENSURE_REGISTERED (AarfcdWifiManager);
57 
58 TypeId
59 AarfcdWifiManager::GetTypeId (void)
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),
101  MakeBooleanAccessor (&AarfcdWifiManager::m_turnOffRtsAfterRateDecrease),
102  MakeBooleanChecker ())
103  .AddAttribute ("TurnOnRtsAfterRateIncrease",
104  "If true the RTS mechanism will be turned on when the rate will be increased",
105  BooleanValue (true),
106  MakeBooleanAccessor (&AarfcdWifiManager::m_turnOnRtsAfterRateIncrease),
107  MakeBooleanChecker ())
108  ;
109  return tid;
110 }
111 AarfcdWifiManager::AarfcdWifiManager ()
112  : WifiRemoteStationManager ()
113 {
114  NS_LOG_FUNCTION (this);
115 }
116 AarfcdWifiManager::~AarfcdWifiManager ()
117 {
118  NS_LOG_FUNCTION (this);
119 }
120 WifiRemoteStation *
122 {
123  NS_LOG_FUNCTION (this);
125 
126  // aarf fields below
127  station->m_successThreshold = m_minSuccessThreshold;
128  station->m_timerTimeout = m_minTimerThreshold;
129  station->m_rate = 0;
130  station->m_success = 0;
131  station->m_failed = 0;
132  station->m_recovery = false;
133  station->m_retry = 0;
134  station->m_timer = 0;
135 
136  // aarf-cd specific fields below
137  station->m_rtsOn = false;
138  station->m_rtsWnd = m_minRtsWnd;
139  station->m_rtsCounter = 0;
140  station->m_justModifyRate = true;
141  station->m_haveASuccess = false;
142 
143  return station;
144 }
145 
146 void
147 AarfcdWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
148 {
149  NS_LOG_FUNCTION (this << station);
150 }
160 void
162 {
163  NS_LOG_FUNCTION (this << st);
165  station->m_timer++;
166  station->m_failed++;
167  station->m_retry++;
168  station->m_success = 0;
169 
170  if (!station->m_rtsOn)
171  {
172  TurnOnRts (station);
173  if (!station->m_justModifyRate && !station->m_haveASuccess)
174  {
175  IncreaseRtsWnd (station);
176  }
177  else
178  {
179  ResetRtsWnd (station);
180  }
181  station->m_rtsCounter = station->m_rtsWnd;
182  if (station->m_retry >= 2)
183  {
184  station->m_timer = 0;
185  }
186  }
187  else if (station->m_recovery)
188  {
189  NS_ASSERT (station->m_retry >= 1);
190  station->m_justModifyRate = false;
191  station->m_rtsCounter = station->m_rtsWnd;
192  if (station->m_retry == 1)
193  {
194  // need recovery fallback
195  if (m_turnOffRtsAfterRateDecrease)
196  {
197  TurnOffRts (station);
198  }
199  station->m_justModifyRate = true;
200  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
201  m_maxSuccessThreshold));
202  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
203  m_minSuccessThreshold));
204  if (station->m_rate != 0)
205  {
206  station->m_rate--;
207  }
208  }
209  station->m_timer = 0;
210  }
211  else
212  {
213  NS_ASSERT (station->m_retry >= 1);
214  station->m_justModifyRate = false;
215  station->m_rtsCounter = station->m_rtsWnd;
216  if (((station->m_retry - 1) % 2) == 1)
217  {
218  // need normal fallback
219  if (m_turnOffRtsAfterRateDecrease)
220  {
221  TurnOffRts (station);
222  }
223  station->m_justModifyRate = true;
224  station->m_timerTimeout = m_minTimerThreshold;
225  station->m_successThreshold = m_minSuccessThreshold;
226  if (station->m_rate != 0)
227  {
228  station->m_rate--;
229  }
230  }
231  if (station->m_retry >= 2)
232  {
233  station->m_timer = 0;
234  }
235  }
236  CheckRts (station);
237 }
238 void
239 AarfcdWifiManager::DoReportRxOk (WifiRemoteStation *station,
240  double rxSnr, WifiMode txMode)
241 {
242  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
243 }
244 void
245 AarfcdWifiManager::DoReportRtsOk (WifiRemoteStation *st,
246  double ctsSnr, WifiMode ctsMode, double rtsSnr)
247 {
248  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
249  AarfcdWifiRemoteStation *station = (AarfcdWifiRemoteStation *) st;
250  NS_LOG_DEBUG ("station=" << station << " rts ok");
251  station->m_rtsCounter--;
252 }
253 void
254 AarfcdWifiManager::DoReportDataOk (WifiRemoteStation *st,
255  double ackSnr, WifiMode ackMode, double dataSnr)
256 {
257  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
258  AarfcdWifiRemoteStation *station = (AarfcdWifiRemoteStation *) st;
259  station->m_timer++;
260  station->m_success++;
261  station->m_failed = 0;
262  station->m_recovery = false;
263  station->m_retry = 0;
264  station->m_justModifyRate = false;
265  station->m_haveASuccess = true;
266  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
267  if ((station->m_success == station->m_successThreshold
268  || station->m_timer == station->m_timerTimeout)
269  && (station->m_rate < (GetNSupported (station) - 1)))
270  {
271  NS_LOG_DEBUG ("station=" << station << " inc rate");
272  station->m_rate++;
273  station->m_timer = 0;
274  station->m_success = 0;
275  station->m_recovery = true;
276  station->m_justModifyRate = true;
277  if (m_turnOnRtsAfterRateIncrease)
278  {
279  TurnOnRts (station);
280  ResetRtsWnd (station);
281  station->m_rtsCounter = station->m_rtsWnd;
282  }
283  }
284  CheckRts (station);
285 }
286 void
287 AarfcdWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
288 {
289  NS_LOG_FUNCTION (this << station);
290 }
291 void
292 AarfcdWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station)
293 {
294  NS_LOG_FUNCTION (this << station);
295 }
296 
297 WifiMode
299 {
300  NS_LOG_FUNCTION (this << st << size);
302  return GetSupported (station, station->m_rate);
303 }
304 WifiMode
306 {
307  NS_LOG_FUNCTION (this << st);
308  // XXX: we could/should implement the Aarf algorithm for
309  // RTS only by picking a single rate within the BasicRateSet.
311  return GetSupported (station, 0);
312 }
313 
314 bool
316  Ptr<const Packet> packet, bool normally)
317 {
318  NS_LOG_FUNCTION (this << st << packet << normally);
320  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
321  " rtsCounter=" << station->m_rtsCounter);
322  return station->m_rtsOn;
323 }
324 
325 bool
327 {
328  NS_LOG_FUNCTION (this);
329  return true;
330 }
331 
332 void
333 AarfcdWifiManager::CheckRts (AarfcdWifiRemoteStation *station)
334 {
335  NS_LOG_FUNCTION (this << station);
336  if (station->m_rtsCounter == 0 && station->m_rtsOn)
337  {
338  TurnOffRts (station);
339  }
340 }
341 
342 void
343 AarfcdWifiManager::TurnOffRts (AarfcdWifiRemoteStation *station)
344 {
345  NS_LOG_FUNCTION (this << station);
346  station->m_rtsOn = false;
347  station->m_haveASuccess = false;
348 }
349 
350 void
351 AarfcdWifiManager::TurnOnRts (AarfcdWifiRemoteStation *station)
352 {
353  NS_LOG_FUNCTION (this << station);
354  station->m_rtsOn = true;
355 }
356 
357 void
358 AarfcdWifiManager::IncreaseRtsWnd (AarfcdWifiRemoteStation *station)
359 {
360  NS_LOG_FUNCTION (this << station);
361  if (station->m_rtsWnd == m_maxRtsWnd)
362  {
363  return;
364  }
365 
366  station->m_rtsWnd *= 2;
367  if (station->m_rtsWnd > m_maxRtsWnd)
368  {
369  station->m_rtsWnd = m_maxRtsWnd;
370  }
371 }
372 
373 void
374 AarfcdWifiManager::ResetRtsWnd (AarfcdWifiRemoteStation *station)
375 {
376  NS_LOG_FUNCTION (this << station);
377  station->m_rtsWnd = m_minRtsWnd;
378 }
379 
380 
381 } // namespace ns3
virtual void DoReportDataFailed(WifiRemoteStation *station)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Hold a bool native type.
Definition: boolean.h:38
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
#define NS_LOG_INFO(msg)
Definition: log.h:264
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
Hold an unsigned integer type.
Definition: uinteger.h:46
hold a list of per-remote-station state.
virtual bool IsLowLatency(void) const
virtual WifiRemoteStation * DoCreateStation(void) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
an implementation of the AARF-CD algorithmThis algorithm was first described in "Efficient Collision ...
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
hold per-remote-station state.