View | Details | Raw Unified | Return to bug 2654
Collapse All | Expand All

(-)a/src/wifi/model/rraa-wifi-manager.cc (-251 / +217 lines)
 Lines 19-24    Link Here 
19
 */
19
 */
20
20
21
#include "rraa-wifi-manager.h"
21
#include "rraa-wifi-manager.h"
22
#include "yans-wifi-phy.h"
23
#include "wifi-phy.h"
24
#include "wifi-mac.h"
22
#include "ns3/log.h"
25
#include "ns3/log.h"
23
#include "ns3/boolean.h"
26
#include "ns3/boolean.h"
24
#include "ns3/double.h"
27
#include "ns3/double.h"
 Lines 39-53    Link Here 
39
 */
42
 */
40
struct RraaWifiRemoteStation : public WifiRemoteStation
43
struct RraaWifiRemoteStation : public WifiRemoteStation
41
{
44
{
42
  uint32_t m_counter; ///< counter
45
  uint32_t m_counter;            //!< Counter for transmission attempts.
43
  uint32_t m_failed; ///< failed
46
  uint32_t m_nFailed;            //!< Number of failed transmission attempts.
44
  uint32_t m_rtsWnd; ///< RTS windows
47
  uint32_t m_adaptiveRtsWnd;     //!< Window size for the Adaptive RTS mechanism.
45
  uint32_t m_rtsCounter; ///< RTS counter
48
  uint32_t m_rtsCounter;         //!< Counter for RTS transmission attempts.
46
  Time m_lastReset; ///< last reset
49
  Time m_lastReset;              //!< Time of the last reset.
47
  bool m_rtsOn; ///< RTS on
50
  bool m_adaptiveRtsOn;          //!< Check if Adaptive RTS mechanism is on.
48
  bool m_lastFrameFail; ///< last frame fail
51
  bool m_lastFrameFail;          //!< Flag if the last frame sent has failed.
49
  bool m_initialized; ///< initialized
52
  bool m_initialized;            //!< For initializing variables.
50
  uint32_t m_rate; ///< rate
53
  
54
  uint32_t m_nRate;              //!< Number of supported rates.
55
56
  uint32_t m_rateIndex;          //!< Current rate index.
57
58
  RraaThresholdsTable m_thresholds; //!< RRAA thresholds for this station.
51
};
59
};
52
60
53
NS_OBJECT_ENSURE_REGISTERED (RraaWifiManager);
61
NS_OBJECT_ENSURE_REGISTERED (RraaWifiManager);
 Lines 65-184    Link Here 
65
                   MakeBooleanAccessor (&RraaWifiManager::m_basic),
73
                   MakeBooleanAccessor (&RraaWifiManager::m_basic),
66
                   MakeBooleanChecker ())
74
                   MakeBooleanChecker ())
67
    .AddAttribute ("Timeout",
75
    .AddAttribute ("Timeout",
68
                   "Timeout for the RRAA BASIC loss estimaton block (s)",
76
                   "Timeout for the RRAA BASIC loss estimation block (s)",
69
                   TimeValue (Seconds (0.05)),
77
                   TimeValue (Seconds (0.05)),
70
                   MakeTimeAccessor (&RraaWifiManager::m_timeout),
78
                   MakeTimeAccessor (&RraaWifiManager::m_timeout),
71
                   MakeTimeChecker ())
79
                   MakeTimeChecker ())
72
    .AddAttribute ("ewndFor54mbps",
80
    .AddAttribute ("FrameLength",
73
                   "ewnd parameter for 54 Mbs data mode",
81
		   "The data frame length (in bytes) used for calculating mode TxTime.",
74
                   UintegerValue (40),
82
		   UintegerValue (1420),
75
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor54),
83
		   MakeUintegerAccessor (&RraaWifiManager::m_frameLength),
76
                   MakeUintegerChecker<uint32_t> ())
84
		   MakeUintegerChecker <uint32_t> ())
77
    .AddAttribute ("ewndFor48mbps",
85
    .AddAttribute ("AckFrameLength",
78
                   "ewnd parameter for 48 Mbs data mode",
86
		   "The ACK frame length (in bytes) used for calculating mode TxTime.",
79
                   UintegerValue (40),
87
		   UintegerValue (14),
80
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor48),
88
		   MakeUintegerAccessor (&RraaWifiManager::m_ackLength),
81
                   MakeUintegerChecker<uint32_t> ())
89
		   MakeUintegerChecker <uint32_t> ())
82
    .AddAttribute ("ewndFor36mbps",
90
    .AddAttribute ("Alpha",
83
                   "ewnd parameter for 36 Mbs data mode",
91
		   "Constant for calculating the MTL threshold.",
84
                   UintegerValue (40),
92
		   DoubleValue (1.25),
85
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor36),
93
		   MakeDoubleAccessor (&RraaWifiManager::m_alpha),
86
                   MakeUintegerChecker<uint32_t> ())
