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.",
83 .AddAttribute("PowerIncrementStep",
84 "Step size for increment the power.",
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_minPower = 0;
124 m_maxPower = phy->GetNTxPower() - 1;
126}
127
128void
130{
131 NS_LOG_FUNCTION(this);
132 if (GetHtSupported())
133 {
134 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
135 }
136 if (GetVhtSupported())
137 {
138 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
139 }
140 if (GetHeSupported())
141 {
142 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
143 }
144}
145
148{
149 NS_LOG_FUNCTION(this);
150 auto station = new AparfWifiRemoteStation();
151
152 station->m_successThreshold = m_successMax1;
153 station->m_failThreshold = m_failMax;
154 station->m_nSuccess = 0;
155 station->m_nFailed = 0;
156 station->m_pCount = 0;
157 station->m_aparfState = AparfWifiManager::High;
158 station->m_initialized = false;
159
160 NS_LOG_DEBUG("create station=" << station << ", rate=" << +station->m_rateIndex
161 << ", power=" << +station->m_powerLevel);
162
163 return station;
164}
165
166void
168{
169 if (!station->m_initialized)
170 {
171 station->m_nSupported = GetNSupported(station);
172 station->m_rateIndex = station->m_nSupported - 1;
173 station->m_prevRateIndex = station->m_nSupported - 1;
174 station->m_powerLevel = m_maxPower;
175 station->m_prevPowerLevel = m_maxPower;
176 station->m_critRateIndex = 0;
177 WifiMode mode = GetSupported(station, station->m_rateIndex);
178 auto channelWidth = GetChannelWidth(station);
179 DataRate rate(mode.GetDataRate(channelWidth));
180 const auto power = GetPhy()->GetPower(m_maxPower);
181 m_powerChange(power, power, station->m_state->m_address);
182 m_rateChange(rate, rate, station->m_state->m_address);
183 station->m_initialized = true;
184 }
185}
186
187void
192
193void
195{
196 NS_LOG_FUNCTION(this << st);
197 auto station = static_cast<AparfWifiRemoteStation*>(st);
198 CheckInit(station);
199 station->m_nFailed++;
200 station->m_nSuccess = 0;
201 NS_LOG_DEBUG("station=" << station << ", rate=" << station->m_rateIndex
202 << ", power=" << (int)station->m_powerLevel);
203
204 if (station->m_aparfState == AparfWifiManager::Low)
205 {
206 station->m_aparfState = AparfWifiManager::High;
207 station->m_successThreshold = m_successMax1;
208 }
209 else if (station->m_aparfState == AparfWifiManager::Spread)
210 {
211 station->m_aparfState = AparfWifiManager::Low;
212 station->m_successThreshold = m_successMax2;
213 }
214
215 if (station->m_nFailed == station->m_failThreshold)
216 {
217 station->m_nFailed = 0;
218 station->m_nSuccess = 0;
219 station->m_pCount = 0;
220 if (station->m_powerLevel == m_maxPower)
221 {
222 station->m_critRateIndex = station->m_rateIndex;
223 if (station->m_rateIndex != 0)
224 {
225 NS_LOG_DEBUG("station=" << station << " dec rate");
226 station->m_rateIndex -= m_rateDec;
227 }
228 }
229 else
230 {
231 NS_LOG_DEBUG("station=" << station << " inc power");
232 station->m_powerLevel += m_powerInc;
233 }
234 }
235}
236
237void
239{
240 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
241}
242
243void
245 double ctsSnr,
246 WifiMode ctsMode,
247 double rtsSnr)
248{
249 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
250}
251
252void
254 double ackSnr,
255 WifiMode ackMode,
256 double dataSnr,
257 MHz_u dataChannelWidth,
258 uint8_t dataNss)
259{
260 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
261 auto station = static_cast<AparfWifiRemoteStation*>(st);
262 CheckInit(station);
263 station->m_nSuccess++;
264 station->m_nFailed = 0;
265 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", rate="
266 << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
267
268 if ((station->m_aparfState == AparfWifiManager::High ||
269 station->m_aparfState == AparfWifiManager::Low) &&
270 station->m_nSuccess >= station->m_successThreshold)
271
272 {
273 station->m_aparfState = AparfWifiManager::Spread;
274 }
275 else if (station->m_aparfState == AparfWifiManager::Spread)
276 {
277 station->m_aparfState = AparfWifiManager::High;
278 station->m_successThreshold = m_successMax1;
279 }
280
281 if (station->m_nSuccess == station->m_successThreshold)
282 {
283 station->m_nSuccess = 0;
284 station->m_nFailed = 0;
285 if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size() - 1))
286 {
287 if (station->m_powerLevel != m_minPower)
288 {
289 NS_LOG_DEBUG("station=" << station << " dec power");
290 station->m_powerLevel -= m_powerDec;
291 }
292 }
293 else
294 {
295 if (station->m_critRateIndex == 0)
296 {
297 if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size() - 1))
298 {
299 NS_LOG_DEBUG("station=" << station << " inc rate");
300 station->m_rateIndex += m_rateInc;
301 }
302 }
303 else
304 {
305 if (station->m_pCount == m_powerMax)
306 {
307 station->m_powerLevel = m_maxPower;
308 station->m_rateIndex = station->m_critRateIndex;
309 station->m_pCount = 0;
310 station->m_critRateIndex = 0;
311 }
312 else
313 {
314 if (station->m_powerLevel != m_minPower)
315 {
316 station->m_powerLevel -= m_powerDec;
317 station->m_pCount++;
318 }
319 }
320 }
321 }
322 }
323}
324
325void
330
331void
336
339{
340 NS_LOG_FUNCTION(this << st << allowedWidth);
341 auto station = static_cast<AparfWifiRemoteStation*>(st);
342 auto channelWidth = GetChannelWidth(station);
343 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
344 {
345 channelWidth = MHz_u{20};
346 }
347 CheckInit(station);
348 WifiMode mode = GetSupported(station, station->m_rateIndex);
349 DataRate rate(mode.GetDataRate(channelWidth));
350 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
351 const auto power = GetPhy()->GetPower(station->m_powerLevel);
352 const auto prevPower = GetPhy()->GetPower(station->m_prevPowerLevel);
353 if (station->m_prevPowerLevel != station->m_powerLevel)
354 {
355 m_powerChange(prevPower, power, station->m_state->m_address);
356 station->m_prevPowerLevel = station->m_powerLevel;
357 }
358 if (station->m_prevRateIndex != station->m_rateIndex)
359 {
360 m_rateChange(prevRate, rate, station->m_state->m_address);
361 station->m_prevRateIndex = station->m_rateIndex;
362 }
363 return WifiTxVector(
364 mode,
365 station->m_powerLevel,
367 NanoSeconds(800),
368 1,
369 1,
370 0,
371 channelWidth,
372 GetAggregation(station));
373}
374
377{
378 NS_LOG_FUNCTION(this << st);
379 /// @todo we could/should implement the ARF algorithm for
380 /// RTS only by picking a single rate within the BasicRateSet.
381 auto station = static_cast<AparfWifiRemoteStation*>(st);
382 auto channelWidth = GetChannelWidth(station);
383 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
384 {
385 channelWidth = MHz_u{20};
386 }
387 WifiMode mode;
389 {
390 mode = GetSupported(station, 0);
391 }
392 else
393 {
394 mode = GetNonErpSupported(station, 0);
395 }
396 return WifiTxVector(
397 mode,
400 NanoSeconds(800),
401 1,
402 1,
403 0,
404 channelWidth,
405 GetAggregation(station));
406}
407
408} // 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.
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.
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.