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

(-)a/src/wifi/model/interference-helper.cc (-72 / +84 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-209    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.0;
200
195
  Time end = now;
201
  auto i = GetPreviousPosition (now);
196
  noiseInterferenceW = m_firstPower;
202
  double noiseInterferenceW = i->GetDelta ();
197
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
203
  Time end = i->GetTime ();
204
  
205
  for ( ; i != m_niChanges.end (); i++)
198
    {
206
    {
199
      noiseInterferenceW += i->GetDelta ();
207
      if (i->GetDelta () < energyW)
200
      end = i->GetTime ();
201
      if (end < now)
202
        {
208
        {
203
          continue;
209
          noiseInterferenceW = i->GetDelta ();
204
        }
210
          end = i->GetTime ();
205
      if (noiseInterferenceW < energyW)
206
        {
207
          break;
211
          break;
208
        }
212
        }
209
    }
213
    }
 Lines 213-235    Link Here 
213
void
217
void
214
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
218
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
215
{
219
{
216
  Time now = Simulator::Now ();
220
  double previousPowerStart = 0;
221
  auto itPreviousEvent = GetPreviousPosition (event->GetStartTime ());
222
  double previousPowerEnd = 0;
223
  auto itNextEvent = GetPreviousPosition (event->GetEndTime ());
224
  if ( m_niChanges.size() > 0 )    {
225
      previousPowerStart = itPreviousEvent->GetPower ();
226
      previousPowerEnd = itNextEvent->GetPower ();
227
    }
228
  
217
  if (!m_rxing)
229
  if (!m_rxing)
218
    {
230
    {
219
      NiChanges::const_iterator nowIterator = GetPosition (now);
231
      m_firstPower = previousPowerStart;
220
      for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++)
232
      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
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
226
    }
233
    }
227
  else
234
  auto first = AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart, event));
235
  auto last = AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event));
236
  for (auto i = first; i < last; i++)
228
    {
237
    {
229
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
238
      m_niChanges.at (i).AddPower (event->GetRxPowerW ());
230
    }
239
    }
231
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
232
233
}
240
}
234
241
235
242
 Lines 252-291    Link Here 
252
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
259
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
253
{
260
{
254
  double noiseInterference = m_firstPower;
261
  double noiseInterference = m_firstPower;
255
  NiChanges::const_iterator eventIterator = m_niChanges.begin ();
262
256
  while (eventIterator != m_niChanges.end ())
263
  // Iterate the NI change list from the beginning to the end
264
  // until find the position of the event in the NI change list
265
  // The reason of using the event that causes the NI change to identify
266
  // different NI changes is because in some special cases
267
  // different NI changes happen at the same time with the same delta
268
  // value. Therefore, it may be impossible to identify a NI change that belongs
269
  // to which event based on just the NI time and NI power value
270
  NiChanges::const_iterator it = GetPreviousPosition (event->GetStartTime ());
271
  while (it != m_niChanges.end () && it->GetEvent () != event)
257
    {
272
    {
258
      // Iterate the NI change list from the beginning to the end
273
      ++it;
259
      // until find the position of the event in the NI change list
260
      // The reason of using the event that causes the NI change to identify
261
      // different NI changes is because in some special cases
262
      // different NI changes happen at the same time with the same delta
263
      // value. Therefore, it may be impossible to identify a NI change that belongs
264
      // to which event based on just the NI time and NI delta value
265
      if (eventIterator->GetEvent () != event)
266
        {
267
          // The NI changes which happen before the event should be considered
268
          // as the interference. This considers the case that the receiving event
269
          // arrives while another receiving event is going on. The SINR of
270
          // the newly arrived event is calculated for checking the possibility of frame capture
271
          noiseInterference += eventIterator->GetDelta ();
272
        }
273
      else
274
        {
275
          break;
276
        }
277
      ++eventIterator;
278
    }
274
    }
279
275
280
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
276
  // The NI changes which happen before the event should be considered
277
  // as the interference. This considers the case that the receiving event
278
  // arrives while another receiving event is going on. The SINR of
279
  // the newly arrived event is calculated for checking the possibility of frame capture
280
  --it;
281
  noiseInterference = it>GetPower ();
282
  ni->push_back (NiChange (event->GetStartTime (), 0, event));
283
  
284
  ++it;
285
  for ( ; it->GetEvent () == event;; ++it)
281
    {
286
    {
282
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
287
      ni->push_back (*it);
283
        {
284
          break;
285
        }
286
      ni->push_back (*i);
287
    }
288
    }
288
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
289
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
289
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
290
  return noiseInterference;
290
  return noiseInterference;
291
}
291
}
 Lines 317-335    Link Here 
317
  const WifiTxVector txVector = event->GetTxVector ();
317
  const WifiTxVector txVector = event->GetTxVector ();
318
  double psr = 1.0; /* Packet Success Rate */
318
  double psr = 1.0; /* Packet Success Rate */
319
  NiChanges::const_iterator j = ni->begin ();
319
  NiChanges::const_iterator j = ni->begin ();
320
  Time previous = (*j).GetTime ();
320
  Time previous = j->GetTime ();
321
  WifiMode payloadMode = event->GetPayloadMode ();
321
  WifiMode payloadMode = event->GetPayloadMode ();