94
		   MakeDoubleChecker<double> (1))
87
    .AddAttribute ("ewndFor24mbps",
95
    .AddAttribute ("Beta",
88
                   "ewnd parameter for 24 Mbs data mode",
96
		   "Constant for calculating the ORI threshold.",
89
                   UintegerValue (40),
97
		   DoubleValue (2),
90
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor24),
98
		   MakeDoubleAccessor (&RraaWifiManager::m_beta),
91
                   MakeUintegerChecker<uint32_t> ())
99
		   MakeDoubleChecker<double> (1))
92
    .AddAttribute ("ewndFor18mbps",
100
    .AddAttribute ("Tau",
93
                   "ewnd parameter for 18 Mbs data mode",
101
		   "Constant for calculating the EWND size.",
94
                   UintegerValue (20),
102
		   DoubleValue (0.012),
95
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor18),
103
		   MakeDoubleAccessor (&RraaWifiManager::m_tau),
96
                   MakeUintegerChecker<uint32_t> ())
104
		   MakeDoubleChecker<double> (0))
97
    .AddAttribute ("ewndFor12mbps",
98
                   "ewnd parameter for 12 Mbs data mode",
99
                   UintegerValue (20),
100
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor12),
101
                   MakeUintegerChecker<uint32_t> ())
102
    .AddAttribute ("ewndFor9mbps",
103
                   "ewnd parameter for 9 Mbs data mode",
104
                   UintegerValue (10),
105
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor9),
106
                   MakeUintegerChecker<uint32_t> ())
107
    .AddAttribute ("ewndFor6mbps",
108
                   "ewnd parameter for 6 Mbs data mode",
109
                   UintegerValue (6),
110
                   MakeUintegerAccessor (&RraaWifiManager::m_ewndfor6),
111
                   MakeUintegerChecker<uint32_t> ())
112
    .AddAttribute ("poriFor48mbps",
113
                   "Pori parameter for 48 Mbs data mode",
114
                   DoubleValue (0.047),
115
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor48),
116
                   MakeDoubleChecker<double> ())
117
    .AddAttribute ("poriFor36mbps",
118
                   "Pori parameter for 36 Mbs data mode",
119
                   DoubleValue (0.115),
120
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor36),
121
                   MakeDoubleChecker<double> ())
122
    .AddAttribute ("poriFor24mbps",
123
                   "Pori parameter for 24 Mbs data mode",
124
                   DoubleValue (0.1681),
125
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor24),
126
                   MakeDoubleChecker<double> ())
127
    .AddAttribute ("poriFor18mbps",
128
                   "Pori parameter for 18 Mbs data mode",
129
                   DoubleValue (0.1325),
130
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor18),
131
                   MakeDoubleChecker<double> ())
132
    .AddAttribute ("poriFor12mbps",
133
                   "Pori parameter for 12 Mbs data mode",
134
                   DoubleValue (0.1861),
135
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor12),
136
                   MakeDoubleChecker<double> ())
137
    .AddAttribute ("poriFor9mbps",
138
                   "Pori parameter for 9 Mbs data mode",
139
                   DoubleValue (0.1434),
140
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor9),
141
                   MakeDoubleChecker<double> ())
142
    .AddAttribute ("poriFor6mbps",
143
                   "Pori parameter for 6 Mbs data mode",
144
                   DoubleValue (0.5),
145
                   MakeDoubleAccessor (&RraaWifiManager::m_porifor6),
146
                   MakeDoubleChecker<double> ())
147
    .AddAttribute ("pmtlFor54mbps",
148
                   "Pmtl parameter for 54 Mbs data mode",
149
                   DoubleValue (0.094),
150
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor54),
151
                   MakeDoubleChecker<double> ())
152
    .AddAttribute ("pmtlFor48mbps",
153
                   "Pmtl parameter for 48 Mbs data mode",
154
                   DoubleValue (0.23),
155
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor48),
156
                   MakeDoubleChecker<double> ())
157
    .AddAttribute ("pmtlFor36mbps",
158
                   "Pmtl parameter for 36 Mbs data mode",
159
                   DoubleValue (0.3363),
160
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor36),
161
                   MakeDoubleChecker<double> ())
162
    .AddAttribute ("pmtlFor24mbps",
163
                   "Pmtl parameter for 24 Mbs data mode",
164
                   DoubleValue (0.265),
165
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor24),
166
                   MakeDoubleChecker<double> ())
167
    .AddAttribute ("pmtlFor18mbps",
168
                   "Pmtl parameter for 18 Mbs data mode",
169
                   DoubleValue (0.3722),
170
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor18),
171
                   MakeDoubleChecker<double> ())
172
    .AddAttribute ("pmtlFor12mbps",
173
                   "Pmtl parameter for 12 Mbs data mode",
174
                   DoubleValue (0.2868),
175
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor12),
176
                   MakeDoubleChecker<double> ())
