21 #include "aarfcd-wifi-manager.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulator.h"
25 #include "ns3/boolean.h"
26 #include "ns3/double.h"
27 #include "ns3/uinteger.h"
30 #define Min(a,b) ((a < b) ? a : b)
31 #define Max(a,b) ((a > b) ? a : b)
43 bool m_justModifyRate;
46 uint32_t m_successThreshold;
47 uint32_t m_timerTimeout;
52 uint32_t m_rtsCounter;
59 AarfcdWifiManager::GetTypeId (
void)
63 .AddConstructor<AarfcdWifiManager> ()
64 .AddAttribute (
"SuccessK",
"Multiplication factor for the success threshold in the AARF algorithm.",
66 MakeDoubleAccessor (&AarfcdWifiManager::m_successK),
67 MakeDoubleChecker<double> ())
68 .AddAttribute (
"TimerK",
69 "Multiplication factor for the timer threshold in the AARF algorithm.",
71 MakeDoubleAccessor (&AarfcdWifiManager::m_timerK),
72 MakeDoubleChecker<double> ())
73 .AddAttribute (
"MaxSuccessThreshold",
74 "Maximum value of the success threshold in the AARF algorithm.",
76 MakeUintegerAccessor (&AarfcdWifiManager::m_maxSuccessThreshold),
77 MakeUintegerChecker<uint32_t> ())
78 .AddAttribute (
"MinTimerThreshold",
79 "The minimum value for the 'timer' threshold in the AARF algorithm.",
81 MakeUintegerAccessor (&AarfcdWifiManager::m_minTimerThreshold),
82 MakeUintegerChecker<uint32_t> ())
83 .AddAttribute (
"MinSuccessThreshold",
84 "The minimum value for the success threshold in the AARF algorithm.",
86 MakeUintegerAccessor (&AarfcdWifiManager::m_minSuccessThreshold),
87 MakeUintegerChecker<uint32_t> ())
88 .AddAttribute (
"MinRtsWnd",
89 "Minimum value for Rts window of Aarf-CD",
91 MakeUintegerAccessor (&AarfcdWifiManager::m_minRtsWnd),
92 MakeUintegerChecker<uint32_t> ())
93 .AddAttribute (
"MaxRtsWnd",
94 "Maximum value for Rts window of Aarf-CD",
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",
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",
106 MakeBooleanAccessor (&AarfcdWifiManager::m_turnOnRtsAfterRateIncrease),
107 MakeBooleanChecker ())
111 AarfcdWifiManager::AarfcdWifiManager ()
112 : WifiRemoteStationManager ()
116 AarfcdWifiManager::~AarfcdWifiManager ()
127 station->m_successThreshold = m_minSuccessThreshold;
128 station->m_timerTimeout = m_minTimerThreshold;
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;
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;
168 station->m_success = 0;
170 if (!station->m_rtsOn)
173 if (!station->m_justModifyRate && !station->m_haveASuccess)
175 IncreaseRtsWnd (station);
179 ResetRtsWnd (station);
181 station->m_rtsCounter = station->m_rtsWnd;
182 if (station->m_retry >= 2)
184 station->m_timer = 0;
187 else if (station->m_recovery)
190 station->m_justModifyRate =
false;
191 station->m_rtsCounter = station->m_rtsWnd;
192 if (station->m_retry == 1)
195 if (m_turnOffRtsAfterRateDecrease)
197 TurnOffRts (station);
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)
209 station->m_timer = 0;
214 station->m_justModifyRate =
false;
215 station->m_rtsCounter = station->m_rtsWnd;
216 if (((station->m_retry - 1) % 2) == 1)
219 if (m_turnOffRtsAfterRateDecrease)
221 TurnOffRts (station);
223 station->m_justModifyRate =
true;
224 station->m_timerTimeout = m_minTimerThreshold;
225 station->m_successThreshold = m_minSuccessThreshold;
226 if (station->m_rate != 0)
231 if (station->m_retry >= 2)
233 station->m_timer = 0;
245 AarfcdWifiManager::DoReportRtsOk (WifiRemoteStation *st,
246 double ctsSnr, WifiMode ctsMode,
double rtsSnr)
249 AarfcdWifiRemoteStation *station = (AarfcdWifiRemoteStation *) st;
251 station->m_rtsCounter--;
254 AarfcdWifiManager::DoReportDataOk (WifiRemoteStation *st,
255 double ackSnr, WifiMode ackMode,
double dataSnr)
258 AarfcdWifiRemoteStation *station = (AarfcdWifiRemoteStation *) st;
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)))
273 station->m_timer = 0;
274 station->m_success = 0;
275 station->m_recovery =
true;
276 station->m_justModifyRate =
true;
277 if (m_turnOnRtsAfterRateIncrease)
280 ResetRtsWnd (station);
281 station->m_rtsCounter = station->m_rtsWnd;
287 AarfcdWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
292 AarfcdWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station)
302 return GetSupported (station, station->m_rate);
311 return GetSupported (station, 0);
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;
336 if (station->m_rtsCounter == 0 && station->m_rtsOn)
338 TurnOffRts (station);
343 AarfcdWifiManager::TurnOffRts (AarfcdWifiRemoteStation *station)
346 station->m_rtsOn =
false;
347 station->m_haveASuccess =
false;
351 AarfcdWifiManager::TurnOnRts (AarfcdWifiRemoteStation *station)
354 station->m_rtsOn =
true;
358 AarfcdWifiManager::IncreaseRtsWnd (AarfcdWifiRemoteStation *station)
361 if (station->m_rtsWnd == m_maxRtsWnd)
366 station->m_rtsWnd *= 2;
367 if (station->m_rtsWnd > m_maxRtsWnd)
369 station->m_rtsWnd = m_maxRtsWnd;
374 AarfcdWifiManager::ResetRtsWnd (AarfcdWifiRemoteStation *station)
377 station->m_rtsWnd = m_minRtsWnd;
virtual void DoReportDataFailed(WifiRemoteStation *station)
#define NS_LOG_FUNCTION(parameters)
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Hold an unsigned integer type.
hold a list of per-remote-station state.
virtual bool IsLowLatency(void) const
virtual WifiRemoteStation * DoCreateStation(void) const
#define NS_LOG_DEBUG(msg)
an implementation of the AARF-CD algorithmThis algorithm was first described in "Efficient Collision ...
Hold an floating point type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
hold per-remote-station state.