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 
44 {
45  uint32_t m_timer;
46  uint32_t m_success;
47  uint32_t m_failed;
48  bool m_recovery;
50  uint32_t m_retry;
51 
53  uint32_t m_timerTimeout;
54 
55  uint32_t m_rate;
56  bool m_rtsOn;
57  uint32_t m_rtsWnd;
58  uint32_t m_rtsCounter;
60 };
61 
63 
64 TypeId
66 {
67  static TypeId tid = TypeId ("ns3::AarfcdWifiManager")
69  .AddConstructor<AarfcdWifiManager> ()
70  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
71  DoubleValue (2.0),
72  MakeDoubleAccessor (&AarfcdWifiManager::m_successK),
73  MakeDoubleChecker<double> ())
74  .AddAttribute ("TimerK",
75  "Multiplication factor for the timer threshold in the AARF algorithm.",
76  DoubleValue (2.0),
77  MakeDoubleAccessor (&AarfcdWifiManager::m_timerK),
78  MakeDoubleChecker<double> ())
79  .AddAttribute ("MaxSuccessThreshold",
80  "Maximum value of the success threshold in the AARF algorithm.",
81  UintegerValue (60),
82  MakeUintegerAccessor (&AarfcdWifiManager::m_maxSuccessThreshold),
83  MakeUintegerChecker<uint32_t> ())
84  .AddAttribute ("MinTimerThreshold",
85  "The minimum value for the 'timer' threshold in the AARF algorithm.",
86  UintegerValue (15),
87  MakeUintegerAccessor (&AarfcdWifiManager::m_minTimerThreshold),
88  MakeUintegerChecker<uint32_t> ())
89  .AddAttribute ("MinSuccessThreshold",
90  "The minimum value for the success threshold in the AARF algorithm.",
91  UintegerValue (10),
92  MakeUintegerAccessor (&AarfcdWifiManager::m_minSuccessThreshold),
93  MakeUintegerChecker<uint32_t> ())
94  .AddAttribute ("MinRtsWnd",
95  "Minimum value for Rts window of Aarf-CD",
96  UintegerValue (1),
97  MakeUintegerAccessor (&AarfcdWifiManager::m_minRtsWnd),
98  MakeUintegerChecker<uint32_t> ())
99  .AddAttribute ("MaxRtsWnd",
100  "Maximum value for Rts window of Aarf-CD",
101  UintegerValue (40),
102  MakeUintegerAccessor (&AarfcdWifiManager::m_maxRtsWnd),
103  MakeUintegerChecker<uint32_t> ())
104  .AddAttribute ("TurnOffRtsAfterRateDecrease",
105  "If true the RTS mechanism will be turned off when the rate will be decreased",
106  BooleanValue (true),
108  MakeBooleanChecker ())
109  .AddAttribute ("TurnOnRtsAfterRateIncrease",
110  "If true the RTS mechanism will be turned on when the rate will be increased",
111  BooleanValue (true),
113  MakeBooleanChecker ())
114  ;
115  return tid;
116 }
119 {
120  NS_LOG_FUNCTION (this);
121 }
123 {
124  NS_LOG_FUNCTION (this);
125 }
128 {
129  NS_LOG_FUNCTION (this);
131 
132  // aarf fields below
135  station->m_rate = 0;
136  station->m_success = 0;
137  station->m_failed = 0;
138  station->m_recovery = false;
139  station->m_retry = 0;
140  station->m_timer = 0;
141 
142  // aarf-cd specific fields below
143  station->m_rtsOn = false;
144  station->m_rtsWnd = m_minRtsWnd;
145  station->m_rtsCounter = 0;
146  station->m_justModifyRate = true;
147  station->m_haveASuccess = false;
148 
149  return station;
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this << station);
156 }
157 
158 void
160 {
161  NS_LOG_FUNCTION (this << st);
163  station->m_timer++;
164  station->m_failed++;
165  station->m_retry++;
166  station->m_success = 0;
167 
168  if (!station->m_rtsOn)
169  {
170  TurnOnRts (station);
171  if (!station->m_justModifyRate && !station->m_haveASuccess)
172  {
173  IncreaseRtsWnd (station);
174  }
175  else
176  {
177  ResetRtsWnd (station);
178  }
179  station->m_rtsCounter = station->m_rtsWnd;
180  if (station->m_retry >= 2)
181  {
182  station->m_timer = 0;
183  }
184  }
185  else if (station->m_recovery)
186  {
187  NS_ASSERT (station->m_retry >= 1);
188  station->m_justModifyRate = false;
189  station->m_rtsCounter = station->m_rtsWnd;
190  if (station->m_retry == 1)
191  {
192  // need recovery fallback
194  {
195  TurnOffRts (station);
196  }
197  station->m_justModifyRate = true;
198  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
200  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
202  if (station->m_rate != 0)
203  {
204  station->m_rate--;
205  }
206  }
207  station->m_timer = 0;
208  }
209  else
210  {
211  NS_ASSERT (station->m_retry >= 1);
212  station->m_justModifyRate = false;
213  station->m_rtsCounter = station->m_rtsWnd;
214  if (((station->m_retry - 1) % 2) == 1)
215  {
216  // need normal fallback
218  {
219  TurnOffRts (station);
220  }
221  station->m_justModifyRate = true;
224  if (station->m_rate != 0)
225  {
226  station->m_rate--;
227  }
228  }
229  if (station->m_retry >= 2)
230  {
231  station->m_timer = 0;
232  }
233  }
234  CheckRts (station);
235 }
236 void
238  double rxSnr, WifiMode txMode)
239 {
240  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
241 }
242 void
244  double ctsSnr, WifiMode ctsMode, double rtsSnr)
245 {
246  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
248  NS_LOG_DEBUG ("station=" << station << " rts ok");
249  station->m_rtsCounter--;
250 }
251 void
253  double ackSnr, WifiMode ackMode, double dataSnr)
254 {
255  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
257  station->m_timer++;
258  station->m_success++;
259  station->m_failed = 0;
260  station->m_recovery = false;
261  station->m_retry = 0;
262  station->m_justModifyRate = false;
263  station->m_haveASuccess = true;
264  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
265  if ((station->m_success == station->m_successThreshold
266  || station->m_timer == station->m_timerTimeout)
267  && (station->m_rate < (GetNSupported (station) - 1)))
268  {
269  NS_LOG_DEBUG ("station=" << station << " inc rate");
270  station->m_rate++;
271  station->m_timer = 0;
272  station->m_success = 0;
273  station->m_recovery = true;
274  station->m_justModifyRate = true;
276  {
277  TurnOnRts (station);
278  ResetRtsWnd (station);
279  station->m_rtsCounter = station->m_rtsWnd;
280  }
281  }
282  CheckRts (station);
283 }
284 void
286 {
287  NS_LOG_FUNCTION (this << station);
288 }
289 void
291 {
292  NS_LOG_FUNCTION (this << station);
293 }
294 
297 {
298  NS_LOG_FUNCTION (this << st << size);
301 }
304 {
305  NS_LOG_FUNCTION (this << st);
310 }
311 
312 bool
314  Ptr<const Packet> packet, bool normally)
315 {
316  NS_LOG_FUNCTION (this << st << packet << normally);
318  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
319  " rtsCounter=" << station->m_rtsCounter);
320  return station->m_rtsOn;
321 }
322 
323 bool
325 {
326  NS_LOG_FUNCTION (this);
327  return true;
328 }
329 
330 void
332 {
333  NS_LOG_FUNCTION (this << station);
334  if (station->m_rtsCounter == 0 && station->m_rtsOn)
335  {
336  TurnOffRts (station);
337  }
338 }
339 
340 void
342 {
343  NS_LOG_FUNCTION (this << station);
344  station->m_rtsOn = false;
345  station->m_haveASuccess = false;
346 }
347 
348 void
350 {
351  NS_LOG_FUNCTION (this << station);
352  station->m_rtsOn = true;
353 }
354 
355 void
357 {
358  NS_LOG_FUNCTION (this << station);
359  if (station->m_rtsWnd == m_maxRtsWnd)
360  {
361  return;
362  }
363 
364  station->m_rtsWnd *= 2;
365  if (station->m_rtsWnd > m_maxRtsWnd)
366  {
367  station->m_rtsWnd = m_maxRtsWnd;
368  }
369 }
370 
371 void
373 {
374  NS_LOG_FUNCTION (this << station);
375  station->m_rtsWnd = m_minRtsWnd;
376 }
377 
378 
379 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
virtual void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a bool native type.
Definition: boolean.h:38
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
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)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
Return the number of receive antenna the station has.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
void TurnOnRts(AarfcdWifiRemoteStation *station)
Turn on RTS for the given station.
void TurnOffRts(AarfcdWifiRemoteStation *station)
Turn off RTS for the given station.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:194
Hold an unsigned integer type.
Definition: uinteger.h:46
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:204
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
Reset the RTS window of the given station.
hold a list of per-remote-station state.
void CheckRts(AarfcdWifiRemoteStation *station)
Check if the use of RTS for the given station can be turned off.
virtual bool IsLowLatency(void) const
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
virtual WifiRemoteStation * DoCreateStation(void) const
hold per-remote-station state for AARF-CD Wifi manager.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
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)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
This method is a pure virtual method that must be implemented by the sub-class.
Hold a floating point type.
Definition: double.h:41
void IncreaseRtsWnd(AarfcdWifiRemoteStation *station)
Increase the RTS window size of the given 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)