A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aarf-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004,2005,2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "aarf-wifi-manager.h"
10
11#include "ns3/log.h"
12#include "ns3/wifi-tx-vector.h"
13
14#define Min(a, b) ((a < b) ? a : b)
15#define Max(a, b) ((a > b) ? a : b)
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("AarfWifiManager");
21
22/**
23 * \brief hold per-remote-station state for AARF Wifi manager.
24 *
25 * This struct extends from WifiRemoteStation struct to hold additional
26 * information required by the AARF Wifi manager
27 */
29{
30 uint32_t m_timer; ///< timer
31 uint32_t m_success; ///< success
32 uint32_t m_failed; ///< failed
33 bool m_recovery; ///< recovery
34 uint32_t m_timerTimeout; ///< timer timeout
35 uint32_t m_successThreshold; ///< success threshold
36 uint8_t m_rate; ///< rate
37};
38
40
43{
44 static TypeId tid =
45 TypeId("ns3::AarfWifiManager")
47 .SetGroupName("Wifi")
48 .AddConstructor<AarfWifiManager>()
49 .AddAttribute("SuccessK",
50 "Multiplication factor for the success threshold in the AARF algorithm.",
51 DoubleValue(2.0),
54 .AddAttribute("TimerK",
55 "Multiplication factor for the timer threshold in the AARF algorithm.",
56 DoubleValue(2.0),
59 .AddAttribute("MaxSuccessThreshold",
60 "Maximum value of the success threshold in the AARF algorithm.",
61 UintegerValue(60),
64 .AddAttribute("MinTimerThreshold",
65 "The minimum value for the 'timer' threshold in the AARF algorithm.",
66 UintegerValue(15),
69 .AddAttribute("MinSuccessThreshold",
70 "The minimum value for the success threshold in the AARF algorithm.",
71 UintegerValue(10),
74 .AddTraceSource("Rate",
75 "Traced value for rate changes (b/s)",
77 "ns3::TracedValueCallback::Uint64");
78 return tid;
79}
80
83 m_currentRate(0)
84{
85 NS_LOG_FUNCTION(this);
86}
87
92
93void
95{
96 NS_LOG_FUNCTION(this);
97 if (GetHtSupported())
98 {
99 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
100 }
101 if (GetVhtSupported())
102 {
103 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
104 }
105 if (GetHeSupported())
106 {
107 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
108 }
109}
110
113{
114 NS_LOG_FUNCTION(this);
115 auto station = new AarfWifiRemoteStation();
116
117 station->m_successThreshold = m_minSuccessThreshold;
118 station->m_timerTimeout = m_minTimerThreshold;
119 station->m_rate = 0;
120 station->m_success = 0;
121 station->m_failed = 0;
122 station->m_recovery = false;
123 station->m_timer = 0;
124
125 return station;
126}
127
128void
133
134/**
135 * It is important to realize that "recovery" mode starts after failure of
136 * the first transmission after a rate increase and ends at the first successful
137 * transmission. Specifically, recovery mode transcends retransmissions boundaries.
138 * Fundamentally, ARF handles each data transmission independently, whether it
139 * is the initial transmission of a packet or the retransmission of a packet.
140 * The fundamental reason for this is that there is a backoff between each data
141 * transmission, be it an initial transmission or a retransmission.
142 *
143 * \param st the station that we failed to send Data
144 */
145void
147{
148 NS_LOG_FUNCTION(this << st);
149 auto station = static_cast<AarfWifiRemoteStation*>(st);
150 station->m_timer++;
151 station->m_failed++;
152 station->m_success = 0;
153
154 if (station->m_recovery)
155 {
156 NS_ASSERT(station->m_failed >= 1);
157 if (station->m_failed == 1)
158 {
159 // need recovery fallback
160 station->m_successThreshold =
161 (int)(Min(station->m_successThreshold * m_successK, m_maxSuccessThreshold));
162 station->m_timerTimeout =
163 (int)(Max(station->m_timerTimeout * m_timerK, m_minSuccessThreshold));
164 if (station->m_rate != 0)
165 {
166 station->m_rate--;
167 }
168 }
169 station->m_timer = 0;
170 }
171 else
172 {
173 NS_ASSERT(station->m_failed >= 1);
174 if (((station->m_failed - 1) % 2) == 1)
175 {
176 // need normal fallback
177 station->m_timerTimeout = m_minTimerThreshold;
178 station->m_successThreshold = m_minSuccessThreshold;
179 if (station->m_rate != 0)
180 {
181 station->m_rate--;
182 }
183 }
184 if (station->m_failed >= 2)
185 {
186 station->m_timer = 0;
187 }
188 }
189}
190
191void
193{
194 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
195}
196
197void
199 double ctsSnr,
200 WifiMode ctsMode,
201 double rtsSnr)
202{
203 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
204 NS_LOG_DEBUG("station=" << station << " rts ok");
205}
206
207void
209 double ackSnr,
210 WifiMode ackMode,
211 double dataSnr,
212 MHz_u dataChannelWidth,
213 uint8_t dataNss)
214{
215 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
216 auto station = static_cast<AarfWifiRemoteStation*>(st);
217 station->m_timer++;
218 station->m_success++;
219 station->m_failed = 0;
220 station->m_recovery = false;
221 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
222 << ", timer=" << station->m_timer);
223 if ((station->m_success == station->m_successThreshold ||
224 station->m_timer == station->m_timerTimeout) &&
225 (station->m_rate < (GetNSupported(station) - 1)))
226 {
227 NS_LOG_DEBUG("station=" << station << " inc rate");
228 station->m_rate++;
229 station->m_timer = 0;
230 station->m_success = 0;
231 station->m_recovery = true;
232 }
233}
234
235void
240
241void
246
249{
250 NS_LOG_FUNCTION(this << st << allowedWidth);
251 auto station = static_cast<AarfWifiRemoteStation*>(st);
252 auto channelWidth = GetChannelWidth(station);
253 if (channelWidth > 20 && channelWidth != 22)
254 {
255 channelWidth = 20;
256 }
257 WifiMode mode = GetSupported(station, station->m_rate);
258 uint64_t rate = mode.GetDataRate(channelWidth);
259 if (m_currentRate != rate)
260 {
261 NS_LOG_DEBUG("New datarate: " << rate);
262 m_currentRate = rate;
263 }
264 return WifiTxVector(
265 mode,
268 NanoSeconds(800),
269 1,
270 1,
271 0,
272 channelWidth,
273 GetAggregation(station));
274}
275
278{
279 NS_LOG_FUNCTION(this << st);
280 /// \todo we could/should implement the AARF algorithm for
281 /// RTS only by picking a single rate within the BasicRateSet.
282 auto station = static_cast<AarfWifiRemoteStation*>(st);
283 auto channelWidth = GetChannelWidth(station);
284 if (channelWidth > 20 && channelWidth != 22)
285 {
286 channelWidth = 20;
287 }
288 WifiMode mode;
290 {
291 mode = GetSupported(station, 0);
292 }
293 else
294 {
295 mode = GetNonErpSupported(station, 0);
296 }
297 return WifiTxVector(
298 mode,
301 NanoSeconds(800),
302 1,
303 1,
304 0,
305 channelWidth,
306 GetAggregation(station));
307}
308
309} // namespace ns3
#define Max(a, b)
#define Min(a, b)
AARF Rate control algorithm.
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.
uint32_t m_minSuccessThreshold
minimum success threshold
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStation * DoCreateStation() const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void DoInitialize() override
Initialize() implementation.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
double m_successK
Multiplication factor for the success threshold.
void DoReportDataFailed(WifiRemoteStation *station) override
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
double m_timerK
Multiplication factor for the timer threshold.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_maxSuccessThreshold
maximum success threshold
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_minTimerThreshold
minimum timer threshold
TracedValue< uint64_t > m_currentRate
Trace rate changes.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
represent a single transmission mode
Definition wifi-mode.h:40
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:111
hold a list of per-remote-station state.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
MHz_u GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled on the link this manager is associated wi...
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled on the link this manager is associated w...
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHeSupported() const
Return whether the device has HE 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:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
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 > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
hold per-remote-station state for AARF Wifi manager.
uint32_t m_timerTimeout
timer timeout
uint32_t m_successThreshold
success threshold
hold per-remote-station state.