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")
95 m_gammaRandomVariable = CreateObject<GammaRandomVariable> ();
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;
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802...
Holds station state and collected statistics.
Simulation virtual time values and global simulation resolution.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< GammaRandomVariable > m_gammaRandomVariable
Variable used to sample beta-distributed random variables.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint8_t GetNumberOfAntennas(void) const
A structure containing parameters of a single rate and its statistics.
void DoReportDataFailed(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.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint16_t channelWidth
channel width in MHz
std::list< WifiMode > GetMcsList(void) const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
double fails
averaged number of failed transmissions
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.
uint8_t nss
Number of spatial streams.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint16_t GetChannelWidth(void) const
void InitializeStation(WifiRemoteStation *station) const
Initializes station rate tables.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
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.
double m_decay
Exponential decay coefficient, Hz.
size_t m_nextMode
Mode to select for the next transmission.
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
std::string GetUniqueName(void) const
double success
averaged number of successful transmissions
std::vector< RateStats > m_mcsStats
Collected statistics.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model...
uint16_t GetChannelWidthForTransmission(WifiMode mode, uint16_t maxSupportedChannelWidth)
Return the channel width that corresponds to the selected mode (instead of letting the PHY's default ...
WifiRemoteStation * DoCreateStation() const override
void Decay(WifiRemoteStation *st, size_t i) const
Applies exponential decay to MCS statistics.
void UpdateNextMode(WifiRemoteStation *station) const
Draws a new MCS and related parameters to try next time for this station.
bool GetShortGuardIntervalSupported(void) const
Return whether the device has SGI support enabled.
static Time Now(void)
Return the current simulation virtual time.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Thompson Sampling rate control algorithmThis class implements Thompson Sampling rate control algorith...
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
#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...
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
uint16_t GetGuardInterval(void) const
Return the supported HE guard interval duration (in nanoseconds).
double SampleBetaVariable(uint64_t alpha, uint64_t beta) const
Sample beta random variable with given parameters.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
ThompsonSamplingWifiManager()
uint8_t GetDefaultTxPowerLevel(void) const
Time lastDecay
last time exponential decay was applied to this rate
uint16_t GetModeGuardInterval(WifiRemoteStation *st, WifiMode mode) const
Returns guard interval in nanoseconds for the given mode.
virtual ~ThompsonSamplingWifiManager()
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
uint8_t GetMaxSupportedTxSpatialStreams(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
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...
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
size_t m_lastMode
Most recently used mode, used to write statistics.