A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
amrr-wifi-manager.cc
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 {
33  Time m_nextModeUpdate;
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;
39  uint32_t m_successThreshold;
40  uint32_t m_success;
41  bool m_recovery;
42 };
43 
44 
45 NS_OBJECT_ENSURE_REGISTERED (AmrrWifiManager);
46 
47 TypeId
48 AmrrWifiManager::GetTypeId (void)
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 
82 AmrrWifiManager::AmrrWifiManager ()
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
87 WifiRemoteStation *
89 {
90  NS_LOG_FUNCTION (this);
92  station->m_nextModeUpdate = Simulator::Now () + m_updatePeriod;
93  station->m_tx_ok = 0;
94  station->m_tx_err = 0;
95  station->m_tx_retr = 0;
96  station->m_retry = 0;
97  station->m_txrate = 0;
98  station->m_successThreshold = m_minSuccessThreshold;
99  station->m_success = 0;
100  station->m_recovery = false;
101  return station;
102 }
103 
104 
105 void
106 AmrrWifiManager::DoReportRxOk (WifiRemoteStation *station,
107  double rxSnr, WifiMode txMode)
108 {
109  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
110 }
111 void
112 AmrrWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
113 {
114  NS_LOG_FUNCTION (this << station);
115 }
116 void
117 AmrrWifiManager::DoReportDataFailed (WifiRemoteStation *st)
118 {
119  NS_LOG_FUNCTION (this << st);
120  AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
121  station->m_retry++;
122  station->m_tx_retr++;
123 }
124 void
125 AmrrWifiManager::DoReportRtsOk (WifiRemoteStation *st,
126  double ctsSnr, WifiMode ctsMode, double rtsSnr)
127 {
128  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
129 }
130 void
131 AmrrWifiManager::DoReportDataOk (WifiRemoteStation *st,
132  double ackSnr, WifiMode ackMode, double dataSnr)
133 {
134  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
135  AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
136  station->m_retry = 0;
137  station->m_tx_ok++;
138 }
139 void
140 AmrrWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
141 {
142  NS_LOG_FUNCTION (this << station);
143 }
144 void
145 AmrrWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
146 {
147  NS_LOG_FUNCTION (this << st);
148  AmrrWifiRemoteStation *station = (AmrrWifiRemoteStation *)st;
149  station->m_retry = 0;
150  station->m_tx_err++;
151 }
152 bool
153 AmrrWifiManager::IsMinRate (AmrrWifiRemoteStation *station) const
154 {
155  NS_LOG_FUNCTION (this << station);
156  return (station->m_txrate == 0);
157 }
158 bool
159 AmrrWifiManager::IsMaxRate (AmrrWifiRemoteStation *station) const
160 {
161  NS_LOG_FUNCTION (this << station);
162  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
163  return (station->m_txrate + 1 == GetNSupported (station));
164 }
165 bool
166 AmrrWifiManager::IsSuccess (AmrrWifiRemoteStation *station) const
167 {
168  NS_LOG_FUNCTION (this << station);
169  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
170 }
171 bool
172 AmrrWifiManager::IsFailure (AmrrWifiRemoteStation *station) const
173 {
174  NS_LOG_FUNCTION (this << station);
175  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
176 }
177 bool
178 AmrrWifiManager::IsEnough (AmrrWifiRemoteStation *station) const
179 {
180  NS_LOG_FUNCTION (this << station);
181  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
182 }
183 void
184 AmrrWifiManager::ResetCnt (AmrrWifiRemoteStation *station)
185 {
186  NS_LOG_FUNCTION (this << station);
187  station->m_tx_ok = 0;
188  station->m_tx_err = 0;
189  station->m_tx_retr = 0;
190 }
191 void
192 AmrrWifiManager::IncreaseRate (AmrrWifiRemoteStation *station)
193 {
194  NS_LOG_FUNCTION (this << station);
195  station->m_txrate++;
196  NS_ASSERT (station->m_txrate < GetNSupported (station));
197 }
198 void
199 AmrrWifiManager::DecreaseRate (AmrrWifiRemoteStation *station)
200 {
201  NS_LOG_FUNCTION (this << station);
202  station->m_txrate--;
203 }
204 
205 void
206 AmrrWifiManager::UpdateMode (AmrrWifiRemoteStation *station)
207 {
208  NS_LOG_FUNCTION (this << station);
209  if (Simulator::Now () < station->m_nextModeUpdate)
210  {
211  return;
212  }
213  station->m_nextModeUpdate = Simulator::Now () + m_updatePeriod;
214  NS_LOG_DEBUG ("Update");
215 
216  bool needChange = false;
217 
218  if (IsSuccess (station) && IsEnough (station))
219  {
220  station->m_success++;
221  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
222  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
223  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
224  if (station->m_success >= station->m_successThreshold
225  && !IsMaxRate (station))
226  {
227  station->m_recovery = true;
228  station->m_success = 0;
229  IncreaseRate (station);
230  needChange = true;
231  }
232  else
233  {
234  station->m_recovery = false;
235  }
236  }
237  else if (IsFailure (station))
238  {
239  station->m_success = 0;
240  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
241  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
242  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
243  if (!IsMinRate (station))
244  {
245  if (station->m_recovery)
246  {
247  station->m_successThreshold *= 2;
248  station->m_successThreshold = std::min (station->m_successThreshold,
249  m_maxSuccessThreshold);
250  }
251  else
252  {
253  station->m_successThreshold = m_minSuccessThreshold;
254  }
255  station->m_recovery = false;
256  DecreaseRate (station);
257  needChange = true;
258  }
259  else
260  {
261  station->m_recovery = false;
262  }
263  }
264  if (IsEnough (station) || needChange)
265  {
266  NS_LOG_DEBUG ("Reset");
267  ResetCnt (station);
268  }
269 }
270 WifiMode
272 {
273  NS_LOG_FUNCTION (this << st << size);
275  UpdateMode (station);
276  NS_ASSERT (station->m_txrate < GetNSupported (station));
277  uint32_t rateIndex;
278  if (station->m_retry < 1)
279  {
280  rateIndex = station->m_txrate;
281  }
282  else if (station->m_retry < 2)
283  {
284  if (station->m_txrate > 0)
285  {
286  rateIndex = station->m_txrate - 1;
287  }
288  else
289  {
290  rateIndex = station->m_txrate;
291  }
292  }
293  else if (station->m_retry < 3)
294  {
295  if (station->m_txrate > 1)
296  {
297  rateIndex = station->m_txrate - 2;
298  }
299  else
300  {
301  rateIndex = station->m_txrate;
302  }
303  }
304  else
305  {
306  if (station->m_txrate > 2)
307  {
308  rateIndex = station->m_txrate - 3;
309  }
310  else
311  {
312  rateIndex = station->m_txrate;
313  }
314  }
315 
316  return GetSupported (station, rateIndex);
317 }
318 WifiMode
320 {
321  NS_LOG_FUNCTION (this << st);
323  UpdateMode (station);
324  // XXX: can we implement something smarter ?
325  return GetSupported (station, 0);
326 }
327 
328 
329 bool
331 {
332  NS_LOG_FUNCTION (this);
333  return true;
334 }
335 
336 } // namespace ns3
keep track of time unit.
Definition: nstime.h:149
#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
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
virtual bool IsLowLatency(void) const
hold objects of type ns3::Time
Definition: nstime.h:700
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
hold a list of per-remote-station state.
static Time Now(void)
Definition: simulator.cc:179
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
hold per-remote-station state.