33 #include "ns3/packet.h" 34 #include "ns3/random-variable-stream.h" 35 #include "ns3/simulator.h" 41 #define Min(a,b) ((a < b) ? a : b) 54 .SetGroupName (
"Wifi")
56 .AddAttribute (
"UpdateStatistics",
57 "The interval between updating statistics table ",
61 .AddAttribute (
"LookAroundRate",
62 "The percentage to try other rates",
65 MakeUintegerChecker<uint8_t> ())
66 .AddAttribute (
"EWMA",
70 MakeUintegerChecker<uint8_t> ())
71 .AddAttribute (
"SampleColumn",
72 "The number of columns used for sampling",
75 MakeUintegerChecker <uint8_t> ())
76 .AddAttribute (
"PacketLength",
77 "The packet length used for calculating mode TxTime",
80 MakeUintegerChecker <uint32_t> ())
81 .AddAttribute (
"PrintStats",
82 "Print statistics table",
86 .AddAttribute (
"PrintSamples",
87 "Print samples table",
91 .AddTraceSource (
"Rate",
92 "Traced value for rate changes (b/s)",
94 "ns3::TracedValueCallback::Uint64")
116 uint8_t nModes =
phy->GetNModes ();
117 for (uint8_t i = 0; i < nModes; i++)
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");
253 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
261 NS_LOG_DEBUG (
" More retries left for the second maximum throughput rate.");
270 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
291 NS_LOG_DEBUG (
"Look around rate is slower than the maximum throughput rate.");
295 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
303 NS_LOG_DEBUG (
" More retries left for the sampling rate.");
312 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
328 NS_LOG_DEBUG (
"Look around rate is faster than the maximum throughput rate.");
332 NS_LOG_DEBUG (
" More retries left for the sampling rate.");
340 NS_LOG_DEBUG (
" More retries left for the maximum throughput rate.");
349 NS_LOG_DEBUG (
" More retries left for the maximum probability rate.");
370 if (channelWidth > 20 && channelWidth != 22)
384 return WifiTxVector (mode,
GetDefaultTxPowerLevel (),
GetPreambleForTransmission (mode.
GetModulationClass (),
GetShortPreambleEnabled (),
UseGreenfieldForDestination (
GetAddress (station))), 800, 1, 1, 0, channelWidth,
GetAggregation (station),
false);
393 if (channelWidth > 20 && channelWidth != 22)
407 rtsTxVector =
WifiTxVector (mode,
GetDefaultTxPowerLevel (),
GetPreambleForTransmission (mode.
GetModulationClass (),
GetShortPreambleEnabled (),
UseGreenfieldForDestination (
GetAddress (station))), 800, 1, 1, 0, channelWidth,
GetAggregation (station),
false);
451 uint8_t ratesSupported = station->
m_nModes;
452 if (delta > ratesSupported * 2)
556 for (uint8_t i = 0; i < station->
m_nModes; i++)
646 uint8_t index_max_tp = 0, index_max_tp2 = 0;
649 NS_LOG_DEBUG (
"Finding the maximum throughput, second maximum throughput, and highest probability");
651 for (uint8_t i = 0; i < station->
m_nModes; i++)
657 if (max_tp < station->m_minstrelTable[i].throughput)
666 for (uint8_t i = 0; i < station->
m_nModes; i++)
668 if ((i != index_max_tp) && (max_tp < station->m_minstrelTable[i].throughput))
675 uint32_t max_prob = 0;
676 uint8_t index_max_prob = 0;
677 for (uint8_t i = 0; i < station->
m_nModes; i++)
695 if (index_max_tp > station->
m_txrate)
701 ")\tsecond max throughput=" << +index_max_tp2 <<
"(" <<
GetSupported (station, index_max_tp2) <<
702 ")\tmax prob=" << +index_max_prob <<
"(" <<
GetSupported (station, index_max_prob) <<
")");
717 NS_LOG_DEBUG (
"DoReportRxOk m_txrate=" << static_cast<MinstrelWifiRemoteStation*> (st)->m_txrate);
760 double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
762 NS_LOG_FUNCTION (
this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
919 for (uint8_t i = 0; i < station->
m_nModes; i++)
941 for (uint32_t retries = 2; retries < 11; retries++)
945 NS_LOG_DEBUG (
" totalTxTimeWithGivenRetries = " << totalTxTimeWithGivenRetries);
961 NS_LOG_FUNCTION (
this << dataTransmissionTime << shortRetries << longRetries);
967 uint32_t cwMax = 1023;
969 for (uint32_t retry = 0; retry < longRetries; retry++)
978 cw =
std::min (cwMax, (cw + 1) * 2);
991 uint8_t numSampleRates = station->
m_nModes;
996 for (uint8_t i = 0; i < numSampleRates; i++ )
1004 newIndex = (i + uv) % numSampleRates;
1009 newIndex = (newIndex + 1) % station->
m_nModes;
1019 uint8_t numSampleRates = station->
m_nModes;
1020 std::stringstream table;
1021 for (uint8_t i = 0; i < numSampleRates; i++)
1037 std::ostringstream tmp;
1039 station->
m_statsFile.open (tmp.str ().c_str (), std::ios::out);
1042 station->
m_statsFile <<
"best _______________rate________________ ________statistics________ ________last_______ ______sum-of________\n" <<
1043 "rate [ name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] [prob.|retry|suc|att] [#success | #attempts]\n";
1049 for (uint8_t i = 0; i < station->
m_nModes; i++)
1061 if (i == maxTpRate2)
1069 if (i == maxProbRate)
1081 std::setw (2) << i <<
" " <<
1083 std::setw (8) <<
" ----- " <<
1084 std::setw (8) << tmpTh <<
" " <<
1085 std::setw (3) << rate.
ewmaProb / 180 <<
1086 std::setw (3) <<
" --- " <<
1087 std::setw (3) << rate.
prob / 180 <<
" " <<
void CheckInit(MinstrelWifiRemoteStation *station)
Check for initializations.
void PrintTable(MinstrelWifiRemoteStation *station)
Print Minstrel Table.
uint16_t m_maxProbRate
rate with highest probability of success in bps
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
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...
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 "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool m_printStats
whether statistics table should be printed.
AttributeValue implementation for Boolean.
uint8_t m_lookAroundRate
the % to try other rates than our current rate
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint8_t m_index
vector index
#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...
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
This method is a pure virtual method that must be implemented by the sub-class.
Implementation of Minstrel Rate Control AlgorithmMinstrel is a rate control algorithm implemented in ...
uint16_t m_maxTpRate
the current throughput rate in bps
uint16_t m_txrate
current transmit rate in bps
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
uint16_t m_maxTpRate2
second highest throughput rate in bps
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)
Update the Minstrel Table every 1/10 seconds.
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint16_t m_sampleRate
current sample rate in bps
Mac48Address m_address
Mac48Address of the remote station.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
MinstrelRate m_minstrelTable
minstrel table
std::ofstream m_statsFile
stats file
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
bool m_sampleDeferred
a flag to indicate sample rate is on the second stage
std::vector< std::vector< uint8_t > > SampleRate
Data structure for a Sample Rate table A vector of a vector uint8_t.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint8_t m_nModes
number of modes supported
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 TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
A struct to contain all information related to a data rate.
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 m_isSampling
a flag to indicate we are currently sampling
int m_numSamplesDeferred
number samples deferred
AttributeValue implementation for Time.
SampleRate m_sampleTable
sample table
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 prevNumRateSuccess
Number of successful frames transmitted with previous rate.
Hold an unsigned integer type.
uint16_t GetNextSample(MinstrelWifiRemoteStation *station)
Get the next sample from Sample Table.
void PrintSampleTable(MinstrelWifiRemoteStation *station)
Print Sample Table.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
uint32_t prevNumRateAttempt
Number of transmission attempts with previous rate.
uint64_t attemptHist
Aggregate of all transmission attempts.
uint64_t successHist
Aggregate of all transmission successes.
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
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...
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.
WifiModulationClass GetModulationClass() const
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t m_longRetry
long retries such as data packets
uint16_t FindRate(MinstrelWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
bool m_initialized
for initializing tables
uint32_t ewmaProb
EWMA calculation ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
TxTime m_calcTxTime
to hold all the calculated TxTime for all modes
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void UpdateRate(MinstrelWifiRemoteStation *station)
Update the rate.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
WifiTxVector GetDataTxVector(MinstrelWifiRemoteStation *station)
Get data transmit vector.
bool UseGreenfieldForDestination(Mac48Address dest) const
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
Time GetAckTxTime(void) const
Return the estimated Ack TX time for this PHY.
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 in bps
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
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void UpdateRetry(MinstrelWifiRemoteStation *station)
Update the number of retries and reset accordingly.
int m_samplePacketsCount
how many packets we have sample so far
static TypeId GetTypeId(void)
Get the type ID.
void InitSampleTable(MinstrelWifiRemoteStation *station)
Initialize Sample Table.
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...
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
Time GetSifs(void) const
Return the Short Interframe Space (SIFS) for this PHY.
WifiTxVector GetRtsTxVector(MinstrelWifiRemoteStation *station)
Get RTS transmit vector.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
#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.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
uint32_t CountRetries(MinstrelWifiRemoteStation *station)
Get the number of retries.
Time GetSlot(void) const
Return the slot duration for this PHY.
uint8_t GetDefaultTxPowerLevel(void) const
void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DoInitialize(void)
Initialize() implementation.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
bool m_printSamples
whether samples table should be printed.
virtual ~MinstrelWifiManager()
uint32_t m_shortRetry
short retries such as control packets
WifiRemoteStation * DoCreateStation(void) const
uint8_t m_sampleCol
number of sample columns
Time GetCalcTxTime(WifiMode mode) const
Estimate the TxTime of a packet with a given mode.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
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.
uint8_t m_ewmaLevel
exponential weighted moving average
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)
Initialize Minstrel Table.
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
uint32_t prob
(# packets success)/(# total packets)
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Update packet counters.
Time m_nextStatsUpdate
10 times every second