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 
33 {
35  uint32_t m_shortRetry;
36  uint32_t m_longRetry;
37  uint32_t m_tx_ok;
38  uint32_t m_tx_err;
39  uint32_t m_tx_retr;
40  uint32_t m_tx_upper;
41  uint32_t m_txrate;
42 };
43 
44 
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
52  .AddConstructor<OnoeWifiManager> ()
53  .AddAttribute ("UpdatePeriod",
54  "The interval between decisions about rate control changes",
55  TimeValue (Seconds (1.0)),
56  MakeTimeAccessor (&OnoeWifiManager::m_updatePeriod),
57  MakeTimeChecker ())
58  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
59  UintegerValue (10),
60  MakeUintegerAccessor (&OnoeWifiManager::m_raiseThreshold),
61  MakeUintegerChecker<uint32_t> ())
62  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
63  UintegerValue (10),
64  MakeUintegerAccessor (&OnoeWifiManager::m_addCreditThreshold),
65  MakeUintegerChecker<uint32_t> ())
66  ;
67  return tid;
68 }
69 
71 {
72 }
75 {
78  station->m_shortRetry = 0;
79  station->m_longRetry = 0;
80  station->m_tx_ok = 0;
81  station->m_tx_err = 0;
82  station->m_tx_retr = 0;
83  station->m_tx_upper = 0;
84  station->m_txrate = 0;
85  return station;
86 }
87 void
89  double rxSnr, WifiMode txMode)
90 {
91 }
92 void
94 {
96  station->m_shortRetry++;
97 }
98 void
100 {
102  station->m_longRetry++;
103 }
104 void
106  double ctsSnr, WifiMode ctsMode, double rtsSnr)
107 {
108 }
109 void
111  double ackSnr, WifiMode ackMode, double dataSnr)
112 {
114  UpdateRetry (station);
115  station->m_tx_ok++;
116 }
117 void
119 {
121  UpdateRetry (station);
122  station->m_tx_err++;
123 }
124 void
126 {
128  UpdateRetry (station);
129  station->m_tx_err++;
130 }
131 void
133 {
134  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
135  station->m_shortRetry = 0;
136  station->m_longRetry = 0;
137 }
138 void
140 {
141  if (Simulator::Now () < station->m_nextModeUpdate)
142  {
143  return;
144  }
151  int dir = 0, enough;
152  uint32_t nrate;
153  enough = (station->m_tx_ok + station->m_tx_err >= 10);
154 
155  /* no packet reached -> down */
156  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
157  {
158  dir = -1;
159  }
160 
161  /* all packets needs retry in average -> down */
162  if (enough && station->m_tx_ok < station->m_tx_retr)
163  {
164  dir = -1;
165  }
166 
167  /* no error and less than rate_raise% of packets need retry -> up */
168  if (enough && station->m_tx_err == 0
169  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
170  {
171  dir = 1;
172  }
173 
174  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
175  " upper " << station->m_tx_upper << " dir " << dir);
176 
177  nrate = station->m_txrate;
178  switch (dir)
179  {
180  case 0:
181  if (enough && station->m_tx_upper > 0)
182  {
183  station->m_tx_upper--;
184  }
185  break;
186  case -1:
187  if (nrate > 0)
188  {
189  nrate--;
190  }
191  station->m_tx_upper = 0;
192  break;
193  case 1:
194  /* raise rate if we hit rate_raise_threshold */
195  if (++station->m_tx_upper < m_raiseThreshold)
196  {
197  break;
198  }
199  station->m_tx_upper = 0;
200  if (nrate + 1 < GetNSupported (station))
201  {
202  nrate++;
203  }
204  break;
205  }
206 
207  if (nrate != station->m_txrate)
208  {
209  NS_ASSERT (nrate < GetNSupported (station));
210  station->m_txrate = nrate;
211  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
212  }
213  else if (enough)
214  {
215  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
216  }
217 
218 }
219 
222  uint32_t size)
223 {
225  UpdateMode (station);
226  NS_ASSERT (station->m_txrate < GetNSupported (station));
227  uint32_t rateIndex;
228  if (station->m_longRetry < 4)
229  {
230  rateIndex = station->m_txrate;
231  }
232  else if (station->m_longRetry < 6)
233  {
234  if (station->m_txrate > 0)
235  {
236  rateIndex = station->m_txrate - 1;
237  }
238  else
239  {
240  rateIndex = station->m_txrate;
241  }
242  }
243  else if (station->m_longRetry < 8)
244  {
245  if (station->m_txrate > 1)
246  {
247  rateIndex = station->m_txrate - 2;
248  }
249  else
250  {
251  rateIndex = station->m_txrate;
252  }
253  }
254  else
255  {
256  if (station->m_txrate > 2)
257  {
258  rateIndex = station->m_txrate - 3;
259  }
260  else
261  {
262  rateIndex = station->m_txrate;
263  }
264  }
266 }
269 {
271  UpdateMode (station);
274 }
275 
276 bool
278 {
279  return false;
280 }
281 
282 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
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
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
void UpdateMode(OnoeWifiRemoteStation *station)
#define NS_ASSERT(condition)
Definition: assert.h:64
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
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
void UpdateRetry(OnoeWifiRemoteStation *station)
bool GetStbc(const WifiRemoteStation *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)
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Definition: int64x64.h:90
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
hold a list of per-remote-station state.
NS_LOG_COMPONENT_DEFINE("OnoeWifiRemoteStation")
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
bool GetShortGuardInterval(const WifiRemoteStation *station) const
static Time Now(void)
Definition: simulator.cc:180
virtual WifiRemoteStation * DoCreateStation(void) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
virtual void DoReportRtsFailed(WifiRemoteStation *station)
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
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
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
a unique identifier for an interface.
Definition: type-id.h:49
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
hold per-remote-station state.
virtual void DoReportDataFailed(WifiRemoteStation *station)