177
    .AddAttribute ("pmtlFor9mbps",
178
                   "Pmtl parameter for 9 Mbs data mode",
179
                   DoubleValue (0.3932),
180
                   MakeDoubleAccessor (&RraaWifiManager::m_pmtlfor9),
181
                   MakeDoubleChecker<double> ())
182
    .AddTraceSource ("Rate",
105
    .AddTraceSource ("Rate",
183
                     "Traced value for rate changes (b/s)",
106
                     "Traced value for rate changes (b/s)",
184
                     MakeTraceSourceAccessor (&RraaWifiManager::m_currentRate),
107
                     MakeTraceSourceAccessor (&RraaWifiManager::m_currentRate),
 Lines 198-232    Link Here 
198
{
121
{
199
}
122
}
200
123
124
void
125
RraaWifiManager::SetupPhy (Ptr<WifiPhy> phy)
126
{
127
  NS_LOG_FUNCTION (this);
128
  uint32_t nModes = phy->GetNModes ();
129
  for (uint32_t i = 0; i < nModes; i++)
130
    {
131
      WifiMode mode = phy->GetMode (i);
132
      WifiTxVector txVector;
133
      txVector.SetMode (mode);
134
      txVector.SetPreambleType (WIFI_PREAMBLE_LONG);
135
      /* Calculate the TX Time of the data and the corresponding ACK*/
136
      Time dataTxTime = phy->CalculateTxDuration (m_frameLength, txVector, phy->GetFrequency ());
137
      Time ackTxTime = phy->CalculateTxDuration (m_ackLength, txVector, phy->GetFrequency ());
138
      NS_LOG_DEBUG ("Calculating TX times: Mode= " << mode << " DataTxTime= " << dataTxTime << " AckTxTime= " << ackTxTime);
139
      AddCalcTxTime (mode, dataTxTime + ackTxTime);
140
    }
141
  WifiRemoteStationManager::SetupPhy (phy);
142
}
143
144
void
145
RraaWifiManager::SetupMac (Ptr<WifiMac> mac)
146
{
147
  NS_LOG_FUNCTION (this);
148
  m_sifs = mac->GetSifs ();
149
  m_difs = m_sifs + 2 * mac->GetSlot ();
150
  WifiRemoteStationManager::SetupMac (mac);
151
}
152
153
Time
154
RraaWifiManager::GetCalcTxTime (WifiMode mode) const
155
{
156
  NS_LOG_FUNCTION (this << mode);
157
  for (TxTime::const_iterator i = m_calcTxTime.begin (); i != m_calcTxTime.end (); i++)
158
    {
159
      if (mode == i->second)
160
        {
161
          return i->first;
162
        }
163
    }
164
  NS_ASSERT (false);
165
  return Seconds (0);
166
}
167
168
void
169
RraaWifiManager::AddCalcTxTime (WifiMode mode, Time t)
170
{
171
  NS_LOG_FUNCTION (this << mode << t);
172
  m_calcTxTime.push_back (std::make_pair (t, mode));
173
}
174
175
WifiRraaThresholds
176
RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station, WifiMode mode) const
177
{
178
  NS_LOG_FUNCTION (this << station << mode);
179
  for (RraaThresholdsTable::const_iterator i = station->m_thresholds.begin (); i != station->m_thresholds.end (); i++)
180
    {
181
      if (mode == i->second)
182
        {
183
          return i->first;
184
        }
185
    }
186
  NS_ASSERT (false);
187
}
188
201
WifiRemoteStation *
189
WifiRemoteStation *
202
RraaWifiManager::DoCreateStation (void) const
190
RraaWifiManager::DoCreateStation (void) const
203
{
191
{
204
  RraaWifiRemoteStation *station = new RraaWifiRemoteStation ();
192
  RraaWifiRemoteStation *station = new RraaWifiRemoteStation ();
205
  station->m_initialized = false;
193
  station->m_initialized = false;
206
  station->m_rtsWnd = 0;
194
  station->m_adaptiveRtsWnd = 0;
207
  station->m_rtsCounter = 0;
195
  station->m_rtsCounter = 0;
208
  station->m_rtsOn = false;
196
  station->m_adaptiveRtsOn = false;
209
  station->m_lastFrameFail = false;
197
  station->m_lastFrameFail = false;
210
  return station;
198
  return station;
211
}
199
}
212
200
213
void
201
void
202
RraaWifiManager::CheckInit (RraaWifiRemoteStation *station)
203
{
204
  NS_LOG_FUNCTION (this << station);
205
  if (!station->m_initialized)
206
    {
207
      //Note: we appear to be doing late initialization of the table
208
      //to make sure that the set of supported rates has been initialized
209
      //before we perform our own initialization.
210
      station->m_nRate = GetNSupported (station);
211
      //Initialize at maximal rate
212
      station->m_rateIndex = GetMaxRate(station);
213
214
      station->m_initialized = true;
215
216
      station->m_thresholds = RraaThresholdsTable (station->m_nRate);
217
      InitThresholds (station);
218
      ResetCountersBasic (station);
219
    }
220
}
221
222
void
223
RraaWifiManager::InitThresholds (RraaWifiRemoteStation *station)
224
{
225
  NS_LOG_FUNCTION (this << station);
226
  NS_LOG_DEBUG ("InitThresholds = " << station);
227
228
  double nextCritical = 0;
229
  double nextMtl = 0;
230
  double mtl = 0;
231
  double ori = 0;
232
  for (uint32_t i = 0; i < station->m_nRate; i++)
233
    {
234
      WifiMode mode = GetSupported (station, i);
235
      Time totalTxTime = GetCalcTxTime (mode) + m_sifs + m_difs;
236
      if (i == GetMaxRate (station))
237
        {
238
          ori = 0;
239
        }
240
      else
241
        {
242
          WifiMode nextMode = GetSupported (station, i + 1);
243
          Time nextTotalTxTime = GetCalcTxTime (nextMode) + m_sifs + m_difs;
244
          nextCritical = 1 - (nextTotalTxTime.GetSeconds () / totalTxTime.GetSeconds ());
245
          nextMtl = m_alpha * nextCritical;
246
          ori = nextMtl / m_beta;
247
        }
248
      if (i == GetMinRate (station))
249
        {
250
          mtl = 1;
251
        }
252
      WifiRraaThresholds th;
253
      th.m_ewnd = ceil (m_tau / totalTxTime.GetSeconds ());
254
      th.m_ori = ori;
255
      th.m_mtl = mtl;
256
      station->m_thresholds.push_back (std::make_pair (th, mode));
257
      mtl = nextMtl;
258
      NS_LOG_DEBUG (mode << " " << th.m_ewnd << " " << th.m_mtl << " " << th.m_ori);
259
    }
260
}
261
262
void
214
RraaWifiManager::ResetCountersBasic (RraaWifiRemoteStation *station)
263
RraaWifiManager::ResetCountersBasic (RraaWifiRemoteStation *station)
215
{
264
{
216
  if (!station->m_initialized)
265
  NS_LOG_FUNCTION (this << station);
217
    {
266
  station->m_nFailed = 0;
218
      station->m_rate = GetMaxRate (station);
267
  station->m_counter = GetThresholds (station, station->m_rateIndex).m_ewnd;
219
      station->m_initialized = true;
220
    }
221
  station->m_failed = 0;
222
  station->m_counter = GetThresholds (station, station->m_rate).ewnd;
223
  station->m_lastReset = Simulator::Now ();
268
  station->m_lastReset = Simulator::Now ();
224
}
269
}
225
270
226
uint32_t
271
uint32_t
227
RraaWifiManager::GetMaxRate (RraaWifiRemoteStation *station)
272
RraaWifiManager::GetMaxRate (RraaWifiRemoteStation *station)
228
{
273
{
229
  return GetNSupported (station) - 1;
274
  return station->m_nRate - 1;
230
}
275
}
231
276
232
uint32_t
277
uint32_t
 Lines 238-253    Link Here 
238
void
283
void
239
RraaWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
284
RraaWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
240
{
285
{
286
  NS_LOG_FUNCTION (this << st);
241
}
287
}
242
288
243
void
289
void
244
RraaWifiManager::DoReportDataFailed (WifiRemoteStation *st)
290
RraaWifiManager::DoReportDataFailed (WifiRemoteStation *st)
245
{
291
{
292
  NS_LOG_FUNCTION (this << st);
246
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
293
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
247
  station->m_lastFrameFail = true;
294
  station->m_lastFrameFail = true;
248
  CheckTimeout (station);
295
  CheckTimeout (station);
249
  station->m_counter--;
296
  station->m_counter--;
250
  station->m_failed++;
297
  station->m_nFailed++;
251
  RunBasicAlgorithm (station);
298
  RunBasicAlgorithm (station);
252
}
299
}
253
300
 Lines 255-266    Link Here 
255
RraaWifiManager::DoReportRxOk (WifiRemoteStation *st,
302
RraaWifiManager::DoReportRxOk (WifiRemoteStation *st,
256
                               double rxSnr, WifiMode txMode)
303
                               double rxSnr, WifiMode txMode)
257
{
304
{
305
  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
258
}
306
}
259
307
260
void
308
void
261
RraaWifiManager::DoReportRtsOk (WifiRemoteStation *st,
309
RraaWifiManager::DoReportRtsOk (WifiRemoteStation *st,
262
                                double ctsSnr, WifiMode ctsMode, double rtsSnr)
310
                                double ctsSnr, WifiMode ctsMode, double rtsSnr)
263
{
311
{
312
  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
264
  NS_LOG_DEBUG ("self=" << st << " rts ok");
313
  NS_LOG_DEBUG ("self=" << st << " rts ok");
265
}
314
}
266
315
 Lines 268-273    Link Here 
268
RraaWifiManager::DoReportDataOk (WifiRemoteStation *st,
317
RraaWifiManager::DoReportDataOk (WifiRemoteStation *st,
269
                                 double ackSnr, WifiMode ackMode, double dataSnr)
318
                                 double ackSnr, WifiMode ackMode, double dataSnr)
270
{
319
{
320
  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
271
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
321
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
272
  station->m_lastFrameFail = false;
322
  station->m_lastFrameFail = false;
273
  CheckTimeout (station);
323
  CheckTimeout (station);
 Lines 278-293    Link Here 
278
void
328
void
279
RraaWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
329
RraaWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
280
{
330
{
331
  NS_LOG_FUNCTION (this << st);
281
}
332
}
282
333
283
void
334
void
284
RraaWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
335
RraaWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
285
{
336
{
337
  NS_LOG_FUNCTION (this << st);
286
}
338
}
287
339
288
WifiTxVector
340
WifiTxVector
289
RraaWifiManager::DoGetDataTxVector (WifiRemoteStation *st)
341
RraaWifiManager::DoGetDataTxVector (WifiRemoteStation *st)
290
{
342
{
343
  NS_LOG_FUNCTION (this << st);
291
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
344
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
292
  uint32_t channelWidth = GetChannelWidth (station);
345
  uint32_t channelWidth = GetChannelWidth (station);
293
  if (channelWidth > 20 && channelWidth != 22)
346
  if (channelWidth > 20 && channelWidth != 22)
 Lines 295-305    Link Here 
295
      //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
348
      //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
296
      channelWidth = 20;
349
      channelWidth = 20;
297
    }
350
    }
298
  if (!station->m_initialized)
351
  CheckInit (station);
299
    {
352
  WifiMode mode = GetSupported (station, station->m_rateIndex);
300
      ResetCountersBasic (station);
301
    }
302
  WifiMode mode = GetSupported (station, station->m_rate);
303
  if (m_currentRate != mode.GetDataRate (channelWidth))
353
  if (m_currentRate != mode.GetDataRate (channelWidth))
304
    {
354
    {
305
      NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
355
      NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
 Lines 311-316    Link Here 
311
WifiTxVector
361
WifiTxVector
312
RraaWifiManager::DoGetRtsTxVector (WifiRemoteStation *st)
362
RraaWifiManager::DoGetRtsTxVector (WifiRemoteStation *st)
313
{
363
{
364
  NS_LOG_FUNCTION (this << st);
314
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
365
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
315
  uint32_t channelWidth = GetChannelWidth (station);
366
  uint32_t channelWidth = GetChannelWidth (station);
316
  if (channelWidth > 20 && channelWidth != 22)
367
  if (channelWidth > 20 && channelWidth != 22)
 Lines 322-334    Link Here 
322
  WifiMode mode;
373
  WifiMode mode;
323
  if (GetUseNonErpProtection () == false)
374
  if (GetUseNonErpProtection () == false)
324
    {
375
    {
325
      mode = GetSupported (st, 0);
376
      mode = GetSupported (station, 0);
326
    }
377
    }
327
  else
378
  else
328
    {
379
    {
329
      mode = GetNonErpSupported (st, 0);
380
      mode = GetNonErpSupported (station, 0);
330
    }
381
    }
331
  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetShortRetryCount (st), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
382
  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetShortRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
332
  return rtsTxVector;
383
  return rtsTxVector;
333
}
384
}
334
385
 Lines 336-353    Link Here 
336
RraaWifiManager::DoNeedRts (WifiRemoteStation *st,
387
RraaWifiManager::DoNeedRts (WifiRemoteStation *st,
337
                            Ptr<const Packet> packet, bool normally)
388
                            Ptr<const Packet> packet, bool normally)
338
{
389
{
390
  NS_LOG_FUNCTION (this << st << packet << normally);
339
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
391
  RraaWifiRemoteStation *station = (RraaWifiRemoteStation *) st;
392
  CheckInit (station);
340
  if (m_basic)
393
  if (m_basic)
341
    {
394
    {
342
      return normally;
395
      return normally;
343
    }
396
    }
344
  ARts (station);
397
  ARts (station);
345
  return station->m_rtsOn;
398
  return station->m_adaptiveRtsOn;
346
}
399
}
347
400
348
void
401
void
349
RraaWifiManager::CheckTimeout (RraaWifiRemoteStation *station)
402
RraaWifiManager::CheckTimeout (RraaWifiRemoteStation *station)
350
{
403
{
404
  NS_LOG_FUNCTION (this << station);
351
  Time d = Simulator::Now () - station->m_lastReset;
405
  Time d = Simulator::Now () - station->m_lastReset;
352
  if (station->m_counter == 0 || d > m_timeout)
406
  if (station->m_counter == 0 || d > m_timeout)
353
    {
407
    {
 Lines 358-377    Link Here 
358
void
412
void
359
RraaWifiManager::RunBasicAlgorithm (RraaWifiRemoteStation *station)
413
RraaWifiManager::RunBasicAlgorithm (RraaWifiRemoteStation *station)
360
{
414
{
361
  ThresholdsItem thresholds = GetThresholds (station, station->m_rate);
415
  NS_LOG_FUNCTION (this << station);
362
  double ploss = (double) station->m_failed / (double) thresholds.ewnd;
416
  WifiRraaThresholds thresholds = GetThresholds (station, station->m_rateIndex);
417
  double ploss = (double) station->m_nFailed / (double) thresholds.m_ewnd;
363
  if (station->m_counter == 0
418
  if (station->m_counter == 0
364
      || ploss > thresholds.pmtl)
419
      || ploss > thresholds.m_mtl)
365
    {
420
    {
366
      if (station->m_rate > GetMinRate (station)
421
      if (station->m_rateIndex > GetMinRate (station)
367
          && ploss > thresholds.pmtl)
422
          && ploss > thresholds.m_mtl)
368
        {
423
        {
369
          station->m_rate--;
424
          station->m_rateIndex--;
370
        }
425
        }
371
      else if (station->m_rate < GetMaxRate (station)
426
      else if (station->m_rateIndex < GetMaxRate (station)
372
               && ploss < thresholds.pori)
427
               && ploss < thresholds.m_ori)
373
        {
428
        {
374
          station->m_rate++;
429
          station->m_rateIndex++;
375
        }
430
        }
376
      ResetCountersBasic (station);
431
      ResetCountersBasic (station);
377
    }
432
    }
 Lines 380-504    Link Here 
380
void
435
void
381
RraaWifiManager::ARts (RraaWifiRemoteStation *station)
436
RraaWifiManager::ARts (RraaWifiRemoteStation *station)
382
{
437
{
383
  if (!station->m_rtsOn
438
  if (!station->m_adaptiveRtsOn
384
      && station->m_lastFrameFail)
439
      && station->m_lastFrameFail)
385
    {
440
    {
386
      station->m_rtsWnd++;
441
      station->m_adaptiveRtsWnd++;
387
      station->m_rtsCounter = station->m_rtsWnd;
442
      station->m_rtsCounter = station->m_adaptiveRtsWnd;
388
    }
443
    }
389
  else if ((station->m_rtsOn && station->m_lastFrameFail)
444
  else if ((station->m_adaptiveRtsOn && station->m_lastFrameFail)
390
           || (!station->m_rtsOn && !station->m_lastFrameFail))
445
           || (!station->m_adaptiveRtsOn && !station->m_lastFrameFail))
391
    {
446
    {
392
      station->m_rtsWnd = station->m_rtsWnd / 2;
447
      station->m_adaptiveRtsWnd = station->m_adaptiveRtsWnd / 2;
393
      station->m_rtsCounter = station->m_rtsWnd;
448
      station->m_rtsCounter = station->m_adaptiveRtsWnd;
394
    }
449
    }
395
  if (station->m_rtsCounter > 0)
450
  if (station->m_rtsCounter > 0)
396
    {
451
    {
397
      station->m_rtsOn = true;
452
      station->m_adaptiveRtsOn = true;
398
      station->m_rtsCounter--;
453
      station->m_rtsCounter--;
399
    }
454
    }
400
  else
455
  else
401
    {
456
    {
402
      station->m_rtsOn = false;
457
      station->m_adaptiveRtsOn = false;
403
    }
458
    }
404
}
459
}
405
460
406
RraaWifiManager::ThresholdsItem
461
WifiRraaThresholds
407
RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
462
RraaWifiManager::GetThresholds (RraaWifiRemoteStation *station,
408
                                uint32_t rate) const
463
                                 uint32_t rate) const
409
{
464
{
465
  NS_LOG_FUNCTION (this << station << rate);
410
  WifiMode mode = GetSupported (station, rate);
466
  WifiMode mode = GetSupported (station, rate);
411
  return GetThresholds (mode, station);
467
  return GetThresholds (station, mode);
412
}
413
414
RraaWifiManager::ThresholdsItem
415
RraaWifiManager::GetThresholds (WifiMode mode, RraaWifiRemoteStation *station) const
416
{
417
  switch (mode.GetDataRate (GetChannelWidth (station)) / 1000000)
418
    {
419
    case 54:
420
      {
421
        ThresholdsItem mode54 = {
422
          54000000,
423
          0.0,
424
          m_pmtlfor54,
425
          m_ewndfor54
426
        };
427
        return mode54;
428
      } break;
429
    case 48:
430
      {
431
        ThresholdsItem mode48 = {
432
          48000000,
433
          m_porifor48,
434
          m_pmtlfor48,
435
          m_ewndfor48
436
        };
437
        return mode48;
438
      } break;
439
    case 36:
440
      {
441
        ThresholdsItem mode36 = {
442
          36000000,
443
          m_porifor36,
444
          m_pmtlfor36,
445
          m_ewndfor36
446
        };
447
        return mode36;
448
      } break;
449
    case 24:
450
      {
451
        ThresholdsItem mode24 = {
452
          24000000,
453
          m_porifor24,
454
          m_pmtlfor24,
455
          m_ewndfor24
456
        };
457
        return mode24;
458
      } break;
459
    case 18:
460
      {
461
        ThresholdsItem mode18 = {
462
          18000000,
463
          m_porifor18,
464
          m_pmtlfor18,
465
          m_ewndfor18
466
        };
467
        return mode18;
468
      } break;
469
    case 12:
470
      {
471
        ThresholdsItem mode12 = {
472
          12000000,
473
          m_porifor12,
474
          m_pmtlfor12,
475
          m_ewndfor12
476
        };
477
        return mode12;
478
      } break;
479
    case 9:
480
      {
481
        ThresholdsItem mode9 =  {
482
          9000000,
483
          m_porifor9,
484
          m_pmtlfor9,
485
          m_ewndfor9
486
        };
487
        return mode9;
488
      } break;
489
    case 6:
490
      {
491
        ThresholdsItem mode6 =  {
492
          6000000,
493
          m_porifor6,
494
          1.0,
495
          m_ewndfor6
496
        };
497
        return mode6;
498
      } break;
499
    }
500
  NS_ASSERT_MSG (false, "Thresholds for an unknown mode are asked (" << mode << ")");
501
  return ThresholdsItem ();
502
}
468
}
503
469
504
bool
470
bool
(-)a/src/wifi/model/rraa-wifi-manager.h (-37 / +70 lines)
 Lines 21-26    Link Here 
21
#ifndef RRAA_WIFI_MANAGER_H
21
#ifndef RRAA_WIFI_MANAGER_H
22
#define RRAA_WIFI_MANAGER_H
22
#define RRAA_WIFI_MANAGER_H
23
23
24
#include "ns3/nstime.h"
24
#include "ns3/traced-value.h"
25
#include "ns3/traced-value.h"
25
#include "wifi-remote-station-manager.h"
26
#include "wifi-remote-station-manager.h"
26
27
 Lines 41-46    Link Here 
41
 * exit if the user tries to configure this RAA with a Wi-Fi MAC
42
 * exit if the user tries to configure this RAA with a Wi-Fi MAC
42
 * that has VhtSupported, HtSupported or HeSupported set.
43
 * that has VhtSupported, HtSupported or HeSupported set.
43
 */
44
 */
45
46
/**
47
 * For each rate there is a Opportunistic Rate Increase threshold,
48
 * a Maximum Tolerable Loss threshold and an Evaluation Window.
49
 */
50
struct WifiRraaThresholds
51
{
52
  double m_ori;
53
  double m_mtl;
54
  uint32_t m_ewnd;
55
};
56
57
/**
58
 * List of thresholds for each mode.
59
 */
60
typedef std::vector<std::pair<WifiRraaThresholds, WifiMode> > RraaThresholdsTable;
61
62
44
class RraaWifiManager : public WifiRemoteStationManager
63
class RraaWifiManager : public WifiRemoteStationManager
45
{
64
{
46
public:
65
public:
 Lines 54-73    Link Here 
54
  virtual ~RraaWifiManager ();
73
  virtual ~RraaWifiManager ();
55
74
56
  // Inherited from WifiRemoteStationManager
75
  // Inherited from WifiRemoteStationManager
76
  virtual void SetupPhy (Ptr<WifiPhy> phy);
77
  virtual void SetupMac (Ptr<WifiMac> mac);
57
  void SetHtSupported (bool enable);
78
  void SetHtSupported (bool enable);
58
  void SetVhtSupported (bool enable);
79
  void SetVhtSupported (bool enable);
59
  void SetHeSupported (bool enable);
80
  void SetHeSupported (bool enable);
60
81
61
82
62
private:
83
private:
63
  /// ThresholdsItem structure
64
  struct ThresholdsItem
65
  {
66
    uint32_t datarate; ///< data rate
67
    double pori; ///< PORI
68
    double pmtl; ///< PMTL
69
    uint32_t ewnd; ///< EWND
70
  };
71
84
72
  //overriden from base class
85
  //overriden from base class
73
  WifiRemoteStation * DoCreateStation (void) const;
86
  WifiRemoteStation * DoCreateStation (void) const;
 Lines 88-93    Link Here 
88
  bool IsLowLatency (void) const;
101
  bool IsLowLatency (void) const;
89
102
90
  /**
103
  /**
104
   * Check for initializations.
105
   * \param station The remote station.
106
   */
107
  void CheckInit (RraaWifiRemoteStation *station);
108
  /**
91
   * Return the index for the maximum transmission rate for
109
   * Return the index for the maximum transmission rate for
92
   * the given station.
110
   * the given station.
93
   *
111
   *
 Lines 131-178    Link Here 
131
   */
149
   */
132
  void ResetCountersBasic (RraaWifiRemoteStation *station);
150
  void ResetCountersBasic (RraaWifiRemoteStation *station);
133
  /**
151
  /**
134
   * Get a threshold for the given mode.
152
   * Initialize the thresholds internal list for the given station.
135
   *
153
   *
154
   * \param station
155
   */
156
  void InitThresholds (RraaWifiRemoteStation *station);
157
  /**
158
   * Get the thresholds for the given station and mode.
159
   *
160
   * \param station
136
   * \param mode
161
   * \param mode
137
   * \param station
138
   *
162
   *
139
   * \return threshold
163
   * \return threshold
140
   */
164
   */
141
  ThresholdsItem GetThresholds (WifiMode mode, RraaWifiRemoteStation *station) const;
165
  WifiRraaThresholds GetThresholds (RraaWifiRemoteStation *station, WifiMode mode) const;
142
  /**
166
  /**
143
   * Get a threshold for the given station and mode index.
167
   * Get the thresholds for the given station and mode index.
144
   *
168
   *
145
   * \param station
169
   * \param station
146
   * \param rate
170
   * \param rate
147
   *
171
   *
148
   * \return threshold
172
   * \return threshold
149
   */
173
   */
150
  ThresholdsItem GetThresholds (RraaWifiRemoteStation *station, uint32_t rate) const;
174
  WifiRraaThresholds GetThresholds (RraaWifiRemoteStation *station, uint32_t rate) const;
175
  /**
176
   * Get the estimated TxTime of a packet with a given mode.
177
   *
178
   * \param mode
179
   *
180
   * \return time
181
   */
182
  Time GetCalcTxTime (WifiMode mode) const;
183
  /**
184
   * Add transmission time for the given mode to an internal list.
185
   *
186
   * \param mode Wi-Fi mode
187
   * \param t transmission time
188
   */
189
  void AddCalcTxTime (WifiMode mode, Time t);
190
  /**
191
   * typedef for a vector of a pair of Time, WifiMode.
192
   * Essentially a list for WifiMode and its corresponding transmission time
193
   * to transmit a reference packet.
194
   */
195
  typedef std::vector<std::pair<Time,WifiMode> > TxTime;
151
196
152
  bool m_basic; ///< basic
197
  TxTime m_calcTxTime;     //!< To hold all the calculated TxTime for all modes.
153
  Time m_timeout; ///< timeout
198
  Time m_sifs;             //!< Value of SIFS configured in the device.
154
  uint32_t m_ewndfor54; ///< ewndfor54
199
  Time m_difs;             //!< Value of DIFS configured in the device.
155
  uint32_t m_ewndfor48; ///< ewndfor48
200
156
  uint32_t m_ewndfor36; ///< ewndfor36
201
  uint32_t m_frameLength;  //!< Data frame length used for calculate mode TxTime.
157
  uint32_t m_ewndfor24; ///< ewndfor24
202
  uint32_t m_ackLength;    //!< Ack frame length used for calculate mode TxTime.
158
  uint32_t m_ewndfor18; ///< ewndfor18
203
159
  uint32_t m_ewndfor12; ///< ewndfor12
204
  bool m_basic;    ///< basic
160
  uint32_t m_ewndfor9; ///< ewndfor9
205
  Time m_timeout;  ///< timeout
161
  uint32_t m_ewndfor6; ///< ewndfor6
206
  double m_alpha;  //!< Alpha value for RRAA (value for calculating MTL threshold)
162
  double m_porifor48; ///< porifor48
207
  double m_beta;   //!< Beta value for RRAA (value for calculating ORI threshold).
163
  double m_porifor36; ///< porifor36
208
  double m_tau;    //!< Tau value for RRAA (value for calculating EWND size).
164
  double m_porifor24; ///< porifor24
165
  double m_porifor18; ///< porifor18
166
  double m_porifor12; ///< porifor12
167
  double m_porifor9; ///< porifor9
168
  double m_porifor6; ///< porifor6
169
  double m_pmtlfor54; ///< pmtlfor54
170
  double m_pmtlfor48; ///< pmtlfor48
171
  double m_pmtlfor36; ///< pmtlfor36
172
  double m_pmtlfor24; ///< pmtlfor24
173
  double m_pmtlfor18; ///< pmtlfor18
174
  double m_pmtlfor12; ///< pmtlfor12
175
  double m_pmtlfor9; ///< pmtlfor9
176
209
177
  TracedValue<uint64_t> m_currentRate; //!< Trace rate changes
210
  TracedValue<uint64_t> m_currentRate; //!< Trace rate changes
178
};
211
};

Return to bug 2654