A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
minstrel-wifi-manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Duy Nguyen
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Duy Nguyen <duy@soe.ucsc.edu>
18 * Matías Richart <mrichart@fing.edu.uy>
19 */
20
21#ifndef MINSTREL_WIFI_MANAGER_H
22#define MINSTREL_WIFI_MANAGER_H
23
24#include "ns3/traced-value.h"
25#include "ns3/wifi-remote-station-manager.h"
26
27#include <fstream>
28#include <map>
29
30namespace ns3
31{
32
33class UniformRandomVariable;
34
35/**
36 * A struct to contain all information related to a data rate
37 */
39{
40 /**
41 * Perfect transmission time calculation, or frame calculation
42 * Given a bit rate and a packet length n bytes
43 */
45
46 uint32_t retryCount; ///< retry limit
47 uint32_t adjustedRetryCount; ///< adjust the retry limit for this rate
48 uint32_t numRateAttempt; ///< how many number of attempts so far
49 uint32_t numRateSuccess; ///< number of successful packets
50 uint32_t prob; ///< (# packets success)/(# total packets)
51 /**
52 * EWMA calculation
53 * ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100
54 */
56 uint32_t throughput; ///< throughput of a rate in bps
57
58 uint32_t prevNumRateAttempt; //!< Number of transmission attempts with previous rate.
59 uint32_t prevNumRateSuccess; //!< Number of successful frames transmitted with previous rate.
60 uint64_t successHist; //!< Aggregate of all transmission successes.
61 uint64_t attemptHist; //!< Aggregate of all transmission attempts.
62
63 uint8_t numSamplesSkipped; //!< number of samples skipped
64 int sampleLimit; //!< sample limit
65};
66
67/**
68 * Data structure for a Minstrel Rate table
69 * A vector of a struct RateInfo
70 */
71typedef std::vector<RateInfo> MinstrelRate;
72/**
73 * Data structure for a Sample Rate table
74 * A vector of a vector uint8_t
75 */
76typedef std::vector<std::vector<uint8_t>> SampleRate;
77
78/**
79 * \brief hold per-remote-station state for Minstrel Wifi manager.
80 *
81 * This struct extends from WifiRemoteStation struct to hold additional
82 * information required by the Minstrel Wifi manager
83 */
85{
86 Time m_nextStatsUpdate; ///< 10 times every second
87
88 /**
89 * To keep track of the current position in the our random sample table
90 * going row by row from 1st column until the 10th column(Minstrel defines 10)
91 * then we wrap back to the row 1 column 1.
92 * note: there are many other ways to do this.
93 */
94 uint8_t m_col; ///< column index
95 uint8_t m_index; ///< vector index
96 uint16_t m_maxTpRate; ///< the current throughput rate in bps
97 uint16_t m_maxTpRate2; ///< second highest throughput rate in bps
98 uint16_t m_maxProbRate; ///< rate with highest probability of success in bps
99 uint8_t m_nModes; ///< number of modes supported
100 int m_totalPacketsCount; ///< total number of packets as of now
101 int m_samplePacketsCount; ///< how many packets we have sample so far
102 int m_numSamplesDeferred; ///< number samples deferred
103 bool m_isSampling; ///< a flag to indicate we are currently sampling
104 uint16_t m_sampleRate; ///< current sample rate in bps
105 bool m_sampleDeferred; ///< a flag to indicate sample rate is on the second stage
106 uint32_t m_shortRetry; ///< short retries such as control packets
107 uint32_t m_longRetry; ///< long retries such as data packets
108 uint32_t m_retry; ///< total retries short + long
109 uint16_t m_txrate; ///< current transmit rate in bps
110 bool m_initialized; ///< for initializing tables
111 MinstrelRate m_minstrelTable; ///< minstrel table
112 SampleRate m_sampleTable; ///< sample table
113 std::ofstream m_statsFile; ///< stats file
114};
115
116/**
117 * \brief Implementation of Minstrel Rate Control Algorithm
118 * \ingroup wifi
119 *
120 * Minstrel is a rate control algorithm implemented in MadWifi and Linux.
121 * The basic principle is to probe the environment and adapt the rate
122 * based on statistics collected on the probability of successful
123 * transmission. The algorithm adapts the rate to the highest rate
124 * that it considers successful, and spends a fraction of its time
125 * doing 'look around' by trying other rates.
126 *
127 * Minstrel is appropriate for non-HT configurations; for HT (i.e. 802.11n
128 * or higher), users should use MinstrelHtWifiManager instead.
129 * Minstrel will error exit if the user tries to configure it with a
130 * Wi-Fi MAC that supports 802.11n or higher.
131 *
132 * Some notes on this implementation follow. The implementation has
133 * been adapted to bring it closer to the Linux implementation.
134 * For each rate, a new parameter samplesSkipped is added. This parameter
135 * is intended to solve an issue regarding the sampling of low rates when
136 * a high rate is working well, which leads to outdated statistics.
137 * This change makes throughput a bit lower in simple, stable scenarios,
138 * but may help in dynamic scenarios to react faster and more accurately
139 * to changes.
140 *
141 * Related to the previous, the logic for deciding when to sample random
142 * rates is as follows. When a sample rate is deferred to the second MRR
143 * chain stage, a new parameter (numSamplesDeferred) is increased. This
144 * parameters is used (jointly with sampleCount) to compare current
145 * sample count with the lookaround rate.
146 *
147 * Also related with sampling, another parameter sampleLimit is added.
148 * This parameter limits the number of times a very low or very high
149 * probability rate is sampled, avoiding to try a poorly working sample
150 * rate too often.
151 *
152 * When updating the EWMA probability of a rate for the first time, it does
153 * not apply EWMA but instead assigns the entire probability.
154 * Since the EWMA probability is initialized to zero, this generates
155 * a more accurate EWMA.
156 */
158{
159 public:
160 /**
161 * \brief Get the type ID.
162 * \return the object TypeId
163 */
164 static TypeId GetTypeId();
166 ~MinstrelWifiManager() override;
167
168 void SetupPhy(const Ptr<WifiPhy> phy) override;
169 void SetupMac(const Ptr<WifiMac> mac) override;
170 int64_t AssignStreams(int64_t stream) override;
171
172 /**
173 * Update the rate.
174 *
175 * \param station the station object
176 */
178
179 /**
180 * Update the Minstrel Table.
181 *
182 * \param station the station object
183 */
185
186 /**
187 * Find a rate to use from Minstrel Table.
188 *
189 * \param station the station object
190 * \returns the rate in bps
191 */
192 uint16_t FindRate(MinstrelWifiRemoteStation* station);
193
194 /**
195 * Get data transmit vector.
196 *
197 * \param station the station object
198 * \returns WifiTxVector
199 */
201
202 /**
203 * Get RTS transmit vector.
204 *
205 * \param station the station object
206 * \returns WifiTxVector
207 */
209
210 /**
211 * Get the number of retries.
212 *
213 * \param station the station object
214 * \returns the number of retries
215 */
217
218 /**
219 * Update packet counters.
220 *
221 * \param station the station object
222 */
224
225 /**
226 * Update the number of retries and reset accordingly.
227 *
228 * \param station the station object
229 */
231
232 /**
233 * Check for initializations.
234 *
235 * \param station the station object
236 */
238
239 /**
240 * Initialize Sample Table.
241 *
242 * \param station the station object
243 */
245
246 private:
247 void DoInitialize() override;
248 WifiRemoteStation* DoCreateStation() const override;
249 void DoReportRxOk(WifiRemoteStation* station, double rxSnr, WifiMode txMode) override;
250 void DoReportRtsFailed(WifiRemoteStation* station) override;
251 void DoReportDataFailed(WifiRemoteStation* station) override;
252 void DoReportRtsOk(WifiRemoteStation* station,
253 double ctsSnr,
254 WifiMode ctsMode,
255 double rtsSnr) override;
256 void DoReportDataOk(WifiRemoteStation* station,
257 double ackSnr,
258 WifiMode ackMode,
259 double dataSnr,
260 uint16_t dataChannelWidth,
261 uint8_t dataNss) override;
262 void DoReportFinalRtsFailed(WifiRemoteStation* station) override;
263 void DoReportFinalDataFailed(WifiRemoteStation* station) override;
264 WifiTxVector DoGetDataTxVector(WifiRemoteStation* station, uint16_t allowedWidth) override;
266
268 Ptr<const Packet> packet,
269 bool normally) override;
270
271 /**
272 * Estimate the TxTime of a packet with a given mode.
273 *
274 * \param mode Wi-Fi mode
275 * \returns the transmission time
276 */
277 Time GetCalcTxTime(WifiMode mode) const;
278 /**
279 * Add transmission time for the given mode to an internal list.
280 *
281 * \param mode Wi-Fi mode
282 * \param t transmission time
283 */
284 void AddCalcTxTime(WifiMode mode, Time t);
285
286 /**
287 * Initialize Minstrel Table.
288 *
289 * \param station the station object
290 */
291 void RateInit(MinstrelWifiRemoteStation* station);
292
293 /**
294 * Get the next sample from Sample Table.
295 *
296 * \param station the station object
297 * \returns the next sample
298 */
299 uint16_t GetNextSample(MinstrelWifiRemoteStation* station);
300
301 /**
302 * Estimate the time to transmit the given packet with the given number of retries.
303 * This function is "roughly" the function "calc_usecs_unicast_packet" in minstrel.c
304 * in the madwifi implementation.
305 *
306 * The basic idea is that, we try to estimate the "average" time used to transmit the
307 * packet for the given number of retries while also accounting for the 802.11 congestion
308 * window change. The original code in the madwifi seems to estimate the number of backoff
309 * slots as the half of the current CW size.
310 *
311 * There are four main parts:
312 * - wait for DIFS (sense idle channel)
313 * - Ack timeouts
314 * - Data transmission
315 * - backoffs according to CW
316 *
317 * \param dataTransmissionTime the data transmission time
318 * \param shortRetries short retries
319 * \param longRetries long retries
320 * \returns the unicast packet time
321 */
322 Time CalculateTimeUnicastPacket(Time dataTransmissionTime,
323 uint32_t shortRetries,
324 uint32_t longRetries);
325
326 /**
327 * Print Sample Table.
328 *
329 * \param station the station object
330 */
331 void PrintSampleTable(MinstrelWifiRemoteStation* station) const;
332
333 /**
334 * Print Minstrel Table.
335 *
336 * \param station the station object
337 */
339
340 /**
341 * typedef for a vector of a pair of Time, WifiMode.
342 * Essentially a map from WifiMode to its corresponding transmission time
343 * to transmit a reference packet.
344 */
345 typedef std::map<WifiMode, Time> TxTime;
346
347 TxTime m_calcTxTime; ///< to hold all the calculated TxTime for all modes
348 Time m_updateStats; ///< how frequent do we calculate the stats
349 uint8_t m_lookAroundRate; ///< the % to try other rates than our current rate
350 uint8_t m_ewmaLevel; ///< exponential weighted moving average
351 uint8_t m_sampleCol; ///< number of sample columns
352 uint32_t m_pktLen; ///< packet length used to calculate mode TxTime
353 bool m_printStats; ///< whether statistics table should be printed.
354 bool m_printSamples; ///< whether samples table should be printed.
355
356 /// Provides uniform random variables.
358
359 TracedValue<uint64_t> m_currentRate; //!< Trace rate changes
360};
361
362} // namespace ns3
363
364#endif /* MINSTREL_WIFI_MANAGER_H */
Implementation of Minstrel Rate Control Algorithm.
WifiRemoteStation * DoCreateStation() const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) 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
std::map< WifiMode, Time > TxTime
typedef for a vector of a pair of Time, WifiMode.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
represent a single transmission mode
Definition: wifi-mode.h:51
hold a list of per-remote-station state.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< RateInfo > MinstrelRate
Data structure for a Minstrel Rate table A vector of a struct RateInfo.
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
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.
uint8_t numSamplesSkipped
number of samples skipped
uint32_t ewmaProb
EWMA calculation ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100.
uint32_t numRateSuccess
number of successful packets
uint32_t adjustedRetryCount
adjust the retry limit for this rate
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
int sampleLimit
sample limit
uint32_t prob
(# packets success)/(# total packets)
uint32_t retryCount
retry limit
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.
uint32_t numRateAttempt
how many number of attempts so far
uint64_t attemptHist
Aggregate of all transmission attempts.
hold per-remote-station state.