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