23 #include "ns3/wifi-phy.h"
61 TypeId(
"ns3::IdealWifiManager")
65 .AddAttribute(
"BerThreshold",
66 "The maximum Bit Error Rate acceptable at any transmission mode",
69 MakeDoubleChecker<double>())
70 .AddTraceSource(
"Rate",
71 "Traced value for rate changes (b/s)",
73 "ns3::TracedValueCallback::Uint64");
124 for (
const auto& mode :
GetPhy()->GetModeList())
135 for (
const auto& mode :
GetPhy()->GetMcsList())
147 <<
" nss " << +nss <<
" GI " << guardInterval);
154 uint16_t guardInterval;
169 <<
" channel width " << j <<
" nss " << +
k
170 <<
" GI " << guardInterval);
192 [&txVector](
const std::pair<double, WifiTxVector>& p) ->
bool {
193 return ((txVector.GetMode() == p.second.GetMode()) &&
194 (txVector.GetNss() == p.second.GetNss()) &&
195 (txVector.GetChannelWidth() == p.second.GetChannelWidth()));
203 [&txVector](
const std::pair<double, WifiTxVector>& p) ->
bool {
204 return ((txVector.GetMode() == p.second.GetMode()) &&
205 (txVector.GetNss() == p.second.GetNss()) &&
206 (txVector.GetChannelWidth() == p.second.GetChannelWidth()));
236 st->m_lastChannelWidthObserved = 0;
237 st->m_lastNssObserved = 1;
240 st->m_lastChannelWidth = 0;
271 station->m_lastChannelWidthObserved =
273 station->m_lastNssObserved = 1;
281 uint16_t dataChannelWidth,
289 NS_LOG_WARN(
"DataSnr reported to be zero; not saving this report.");
292 station->m_lastSnrObserved = dataSnr;
293 station->m_lastChannelWidthObserved = dataChannelWidth;
294 station->m_lastNssObserved = dataNss;
299 uint16_t nSuccessfulMpdus,
300 uint16_t nFailedMpdus,
303 uint16_t dataChannelWidth,
306 NS_LOG_FUNCTION(
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr
307 << dataChannelWidth << +dataNss);
311 NS_LOG_WARN(
"DataSnr reported to be zero; not saving this report.");
314 station->m_lastSnrObserved = dataSnr;
315 station->m_lastChannelWidthObserved = dataChannelWidth;
316 station->m_lastNssObserved = dataNss;
343 uint64_t bestRate = 0;
344 uint8_t selectedNss = 1;
345 uint16_t guardInterval;
349 (station->m_lastSnrObserved == station->m_lastSnrCached) &&
350 (channelWidth == station->m_lastChannelWidth))
353 maxMode = station->m_lastMode;
354 selectedNss = station->m_lastNss;
356 << station->m_lastSnrObserved <<
" cached "
357 << station->m_lastSnrCached <<
" channel width "
358 << station->m_lastChannelWidth <<
" nss "
373 uint16_t guardInterval;
380 guardInterval =
static_cast<uint16_t
>(
389 uint8_t nss = (mode.GetMcsValue() / 8) + 1;
394 NS_LOG_DEBUG(
"Skipping mode " << mode.GetUniqueName() <<
" nss " << +nss
402 NS_LOG_DEBUG(
"Testing mode " << mode.GetUniqueName() <<
" data rate "
403 << dataRate <<
" threshold " << threshold
404 <<
" last snr observed "
405 << station->m_lastSnrObserved <<
" cached "
406 << station->m_lastSnrCached);
408 if (dataRate > bestRate && threshold < snr)
410 NS_LOG_DEBUG(
"Candidate mode = " << mode.GetUniqueName() <<
" data rate "
411 << dataRate <<
" threshold " << threshold
412 <<
" channel width " << channelWidth
428 NS_LOG_DEBUG(
"Skipping mode " << mode.GetUniqueName() <<
" nss " << +nss
437 NS_LOG_DEBUG(
"Testing mode = " << mode.GetUniqueName() <<
" data rate "
438 << dataRate <<
" threshold " << threshold
439 <<
" last snr observed "
440 << station->m_lastSnrObserved <<
" cached "
441 << station->m_lastSnrCached);
443 if (dataRate > bestRate && threshold < snr)
446 << mode.GetUniqueName() <<
" data rate " << dataRate
447 <<
" threshold " << threshold <<
" channel width "
448 << channelWidth <<
" snr " << snr);
465 txVector.
SetNss(selectedNss);
472 NS_LOG_DEBUG(
"mode = " << mode.GetUniqueName() <<
" threshold " << threshold
473 <<
" last snr observed " << station->m_lastSnrObserved);
475 if (dataRate > bestRate && threshold < snr)
477 NS_LOG_DEBUG(
"Candidate mode = " << mode.GetUniqueName() <<
" data rate "
478 << dataRate <<
" threshold " << threshold
486 << station->m_lastSnrObserved);
487 station->m_lastSnrCached = station->m_lastSnrObserved;
488 station->m_lastMode = maxMode;
489 station->m_lastNss = selectedNss;
491 NS_LOG_DEBUG(
"Found maxMode: " << maxMode <<
" channelWidth: " << channelWidth
492 <<
" nss: " << +selectedNss);
493 station->m_lastChannelWidth = channelWidth;
518 uint64_t maxDataRate = maxMode.
GetDataRate(bestTxVector);
535 double maxThreshold = 0.0;
548 if (threshold > maxThreshold && threshold < station->m_lastSnrObserved)
550 maxThreshold = threshold;
568 uint16_t channelWidth,
583 << snr <<
" for channel width " << channelWidth
584 <<
" and nss " << +nss);
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Ideal rate control algorithm.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void AddSnrThreshold(WifiTxVector txVector, double snr)
Adds a pair of WifiTxVector and the minimum SNR for that given vector to the list.
void BuildSnrThresholds()
Construct the vector of minimum SNRs needed to successfully transmit for all possible combinations (r...
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoInitialize() override
Initialize() implementation.
uint16_t GetChannelWidthForNonHtMode(WifiMode mode) const
Convenience function for selecting a channel width for non-HT mode.
double m_ber
The maximum Bit Error Rate acceptable at any transmission mode.
WifiRemoteStation * DoCreateStation() const override
~IdealWifiManager() override
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId()
Get the type ID.
bool IsModulationClassSupported(WifiModulationClass mc, IdealWifiRemoteStation *station)
Check whether a given modulation class is supported by both the node and the peer.
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.
bool IsCandidateModulationClass(WifiModulationClass mc, IdealWifiRemoteStation *station)
Check whether a given modulation class is supported and that there are no higher modulation classes t...
void DoReportAmpduTxStatus(WifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus, double rxSnr, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
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.
double GetLastObservedSnr(IdealWifiRemoteStation *station, uint16_t channelWidth, uint8_t nss) const
Convenience function to get the last observed SNR from a given station for a given channel width and ...
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.
Thresholds m_thresholds
List of WifiTxVector and the minimum SNR pair.
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 GetSnrThreshold(WifiTxVector txVector)
Return the minimum SNR needed to successfully transmit data with this WifiTxVector at the specified B...
void DoReportDataFailed(WifiRemoteStation *station) 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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
represent a single transmission mode
std::string GetUniqueName() const
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
bool IsAllowed(uint16_t channelWidth, uint8_t nss) const
uint8_t GetMcsValue() const
uint16_t GetChannelWidth() const
uint16_t GetTxBandwidth(WifiMode mode, uint16_t maxAllowedBandWidth=std::numeric_limits< uint16_t >::max()) const
Get the bandwidth for a transmission occurring on the current operating channel and using the given W...
uint8_t GetMaxSupportedTxSpatialStreams() const
hold a list of per-remote-station state.
uint8_t GetNumberOfSupportedStreams(Mac48Address address) const
Return the number of spatial streams supported by the station.
WifiMode GetDefaultModeForSta(const WifiRemoteStation *st) const
Return the default MCS to use to transmit frames to the given station.
uint8_t GetNBasicModes() const
Return the number of basic modes we support.
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.
uint16_t GetGuardInterval() const
Return the supported HE guard interval duration (in nanoseconds).
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.
bool GetEhtSupported() const
Return whether the device has EHT capability support enabled.
uint8_t GetNumberOfAntennas() const
uint8_t GetNMcsSupported(Mac48Address address) const
Return the number of MCS supported by the station.
WifiMode GetBasicMode(uint8_t i) const
Return a basic mode from the set of basic modes.
bool GetShortGuardIntervalSupported() const
Return whether the device has SGI support enabled.
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...
uint8_t GetMaxNumberOfTransmitStreams() const
WifiMode GetMcsSupported(const WifiRemoteStation *station, uint8_t i) const
Return the WifiMode supported by the specified station at the specified index.
void Reset()
Reset the station, invoked in a STA upon dis-association or in an AP upon reboot.
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.
WifiMode GetDefaultMode() const
Return the default transmission mode.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetGuardInterval() const
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
bool IsValid(WifiPhyBand band=WIFI_PHY_BAND_UNSPECIFIED) const
The standard disallows certain combinations of WifiMode, number of spatial streams,...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
uint16_t GetChannelWidth() const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetNss(uint8_t nss)
Sets the number of Nss.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#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_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const double CACHE_INITIAL_VALUE
To avoid using the cache before a valid value has been cached.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for Ideal Wifi manager.
WifiMode m_lastMode
Mode most recently used to the remote station.
double m_lastSnrObserved
SNR of most recently reported packet sent to the remote station.
double m_lastSnrCached
SNR most recently used to select a rate.
uint8_t m_lastNss
Number of spatial streams most recently used to the remote station.
uint16_t m_lastNssObserved
Number of spatial streams of most recently reported packet sent to the remote station.
uint16_t m_lastChannelWidth
Channel width (in MHz) most recently used to the remote station.
uint16_t m_lastChannelWidthObserved
Channel width (in MHz) of most recently reported packet sent to the remote station.
hold per-remote-station state.