22 #include "ns3/boolean.h"
23 #include "ns3/data-rate.h"
24 #include "ns3/double.h"
26 #include "ns3/packet.h"
27 #include "ns3/simulator.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/wifi-mac.h"
30 #include "ns3/wifi-phy.h"
68 TypeId(
"ns3::RrpaaWifiManager")
74 "If true the RRPAA-BASIC algorithm will be used, otherwise the RRPAA will be used.",
78 .AddAttribute(
"Timeout",
79 "Timeout for the RRPAA-BASIC loss estimation block.",
83 .AddAttribute(
"FrameLength",
84 "The Data frame length (in bytes) used for calculating mode TxTime.",
87 MakeUintegerChecker<uint32_t>())
88 .AddAttribute(
"AckFrameLength",
89 "The Ack frame length (in bytes) used for calculating mode TxTime.",
92 MakeUintegerChecker<uint32_t>())
93 .AddAttribute(
"Alpha",
94 "Constant for calculating the MTL threshold.",
97 MakeDoubleChecker<double>(1))
99 "Constant for calculating the ORI threshold.",
102 MakeDoubleChecker<double>(1))
104 "Constant for calculating the EWND size.",
107 MakeDoubleChecker<double>(0))
108 .AddAttribute(
"Gamma",
109 "Constant for Probabilistic Decision Table decrements.",
112 MakeDoubleChecker<double>(1))
113 .AddAttribute(
"Delta",
114 "Constant for Probabilistic Decision Table increments.",
117 MakeDoubleChecker<double>(1))
118 .AddTraceSource(
"RateChange",
119 "The transmission rate has change.",
121 "ns3::WifiRemoteStationManager::RateChangeTracedCallback")
122 .AddTraceSource(
"PowerChange",
123 "The transmission power has change.",
125 "ns3::WifiRemoteStationManager::PowerChangeTracedCallback");
157 for (
const auto& mode :
phy->GetModeList())
165 NS_LOG_DEBUG(
"Calculating TX times: Mode= " << mode <<
" DataTxTime= " << dataTxTime
166 <<
" AckTxTime= " << ackTxTime);
185 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HT rates");
189 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support VHT rates");
193 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HE rates");
203 if (mode == i->second)
226 if (mode == i->second)
231 NS_ABORT_MSG(
"No thresholds for mode " << mode <<
" found");
240 station->m_adaptiveRtsWnd = 0;
241 station->m_rtsCounter = 0;
242 station->m_adaptiveRtsOn =
false;
243 station->m_lastFrameFail =
false;
244 station->m_initialized =
false;
273 for (uint8_t i = 0; i < station->
m_nRate; i++)
293 double nextCritical = 0;
297 for (uint8_t i = 0; i < station->
m_nRate; i++)
310 nextMtl =
m_alpha * nextCritical;
348 station->m_lastFrameFail =
true;
350 station->m_counter--;
351 station->m_nFailed++;
375 uint16_t dataChannelWidth,
378 NS_LOG_FUNCTION(
this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
381 station->m_lastFrameFail =
false;
383 station->m_counter--;
405 if (channelWidth > 20 && channelWidth != 22)
415 if (station->m_prevRateIndex != station->m_rateIndex)
417 m_rateChange(prevRate, rate, station->m_state->m_address);
418 station->m_prevRateIndex = station->m_rateIndex;
420 if (station->m_prevPowerLevel != station->m_powerLevel)
422 m_powerChange(prevPower, power, station->m_state->m_address);
423 station->m_prevPowerLevel = station->m_powerLevel;
427 station->m_powerLevel,
443 if (channelWidth > 20 && channelWidth != 22)
479 return station->m_adaptiveRtsOn;
498 double bploss = (
static_cast<double>(station->
m_nFailed) / thresholds.
m_ewnd);
503 if (bploss >= thresholds.
m_mtl)
507 NS_LOG_DEBUG(
"bploss >= MTL and power < maxPower => Increase Power");
517 NS_LOG_DEBUG(
"bploss >= MTL and power = maxPower => Decrease Rate");
527 NS_LOG_DEBUG(
"bploss >= MTL but already at maxPower and minRate");
530 else if (wploss <= thresholds.
m_ori)
534 NS_LOG_DEBUG(
"wploss <= ORI and rate < maxRate => Probabilistic Rate Increase");
537 for (uint8_t i = 0; i <= station->
m_rateIndex; i++)
556 NS_LOG_DEBUG(
"wploss <= ORI and rate = maxRate => Probabilistic Power Decrease");
578 else if (bploss > thresholds.
m_ori && wploss < thresholds.
m_mtl)
582 NS_LOG_DEBUG(
"loss between ORI and MTL and power > minPowerLevel => Probabilistic "
Class for representing data rates.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Time m_sifs
Value of SIFS configured in the device.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables for probabilistic changes.
uint8_t m_maxPowerLevel
Maximal power level.
void ResetCountersBasic(RrpaaWifiRemoteStation *station)
Reset the counters of the given station.
double m_beta
Beta value for RRPAA (value for calculating ORI threshold).
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Time m_difs
Value of DIFS configured in the device.
WifiRemoteStation * DoCreateStation() const override
bool m_basic
If using the basic algorithm (without RTS/CTS).
void DoInitialize() override
Initialize() implementation.
void DoReportRtsFailed(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...
TxTime m_calcTxTime
To hold all the calculated TxTime for all modes.
void CheckInit(RrpaaWifiRemoteStation *station)
Check for initializations.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power change.
uint8_t m_minPowerLevel
Differently form rate, power levels do not depend on the remote station.
~RrpaaWifiManager() override
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 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...
void RunAdaptiveRtsAlgorithm(RrpaaWifiRemoteStation *station)
Run an enhanced algorithm which activates the use of RTS for the given station if the conditions are ...
TracedCallback< DataRate, DataRate, Mac48Address > m_rateChange
The trace source fired when the transmission rate change.
Time m_timeout
Timeout for the RRAA BASIC loss estimation block.
uint32_t m_ackLength
Ack frame length used to calculate mode TxTime (in bytes).
uint8_t m_nPowerLevels
Number of power levels.
WifiRrpaaThresholds GetThresholds(RrpaaWifiRemoteStation *station, WifiMode mode) const
Get the thresholds for the given station and mode.
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.
double m_tau
Tau value for RRPAA (value for calculating EWND size).
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_gamma
Gamma value for RRPAA (value for pdTable decrements).
Time GetCalcTxTime(WifiMode mode) const
Get the estimated TxTime of a packet with a given mode.
double m_delta
Delta value for RRPAA (value for pdTable increments).
void CheckTimeout(RrpaaWifiRemoteStation *station)
Check if the counter should be reset.
double m_alpha
Alpha value for RRPAA (value for calculating MTL threshold)
bool DoNeedRts(WifiRemoteStation *st, uint32_t size, bool normally) override
void DoReportFinalDataFailed(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.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_frameLength
Data frame length used to calculate mode TxTime (in bytes).
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
void InitThresholds(RrpaaWifiRemoteStation *station)
Initialize the thresholds internal list for the given station.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
static TypeId GetTypeId()
Register this type.
void RunBasicAlgorithm(RrpaaWifiRemoteStation *station)
Find an appropriate rate and power for the given station, using a basic algorithm.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
represent a single transmission mode
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
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 GetDefaultTxPowerLevel() const
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.
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,...
#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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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 > MakeBooleanChecker()
std::vector< std::vector< double > > RrpaaProbabilitiesTable
List of probabilities.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
std::vector< std::pair< WifiRrpaaThresholds, WifiMode > > RrpaaThresholdsTable
List of thresholds for each mode.
Hold per-remote-station state for RRPAA Wifi manager.
uint32_t m_rtsCounter
Counter for RTS transmission attempts.
uint32_t m_counter
Counter for transmission attempts.
bool m_initialized
For initializing variables.
uint32_t m_nFailed
Number of failed transmission attempts.
uint8_t m_prevPowerLevel
Power level of the previous transmission.
RrpaaThresholdsTable m_thresholds
RRPAA thresholds for this station.
Time m_lastReset
Time of the last reset.
bool m_adaptiveRtsOn
Check if Adaptive RTS mechanism is on.
uint8_t m_prevRateIndex
Rate index of the previous transmission.
bool m_lastFrameFail
Flag if the last frame sent has failed.
uint8_t m_nRate
Number of supported rates.
uint8_t m_powerLevel
Current power level.
RrpaaProbabilitiesTable m_pdTable
Probability table for power and rate changes.
uint8_t m_rateIndex
Current rate index.
uint32_t m_adaptiveRtsWnd
Window size for the Adaptive RTS mechanism.
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.
Robust Rate and Power Adaptation Algorithm.
double m_ori
The Opportunistic Rate Increase threshold.
uint32_t m_ewnd
The Estimation Window size.
double m_mtl
The Maximum Tolerable Loss threshold.