A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aparf-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universidad de la República - Uruguay
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Matias Richart <mrichart@fing.edu.uy>
7 */
8
10
11#include "ns3/data-rate.h"
12#include "ns3/log.h"
13#include "ns3/uinteger.h"
14#include "ns3/wifi-phy.h"
15
16#define Min(a, b) ((a < b) ? a : b)
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("AparfWifiManager");
22
23/**
24 * Hold per-remote-station state for APARF Wifi manager.
25 *
26 * This struct extends from WifiRemoteStation struct to hold additional
27 * information required by the APARF Wifi manager
28 */
30{
31 uint32_t m_nSuccess; //!< Number of successful transmission attempts.
32 uint32_t m_nFailed; //!< Number of failed transmission attempts.
33 uint32_t m_pCount; //!< Number of power changes.
34 uint32_t m_successThreshold; //!< The minimum number of successful transmissions to try a new
35 //!< power or rate.
37 m_failThreshold; //!< The minimum number of failed transmissions to try a new power or rate.
38 uint8_t m_prevRateIndex; //!< Rate index of the previous transmission.
39 uint8_t m_rateIndex; //!< Current rate index.
40 uint8_t m_critRateIndex; //!< Critical rate.
41 uint8_t m_prevPowerLevel; //!< Power level of the previous transmission.
42 uint8_t m_powerLevel; //!< Current power level.
43 uint8_t m_nSupported; //!< Number of supported rates by the remote station.
44 bool m_initialized; //!< For initializing variables.
45 AparfWifiManager::State m_aparfState; //!< The estimated state of the channel.
46};
47
49
52{
53 static TypeId tid =
54 TypeId("ns3::AparfWifiManager")
56 .SetGroupName("Wifi")
57 .AddConstructor<AparfWifiManager>()
58 .AddAttribute("SuccessThreshold1",
59 "The minimum number of successful transmissions in \"High\" state to try "
60 "a new power or rate.",
64 .AddAttribute("SuccessThreshold2",
65 "The minimum number of successful transmissions in \"Low\" state to try "
66 "a new power or rate.",
67 UintegerValue(10),
70 .AddAttribute("FailThreshold",
71 "The minimum number of failed transmissions to try a new power or rate.",
75 .AddAttribute("PowerThreshold",
76 "The maximum number of power changes.",
77 UintegerValue(10),
80 .AddAttribute("PowerDecrementStep",
81 "Step size for decrement the power.",
85 .AddAttribute("PowerIncrementStep",
86 "Step size for increment the power.",
90 .AddAttribute("RateDecrementStep",
91 "Step size for decrement the rate.",
95 .AddAttribute("RateIncrementStep",
96 "Step size for increment the rate.",
100 .AddTraceSource("PowerChange",
101 "The transmission power has change",
103 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
104 .AddTraceSource("RateChange",
105 "The transmission rate has change",
107 "ns3::WifiRemoteStationManager::RateChangeTracedCallback");
108 return tid;
109}
110
115
120
121void
123{
124 NS_LOG_FUNCTION(this << phy);
125 m_minPower = 0;
126 m_maxPower = phy->GetNTxPower() - 1;
128}
129
130void
132{
133 NS_LOG_FUNCTION(this);
134 if (GetHtSupported())
135 {
136 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
137 }
138 if (GetVhtSupported())
139 {
140 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
141 }
142 if (GetHeSupported())
143 {
144 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
145 }
146}
147
150{
151 NS_LOG_FUNCTION(this);
152 auto station = new AparfWifiRemoteStation();
153
154 station->m_successThreshold = m_successMax1;
155 station->m_failThreshold = m_failMax;
156 station->m_nSuccess = 0;
157 station->m_nFailed = 0;
158 station->m_pCount = 0;
159 station->m_aparfState = AparfWifiManager::High;
160 station->m_initialized = false;
161
162 NS_LOG_DEBUG("create station=" << station << ", rate=" << +station->m_rateIndex
163 << ", power=" << +station->m_powerLevel);
164
165 return station;
166}
167
168void
170{
171 if (!station->m_initialized)
172 {
173 station->m_nSupported = GetNSupported(station);
174 station->m_rateIndex = station->m_nSupported - 1;
175 station->m_prevRateIndex = station->m_nSupported - 1;
176 station->m_powerLevel = m_maxPower;
177 station->m_prevPowerLevel = m_maxPower;
178 station->m_critRateIndex = 0;
179 WifiMode mode = GetSupported(station, station->m_rateIndex);
180 auto channelWidth = GetChannelWidth(station);
181 DataRate rate(mode.GetDataRate(channelWidth));
182 const auto power = GetPhy()->GetPower(m_maxPower);
183 m_powerChange(power, power, station->m_state->m_address);
184 m_rateChange(rate, rate, station->m_state->m_address);
185 station->m_initialized = true;
186 }
187}
188
189void
194
195void
197{
198 NS_LOG_FUNCTION(this << st);
199 auto station = static_cast<AparfWifiRemoteStation*>(st);
200 CheckInit(station);
201 station->m_nFailed++;
202 station->m_nSuccess = 0;
203 NS_LOG_DEBUG("station=" << station << ", rate=" << station->m_rateIndex
204 << ", power=" << (int)station->m_powerLevel);
205
206 if (station->m_aparfState == AparfWifiManager::Low)
207 {
208 station->m_aparfState = AparfWifiManager::High;
209 station->m_successThreshold = m_successMax1;
210 }
211 else if (station->m_aparfState == AparfWifiManager::Spread)
212 {
213 station->m_aparfState = AparfWifiManager::Low;
214 station->m_successThreshold = m_successMax2;
215 }
216
217 if (station->m_nFailed == station->m_failThreshold)
218 {
219 station->m_nFailed = 0;
220 station->m_nSuccess = 0;
221 station->m_pCount = 0;
222 if (station->m_powerLevel == m_maxPower)
223 {
224 station->m_critRateIndex = station->m_rateIndex;
225 if (station->m_rateIndex != 0)
226 {
227 NS_LOG_DEBUG("station=" << station << " dec rate");
228 station->m_rateIndex -= m_rateDec;
229 }
230 }
231 else
232 {
233 NS_LOG_DEBUG("station=" << station << " inc power");
234 station->m_powerLevel += m_powerInc;
235 }
236 }
237}
238
239void
241{
242 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
243}
244
245void
247 double ctsSnr,
248 WifiMode ctsMode,
249 double rtsSnr)
250{
251 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
252}
253
254void
256 double ackSnr,
257 WifiMode ackMode,
258 double dataSnr,
259 MHz_u dataChannelWidth,
260 uint8_t dataNss)
261{
262 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
263 auto station = static_cast<AparfWifiRemoteStation*>(st);
264 CheckInit(station);
265 station->m_nSuccess++;
266 station->m_nFailed = 0;
267 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", rate="
268 << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
269
270 if ((station->m_aparfState == AparfWifiManager::High ||
271 station->m_aparfState == AparfWifiManager::Low) &&
272 station->m_nSuccess >= station->m_successThreshold)
273
274 {
275 station->m_aparfState = AparfWifiManager::Spread;
276 }
277 else if (station->m_aparfState == AparfWifiManager::Spread)
278 {
279 station->m_aparfState = AparfWifiManager::High;
280 station->m_successThreshold = m_successMax1;
281 }
282
283 if (station->m_nSuccess == station->m_successThreshold)
284 {
285 station->m_nSuccess = 0;
286 station->m_nFailed = 0;
287 if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size() - 1))
288 {
289 if (station->m_powerLevel != m_minPower)
290 {
291 NS_LOG_DEBUG("station=" << station << " dec power");
292 station->m_powerLevel -= m_powerDec;
293 }
294 }
295 else
296 {
297 if (station->m_critRateIndex == 0)
298 {
299 if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size() - 1))
300 {
301 NS_LOG_DEBUG("station=" << station << " inc rate");
302 station->m_rateIndex += m_rateInc;
303 }
304 }
305 else
306 {
307 if (station->m_pCount == m_powerMax)
308 {
309 station->m_powerLevel = m_maxPower;
310 station->m_rateIndex = station->m_critRateIndex;
311 station->m_pCount = 0;
312 station->m_critRateIndex = 0;
313 }
314 else
315 {
316 if (station->m_powerLevel != m_minPower)
317 {
318 station->m_powerLevel -= m_powerDec;
319 station->m_pCount++;
320 }
321 }
322 }
323 }
324 }
325}
326
327void
332
333void
338
341{
342 NS_LOG_FUNCTION(this << st << allowedWidth);
343 auto station = static_cast<AparfWifiRemoteStation*>(st);
344 auto channelWidth = GetChannelWidth(station);
345 if (channelWidth > 20 && channelWidth != 22)
346 {
347 channelWidth = 20;
348 }
349 CheckInit(station);
350 WifiMode mode = GetSupported(station, station->m_rateIndex);
351 DataRate rate(mode.GetDataRate(channelWidth));
352 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
353 const auto power = GetPhy()->GetPower(station->m_powerLevel);
354 const auto prevPower = GetPhy()->GetPower(station->m_prevPowerLevel);
355 if (station->m_prevPowerLevel != station->m_powerLevel)
356 {
357 m_powerChange(prevPower, power, station->m_state->m_address);
358 station->m_prevPowerLevel = station->m_powerLevel;
359 }
360 if (station->m_prevRateIndex != station->m_rateIndex)
361 {
362 m_rateChange(prevRate, rate, station->m_state->m_address);
363 station->m_prevRateIndex = station->m_rateIndex;
364 }
365 return WifiTxVector(
366 mode,
367 station->m_powerLevel,
369 NanoSeconds(800),
370 1,
371 1,
372 0,
373 channelWidth,
374 GetAggregation(station));
375}
376
379{
380 NS_LOG_FUNCTION(this << st);
381 /// \todo we could/should implement the ARF algorithm for
382 /// RTS only by picking a single rate within the BasicRateSet.
383 auto station = static_cast<AparfWifiRemoteStation*>(st);
384 auto channelWidth = GetChannelWidth(station);
385 if (channelWidth > 20 && channelWidth != 22)
386 {
387 channelWidth = 20;
388 }
389 WifiMode mode;
391 {
392 mode = GetSupported(station, 0);
393 }
394 else
395 {
396 mode = GetNonErpSupported(station, 0);
397 }
398 return WifiTxVector(
399 mode,
402 NanoSeconds(800),
403 1,
404 1,
405 0,
406 channelWidth,
407 GetAggregation(station));
408}
409
410} // namespace ns3
APARF Power and rate control algorithm.
void DoReportFinalDataFailed(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.
uint32_t m_failMax
The minimum number of failed transmissions to try a new power or rate.
uint8_t m_minPower
Minimal power level.
void DoInitialize() override
Initialize() implementation.
WifiRemoteStation * DoCreateStation() const override
uint32_t m_successMax2
The minimum number of successful transmissions in "Low" state to try a new power or rate.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
uint8_t m_maxPower
Maximal power level.
uint32_t m_powerMax
The maximum number of power changes.
uint8_t m_powerDec
Step size for decrement the power.
State
Enumeration of the possible states of the channel.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
uint8_t m_rateDec
Step size for decrement the rate.
uint32_t m_successMax1
The minimum number of successful transmissions in "High" state to try a new power or rate.
uint8_t m_powerInc
Step size for increment the power.
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.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void CheckInit(AparfWifiRemoteStation *station)
Check for initializations.
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.
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void SetupPhy(const Ptr< WifiPhy > phy) override
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
uint8_t m_rateInc
Step size for increment the rate.
TracedCallback< DataRate, DataRate, Mac48Address > m_rateChange
The trace source fired when the transmission rate changes.
static TypeId GetTypeId()
Register this type.
Class for representing data rates.
Definition data-rate.h:78
Smart pointer class similar to boost::intrusive_ptr.
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
dBm_u GetPower(uint8_t powerLevel) const
Get the power of the given power level.
Definition wifi-phy.cc:714
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.
Ptr< WifiPhy > GetPhy() const
Return the WifiPhy.
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.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
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_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 APARF Wifi manager.
uint8_t m_prevRateIndex
Rate index of the previous transmission.
uint8_t m_nSupported
Number of supported rates by the remote station.
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
uint32_t m_nSuccess
Number of successful transmission attempts.
uint32_t m_failThreshold
The minimum number of failed transmissions to try a new power or rate.
uint8_t m_rateIndex
Current rate index.
uint32_t m_pCount
Number of power changes.
uint8_t m_critRateIndex
Critical rate.
bool m_initialized
For initializing variables.
AparfWifiManager::State m_aparfState
The estimated state of the channel.
uint8_t m_powerLevel
Current power level.
uint8_t m_prevPowerLevel
Power level of the previous transmission.
uint32_t m_nFailed
Number of failed transmission attempts.
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.