A Discrete-Event Network Simulator
API
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 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
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 TypeId
55 {
56  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
58  .AddConstructor<OnoeWifiManager> ()
59  .AddAttribute ("UpdatePeriod",
60  "The interval between decisions about rate control changes",
61  TimeValue (Seconds (1.0)),
63  MakeTimeChecker ())
64  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
65  UintegerValue (10),
67  MakeUintegerChecker<uint32_t> ())
68  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
69  UintegerValue (10),
71  MakeUintegerChecker<uint32_t> ())
72  ;
73  return tid;
74 }
75 
77 {
78 }
81 {
84  station->m_shortRetry = 0;
85  station->m_longRetry = 0;
86  station->m_tx_ok = 0;
87  station->m_tx_err = 0;
88  station->m_tx_retr = 0;
89  station->m_tx_upper = 0;
90  station->m_txrate = 0;
91  return station;
92 }
93 void
95  double rxSnr, WifiMode txMode)
96 {
97 }
98 void
100 {
102  station->m_shortRetry++;
103 }
104 void
106 {
108  station->m_longRetry++;
109 }
110 void
112  double ctsSnr, WifiMode ctsMode, double rtsSnr)
113 {
114 }
115 void
117  double ackSnr, WifiMode ackMode, double dataSnr)
118 {
120  UpdateRetry (station);
121  station->m_tx_ok++;
122 }
123 void
125 {
127  UpdateRetry (station);
128  station->m_tx_err++;
129 }
130 void
132 {
134  UpdateRetry (station);
135  station->m_tx_err++;
136 }
137 void
139 {
140  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
141  station->m_shortRetry = 0;
142  station->m_longRetry = 0;
143 }
144 void
146 {
147  if (Simulator::Now () < station->m_nextModeUpdate)
148  {
149  return;
150  }
157  int dir = 0, enough;
158  uint32_t nrate;
159  enough = (station->m_tx_ok + station->m_tx_err >= 10);
160 
161  /* no packet reached -> down */
162  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
163  {
164  dir = -1;
165  }
166 
167  /* all packets needs retry in average -> down */
168  if (enough && station->m_tx_ok < station->m_tx_retr)
169  {
170  dir = -1;
171  }
172 
173  /* no error and less than rate_raise% of packets need retry -> up */
174  if (enough && station->m_tx_err == 0
175  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
176  {
177  dir = 1;
178  }
179 
180  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
181  " upper " << station->m_tx_upper << " dir " << dir);
182 
183  nrate = station->m_txrate;
184  switch (dir)
185  {
186  case 0:
187  if (enough && station->m_tx_upper > 0)
188  {
189  station->m_tx_upper--;
190  }
191  break;
192  case -1:
193  if (nrate > 0)
194  {
195  nrate--;
196  }
197  station->m_tx_upper = 0;
198  break;
199  case 1:
200  /* raise rate if we hit rate_raise_threshold */
201  if (++station->m_tx_upper < m_raiseThreshold)
202  {
203  break;
204  }
205  station->m_tx_upper = 0;
206  if (nrate + 1 < GetNSupported (station))
207  {
208  nrate++;
209  }
210  break;
211  }
212 
213  if (nrate != station->m_txrate)
214  {
215  NS_ASSERT (nrate < GetNSupported (station));
216  station->m_txrate = nrate;
217  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
218  }
219  else if (enough)
220  {
221  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
222  }
223 
224 }
225 
228  uint32_t size)
229 {
231  UpdateMode (station);
232  NS_ASSERT (station->m_txrate < GetNSupported (station));
233  uint32_t rateIndex;
234  if (station->m_longRetry < 4)
235  {
236  rateIndex = station->m_txrate;
237  }
238  else if (station->m_longRetry < 6)
239  {
240  if (station->m_txrate > 0)
241  {
242  rateIndex = station->m_txrate - 1;
243  }
244  else
245  {
246  rateIndex = station->m_txrate;
247  }
248  }
249  else if (station->m_longRetry < 8)
250  {
251  if (station->m_txrate > 1)
252  {
253  rateIndex = station->m_txrate - 2;
254  }
255  else
256  {
257  rateIndex = station->m_txrate;
258  }
259  }
260  else
261  {
262  if (station->m_txrate > 2)
263  {
264  rateIndex = station->m_txrate - 3;
265  }
266  else
267  {
268  rateIndex = station->m_txrate;
269  }
270  }
271  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas()), GetNess (station), GetStbc (station));
272 }
275 {
277  UpdateMode (station);
280 }
281 
282 bool
284 {
285  return false;
286 }
287 
288 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
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...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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:93
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).
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:191
AttributeValue implementation for Time.
Definition: nstime.h:921
Hold an unsigned integer type.
Definition: uinteger.h:44
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.
uint32_t GetNess(const WifiRemoteStation *station) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:922
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
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)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:51
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:631
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.