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
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("AparfWifiManager");
20
21/**
22 * Hold per-remote-station state for APARF Wifi manager.
23 *
24 * This struct extends from WifiRemoteStation struct to hold additional
25 * information required by the APARF Wifi manager
26 */
28{
29 uint32_t m_nSuccess; //!< Number of successful transmission attempts.
30 uint32_t m_nFailed; //!< Number of failed transmission attempts.
31 uint32_t m_pCount; //!< Number of power changes.
32 uint32_t m_successThreshold; //!< The minimum number of successful transmissions to try a new
33 //!< power or rate.
35 m_failThreshold; //!< The minimum number of failed transmissions to try a new power or rate.
36 uint8_t m_prevRateIndex; //!< Rate index of the previous transmission.
37 uint8_t m_rateIndex; //!< Current rate index.
38 uint8_t m_critRateIndex; //!< Critical rate.
39 uint8_t m_prevPowerLevel; //!< Power level of the previous transmission.
40 uint8_t m_powerLevel; //!< Current power level.
41 uint8_t m_nSupported; //!< Number of supported rates by the remote station.
42 bool m_initialized; //!< For initializing variables.
43 AparfWifiManager::State m_aparfState; //!< The estimated state of the channel.
44};
45
47
50{
51 static TypeId tid =
52 TypeId("ns3::AparfWifiManager")
54 .SetGroupName("Wifi")
55 .AddConstructor<AparfWifiManager>()
56 .AddAttribute("SuccessThreshold1",
57 "The minimum number of successful transmissions in \"High\" state to try "
58 "a new power or rate.",
62 .AddAttribute("SuccessThreshold2",
63 "The minimum number of successful transmissions in \"Low\" state to try "
64 "a new power or rate.",
65 UintegerValue(10),
68 .AddAttribute("FailThreshold",
69 "The minimum number of failed transmissions to try a new power or rate.",
73 .AddAttribute("PowerThreshold",
74 "The maximum number of power changes.",
75 UintegerValue(10),
78 .AddAttribute("PowerDecrementStep",
79 "Step size for decrement the power level.",
83 .AddAttribute("PowerIncrementStep",
84 "Step size for increment the power level.",
88 .AddAttribute("RateDecrementStep",
89 "Step size for decrement the rate.",
93 .AddAttribute("RateIncrementStep",
94 "Step size for increment the rate.",
98 .AddTraceSource("PowerChange",
99 "The transmission power has change",
101 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
102 .AddTraceSource("RateChange",
103 "The transmission rate has change",
105 "ns3::WifiRemoteStationManager::RateChangeTracedCallback");
106 return tid;
107}
108
113
118
119void
121{
122 NS_LOG_FUNCTION(this << phy);
123 m_maxPowerLevel = WIFI_MIN_TX_PWR_LEVEL + phy->GetNTxPowerLevels() - 1;
125}
126
127void
129{
130 NS_LOG_FUNCTION(this);
131 if (GetHtSupported())
132 {
133 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
134 }
135 if (GetVhtSupported())
136 {
137 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
138 }
139 if (GetHeSupported())
140 {
141 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
142 }
143}
144
147{
148 NS_LOG_FUNCTION(this);
149 auto station = new AparfWifiRemoteStation();
150
151 station->m_successThreshold = m_successMax1;
152 station->m_failThreshold = m_failMax;
153 station->m_nSuccess = 0;
154 station->m_nFailed = 0;
155 station->m_pCount = 0;
156 station->m_aparfState = AparfWifiManager::High;
157 station->m_initialized = false;
158
159 NS_LOG_DEBUG("create station=" << station << ", rate=" << +station->m_rateIndex
160 << ", power=" << +station->m_powerLevel);
161
162 return station;
163}
164
165void
167{
168 if (!station->m_initialized)
169 {
170 station->m_nSupported = GetNSupported(station);
171 station->m_rateIndex = station->m_nSupported - 1;
172 station->m_prevRateIndex = station->m_nSupported - 1;
173 station->m_powerLevel = m_maxPowerLevel;
175 station->m_critRateIndex = 0;
176 WifiMode mode = GetSupported(station, station->m_rateIndex);
177 auto channelWidth = GetChannelWidth(station);
178 DataRate rate(mode.GetDataRate(channelWidth));
179 const auto power = GetPhy()->GetPower(m_maxPowerLevel);
180 m_powerChange(power, power, station->m_state->m_address);
181 m_rateChange(rate, rate, station->m_state->m_address);
182 station->m_initialized = true;
183 }
184}
185
186void
191
192void
194{
195 NS_LOG_FUNCTION(this << st);
196 auto station = static_cast<AparfWifiRemoteStation*>(st);
197 CheckInit(station);
198 station->m_nFailed++;
199 station->m_nSuccess = 0;
200 NS_LOG_DEBUG("station=" << station << ", rate=" << station->m_rateIndex
201 << ", power=" << (int)station->m_powerLevel);
202
203 if (station->m_aparfState == AparfWifiManager::Low)
204 {
205 station->m_aparfState = AparfWifiManager::High;
206 station->m_successThreshold = m_successMax1;
207 }
208 else if (station->m_aparfState == AparfWifiManager::Spread)
209 {
210 station->m_aparfState = AparfWifiManager::Low;
211 station->m_successThreshold = m_successMax2;
212 }
213
214 if (station->m_nFailed == station->m_failThreshold)
215 {
216 station->m_nFailed = 0;
217 station->m_nSuccess = 0;
218 station->m_pCount = 0;
219 if (station->m_powerLevel == m_maxPowerLevel)
220 {
221 station->m_critRateIndex = station->m_rateIndex;
222 if (station->m_rateIndex != 0)
223 {
224 NS_LOG_DEBUG("station=" << station << " dec rate");
225 station->m_rateIndex -= m_rateDec;
226 }
227 }
228 else
229 {
230 NS_LOG_DEBUG("station=" << station << " inc power");
231 station->m_powerLevel += m_powerLevelInc;
232 }
233 }
234}
235
236void
238{
239 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
240}
241
242void
244 double ctsSnr,
245 WifiMode ctsMode,
246 double rtsSnr)
247{
248 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
249}
250
251void
253 double ackSnr,
254 WifiMode ackMode,
255 double dataSnr,
256 MHz_u dataChannelWidth,
257 uint8_t dataNss)
258{
259 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
260 auto station = static_cast<AparfWifiRemoteStation*>(st);
261 CheckInit(station);
262 station->m_nSuccess++;
263 station->m_nFailed = 0;
264 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", rate="
265 << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
266
267 if ((station->m_aparfState == AparfWifiManager::High ||
268 station->m_aparfState == AparfWifiManager::Low) &&
269 station->m_nSuccess >= station->m_successThreshold)
270
271 {
272 station->m_aparfState = AparfWifiManager::Spread;
273 }
274 else if (station->m_aparfState == AparfWifiManager::Spread)
275 {
276 station->m_aparfState = AparfWifiManager::High;
277 station->m_successThreshold = m_successMax1;
278 }
279
280 if (station->m_nSuccess == station->m_successThreshold)
281 {
282 station->m_nSuccess = 0;
283 station->m_nFailed = 0;
284 if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size() - 1))
285 {
286 if (station->m_powerLevel != m_minPowerLevel)
287 {
288 NS_LOG_DEBUG("station=" << station << " dec power");
289 station->m_powerLevel -= m_powerLevelDec;
290 }
291 }
292 else
293 {
294 if (station->m_critRateIndex == 0)
295 {
296 if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size() - 1))
297 {
298 NS_LOG_DEBUG("station=" << station << " inc rate");
299 station->m_rateIndex += m_rateInc;
300 }
301 }
302 else
303 {
304 if (station->m_pCount == m_powerMax)
305 {
306 station->m_powerLevel = m_maxPowerLevel;
307 station->m_rateIndex = station->m_critRateIndex;
308 station->m_pCount = 0;
309 station->m_critRateIndex = 0;
310 }
311 else
312 {
313 if (station->m_powerLevel != m_minPowerLevel)
314 {
315 station->m_powerLevel -= m_powerLevelDec;
316 station->m_pCount++;
317 }
318 }
319 }
320 }
321 }
322}
323
324void
329
330void
335
338{
339 NS_LOG_FUNCTION(this << st << allowedWidth);
340 auto station = static_cast<AparfWifiRemoteStation*>(st);
341 auto channelWidth = GetChannelWidth(station);
342 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
343 {
344 channelWidth = MHz_u{20};
345 }
346 CheckInit(station);
347 WifiMode mode = GetSupported(station, station->m_rateIndex);
348 DataRate rate(mode.GetDataRate(channelWidth));
349 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
350 const auto power = GetPhy()->GetPower(station->m_powerLevel);
351 const auto prevPower = GetPhy()->GetPower(station->m_prevPowerLevel);
352 if (station->m_prevPowerLevel != station->m_powerLevel)
353 {
354 m_powerChange(prevPower, power, station->m_state->m_address);
355 station->m_prevPowerLevel = station->m_powerLevel;
356 }
357 if (station->m_prevRateIndex != station->m_rateIndex)
358 {
359 m_rateChange(prevRate, rate, station->m_state->m_address);
360 station->m_prevRateIndex = station->m_rateIndex;
361 }
362 return WifiTxVector(
363 mode,
364 station->m_powerLevel,
366 NanoSeconds(800),
367 1,
368 1,
369 0,
370 channelWidth,
371 GetAggregation(station));
372}
373
376{
377 NS_LOG_FUNCTION(this << st);
378 /// @todo we could/should implement the ARF algorithm for
379 /// RTS only by picking a single rate within the BasicRateSet.
380 auto station = static_cast<AparfWifiRemoteStation*>(st);
381 auto channelWidth = GetChannelWidth(station);
382 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
383 {
384 channelWidth = MHz_u{20};
385 }
386 WifiMode mode;
388 {
389 mode = GetSupported(station, 0);
390 }
391 else
392 {
393 mode = GetNonErpSupported(station, 0);
394 }
395 return WifiTxVector(
396 mode,
399 NanoSeconds(800),
400 1,
401 1,
402 0,
403 channelWidth,
404 GetAggregation(station));
405}
406
407} // 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.
uint8_t m_maxPowerLevel
Maximal power level.
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.
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
uint32_t m_powerMax
The maximum number of power changes.
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.
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.
uint8_t m_minPowerLevel
Minimal power level.
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.
uint8_t m_powerLevelDec
Step size for decrement the power level.
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.
uint8_t m_powerLevelInc
Step size for increment the power level.
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.
Definition ptr.h:67
a unique identifier for an interface.
Definition type-id.h:49
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:38
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:172
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
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...
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#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:1405
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.
static constexpr uint8_t WIFI_MIN_TX_PWR_LEVEL
minimum TX power level value
double MHz_u
MHz weak type.
Definition wifi-units.h:31
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.