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 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::AarfcdWifiManager")
70  .AddConstructor<AarfcdWifiManager> ()
71  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
72  DoubleValue (2.0),
73  MakeDoubleAccessor (&AarfcdWifiManager::m_successK),
74  MakeDoubleChecker<double> ())
75  .AddAttribute ("TimerK",
76  "Multiplication factor for the timer threshold in the AARF algorithm.",
77  DoubleValue (2.0),
78  MakeDoubleAccessor (&AarfcdWifiManager::m_timerK),
79  MakeDoubleChecker<double> ())
80  .AddAttribute ("MaxSuccessThreshold",
81  "Maximum value of the success threshold in the AARF algorithm.",
82  UintegerValue (60),
83  MakeUintegerAccessor (&AarfcdWifiManager::m_maxSuccessThreshold),
84  MakeUintegerChecker<uint32_t> ())
85  .AddAttribute ("MinTimerThreshold",
86  "The minimum value for the 'timer' threshold in the AARF algorithm.",
87  UintegerValue (15),
88  MakeUintegerAccessor (&AarfcdWifiManager::m_minTimerThreshold),
89  MakeUintegerChecker<uint32_t> ())
90  .AddAttribute ("MinSuccessThreshold",
91  "The minimum value for the success threshold in the AARF algorithm.",
92  UintegerValue (10),
93  MakeUintegerAccessor (&AarfcdWifiManager::m_minSuccessThreshold),
94  MakeUintegerChecker<uint32_t> ())
95  .AddAttribute ("MinRtsWnd",
96  "Minimum value for Rts window of Aarf-CD",
97  UintegerValue (1),
98  MakeUintegerAccessor (&AarfcdWifiManager::m_minRtsWnd),
99  MakeUintegerChecker<uint32_t> ())
100  .AddAttribute ("MaxRtsWnd",
101  "Maximum value for Rts window of Aarf-CD",
102  UintegerValue (40),
103  MakeUintegerAccessor (&AarfcdWifiManager::m_maxRtsWnd),
104  MakeUintegerChecker<uint32_t> ())
105  .AddAttribute ("TurnOffRtsAfterRateDecrease",
106  "If true the RTS mechanism will be turned off when the rate will be decreased",
107  BooleanValue (true),
109  MakeBooleanChecker ())
110  .AddAttribute ("TurnOnRtsAfterRateIncrease",
111  "If true the RTS mechanism will be turned on when the rate will be increased",
112  BooleanValue (true),
114  MakeBooleanChecker ())
115  ;
116  return tid;
117 }
120 {
121  NS_LOG_FUNCTION (this);
122 }
124 {
125  NS_LOG_FUNCTION (this);
126 }
129 {
130  NS_LOG_FUNCTION (this);
132 
133  // aarf fields below
136  station->m_rate = 0;
137  station->m_success = 0;
138  station->m_failed = 0;
139  station->m_recovery = false;
140  station->m_retry = 0;
141  station->m_timer = 0;
142 
143  // aarf-cd specific fields below
144  station->m_rtsOn = false;
145  station->m_rtsWnd = m_minRtsWnd;
146  station->m_rtsCounter = 0;
147  station->m_justModifyRate = true;
148  station->m_haveASuccess = false;
149 
150  return station;
151 }
152 
153 void
155 {
156  NS_LOG_FUNCTION (this << station);
157 }
158 
159 void
161 {
162  NS_LOG_FUNCTION (this << st);
164  station->m_timer++;
165  station->m_failed++;
166  station->m_retry++;
167  station->m_success = 0;
168 
169  if (!station->m_rtsOn)
170  {
171  TurnOnRts (station);
172  if (!station->m_justModifyRate && !station->m_haveASuccess)
173  {
174  IncreaseRtsWnd (station);
175  }
176  else
177  {
178  ResetRtsWnd (station);
179  }
180  station->m_rtsCounter = station->m_rtsWnd;
181  if (station->m_retry >= 2)
182  {
183  station->m_timer = 0;
184  }
185  }
186  else if (station->m_recovery)
187  {
188  NS_ASSERT (station->m_retry >= 1);
189  station->m_justModifyRate = false;
190  station->m_rtsCounter = station->m_rtsWnd;
191  if (station->m_retry == 1)
192  {
193  // need recovery fallback
195  {
196  TurnOffRts (station);
197  }
198  station->m_justModifyRate = true;
199  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
201  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
203  if (station->m_rate != 0)
204  {
205  station->m_rate--;
206  }
207  }
208  station->m_timer = 0;
209  }
210  else
211  {
212  NS_ASSERT (station->m_retry >= 1);
213  station->m_justModifyRate = false;
214  station->m_rtsCounter = station->m_rtsWnd;
215  if (((station->m_retry - 1) % 2) == 1)
216  {
217  // need normal fallback
219  {
220  TurnOffRts (station);
221  }
222  station->m_justModifyRate = true;
225  if (station->m_rate != 0)
226  {
227  station->m_rate--;
228  }
229  }
230  if (station->m_retry >= 2)
231  {
232  station->m_timer = 0;
233  }
234  }
235  CheckRts (station);
236 }
237 void
239  double rxSnr, WifiMode txMode)
240 {
241  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
242 }
243 void
245  double ctsSnr, WifiMode ctsMode, double rtsSnr)
246 {
247  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
249  NS_LOG_DEBUG ("station=" << station << " rts ok");
250  station->m_rtsCounter--;
251 }
252 void
254  double ackSnr, WifiMode ackMode, double dataSnr)
255 {
256  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
258  station->m_timer++;
259  station->m_success++;
260  station->m_failed = 0;
261  station->m_recovery = false;
262  station->m_retry = 0;
263  station->m_justModifyRate = false;
264  station->m_haveASuccess = true;
265  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
266  if ((station->m_success == station->m_successThreshold
267  || station->m_timer == station->m_timerTimeout)
268  && (station->m_rate < (GetNSupported (station) - 1)))
269  {
270  NS_LOG_DEBUG ("station=" << station << " inc rate");
271  station->m_rate++;
272  station->m_timer = 0;
273  station->m_success = 0;
274  station->m_recovery = true;
275  station->m_justModifyRate = true;
277  {
278  TurnOnRts (station);
279  ResetRtsWnd (station);
280  station->m_rtsCounter = station->m_rtsWnd;
281  }
282  }
283  CheckRts (station);
284 }
285 void
287 {
288  NS_LOG_FUNCTION (this << station);
289 }
290 void
292 {
293  NS_LOG_FUNCTION (this << station);
294 }
295 
298 {
299  NS_LOG_FUNCTION (this << st << size);
302 }
305 {
306  NS_LOG_FUNCTION (this << st);
311 }
312 
313 bool
315  Ptr<const Packet> packet, bool normally)
316 {
317  NS_LOG_FUNCTION (this << st << packet << normally);
319  NS_LOG_INFO ("" << station << " rate=" << station->m_rate << " rts=" << (station->m_rtsOn ? "RTS" : "BASIC") <<
320  " rtsCounter=" << station->m_rtsCounter);
321  return station->m_rtsOn;
322 }
323 
324 bool
326 {
327  NS_LOG_FUNCTION (this);
328  return true;
329 }
330 
331 void
333 {
334  NS_LOG_FUNCTION (this << station);
335  if (station->m_rtsCounter == 0 && station->m_rtsOn)
336  {
337  TurnOffRts (station);
338  }
339 }
340 
341 void
343 {
344  NS_LOG_FUNCTION (this << station);
345  station->m_rtsOn = false;
346  station->m_haveASuccess = false;
347 }
348 
349 void
351 {
352  NS_LOG_FUNCTION (this << station);
353  station->m_rtsOn = true;
354 }
355 
356 void
358 {
359  NS_LOG_FUNCTION (this << station);
360  if (station->m_rtsWnd == m_maxRtsWnd)
361  {
362  return;
363  }
364 
365  station->m_rtsWnd *= 2;
366  if (station->m_rtsWnd > m_maxRtsWnd)
367  {
368  station->m_rtsWnd = m_maxRtsWnd;
369  }
370 }
371 
372 void
374 {
375  NS_LOG_FUNCTION (this << station);
376  station->m_rtsWnd = m_minRtsWnd;
377 }
378 
379 
380 } // 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)
Definition: log.h:345
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_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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)
Definition: log.h:298
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.
Hold an unsigned integer type.
Definition: uinteger.h:46
void ResetRtsWnd(AarfcdWifiRemoteStation *station)
Reset the RTS window of the given 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)
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)
Definition: log.h:289
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:611
hold per-remote-station state.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)