A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
amrr-wifi-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2003,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "amrr-wifi-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/double.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 
29 NS_LOG_COMPONENT_DEFINE ("AmrrWifiRemoteStation");
30 
31 namespace ns3 {
32 
34 {
36  uint32_t m_tx_ok;
37  uint32_t m_tx_err;
38  uint32_t m_tx_retr;
39  uint32_t m_retry;
40  uint32_t m_txrate;
42  uint32_t m_success;
43  bool m_recovery;
44 };
45 
46 
48 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
54  .AddConstructor<AmrrWifiManager> ()
55  .AddAttribute ("UpdatePeriod",
56  "The interval between decisions about rate control changes",
57  TimeValue (Seconds (1.0)),
58  MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod),
59  MakeTimeChecker ())
60  .AddAttribute ("FailureRatio",
61  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
62  DoubleValue (1.0 / 3.0),
63  MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
64  MakeDoubleChecker<double> (0.0, 1.0))
65  .AddAttribute ("SuccessRatio",
66  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
67  DoubleValue (1.0 / 10.0),
68  MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
69  MakeDoubleChecker<double> (0.0, 1.0))
70  .AddAttribute ("MaxSuccessThreshold",
71  "Maximum number of consecutive success periods needed to switch to a higher rate",
72  UintegerValue (10),
73  MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold),
74  MakeUintegerChecker<uint32_t> ())
75  .AddAttribute ("MinSuccessThreshold",
76  "Minimum number of consecutive success periods needed to switch to a higher rate",
77  UintegerValue (1),
78  MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold),
79  MakeUintegerChecker<uint32_t> ())
80  ;
81  return tid;
82 }
83 
85 {
86  NS_LOG_FUNCTION (this);
87 }
88 
91 {
92  NS_LOG_FUNCTION (this);
95  station->m_tx_ok = 0;
96  station->m_tx_err = 0;
97  station->m_tx_retr = 0;
98  station->m_retry = 0;
99  station->m_txrate = 0;
101  station->m_success = 0;
102  station->m_recovery = false;
103  return station;
104 }
105 
106 
107 void
109  double rxSnr, WifiMode txMode)
110 {
111  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
112 }
113 void
115 {
116  NS_LOG_FUNCTION (this << station);
117 }
118 void
120 {
121  NS_LOG_FUNCTION (this << st);
123  station->m_retry++;
124  station->m_tx_retr++;
125 }
126 void
128  double ctsSnr, WifiMode ctsMode, double rtsSnr)
129 {
130  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
131 }
132 void
134  double ackSnr, WifiMode ackMode, double dataSnr)
135 {
136  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
138  station->m_retry = 0;
139  station->m_tx_ok++;
140 }
141 void
143 {
144  NS_LOG_FUNCTION (this << station);
145 }
146 void
148 {
149  NS_LOG_FUNCTION (this << st);
151  station->m_retry = 0;
152  station->m_tx_err++;
153 }
154 bool
156 {
157  NS_LOG_FUNCTION (this << station);
158  return (station->m_txrate == 0);
159 }
160 bool
162 {
163  NS_LOG_FUNCTION (this << station);
164  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
165  return (station->m_txrate + 1 == GetNSupported (station));
166 }
167 bool
169 {
170  NS_LOG_FUNCTION (this << station);
171  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
172 }
173 bool
175 {
176  NS_LOG_FUNCTION (this << station);
177  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
178 }
179 bool
181 {
182  NS_LOG_FUNCTION (this << station);
183  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
184 }
185 void
187 {
188  NS_LOG_FUNCTION (this << station);
189  station->m_tx_ok = 0;
190  station->m_tx_err = 0;
191  station->m_tx_retr = 0;
192 }
193 void
195 {
196  NS_LOG_FUNCTION (this << station);
197  station->m_txrate++;
198  NS_ASSERT (station->m_txrate < GetNSupported (station));
199 }
200 void
202 {
203  NS_LOG_FUNCTION (this << station);
204  station->m_txrate--;
205 }
206 
207 void
209 {
210  NS_LOG_FUNCTION (this << station);
211  if (Simulator::Now () < station->m_nextModeUpdate)
212  {
213  return;
214  }
216  NS_LOG_DEBUG ("Update");
217 
218  bool needChange = false;
219 
220  if (IsSuccess (station) && IsEnough (station))
221  {
222  station->m_success++;
223  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
224  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
225  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
226  if (station->m_success >= station->m_successThreshold
227  && !IsMaxRate (station))
228  {
229  station->m_recovery = true;
230  station->m_success = 0;
231  IncreaseRate (station);
232  needChange = true;
233  }
234  else
235  {
236  station->m_recovery = false;
237  }
238  }
239  else if (IsFailure (station))
240  {
241  station->m_success = 0;
242  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
243  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
244  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
245  if (!IsMinRate (station))
246  {
247  if (station->m_recovery)
248  {
249  station->m_successThreshold *= 2;
250  station->m_successThreshold = std::min (station->m_successThreshold,
252  }
253  else
254  {
256  }
257  station->m_recovery = false;
258  DecreaseRate (station);
259  needChange = true;
260  }
261  else
262  {
263  station->m_recovery = false;
264  }
265  }
266  if (IsEnough (station) || needChange)
267  {
268  NS_LOG_DEBUG ("Reset");
269  ResetCnt (station);
270  }
271 }
274 {
275  NS_LOG_FUNCTION (this << st << size);
277  UpdateMode (station);
278  NS_ASSERT (station->m_txrate < GetNSupported (station));
279  uint32_t rateIndex;
280  if (station->m_retry < 1)
281  {
282  rateIndex = station->m_txrate;
283  }
284  else if (station->m_retry < 2)
285  {
286  if (station->m_txrate > 0)
287  {
288  rateIndex = station->m_txrate - 1;
289  }
290  else
291  {
292  rateIndex = station->m_txrate;
293  }
294  }
295  else if (station->m_retry < 3)
296  {
297  if (station->m_txrate > 1)
298  {
299  rateIndex = station->m_txrate - 2;
300  }
301  else
302  {
303  rateIndex = station->m_txrate;
304  }
305  }
306  else
307  {
308  if (station->m_txrate > 2)
309  {
310  rateIndex = station->m_txrate - 3;
311  }
312  else
313  {
314  rateIndex = station->m_txrate;
315  }
316  }
317 
319 }
322 {
323  NS_LOG_FUNCTION (this << st);
325  UpdateMode (station);
328 }
329 
330 
331 bool
333 {
334  NS_LOG_FUNCTION (this);
335  return true;
336 }
337 
338 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
bool IsMinRate(AmrrWifiRemoteStation *station) const
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
virtual WifiRemoteStation * DoCreateStation(void) const
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
void ResetCnt(AmrrWifiRemoteStation *station)
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
#define NS_ASSERT(condition)
Definition: assert.h:64
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
virtual void DoReportRtsFailed(WifiRemoteStation *station)
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
bool GetStbc(const WifiRemoteStation *station) const
virtual bool IsLowLatency(void) const
bool IsFailure(AmrrWifiRemoteStation *station) const
hold objects of type ns3::Time
Definition: nstime.h:828
Hold an unsigned integer type.
Definition: uinteger.h:46
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual void DoReportDataFailed(WifiRemoteStation *station)
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
void DecreaseRate(AmrrWifiRemoteStation *station)
hold a list of per-remote-station state.
void IncreaseRate(AmrrWifiRemoteStation *station)
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
static TypeId GetTypeId(void)
bool GetShortGuardInterval(const WifiRemoteStation *station) const
static Time Now(void)
Definition: simulator.cc:180
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
bool IsSuccess(AmrrWifiRemoteStation *station) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
NS_LOG_COMPONENT_DEFINE("AmrrWifiRemoteStation")
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
void UpdateMode(AmrrWifiRemoteStation *station)
bool IsMaxRate(AmrrWifiRemoteStation *station) const
bool IsEnough(AmrrWifiRemoteStation *station) const
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range. Both limits are inclusive.
Definition: time.cc:404
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
hold per-remote-station state.