A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
onoe-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 "onoe-wifi-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 
26 #define Min(a,b) ((a < b) ? a : b)
27 
28 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
29 
30 namespace ns3 {
31 
39 {
41  uint32_t m_shortRetry;
42  uint32_t m_longRetry;
43  uint32_t m_tx_ok;
44  uint32_t m_tx_err;
45  uint32_t m_tx_retr;
46  uint32_t m_tx_upper;
47  uint32_t m_txrate;
48 };
49 
50 
52  ;
53 
54 TypeId
56 {
57  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
59  .AddConstructor<OnoeWifiManager> ()
60  .AddAttribute ("UpdatePeriod",
61  "The interval between decisions about rate control changes",
62  TimeValue (Seconds (1.0)),
63  MakeTimeAccessor (&OnoeWifiManager::m_updatePeriod),
64  MakeTimeChecker ())
65  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
66  UintegerValue (10),
67  MakeUintegerAccessor (&OnoeWifiManager::m_raiseThreshold),
68  MakeUintegerChecker<uint32_t> ())
69  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
70  UintegerValue (10),
71  MakeUintegerAccessor (&OnoeWifiManager::m_addCreditThreshold),
72  MakeUintegerChecker<uint32_t> ())
73  ;
74  return tid;
75 }
76 
78 {
79 }
82 {
85  station->m_shortRetry = 0;
86  station->m_longRetry = 0;
87  station->m_tx_ok = 0;
88  station->m_tx_err = 0;
89  station->m_tx_retr = 0;
90  station->m_tx_upper = 0;
91  station->m_txrate = 0;
92  return station;
93 }
94 void
96  double rxSnr, WifiMode txMode)
97 {
98 }
99 void
101 {
103  station->m_shortRetry++;
104 }
105 void
107 {
109  station->m_longRetry++;
110 }
111 void
113  double ctsSnr, WifiMode ctsMode, double rtsSnr)
114 {
115 }
116 void
118  double ackSnr, WifiMode ackMode, double dataSnr)
119 {
121  UpdateRetry (station);
122  station->m_tx_ok++;
123 }
124 void
126 {
128  UpdateRetry (station);
129  station->m_tx_err++;
130 }
131 void
133 {
135  UpdateRetry (station);
136  station->m_tx_err++;
137 }
138 void
140 {
141  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
142  station->m_shortRetry = 0;
143  station->m_longRetry = 0;
144 }
145 void
147 {
148  if (Simulator::Now () < station->m_nextModeUpdate)
149  {
150  return;
151  }
158  int dir = 0, enough;
159  uint32_t nrate;
160  enough = (station->m_tx_ok + station->m_tx_err >= 10);
161 
162  /* no packet reached -> down */
163  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
164  {
165  dir = -1;
166  }
167 
168  /* all packets needs retry in average -> down */
169  if (enough && station->m_tx_ok < station->m_tx_retr)
170  {
171  dir = -1;
172  }
173 
174  /* no error and less than rate_raise% of packets need retry -> up */
175  if (enough && station->m_tx_err == 0
176  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
177  {
178  dir = 1;
179  }
180 
181  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
182  " upper " << station->m_tx_upper << " dir " << dir);
183 
184  nrate = station->m_txrate;
185  switch (dir)
186  {
187  case 0:
188  if (enough && station->m_tx_upper > 0)
189  {
190  station->m_tx_upper--;
191  }
192  break;
193  case -1:
194  if (nrate > 0)
195  {
196  nrate--;
197  }
198  station->m_tx_upper = 0;
199  break;
200  case 1:
201  /* raise rate if we hit rate_raise_threshold */
202  if (++station->m_tx_upper < m_raiseThreshold)
203  {
204  break;
205  }
206  station->m_tx_upper = 0;
207  if (nrate + 1 < GetNSupported (station))
208  {
209  nrate++;
210  }
211  break;
212  }
213 
214  if (nrate != station->m_txrate)
215  {
216  NS_ASSERT (nrate < GetNSupported (station));
217  station->m_txrate = nrate;
218  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
219  }
220  else if (enough)
221  {
222  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
223  }
224 
225 }
226 
229  uint32_t size)
230 {
232  UpdateMode (station);
233  NS_ASSERT (station->m_txrate < GetNSupported (station));
234  uint32_t rateIndex;
235  if (station->m_longRetry < 4)
236  {
237  rateIndex = station->m_txrate;
238  }
239  else if (station->m_longRetry < 6)
240  {
241  if (station->m_txrate > 0)
242  {
243  rateIndex = station->m_txrate - 1;
244  }
245  else
246  {
247  rateIndex = station->m_txrate;
248  }
249  }
250  else if (station->m_longRetry < 8)
251  {
252  if (station->m_txrate > 1)
253  {
254  rateIndex = station->m_txrate - 2;
255  }
256  else
257  {
258  rateIndex = station->m_txrate;
259  }
260  }
261  else
262  {
263  if (station->m_txrate > 2)
264  {
265  rateIndex = station->m_txrate - 3;
266  }
267  else
268  {
269  rateIndex = station->m_txrate;
270  }
271  }
273 }
276 {
278  UpdateMode (station);
281 }
282 
283 bool
285 {
286  return false;
287 }
288 
289 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
an implementation of the rate control algorithm developed by Atsushi Onoe
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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.
void UpdateMode(OnoeWifiRemoteStation *station)
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual bool IsLowLatency(void) const
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
static TypeId GetTypeId(void)
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. ...
void UpdateRetry(OnoeWifiRemoteStation *station)
Update the number of retry (both short and long).
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold a list of per-remote-station state.
NS_LOG_COMPONENT_DEFINE("OnoeWifiRemoteStation")
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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 WifiRemoteStation * DoCreateStation(void) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold per-remote-station state for ONOE Wifi manager.
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:452
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
a unique identifier for an interface.
Definition: type-id.h:49
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.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
hold per-remote-station state.
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.