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

(-)a/src/wifi/model/interference-helper.cc (-74 / +83 lines)
 Lines 88-96    Link Here 
88
 *       short period of time.
88
 *       short period of time.
89
 ****************************************************************/
89
 ****************************************************************/
90
90
91
InterferenceHelper::NiChange::NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event)
91
InterferenceHelper::NiChange::NiChange (Time time, double power, Ptr<InterferenceHelper::Event> event)
92
  : m_time (time),
92
  : m_time (time),
93
    m_delta (delta),
93
    m_power (power),
94
    m_event (event)
94
    m_event (event)
95
{
95
{
96
}
96
}
 Lines 102-110    Link Here 
102
}
102
}
103
103
104
double
104
double
105
InterferenceHelper::NiChange::GetDelta (void) const
105
InterferenceHelper::NiChange::GetPower (void) const
106
{
106
{
107
  return m_delta;
107
  return m_power;
108
}
109
110
void
111
InterferenceHelper::NiChange::AddPower (double power)
112
{
113
  m_power += power;
108
}
114
}
109
115
110
Ptr<InterferenceHelper::Event>
116
Ptr<InterferenceHelper::Event>
 Lines 188-211    Link Here 
188
}
194
}
189
195
190
Time
196
Time
191
InterferenceHelper::GetEnergyDuration (double energyW) const
197
InterferenceHelper::GetEnergyDuration (double energyW)
192
{
198
{
193
  Time now = Simulator::Now ();
199
  Time now = Simulator::Now ();
194
  double noiseInterferenceW = 0;
200
  auto i = GetPreviousPosition (now);
195
  Time end = now;
201
  Time end = i->GetTime ();
196
  noiseInterferenceW = m_firstPower;
202
  while (i != m_niChanges.end ())
197
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
198
    {
203
    {
199
      noiseInterferenceW += i->GetDelta ();
204
      double noiseInterferenceW = i->GetPower ();
200
      end = i->GetTime ();
205
      end = i->GetTime ();
201
      if (end < now)
202
        {
203
          continue;
204
        }
205
      if (noiseInterferenceW < energyW)
206
      if (noiseInterferenceW < energyW)
206
        {
207
        {
207
          break;
208
          break;
208
        }
209
        }
210
      ++i;
209
    }
211
    }
210
  return end > now ? end - now : MicroSeconds (0);
212
  return end > now ? end - now : MicroSeconds (0);
211
}
213
}
 Lines 213-230    Link Here 
213
void
215
void
214
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
216
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
215
{
217
{
216
  Time now = Simulator::Now ();
218
  double previousPowerStart = 0;
219
  double previousPowerEnd = 0;
220
  auto itPreviousEvent = GetPreviousPosition (event->GetStartTime ());
221
  auto itNextEvent = GetPreviousPosition (event->GetEndTime ());
222
  if (m_niChanges.size() > 0)
223
    {
224
      previousPowerStart = itPreviousEvent->GetPower ();
225
      previousPowerEnd = itNextEvent->GetPower ();
226
    }
217
  if (!m_rxing)
227
  if (!m_rxing)
218
    {
228
    {
219
      NiChanges::const_iterator nowIterator = GetPosition (now);
229
      m_firstPower = previousPowerStart;
220
      for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++)
230
      m_niChanges.erase (m_niChanges.begin (), GetNextPosition (event->GetStartTime ()));
221
        {
222
          m_firstPower += i->GetDelta ();
223
        }
224
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
225
    }
231
    }
226
  AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
232
  auto first = AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart, event));
227
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
233
  auto last = AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event));
234
  for (auto i = first; i < last; i++)
235
    {
236
      m_niChanges.at (i).AddPower (event->GetRxPowerW ());
237
    }
228
}
238
}
229
239
230
double
240
double
 Lines 243-285    Link Here 
