11#include "ns3/double.h"
13#include "ns3/packet.h"
14#include "ns3/wifi-phy.h"
62 TypeId(
"ns3::ThompsonSamplingWifiManager")
68 "Exponential decay coefficient, Hz; zero is a valid value for static scenarios",
72 .AddTraceSource(
"Rate",
73 "Traced value for rate changes (b/s)",
75 "ns3::TracedValueCallback::Uint64");
97 station->m_nextMode = 0;
98 station->m_lastMode = 0;
106 if (!station->m_mcsStats.empty())
112 for (
const auto& mode :
GetPhy()->GetMcsList())
114 for (
MHz_u j{20}; j <=
GetPhy()->GetChannelWidth(); j *= 2)
125 if (mode.GetModulationClass() == modulationClass)
127 for (uint8_t k = 1; k <=
GetPhy()->GetMaxSupportedTxSpatialStreams(); k++)
129 if (mode.IsAllowed(j, k))
136 station->m_mcsStats.push_back(stats);
143 if (station->m_mcsStats.empty())
160 station->m_mcsStats.push_back(stats);
164 NS_ASSERT_MSG(!station->m_mcsStats.empty(),
"No usable MCS found");
187 Decay(st, station->m_lastMode);
188 station->m_mcsStats.at(station->m_lastMode).fails++;
207 double maxThroughput = 0.0;
208 double frameSuccessRate = 1.0;
213 station->m_nextMode = 0;
215 for (
uint32_t i = 0; i < station->m_mcsStats.size(); i++)
218 const auto mode{station->m_mcsStats.at(i).mode};
221 const auto rate = mode.GetDataRate(station->m_mcsStats.at(i).channelWidth,
223 station->m_mcsStats.at(i).nss);
227 1.0 + station->m_mcsStats.at(i).fails);
228 NS_LOG_DEBUG(
"Draw success=" << station->m_mcsStats.at(i).success
229 <<
" fails=" << station->m_mcsStats.at(i).fails
230 <<
" frameSuccessRate=" << frameSuccessRate
231 <<
" mode=" << mode);
232 if (frameSuccessRate * rate > maxThroughput)
234 maxThroughput = frameSuccessRate * rate;
235 station->m_nextMode = i;
245 MHz_u dataChannelWidth,
251 Decay(st, station->m_lastMode);
252 station->m_mcsStats.at(station->m_lastMode).success++;
258 uint16_t nSuccessfulMpdus,
259 uint16_t nFailedMpdus,
262 MHz_u dataChannelWidth,
265 NS_LOG_FUNCTION(
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr);
269 Decay(st, station->m_lastMode);
270 station->m_mcsStats.at(station->m_lastMode).success += nSuccessfulMpdus;
271 station->m_mcsStats.at(station->m_lastMode).fails += nFailedMpdus;
314 auto& stats = station->
m_mcsStats.at(station->m_nextMode);
315 const auto mode = stats.mode;
316 const auto channelWidth = std::min(stats.channelWidth, allowedWidth);
317 const auto nss = stats.nss;
320 station->m_lastMode = station->m_nextMode;
322 NS_LOG_DEBUG(
"Using mode=" << mode <<
" channelWidth=" << channelWidth <<
" nss=" << +nss
323 <<
" guardInterval=" << guardInterval);
325 const auto rate = mode.GetDataRate(channelWidth, guardInterval, nss);
340 GetPhy()->GetTxBandwidth(mode, channelWidth),
355 uint8_t nss = stats.nss;
368 GetPhy()->GetTxBandwidth(mode, stats.channelWidth),
389 auto& stats = station->m_mcsStats.at(i);
390 if (now > stats.lastDecay)
392 const double coefficient = std::exp(
m_decay * (stats.lastDecay - now).GetSeconds());
394 stats.success *= coefficient;
395 stats.fails *= coefficient;
396 stats.lastDecay = now;
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static Time Now()
Return the current simulation virtual time.
Thompson Sampling rate control algorithm.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
void InitializeStation(WifiRemoteStation *station) const
Initializes station rate tables.
~ThompsonSamplingWifiManager() override
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Time GetModeGuardInterval(WifiRemoteStation *st, WifiMode mode) const
Returns guard interval for the given mode.
double SampleBetaVariable(uint64_t alpha, uint64_t beta) const
Sample beta random variable with given parameters.
WifiRemoteStation * DoCreateStation() const override
Ptr< GammaRandomVariable > m_gammaRandomVariable
Variable used to sample beta-distributed random variables.
void DoReportFinalRtsFailed(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.
ThompsonSamplingWifiManager()
static TypeId GetTypeId()
Get the type ID.
double m_decay
Exponential decay coefficient, Hz.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
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.
void DoReportAmpduTxStatus(WifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus, double rxSnr, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
void UpdateNextMode(WifiRemoteStation *station) const
Draws a new MCS and related parameters to try next time for this station.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) 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 Decay(WifiRemoteStation *st, size_t i) const
Applies exponential decay to MCS statistics.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
represent a single transmission mode
const std::string & GetUniqueName() const
WifiModulationClass GetModulationClass() const
Time GetGuardInterval() const
Return the shortest supported HE guard interval duration.
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.
WifiRemoteStationManager()
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
uint8_t GetNumberOfAntennas() const
bool GetShortGuardIntervalSupported() const
Return whether the device has SGI support enabled.
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_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_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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time NanoSeconds(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.
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_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.
Ptr< const AttributeChecker > MakeDoubleChecker()
double MHz_u
MHz weak type.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
A structure containing parameters of a single rate and its statistics.
MHz_u channelWidth
channel width
uint8_t nss
Number of spatial streams.
double success
averaged number of successful transmissions
double fails
averaged number of failed transmissions
Time lastDecay
last time exponential decay was applied to this rate
Holds station state and collected statistics.
size_t m_nextMode
Mode to select for the next transmission.
std::vector< RateStats > m_mcsStats
Collected statistics.
size_t m_lastMode
Most recently used mode, used to write statistics.
hold per-remote-station state.