34 #include "ns3/simulator.h"
36 #include "ns3/uinteger.h"
37 #include "ns3/double.h"
38 #include "ns3/boolean.h"
39 #include "ns3/wifi-mac.h"
40 #include "ns3/assert.h"
44 #define Min(a,b) ((a < b) ? a : b)
57 .SetGroupName (
"Wifi")
59 .AddAttribute (
"UpdateStatistics",
60 "The interval between updating statistics table ",
64 .AddAttribute (
"LookAroundRate",
65 "the percentage to try other rates",
68 MakeDoubleChecker<double> ())
69 .AddAttribute (
"EWMA",
73 MakeDoubleChecker<double> ())
74 .AddAttribute (
"SampleColumn",
75 "The number of columns used for sampling",
78 MakeUintegerChecker <uint32_t> ())
79 .AddAttribute (
"PacketLength",
80 "The packet length used for calculating mode TxTime",
83 MakeUintegerChecker <uint32_t> ())
84 .AddAttribute (
"PrintStats",
85 "Print statistics table",
109 for (uint32_t i = 0; i < nModes; i++)
140 if (mode == i->second)
198 std::ostringstream tmp;
200 station->
m_statsFile.open (tmp.str ().c_str (), std::ios::out);
235 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
243 NS_LOG_DEBUG (
" More retries left for the second maximum throughput rate.");
252 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
273 NS_LOG_DEBUG (
"Look around rate is slower than the maximum throughput rate.");
277 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
285 NS_LOG_DEBUG (
" More retries left for the sampling rate.");
294 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
310 NS_LOG_DEBUG (
"Look around rate is faster than the maximum throughput rate.");
314 NS_LOG_DEBUG (
" More retries left for the sampling rate.");
322 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
331 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
352 if (channelWidth > 20 && channelWidth != 22)
373 if (channelWidth > 20 && channelWidth != 22)
430 int ratesSupported = station->
m_nModes;
431 if (delta > ratesSupported * 2)
533 for (uint32_t i = 0; i < station->
m_nModes; i++)
623 uint32_t max_tp = 0, index_max_tp = 0, index_max_tp2 = 0;
626 NS_LOG_DEBUG (
"Finding the maximum throughput, second maximum throughput, and highest probability");
628 for (uint32_t i = 0; i < station->
m_nModes; i++)
634 if (max_tp < station->m_minstrelTable[i].throughput)
643 for (uint32_t i = 0; i < station->
m_nModes; i++)
645 if ((i != index_max_tp) && (max_tp < station->m_minstrelTable[i].throughput))
652 uint32_t max_prob = 0, index_max_prob = 0;
653 for (uint32_t i = 0; i < station->
m_nModes; i++)
671 if (index_max_tp > station->
m_txrate)
677 ")\tsecond max throughput=" << index_max_tp2 <<
"(" <<
GetSupported (station, index_max_tp2) <<
678 ")\tmax prob=" << index_max_prob <<
"(" <<
GetSupported (station, index_max_prob) <<
")");
733 double ackSnr,
WifiMode ackMode,
double dataSnr)
895 for (uint32_t i = 0; i < station->
m_nModes; i++)
917 for (uint32_t retries = 2; retries < 11; retries++)
921 NS_LOG_DEBUG (
" totalTxTimeWithGivenRetries = " << totalTxTimeWithGivenRetries);
937 NS_LOG_FUNCTION (
this << dataTransmissionTime << shortRetries << longRetries);
941 Time tt = dataTransmissionTime +
GetMac ()->GetAckTimeout ();
943 uint32_t cwMax = 1023;
945 for (uint32_t retry = 0; retry < longRetries; retry++)
948 tt += dataTransmissionTime +
GetMac ()->GetAckTimeout ();
954 cw =
std::min (cwMax, (cw + 1) * 2);
968 uint32_t numSampleRates = station->
m_nModes;
973 for (uint32_t i = 0; i < numSampleRates; i++ )
980 newIndex = (i + uv) % numSampleRates;
985 newIndex = (newIndex + 1) % station->
m_nModes;
997 uint32_t numSampleRates = station->
m_nModes;
998 std::stringstream table;
999 for (uint32_t i = 0; i < numSampleRates; i++)
1016 station->
m_statsFile <<
"best _______________rate________________ ________statistics________ ________last_______ ______sum-of________\n" <<
1017 "rate [ name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] [prob.|retry|suc|att] [#success | #attempts]\n";
1023 for (uint32_t i = 0; i < station->
m_nModes; i++)
1035 if (i == maxTpRate2)
1043 if (i == maxProbRate)
1055 std::setw (2) << i <<
" " <<
1057 std::setw (8) <<
" ----- " <<
1058 std::setw (8) << tmpTh <<
" " <<
1059 std::setw (3) << rate.
ewmaProb / 180 <<
1060 std::setw (3) <<
" --- " <<
1061 std::setw (3) << rate.
prob / 180 <<
" " <<
1081 NS_FATAL_ERROR (
"WifiRemoteStationManager selected does not support HT rates");
1091 NS_FATAL_ERROR (
"WifiRemoteStationManager selected does not support VHT rates");
void CheckInit(MinstrelWifiRemoteStation *station)
check for initializations
void PrintTable(MinstrelWifiRemoteStation *station)
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
virtual uint32_t GetFrequency(void) const =0
virtual void SetupMac(Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
Simulation virtual time values and global simulation resolution.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
bool m_printStats
If statistics table should be printed.
AttributeValue implementation for Boolean.
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.
Time perfectTxTime
Perfect transmission time calculation, or frame calculation Given a bit rate and a packet length n by...
Implementation of Minstrel Rate Control AlgorithmMinstrel is a rate control algorithm implemented in ...
virtual uint32_t GetNModes(void) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold per-remote-station state for Minstrel Wifi manager.
Time m_updateStats
how frequent do we calculate the stats (1/10 seconds)
void UpdateStats(MinstrelWifiRemoteStation *station)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t m_sampleRate
current sample rate
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint32_t GetNextSample(MinstrelWifiRemoteStation *station)
Mac48Address m_address
Mac48Address of the remote station.
virtual bool DoNeedDataRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint32_t m_txrate
current transmit rate
MinstrelRate m_minstrelTable
minstrel table
std::ofstream m_statsFile
bool m_sampleDeferred
a flag to indicate sample rate is on the second stage
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
uint32_t FindRate(MinstrelWifiRemoteStation *station)
uint32_t m_pktLen
packet length used for calculate mode TxTime
WifiRemoteStationState * m_state
Remote station state.
uint32_t adjustedRetryCount
adjust the retry limit for this rate
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_col
To keep track of the current position in the our random sample table going row by row from 1st column...
A struct to contain all information related to a data rate.
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
bool m_isSampling
a flag to indicate we are currently sampling
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
AttributeValue implementation for Time.
SampleRate m_sampleTable
sample table
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
Hold an unsigned integer type.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
void PrintSampleTable(MinstrelWifiRemoteStation *station)
uint32_t prevNumRateAttempt
Number of transmission attempts with previous rate.
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
uint64_t attemptHist
Aggregate of all transmission attempts.
double m_ewmaLevel
exponential weighted moving average
uint64_t successHist
Aggregate of all transmission successes.
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, double frequency)
virtual WifiRemoteStation * DoCreateStation(void) const
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold a list of per-remote-station state.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t m_longRetry
long retries such as data packets
bool m_initialized
for initializing tables
uint32_t ewmaProb
EWMA calculation ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100.
TxTime m_calcTxTime
to hold all the calculated TxTime for all modes
virtual bool IsLowLatency(void) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void UpdateRate(MinstrelWifiRemoteStation *station)
Retry Chain table is implemented here.
uint32_t m_maxTpRate2
second highest throughput rate
WifiTxVector GetDataTxVector(MinstrelWifiRemoteStation *station)
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
uint32_t throughput
throughput of a rate
static Time Now(void)
Return the current simulation virtual time.
uint32_t m_retry
total retries short + long
int m_totalPacketsCount
total number of packets as of now
virtual void SetupMac(Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
Ptr< UniformRandomVariable > m_uniformRandomVariable
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void UpdateRetry(MinstrelWifiRemoteStation *station)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double m_lookAroundRate
the % to try other rates than our current rate
int m_samplePacketsCount
how many packets we have sample so far
static TypeId GetTypeId(void)
uint8_t GetDefaultTxPowerLevel(void) const
void InitSampleTable(MinstrelWifiRemoteStation *station)
uint32_t m_maxProbRate
rate with highest prob of success
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_nModes
number of modes supported
WifiTxVector GetRtsTxVector(MinstrelWifiRemoteStation *station)
virtual void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint32_t m_maxTpRate
the current throughput rate
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint32_t CountRetries(MinstrelWifiRemoteStation *station)
Time GetCalcTxTime(WifiMode mode) const
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
std::vector< struct RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
uint32_t m_sampleCol
number of sample columns
virtual ~MinstrelWifiManager()
uint32_t m_shortRetry
short retries such as control packts
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
a unique identifier for an interface.
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 RateInit(MinstrelWifiRemoteStation *station)
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::vector< std::vector< uint32_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint32_t.
hold per-remote-station state.
uint32_t prob
(# pkts success )/(# total pkts)
Ptr< WifiMac > GetMac(void) const
Return the WifiMac.
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Time m_nextStatsUpdate
10 times every second