11#include "ns3/core-module.h"
12#include "ns3/double.h"
14#include "ns3/packet.h"
15#include "ns3/wifi-phy.h"
63 TypeId(
"ns3::ThompsonSamplingWifiManager")
69 "Exponential decay coefficient, Hz; zero is a valid value for static scenarios",
73 .AddTraceSource(
"Rate",
74 "Traced value for rate changes (b/s)",
76 "ns3::TracedValueCallback::Uint64");
98 station->m_nextMode = 0;
99 station->m_lastMode = 0;
107 if (!station->m_mcsStats.empty())
126 if (mode.GetModulationClass() == modulationClass)
130 if (mode.IsAllowed(j, k))
137 station->m_mcsStats.push_back(stats);
144 if (station->m_mcsStats.empty())
161 station->m_mcsStats.push_back(stats);
165 NS_ASSERT_MSG(!station->m_mcsStats.empty(),
"No usable MCS found");
188 Decay(st, station->m_lastMode);
189 station->m_mcsStats.at(station->m_lastMode).fails++;
208 double maxThroughput = 0.0;
209 double frameSuccessRate = 1.0;
214 station->m_nextMode = 0;
216 for (
uint32_t i = 0; i < station->m_mcsStats.size(); i++)
219 const auto mode{station->m_mcsStats.at(i).mode};
222 const auto rate = mode.GetDataRate(station->m_mcsStats.at(i).channelWidth,
224 station->m_mcsStats.at(i).nss);
228 1.0 + station->m_mcsStats.at(i).fails);
230 <<
" success=" << station->m_mcsStats.at(i).success
231 <<
" fails=" << station->m_mcsStats.at(i).fails
232 <<
" frameSuccessRate=" << frameSuccessRate <<
" mode=" << mode);
233 if (frameSuccessRate * rate > maxThroughput)
235 maxThroughput = frameSuccessRate * rate;
236 station->m_nextMode = i;
246 MHz_u dataChannelWidth,
252 Decay(st, station->m_lastMode);
253 station->m_mcsStats.at(station->m_lastMode).success++;
259 uint16_t nSuccessfulMpdus,
260 uint16_t nFailedMpdus,
263 MHz_u dataChannelWidth,
266 NS_LOG_FUNCTION(
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr);
270 Decay(st, station->m_lastMode);
271 station->m_mcsStats.at(station->m_lastMode).success += nSuccessfulMpdus;
272 station->m_mcsStats.at(station->m_lastMode).fails += nFailedMpdus;
315 auto& stats = station->
m_mcsStats.at(station->m_nextMode);
316 const auto mode = stats.mode;
317 const auto channelWidth = std::min(stats.channelWidth, allowedWidth);
318 const auto nss = stats.nss;
321 station->m_lastMode = station->m_nextMode;
324 <<
" mode=" << mode <<
" channelWidth=" << channelWidth <<
" nss=" << +nss
325 <<
" guardInterval=" << guardInterval);
327 const auto rate = mode.GetDataRate(channelWidth, guardInterval, nss);
342 GetPhy()->GetTxBandwidth(mode, channelWidth),
357 uint8_t nss = stats.nss;
370 GetPhy()->GetTxBandwidth(mode, stats.channelWidth),
391 auto& stats = station->m_mcsStats.at(i);
392 if (now > stats.lastDecay)
394 const double coefficient = std::exp(
m_decay * (stats.lastDecay - now).GetSeconds());
396 stats.success *= coefficient;
397 stats.fails *= coefficient;
398 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
MHz_u GetChannelWidth() const
uint8_t GetMaxSupportedTxSpatialStreams() const
std::list< WifiMode > GetMcsList() const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
hold a list of per-remote-station state.
Time GetGuardInterval() const
Return the 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.
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()
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
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.