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 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
27 
28 namespace ns3 {
29 
31 {
33  uint32_t m_shortRetry;
34  uint32_t m_longRetry;
35  uint32_t m_tx_ok;
36  uint32_t m_tx_err;
37  uint32_t m_tx_retr;
38  uint32_t m_tx_upper;
39  uint32_t m_txrate;
40 };
41 
42 
44 
45 TypeId
47 {
48  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
50  .AddConstructor<OnoeWifiManager> ()
51  .AddAttribute ("UpdatePeriod",
52  "The interval between decisions about rate control changes",
53  TimeValue (Seconds (1.0)),
54  MakeTimeAccessor (&OnoeWifiManager::m_updatePeriod),
55  MakeTimeChecker ())
56  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
57  UintegerValue (10),
58  MakeUintegerAccessor (&OnoeWifiManager::m_raiseThreshold),
59  MakeUintegerChecker<uint32_t> ())
60  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
61  UintegerValue (10),
62  MakeUintegerAccessor (&OnoeWifiManager::m_addCreditThreshold),
63  MakeUintegerChecker<uint32_t> ())
64  ;
65  return tid;
66 }
67 
69 {
70 }
73 {
76  station->m_shortRetry = 0;
77  station->m_longRetry = 0;
78  station->m_tx_ok = 0;
79  station->m_tx_err = 0;
80  station->m_tx_retr = 0;
81  station->m_tx_upper = 0;
82  station->m_txrate = 0;
83  return station;
84 }
85 void
87  double rxSnr, WifiMode txMode)
88 {
89 }
90 void
92 {
94  station->m_shortRetry++;
95 }
96 void
98 {
100  station->m_longRetry++;
101 }
102 void
104  double ctsSnr, WifiMode ctsMode, double rtsSnr)
105 {
106 }
107 void
109  double ackSnr, WifiMode ackMode, double dataSnr)
110 {
112  UpdateRetry (station);
113  station->m_tx_ok++;
114 }
115 void
117 {
119  UpdateRetry (station);
120  station->m_tx_err++;
121 }
122 void
124 {
126  UpdateRetry (station);
127  station->m_tx_err++;
128 }
129 void
131 {
132  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
133  station->m_shortRetry = 0;
134  station->m_longRetry = 0;
135 }
136 void
138 {
139  if (Simulator::Now () < station->m_nextModeUpdate)
140  {
141  return;
142  }
149  int dir = 0, enough;
150  uint32_t nrate;
151  enough = (station->m_tx_ok + station->m_tx_err >= 10);
152 
153  /* no packet reached -> down */
154  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
155  {
156  dir = -1;
157  }
158 
159  /* all packets needs retry in average -> down */
160  if (enough && station->m_tx_ok < station->m_tx_retr)
161  {
162  dir = -1;
163  }
164 
165  /* no error and less than rate_raise% of packets need retry -> up */
166  if (enough && station->m_tx_err == 0
167  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
168  {
169  dir = 1;
170  }
171 
172  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
173  " upper " << station->m_tx_upper << " dir " << dir);
174 
175  nrate = station->m_txrate;
176  switch (dir)
177  {
178  case 0:
179  if (enough && station->m_tx_upper > 0)
180  {
181  station->m_tx_upper--;
182  }
183  break;
184  case -1:
185  if (nrate > 0)
186  {
187  nrate--;
188  }
189  station->m_tx_upper = 0;
190  break;
191  case 1:
192  /* raise rate if we hit rate_raise_threshold */
193  if (++station->m_tx_upper < m_raiseThreshold)
194  {
195  break;
196  }
197  station->m_tx_upper = 0;
198  if (nrate + 1 < GetNSupported (station))
199  {
200  nrate++;
201  }
202  break;
203  }
204 
205  if (nrate != station->m_txrate)
206  {
207  NS_ASSERT (nrate < GetNSupported (station));
208  station->m_txrate = nrate;
209  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
210  }
211  else if (enough)
212  {
213  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
214  }
215 
216 }
217 
218 WifiMode
220  uint32_t size)
221 {
223  UpdateMode (station);
224  NS_ASSERT (station->m_txrate < GetNSupported (station));
225  uint32_t rateIndex;
226  if (station->m_longRetry < 4)
227  {
228  rateIndex = station->m_txrate;
229  }
230  else if (station->m_longRetry < 6)
231  {
232  if (station->m_txrate > 0)
233  {
234  rateIndex = station->m_txrate - 1;
235  }
236  else
237  {
238  rateIndex = station->m_txrate;
239  }
240  }
241  else if (station->m_longRetry < 8)
242  {
243  if (station->m_txrate > 1)
244  {
245  rateIndex = station->m_txrate - 2;
246  }
247  else
248  {
249  rateIndex = station->m_txrate;
250  }
251  }
252  else
253  {
254  if (station->m_txrate > 2)
255  {
256  rateIndex = station->m_txrate - 3;
257  }
258  else
259  {
260  rateIndex = station->m_txrate;
261  }
262  }
263  return GetSupported (station, rateIndex);
264 }
265 WifiMode
267 {
269  UpdateMode (station);
270  // XXX: can we implement something smarter ?
271  return GetSupported (station, 0);
272 }
273 
274 bool
276 {
277  return false;
278 }
279 
280 } // namespace ns3