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  NS_LOG_FUNCTION (this);
115 }
117 {
118  NS_LOG_FUNCTION (this);
119 }
122 {
123  NS_LOG_FUNCTION (this);
125 
126  // aarf fields below
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
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
196  {
197  TurnOffRts (station);
198  }
199  station->m_justModifyRate = true;
200  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
202  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
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
220  {
221  TurnOffRts (station);
222  }
223  station->m_justModifyRate = true;
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
240  double rxSnr, WifiMode txMode)
241 {
242  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
243 }
244 void
246  double ctsSnr, WifiMode ctsMode, double rtsSnr)
247 {
248  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
250  NS_LOG_DEBUG ("station=" << station << " rts ok");
251  station->m_rtsCounter--;
252 }
253 void
255  double ackSnr, WifiMode ackMode, double dataSnr)
256 {
257  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
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;
278  {
279  TurnOnRts (station);
280  ResetRtsWnd (station);
281  station->m_rtsCounter = station->m_rtsWnd;
282  }
283  }
284  CheckRts (station);
285 }
286 void
288 {
289  NS_LOG_FUNCTION (this << station);
290 }
291 void
293 {
294  NS_LOG_FUNCTION (this << station);
295 }
296 
299 {
300  NS_LOG_FUNCTION (this << st << size);
303 }
306 {
307  NS_LOG_FUNCTION (this << st);
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
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
344 {
345  NS_LOG_FUNCTION (this << station);
346  station->m_rtsOn = false;
347  station->m_haveASuccess = false;
348 }
349 
350 void
352 {
353  NS_LOG_FUNCTION (this << station);
354  station->m_rtsOn = true;
355 }
356 
357 void
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
375 {
376  NS_LOG_FUNCTION (this << station);
377  station->m_rtsWnd = m_minRtsWnd;
378 }
379 
380 
381 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
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)
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
#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:91
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
bool GetStbc(const WifiRemoteStation *station) const
void TurnOnRts(AarfcdWifiRemoteStation *station)
void TurnOffRts(AarfcdWifiRemoteStation *station)
Hold an unsigned integer type.
Definition: uinteger.h:46
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
NS_LOG_COMPONENT_DEFINE("Aarfcd")
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:95
hold a list of per-remote-station state.
void CheckRts(AarfcdWifiRemoteStation *station)
virtual bool IsLowLatency(void) const
virtual void DoReportRtsFailed(WifiRemoteStation *station)
bool GetShortGuardInterval(const WifiRemoteStation *station) const
virtual WifiRemoteStation * DoCreateStation(void) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
static TypeId GetTypeId(void)
an implementation of the AARF-CD algorithmThis algorithm was first described in "Efficient Collision ...
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
Hold an floating point type.
Definition: double.h:41
void IncreaseRtsWnd(AarfcdWifiRemoteStation *station)
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.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)