A Discrete-Event Network Simulator
API
amrr-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) 2003,2007 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20
21#include "ns3/log.h"
22#include "ns3/simulator.h"
23#include "amrr-wifi-manager.h"
24#include "ns3/wifi-tx-vector.h"
25
26#define Min(a,b) ((a < b) ? a : b)
27
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("AmrrWifiManager");
31
39{
45 uint8_t m_txrate;
49};
50
51
53
56{
57 static TypeId tid = TypeId ("ns3::AmrrWifiManager")
59 .SetGroupName ("Wifi")
60 .AddConstructor<AmrrWifiManager> ()
61 .AddAttribute ("UpdatePeriod",
62 "The interval between decisions about rate control changes",
63 TimeValue (Seconds (1.0)),
66 .AddAttribute ("FailureRatio",
67 "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
68 DoubleValue (1.0 / 3.0),
70 MakeDoubleChecker<double> (0.0, 1.0))
71 .AddAttribute ("SuccessRatio",
72 "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
73 DoubleValue (1.0 / 10.0),
75 MakeDoubleChecker<double> (0.0, 1.0))
76 .AddAttribute ("MaxSuccessThreshold",
77 "Maximum number of consecutive success periods needed to switch to a higher rate",
78 UintegerValue (10),
80 MakeUintegerChecker<uint32_t> ())
81 .AddAttribute ("MinSuccessThreshold",
82 "Minimum number of consecutive success periods needed to switch to a higher rate",
83 UintegerValue (1),
85 MakeUintegerChecker<uint32_t> ())
86 .AddTraceSource ("Rate",
87 "Traced value for rate changes (b/s)",
89 "ns3::TracedValueCallback::Uint64")
90 ;
91 return tid;
92}
93
96 m_currentRate (0)
97{
98 NS_LOG_FUNCTION (this);
99}
100
102{
103 NS_LOG_FUNCTION (this);
104}
105
106void
108{
109 NS_LOG_FUNCTION (this);
110 if (GetHtSupported ())
111 {
112 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
113 }
114 if (GetVhtSupported ())
115 {
116 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
117 }
118 if (GetHeSupported ())
119 {
120 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
121 }
122}
123
126{
127 NS_LOG_FUNCTION (this);
130 station->m_tx_ok = 0;
131 station->m_tx_err = 0;
132 station->m_tx_retr = 0;
133 station->m_retry = 0;
134 station->m_txrate = 0;
136 station->m_success = 0;
137 station->m_recovery = false;
138 return station;
139}
140
141void
143 double rxSnr, WifiMode txMode)
144{
145 NS_LOG_FUNCTION (this << station << rxSnr << txMode);
146}
147
148void
150{
151 NS_LOG_FUNCTION (this << station);
152}
153
154void
156{
157 NS_LOG_FUNCTION (this << st);
158 AmrrWifiRemoteStation *station = static_cast<AmrrWifiRemoteStation*> (st);
159 station->m_retry++;
160 station->m_tx_retr++;
161}
162
163void
165 double ctsSnr, WifiMode ctsMode, double rtsSnr)
166{
167 NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
168}
169
170void
172 double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
173{
174 NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
175 AmrrWifiRemoteStation *station = static_cast<AmrrWifiRemoteStation*> (st);
176 station->m_retry = 0;
177 station->m_tx_ok++;
178}
179
180void
182{
183 NS_LOG_FUNCTION (this << station);
184}
185
186void
188{
189 NS_LOG_FUNCTION (this << st);
190 AmrrWifiRemoteStation *station = static_cast<AmrrWifiRemoteStation*> (st);
191 station->m_retry = 0;
192 station->m_tx_err++;
193}
194
195bool
197{
198 NS_LOG_FUNCTION (this << station);
199 return (station->m_txrate == 0);
200}
201
202bool
204{
205 NS_LOG_FUNCTION (this << station);
206 NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
207 return (station->m_txrate + 1 == GetNSupported (station));
208}
209
210bool
212{
213 NS_LOG_FUNCTION (this << station);
214 return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
215}
216
217bool
219{
220 NS_LOG_FUNCTION (this << station);
221 return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
222}
223
224bool
226{
227 NS_LOG_FUNCTION (this << station);
228 return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
229}
230
231void
233{
234 NS_LOG_FUNCTION (this << station);
235 station->m_tx_ok = 0;
236 station->m_tx_err = 0;
237 station->m_tx_retr = 0;
238}
239
240void
242{
243 NS_LOG_FUNCTION (this << station);
244 station->m_txrate++;
245 NS_ASSERT (station->m_txrate < GetNSupported (station));
246}
247
248void
250{
251 NS_LOG_FUNCTION (this << station);
252 station->m_txrate--;
253}
254
255void
257{
258 NS_LOG_FUNCTION (this << station);
259 if (Simulator::Now () < station->m_nextModeUpdate)
260 {
261 return;
262 }
264 NS_LOG_DEBUG ("Update");
265
266 bool needChange = false;
267
268 if (IsSuccess (station) && IsEnough (station))
269 {
270 station->m_success++;
271 NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
272 " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
273 " rate=" << +station->m_txrate << " n-supported-rates=" << +GetNSupported (station));
274 if (station->m_success >= station->m_successThreshold
275 && !IsMaxRate (station))
276 {
277 station->m_recovery = true;
278 station->m_success = 0;
279 IncreaseRate (station);
280 needChange = true;
281 }
282 else
283 {
284 station->m_recovery = false;
285 }
286 }
287 else if (IsFailure (station))
288 {
289 station->m_success = 0;
290 NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
291 " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
292 " rate=" << +station->m_txrate << " n-supported-rates=" << +GetNSupported (station));
293 if (!IsMinRate (station))
294 {
295 if (station->m_recovery)
296 {
297 station->m_successThreshold *= 2;
300 }
301 else
302 {
304 }
305 station->m_recovery = false;
306 DecreaseRate (station);
307 needChange = true;
308 }
309 else
310 {
311 station->m_recovery = false;
312 }
313 }
314 if (IsEnough (station) || needChange)
315 {
316 NS_LOG_DEBUG ("Reset");
317 ResetCnt (station);
318 }
319}
320
323{
324 NS_LOG_FUNCTION (this << st);
325 AmrrWifiRemoteStation *station = static_cast<AmrrWifiRemoteStation*> (st);
326 UpdateMode (station);
327 NS_ASSERT (station->m_txrate < GetNSupported (station));
328 uint8_t rateIndex;
329 if (station->m_retry < 1)
330 {
331 rateIndex = station->m_txrate;
332 }
333 else if (station->m_retry < 2)
334 {
335 if (station->m_txrate > 0)
336 {
337 rateIndex = station->m_txrate - 1;
338 }
339 else
340 {
341 rateIndex = station->m_txrate;
342 }
343 }
344 else if (station->m_retry < 3)
345 {
346 if (station->m_txrate > 1)
347 {
348 rateIndex = station->m_txrate - 2;
349 }
350 else
351 {
352 rateIndex = station->m_txrate;
353 }
354 }
355 else
356 {
357 if (station->m_txrate > 2)
358 {
359 rateIndex = station->m_txrate - 3;
360 }
361 else
362 {
363 rateIndex = station->m_txrate;
364 }
365 }
366 uint16_t channelWidth = GetChannelWidth (station);
367 if (channelWidth > 20 && channelWidth != 22)
368 {
369 channelWidth = 20;
370 }
371 WifiMode mode = GetSupported (station, rateIndex);
372 uint64_t rate = mode.GetDataRate (channelWidth);
373 if (m_currentRate != rate)
374 {
375 NS_LOG_DEBUG ("New datarate: " << rate);
376 m_currentRate = rate;
377 }
378 return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
379}
380
383{
384 NS_LOG_FUNCTION (this << st);
385 AmrrWifiRemoteStation *station = static_cast<AmrrWifiRemoteStation*> (st);
386 uint16_t channelWidth = GetChannelWidth (station);
387 if (channelWidth > 20 && channelWidth != 22)
388 {
389 channelWidth = 20;
390 }
391 UpdateMode (station);
392 WifiMode mode;
393 if (GetUseNonErpProtection () == false)
394 {
395 mode = GetSupported (station, 0);
396 }
397 else
398 {
399 mode = GetNonErpSupported (station, 0);
400 }
401 return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
402}
403
404} //namespace ns3
#define min(a, b)
Definition: 80211b.c:42
AMRR Rate control algorithm.
double m_failureRatio
failure ratio
void UpdateMode(AmrrWifiRemoteStation *station)
Update the mode used to send to the given station.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_minSuccessThreshold
minimum success threshold
bool IsMaxRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the maximum rate.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
static TypeId GetTypeId(void)
Get the type ID.
bool IsMinRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the minimum rate.
void DoInitialize(void) override
Initialize() implementation.
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
void ResetCnt(AmrrWifiRemoteStation *station)
Reset transmission statistics of the given station.
uint32_t m_maxSuccessThreshold
maximum success threshold
bool IsEnough(AmrrWifiRemoteStation *station) const
Check if the number of retransmission, transmission error, and successful transmission are greater th...
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DecreaseRate(AmrrWifiRemoteStation *station)
Decrease the transmission rate to the given station.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
bool IsSuccess(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is less than the number of successful tr...
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStation * DoCreateStation(void) const override
Time m_updatePeriod
update period
void IncreaseRate(AmrrWifiRemoteStation *station)
Increase the transmission rate to the given station.
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
bool IsFailure(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is greater than the number of successful...
double m_successRatio
success ratio
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:42
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:522
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for AMRR Wifi manager.
uint8_t m_txrate
transmit rate
Time m_nextModeUpdate
next mode update time
uint32_t m_tx_err
transmit error
uint32_t m_tx_ok
transmit OK
uint32_t m_tx_retr
transmit retry
uint32_t m_successThreshold
success threshold
hold per-remote-station state.