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

(-)a/src/wifi/model/interference-helper.cc (-32 / +68 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 191-202    Link Here 
191
InterferenceHelper::GetEnergyDuration (double energyW) const
197
InterferenceHelper::GetEnergyDuration (double energyW) const
192
{
198
{
193
  Time now = Simulator::Now ();
199
  Time now = Simulator::Now ();
194
  double noiseInterferenceW = 0;
200
  double noiseInterferenceW = m_firstPower;
195
  Time end = now;
201
  Time end = now;
196
  noiseInterferenceW = m_firstPower;
197
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
202
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
198
    {
203
    {
199
      noiseInterferenceW += i->GetDelta ();
204
      noiseInterferenceW = i->GetPower ();
200
      end = i->GetTime ();
205
      end = i->GetTime ();
201
      if (end < now)
206
      if (end < now)
202
        {
207
        {
 Lines 213-230    Link Here 
213
void
218
void
214
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
219
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
215
{
220
{
216
  Time now = Simulator::Now ();
221
  double previousPowerStart = 0;
222
  NiChanges::iterator itPreviousEvent = GetPreviousPosition (event->GetStartTime ());
223
  if ((std::distance (m_niChanges.begin (), itPreviousEvent) > 0) || (itPreviousEvent == m_niChanges.begin ()))
224
    {
225
      previousPowerStart = itPreviousEvent->GetPower ();
226
    }
227
  double previousPowerEnd = 0;
228
  NiChanges::iterator itNextEvent = GetPreviousPosition (event->GetEndTime ());
229
  if ((std::distance (m_niChanges.begin (), itNextEvent) > 0) || (itNextEvent == m_niChanges.begin ()))
230
    {
231
      previousPowerEnd = itNextEvent->GetPower ();
232
    }
217
  if (!m_rxing)
233
  if (!m_rxing)
218
    {
234
    {
219
      NiChanges::const_iterator nowIterator = GetPosition (now);
235
      m_firstPower = previousPowerStart;
220
      for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++)
236
      m_niChanges.erase (m_niChanges.begin (), GetNextPosition (event->GetStartTime ()));
237
    }
238
  AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart + event->GetRxPowerW (), event));
239
  AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event));
240
  for (NiChanges::iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
241
    {
242
      if (i->GetTime () > event->GetStartTime () && i->GetTime () <= event->GetEndTime () && i->GetEvent () != event)
221
        {
243
        {
222
          m_firstPower += i->GetDelta ();
244
          i->AddPower (event->GetRxPowerW ());
223
        }
245
        }
224
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
225
    }
246
    }
226
  AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
227
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
228
}
247
}
229
248
230
double
249
double
 Lines 262-268    Link Here 
262
          // as the interference. This considers the case that the receiving event
281
          // as the interference. This considers the case that the receiving event
263
          // arrives while another receiving event is going on. The SINR of
282
          // 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
283
          // the newly arrived event is calculated for checking the possibility of frame capture
265
          noiseInterference += eventIterator->GetDelta ();
284
          noiseInterference = eventIterator->GetPower ();
266
        }
285
        }
267
      else
286
      else
268
        {
287
        {
 Lines 270-276    Link Here 
270
        }
289
        }
271
      ++eventIterator;
290
      ++eventIterator;
272
    }
291
    }
273
292
  ni->push_back (NiChange (event->GetStartTime (), 0, event));
274
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
293
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
275
    {
294
    {
276
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
295
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
 Lines 279-285    Link Here 
279
        }
298
        }
280
      ni->push_back (*i);
299
      ni->push_back (*i);
281
    }
300
    }
282
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
283
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
301
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
284
  return noiseInterference;
302
  return noiseInterference;
285
}
303
}
 Lines 311-329    Link Here 
311
  const WifiTxVector txVector = event->GetTxVector ();
329
  const WifiTxVector txVector = event->GetTxVector ();
312
  double psr = 1.0; /* Packet Success Rate */
330
  double psr = 1.0; /* Packet Success Rate */
313
  NiChanges::const_iterator j = ni->begin ();
331
  NiChanges::const_iterator j = ni->begin ();
314
  Time previous = (*j).GetTime ();
332
  Time previous = j->GetTime ();
315
  WifiMode payloadMode = event->GetPayloadMode ();
333
  WifiMode payloadMode = event->GetPayloadMode ();
316
  WifiPreamble preamble = txVector.GetPreambleType ();
334
  WifiPreamble preamble = txVector.GetPreambleType ();
317
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
335
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
318
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
336
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
319
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
337
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
320
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
338
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
321
  double noiseInterferenceW = (*j).GetDelta ();
339
  double noiseInterferenceW = m_firstPower;
322
  double powerW = event->GetRxPowerW ();
340
  double powerW = event->GetRxPowerW ();
323
  j++;
341
  j++;
