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 NS_LOG_COMPONENT_DEFINE ("AmrrWifiRemoteStation");
28 
29 namespace ns3 {
30 
32 {
34  uint32_t m_tx_ok;
35  uint32_t m_tx_err;
36  uint32_t m_tx_retr;
37  uint32_t m_retry;
38  uint32_t m_txrate;
40  uint32_t m_success;
41  bool m_recovery;
42 };
43 
44 
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
52  .AddConstructor<AmrrWifiManager> ()
53  .AddAttribute ("UpdatePeriod",
54  "The interval between decisions about rate control changes",
55  TimeValue (Seconds (1.0)),
56  MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod),
57  MakeTimeChecker ())
58  .AddAttribute ("FailureRatio",
59  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
60  DoubleValue (1.0 / 3.0),
61  MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
62  MakeDoubleChecker<double> (0.0, 1.0))
63  .AddAttribute ("SuccessRatio",
64  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
65  DoubleValue (1.0 / 10.0),
66  MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
67  MakeDoubleChecker<double> (0.0, 1.0))
68  .AddAttribute ("MaxSuccessThreshold",
69  "Maximum number of consecutive success periods needed to switch to a higher rate",
70  UintegerValue (10),
71  MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold),
72  MakeUintegerChecker<uint32_t> ())
73  .AddAttribute ("MinSuccessThreshold",
74  "Minimum number of consecutive success periods needed to switch to a higher rate",
75  UintegerValue (1),
76  MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold),
77  MakeUintegerChecker<uint32_t> ())
78  ;
79  return tid;
80 }
81 
83 {
84 }
85 
88 {
91  station->m_tx_ok = 0;
92  station->m_tx_err = 0;
93  station->m_tx_retr = 0;
94  station->m_retry = 0;
95  station->m_txrate = 0;
97  station->m_success = 0;
98  station->m_recovery = false;
99  return station;
100 }
101 
102 
103 void
105  double rxSnr, WifiMode txMode)
106 {
107 }
108 void
110 {
111 }
112 void
114 {
116  station->m_retry++;
117  station->m_tx_retr++;
118 }
119 void
121  double ctsSnr, WifiMode ctsMode, double rtsSnr)
122 {
123 }
124 void
126  double ackSnr, WifiMode ackMode, double dataSnr)
127 {
129  station->m_retry = 0;
130  station->m_tx_ok++;
131 }
132 void
134 {
135 }
136 void
138 {
140  station->m_retry = 0;
141  station->m_tx_err++;
142 }
143 bool
145 {
146  return (station->m_txrate == 0);
147 }
148 bool
150 {
151  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
152  return (station->m_txrate + 1 == GetNSupported (station));
153 }
154 bool
156 {
157  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
158 }
159 bool
161 {
162  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
163 }
164 bool
166 {
167  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
168 }
169 void
171 {
172  station->m_tx_ok = 0;
173  station->m_tx_err = 0;
174  station->m_tx_retr = 0;
175 }
176 void
178 {
179  station->m_txrate++;
180  NS_ASSERT (station->m_txrate < GetNSupported (station));
181 }
182 void
184 {
185  station->m_txrate--;
186 }
187 
188 void
190 {
191  if (Simulator::Now () < station->m_nextModeUpdate)
192  {
193  return;
194  }
196  NS_LOG_DEBUG ("Update");
197 
198  bool needChange = false;
199 
200  if (IsSuccess (station) && IsEnough (station))
201  {
202  station->m_success++;
203  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
204  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
205  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
206  if (station->m_success >= station->m_successThreshold
207  && !IsMaxRate (station))
208  {
209  station->m_recovery = true;
210  station->m_success = 0;
211  IncreaseRate (station);
212  needChange = true;
213  }
214  else
215  {
216  station->m_recovery = false;
217  }
218  }
219  else if (IsFailure (station))
220  {
221  station->m_success = 0;
222  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
223  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
224  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
225  if (!IsMinRate (station))
226  {
227  if (station->m_recovery)
228  {
229  station->m_successThreshold *= 2;
230  station->m_successThreshold = std::min (station->m_successThreshold,
232  }
233  else
234  {
236  }
237  station->m_recovery = false;
238  DecreaseRate (station);
239  needChange = true;
240  }
241  else
242  {
243  station->m_recovery = false;
244  }
245  }
246  if (IsEnough (station) || needChange)
247  {
248  NS_LOG_DEBUG ("Reset");
249  ResetCnt (station);
250  }
251 }
252 WifiMode
254 {
256  UpdateMode (station);
257  NS_ASSERT (station->m_txrate < GetNSupported (station));
258  uint32_t rateIndex;
259  if (station->m_retry < 1)
260  {
261  rateIndex = station->m_txrate;
262  }
263  else if (station->m_retry < 2)
264  {
265  if (station->m_txrate > 0)
266  {
267  rateIndex = station->m_txrate - 1;
268  }
269  else
270  {
271  rateIndex = station->m_txrate;
272  }
273  }
274  else if (station->m_retry < 3)
275  {
276  if (station->m_txrate > 1)
277  {
278  rateIndex = station->m_txrate - 2;
279  }
280  else
281  {
282  rateIndex = station->m_txrate;
283  }
284  }
285  else
286  {
287  if (station->m_txrate > 2)
288  {
289  rateIndex = station->m_txrate - 3;
290  }
291  else
292  {
293  rateIndex = station->m_txrate;
294  }
295  }
296 
297  return GetSupported (station, rateIndex);
298 }
299 WifiMode
301 {
303  UpdateMode (station);
304  // XXX: can we implement something smarter ?
305  return GetSupported (station, 0);
306 }
307 
308 
309 bool
311 {
312  return true;
313 }
314 
315 } // namespace ns3