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 
40 {
42  uint32_t m_tx_ok;
43  uint32_t m_tx_err;
44  uint32_t m_tx_retr;
45  uint32_t m_retry;
46  uint32_t m_txrate;
48  uint32_t m_success;
49  bool m_recovery;
50 };
51 
52 
54  ;
55 
56 TypeId
58 {
59  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
61  .AddConstructor<AmrrWifiManager> ()
62  .AddAttribute ("UpdatePeriod",
63  "The interval between decisions about rate control changes",
64  TimeValue (Seconds (1.0)),
65  MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod),
66  MakeTimeChecker ())
67  .AddAttribute ("FailureRatio",
68  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
69  DoubleValue (1.0 / 3.0),
70  MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
71  MakeDoubleChecker<double> (0.0, 1.0))
72  .AddAttribute ("SuccessRatio",
73  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
74  DoubleValue (1.0 / 10.0),
75  MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
76  MakeDoubleChecker<double> (0.0, 1.0))
77  .AddAttribute ("MaxSuccessThreshold",
78  "Maximum number of consecutive success periods needed to switch to a higher rate",
79  UintegerValue (10),
80  MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold),
81  MakeUintegerChecker<uint32_t> ())
82  .AddAttribute ("MinSuccessThreshold",
83  "Minimum number of consecutive success periods needed to switch to a higher rate",
84  UintegerValue (1),
85  MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold),
86  MakeUintegerChecker<uint32_t> ())
87  ;
88  return tid;
89 }
90 
92 {
93  NS_LOG_FUNCTION (this);
94 }
95 
98 {
99  NS_LOG_FUNCTION (this);
102  station->m_tx_ok = 0;
103  station->m_tx_err = 0;
104  station->m_tx_retr = 0;
105  station->m_retry = 0;
106  station->m_txrate = 0;
108  station->m_success = 0;
109  station->m_recovery = false;
110  return station;
111 }
112 
113 
114 void
116  double rxSnr, WifiMode txMode)
117 {
118  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
119 }
120 void
122 {
123  NS_LOG_FUNCTION (this << station);
124 }
125 void
127 {
128  NS_LOG_FUNCTION (this << st);
130  station->m_retry++;
131  station->m_tx_retr++;
132 }
133 void
135  double ctsSnr, WifiMode ctsMode, double rtsSnr)
136 {
137  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
138 }
139 void
141  double ackSnr, WifiMode ackMode, double dataSnr)
142 {
143  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
145  station->m_retry = 0;
146  station->m_tx_ok++;
147 }
148 void
150 {
151  NS_LOG_FUNCTION (this << station);
152 }
153 void
155 {
156  NS_LOG_FUNCTION (this << st);
158  station->m_retry = 0;
159  station->m_tx_err++;
160 }
161 bool
163 {
164  NS_LOG_FUNCTION (this << station);
165  return (station->m_txrate == 0);
166 }
167 bool
169 {
170  NS_LOG_FUNCTION (this << station);
171  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
172  return (station->m_txrate + 1 == GetNSupported (station));
173 }
174 bool
176 {
177  NS_LOG_FUNCTION (this << station);
178  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
179 }
180 bool
182 {
183  NS_LOG_FUNCTION (this << station);
184  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
185 }
186 bool
188 {
189  NS_LOG_FUNCTION (this << station);
190  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
191 }
192 void
194 {
195  NS_LOG_FUNCTION (this << station);
196  station->m_tx_ok = 0;
197  station->m_tx_err = 0;
198  station->m_tx_retr = 0;
199 }
200 void
202 {
203  NS_LOG_FUNCTION (this << station);
204  station->m_txrate++;
205  NS_ASSERT (station->m_txrate < GetNSupported (station));
206 }
207 void
209 {
210  NS_LOG_FUNCTION (this << station);
211  station->m_txrate--;
212 }
213 
214 void
216 {
217  NS_LOG_FUNCTION (this << station);
218  if (Simulator::Now () < station->m_nextModeUpdate)
219  {
220  return;
221  }
223  NS_LOG_DEBUG ("Update");
224 
225  bool needChange = false;
226 
227  if (IsSuccess (station) && IsEnough (station))
228  {
229  station->m_success++;
230  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
231  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
232  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
233  if (station->m_success >= station->m_successThreshold
234  && !IsMaxRate (station))
235  {
236  station->m_recovery = true;
237  station->m_success = 0;
238  IncreaseRate (station);
239  needChange = true;
240  }
241  else
242  {
243  station->m_recovery = false;
244  }
245  }
246  else if (IsFailure (station))
247  {
248  station->m_success = 0;
249  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
250  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
251  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
252  if (!IsMinRate (station))
253  {
254  if (station->m_recovery)
255  {
256  station->m_successThreshold *= 2;
257  station->m_successThreshold = std::min (station->m_successThreshold,
259  }
260  else
261  {
263  }
264  station->m_recovery = false;
265  DecreaseRate (station);
266  needChange = true;
267  }
268  else
269  {
270  station->m_recovery = false;
271  }
272  }
273  if (IsEnough (station) || needChange)
274  {
275  NS_LOG_DEBUG ("Reset");
276  ResetCnt (station);
277  }
278 }
281 {
282  NS_LOG_FUNCTION (this << st << size);
284  UpdateMode (station);
285  NS_ASSERT (station->m_txrate < GetNSupported (station));
286  uint32_t rateIndex;
287  if (station->m_retry < 1)
288  {
289  rateIndex = station->m_txrate;
290  }
291  else if (station->m_retry < 2)
292  {
293  if (station->m_txrate > 0)
294  {
295  rateIndex = station->m_txrate - 1;
296  }
297  else
298  {
299  rateIndex = station->m_txrate;
300  }
301  }
302  else if (station->m_retry < 3)
303  {
304  if (station->m_txrate > 1)
305  {
306  rateIndex = station->m_txrate - 2;
307  }
308  else
309  {
310  rateIndex = station->m_txrate;
311  }
312  }
313  else
314  {
315  if (station->m_txrate > 2)
316  {
317  rateIndex = station->m_txrate - 3;
318  }
319  else
320  {
321  rateIndex = station->m_txrate;
322  }
323  }
324 
326 }
329 {
330  NS_LOG_FUNCTION (this << st);
332  UpdateMode (station);
335 }
336 
337 
338 bool
340 {
341  NS_LOG_FUNCTION (this);
342  return true;
343 }
344 
345 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool IsMinRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the minimum rate.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
virtual WifiRemoteStation * DoCreateStation(void) const
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void ResetCnt(AmrrWifiRemoteStation *station)
Reset transmission statistics of the given station.
hold per-remote-station state for AMRR Wifi manager.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
Return the number of receive antenna the station has.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
virtual bool IsLowLatency(void) const
bool IsFailure(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is greater than the number of successful...
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
void DecreaseRate(AmrrWifiRemoteStation *station)
Decrease the transmission rate to the given station.
hold a list of per-remote-station state.
void IncreaseRate(AmrrWifiRemoteStation *station)
Increase the transmission rate to the given station.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
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.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId(void)
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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.
bool IsSuccess(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is less than the number of successful tr...
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
NS_LOG_COMPONENT_DEFINE("AmrrWifiRemoteStation")
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
void UpdateMode(AmrrWifiRemoteStation *station)
Update the mode used to send to the given station.
bool IsMaxRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the maximum rate.
bool IsEnough(AmrrWifiRemoteStation *station) const
Check if the number of retransmission, transmission error, and successful transmission are greater th...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:452
Hold a 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:611
hold per-remote-station state.