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 * 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 "aparf-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("AparfWifiManager");
33
34/**
35 * Hold per-remote-station state for APARF Wifi manager.
36 *
37 * This struct extends from WifiRemoteStation struct to hold additional
38 * information required by the APARF Wifi manager
39 */
41{
42 uint32_t m_nSuccess; //!< Number of successful transmission attempts.
43 uint32_t m_nFailed; //!< Number of failed transmission attempts.
44 uint32_t m_pCount; //!< Number of power changes.
45 uint32_t m_successThreshold; //!< The minimum number of successful transmissions to try a new
46 //!< power or rate.
48 m_failThreshold; //!< The minimum number of failed transmissions to try a new power or rate.
49 uint8_t m_prevRateIndex; //!< Rate index of the previous transmission.
50 uint8_t m_rateIndex; //!< Current rate index.
51 uint8_t m_critRateIndex; //!< Critical rate.
52 uint8_t m_prevPowerLevel; //!< Power level of the previous transmission.
53 uint8_t m_powerLevel; //!< Current power level.
54 uint8_t m_nSupported; //!< Number of supported rates by the remote station.
55 bool m_initialized; //!< For initializing variables.
56 AparfWifiManager::State m_aparfState; //!< The estimated state of the channel.
57};
58
60
63{
64 static TypeId tid =
65 TypeId("ns3::AparfWifiManager")
67 .SetGroupName("Wifi")
68 .AddConstructor<AparfWifiManager>()
69 .AddAttribute("SuccessThreshold1",
70 "The minimum number of successful transmissions in \"High\" state to try "
71 "a new power or rate.",
74 MakeUintegerChecker<uint32_t>())
75 .AddAttribute("SuccessThreshold2",
76 "The minimum number of successful transmissions in \"Low\" state to try "
77 "a new power or rate.",
78 UintegerValue(10),
80 MakeUintegerChecker<uint32_t>())
81 .AddAttribute("FailThreshold",
82 "The minimum number of failed transmissions to try a new power or rate.",
85 MakeUintegerChecker<uint32_t>())
86 .AddAttribute("PowerThreshold",
87 "The maximum number of power changes.",
88 UintegerValue(10),
90 MakeUintegerChecker<uint32_t>())
91 .AddAttribute("PowerDecrementStep",
92 "Step size for decrement the power.",
95 MakeUintegerChecker<uint8_t>())
96 .AddAttribute("PowerIncrementStep",
97 "Step size for increment the power.",
100 MakeUintegerChecker<uint8_t>())
101 .AddAttribute("RateDecrementStep",
102 "Step size for decrement the rate.",
103 UintegerValue(1),
105 MakeUintegerChecker<uint8_t>())
106 .AddAttribute("RateIncrementStep",
107 "Step size for increment the rate.",
108 UintegerValue(1),
110 MakeUintegerChecker<uint8_t>())
111 .AddTraceSource("PowerChange",
112 "The transmission power has change",
114 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
115 .AddTraceSource("RateChange",
116 "The transmission rate has change",
118 "ns3::WifiRemoteStationManager::RateChangeTracedCallback");
119 return tid;
120}
121
123{
124 NS_LOG_FUNCTION(this);
125}
126
128{
129 NS_LOG_FUNCTION(this);
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << phy);
136 m_minPower = 0;
137 m_maxPower = phy->GetNTxPower() - 1;
139}
140
141void
143{
144 NS_LOG_FUNCTION(this);
145 if (GetHtSupported())
146 {
147 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
148 }
149 if (GetVhtSupported())
150 {
151 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
152 }
153 if (GetHeSupported())
154 {
155 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
156 }
157}
158
161{
162 NS_LOG_FUNCTION(this);
163 auto station = new AparfWifiRemoteStation();
164
165 station->m_successThreshold = m_successMax1;
166 station->m_failThreshold = m_failMax;
167 station->m_nSuccess = 0;
168 station->m_nFailed = 0;
169 station->m_pCount = 0;
170 station->m_aparfState = AparfWifiManager::High;
171 station->m_initialized = false;
172
173 NS_LOG_DEBUG("create station=" << station << ", rate=" << +station->m_rateIndex
174 << ", power=" << +station->m_powerLevel);
175
176 return station;
177}
178
179void
181{
182 if (!station->m_initialized)
183 {
184 station->m_nSupported = GetNSupported(station);
185 station->m_rateIndex = station->m_nSupported - 1;
186 station->m_prevRateIndex = station->m_nSupported - 1;
187 station->m_powerLevel = m_maxPower;
188 station->m_prevPowerLevel = m_maxPower;
189 station->m_critRateIndex = 0;
190 WifiMode mode = GetSupported(station, station->m_rateIndex);
191 uint16_t channelWidth = GetChannelWidth(station);
192 DataRate rate(mode.GetDataRate(channelWidth));
193 double power = GetPhy()->GetPowerDbm(m_maxPower);
194 m_powerChange(power, power, station->m_state->m_address);
195 m_rateChange(rate, rate, station->m_state->m_address);
196 station->m_initialized = true;
197 }
198}
199
200void
202{
203 NS_LOG_FUNCTION(this << station);
204}
205
206void
208{
209 NS_LOG_FUNCTION(this << st);
210 auto station = static_cast<AparfWifiRemoteStation*>(st);
211 CheckInit(station);
212 station->m_nFailed++;
213 station->m_nSuccess = 0;
214 NS_LOG_DEBUG("station=" << station << ", rate=" << station->m_rateIndex
215 << ", power=" << (int)station->m_powerLevel);
216
217 if (station->m_aparfState == AparfWifiManager::Low)
218 {
219 station->m_aparfState = AparfWifiManager::High;
220 station->m_successThreshold = m_successMax1;
221 }
222 else if (station->m_aparfState == AparfWifiManager::Spread)
223 {
224 station->m_aparfState = AparfWifiManager::Low;
225 station->m_successThreshold = m_successMax2;
226 }
227
228 if (station->m_nFailed == station->m_failThreshold)
229 {
230 station->m_nFailed = 0;
231 station->m_nSuccess = 0;
232 station->m_pCount = 0;
233 if (station->m_powerLevel == m_maxPower)
234 {
235 station->m_critRateIndex = station->m_rateIndex;
236 if (station->m_rateIndex != 0)
237 {
238 NS_LOG_DEBUG("station=" << station << " dec rate");
239 station->m_rateIndex -= m_rateDec;
240 }
241 }
242 else
243 {
244 NS_LOG_DEBUG("station=" << station << " inc power");
245 station->m_powerLevel += m_powerInc;
246 }
247 }
248}
249
250void
252{
253 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
254}
255
256void
258 double ctsSnr,
259 WifiMode ctsMode,
260 double rtsSnr)
261{
262 NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
263}
264
265void
267 double ackSnr,
268 WifiMode ackMode,
269 double dataSnr,
270 uint16_t dataChannelWidth,
271 uint8_t dataNss)
272{
273 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
274 auto station = static_cast<AparfWifiRemoteStation*>(st);
275 CheckInit(station);
276 station->m_nSuccess++;
277 station->m_nFailed = 0;
278 NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_nSuccess << ", rate="
279 << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
280
281 if ((station->m_aparfState == AparfWifiManager::High ||
282 station->m_aparfState == AparfWifiManager::Low) &&
283 station->m_nSuccess >= station->m_successThreshold)
284
285 {
286 station->m_aparfState = AparfWifiManager::Spread;
287 }
288 else if (station->m_aparfState == AparfWifiManager::Spread)
289 {
290 station->m_aparfState = AparfWifiManager::High;
291 station->m_successThreshold = m_successMax1;
292 }
293
294 if (station->m_nSuccess == station->m_successThreshold)
295 {
296 station->m_nSuccess = 0;
297 station->m_nFailed = 0;
298 if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size() - 1))
299 {
300 if (station->m_powerLevel != m_minPower)
301 {
302 NS_LOG_DEBUG("station=" << station << " dec power");
303 station->m_powerLevel -= m_powerDec;
304 }
305 }
306 else
307 {
308 if (station->m_critRateIndex == 0)
309 {
310 if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size() - 1))
311 {
312 NS_LOG_DEBUG("station=" << station << " inc rate");
313 station->m_rateIndex += m_rateInc;
314 }
315 }
316 else
317 {
318 if (station->m_pCount == m_powerMax)
319 {
320 station->m_powerLevel = m_maxPower;
321 station->m_rateIndex = station->m_critRateIndex;
322 station->m_pCount = 0;
323 station->m_critRateIndex = 0;
324 }
325 else
326 {
327 if (station->m_powerLevel != m_minPower)
328 {
329 station->m_powerLevel -= m_powerDec;
330 station->m_pCount++;
331 }
332 }
333 }
334 }
335 }
336}
337
338void
340{
341 NS_LOG_FUNCTION(this << station);
342}
343
344void
346{
347 NS_LOG_FUNCTION(this << station);
348}
349
352{
353 NS_LOG_FUNCTION(this << st << allowedWidth);
354 auto station = static_cast<AparfWifiRemoteStation*>(st);
355 uint16_t channelWidth = GetChannelWidth(station);
356 if (channelWidth > 20 && channelWidth != 22)
357 {
358 channelWidth = 20;
359 }
360 CheckInit(station);
361 WifiMode mode = GetSupported(station, station->m_rateIndex);
362 DataRate rate(mode.GetDataRate(channelWidth));
363 DataRate prevRate(GetSupported(station, station->m_prevRateIndex).GetDataRate(channelWidth));
364 double power = GetPhy()->GetPowerDbm(station->m_powerLevel);
365 double prevPower = GetPhy()->GetPowerDbm(station->m_prevPowerLevel);
366 if (station->m_prevPowerLevel != station->m_powerLevel)
367 {
368 m_powerChange(prevPower, power, station->m_state->m_address);
369 station->m_prevPowerLevel = station->m_powerLevel;
370 }
371 if (station->m_prevRateIndex != station->m_rateIndex)
372 {
373 m_rateChange(prevRate, rate, station->m_state->m_address);
374 station->m_prevRateIndex = station->m_rateIndex;
375 }
376 return WifiTxVector(
377 mode,
378 station->m_powerLevel,
380 800,
381 1,
382 1,
383 0,
384 channelWidth,
385 GetAggregation(station));
386}
387
390{
391 NS_LOG_FUNCTION(this << st);
392 /// \todo we could/should implement the ARF algorithm for
393 /// RTS only by picking a single rate within the BasicRateSet.
394 auto station = static_cast<AparfWifiRemoteStation*>(st);
395 uint16_t channelWidth = GetChannelWidth(station);
396 if (channelWidth > 20 && channelWidth != 22)
397 {
398 channelWidth = 20;
399 }
400 WifiMode mode;
402 {
403 mode = GetSupported(station, 0);
404 }
405 else
406 {
407 mode = GetNonErpSupported(station, 0);
408 }
409 return WifiTxVector(
410 mode,
413 800,
414 1,
415 1,
416 0,
417 channelWidth,
418 GetAggregation(station));
419}
420
421} // 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 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 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.
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.
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
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:89
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:704
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 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.
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.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
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.