A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rraa-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004,2005,2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Federico Maguolo <maguolof@dei.unipd.it>
7 */
8
9#include "rraa-wifi-manager.h"
10
11#include "ns3/log.h"
12#include "ns3/packet.h"
13#include "ns3/simulator.h"
14#include "ns3/wifi-mac.h"
15#include "ns3/wifi-phy.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("RraaWifiManager");
21
22/**
23 * @brief hold per-remote-station state for RRAA Wifi manager.
24 *
25 * This struct extends from WifiRemoteStation struct to hold additional
26 * information required by the RRAA Wifi manager
27 */
29{
30 uint32_t m_counter; //!< Counter for transmission attempts.
31 uint32_t m_nFailed; //!< Number of failed transmission attempts.
32 uint32_t m_adaptiveRtsWnd; //!< Window size for the Adaptive RTS mechanism.
33 uint32_t m_rtsCounter; //!< Counter for RTS transmission attempts.
34 Time m_lastReset; //!< Time of the last reset.
35 bool m_adaptiveRtsOn; //!< Check if Adaptive RTS mechanism is on.
36 bool m_lastFrameFail; //!< Flag if the last frame sent has failed.
37 bool m_initialized; //!< For initializing variables.
38 uint8_t m_nRate; //!< Number of supported rates.
39 uint8_t m_rateIndex; //!< Current rate index.
40
41 RraaThresholdsTable m_thresholds; //!< RRAA thresholds for this station.
42};
43
45
48{
49 static TypeId tid =
50 TypeId("ns3::RraaWifiManager")
52 .SetGroupName("Wifi")
53 .AddConstructor<RraaWifiManager>()
54 .AddAttribute(
55 "Basic",
56 "If true the RRAA-BASIC algorithm will be used, otherwise the RRAA will be used",
57 BooleanValue(false),
60 .AddAttribute("Timeout",
61 "Timeout for the RRAA BASIC loss estimation block",
62 TimeValue(Seconds(0.05)),
65 .AddAttribute("FrameLength",
66 "The Data frame length (in bytes) used for calculating mode TxTime.",
67 UintegerValue(1420),
70 .AddAttribute("AckFrameLength",
71 "The Ack frame length (in bytes) used for calculating mode TxTime.",
72 UintegerValue(14),
75 .AddAttribute("Alpha",
76 "Constant for calculating the MTL threshold.",
77 DoubleValue(1.25),
80 .AddAttribute("Beta",
81 "Constant for calculating the ORI threshold.",
82 DoubleValue(2),
85 .AddAttribute("Tau",
86 "Constant for calculating the EWND size.",
87 DoubleValue(0.012),
90 .AddTraceSource("Rate",
91 "Traced value for rate changes (b/s)",
93 "ns3::TracedValueCallback::Uint64");
94 return tid;
95}
96
103
108
109void
111{
112 NS_LOG_FUNCTION(this << phy);
113 m_sifs = phy->GetSifs();
114 m_difs = m_sifs + 2 * phy->GetSlot();
115 for (const auto& mode : phy->GetModeList())
116 {
117 WifiTxVector txVector;
118 txVector.SetMode(mode);
120 /* Calculate the TX Time of the Data and the corresponding Ack */
121 Time dataTxTime = WifiPhy::CalculateTxDuration(m_frameLength, txVector, phy->GetPhyBand());
122 Time ackTxTime = WifiPhy::CalculateTxDuration(m_ackLength, txVector, phy->GetPhyBand());
123 NS_LOG_DEBUG("Calculating TX times: Mode= " << mode << " DataTxTime= " << dataTxTime
124 << " AckTxTime= " << ackTxTime);
125 AddCalcTxTime(mode, dataTxTime + ackTxTime);
126 }
128}
129
130void
136
137void
139{
140 NS_LOG_FUNCTION(this);
141 if (GetHtSupported())
142 {
143 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
144 }
145 if (GetVhtSupported())
146 {
147 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
148 }
149 if (GetHeSupported())
150 {
151 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
152 }
153}
154
155Time
157{
158 NS_LOG_FUNCTION(this << mode);
159 for (auto i = m_calcTxTime.begin(); i != m_calcTxTime.end(); i++)
160 {
161 if (mode == i->second)
162 {
163 return i->first;
164 }
165 }
166 NS_ASSERT(false);
167 return Seconds(0);
168}
169
170void
172{
173 NS_LOG_FUNCTION(this << mode << t);
174 m_calcTxTime.emplace_back(t, mode);
175}
176
179{
180 NS_LOG_FUNCTION(this << station << mode);
181 WifiRraaThresholds threshold;
182 for (auto i = station->m_thresholds.begin(); i != station->m_thresholds.end(); i++)
183 {
184 if (mode == i->second)
185 {
186 return i->first;
187 }
188 }
189 NS_ABORT_MSG("No thresholds for mode " << mode << " found");
190 return threshold; // Silence compiler warning
191}
192
195{
196 auto station = new RraaWifiRemoteStation();
197 station->m_initialized = false;
198 station->m_adaptiveRtsWnd = 0;
199 station->m_rtsCounter = 0;
200 station->m_adaptiveRtsOn = false;
201 station->m_lastFrameFail = false;
202 return station;
203}
204
205void
207{
208 NS_LOG_FUNCTION(this << station);
209 if (!station->m_initialized)
210 {
211 // Note: we appear to be doing late initialization of the table
212 // to make sure that the set of supported rates has been initialized
213 // before we perform our own initialization.
214 station->m_nRate = GetNSupported(station);
215 // Initialize at maximal rate
216 station->m_rateIndex = GetMaxRate(station);
217
218 station->m_initialized = true;
219
220 station->m_thresholds = RraaThresholdsTable(station->m_nRate);
221 InitThresholds(station);
222 ResetCountersBasic(station);
223 }
224}
225
226void
228{
229 NS_LOG_FUNCTION(this << station);
230 NS_LOG_DEBUG("InitThresholds = " << station);
231
232 double nextCritical = 0;
233 double nextMtl = 0;
234 double mtl = 0;
235 double ori = 0;
236 for (uint8_t i = 0; i < station->m_nRate; i++)
237 {
238 WifiMode mode = GetSupported(station, i);
239 Time totalTxTime = GetCalcTxTime(mode) + m_sifs + m_difs;
240 if (i == GetMaxRate(station))
241 {
242 ori = 0;
243 }
244 else
245 {
246 WifiMode nextMode = GetSupported(station, i + 1);
247 Time nextTotalTxTime = GetCalcTxTime(nextMode) + m_sifs + m_difs;
248 nextCritical = 1 - (nextTotalTxTime.GetSeconds() / totalTxTime.GetSeconds());
249 nextMtl = m_alpha * nextCritical;
250 ori = nextMtl / m_beta;
251 }
252 if (i == 0)
253 {
254 mtl = 1;
255 }
257 th.m_ewnd = static_cast<uint32_t>(ceil(m_tau / totalTxTime.GetSeconds()));
258 th.m_ori = ori;
259 th.m_mtl = mtl;
260 station->m_thresholds.emplace_back(th, mode);
261 mtl = nextMtl;
262 NS_LOG_DEBUG(mode << " " << th.m_ewnd << " " << th.m_mtl << " " << th.m_ori);
263 }
264}
265
266void
268{
269 NS_LOG_FUNCTION(this << station);
270 station->m_nFailed = 0;
271 station->m_counter = GetThresholds(station, station->m_rateIndex).m_ewnd;
272 station->m_lastReset = Simulator::Now();
273}
274
275uint8_t
277{
278 return station->m_nRate - 1;
279}
280
281void
286
287void
289{
290 NS_LOG_FUNCTION(this << st);
291 auto station = static_cast<RraaWifiRemoteStation*>(st);
292 station->m_lastFrameFail = true;
293 CheckTimeout(station);
294 station->m_counter--;
295 station->m_nFailed++;
296 RunBasicAlgorithm(station);
297}
298
299void
301{
302 NS_LOG_FUNCTION(this << st << rxSnr << txMode);
303}
304
305void
307 double ctsSnr,
308 WifiMode ctsMode,
309 double rtsSnr)
310{
311 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
312}
313
314void
316 double ackSnr,
317 WifiMode ackMode,
318 double dataSnr,
319 MHz_u dataChannelWidth,
320 uint8_t dataNss)
321{
322 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
323 auto station = static_cast<RraaWifiRemoteStation*>(st);
324 station->m_lastFrameFail = false;
325 CheckTimeout(station);
326 station->m_counter--;
327 RunBasicAlgorithm(station);
328}
329
330void
335
336void
341
344{
345 NS_LOG_FUNCTION(this << st << allowedWidth);
346 auto station = static_cast<RraaWifiRemoteStation*>(st);
347 auto channelWidth = GetChannelWidth(station);
348 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
349 {
350 channelWidth = MHz_u{20};
351 }
352 CheckInit(station);
353 WifiMode mode = GetSupported(station, station->m_rateIndex);
354 uint64_t rate = mode.GetDataRate(channelWidth);
355 if (m_currentRate != rate)
356 {
357 NS_LOG_DEBUG("New datarate: " << rate);
358 m_currentRate = rate;
359 }
360 return WifiTxVector(
361 mode,
364 NanoSeconds(800),
365 1,
366 1,
367 0,
368 channelWidth,
369 GetAggregation(station));
370}
371
374{
375 NS_LOG_FUNCTION(this << st);
376 auto station = static_cast<RraaWifiRemoteStation*>(st);
377 auto channelWidth = GetChannelWidth(station);
378 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
379 {
380 channelWidth = MHz_u{20};
381 }
382 WifiMode mode;
384 {
385 mode = GetSupported(station, 0);
386 }
387 else
388 {
389 mode = GetNonErpSupported(station, 0);
390 }
391 return WifiTxVector(
392 mode,
395 NanoSeconds(800),
396 1,
397 1,
398 0,
399 channelWidth,
400 GetAggregation(station));
401}
402
403bool
405{
406 NS_LOG_FUNCTION(this << st << size << normally);
407 auto station = static_cast<RraaWifiRemoteStation*>(st);
408 CheckInit(station);
409 if (m_basic)
410 {
411 return normally;
412 }
413 ARts(station);
414 return station->m_adaptiveRtsOn;
415}
416
417void
419{
420 NS_LOG_FUNCTION(this << station);
421 Time d = Simulator::Now() - station->m_lastReset;
422 if (station->m_counter == 0 || d > m_timeout)
423 {
424 ResetCountersBasic(station);
425 }
426}
427
428void
430{
431 NS_LOG_FUNCTION(this << station);
432 WifiRraaThresholds thresholds = GetThresholds(station, station->m_rateIndex);
433 auto ploss = (static_cast<double>(station->m_nFailed) / thresholds.m_ewnd);
434 if (station->m_counter == 0 || ploss > thresholds.m_mtl)
435 {
436 if (ploss > thresholds.m_mtl)
437 {
438 station->m_rateIndex--;
439 }
440 else if (station->m_rateIndex < GetMaxRate(station) && ploss < thresholds.m_ori)
441 {
442 station->m_rateIndex++;
443 }
444 ResetCountersBasic(station);
445 }
446}
447
448void
450{
451 if (!station->m_adaptiveRtsOn && station->m_lastFrameFail)
452 {
453 station->m_adaptiveRtsWnd++;
454 station->m_rtsCounter = station->m_adaptiveRtsWnd;
455 }
456 else if ((station->m_adaptiveRtsOn && station->m_lastFrameFail) ||
457 (!station->m_adaptiveRtsOn && !station->m_lastFrameFail))
458 {
459 station->m_adaptiveRtsWnd = station->m_adaptiveRtsWnd / 2;
460 station->m_rtsCounter = station->m_adaptiveRtsWnd;
461 }
462 if (station->m_rtsCounter > 0)
463 {
464 station->m_adaptiveRtsOn = true;
465 station->m_rtsCounter--;
466 }
467 else
468 {
469 station->m_adaptiveRtsOn = false;
470 }
471}
472
475{
476 NS_LOG_FUNCTION(this << station << +index);
477 WifiMode mode = GetSupported(station, index);
478 return GetThresholds(station, mode);
479}
480
481} // namespace ns3
AttributeValue implementation for Boolean.
Definition boolean.h:26
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Robust Rate Adaptation Algorithm.
WifiRemoteStation * DoCreateStation() const override
double m_tau
Tau value for RRAA (value for calculating EWND size).
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void ARts(RraaWifiRemoteStation *station)
Activate the use of RTS for the given station if the conditions are met.
void CheckInit(RraaWifiRemoteStation *station)
Check for initializations.
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...
TracedValue< uint64_t > m_currentRate
Trace rate changes.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_frameLength
Data frame length used to calculate mode TxTime.
bool DoNeedRts(WifiRemoteStation *st, uint32_t size, bool normally) override
Time m_difs
Value of DIFS configured in the device.
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void SetupMac(const Ptr< WifiMac > mac) override
Set up MAC associated with this device since it is the object that knows the full set of timing param...
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
void RunBasicAlgorithm(RraaWifiRemoteStation *station)
Find an appropriate rate for the given station, using a basic algorithm.
Time GetCalcTxTime(WifiMode mode) const
Get the estimated TxTime of a packet with a given mode.
void ResetCountersBasic(RraaWifiRemoteStation *station)
Reset the counters of the given station.
TxTime m_calcTxTime
To hold all the calculated TxTime for all modes.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
double m_beta
Beta value for RRAA (value for calculating ORI threshold).
void CheckTimeout(RraaWifiRemoteStation *station)
Check if the counter should be reset.
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 DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRraaThresholds GetThresholds(RraaWifiRemoteStation *station, WifiMode mode) const
Get the thresholds for the given station and mode.
void DoInitialize() override
Initialize() implementation.
uint32_t m_ackLength
Ack frame length used to calculate mode TxTime.
double m_alpha
Alpha value for RRAA (value for calculating MTL threshold)
Time m_sifs
Value of SIFS configured in the device.
void InitThresholds(RraaWifiRemoteStation *station)
Initialize the thresholds internal list for the given station.
uint8_t GetMaxRate(RraaWifiRemoteStation *station) const
Return the index for the maximum transmission rate for the given station.
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.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:394
AttributeValue implementation for Time.
Definition nstime.h:1456
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
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition wifi-phy.cc:1568
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
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.
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#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
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:114
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition double.h:32
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition nstime.h:1457
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1477
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_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
@ WIFI_PREAMBLE_LONG
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
std::vector< std::pair< WifiRraaThresholds, WifiMode > > RraaThresholdsTable
List of thresholds for each mode.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for RRAA Wifi manager.
uint8_t m_nRate
Number of supported rates.
Time m_lastReset
Time of the last reset.
RraaThresholdsTable m_thresholds
RRAA thresholds for this station.
bool m_initialized
For initializing variables.
uint32_t m_counter
Counter for transmission attempts.
uint32_t m_rtsCounter
Counter for RTS transmission attempts.
uint32_t m_adaptiveRtsWnd
Window size for the Adaptive RTS mechanism.
bool m_lastFrameFail
Flag if the last frame sent has failed.
bool m_adaptiveRtsOn
Check if Adaptive RTS mechanism is on.
uint8_t m_rateIndex
Current rate index.
uint32_t m_nFailed
Number of failed transmission attempts.
hold per-remote-station state.
WifiRraaThresholds structure.
double m_mtl
Maximum Tolerable Loss threshold.
uint32_t m_ewnd
Evaluation Window.
double m_ori
Opportunistic Rate Increase threshold.