243
}
253
}
244
254
245
double
255
double
246
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
256
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni)
247
{
257
{
248
  double noiseInterference = m_firstPower;
258
  double noiseInterference = m_firstPower;
249
  NiChanges::const_iterator eventIterator = m_niChanges.begin ();
259
  auto it = m_niChanges.begin ();
250
  while (eventIterator != m_niChanges.end ())
260
  while (it != m_niChanges.end () && it->GetEvent () != event)
251
    {
261
    {
252
      // Iterate the NI change list from the beginning to the end
262
      noiseInterference = it->GetPower ();
253
      // until find the position of the event in the NI change list
263
      ++it;
254
      // The reason of using the event that causes the NI change to identify
255
      // different NI changes is because in some special cases
256
      // different NI changes happen at the same time with the same delta
257
      // value. Therefore, it may be impossible to identify a NI change that belongs
258
      // to which event based on just the NI time and NI delta value
259
      if (eventIterator->GetEvent () != event)
260
        {
261
          // The NI changes which happen before the event should be considered
262
          // as the interference. This considers the case that the receiving event
263
          // arrives while another receiving event is going on. The SINR of
264
          // the newly arrived event is calculated for checking the possibility of frame capture
265
          noiseInterference += eventIterator->GetDelta ();
266
        }
267
      else
268
        {
269
          break;
270
        }
271
      ++eventIterator;
272
    }
264
    }
273
265
  ni->push_back (NiChange (event->GetStartTime (), 0, event));
274
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
266
  ++it;
267
  while (it != m_niChanges.end () && event != it->GetEvent ())
275
    {
268
    {
276
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
269
      ni->push_back (*it);
277
        {
270
      ++it;
278
          break;
279
        }
280
      ni->push_back (*i);
281
    }
271
    }
282
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
283
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
272
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
284
  return noiseInterference;
273
  return noiseInterference;
285
}
274
}
 Lines 313-331    Link Here 
313
  const WifiTxVector txVector = event->GetTxVector ();
302
  const WifiTxVector txVector = event->GetTxVector ();
314
  double psr = 1.0; /* Packet Success Rate */
303
  double psr = 1.0; /* Packet Success Rate */
315
  NiChanges::const_iterator j = ni->begin ();
304
  NiChanges::const_iterator j = ni->begin ();
316
  Time previous = (*j).GetTime ();
305
  Time previous = j->GetTime ();
317
  WifiMode payloadMode = event->GetPayloadMode ();
306
  WifiMode payloadMode = event->GetPayloadMode ();
318
  WifiPreamble preamble = txVector.GetPreambleType ();
307
  WifiPreamble preamble = txVector.GetPreambleType ();
319
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
308
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
320
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
309
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
321
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
310
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
322
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
311
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
323
  double noiseInterferenceW = (*j).GetDelta ();
312
  double noiseInterferenceW = m_firstPower;
324
  double powerW = event->GetRxPowerW ();
313
  double powerW = event->GetRxPowerW ();
325
  j++;
314
  ++j;
326
  while (ni->end () != j)
315
  while (ni->end () != j)
327
    {
316
    {
328
      Time current = (*j).GetTime ();
317
      Time current = j->GetTime ();
329
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
318
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
330
      NS_ASSERT (current >= previous);
319
      NS_ASSERT (current >= previous);
331
      //Case 1: Both previous and current point to the payload
320
      //Case 1: Both previous and current point to the payload
 Lines 348-356    Link Here 
348
                                            payloadMode, txVector);
337
                                            payloadMode, txVector);
349
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
338
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
350
        }
339
        }
351
      noiseInterferenceW += (*j).GetDelta ();
340
      noiseInterferenceW = j->GetPower () - powerW;
352
      previous = (*j).GetTime ();
341
      previous = j->GetTime ();
353
      j++;
342
      ++j;
354
    }
343
    }
355
  double per = 1 - psr;
344
  double per = 1 - psr;
356
  return per;
345
  return per;
 Lines 363-369    Link Here 
363
  const WifiTxVector txVector = event->GetTxVector ();
352
  const WifiTxVector txVector = event->GetTxVector ();
