author | Ghada Badawy <gbadawy@gmail.com> |
Tue, 13 Aug 2013 22:05:25 -0700 | |
changeset 10139 | 17a71cd49da3 |
parent 8981 | 7e1c95c4d1a7 |
child 10218 | 97da49da2d6c |
permissions | -rw-r--r-- |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
2 |
/* |
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
3 |
* Copyright (c) 2009 Duy Nguyen |
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
4 |
* |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
8 |
* |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
13 |
* |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
17 |
* |
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
18 |
* Author: Duy Nguyen <duy@soe.ucsc.edu> |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
19 |
*/ |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
20 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
21 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
22 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
23 |
#ifndef MINSTREL_WIFI_MANAGER_H |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
24 |
#define MINSTREL_WIFI_MANAGER_H |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
25 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
26 |
#include "wifi-remote-station-manager.h" |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
27 |
#include "wifi-mode.h" |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
28 |
#include "ns3/nstime.h" |
8981
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
29 |
#include "ns3/random-variable-stream.h" |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
30 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
31 |
namespace ns3 { |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
32 |
|
6340 | 33 |
struct MinstrelWifiRemoteStation; |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
34 |
|
6337 | 35 |
/** |
36 |
* A struct to contain all information related to a data rate |
|
37 |
*/ |
|
38 |
struct RateInfo |
|
39 |
{ |
|
40 |
/** |
|
41 |
* Perfect transmission time calculation, or frame calculation |
|
42 |
* Given a bit rate and a packet length n bytes |
|
43 |
*/ |
|
44 |
Time perfectTxTime; |
|
45 |
||
46 |
||
47 |
uint32_t retryCount; ///< retry limit |
|
48 |
uint32_t adjustedRetryCount; ///< adjust the retry limit for this rate |
|
49 |
uint32_t numRateAttempt; ///< how many number of attempts so far |
|
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
50 |
uint32_t numRateSuccess; ///< number of successful pkts |
6337 | 51 |
uint32_t prob; ///< (# pkts success )/(# total pkts) |
52 |
||
53 |
/** |
|
54 |
* EWMA calculation |
|
55 |
* ewma_prob =[prob *(100 - ewma_level) + (ewma_prob_old * ewma_level)]/100 |
|
56 |
*/ |
|
57 |
uint32_t ewmaProb; |
|
58 |
||
59 |
uint32_t prevNumRateAttempt; ///< from last rate |
|
60 |
uint32_t prevNumRateSuccess; ///< from last rate |
|
61 |
uint64_t successHist; ///< aggregate of all successes |
|
62 |
uint64_t attemptHist; ///< aggregate of all attempts |
|
63 |
uint32_t throughput; ///< throughput of a rate |
|
64 |
}; |
|
65 |
||
66 |
/** |
|
67 |
* Data structure for a Minstrel Rate table |
|
68 |
* A vector of a struct RateInfo |
|
69 |
*/ |
|
70 |
typedef std::vector<struct RateInfo> MinstrelRate; |
|
71 |
||
72 |
/** |
|
73 |
* Data structure for a Sample Rate table |
|
74 |
* A vector of a vector uint32_t |
|
75 |
*/ |
|
76 |
typedef std::vector<std::vector<uint32_t> > SampleRate; |
|
77 |
||
78 |
||
7139
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
79 |
/** |
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
80 |
* \author Duy Nguyen |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
81 |
* \brief Implementation of Minstrel Rate Control Algorithm |
7139
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
82 |
* \ingroup wifi |
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
83 |
* |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
84 |
* Porting Minstrel from Madwifi and Linux Kernel |
7139
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
85 |
* http://linuxwireless.org/en/developers/Documentation/mac80211/RateControl/minstrel |
79dd02ed46ec
doxygen wifi module grouping all wifi classes
Nicola Baldo <nbaldo@cttc.es>
parents:
6852
diff
changeset
|
86 |
*/ |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
87 |
class MinstrelWifiManager : public WifiRemoteStationManager |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
88 |
{ |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
89 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
90 |
public: |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
91 |
static TypeId GetTypeId (void); |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
92 |
MinstrelWifiManager (); |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
93 |
virtual ~MinstrelWifiManager (); |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
94 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
95 |
virtual void SetupPhy (Ptr<WifiPhy> phy); |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
96 |
|
8981
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
97 |
/** |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
98 |
* Assign a fixed random variable stream number to the random variables |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
99 |
* used by this model. Return the number of streams (possibly zero) that |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
100 |
* have been assigned. |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
101 |
* |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
102 |
* \param stream first stream index to use |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
103 |
* \return the number of stream indices assigned by this model |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
104 |
*/ |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
105 |
int64_t AssignStreams (int64_t stream); |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
106 |
|
6065 | 107 |
private: |
108 |
// overriden from base class |
|
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
109 |
virtual WifiRemoteStation * DoCreateStation (void) const; |
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
110 |
virtual void DoReportRxOk (WifiRemoteStation *station, |
6065 | 111 |
double rxSnr, WifiMode txMode); |
112 |
virtual void DoReportRtsFailed (WifiRemoteStation *station); |
|
113 |
virtual void DoReportDataFailed (WifiRemoteStation *station); |
|
114 |
virtual void DoReportRtsOk (WifiRemoteStation *station, |
|
115 |
double ctsSnr, WifiMode ctsMode, double rtsSnr); |
|
116 |
virtual void DoReportDataOk (WifiRemoteStation *station, |
|
117 |
double ackSnr, WifiMode ackMode, double dataSnr); |
|
118 |
virtual void DoReportFinalRtsFailed (WifiRemoteStation *station); |
|
119 |
virtual void DoReportFinalDataFailed (WifiRemoteStation *station); |
|
10139 | 120 |
virtual WifiTxVector DoGetDataTxVector (WifiRemoteStation *station, uint32_t size); |
121 |
virtual WifiTxVector DoGetRtsTxVector (WifiRemoteStation *station); |
|
6065 | 122 |
virtual bool IsLowLatency (void) const; |
123 |
||
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
124 |
/// for estimating the TxTime of a packet with a given mode |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
125 |
Time GetCalcTxTime (WifiMode mode) const; |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
126 |
void AddCalcTxTime (WifiMode mode, Time t); |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
127 |
|
6065 | 128 |
/// update the number of retries and reset accordingly |
129 |
void UpdateRetry (MinstrelWifiRemoteStation *station); |
|
130 |
||
131 |
/// getting the next sample from Sample Table |
|
132 |
uint32_t GetNextSample (MinstrelWifiRemoteStation *station); |
|
133 |
||
134 |
/// find a rate to use from Minstrel Table |
|
135 |
uint32_t FindRate (MinstrelWifiRemoteStation *station); |
|
136 |
||
137 |
/// updating the Minstrel Table every 1/10 seconds |
|
138 |
void UpdateStats (MinstrelWifiRemoteStation *station); |
|
139 |
||
140 |
/// initialize Minstrel Table |
|
141 |
void RateInit (MinstrelWifiRemoteStation *station); |
|
142 |
||
143 |
/// initialize Sample Table |
|
144 |
void InitSampleTable (MinstrelWifiRemoteStation *station); |
|
145 |
||
146 |
/// printing Sample Table |
|
147 |
void PrintSampleTable (MinstrelWifiRemoteStation *station); |
|
148 |
||
149 |
/// printing Minstrel Table |
|
150 |
void PrintTable (MinstrelWifiRemoteStation *station); |
|
151 |
||
152 |
void CheckInit (MinstrelWifiRemoteStation *station); ///< check for initializations |
|
153 |
||
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
154 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
155 |
typedef std::vector<std::pair<Time,WifiMode> > TxTime; |
6337 | 156 |
MinstrelRate m_minstrelTable; ///< minstrel table |
157 |
SampleRate m_sampleTable; ///< sample table |
|
158 |
||
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
159 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
160 |
TxTime m_calcTxTime; ///< to hold all the calculated TxTime for all modes |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
161 |
Time m_updateStats; ///< how frequent do we calculate the stats(1/10 seconds) |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
162 |
double m_lookAroundRate; ///< the % to try other rates than our current rate |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
163 |
double m_ewmaLevel; ///< exponential weighted moving average |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
164 |
uint32_t m_segmentSize; ///< largest allowable segment size |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
165 |
uint32_t m_sampleCol; ///< number of sample columns |
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
166 |
uint32_t m_pktLen; ///< packet length used for calculate mode TxTime |
6337 | 167 |
uint32_t m_nsupported; ///< modes supported |
8981
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
168 |
|
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
169 |
/// Provides uniform random variables. |
7e1c95c4d1a7
Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7141
diff
changeset
|
170 |
Ptr<UniformRandomVariable> m_uniformRandomVariable; |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
171 |
}; |
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
172 |
|
7141
072fb225b714
run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents:
7139
diff
changeset
|
173 |
} // namespace ns3 |
4703
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
174 |
|
e1259e2fdaad
add an implementation of the minstrel rate control algorithm
Duy Nguyen <duy@soe.ucsc.edu>
parents:
diff
changeset
|
175 |
#endif /* MINSTREL_WIFI_MANAGER_H */ |