324
  while (ni->end () != j)
342
  while (ni->end () != j)
325
    {
343
    {
326
      Time current = (*j).GetTime ();
344
      Time current = j->GetTime ();
327
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
345
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
328
      NS_ASSERT (current >= previous);
346
      NS_ASSERT (current >= previous);
329
      //Case 1: Both previous and current point to the payload
347
      //Case 1: Both previous and current point to the payload
 Lines 346-353    Link Here 
346
                                            payloadMode, txVector);
364
                                            payloadMode, txVector);
347
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
365
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
348
        }
366
        }
349
      noiseInterferenceW += (*j).GetDelta ();
367
      noiseInterferenceW = j->GetPower () - powerW;
350
      previous = (*j).GetTime ();
368
      previous = j->GetTime ();
351
      j++;
369
      j++;
352
    }
370
    }
353
  double per = 1 - psr;
371
  double per = 1 - psr;
 Lines 361-367    Link Here 
361
  const WifiTxVector txVector = event->GetTxVector ();
379
  const WifiTxVector txVector = event->GetTxVector ();
362
  double psr = 1.0; /* Packet Success Rate */
380
  double psr = 1.0; /* Packet Success Rate */
363
  NiChanges::const_iterator j = ni->begin ();
381
  NiChanges::const_iterator j = ni->begin ();
364
  Time previous = (*j).GetTime ();
382
  Time previous = j->GetTime ();
365
  WifiPreamble preamble = txVector.GetPreambleType ();
383
  WifiPreamble preamble = txVector.GetPreambleType ();
366
  WifiMode mcsHeaderMode;
384
  WifiMode mcsHeaderMode;
367
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
385
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
 Lines 380-395    Link Here 
380
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
398
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
381
    }
399
    }
382
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
400
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
383
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
401
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
384
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
402
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
385
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
403
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
386
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
404
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
387
  double noiseInterferenceW = (*j).GetDelta ();
405
  double noiseInterferenceW = m_firstPower;
388
  double powerW = event->GetRxPowerW ();
406
  double powerW = event->GetRxPowerW ();
389
  j++;
407
  j++;
390
  while (ni->end () != j)
408
  while (ni->end () != j)
391
    {
409
    {
392
      Time current = (*j).GetTime ();
410
      Time current = j->GetTime ();
393
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
411
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
394
      NS_ASSERT (current >= previous);
412
      NS_ASSERT (current >= previous);
395
      //Case 1: previous and current after playload start: nothing to do
413
      //Case 1: previous and current after playload start: nothing to do
 Lines 762-769    Link Here 
762
            }
780
            }
763
        }
781
        }
764
782
765
      noiseInterferenceW += (*j).GetDelta ();
783
      noiseInterferenceW = j->GetPower () - powerW;
766
      previous = (*j).GetTime ();
784
      previous = j->GetTime ();
767
      j++;
785
      j++;
768
    }
786
    }
769
787
 Lines 819-834    Link Here 
819
  m_firstPower = 0;
837
  m_firstPower = 0;
820
}
838
}
821
839
822
InterferenceHelper::NiChanges::const_iterator
840
InterferenceHelper::NiChanges::iterator
823
InterferenceHelper::GetPosition (Time moment)
841
InterferenceHelper::GetNextPosition (Time moment)
824
{
842
{
825
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
843
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
826
}
844
}
827
845
846
InterferenceHelper::NiChanges::iterator
847
InterferenceHelper::GetPreviousPosition (Time moment)
848
{
849
  InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment);
850
  --it;
851
  return it;
852
}
853
828
void
854
void
829
InterferenceHelper::AddNiChangeEvent (NiChange change)
855
InterferenceHelper::AddNiChangeEvent (NiChange change)
830
{
856
{
831
  m_niChanges.insert (GetPosition (change.GetTime ()), change);
857
  m_niChanges.insert (GetNextPosition (change.GetTime ()), change);
832
}
858
}
833
859
834
void
860
void
 Lines 843-848    Link Here 
843
{
869
{
844
  NS_LOG_FUNCTION (this);
870
  NS_LOG_FUNCTION (this);
845
  m_rxing = false;
871
  m_rxing = false;
872
  Time now = Simulator::Now ();
873
  //Update m_firstPower for frame capture
874
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
875
    {
876
      if (i->GetTime () >= now)
877
        {
878
          break;
879
        }
880
      m_firstPower = i->GetPower ();
881
    }
846
}
882
}
847
883
848
} //namespace ns3
884
} //namespace ns3
(-)a/src/wifi/model/interference-helper.h (-6 / +20 lines)
 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 322-333    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);
337
  /**
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
331
  /**
345
  /**
332
   * Add NiChange to the list at the appropriate position.
346
   * Add NiChange to the list at the appropriate position.
333
   *
347
   *

Return to bug 2791