364
  double psr = 1.0; /* Packet Success Rate */
353
  double psr = 1.0; /* Packet Success Rate */
365
  NiChanges::const_iterator j = ni->begin ();
354
  NiChanges::const_iterator j = ni->begin ();
366
  Time previous = (*j).GetTime ();
355
  Time previous = j->GetTime ();
367
  WifiPreamble preamble = txVector.GetPreambleType ();
356
  WifiPreamble preamble = txVector.GetPreambleType ();
368
  WifiMode mcsHeaderMode;
357
  WifiMode mcsHeaderMode;
369
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
358
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
 Lines 382-397    Link Here 
382
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
371
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
383
    }
372
    }
384
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
373
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
385
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
374
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
386
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
375
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
387
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
376
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
388
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
377
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
389
  double noiseInterferenceW = (*j).GetDelta ();
378
  double noiseInterferenceW = m_firstPower;
390
  double powerW = event->GetRxPowerW ();
379
  double powerW = event->GetRxPowerW ();
391
  j++;
380
  ++j;
392
  while (ni->end () != j)
381
  while (ni->end () != j)
393
    {
382
    {
394
      Time current = (*j).GetTime ();
383
      Time current = j->GetTime ();
395
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
384
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
396
      NS_ASSERT (current >= previous);
385
      NS_ASSERT (current >= previous);
397
      //Case 1: previous and current after playload start: nothing to do
386
      //Case 1: previous and current after playload start: nothing to do
 Lines 764-772    Link Here 
764
            }
753
            }
765
        }
754
        }
766
755
767
      noiseInterferenceW += (*j).GetDelta ();
756
      noiseInterferenceW = j->GetPower () - powerW;
768
      previous = (*j).GetTime ();
757
      previous = j->GetTime ();
769
      j++;
758
      ++j;
770
    }
759
    }
771
760
772
  double per = 1 - psr;
761
  double per = 1 - psr;
 Lines 821-836    Link Here 
821
  m_firstPower = 0;
810
  m_firstPower = 0;
822
}
811
}
823
812
824
InterferenceHelper::NiChanges::const_iterator
813
InterferenceHelper::NiChanges::iterator
825
InterferenceHelper::GetPosition (Time moment)
814
InterferenceHelper::GetNextPosition (Time moment)
826
{
815
{
827
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
816
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
828
}
817
}
829
818
830
void
819
InterferenceHelper::NiChanges::iterator
820
InterferenceHelper::GetPreviousPosition (Time moment)
821
{
822
  InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment);
823
  --it;
824
  return it;
825
}
826
827
InterferenceHelper::NiChanges::iterator
828
InterferenceHelper::GetPositionBeforeTime (Time moment)
829
{
830
  InterferenceHelper::NiChanges::iterator it = std::lower_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
831
  --it;
832
  return it;
833
}
834
835
int64_t
831
InterferenceHelper::AddNiChangeEvent (NiChange change)
836
InterferenceHelper::AddNiChangeEvent (NiChange change)
832
{
837
{
833
  m_niChanges.insert (GetPosition (change.GetTime ()), change);
838
  auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change);
839
  return std::distance (m_niChanges.begin (), it);
834
}
840
}
835
841
836
void
842
void
 Lines 845-850    Link Here 
845
{
851
{
846
  NS_LOG_FUNCTION (this);
852
  NS_LOG_FUNCTION (this);
847
  m_rxing = false;
853
  m_rxing = false;
854
  //Update m_firstPower for frame capture
855
  auto it = GetPositionBeforeTime (Simulator::Now ());
856
  m_firstPower = it->GetPower ();
848
}
857
}
849
858
850
} //namespace ns3
859
} //namespace ns3
(-)a/src/wifi/model/interference-helper.h (-10 / +33 lines)
 Lines 149-155    Link Here 
149
   *          energy on the medium will be higher than
149
   *          energy on the medium will be higher than
150
   *          the requested threshold.
150
   *          the requested threshold.
151
   */
151
   */
