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  *Author: 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 
30 #include "minstrel-wifi-manager.h"
31 #include "wifi-mode.h"
32 #include "ns3/nstime.h"
33 #include "ns3/random-variable-stream.h"
34 #include <vector>
35 #include <map>
36 #include <deque>
37 
38 namespace ns3 {
39 
44 typedef std::vector<std::pair<Time, WifiMode> > TxTime;
45 
52 struct McsGroup
53 {
54  uint8_t streams;
55  uint8_t sgi;
56  uint32_t chWidth;
57  bool isVht;
59 
60  // To accurately account for TX times, we separate the TX time of the first
61  // MPDU in an A-MPDU from the rest of the MPDUs.
64 };
65 
70 typedef std::vector<struct McsGroup> MinstrelMcsGroups;
71 
76 struct HtRateInfo
77 {
83 
84  bool supported;
85 
86  uint32_t mcsIndex;
87 
88  uint32_t retryCount;
89  uint32_t adjustedRetryCount;
90  uint32_t numRateAttempt;
91  uint32_t numRateSuccess;
92  double prob;
93 
94  bool retryUpdated;
95 
101  double ewmaProb;
102 
103  double ewmsdProb;
104 
107  uint32_t numSamplesSkipped;
108  uint64_t successHist;
109  uint64_t attemptHist;
110  double throughput;
111 };
112 
117 typedef std::vector<struct HtRateInfo> HtMinstrelRate;
118 
122 struct GroupInfo
123 {
127  uint8_t m_col;
128  uint8_t m_index;
129 
130  bool m_supported;
131 
132  uint32_t m_maxTpRate;
133  uint32_t m_maxTpRate2;
134  uint32_t m_maxProbRate;
135 
136  HtMinstrelRate m_ratesTable;
137 };
138 
143 typedef std::vector<struct GroupInfo> McsGroupData;
144 
149 typedef std::vector<std::vector<uint32_t> > HtSampleRate;
150 
155 static const uint8_t MAX_SUPPORTED_STREAMS = 4;
156 static const uint8_t MAX_HT_STREAM_GROUPS = 4;
157 static const uint8_t MAX_VHT_STREAM_GROUPS = 8;
158 static const uint8_t MAX_HT_GROUP_RATES = 8;
159 static const uint8_t MAX_VHT_GROUP_RATES = 10;
160 static const uint8_t MAX_HT_WIDTH = 40;
161 static const uint8_t MAX_VHT_WIDTH = 160;
162 
208 {
209 
210 public:
211  static TypeId GetTypeId (void);
213  virtual ~MinstrelHtWifiManager ();
214 
223  int64_t AssignStreams (int64_t stream);
224 
225  // Inherited from WifiRemoteStationManager
226  virtual void SetupPhy (Ptr<WifiPhy> phy);
227  virtual void SetupMac (Ptr<WifiMac> mac);
228 
235  typedef void (*RateChangeTracedCallback)(const uint64_t rate, const Mac48Address remoteAddress);
236 
237 private:
238  // Overriden from base class.
239  virtual void DoInitialize (void);
240  virtual WifiRemoteStation * DoCreateStation (void) const;
241  virtual void DoReportRxOk (WifiRemoteStation *station,
242  double rxSnr, WifiMode txMode);
243  virtual void DoReportRtsFailed (WifiRemoteStation *station);
244  virtual void DoReportDataFailed (WifiRemoteStation *station);
245  virtual void DoReportRtsOk (WifiRemoteStation *station,
246  double ctsSnr, WifiMode ctsMode, double rtsSnr);
247  virtual void DoReportDataOk (WifiRemoteStation *station,
248  double ackSnr, WifiMode ackMode, double dataSnr);
249  virtual void DoReportFinalRtsFailed (WifiRemoteStation *station);
250  virtual void DoReportFinalDataFailed (WifiRemoteStation *station);
253  virtual void DoReportAmpduTxStatus (WifiRemoteStation *station, uint32_t nSuccessfulMpdus, uint32_t nFailedMpdus, double rxSnr, double dataSnr);
254  virtual bool IsLowLatency (void) const;
255  virtual bool DoNeedDataRetransmission (WifiRemoteStation *st, Ptr<const Packet> packet, bool normally);
256  virtual void DoDisposeStation (WifiRemoteStation *station);
257 
259  bool IsValidMcs (Ptr<WifiPhy> phy, uint8_t streams, uint32_t chWidth, WifiMode mode);
260 
262  Time CalculateMpduTxDuration (Ptr<WifiPhy> phy, uint8_t streams, uint8_t sgi, uint32_t chWidth, WifiMode mode);
263 
265  Time CalculateFirstMpduTxDuration (Ptr<WifiPhy> phy, uint8_t streams, uint8_t sgi, uint32_t chWidth, WifiMode mode);
266 
268  Time GetMpduTxTime (uint32_t groupId, WifiMode mode) const;
269 
271  void AddMpduTxTime (uint32_t groupId, WifiMode mode, Time t);
272 
274  Time GetFirstMpduTxTime (uint32_t groupId, WifiMode mode) const;
275 
277  void AddFirstMpduTxTime (uint32_t groupId, WifiMode mode, Time t);
278 
281 
283  void UpdatePacketCounters (MinstrelHtWifiRemoteStation *station, uint32_t nSuccessfulMpdus, uint32_t nFailedMpdus);
284 
286  uint32_t GetNextSample (MinstrelHtWifiRemoteStation *station);
287 
290 
292  uint32_t FindRate (MinstrelHtWifiRemoteStation *station);
293 
296 
298  void RateInit (MinstrelHtWifiRemoteStation *station);
299 
301  double CalculateThroughput (MinstrelHtWifiRemoteStation *station, uint32_t groupId, uint32_t rateId, double ewmaProb);
302 
304  void SetBestStationThRates (MinstrelHtWifiRemoteStation *station, uint32_t index);
305 
307  void SetBestProbabilityRate (MinstrelHtWifiRemoteStation *station, uint32_t index);
308 
310  void CalculateRetransmits (MinstrelHtWifiRemoteStation *station, uint32_t index);
311 
313  void CalculateRetransmits (MinstrelHtWifiRemoteStation *station, uint32_t groupId, uint32_t rateId);
314 
331  Time CalculateTimeUnicastPacket (Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries);
332 
334  double CalculateEwmsd (double oldEwmsd, double currentProb, double ewmaProb, uint32_t weight);
335 
338 
341 
343  void PrintTable (MinstrelHtWifiRemoteStation *station);
344 
346  void StatsDump (MinstrelHtWifiRemoteStation *station, uint32_t index, std::ofstream &of);
347 
349  void CheckInit (MinstrelHtWifiRemoteStation *station);
350 
351  uint32_t CountRetries (MinstrelHtWifiRemoteStation * station);
352 
353  void UpdateRate (MinstrelHtWifiRemoteStation *station);
354 
363  uint32_t GetRateId (uint32_t index);
365 
367  uint32_t GetGroupId (uint32_t index);
368 
370  uint32_t GetIndex (uint32_t groupId, uint32_t rateId);
371 
373  uint32_t GetHtGroupId (uint8_t txstreams, uint8_t sgi, uint32_t chWidth);
374 
376  uint32_t GetVhtGroupId (uint8_t txstreams, uint8_t sgi, uint32_t chWidth);
377 
379  uint32_t GetLowestIndex (MinstrelHtWifiRemoteStation *station);
380 
382  uint32_t GetLowestIndex (MinstrelHtWifiRemoteStation *station, uint32_t groupId);
383 
385  WifiModeList GetVhtDeviceMcsList (void) const;
386 
388  WifiModeList GetHtDeviceMcsList (void) const;
389 
392  double m_ewmaLevel;
393 
394  uint32_t m_nSampleCol;
395  uint32_t m_frameLength;
396 
397 
398  uint8_t m_numGroups;
399  uint8_t m_numRates;
400 
402 
404 
405 
406  MinstrelMcsGroups m_minstrelGroups;
407 
409 
410 
412 
417 };
418 
419 } // namespace ns3
420 
421 #endif /* MINSTREL_HT_WIFI_MANAGER_H */
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.
double throughput
Throughput of this rate (in pkts per second).
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool m_supported
If the rates of this group are supported by the station.
A struct to contain information of a group.
double CalculateThroughput(MinstrelHtWifiRemoteStation *station, uint32_t groupId, uint32_t rateId, double ewmaProb)
Return the average throughput of the MCS defined by groupId and rateId.
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.
WifiModeList GetHtDeviceMcsList(void) const
Returns a list of only the HT MCS supported by the device.
void PrintTable(MinstrelHtWifiRemoteStation *station)
Printing Minstrel Table.
uint32_t GetHtGroupId(uint8_t txstreams, uint8_t sgi, uint32_t chWidth)
Returns the groupId of a HT MCS with the given number of streams, if using sgi and the channel width ...
uint8_t m_col
MCS rates are divided into groups based on the number of streams and flags that they use...
uint32_t GetLowestIndex(MinstrelHtWifiRemoteStation *station)
Returns the lowest global index of the rates supported by the station.
uint32_t m_maxProbRate
The highest success probability rate of this group.
double CalculateEwmsd(double oldEwmsd, double currentProb, double ewmaProb, uint32_t weight)
Perform EWMSD (Exponentially Weighted Moving Standard Deviation) calculation.
Forward calls to a chain of Callback.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
uint32_t GetIndex(uint32_t groupId, uint32_t rateId)
Returns the global index corresponding to the groupId and rateId.
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...
uint32_t m_maxTpRate
The max throughput rate of this group.
std::vector< struct McsGroup > MinstrelMcsGroups
Data structure for a table of group definitions.
double prob
Current probability within last time interval.
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void StatsDump(MinstrelHtWifiRemoteStation *station, uint32_t index, std::ofstream &of)
Print group statistics.
HtMinstrelRate m_ratesTable
Information about rates of this group.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
virtual bool DoNeedDataRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
uint32_t m_frameLength
Frame length used for calculate modes TxTime.
std::vector< std::vector< uint32_t > > HtSampleRate
Data structure for a Sample Rate table.
MinstrelMcsGroups m_minstrelGroups
Global array for groups information.
STL namespace.
uint32_t m_maxTpRate2
The second max throughput rate of this group.
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 UpdatePacketCounters(MinstrelHtWifiRemoteStation *station, uint32_t nSuccessfulMpdus, uint32_t nFailedMpdus)
Update the number of sample count variables.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
bool m_printStats
If statistics table should be printed.
uint32_t adjustedRetryCount
Adjust the retry limit for this rate.
uint32_t numRateAttempt
Number of transmission attempts so far.
uint8_t m_index
Sample table index.
Time CalculateFirstMpduTxDuration(Ptr< WifiPhy > phy, uint8_t streams, uint8_t sgi, uint32_t chWidth, WifiMode mode)
Estimates the TxTime of a frame with a given mode and group (stream, guard interval and channel width...
void AddFirstMpduTxTime(uint32_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
tuple phy
Definition: third.py:86
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
double m_ewmaLevel
Exponential weighted moving average level (or coefficient).
void CalculateRetransmits(MinstrelHtWifiRemoteStation *station, uint32_t index)
Calculate the number of retransmissions to set for the index rate.
static const uint8_t MAX_VHT_GROUP_RATES
Number of rates (or MCS) per VHT group.
Time GetMpduTxTime(uint32_t groupId, WifiMode mode) const
Obtain the TXtime saved in the group information.
static const uint8_t MAX_HT_WIDTH
Maximal channel width.
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...
virtual void DoDisposeStation(WifiRemoteStation *station)
uint32_t GetRateId(uint32_t index)
For managing rates from different groups, a global index for all rates in all groups is used...
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...
tuple mac
Definition: third.py:92
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.
uint32_t mcsIndex
The index in the operationalMcsSet of the WifiRemoteStationManager.
std::vector< struct GroupInfo > McsGroupData
Data structure for a table of groups.
static const uint8_t MAX_VHT_WIDTH
Maximal channel width.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
virtual WifiRemoteStation * DoCreateStation(void) const
bool retryUpdated
If number of retries was updated already.
uint32_t GetVhtGroupId(uint8_t txstreams, uint8_t sgi, uint32_t chWidth)
Returns the groupId of a VHT MCS with the given number of streams, if using sgi and the channel width...
double ewmaProb
Exponential weighted moving average of probability.
std::vector< std::pair< Time, WifiMode > > TxTime
Data structure to save transmission time calculations per rate.
Time perfectTxTime
Perfect transmission time calculation, or frame calculation.
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 SetBestStationThRates(MinstrelHtWifiRemoteStation *station, uint32_t index)
Set index rate as maxTpRate or maxTp2Rate if is better than current values.
void InitSampleTable(MinstrelHtWifiRemoteStation *station)
Initialize Sample Table.
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void UpdateRetry(MinstrelHtWifiRemoteStation *station)
Update the number of retries and reset accordingly.
uint32_t m_nSampleCol
Number of sample columns.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool supported
If the rate is supported.
uint8_t m_numGroups
Number of groups Minstrel should consider.
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...
Time m_updateStats
How frequent do we calculate the stats (1/10 seconds).
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.
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void UpdateStats(MinstrelHtWifiRemoteStation *station)
Updating the Minstrel Table every 1/10 seconds.
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:226
WifiModeList GetVhtDeviceMcsList(void) const
Returns a list of only the VHT MCS supported by the device.
void RateInit(MinstrelHtWifiRemoteStation *station)
Initialize Minstrel Table.
Implementation of Minstrel HT Rate Control AlgorithmMinstrel-HT is a rate adaptation mechanism for th...
uint32_t FindRate(MinstrelHtWifiRemoteStation *station)
Find a rate to use from Minstrel Table.
Data structure to contain the information that defines a group.
uint32_t retryCount
Retry limit.
double ewmsdProb
Exponential weighted moving standard deviation of probability.
virtual void DoInitialize(void)
Initialize() implementation.
double m_lookAroundRate
The % to try other rates than our current rate.
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 AddMpduTxTime(uint32_t groupId, WifiMode mode, Time t)
Save a TxTime to the vector of groups.
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.
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...
uint32_t GetGroupId(uint32_t index)
Return the groupId from the global index.
uint64_t successHist
Aggregate of all transmission successes.
void SetBestProbabilityRate(MinstrelHtWifiRemoteStation *station, uint32_t index)
Set index rate as maxProbRate if it is better than current value.
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
uint64_t attemptHist
Aggregate of all transmission attempts.
std::vector< struct HtRateInfo > HtMinstrelRate
Data structure for a Minstrel Rate table.
virtual bool IsLowLatency(void) const
Time GetFirstMpduTxTime(uint32_t groupId, WifiMode mode) const
Obtain the TXtime saved in the group information.
Time CalculateMpduTxDuration(Ptr< WifiPhy > phy, uint8_t streams, uint8_t sgi, uint32_t chWidth, WifiMode mode)
Estimates the TxTime of a frame with a given mode and group (stream, guard interval and channel width...
uint32_t CountRetries(MinstrelHtWifiRemoteStation *station)
TracedCallback< uint64_t, Mac48Address > m_rateChange
The trace source fired when the transmission rate change.
void UpdateRate(MinstrelHtWifiRemoteStation *station)
uint32_t GetNextSample(MinstrelHtWifiRemoteStation *station)
Getting the next sample from Sample Table.
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 DoReportAmpduTxStatus(WifiRemoteStation *station, uint32_t nSuccessfulMpdus, uint32_t nFailedMpdus, double rxSnr, double dataSnr)
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
a unique identifier for an interface.
Definition: type-id.h:58
bool IsValidMcs(Ptr< WifiPhy > phy, uint8_t streams, uint32_t chWidth, WifiMode mode)
Check the validity of a combination of number of streams, chWidth and mode.
void CheckInit(MinstrelHtWifiRemoteStation *station)
Check for initializations.
hold per-remote-station state.