A Discrete-Event Network Simulator
API
minstrel-ht-wifi-manager.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 Duy Nguyen
4  * Copyright (c) 2015 Ghada Badawy
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  *Authors: Duy Nguyen <duy@soe.ucsc.edu>
20  * Ghada Badawy <gbadawy@gmail.com>
21  * Matias Richart <mrichart@fing.edu.uy>
22  *
23  * MinstrelHt is a rate adaptation algorithm for high-throughput (HT) 802.11
24  */
25 
26 #ifndef MINSTREL_HT_WIFI_MANAGER_H
27 #define MINSTREL_HT_WIFI_MANAGER_H
28 
29 #include "ns3/wifi-remote-station-manager.h"
30 #include "minstrel-wifi-manager.h"
31 #include "ns3/wifi-mpdu-type.h"
32 
33 namespace ns3 {
34 
38 typedef std::map<WifiMode, Time> TxTime;
39 
46 struct McsGroup
47 {
48  uint8_t streams;
49  uint8_t sgi;
50  uint16_t chWidth;
51  bool isVht;
52  bool isSupported;
53  // To accurately account for TX times, we separate the TX time of the first
54  // MPDU in an A-MPDU from the rest of the MPDUs.
57 };
58 
63 typedef std::vector<McsGroup> MinstrelMcsGroups;
64 
69 struct HtRateInfo
70 {
76  bool supported;
77  uint8_t mcsIndex;
78  uint32_t retryCount;
79  uint32_t adjustedRetryCount;
80  uint32_t numRateAttempt;
81  uint32_t numRateSuccess;
82  double prob;
83  bool retryUpdated;
84 
89  double ewmaProb;
90  double ewmsdProb;
91  uint32_t prevNumRateAttempt;
92  uint32_t prevNumRateSuccess;
93  uint32_t numSamplesSkipped;
94  uint64_t successHist;
95  uint64_t attemptHist;
96  double throughput;
97 };
98 
103 typedef std::vector<HtRateInfo> HtMinstrelRate;
104 
108 struct GroupInfo
109 {
113  uint8_t m_col;
114  uint8_t m_index;
115  bool m_supported;
116  uint16_t m_maxTpRate;
117  uint16_t m_maxTpRate2;
118  uint16_t m_maxProbRate;
120 };
121 
126 typedef std::vector<struct GroupInfo> McsGroupData;
127 
132 static const uint8_t MAX_SUPPORTED_STREAMS = 4;
133 static const uint8_t MAX_HT_STREAM_GROUPS = 4;
134 static const uint8_t MAX_VHT_STREAM_GROUPS = 8;
135 static const uint8_t MAX_HT_GROUP_RATES = 8;
136 static const uint8_t MAX_VHT_GROUP_RATES = 10;
137 static const uint8_t MAX_HT_WIDTH = 40;
138 static const uint8_t MAX_VHT_WIDTH = 160;
139 
189 {
190 public:
195  static TypeId GetTypeId (void);
197  virtual ~MinstrelHtWifiManager ();
198 
199  // Inherited from WifiRemoteStationManager
200  void SetupPhy (const Ptr<WifiPhy> phy) override;
201  void SetupMac (const Ptr<WifiMac> mac) override;
202  int64_t AssignStreams (int64_t stream) override;
203 
210  typedef void (*RateChangeTracedCallback)(const uint64_t rate, const Mac48Address remoteAddress);
211 
212 
213 private:
214  // Overridden from base class.
215  void DoInitialize (void) override;
216  WifiRemoteStation * DoCreateStation (void) const override;
217  void DoReportRxOk (WifiRemoteStation *station,
218  double rxSnr, WifiMode txMode) override;
219  void DoReportRtsFailed (WifiRemoteStation *station) override;
220  void DoReportDataFailed (WifiRemoteStation *station) override;
221  void DoReportRtsOk (WifiRemoteStation *station,
222  double ctsSnr, WifiMode ctsMode, double rtsSnr) override;
223  void DoReportDataOk (WifiRemoteStation *station, double ackSnr, WifiMode ackMode,
224  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override;
225  void DoReportFinalRtsFailed (WifiRemoteStation *station) override;
226  void DoReportFinalDataFailed (WifiRemoteStation *station) override;
228  WifiTxVector DoGetRtsTxVector (WifiRemoteStation *station) override;
229  void DoReportAmpduTxStatus (WifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus,
230  double rxSnr, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override;
231  bool DoNeedRetransmission (WifiRemoteStation *st, Ptr<const Packet> packet, bool normally) override;
232 
242  bool IsValidMcs (Ptr<WifiPhy> phy, uint8_t streams, uint16_t chWidth, WifiMode mode);
243 
255  Time CalculateMpduTxDuration (Ptr<WifiPhy> phy, uint8_t streams, uint8_t sgi,
256  uint16_t chWidth, WifiMode mode, MpduType mpduType);
257 
265  Time GetMpduTxTime (uint8_t groupId, WifiMode mode) const;
266 
274  void AddMpduTxTime (uint8_t groupId, WifiMode mode, Time t);
275 
283  Time GetFirstMpduTxTime (uint8_t groupId, WifiMode mode) const;
284 
292  void AddFirstMpduTxTime (uint8_t groupId, WifiMode mode, Time t);
293 
299 
307  void UpdatePacketCounters (MinstrelHtWifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus);
308 
315  uint16_t GetNextSample (MinstrelHtWifiRemoteStation *station);
316 
323 
330  uint16_t FindRate (MinstrelHtWifiRemoteStation *station);
331 
338 
344  void RateInit (MinstrelHtWifiRemoteStation *station);
345 
355  double CalculateThroughput (MinstrelHtWifiRemoteStation *station, uint8_t groupId, uint8_t rateId, double ewmaProb);
356 
363  void SetBestStationThRates (MinstrelHtWifiRemoteStation *station, uint16_t index);
364 
371  void SetBestProbabilityRate (MinstrelHtWifiRemoteStation *station, uint16_t index);
372 
379  void CalculateRetransmits (MinstrelHtWifiRemoteStation *station, uint16_t index);
380 
388  void CalculateRetransmits (MinstrelHtWifiRemoteStation *station, uint8_t groupId, uint8_t rateId);
389 
411  Time CalculateTimeUnicastPacket (Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries);
412 
422  double CalculateEwmsd (double oldEwmsd, double currentProb, double ewmaProb, double weight);
423 
430 
437 
443  void PrintTable (MinstrelHtWifiRemoteStation *station);
444 
452  void StatsDump (MinstrelHtWifiRemoteStation *station, uint8_t groupId, std::ofstream &of);
453 
459  void CheckInit (MinstrelHtWifiRemoteStation *station);
460 
467  uint32_t CountRetries (MinstrelHtWifiRemoteStation * station);
468 
474  void UpdateRate (MinstrelHtWifiRemoteStation *station);
475 
493  uint8_t GetRateId (uint16_t index);
494 
501  uint8_t GetGroupId (uint16_t index);
502 
510  uint16_t GetIndex (uint8_t groupId, uint8_t rateId);
511 
520  uint8_t GetHtGroupId (uint8_t txstreams, uint8_t sgi, uint16_t chWidth);
521 
530  uint8_t GetVhtGroupId (uint8_t txstreams, uint8_t sgi, uint16_t chWidth);
531 
538  uint16_t GetLowestIndex (MinstrelHtWifiRemoteStation *station);
539 
547  uint16_t GetLowestIndex (MinstrelHtWifiRemoteStation *station, uint8_t groupId);
548 
553  WifiModeList GetVhtDeviceMcsList (void) const;
554 
559  WifiModeList GetHtDeviceMcsList (void) const;
560 
564  uint8_t m_ewmaLevel;
565  uint8_t m_nSampleCol;
566  uint32_t m_frameLength;
567  uint8_t m_numGroups;
568  uint8_t m_numRates;
571 
573 
575 
577 
579 };
580 
581 } // namespace ns3
582 
583 #endif /* MINSTREL_HT_WIFI_MANAGER_H */
uint16_t m_maxProbRate
The highest success probability rate of this group in bps.
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...
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...
uint8_t m_nSampleCol
Number of sample columns.
double throughput
Throughput of this rate (in packets per second).
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool m_supported
If the rates of this group are supported by the station.
Time GetMpduTxTime(uint8_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
A struct to contain information of a group.
WifiModeList GetVhtDeviceMcsList(void) const
Returns a list of only the VHT MCS supported by the device.
bool DoNeedRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally) override
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static const uint8_t MAX_SUPPORTED_STREAMS
Constants for maximum values.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
void PrintTable(MinstrelHtWifiRemoteStation *station)
Printing Minstrel Table.
uint16_t GetLowestIndex(MinstrelHtWifiRemoteStation *station)
Returns the lowest global index of the rates supported by the station.
uint8_t m_col
MCS rates are divided into groups based on the number of streams and flags that they use...
void SetBestProbabilityRate(MinstrelHtWifiRemoteStation *station, uint16_t index)
Set index rate as maxProbRate if it is better than current value.
MinstrelHtWifiRemoteStation structure.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void CalculateRetransmits(MinstrelHtWifiRemoteStation *station, uint16_t index)
Calculate the number of retransmissions to set for the index rate.
void DoInitialize(void) override
Initialize() implementation.
static const uint8_t MAX_VHT_STREAM_GROUPS
Maximal number of groups per stream in VHT (4 possible channel widths and 2 possible SGI configuratio...
bool isSupported
is supported?
double prob
Current probability within last time interval.
Time m_legacyUpdateStats
How frequent do we calculate the stats for legacy MinstrelWifiManager.
HtMinstrelRate m_ratesTable
Information about rates of this group.
uint8_t sgi
short guard interval (0 or 1)
uint16_t FindRate(MinstrelHtWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
uint32_t m_frameLength
Frame length used for calculate modes TxTime in bytes.
MinstrelMcsGroups m_minstrelGroups
Global array for groups information.
Time CalculateTimeUnicastPacket(Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries)
Estimate the time to transmit the given packet with the given number of retries.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
TxTime ratesFirstMpduTxTimeTable
rates MPDU transmit time table
WifiRemoteStation * DoCreateStation(void) const override
uint8_t GetRateId(uint16_t index)
For managing rates from different groups, a global index for all rates in all groups is used...
bool m_printStats
If statistics table should be printed.
MpduType
The type of an MPDU.
uint32_t adjustedRetryCount
Adjust the retry limit for this rate.
uint16_t GetIndex(uint8_t groupId, uint8_t rateId)
Returns the global index corresponding to the groupId and rateId.
uint32_t numRateAttempt
Number of transmission attempts so far.
uint8_t m_index
Sample table index.
uint8_t m_lookAroundRate
The % to try other rates than our current rate.
phy
Definition: third.py:93
uint8_t m_ewmaLevel
Exponential weighted moving average level (or coefficient).
void SetBestStationThRates(MinstrelHtWifiRemoteStation *station, uint16_t index)
Set index rate as maxTpRate or maxTp2Rate if is better than current values.
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...
Time GetFirstMpduTxTime(uint8_t groupId, WifiMode mode) const
Obtain the TxTime saved in the group information.
TxTime ratesTxTimeTable
rates transmit time table
uint16_t chWidth
channel width (MHz)
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
static const uint8_t MAX_VHT_GROUP_RATES
Number of rates (or MCS) per VHT group.
static const uint8_t MAX_HT_WIDTH
Maximal channel width in MHz.
mac
Definition: third.py:99
uint8_t streams
streams
static const uint8_t MAX_HT_STREAM_GROUPS
Maximal number of groups per stream in HT (2 possible channel widths and 2 possible SGI configuration...
uint8_t mcsIndex
The index in the operationalMcsSet of the WifiRemoteStationManager.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
hold a list of per-remote-station state.
bool m_useVhtOnly
If only VHT MCS should be used, instead of HT and VHT.
std::vector< struct GroupInfo > McsGroupData
Data structure for a table of groups.
static TypeId GetTypeId(void)
Get the type ID.
static const uint8_t MAX_VHT_WIDTH
Maximal channel width in MHz.
bool retryUpdated
If number of retries was updated already.
uint16_t GetNextSample(MinstrelHtWifiRemoteStation *station)
Getting the next sample from Sample Table.
uint16_t m_maxTpRate2
The second max throughput rate of this group in bps.
double ewmaProb
Exponential weighted moving average of probability.
Time perfectTxTime
Perfect transmission time calculation, or frame calculation.
bool IsValidMcs(Ptr< WifiPhy > phy, uint8_t streams, uint16_t chWidth, WifiMode mode)
Check the validity of a combination of number of streams, chWidth and mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t m_numRates
Number of rates per group Minstrel should consider.
void InitSampleTable(MinstrelHtWifiRemoteStation *station)
Initialize Sample Table.
double CalculateThroughput(MinstrelHtWifiRemoteStation *station, uint8_t groupId, uint8_t rateId, double ewmaProb)
Return the average throughput of the MCS defined by groupId and rateId.
void UpdateRetry(MinstrelHtWifiRemoteStation *station)
Update the number of retries and reset accordingly.
bool supported
If the rate is supported.
uint8_t m_numGroups
Number of groups Minstrel should consider.
Time m_updateStats
How frequent do we calculate the stats.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
an EUI-48 address
Definition: mac48-address.h:43
static const uint8_t MAX_HT_GROUP_RATES
Number of rates (or MCS) per HT group.
void UpdateStats(MinstrelHtWifiRemoteStation *station)
Update the Minstrel Table.
uint32_t prevNumRateAttempt
Number of transmission attempts with previous rate.
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes...
Definition: wifi-mode.h:254
uint16_t m_maxTpRate
The max throughput rate of this group in bps.
std::vector< HtRateInfo > HtMinstrelRate
Data structure for a Minstrel Rate table.
void RateInit(MinstrelHtWifiRemoteStation *station)
Initialize Minstrel Table.
Implementation of Minstrel HT Rate Control AlgorithmMinstrel-HT is a rate adaptation mechanism for th...
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model...
Data structure to contain the information that defines a group.
uint32_t retryCount
Retry limit.
double ewmsdProb
Exponential weighted moving standard deviation of probability.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void StatsDump(MinstrelHtWifiRemoteStation *station, uint8_t groupId, std::ofstream &of)
Print group statistics.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
void UpdatePacketCounters(MinstrelHtWifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus)
Update the number of sample count variables.
std::map< WifiMode, Time > TxTime
Data structure to save transmission time calculations per rate.
uint8_t GetVhtGroupId(uint8_t txstreams, uint8_t sgi, uint16_t chWidth)
Returns the groupId of a VHT MCS with the given number of streams, if using SGI and the channel width...
double CalculateEwmsd(double oldEwmsd, double currentProb, double ewmaProb, double weight)
Perform EWMSD (Exponentially Weighted Moving Standard Deviation) calculation.
void(* RateChangeTracedCallback)(const uint64_t rate, const Mac48Address remoteAddress)
TracedCallback signature for rate change events.
uint32_t numRateSuccess
Number of successful frames transmitted so far.
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.
std::vector< McsGroup > MinstrelMcsGroups
Data structure for a table of group definitions.
void AddMpduTxTime(uint8_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
A struct to contain all statistics information related to a data rate.
void SetNextSample(MinstrelHtWifiRemoteStation *station)
Set the next sample from Sample Table.
void PrintSampleTable(MinstrelHtWifiRemoteStation *station)
Printing Sample Table.
WifiModeList GetHtDeviceMcsList(void) const
Returns a list of only the HT MCS supported by the device.
Ptr< MinstrelWifiManager > m_legacyManager
Pointer to an instance of MinstrelWifiManager.
uint32_t numSamplesSkipped
Number of times this rate statistics were not updated because no attempts have been made...
uint64_t successHist
Aggregate of all transmission successes.
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
uint64_t attemptHist
Aggregate of all transmission attempts.
uint8_t GetHtGroupId(uint8_t txstreams, uint8_t sgi, uint16_t chWidth)
Returns the groupId of a HT MCS with the given number of streams, if using SGI and the channel width ...
uint8_t GetGroupId(uint16_t index)
Return the groupId from the global index.
Time CalculateMpduTxDuration(Ptr< WifiPhy > phy, uint8_t streams, uint8_t sgi, uint16_t chWidth, WifiMode mode, MpduType mpduType)
Estimates the TxTime of a frame with a given mode and group (stream, guard interval and channel width...
uint32_t CountRetries(MinstrelHtWifiRemoteStation *station)
Count retries.
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 UpdateRate(MinstrelHtWifiRemoteStation *station)
Update rate.
void AddFirstMpduTxTime(uint8_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
a unique identifier for an interface.
Definition: type-id.h:58
void CheckInit(MinstrelHtWifiRemoteStation *station)
Check for initializations.
hold per-remote-station state.