152
  Time GetEnergyDuration (double energyW) const;
152
  Time GetEnergyDuration (double energyW);
153
153
154
  /**
154
  /**
155
   * Add the packet-related signal to interference helper.
155
   * Add the packet-related signal to interference helper.
 Lines 213-222    Link Here 
213
     * Create a NiChange at the given time and the amount of NI change.
213
     * Create a NiChange at the given time and the amount of NI change.
214
     *
214
     *
215
     * \param time time of the event
215
     * \param time time of the event
216
     * \param delta the power
216
     * \param power the power
217
     * \param event causes this NI change
217
     * \param event causes this NI change
218
     */
218
     */
219
    NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event);
219
    NiChange (Time time, double power, Ptr<InterferenceHelper::Event> event);
220
    /**
220
    /**
221
     * Return the event time.
221
     * Return the event time.
222
     *
222
     *
 Lines 228-234    Link Here 
228
     *
228
     *
229
     * \return the power
229
     * \return the power
230
     */
230
     */
231
    double GetDelta (void) const;
231
    double GetPower (void) const;
232
    /**
233
     * Add a given amount of power.
234
     *
235
     * \param power the power to be added to the existing value
236
     */
237
    void AddPower (double power);
232
    /**
238
    /**
233
     * Return the event causes the corresponding NI change
239
     * Return the event causes the corresponding NI change
234
     *
240
     *
 Lines 246-252    Link Here 
246
252
247
private:
253
private:
248
    Time m_time; ///< time
254
    Time m_time; ///< time
249
    double m_delta; ///< delta
255
    double m_power; ///< power
250
    Ptr<InterferenceHelper::Event> m_event; ///< event
256
    Ptr<InterferenceHelper::Event> m_event; ///< event
251
  };
257
  };
252
  /**
258
  /**
 Lines 268-274    Link Here 
268
   *
274
   *
269
   * \return noise and interference power
275
   * \return noise and interference power
270
   */
276
   */
271
  double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const;
277
  double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni);
272
  /**
278
  /**
273
   * Calculate SNR (linear ratio) from the given signal power and noise+interference power.
279
   * Calculate SNR (linear ratio) from the given signal power and noise+interference power.
274
   * (Mode is not currently used)
280
   * (Mode is not currently used)
 Lines 322-339    Link Here 
322
  bool m_rxing; ///< flag whether it is in receiving state
328
  bool m_rxing; ///< flag whether it is in receiving state
323
329
324
  /**
330
  /**
325
   * Returns a const iterator to the first nichange, which is later than moment
331
   * Returns an iterator to the first nichange that is later than moment
326
   *
332
   *
327
   * \param moment time to check from
333
   * \param moment time to check from
328
   * \returns an iterator to the list of NiChanges
334
   * \returns an iterator to the list of NiChanges
329
   */
335
   */
330
  NiChanges::const_iterator GetPosition (Time moment);
336
  NiChanges::iterator GetNextPosition (Time moment);
331
  /**
337
  /**
332
   * Add NiChange to the list at the appropriate position.
338
   * Returns an iterator to the last nichange that is before than moment
339
   *
340
   * \param moment time to check from
341
   * \returns an iterator to the list of NiChanges
342
   */
343
  NiChanges::iterator GetPreviousPosition (Time moment);
344
  /**
345
   * Returns an iterator to the nichange that occured just before moment
346
   *
347
   * \param moment time to check from
348
   * \returns an iterator to the list of NiChanges
349
   */
350
  NiChanges::iterator GetPositionBeforeTime (Time moment);
351
352
  /**
353
   * Add NiChange to the list at the appropriate position and
354
   * return the iterator of the new event.
333
   *
355
   *
334
   * \param change
356
   * \param change
357
   * \returns the iterator of the new event
335
   */
358
   */
336
  void AddNiChangeEvent (NiChange change);
359
  int64_t AddNiChangeEvent (NiChange change);
337
};
360
};
338
361
339
} //namespace ns3
362
} //namespace ns3

Return to bug 2791