21 #include "amrr-wifi-manager.h"
22 #include "ns3/simulator.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/double.h"
33 Time m_nextModeUpdate;
39 uint32_t m_successThreshold;
48 AmrrWifiManager::GetTypeId (
void)
52 .AddConstructor<AmrrWifiManager> ()
53 .AddAttribute (
"UpdatePeriod",
54 "The interval between decisions about rate control changes",
56 MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod),
58 .AddAttribute (
"FailureRatio",
59 "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
61 MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
62 MakeDoubleChecker<double> (0.0, 1.0))
63 .AddAttribute (
"SuccessRatio",
64 "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
66 MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
67 MakeDoubleChecker<double> (0.0, 1.0))
68 .AddAttribute (
"MaxSuccessThreshold",
69 "Maximum number of consecutive success periods needed to switch to a higher rate",
71 MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold),
72 MakeUintegerChecker<uint32_t> ())
73 .AddAttribute (
"MinSuccessThreshold",
74 "Minimum number of consecutive success periods needed to switch to a higher rate",
76 MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold),
77 MakeUintegerChecker<uint32_t> ())
82 AmrrWifiManager::AmrrWifiManager ()
94 station->m_tx_err = 0;
95 station->m_tx_retr = 0;
97 station->m_txrate = 0;
98 station->m_successThreshold = m_minSuccessThreshold;
99 station->m_success = 0;
100 station->m_recovery =
false;
112 AmrrWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
117 AmrrWifiManager::DoReportDataFailed (WifiRemoteStation *st)
120 AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
122 station->m_tx_retr++;
125 AmrrWifiManager::DoReportRtsOk (WifiRemoteStation *st,
126 double ctsSnr, WifiMode ctsMode,
double rtsSnr)
131 AmrrWifiManager::DoReportDataOk (WifiRemoteStation *st,
132 double ackSnr, WifiMode ackMode,
double dataSnr)
135 AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
136 station->m_retry = 0;
140 AmrrWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
145 AmrrWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
148 AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
149 station->m_retry = 0;
153 AmrrWifiManager::IsMinRate (AmrrWifiRemoteStation *station)
const
156 return (station->m_txrate == 0);
159 AmrrWifiManager::IsMaxRate (AmrrWifiRemoteStation *station)
const
162 NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
163 return (station->m_txrate + 1 == GetNSupported (station));
166 AmrrWifiManager::IsSuccess (AmrrWifiRemoteStation *station)
const
169 return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
172 AmrrWifiManager::IsFailure (AmrrWifiRemoteStation *station)
const
175 return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
178 AmrrWifiManager::IsEnough (AmrrWifiRemoteStation *station)
const
181 return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
184 AmrrWifiManager::ResetCnt (AmrrWifiRemoteStation *station)
187 station->m_tx_ok = 0;
188 station->m_tx_err = 0;
189 station->m_tx_retr = 0;
192 AmrrWifiManager::IncreaseRate (AmrrWifiRemoteStation *station)
196 NS_ASSERT (station->m_txrate < GetNSupported (station));
199 AmrrWifiManager::DecreaseRate (AmrrWifiRemoteStation *station)
206 AmrrWifiManager::UpdateMode (AmrrWifiRemoteStation *station)
216 bool needChange =
false;
218 if (IsSuccess (station) && IsEnough (station))
220 station->m_success++;
221 NS_LOG_DEBUG (
"++ success=" << station->m_success <<
" successThreshold=" << station->m_successThreshold <<
222 " tx_ok=" << station->m_tx_ok <<
" tx_err=" << station->m_tx_err <<
" tx_retr=" << station->m_tx_retr <<
223 " rate=" << station->m_txrate <<
" n-supported-rates=" << GetNSupported (station));
224 if (station->m_success >= station->m_successThreshold
225 && !IsMaxRate (station))
227 station->m_recovery =
true;
228 station->m_success = 0;
229 IncreaseRate (station);
234 station->m_recovery =
false;
237 else if (IsFailure (station))
239 station->m_success = 0;
240 NS_LOG_DEBUG (
"-- success=" << station->m_success <<
" successThreshold=" << station->m_successThreshold <<
241 " tx_ok=" << station->m_tx_ok <<
" tx_err=" << station->m_tx_err <<
" tx_retr=" << station->m_tx_retr <<
242 " rate=" << station->m_txrate <<
" n-supported-rates=" << GetNSupported (station));
243 if (!IsMinRate (station))
245 if (station->m_recovery)
247 station->m_successThreshold *= 2;
248 station->m_successThreshold = std::min (station->m_successThreshold,
249 m_maxSuccessThreshold);
253 station->m_successThreshold = m_minSuccessThreshold;
255 station->m_recovery =
false;
256 DecreaseRate (station);
261 station->m_recovery =
false;
264 if (IsEnough (station) || needChange)
275 UpdateMode (station);
276 NS_ASSERT (station->m_txrate < GetNSupported (station));
278 if (station->m_retry < 1)
280 rateIndex = station->m_txrate;
282 else if (station->m_retry < 2)
284 if (station->m_txrate > 0)
286 rateIndex = station->m_txrate - 1;
290 rateIndex = station->m_txrate;
293 else if (station->m_retry < 3)
295 if (station->m_txrate > 1)
297 rateIndex = station->m_txrate - 2;
301 rateIndex = station->m_txrate;
306 if (station->m_txrate > 2)
308 rateIndex = station->m_txrate - 3;
312 rateIndex = station->m_txrate;
316 return GetSupported (station, rateIndex);
323 UpdateMode (station);
325 return GetSupported (station, 0);
#define NS_LOG_FUNCTION(parameters)
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
virtual WifiRemoteStation * DoCreateStation(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
virtual bool IsLowLatency(void) const
hold objects of type ns3::Time
Hold an unsigned integer type.
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
hold a list of per-remote-station state.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
#define NS_LOG_DEBUG(msg)
Hold an floating point type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
hold per-remote-station state.