A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
arf-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 "arf-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
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("ArfWifiManager");
20
21/**
22 * \brief hold per-remote-station state for ARF Wifi manager.
23 *
24 * This struct extends from WifiRemoteStation struct to hold additional
25 * information required by the ARF Wifi manager
26 */
28{
29 uint32_t m_timer; ///< timer value
30 uint32_t m_success; ///< success count
31 uint32_t m_failed; ///< failed count
32 bool m_recovery; ///< recovery
33 uint32_t m_timerTimeout; ///< timer timeout
34 uint32_t m_successThreshold; ///< success threshold
35 uint8_t m_rate; ///< rate
36};
37
39
42{
43 static TypeId tid =
44 TypeId("ns3::ArfWifiManager")
46 .SetGroupName("Wifi")
47 .AddConstructor<ArfWifiManager>()
48 .AddAttribute("TimerThreshold",
49 "The 'timer' threshold in the ARF algorithm.",
50 UintegerValue(15),
53 .AddAttribute("SuccessThreshold",
54 "The minimum number of successful transmissions to try a new rate.",
55 UintegerValue(10),
58 .AddTraceSource("Rate",
59 "Traced value for rate changes (b/s)",
61 "ns3::TracedValueCallback::Uint64");
62 return tid;
63}
64
67 m_currentRate(0)
68{
69 NS_LOG_FUNCTION(this);
70}
71
76
77void
79{
80 NS_LOG_FUNCTION(this);
81 if (GetHtSupported())
82 {
83 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
84 }
85 if (GetVhtSupported())
86 {
87 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
88 }
89 if (GetHeSupported())
90 {
91 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
92 }
93}
94
97{
98 NS_LOG_FUNCTION(this);
99 auto station = new ArfWifiRemoteStation();
100
101 station->m_successThreshold = m_successThreshold;
102 station->m_timerTimeout = m_timerThreshold;
103 station->m_rate = 0;
104 station->m_success = 0;
105 station->m_failed = 0;
106 station->m_recovery = false;
107 station->m_timer = 0;
108
109 return station;
110}
111
112void
117
118/**
119 * It is important to realize that "recovery" mode starts after failure of
120 * the first transmission after a rate increase and ends at the first successful
121 * transmission. Specifically, recovery mode transcends retransmissions boundaries.
122 * Fundamentally, ARF handles each data transmission independently, whether it
123 * is the initial transmission of a packet or the retransmission of a packet.
124 * The fundamental reason for this is that there is a backoff between each data
125 * transmission, be it an initial transmission or a retransmission.
126 *
127 * \param st the station that we failed to send Data
128 */
129void
131{
132 NS_LOG_FUNCTION(this << st);
133 auto station = static_cast<ArfWifiRemoteStation*>(st);
134 station->m_timer++;
135 station->m_failed++;
136 station->m_success = 0;
137
138 if (station->m_recovery)
139 {
140 NS_ASSERT(station->m_failed >= 1);
141 if (station->m_failed == 1)
142 {
143 // need recovery fallback
144 if (station->m_rate != 0)
145 {
146 station->m_rate--;
147 }
148 }
149 station->m_timer = 0;
150 }
151 else
152 {
153 NS_ASSERT(station->m_failed >= 1);
154 if (((station->m_failed - 1) % 2) == 1)
155 {
156 // need normal fallback
157 if (station->m_rate != 0)
158 {
159 station->m_rate--;
160 }
161 }
162 if (station->m_failed >= 2)
163 {
164 station->m_timer = 0;
165 }
166 }
167}
168
169void
171{
172 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
173}
174
175void
177 double ctsSnr,
178 WifiMode ctsMode,
179 double rtsSnr)
180{
181 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
182 NS_LOG_DEBUG("station=" << station << " rts ok");
183}
184
185void
187 double ackSnr,
188 WifiMode ackMode,
189 double dataSnr,
190 MHz_u dataChannelWidth,
191 uint8_t dataNss)
192{
193 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
194 auto station = static_cast<ArfWifiRemoteStation*>(st);
195 station->m_timer++;
196 station->m_success++;
197 station->m_failed = 0;
198 station->m_recovery = false;
199 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
200 << ", timer=" << station->m_timer);
201 if ((station->m_success == m_successThreshold || station->m_timer == m_timerThreshold) &&
202 (station->m_rate < (station->m_state->m_operationalRateSet.size() - 1)))
203 {
204 NS_LOG_DEBUG("station=" << station << " inc rate");
205 station->m_rate++;
206 station->m_timer = 0;
207 station->m_success = 0;
208 station->m_recovery = true;
209 }
210}
211
212void
217
218void
223
226{
227 NS_LOG_FUNCTION(this << st << allowedWidth);
228 auto station = static_cast<ArfWifiRemoteStation*>(st);
229 auto channelWidth = GetChannelWidth(station);
230 if (channelWidth > 20 && channelWidth != 22)
231 {
232 channelWidth = 20;
233 }
234 WifiMode mode = GetSupported(station, station->m_rate);
235 uint64_t rate = mode.GetDataRate(channelWidth);
236 if (m_currentRate != rate)
237 {
238 NS_LOG_DEBUG("New datarate: " << rate);
239 m_currentRate = rate;
240 }
241 return WifiTxVector(
242 mode,
245 NanoSeconds(800),
246 1,
247 1,
248 0,
249 channelWidth,
250 GetAggregation(station));
251}
252
255{
256 NS_LOG_FUNCTION(this << st);
257 /// \todo we could/should implement the ARF algorithm for
258 /// RTS only by picking a single rate within the BasicRateSet.
259 auto station = static_cast<ArfWifiRemoteStation*>(st);
260 auto channelWidth = GetChannelWidth(station);
261 if (channelWidth > 20 && channelWidth != 22)
262 {
263 channelWidth = 20;
264 }
265 WifiMode mode;
267 {
268 mode = GetSupported(station, 0);
269 }
270 else
271 {
272 mode = GetNonErpSupported(station, 0);
273 }
274 return WifiTxVector(
275 mode,
278 NanoSeconds(800),
279 1,
280 1,
281 0,
282 channelWidth,
283 GetAggregation(station));
284}
285
286} // namespace ns3
ARF Rate control algorithm.
static TypeId GetTypeId()
Get the type ID.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRtsFailed(WifiRemoteStation *station) 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 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.
uint32_t m_successThreshold
success threshold
void DoInitialize() override
Initialize() implementation.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
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_timerThreshold
timer threshold
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
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
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
TracedValue< uint64_t > m_currentRate
Trace rate changes.
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.
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
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for ARF Wifi manager.
uint32_t m_timer
timer value
uint32_t m_failed
failed count
uint32_t m_timerTimeout
timer timeout
uint32_t m_successThreshold
success threshold
uint32_t m_success
success count
hold per-remote-station state.