34 #include "ns3/packet.h"
35 #include "ns3/random-variable-stream.h"
36 #include "ns3/simulator.h"
37 #include "ns3/wifi-mac.h"
38 #include "ns3/wifi-phy.h"
42 #define Min(a, b) ((a < b) ? a : b)
55 TypeId(
"ns3::MinstrelWifiManager")
59 .AddAttribute(
"UpdateStatistics",
60 "The interval between updating statistics table",
64 .AddAttribute(
"LookAroundRate",
65 "The percentage to try other rates",
68 MakeUintegerChecker<uint8_t>())
73 MakeUintegerChecker<uint8_t>())
74 .AddAttribute(
"SampleColumn",
75 "The number of columns used for sampling",
78 MakeUintegerChecker<uint8_t>())
79 .AddAttribute(
"PacketLength",
80 "The packet length used for calculating mode TxTime",
83 MakeUintegerChecker<uint32_t>())
84 .AddAttribute(
"PrintStats",
85 "Print statistics table",
89 .AddAttribute(
"PrintSamples",
90 "Print samples table",
94 .AddTraceSource(
"Rate",
95 "Traced value for rate changes (b/s)",
97 "ns3::TracedValueCallback::Uint64");
118 for (
const auto& mode :
phy->GetModeList())
141 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HT rates");
145 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support VHT rates");
149 NS_FATAL_ERROR(
"WifiRemoteStationManager selected does not support HE rates");
185 station->m_index = 0;
186 station->m_maxTpRate = 0;
187 station->m_maxTpRate2 = 0;
188 station->m_maxProbRate = 0;
189 station->m_nModes = 0;
190 station->m_totalPacketsCount = 0;
191 station->m_samplePacketsCount = 0;
192 station->m_isSampling =
false;
193 station->m_sampleRate = 0;
194 station->m_sampleDeferred =
false;
195 station->m_shortRetry = 0;
196 station->m_longRetry = 0;
197 station->m_retry = 0;
198 station->m_txrate = 0;
199 station->m_initialized =
false;
258 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
267 NS_LOG_DEBUG(
" More retries left for the second maximum throughput rate.");
277 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
302 NS_LOG_DEBUG(
"Look around rate is slower than the maximum throughput rate.");
307 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
316 NS_LOG_DEBUG(
" More retries left for the sampling rate.");
326 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
343 NS_LOG_DEBUG(
"Look around rate is faster than the maximum throughput rate.");
348 NS_LOG_DEBUG(
" More retries left for the sampling rate.");
357 NS_LOG_DEBUG(
" More retries left for the maximum throughput rate.");
367 NS_LOG_DEBUG(
" More retries left for the maximum probability rate.");
389 if (channelWidth > 20 && channelWidth != 22)
422 if (channelWidth > 20 && channelWidth != 22)
490 uint8_t ratesSupported = station->
m_nModes;
491 if (
delta > ratesSupported * 2)
558 NS_LOG_DEBUG(
"The next look around rate is slower than the maximum throughput rate, "
559 "continue with the maximum throughput rate: "
568 NS_LOG_DEBUG(
"Continue using the maximum throughput rate: "
602 for (uint8_t i = 0; i < station->
m_nModes; i++)
698 uint8_t index_max_tp = 0;
699 uint8_t index_max_tp2 = 0;
703 "Finding the maximum throughput, second maximum throughput, and highest probability");
705 for (uint8_t i = 0; i < station->
m_nModes; i++)
711 if (max_tp < station->m_minstrelTable[i].
throughput)
720 for (uint8_t i = 0; i < station->
m_nModes; i++)
722 if ((i != index_max_tp) && (max_tp < station->m_minstrelTable[i].
throughput))
729 uint32_t max_prob = 0;
730 uint8_t index_max_prob = 0;
731 for (uint8_t i = 0; i < station->
m_nModes; i++)
751 if (index_max_tp > station->
m_txrate)
757 <<
")\tsecond max throughput=" << +index_max_tp2 <<
"("
759 <<
")\tmax prob=" << +index_max_prob <<
"("
783 NS_LOG_DEBUG(
"DoReportRtsFailed m_txrate=" << station->m_txrate);
784 station->m_shortRetry++;
809 NS_LOG_DEBUG(
"DoReportDataFailed " << station <<
"\t rate " << station->m_txrate
810 <<
"\tlongRetry \t" << station->m_longRetry);
812 if (!station->m_initialized)
825 uint16_t dataChannelWidth,
828 NS_LOG_FUNCTION(
this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
832 if (!station->m_initialized)
839 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
840 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
841 <<
" (before update).");
843 station->m_minstrelTable[station->m_txrate].numRateSuccess++;
844 station->m_minstrelTable[station->m_txrate].numRateAttempt++;
850 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
851 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
852 <<
" (after update).");
857 if (station->m_nModes >= 1)
859 station->m_txrate =
FindRate(station);
861 NS_LOG_DEBUG(
"Next rate to use TxRate = " << station->m_txrate);
871 if (!station->m_initialized)
878 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
879 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
880 <<
" (before update).");
889 <<
", attempt = " << station->m_minstrelTable[station->m_txrate].numRateAttempt
890 <<
", success = " << station->m_minstrelTable[station->m_txrate].numRateSuccess
891 <<
" (after update).");
893 if (station->m_nModes >= 1)
895 station->m_txrate =
FindRate(station);
897 NS_LOG_DEBUG(
"Next rate to use TxRate = " << station->m_txrate);
963 if (!station->m_initialized)
970 << station->m_longRetry <<
" Max retries: " <<
CountRetries(station));
975 NS_LOG_DEBUG(
"Re-transmit. Retries: " << station->m_longRetry
1007 for (uint8_t i = 0; i < station->
m_nModes; i++)
1029 for (uint32_t retries = 2; retries < 11; retries++)
1032 totalTxTimeWithGivenRetries =
1034 NS_LOG_DEBUG(
" totalTxTimeWithGivenRetries = " << totalTxTimeWithGivenRetries);
1049 uint32_t shortRetries,
1050 uint32_t longRetries)
1052 NS_LOG_FUNCTION(
this << dataTransmissionTime << shortRetries << longRetries);
1058 uint32_t cwMax = 1023;
1060 for (uint32_t retry = 0; retry < longRetries; retry++)
1069 cw =
std::min(cwMax, (cw + 1) * 2);
1082 uint8_t numSampleRates = station->
m_nModes;
1087 for (uint8_t i = 0; i < numSampleRates; i++)
1095 newIndex = (i + uv) % numSampleRates;
1100 newIndex = (newIndex + 1) % station->
m_nModes;
1110 uint8_t numSampleRates = station->
m_nModes;
1111 std::stringstream table;
1112 for (uint8_t i = 0; i < numSampleRates; i++)
1128 std::ostringstream tmp;
1130 station->
m_statsFile.open(tmp.str(), std::ios::out);
1134 <<
"best _______________rate________________ ________statistics________ "
1135 "________last_______ ______sum-of________\n"
1136 <<
"rate [ name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] "
1137 "[prob.|retry|suc|att] [#success | #attempts]\n";
1143 for (uint8_t i = 0; i < station->
m_nModes; i++)
1155 if (i == maxTpRate2)
1163 if (i == maxProbRate)
1174 << std::setw(2) << i <<
" " << std::setw(4)
1176 <<
" ----- " << std::setw(8) << tmpTh <<
" " << std::setw(3)
1177 << rate.
ewmaProb / 180 << std::setw(3) <<
" --- "
1178 << std::setw(3) << rate.
prob / 180 <<
" " << std::setw(1)
1182 <<
" " << std::setw(9) << rate.
attemptHist <<
"\n";
1184 station->
m_statsFile <<
"\nTotal packet count: ideal "
Implementation of Minstrel Rate Control Algorithm.
WifiRemoteStation * DoCreateStation() const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
~MinstrelWifiManager() override
uint8_t m_lookAroundRate
the % to try other rates than our current rate
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...
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.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Time m_updateStats
how frequent do we calculate the stats
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally) override
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Update packet counters.
void UpdateRate(MinstrelWifiRemoteStation *station)
Update the rate.
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 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.
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.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
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.
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(uint16_t channelWidth, uint16_t 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.
Time GetAckTxTime() const
Return the estimated Ack TX time for this PHY.
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
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.
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.
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.
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,...
#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.
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()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
std::vector< std::vector< uint8_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint8_t.
hold per-remote-station state for Minstrel Wifi manager.
uint16_t m_maxTpRate2
second highest throughput rate in bps
Time m_nextStatsUpdate
10 times every second
bool m_initialized
for initializing tables
uint16_t m_sampleRate
current sample rate in bps
uint8_t m_index
vector index
int m_numSamplesDeferred
number samples deferred
uint16_t m_txrate
current transmit rate in bps
int m_totalPacketsCount
total number of packets as of now
bool m_isSampling
a flag to indicate we are currently sampling
MinstrelRate m_minstrelTable
minstrel table
uint32_t m_shortRetry
short retries such as control packets
uint32_t m_retry
total retries short + long
uint16_t m_maxTpRate
the current throughput rate in bps
bool m_sampleDeferred
a flag to indicate sample rate is on the second stage
uint8_t m_nModes
number of modes supported
SampleRate m_sampleTable
sample table
int m_samplePacketsCount
how many packets we have sample so far
std::ofstream m_statsFile
stats file
uint8_t m_col
To keep track of the current position in the our random sample table going row by row from 1st column...
uint32_t m_longRetry
long retries such as data packets
uint16_t m_maxProbRate
rate with highest probability of success in bps
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.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.