23#include "ns3/packet.h"
24#include "ns3/random-variable-stream.h"
25#include "ns3/simulator.h"
26#include "ns3/wifi-mac.h"
27#include "ns3/wifi-phy.h"
28#include "ns3/wifi-psdu.h"
33#define Min(a, b) ((a < b) ? a : b)
46 TypeId(
"ns3::MinstrelWifiManager")
50 .AddAttribute(
"UpdateStatistics",
51 "The interval between updating statistics table",
55 .AddAttribute(
"LookAroundRate",
56 "The percentage to try other rates",
65 .AddAttribute(
"SampleColumn",
66 "The number of columns used for sampling",
70 .AddAttribute(
"PacketLength",
71 "The packet length used for calculating mode TxTime",
75 .AddAttribute(
"PrintStats",
76 "Print statistics table",
80 .AddAttribute(
"PrintSamples",
81 "Print samples table",
85 .AddTraceSource(
"Rate",
86 "Traced value for rate changes (b/s)",
88 "ns3::TracedValueCallback::Uint64");
109 for (
const auto& mode : phy->GetModeList())
132 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HT rates");
136 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support VHT rates");
140 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HE rates");
181 station->m_totalPacketsCount = 0;
182 station->m_samplePacketsCount = 0;
185 station->m_sampleDeferred =
false;
190 station->m_initialized =
false;
243 <<
", maxTp=" <<
station->m_maxTpRate <<
", maxTp2=" <<
station->m_maxTpRate2
244 <<
", maxProb=" <<
station->m_maxProbRate);
247 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount)
249 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
254 else if (
station->m_longRetry <=
255 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
256 station->m_minstrelTable[
station->m_maxTpRate2].adjustedRetryCount))
258 NS_LOG_DEBUG(
" More retries left for the second maximum throughput rate.");
263 else if (
station->m_longRetry <=
264 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
265 station->m_minstrelTable[
station->m_maxTpRate2].adjustedRetryCount +
266 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
268 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
273 else if (
station->m_longRetry >
274 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
275 station->m_minstrelTable[
station->m_maxTpRate2].adjustedRetryCount +
276 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
288 <<
", maxTp=" <<
station->m_maxTpRate <<
", maxTp2=" <<
station->m_maxTpRate2
289 <<
", maxProb=" <<
station->m_maxProbRate);
293 NS_LOG_DEBUG(
"Look around rate is slower than the maximum throughput rate.");
296 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount)
298 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
303 else if (
station->m_longRetry <=
304 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
305 station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount))
307 NS_LOG_DEBUG(
" More retries left for the sampling rate.");
312 else if (
station->m_longRetry <=
313 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
314 station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
315 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
317 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
322 else if (
station->m_longRetry >
323 (
station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
324 station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
325 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
334 NS_LOG_DEBUG(
"Look around rate is faster than the maximum throughput rate.");
337 station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount)
339 NS_LOG_DEBUG(
" More retries left for the sampling rate.");
344 else if (
station->m_longRetry <=
345 (
station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
346 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount))
348 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
353 else if (
station->m_longRetry <=
354 (
station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
355 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
356 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
358 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
363 else if (
station->m_longRetry >
364 (
station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
365 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
366 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount))
380 if (channelWidth >
MHz_u{20} && channelWidth !=
MHz_u{22})
382 channelWidth =
MHz_u{20};
413 if (channelWidth >
MHz_u{20} && channelWidth !=
MHz_u{22})
415 channelWidth =
MHz_u{20};
443 return station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
444 station->m_minstrelTable[
station->m_maxTpRate2].adjustedRetryCount +
445 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount +
446 station->m_minstrelTable[0].adjustedRetryCount;
450 return station->m_minstrelTable[
station->m_sampleRate].adjustedRetryCount +
451 station->m_minstrelTable[
station->m_maxTpRate].adjustedRetryCount +
452 station->m_minstrelTable[
station->m_maxProbRate].adjustedRetryCount +
453 station->m_minstrelTable[0].adjustedRetryCount;
462 if (
station->m_totalPacketsCount == 0)
469 <<
" Sample: " <<
station->m_samplePacketsCount
470 <<
" Deferred: " <<
station->m_numSamplesDeferred);
473 (
station->m_samplePacketsCount +
station->m_numSamplesDeferred / 2);
516 if ((
station->m_minstrelTable[
idx].perfectTxTime >
518 (
station->m_minstrelTable[
idx].numSamplesSkipped < 20))
521 station->m_sampleDeferred =
true;
522 station->m_numSamplesDeferred++;
530 if (!
station->m_minstrelTable[
idx].sampleLimit)
539 if (
station->m_minstrelTable[
idx].sampleLimit > 0)
549 NS_LOG_DEBUG(
"The next look around rate is slower than the maximum throughput rate, "
550 "continue with the maximum throughput rate: "
559 NS_LOG_DEBUG(
"Continue using the maximum throughput rate: "
593 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
596 txTime =
station->m_minstrelTable[
i].perfectTxTime;
605 <<
station->m_minstrelTable[
i].numRateAttempt <<
"\t"
606 <<
station->m_minstrelTable[
i].numRateSuccess);
609 if (
station->m_minstrelTable[
i].numRateAttempt)
611 station->m_minstrelTable[
i].numSamplesSkipped = 0;
617 station->m_minstrelTable[
i].numRateAttempt;
622 if (
station->m_minstrelTable[
i].successHist == 0)
637 station->m_minstrelTable[
i].throughput =
642 station->m_minstrelTable[
i].numSamplesSkipped++;
646 station->m_minstrelTable[
i].successHist +=
station->m_minstrelTable[
i].numRateSuccess;
647 station->m_minstrelTable[
i].attemptHist +=
station->m_minstrelTable[
i].numRateAttempt;
648 station->m_minstrelTable[
i].prevNumRateSuccess =
station->m_minstrelTable[
i].numRateSuccess;
649 station->m_minstrelTable[
i].prevNumRateAttempt =
station->m_minstrelTable[
i].numRateAttempt;
650 station->m_minstrelTable[
i].numRateSuccess = 0;
651 station->m_minstrelTable[
i].numRateAttempt = 0;
654 if ((
station->m_minstrelTable[
i].ewmaProb > 17100) ||
655 (
station->m_minstrelTable[
i].ewmaProb < 1800))
666 if (
station->m_minstrelTable[
i].retryCount > 2)
668 station->m_minstrelTable[
i].adjustedRetryCount = 2;
670 station->m_minstrelTable[
i].sampleLimit = 4;
675 station->m_minstrelTable[
i].sampleLimit = -1;
676 station->m_minstrelTable[
i].adjustedRetryCount =
station->m_minstrelTable[
i].retryCount;
680 if (
station->m_minstrelTable[
i].adjustedRetryCount == 0)
682 station->m_minstrelTable[
i].adjustedRetryCount = 2;
694 "Finding the maximum throughput, second maximum throughput, and highest probability");
696 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
699 <<
station->m_minstrelTable[
i].throughput <<
"\t"
700 <<
station->m_minstrelTable[
i].ewmaProb);
711 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
722 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
724 if ((
station->m_minstrelTable[
i].ewmaProb >= 95 * 180 &&
725 station->m_minstrelTable[
i].throughput >=
797 <<
"\tlongRetry \t" <<
station->m_longRetry);
826 <<
", attempt = " <<
station->m_minstrelTable[
station->m_txrate].numRateAttempt
827 <<
", success = " <<
station->m_minstrelTable[
station->m_txrate].numRateSuccess
828 <<
" (before update).");
837 <<
", attempt = " <<
station->m_minstrelTable[
station->m_txrate].numRateAttempt
838 <<
", success = " <<
station->m_minstrelTable[
station->m_txrate].numRateSuccess
839 <<
" (after update).");
865 <<
", attempt = " <<
station->m_minstrelTable[
station->m_txrate].numRateAttempt
866 <<
", success = " <<
station->m_minstrelTable[
station->m_txrate].numRateSuccess
867 <<
" (before update).");
876 <<
", attempt = " <<
station->m_minstrelTable[
station->m_txrate].numRateAttempt
877 <<
", success = " <<
station->m_minstrelTable[
station->m_txrate].numRateSuccess
878 <<
" (after update).");
892 station->m_totalPacketsCount++;
898 station->m_samplePacketsCount++;
901 if (
station->m_numSamplesDeferred > 0)
903 station->m_numSamplesDeferred--;
906 if (
station->m_totalPacketsCount == ~0)
908 station->m_numSamplesDeferred = 0;
909 station->m_samplePacketsCount = 0;
910 station->m_totalPacketsCount = 0;
913 station->m_sampleDeferred =
false;
941std::list<Ptr<WifiMpdu>>
952 (mpdu->GetRetryCount() <
GetMac()->GetFrameRetryLimit())))
1015 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
1018 station->m_minstrelTable[
i].numRateAttempt = 0;
1019 station->m_minstrelTable[
i].numRateSuccess = 0;
1020 station->m_minstrelTable[
i].prevNumRateSuccess = 0;
1021 station->m_minstrelTable[
i].prevNumRateAttempt = 0;
1022 station->m_minstrelTable[
i].successHist = 0;
1023 station->m_minstrelTable[
i].attemptHist = 0;
1024 station->m_minstrelTable[
i].numSamplesSkipped = 0;
1025 station->m_minstrelTable[
i].prob = 0;
1026 station->m_minstrelTable[
i].ewmaProb = 0;
1027 station->m_minstrelTable[
i].throughput = 0;
1030 station->m_minstrelTable[
i].retryCount = 1;
1031 station->m_minstrelTable[
i].adjustedRetryCount = 1;
1047 station->m_minstrelTable[
i].sampleLimit = -1;
1077 cw = std::min(cwMax, (cw + 1) * 2);
1119 std::stringstream table;
1124 table <<
station->m_sampleTable[
i][
j] <<
"\t";
1134 if (!
station->m_statsFile.is_open())
1136 std::ostringstream
tmp;
1137 tmp <<
"minstrel-stats-" <<
station->m_state->m_address <<
".txt";
1138 station->m_statsFile.open(
tmp.str(), std::ios::out);
1142 <<
"best _______________rate________________ ________statistics________ "
1143 "________last_______ ______sum-of________\n"
1144 <<
"rate [ name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] "
1145 "[prob.|retry|suc|att] [#success | #attempts]\n";
1151 for (uint8_t
i = 0;
i <
station->m_nModes;
i++)
1182 << std::setw(2) <<
i <<
" " << std::setw(4)
1184 <<
" ----- " << std::setw(8) <<
tmpTh <<
" " << std::setw(3)
1185 << rate.
ewmaProb / 180 << std::setw(3) <<
" --- "
1186 << std::setw(3) << rate.
prob / 180 <<
" " << std::setw(1)
1190 <<
" " << std::setw(9) << rate.
attemptHist <<
"\n";
1192 station->m_statsFile <<
"\nTotal packet count: ideal "
1194 <<
" lookaround " <<
station->m_samplePacketsCount <<
"\n\n";
AttributeValue implementation for Boolean.
Implementation of Minstrel Rate Control Algorithm.
WifiRemoteStation * DoCreateStation() const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
~MinstrelWifiManager() override
uint8_t m_lookAroundRate
the % to try other rates than our current rate
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 PrintSampleTable(MinstrelWifiRemoteStation *station) const
Print Sample Table.
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
void RateInit(MinstrelWifiRemoteStation *station)
Initialize Minstrel Table.
uint32_t m_pktLen
packet length used to calculate mode TxTime
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoInitialize() override
Initialize() implementation.
void UpdateStats(MinstrelWifiRemoteStation *station)
Update the Minstrel Table.
void CheckInit(MinstrelWifiRemoteStation *station)
Check for initializations.
static TypeId GetTypeId()
Get the type ID.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
TxTime m_calcTxTime
to hold all the calculated TxTime for all modes
bool m_printSamples
whether samples table should be printed.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
bool m_printStats
whether statistics table should be printed.
WifiTxVector GetRtsTxVector(MinstrelWifiRemoteStation *station)
Get RTS transmit vector.
uint8_t m_sampleCol
number of sample columns
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void SetupMac(const Ptr< WifiMac > mac) override
Set up MAC associated with this device since it is the object that knows the full set of timing param...
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
uint16_t FindRate(MinstrelWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
Time GetCalcTxTime(WifiMode mode) const
Estimate the TxTime of a packet with a given mode.
Time CalculateTimeUnicastPacket(Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries)
Estimate the time to transmit the given packet with the given number of retries.
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 InitSampleTable(MinstrelWifiRemoteStation *station)
Initialize Sample Table.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Time m_updateStats
how frequent do we calculate the stats
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Update packet counters.
void UpdateRate(MinstrelWifiRemoteStation *station)
Update the rate.
void PrintTable(MinstrelWifiRemoteStation *station)
Print Minstrel Table.
uint16_t GetNextSample(MinstrelWifiRemoteStation *station)
Get the next sample from Sample Table.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
std::list< Ptr< WifiMpdu > > DoGetMpdusToDropOnTxFailure(WifiRemoteStation *station, Ptr< WifiPsdu > psdu) override
Find the MPDUs to drop (possibly based on their frame retry count) in the given PSDU,...
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 m_ewmaLevel
exponential weighted moving average
void SetupPhy(const Ptr< WifiPhy > phy) override
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
uint32_t CountRetries(MinstrelWifiRemoteStation *station)
Get the number of retries.
void UpdateRetry(MinstrelWifiRemoteStation *station)
Update the number of retries and reset accordingly.
WifiTxVector GetDataTxVector(MinstrelWifiRemoteStation *station)
Get data transmit vector.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
represent a single transmission mode
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Time GetSlot() const
Return the slot duration for this PHY.
Time GetSifs() const
Return the Short Interframe Space (SIFS) for this PHY.
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Time GetAckTxTime() const
Return the estimated Ack TX time for this PHY.
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.
MHz_u GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled on the link this manager is associated wi...
Ptr< WifiMac > GetMac() const
Return the WifiMac.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
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.
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#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< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
U * PeekPointer(const Ptr< U > &p)
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
std::vector< std::vector< uint8_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint8_t.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for Minstrel Wifi manager.
A struct to contain all information related to a data rate.
uint32_t ewmaProb
EWMA calculation ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100.
uint32_t adjustedRetryCount
adjust the retry limit for this rate
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
uint32_t prob
(# packets success)/(# total packets)
Time perfectTxTime
Perfect transmission time calculation, or frame calculation Given a bit rate and a packet length n by...
uint64_t successHist
Aggregate of all transmission successes.
uint32_t throughput
throughput of a rate in bps
uint32_t prevNumRateAttempt
Number of transmission attempts with previous rate.
uint64_t attemptHist
Aggregate of all transmission attempts.
hold per-remote-station state.