A Discrete-Event Network Simulator
API
minstrel-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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Duy Nguyen <duy@soe.ucsc.edu>
19  * Matías Richart <mrichart@fing.edu.uy>
20  */
21 
22 #ifndef MINSTREL_WIFI_MANAGER_H
23 #define MINSTREL_WIFI_MANAGER_H
24 
26 #include "wifi-mode.h"
27 #include "ns3/nstime.h"
28 #include "ns3/random-variable-stream.h"
29 #include <fstream>
30 
31 namespace ns3 {
32 
36 struct RateInfo
37 {
43 
44  uint32_t retryCount;
45  uint32_t adjustedRetryCount;
46  uint32_t numRateAttempt;
47  uint32_t numRateSuccess;
48  uint32_t prob;
49 
53  uint32_t ewmaProb;
54  uint32_t throughput;
55 
56  uint32_t prevNumRateAttempt;
57  uint32_t prevNumRateSuccess;
58  uint64_t successHist;
59  uint64_t attemptHist;
60 
63 };
64 
69 typedef std::vector<struct RateInfo> MinstrelRate;
74 typedef std::vector<std::vector<uint32_t> > SampleRate;
75 
83 {
85 
92  uint32_t m_col, m_index;
93  uint32_t m_maxTpRate;
94  uint32_t m_maxTpRate2;
95  uint32_t m_maxProbRate;
96  uint32_t m_nModes;
101  uint32_t m_sampleRate;
103  uint32_t m_shortRetry;
104  uint32_t m_longRetry;
105  uint32_t m_retry;
106  uint32_t m_txrate;
108  MinstrelRate m_minstrelTable;
109  SampleRate m_sampleTable;
110  std::ofstream m_statsFile;
111 };
112 
113 
154 {
155 
156 public:
157  static TypeId GetTypeId (void);
159  virtual ~MinstrelWifiManager ();
160 
161  // Inherited from WifiRemoteStationManager
162  virtual void SetupPhy (Ptr<WifiPhy> phy);
163  virtual void SetupMac (Ptr<WifiMac> mac);
164 
174  int64_t AssignStreams (int64_t stream);
175 
176  void UpdateRate (MinstrelWifiRemoteStation *station);
177 
178  //updating the Minstrel Table every 1/10 seconds
179  void UpdateStats (MinstrelWifiRemoteStation *station);
180 
181  //find a rate to use from Minstrel Table
182  uint32_t FindRate (MinstrelWifiRemoteStation *station);
183 
185 
187 
188  uint32_t CountRetries (MinstrelWifiRemoteStation *station);
189 
191 
192  //update the number of retries and reset accordingly
193  void UpdateRetry (MinstrelWifiRemoteStation *station);
194 
195  void CheckInit (MinstrelWifiRemoteStation *station);
196 
197  //initialize Sample Table
199 
200 private:
201  //overriden from base class
202  virtual WifiRemoteStation * DoCreateStation (void) const;
203  virtual void DoReportRxOk (WifiRemoteStation *station,
204  double rxSnr, WifiMode txMode);
205  virtual void DoReportRtsFailed (WifiRemoteStation *station);
206  virtual void DoReportDataFailed (WifiRemoteStation *station);
207  virtual void DoReportRtsOk (WifiRemoteStation *station,
208  double ctsSnr, WifiMode ctsMode, double rtsSnr);
209  virtual void DoReportDataOk (WifiRemoteStation *station,
210  double ackSnr, WifiMode ackMode, double dataSnr);
211  virtual void DoReportFinalRtsFailed (WifiRemoteStation *station);
212  virtual void DoReportFinalDataFailed (WifiRemoteStation *station);
215 
216  virtual bool DoNeedDataRetransmission (WifiRemoteStation *st, Ptr<const Packet> packet, bool normally);
217 
218  virtual bool IsLowLatency (void) const;
219 
220  //for estimating the TxTime of a packet with a given mode
221  Time GetCalcTxTime (WifiMode mode) const;
228  void AddCalcTxTime (WifiMode mode, Time t);
229 
230  //initialize Minstrel Table
231  void RateInit (MinstrelWifiRemoteStation *station);
232 
233  //getting the next sample from Sample Table
234  uint32_t GetNextSample (MinstrelWifiRemoteStation *station);
235 
252  Time CalculateTimeUnicastPacket (Time dataTransmissionTime, uint32_t shortRetries, uint32_t longRetries);
253 
254  //printing Sample Table
256 
257  //printing Minstrel Table
258  void PrintTable (MinstrelWifiRemoteStation *station);
259 
260 
266  typedef std::vector<std::pair<Time,WifiMode> > TxTime;
267 
268  TxTime m_calcTxTime;
271  double m_ewmaLevel;
272  uint32_t m_sampleCol;
273  uint32_t m_pktLen;
275 
276  //Provides uniform random variables.
278 };
279 
280 } //namespace ns3
281 
282 #endif /* MINSTREL_WIFI_MANAGER_H */
void CheckInit(MinstrelWifiRemoteStation *station)
check for initializations
void PrintTable(MinstrelWifiRemoteStation *station)
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
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.
Definition: nstime.h:102
bool m_printStats
If statistics table should be printed.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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 ...
uint32_t numRateSuccess
number of successful pkts
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)
uint32_t m_sampleRate
current sample rate
uint32_t GetNextSample(MinstrelWifiRemoteStation *station)
virtual bool DoNeedDataRetransmission(WifiRemoteStation *st, Ptr< const Packet > packet, bool normally)
uint32_t m_txrate
current transmit rate
MinstrelRate m_minstrelTable
minstrel table
bool m_sampleDeferred
a flag to indicate sample rate is on the second stage
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
uint32_t retryCount
retry limit
uint32_t FindRate(MinstrelWifiRemoteStation *station)
uint32_t m_pktLen
packet length used for calculate mode TxTime
uint32_t adjustedRetryCount
adjust the retry limit for this rate
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.
tuple phy
Definition: third.py:86
bool m_isSampling
a flag to indicate we are currently sampling
SampleRate m_sampleTable
sample table
uint32_t prevNumRateSuccess
Number of successful frames transmitted with previous rate.
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.
virtual WifiRemoteStation * DoCreateStation(void) const
void AddCalcTxTime(WifiMode mode, Time t)
Add transmission time for the given mode to an internal list.
tuple mac
Definition: third.py:92
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.
uint32_t numRateAttempt
how many number of attempts so far
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void UpdateRate(MinstrelWifiRemoteStation *station)
Retry Chain table is implemented here.
uint32_t m_maxTpRate2
second highest throughput rate
WifiTxVector GetDataTxVector(MinstrelWifiRemoteStation *station)
uint32_t throughput
throughput of a rate
uint32_t m_retry
total retries short + long
int m_totalPacketsCount
total number of packets as of now
Ptr< UniformRandomVariable > m_uniformRandomVariable
void UpdateRetry(MinstrelWifiRemoteStation *station)
double m_lookAroundRate
the % to try other rates than our current rate
int m_samplePacketsCount
how many packets we have sample so far
void InitSampleTable(MinstrelWifiRemoteStation *station)
uint32_t m_maxProbRate
rate with highest prob of success
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)
uint32_t m_maxTpRate
the current throughput rate
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 m_sampleCol
number of sample columns
std::vector< std::pair< Time, WifiMode > > TxTime
typedef for a vector of a pair of Time, WifiMode.
uint32_t m_shortRetry
short retries such as control packts
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.
Definition: type-id.h:58
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)
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)
void UpdatePacketCounters(MinstrelWifiRemoteStation *station)
Time m_nextStatsUpdate
10 times every second