22 #include "ns3/double.h"
23 #include "ns3/core-module.h"
24 #include "ns3/packet.h"
26 #include "ns3/wifi-phy.h"
73 static TypeId tid =
TypeId (
"ns3::ThompsonSamplingWifiManager")
75 .SetGroupName (
"Wifi")
77 .AddAttribute (
"Decay",
78 "Exponential decay coefficient, Hz; zero is a valid value for static scenarios",
81 MakeDoubleChecker<double> (0.0))
82 .AddTraceSource (
"Rate",
83 "Traced value for rate changes (b/s)",
85 "ns3::TracedValueCallback::Uint64")
117 if (!station->m_mcsStats.empty ())
136 if (mode.GetModulationClass () == modulationClass)
140 if (mode.IsAllowed (j,
k))
147 station->m_mcsStats.push_back (stats);
154 if (station->m_mcsStats.empty ())
171 station->m_mcsStats.push_back (stats);
175 NS_ASSERT_MSG (!station->m_mcsStats.empty (),
"No usable MCS found");
198 Decay (st, station->m_lastMode);
199 station->m_mcsStats.at (station->m_lastMode).fails++;
216 double maxThroughput = 0.0;
217 double frameSuccessRate = 1.0;
219 NS_ASSERT (!station->m_mcsStats.empty ());
222 station->m_nextMode = 0;
224 for (uint32_t i = 0; i < station->m_mcsStats.size (); i++)
227 const WifiMode mode{station->m_mcsStats.at (i).mode};
230 double rate = mode.GetDataRate (station->m_mcsStats.at (i).channelWidth,
232 station->m_mcsStats.at (i).nss);
236 1.0 + station->m_mcsStats.at (i).fails);
238 <<
" success=" << station->m_mcsStats.at (i).success
239 <<
" fails=" << station->m_mcsStats.at (i).fails
240 <<
" frameSuccessRate=" << frameSuccessRate
241 <<
" mode=" << mode);
242 if (frameSuccessRate * rate > maxThroughput)
244 maxThroughput = frameSuccessRate * rate;
245 station->m_nextMode = i;
252 double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
257 Decay (st, station->m_lastMode);
258 station->m_mcsStats.at (station->m_lastMode).success++;
264 uint16_t nFailedMpdus,
double rxSnr,
double dataSnr,
265 uint16_t dataChannelWidth, uint8_t dataNss)
267 NS_LOG_FUNCTION (
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr);
271 Decay (st, station->m_lastMode);
272 station->m_mcsStats.at (station->m_lastMode).success += nSuccessfulMpdus;
273 station->m_mcsStats.at (station->m_lastMode).fails += nFailedMpdus;
316 auto &stats = station->
m_mcsStats.at (station->m_nextMode);
319 uint8_t nss = stats.nss;
322 station->m_lastMode = station->m_nextMode;
326 <<
" channelWidth=" << channelWidth
328 <<
" guardInterval=" << guardInterval);
330 uint64_t rate = mode.
GetDataRate (channelWidth, guardInterval, nss);
362 uint8_t nss = stats.nss;
395 auto &stats = station->m_mcsStats.at (i);
396 if (now > stats.lastDecay)
398 const double coefficient =
399 std::exp (
m_decay * (stats.lastDecay - now).GetSeconds ());
401 stats.success *= coefficient;
402 stats.fails *= coefficient;
403 stats.lastDecay = now;
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static Time Now(void)
Return the current simulation virtual time.
Thompson Sampling rate control algorithm.
uint16_t GetModeGuardInterval(WifiRemoteStation *st, WifiMode mode) const
Returns guard interval in nanoseconds for the given mode.
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.
void DoReportDataFailed(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, uint16_t 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, uint16_t dataChannelWidth, uint8_t dataNss) override
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
TracedValue< uint64_t > m_currentRate
Trace rate changes.
virtual ~ThompsonSamplingWifiManager()
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.
static TypeId GetTypeId(void)
Get the type ID.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
ThompsonSamplingWifiManager()
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 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 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
WifiModulationClass GetModulationClass() const
std::string GetUniqueName(void) const
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
std::list< WifiMode > GetMcsList(void) const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
uint8_t GetMaxSupportedTxSpatialStreams(void) const
uint16_t GetChannelWidth(void) const
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
uint8_t GetDefaultTxPowerLevel(void) const
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
bool GetShortGuardIntervalSupported(void) const
Return whether the device has SGI support enabled.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
uint16_t GetGuardInterval(void) const
Return the supported HE guard interval duration (in nanoseconds).
uint8_t GetNumberOfAntennas(void) const
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...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
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.
uint16_t GetChannelWidthForTransmission(WifiMode mode, uint16_t maxAllowedChannelWidth)
Return the channel width that is allowed based on the selected mode and the given maximum channel wid...
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
float alpha
Plot alpha value (transparency)
A structure containing parameters of a single rate and its statistics.
uint16_t channelWidth
channel width in MHz
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.