A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
parf-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
9#include "parf-wifi-manager.h"
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("ParfWifiManager");
22
23/**
24 * Hold per-remote-station state for PARF Wifi manager.
25 *
26 * This struct extends from WifiRemoteStation struct to hold additional
27 * information required by the PARF Wifi manager
28 */
30{
31 uint32_t m_nAttempt; //!< Number of transmission attempts.
32 uint32_t m_nSuccess; //!< Number of successful transmission attempts.
33 uint32_t m_nFail; //!< Number of failed transmission attempts.
34 bool m_usingRecoveryRate; //!< If using recovery rate.
35 bool m_usingRecoveryPower; //!< If using recovery power.
36 uint32_t m_nRetry; //!< Number of transmission retries.
37 uint8_t m_prevRateIndex; //!< Rate index of the previous transmission.
38 uint8_t m_rateIndex; //!< Current rate index used by the remote station.
39 uint8_t m_prevPowerLevel; //!< Power level of the previous transmission.
40 uint8_t m_powerLevel; //!< Current power level used by the remote station.
41 uint8_t m_nSupported; //!< Number of supported rates by the remote station.
42 bool m_initialized; //!< For initializing variables.
43};
44
46
49{
50 static TypeId tid =
51 TypeId("ns3::ParfWifiManager")
53 .SetGroupName("Wifi")
54 .AddConstructor<ParfWifiManager>()
55 .AddAttribute("AttemptThreshold",
56 "The minimum number of transmission attempts to try a new power or rate.",
57 UintegerValue(15),
60 .AddAttribute(
61 "SuccessThreshold",
62 "The minimum number of successful transmissions to try a new power or rate.",
63 UintegerValue(10),
66 .AddTraceSource("PowerChange",
67 "The transmission power has change",
69 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
70 .AddTraceSource("RateChange",
71 "The transmission rate has change",
73 "ns3::WifiRemoteStationManager::RateChangeTracedCallback");
74 return tid;
75}
76
81
86
87void
89{
90 NS_LOG_FUNCTION(this << phy);
91 m_minPower = 0;
92 m_maxPower = phy->GetNTxPower() - 1;
94}
95
96void
98{
99 NS_LOG_FUNCTION(this);
100 if (GetHtSupported())
101 {
102 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
103 }
104 if (GetVhtSupported())
105 {
106 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
107 }
108 if (GetHeSupported())
109 {
110 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
111 }
112}
113
116{
117 NS_LOG_FUNCTION(this);
118 auto station = new ParfWifiRemoteStation();
119
120 station->m_nSuccess = 0;
121 station->m_nFail = 0;
122 station->m_usingRecoveryRate = false;
123 station->m_usingRecoveryPower = false;
124 station->m_initialized = false;
125 station->m_nRetry = 0;
126 station->m_nAttempt = 0;
127
128 NS_LOG_DEBUG("create station=" << station << ", timer=" << station->m_nAttempt
129 << ", rate=" << +station->m_rateIndex
130 << ", power=" << +station->m_powerLevel);
131
132 return station;
133}
134
135void
137{
138 if (!station->m_initialized)
139 {
140 station->m_nSupported = GetNSupported(station);
141 station->m_rateIndex = station->m_nSupported - 1;
142 station->m_prevRateIndex = station->m_nSupported - 1;
143 station->m_powerLevel = m_maxPower;
144 station->m_prevPowerLevel = m_maxPower;
145 WifiMode mode = GetSupported(station, station->m_rateIndex);
146 auto channelWidth = GetChannelWidth(station);
147 DataRate rate(mode.GetDataRate(channelWidth));
148 const auto power = GetPhy()->GetPower(m_maxPower);
149 m_powerChange(power, power, station->m_state->m_address);
150 m_rateChange(rate, rate, station->m_state->m_address);
151 station->m_initialized = true;
152 }
153}
154
155void
160
161/*
162 * It is important to realize that "recovery" mode starts after failure of
163 * the first transmission after a rate increase and ends at the first successful
164 * transmission. Specifically, recovery mode spans retransmissions boundaries.
165 * Fundamentally, ARF handles each data transmission independently, whether it
166 * is the initial transmission of a packet or the retransmission of a packet.
167 * The fundamental reason for this is that there is a backoff between each data
168 * transmission, be it an initial transmission or a retransmission.
169 */
170void
172{
173 NS_LOG_FUNCTION(this << st);
174 auto station = static_cast<ParfWifiRemoteStation*>(st);
175 CheckInit(station);
176 station->m_nAttempt++;
177 station->m_nFail++;
178 station->m_nRetry++;
179 station->m_nSuccess = 0;
180
181 NS_LOG_DEBUG("station=" << station << " data fail retry=" << station->m_nRetry << ", timer="
182 << station->m_nAttempt << ", rate=" << +station->m_rateIndex
183 << ", power=" << +station->m_powerLevel);
184 if (station->m_usingRecoveryRate)
185 {
186 NS_ASSERT(station->m_nRetry >= 1);
187 if (station->m_nRetry == 1)
188 {
189 // need recovery fallback
190 if (station->m_rateIndex != 0)
191 {
192 NS_LOG_DEBUG("station=" << station << " dec rate");
193 station->m_rateIndex--;
194 station->m_usingRecoveryRate = false;
195 }
196 }
197 station->m_nAttempt = 0;
198 }
199 else if (station->m_usingRecoveryPower)
200 {
201 NS_ASSERT(station->m_nRetry >= 1);
202 if (station->m_nRetry == 1)
203 {
204 // need recovery fallback
205 if (station->m_powerLevel < m_maxPower)
206 {
207 NS_LOG_DEBUG("station=" << station << " inc power");
208 station->m_powerLevel++;
209 station->m_usingRecoveryPower = false;
210 }
211 }
212 station->m_nAttempt = 0;
213 }
214 else
215 {
216 NS_ASSERT(station->m_nRetry >= 1);
217 if (((station->m_nRetry - 1) % 2) == 1)
218 {
219 // need normal fallback
220 if (station->m_powerLevel == m_maxPower)
221 {
222 if (station->m_rateIndex != 0)
223 {
224 NS_LOG_DEBUG("station=" << station << " dec rate");
225 station->m_rateIndex--;
226 }
227 }
228 else
229 {
230 NS_LOG_DEBUG("station=" << station << " inc power");
231 station->m_powerLevel++;
232 }
233 }
234 if (station->m_nRetry >= 2)
235 {
236 station->m_nAttempt = 0;
237 }
238 }
239}
240
241void
243{
244 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
245}
246
247void
249 double ctsSnr,
250 WifiMode ctsMode,
251 double rtsSnr)
252{
253 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
254}
255
256void
258 double ackSnr,
259 WifiMode ackMode,
260 double dataSnr,
261 MHz_u dataChannelWidth,
262 uint8_t dataNss)
263{
264 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
265 auto station = static_cast<ParfWifiRemoteStation*>(st);
266 CheckInit(station);
267 station->m_nAttempt++;
268 station->m_nSuccess++;
269 station->m_nFail = 0;
270 station->m_usingRecoveryRate = false;
271 station->m_usingRecoveryPower = false;
272 station->m_nRetry = 0;
273 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", timer="
274 << station->m_nAttempt << ", rate=" << +station->m_rateIndex
275 << ", power=" << +station->m_powerLevel);
276 if ((station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold) &&
277 (station->m_rateIndex < (station->m_state->m_operationalRateSet.size() - 1)))
278 {
279 NS_LOG_DEBUG("station=" << station << " inc rate");
280 station->m_rateIndex++;
281 station->m_nAttempt = 0;
282 station->m_nSuccess = 0;
283 station->m_usingRecoveryRate = true;
284 }
285 else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
286 {
287 // we are at the maximum rate, we decrease power
288 if (station->m_powerLevel != m_minPower)
289 {
290 NS_LOG_DEBUG("station=" << station << " dec power");
291 station->m_powerLevel--;
292 }
293 station->m_nAttempt = 0;
294 station->m_nSuccess = 0;
295 station->m_usingRecoveryPower = true;
296 }
297}
298
299void
304
305void
310
313{
314 NS_LOG_FUNCTION(this << st << allowedWidth);
315 auto station = static_cast<ParfWifiRemoteStation*>(st);
316 auto channelWidth = GetChannelWidth(station);
317 if (channelWidth > 20 && channelWidth != 22)
318 {
319 channelWidth = 20;
320 }
321 CheckInit(station);
322 WifiMode mode = GetSupported(station, station->m_rateIndex);
323 DataRate rate(mode.GetDataRate(channelWidth));
324 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
325 const auto power = GetPhy()->GetPower(station->m_powerLevel);
326 const auto prevPower = GetPhy()->GetPower(station->m_prevPowerLevel);
327 if (station->m_prevPowerLevel != station->m_powerLevel)
328 {
329 m_powerChange(prevPower, power, station->m_state->m_address);
330 station->m_prevPowerLevel = station->m_powerLevel;
331 }
332 if (station->m_prevRateIndex != station->m_rateIndex)
333 {
334 m_rateChange(prevRate, rate, station->m_state->m_address);
335 station->m_prevRateIndex = station->m_rateIndex;
336 }
337 return WifiTxVector(
338 mode,
339 station->m_powerLevel,
341 NanoSeconds(800),
342 1,
343 1,
344 0,
345 channelWidth,
346 GetAggregation(station));
347}
348
351{
352 NS_LOG_FUNCTION(this << st);
353 /// \todo we could/should implement the ARF algorithm for
354 /// RTS only by picking a single rate within the BasicRateSet.
355 auto station = static_cast<ParfWifiRemoteStation*>(st);
356 auto channelWidth = GetChannelWidth(station);
357 if (channelWidth > 20 && channelWidth != 22)
358 {
359 channelWidth = 20;
360 }
361 WifiMode mode;
363 {
364 mode = GetSupported(station, 0);
365 }
366 else
367 {
368 mode = GetNonErpSupported(station, 0);
369 }
370 return WifiTxVector(
371 mode,
374 NanoSeconds(800),
375 1,
376 1,
377 0,
378 channelWidth,
379 GetAggregation(station));
380}
381
382} // namespace ns3
Class for representing data rates.
Definition data-rate.h:78
PARF Rate control algorithm.
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.
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
void CheckInit(ParfWifiRemoteStation *station)
Check for initializations.
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
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 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< DataRate, DataRate, Mac48Address > m_rateChange
The trace source fired when the transmission rate changes.
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.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.
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_maxPower
Maximal power level.
WifiRemoteStation * DoCreateStation() const override
static TypeId GetTypeId()
Register this type.
uint8_t m_minPower
Minimal power level.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoInitialize() override
Initialize() implementation.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
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_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 PARF Wifi manager.
uint32_t m_nRetry
Number of transmission retries.
bool m_usingRecoveryPower
If using recovery power.
uint32_t m_nFail
Number of failed transmission attempts.
bool m_usingRecoveryRate
If using recovery rate.
uint8_t m_rateIndex
Current rate index used by the remote station.
uint32_t m_nSuccess
Number of successful transmission attempts.
uint8_t m_prevRateIndex
Rate index of the previous transmission.
uint8_t m_powerLevel
Current power level used by the remote station.
uint8_t m_nSupported
Number of supported rates by the remote station.
bool m_initialized
For initializing variables.
uint8_t m_prevPowerLevel
Power level of the previous transmission.
uint32_t m_nAttempt
Number of transmission attempts.
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.