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 * 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: Matias Richart <mrichart@fing.edu.uy>
18 */
19
20#include "parf-wifi-manager.h"
21
22#include "ns3/data-rate.h"
23#include "ns3/log.h"
24#include "ns3/uinteger.h"
25#include "ns3/wifi-phy.h"
26
27#define Min(a, b) ((a < b) ? a : b)
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("ParfWifiManager");
33
34/**
35 * Hold per-remote-station state for PARF Wifi manager.
36 *
37 * This struct extends from WifiRemoteStation struct to hold additional
38 * information required by the PARF Wifi manager
39 */
41{
42 uint32_t m_nAttempt; //!< Number of transmission attempts.
43 uint32_t m_nSuccess; //!< Number of successful transmission attempts.
44 uint32_t m_nFail; //!< Number of failed transmission attempts.
45 bool m_usingRecoveryRate; //!< If using recovery rate.
46 bool m_usingRecoveryPower; //!< If using recovery power.
47 uint32_t m_nRetry; //!< Number of transmission retries.
48 uint8_t m_prevRateIndex; //!< Rate index of the previous transmission.
49 uint8_t m_rateIndex; //!< Current rate index used by the remote station.
50 uint8_t m_prevPowerLevel; //!< Power level of the previous transmission.
51 uint8_t m_powerLevel; //!< Current power level used by the remote station.
52 uint8_t m_nSupported; //!< Number of supported rates by the remote station.
53 bool m_initialized; //!< For initializing variables.
54};
55
57
60{
61 static TypeId tid =
62 TypeId("ns3::ParfWifiManager")
64 .SetGroupName("Wifi")
65 .AddConstructor<ParfWifiManager>()
66 .AddAttribute("AttemptThreshold",
67 "The minimum number of transmission attempts to try a new power or rate.",
68 UintegerValue(15),
70 MakeUintegerChecker<uint32_t>())
71 .AddAttribute(
72 "SuccessThreshold",
73 "The minimum number of successful transmissions to try a new power or rate.",
74 UintegerValue(10),
76 MakeUintegerChecker<uint32_t>())
77 .AddTraceSource("PowerChange",
78 "The transmission power has change",
80 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
81 .AddTraceSource("RateChange",
82 "The transmission rate has change",
84 "ns3::WifiRemoteStationManager::RateChangeTracedCallback");
85 return tid;
86}
87
89{
90 NS_LOG_FUNCTION(this);
91}
92
94{
95 NS_LOG_FUNCTION(this);
96}
97
98void
100{
101 NS_LOG_FUNCTION(this << phy);
102 m_minPower = 0;
103 m_maxPower = phy->GetNTxPower() - 1;
105}
106
107void
109{
110 NS_LOG_FUNCTION(this);
111 if (GetHtSupported())
112 {
113 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
114 }
115 if (GetVhtSupported())
116 {
117 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
118 }
119 if (GetHeSupported())
120 {
121 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
122 }
123}
124
127{
128 NS_LOG_FUNCTION(this);
129 auto station = new ParfWifiRemoteStation();
130
131 station->m_nSuccess = 0;
132 station->m_nFail = 0;
133 station->m_usingRecoveryRate = false;
134 station->m_usingRecoveryPower = false;
135 station->m_initialized = false;
136 station->m_nRetry = 0;
137 station->m_nAttempt = 0;
138
139 NS_LOG_DEBUG("create station=" << station << ", timer=" << station->m_nAttempt
140 << ", rate=" << +station->m_rateIndex
141 << ", power=" << +station->m_powerLevel);
142
143 return station;
144}
145
146void
148{
149 if (!station->m_initialized)
150 {
151 station->m_nSupported = GetNSupported(station);
152 station->m_rateIndex = station->m_nSupported - 1;
153 station->m_prevRateIndex = station->m_nSupported - 1;
154 station->m_powerLevel = m_maxPower;
155 station->m_prevPowerLevel = m_maxPower;
156 WifiMode mode = GetSupported(station, station->m_rateIndex);
157 uint16_t channelWidth = GetChannelWidth(station);
158 DataRate rate(mode.GetDataRate(channelWidth));
159 double power = GetPhy()->GetPowerDbm(m_maxPower);
160 m_powerChange(power, power, station->m_state->m_address);
161 m_rateChange(rate, rate, station->m_state->m_address);
162 station->m_initialized = true;
163 }
164}
165
166void
168{
169 NS_LOG_FUNCTION(this << station);
170}
171
172/*
173 * It is important to realize that "recovery" mode starts after failure of
174 * the first transmission after a rate increase and ends at the first successful
175 * transmission. Specifically, recovery mode spans retransmissions boundaries.
176 * Fundamentally, ARF handles each data transmission independently, whether it
177 * is the initial transmission of a packet or the retransmission of a packet.
178 * The fundamental reason for this is that there is a backoff between each data
179 * transmission, be it an initial transmission or a retransmission.
180 */
181void
183{
184 NS_LOG_FUNCTION(this << st);
185 auto station = static_cast<ParfWifiRemoteStation*>(st);
186 CheckInit(station);
187 station->m_nAttempt++;
188 station->m_nFail++;
189 station->m_nRetry++;
190 station->m_nSuccess = 0;
191
192 NS_LOG_DEBUG("station=" << station << " data fail retry=" << station->m_nRetry << ", timer="
193 << station->m_nAttempt << ", rate=" << +station->m_rateIndex
194 << ", power=" << +station->m_powerLevel);
195 if (station->m_usingRecoveryRate)
196 {
197 NS_ASSERT(station->m_nRetry >= 1);
198 if (station->m_nRetry == 1)
199 {
200 // need recovery fallback
201 if (station->m_rateIndex != 0)
202 {
203 NS_LOG_DEBUG("station=" << station << " dec rate");
204 station->m_rateIndex--;
205 station->m_usingRecoveryRate = false;
206 }
207 }
208 station->m_nAttempt = 0;
209 }
210 else if (station->m_usingRecoveryPower)
211 {
212 NS_ASSERT(station->m_nRetry >= 1);
213 if (station->m_nRetry == 1)
214 {
215 // need recovery fallback
216 if (station->m_powerLevel < m_maxPower)
217 {
218 NS_LOG_DEBUG("station=" << station << " inc power");
219 station->m_powerLevel++;
220 station->m_usingRecoveryPower = false;
221 }
222 }
223 station->m_nAttempt = 0;
224 }
225 else
226 {
227 NS_ASSERT(station->m_nRetry >= 1);
228 if (((station->m_nRetry - 1) % 2) == 1)
229 {
230 // need normal fallback
231 if (station->m_powerLevel == m_maxPower)
232 {
233 if (station->m_rateIndex != 0)
234 {
235 NS_LOG_DEBUG("station=" << station << " dec rate");
236 station->m_rateIndex--;
237 }
238 }
239 else
240 {
241 NS_LOG_DEBUG("station=" << station << " inc power");
242 station->m_powerLevel++;
243 }
244 }
245 if (station->m_nRetry >= 2)
246 {
247 station->m_nAttempt = 0;
248 }
249 }
250}
251
252void
254{
255 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
256}
257
258void
260 double ctsSnr,
261 WifiMode ctsMode,
262 double rtsSnr)
263{
264 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
265}
266
267void
269 double ackSnr,
270 WifiMode ackMode,
271 double dataSnr,
272 uint16_t dataChannelWidth,
273 uint8_t dataNss)
274{
275 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
276 auto station = static_cast<ParfWifiRemoteStation*>(st);
277 CheckInit(station);
278 station->m_nAttempt++;
279 station->m_nSuccess++;
280 station->m_nFail = 0;
281 station->m_usingRecoveryRate = false;
282 station->m_usingRecoveryPower = false;
283 station->m_nRetry = 0;
284 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", timer="
285 << station->m_nAttempt << ", rate=" << +station->m_rateIndex
286 << ", power=" << +station->m_powerLevel);
287 if ((station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold) &&
288 (station->m_rateIndex < (station->m_state->m_operationalRateSet.size() - 1)))
289 {
290 NS_LOG_DEBUG("station=" << station << " inc rate");
291 station->m_rateIndex++;
292 station->m_nAttempt = 0;
293 station->m_nSuccess = 0;
294 station->m_usingRecoveryRate = true;
295 }
296 else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
297 {
298 // we are at the maximum rate, we decrease power
299 if (station->m_powerLevel != m_minPower)
300 {
301 NS_LOG_DEBUG("station=" << station << " dec power");
302 station->m_powerLevel--;
303 }
304 station->m_nAttempt = 0;
305 station->m_nSuccess = 0;
306 station->m_usingRecoveryPower = true;
307 }
308}
309
310void
312{
313 NS_LOG_FUNCTION(this << station);
314}
315
316void
318{
319 NS_LOG_FUNCTION(this << station);
320}
321
324{
325 NS_LOG_FUNCTION(this << st << allowedWidth);
326 auto station = static_cast<ParfWifiRemoteStation*>(st);
327 uint16_t channelWidth = GetChannelWidth(station);
328 if (channelWidth > 20 && channelWidth != 22)
329 {
330 channelWidth = 20;
331 }
332 CheckInit(station);
333 WifiMode mode = GetSupported(station, station->m_rateIndex);
334 DataRate rate(mode.GetDataRate(channelWidth));
335 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
336 double power = GetPhy()->GetPowerDbm(station->m_powerLevel);
337 double prevPower = GetPhy()->GetPowerDbm(station->m_prevPowerLevel);
338 if (station->m_prevPowerLevel != station->m_powerLevel)
339 {
340 m_powerChange(prevPower, power, station->m_state->m_address);
341 station->m_prevPowerLevel = station->m_powerLevel;
342 }
343 if (station->m_prevRateIndex != station->m_rateIndex)
344 {
345 m_rateChange(prevRate, rate, station->m_state->m_address);
346 station->m_prevRateIndex = station->m_rateIndex;
347 }
348 return WifiTxVector(
349 mode,
350 station->m_powerLevel,
352 800,
353 1,
354 1,
355 0,
356 channelWidth,
357 GetAggregation(station));
358}
359
362{
363 NS_LOG_FUNCTION(this << st);
364 /// \todo we could/should implement the ARF algorithm for
365 /// RTS only by picking a single rate within the BasicRateSet.
366 auto station = static_cast<ParfWifiRemoteStation*>(st);
367 uint16_t channelWidth = GetChannelWidth(station);
368 if (channelWidth > 20 && channelWidth != 22)
369 {
370 channelWidth = 20;
371 }
372 WifiMode mode;
374 {
375 mode = GetSupported(station, 0);
376 }
377 else
378 {
379 mode = GetNonErpSupported(station, 0);
380 }
381 return WifiTxVector(
382 mode,
385 800,
386 1,
387 1,
388 0,
389 channelWidth,
390 GetAggregation(station));
391}
392
393} // namespace ns3
Class for representing data rates.
Definition: data-rate.h:89
PARF Rate control algorithm.
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 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 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.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
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.
Definition: ptr.h:77
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
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:693
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
Ptr< WifiPhy > GetPhy() const
Return the WifiPhy.
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.
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.
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 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.