22 #include "ns3/core-module.h" 
   23 #include "ns3/double.h" 
   25 #include "ns3/packet.h" 
   26 #include "ns3/wifi-phy.h" 
   74         TypeId(
"ns3::ThompsonSamplingWifiManager")
 
   80                 "Exponential decay coefficient, Hz; zero is a valid value for static scenarios",
 
   83                 MakeDoubleChecker<double>(0.0))
 
   84             .AddTraceSource(
"Rate",
 
   85                             "Traced value for rate changes (b/s)",
 
   87                             "ns3::TracedValueCallback::Uint64");
 
  118     if (!station->m_mcsStats.empty())
 
  137             if (mode.GetModulationClass() == modulationClass)
 
  141                     if (mode.IsAllowed(j, 
k))
 
  148                         station->m_mcsStats.push_back(stats);
 
  155     if (station->m_mcsStats.empty())
 
  172             station->m_mcsStats.push_back(stats);
 
  176     NS_ASSERT_MSG(!station->m_mcsStats.empty(), 
"No usable MCS found");
 
  199     Decay(st, station->m_lastMode);
 
  200     station->m_mcsStats.at(station->m_lastMode).fails++;
 
  219     double maxThroughput = 0.0;
 
  220     double frameSuccessRate = 1.0;
 
  225     station->m_nextMode = 0;
 
  227     for (uint32_t i = 0; i < station->m_mcsStats.size(); i++)
 
  230         const WifiMode mode{station->m_mcsStats.at(i).mode};
 
  233         double rate = mode.GetDataRate(station->m_mcsStats.at(i).channelWidth,
 
  235                                        station->m_mcsStats.at(i).nss);
 
  239                                               1.0 + station->m_mcsStats.at(i).fails);
 
  241                      << 
" success=" << station->m_mcsStats.at(i).success
 
  242                      << 
" fails=" << station->m_mcsStats.at(i).fails
 
  243                      << 
" frameSuccessRate=" << frameSuccessRate << 
" mode=" << mode);
 
  244         if (frameSuccessRate * rate > maxThroughput)
 
  246             maxThroughput = frameSuccessRate * rate;
 
  247             station->m_nextMode = i;
 
  257                                             uint16_t dataChannelWidth,
 
  263     Decay(st, station->m_lastMode);
 
  264     station->m_mcsStats.at(station->m_lastMode).success++;
 
  270                                                    uint16_t nSuccessfulMpdus,
 
  271                                                    uint16_t nFailedMpdus,
 
  274                                                    uint16_t dataChannelWidth,
 
  277     NS_LOG_FUNCTION(
this << st << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr);
 
  281     Decay(st, station->m_lastMode);
 
  282     station->m_mcsStats.at(station->m_lastMode).success += nSuccessfulMpdus;
 
  283     station->m_mcsStats.at(station->m_lastMode).fails += nFailedMpdus;
 
  326     auto& stats = station->
m_mcsStats.at(station->m_nextMode);
 
  328     uint16_t channelWidth = 
std::min(stats.channelWidth, allowedWidth);
 
  329     uint8_t nss = stats.nss;
 
  332     station->m_lastMode = station->m_nextMode;
 
  335                  << 
" mode=" << mode << 
" channelWidth=" << channelWidth << 
" nss=" << +nss
 
  336                  << 
" guardInterval=" << guardInterval);
 
  338     uint64_t rate = mode.
GetDataRate(channelWidth, guardInterval, nss);
 
  353         GetPhy()->GetTxBandwidth(mode, channelWidth),
 
  368     uint8_t nss = stats.nss;
 
  381         GetPhy()->GetTxBandwidth(mode, stats.channelWidth),
 
  402     auto& stats = station->m_mcsStats.at(i);
 
  403     if (now > stats.lastDecay)
 
  405         const double coefficient = std::exp(
m_decay * (stats.lastDecay - now).GetSeconds());
 
  407         stats.success *= coefficient;
 
  408         stats.fails *= coefficient;
 
  409         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.
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.
~ThompsonSamplingWifiManager() override
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.
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.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
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
std::string GetUniqueName() const
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
uint16_t 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.
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.
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.
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...
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.
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.
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.