322
  WifiPreamble preamble = txVector.GetPreambleType ();
322
  WifiPreamble preamble = txVector.GetPreambleType ();
323
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
323
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
324
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
324
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
325
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
325
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
326
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
326
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
327
  double noiseInterferenceW = (*j).GetDelta ();
327
  double noiseInterferenceW = m_firstPower;
328
  double powerW = event->GetRxPowerW ();
328
  double powerW = event->GetRxPowerW ();
329
  j++;
329
  j++;
330
  while (ni->end () != j)
330
  while (ni->end () != j)
331
    {
331
    {
332
      Time current = (*j).GetTime ();
332
      Time current = j->GetTime ();
333
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
333
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
334
      NS_ASSERT (current >= previous);
334
      NS_ASSERT (current >= previous);
335
      //Case 1: Both previous and current point to the payload
335
      //Case 1: Both previous and current point to the payload
 Lines 354-361    Link Here 
354
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
354
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
355
        }
355
        }
356
356
357
      noiseInterferenceW += (*j).GetDelta ();
357
      noiseInterferenceW = j->GetPower () - powerW;
358
      previous = (*j).GetTime ();
358
      previous = j->GetTime ();
359
      j++;
359
      j++;
360
    }
360
    }
361
361
 Lines 370-376    Link Here 
370
  const WifiTxVector txVector = event->GetTxVector ();
370
  const WifiTxVector txVector = event->GetTxVector ();
371
  double psr = 1.0; /* Packet Success Rate */
371
  double psr = 1.0; /* Packet Success Rate */
372
  NiChanges::const_iterator j = ni->begin ();
372
  NiChanges::const_iterator j = ni->begin ();
373
  Time previous = (*j).GetTime ();
373
  Time previous = j->GetTime ();
374
  WifiPreamble preamble = txVector.GetPreambleType ();
374
  WifiPreamble preamble = txVector.GetPreambleType ();
375
  WifiMode mcsHeaderMode;
375
  WifiMode mcsHeaderMode;
376
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
376
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
 Lines 389-404    Link Here 
389
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
389
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
390
    }
390
    }
391
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
391
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
392
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
392
  Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
393
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
393
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
394
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
394
  Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A
395
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
395
  Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B
396
  double noiseInterferenceW = (*j).GetDelta ();
396
  double noiseInterferenceW = m_firstPower;
397
  double powerW = event->GetRxPowerW ();
397
  double powerW = event->GetRxPowerW ();
398
  j++;
398
  j++;
399
  while (ni->end () != j)
399
  while (ni->end () != j)
400
    {
400
    {
401
      Time current = (*j).GetTime ();
401
      Time current = j->GetTime ();
402
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
402
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
403
      NS_ASSERT (current >= previous);
403
      NS_ASSERT (current >= previous);
404
      //Case 1: previous and current after playload start: nothing to do
404
      //Case 1: previous and current after playload start: nothing to do
 Lines 812-819    Link Here 
812
            }
812
            }
813
        }
813
        }
814
814
815
      noiseInterferenceW += (*j).GetDelta ();
815
      noiseInterferenceW = j->GetPower () - powerW;
816
      previous = (*j).GetTime ();
816
      previous = j->GetTime ();
817
      j++;
817
      j++;
818
    }
818
    }
819
819
 Lines 869-884    Link Here 
869
  m_firstPower = 0.0;
869
  m_firstPower = 0.0;
870
}
870
}
871
871
872
InterferenceHelper::NiChanges::const_iterator
872
InterferenceHelper::NiChanges::iterator
873
InterferenceHelper::GetPosition (Time moment)
873
InterferenceHelper::GetNextPosition (Time moment)
874
{
874
{
875
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
875
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
876
}
876
}
877
877
878
void
878
InterferenceHelper::NiChanges::iterator
879
InterferenceHelper::GetPreviousPosition (Time moment)
880
{
881
  InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment);
882
  --it;
883
  return it;
884
}
885
886
int64_t
879
InterferenceHelper::AddNiChangeEvent (NiChange change)
887
InterferenceHelper::AddNiChangeEvent (NiChange change)
880
{
888
{
881
  m_niChanges.insert (GetPosition (change.GetTime ()), change);
889
  auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change);
890
  return std::distance (m_niChanges.begin (), it);
882
}
891
}
883
892
884
void
893
void
 Lines 893-898    Link Here 
893
{
902
{
894
  NS_LOG_FUNCTION (this);
903
  NS_LOG_FUNCTION (this);
895
  m_rxing = false;
904
  m_rxing = false;
905
  //Update m_firstPower for frame capture
906
  auto it = GetPreviousPosition (Simulator::Now ());
907
  m_firstPower = it->GetPower ();
896
}
908
}
897
909
898
} //namespace ns3
910
} //namespace ns3
(-)a/src/wifi/model/interference-helper.h (-8 / +24 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-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
  /**
346
   * Add NiChange to the list at the appropriate position and
347
   * return the iterator of the new event.
333
   *
348
   *
334
   * \param change
349
   * \param change
350
   * \returns the iterator of the new event
335
   */
351
   */
336
  void AddNiChangeEvent (NiChange change);
352
  int64_t AddNiChangeEvent (NiChange change);
337
};
353
};
338
354
339
} //namespace ns3
355
} //namespace ns3

Return to bug 2791