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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "arf-wifi-manager.h"
21
22#include "ns3/log.h"
23#include "ns3/wifi-tx-vector.h"
24
25#define Min(a, b) ((a < b) ? a : b)
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("ArfWifiManager");
31
39{
46 uint8_t m_rate;
47};
48
50
53{
54 static TypeId tid =
55 TypeId("ns3::ArfWifiManager")
57 .SetGroupName("Wifi")
58 .AddConstructor<ArfWifiManager>()
59 .AddAttribute("TimerThreshold",
60 "The 'timer' threshold in the ARF algorithm.",
61 UintegerValue(15),
63 MakeUintegerChecker<uint32_t>())
64 .AddAttribute("SuccessThreshold",
65 "The minimum number of successful transmissions to try a new rate.",
66 UintegerValue(10),
68 MakeUintegerChecker<uint32_t>())
69 .AddTraceSource("Rate",
70 "Traced value for rate changes (b/s)",
72 "ns3::TracedValueCallback::Uint64");
73 return tid;
74}
75
78 m_currentRate(0)
79{
80 NS_LOG_FUNCTION(this);
81}
82
84{
85 NS_LOG_FUNCTION(this);
86}
87
88void
90{
91 NS_LOG_FUNCTION(this);
92 if (GetHtSupported())
93 {
94 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
95 }
96 if (GetVhtSupported())
97 {
98 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
99 }
100 if (GetHeSupported())
101 {
102 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
103 }
104}
105
108{
109 NS_LOG_FUNCTION(this);
110 auto station = new ArfWifiRemoteStation();
111
112 station->m_successThreshold = m_successThreshold;
113 station->m_timerTimeout = m_timerThreshold;
114 station->m_rate = 0;
115 station->m_success = 0;
116 station->m_failed = 0;
117 station->m_recovery = false;
118 station->m_timer = 0;
119
120 return station;
121}
122
123void
125{
126 NS_LOG_FUNCTION(this << station);
127}
128
140void
142{
143 NS_LOG_FUNCTION(this << st);
144 auto station = static_cast<ArfWifiRemoteStation*>(st);
145 station->m_timer++;
146 station->m_failed++;
147 station->m_success = 0;
148
149 if (station->m_recovery)
150 {
151 NS_ASSERT(station->m_failed >= 1);
152 if (station->m_failed == 1)
153 {
154 // need recovery fallback
155 if (station->m_rate != 0)
156 {
157 station->m_rate--;
158 }
159 }
160 station->m_timer = 0;
161 }
162 else
163 {
164 NS_ASSERT(station->m_failed >= 1);
165 if (((station->m_failed - 1) % 2) == 1)
166 {
167 // need normal fallback
168 if (station->m_rate != 0)
169 {
170 station->m_rate--;
171 }
172 }
173 if (station->m_failed >= 2)
174 {
175 station->m_timer = 0;
176 }
177 }
178}
179
180void
182{
183 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
184}
185
186void
188 double ctsSnr,
189 WifiMode ctsMode,
190 double rtsSnr)
191{
192 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
193 NS_LOG_DEBUG("station=" << station << " rts ok");
194}
195
196void
198 double ackSnr,
199 WifiMode ackMode,
200 double dataSnr,
201 uint16_t dataChannelWidth,
202 uint8_t dataNss)
203{
204 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
205 auto station = static_cast<ArfWifiRemoteStation*>(st);
206 station->m_timer++;
207 station->m_success++;
208 station->m_failed = 0;
209 station->m_recovery = false;
210 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
211 << ", timer=" << station->m_timer);
212 if ((station->m_success == m_successThreshold || station->m_timer == m_timerThreshold) &&
213 (station->m_rate < (station->m_state->m_operationalRateSet.size() - 1)))
214 {
215 NS_LOG_DEBUG("station=" << station << " inc rate");
216 station->m_rate++;
217 station->m_timer = 0;
218 station->m_success = 0;
219 station->m_recovery = true;
220 }
221}
222
223void
225{
226 NS_LOG_FUNCTION(this << station);
227}
228
229void
231{
232 NS_LOG_FUNCTION(this << station);
233}
234
237{
238 NS_LOG_FUNCTION(this << st << allowedWidth);
239 auto station = static_cast<ArfWifiRemoteStation*>(st);
240 uint16_t channelWidth = GetChannelWidth(station);
241 if (channelWidth > 20 && channelWidth != 22)
242 {
243 channelWidth = 20;
244 }
245 WifiMode mode = GetSupported(station, station->m_rate);
246 uint64_t rate = mode.GetDataRate(channelWidth);
247 if (m_currentRate != rate)
248 {
249 NS_LOG_DEBUG("New datarate: " << rate);
250 m_currentRate = rate;
251 }
252 return WifiTxVector(
253 mode,
256 800,
257 1,
258 1,
259 0,
260 channelWidth,
261 GetAggregation(station));
262}
263
266{
267 NS_LOG_FUNCTION(this << st);
270 auto station = static_cast<ArfWifiRemoteStation*>(st);
271 uint16_t channelWidth = GetChannelWidth(station);
272 if (channelWidth > 20 && channelWidth != 22)
273 {
274 channelWidth = 20;
275 }
276 WifiMode mode;
278 {
279 mode = GetSupported(station, 0);
280 }
281 else
282 {
283 mode = GetNonErpSupported(station, 0);
284 }
285 return WifiTxVector(
286 mode,
289 800,
290 1,
291 1,
292 0,
293 channelWidth,
294 GetAggregation(station));
295}
296
297} // namespace ns3
ARF Rate control algorithm.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
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
uint32_t m_successThreshold
success threshold
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.
void DoInitialize() 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.
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:51
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
uint16_t 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.
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.
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:66
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
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.
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.