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

(-)a/src/wifi/model/interference-helper.cc (-93 / +81 lines)
 Lines 88-110    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 (double power, Ptr<InterferenceHelper::Event> event)
92
  : m_time (time),
92
  : m_power (power),
93
    m_delta (delta),
94
    m_event (event)
93
    m_event (event)
95
{
94
{
96
}
95
}
97
96
98
Time
97
double
99
InterferenceHelper::NiChange::GetTime (void) const
98
InterferenceHelper::NiChange::GetPower (void) const
100
{
99
{
101
  return m_time;
100
  return m_power;
102
}
101
}
103
102
104
double
103
void
105
InterferenceHelper::NiChange::GetDelta (void) const
104
InterferenceHelper::NiChange::AddPower (double power)
106
{
105
{
107
  return m_delta;
106
  m_power += power;
108
}
107
}
109
108
110
Ptr<InterferenceHelper::Event>
109
Ptr<InterferenceHelper::Event>
 Lines 113-124    Link Here 
113
  return m_event;
112
  return m_event;
114
}
113
}
115
114
116
bool
117
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const
118
{
119
  return (m_time < o.m_time);
120
}
121
122
115
123
/****************************************************************
116
/****************************************************************
124
 *       The actual InterferenceHelper
117
 *       The actual InterferenceHelper
 Lines 141-148    Link Here 
141
Ptr<InterferenceHelper::Event>
134
Ptr<InterferenceHelper::Event>
142
InterferenceHelper::Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPowerW)
135
InterferenceHelper::Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPowerW)
143
{
136
{
144
  Ptr<InterferenceHelper::Event> event;
137
  Ptr<InterferenceHelper::Event> event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW);
145
  event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW);
146
  AppendEvent (event);
138
  AppendEvent (event);
147
  return event;
139
  return event;
148
}
140
}
 Lines 188-211    Link Here 
188
}
180
}
189
181
190
Time
182
Time
191
InterferenceHelper::GetEnergyDuration (double energyW) const
183
InterferenceHelper::GetEnergyDuration (double energyW)
192
{
184
{
193
  Time now = Simulator::Now ();
185
  Time now = Simulator::Now ();
194
  double noiseInterferenceW = 0;
186
  auto i = GetPreviousPosition (now);
195
  Time end = now;
187
  Time end = i->first;
196
  noiseInterferenceW = m_firstPower;
188
  while (i != m_niChanges.end ())
197
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
198
    {
189
    {
199
      noiseInterferenceW += i->GetDelta ();
190
      double noiseInterferenceW = i->second.GetPower ();
200
      end = i->GetTime ();
191
      end = i->first;
201
      if (end < now)
202
        {
203
          continue;
204
        }
205
      if (noiseInterferenceW < energyW)
192
      if (noiseInterferenceW < energyW)
206
        {
193
        {
207
          break;
194
          break;
208
        }
195
        }
196
      ++i;
209
    }
197
    }
210
  return end > now ? end - now : MicroSeconds (0);
198
  return end > now ? end - now : MicroSeconds (0);
211
}
199
}
 Lines 213-230    Link Here 
213
void
201
void
214
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
202
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
215
{
203
{
216
  Time now = Simulator::Now ();
204
  NS_LOG_FUNCTION (this);
205
  double previousPowerStart = 0;
206
  double previousPowerEnd = 0;
207
  if (m_niChanges.size() > 0)
208
    {
209
      previousPowerStart = GetPreviousPosition (event->GetStartTime ())->second.GetPower ();
210
      previousPowerEnd = GetPreviousPosition (event->GetEndTime ())->second.GetPower ();
211
    }
217
  if (!m_rxing)
212
  if (!m_rxing)
218
    {
213
    {
219
      NiChanges::const_iterator nowIterator = GetPosition (now);
214
      m_firstPower = previousPowerStart;
220
      for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++)
215
      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
    }
216
    }
226
  AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
217
  auto first = AddNiChangeEvent (event->GetStartTime (), NiChange (previousPowerStart, event));
227
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
218
  auto last = AddNiChangeEvent (event->GetEndTime (), NiChange (previousPowerEnd, event));
219
  for (auto i = first; i != last; ++i)
220
    {
221
      i->second.AddPower (event->GetRxPowerW ());
222
    }
228
}
223
}
229
224
230
double
225
double
 Lines 243-286    Link Here 
243
}
238
}
244
239
245
double
240
double
246
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
241
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni)
247
{
242
{
248
  double noiseInterference = m_firstPower;
243
  double noiseInterference = m_firstPower;
249
  NiChanges::const_iterator eventIterator = m_niChanges.begin ();
244
  auto it = m_niChanges.begin ();
250
  while (eventIterator != m_niChanges.end ())
245
  for (; it != m_niChanges.end () && it->second.GetEvent () != event; ++it)
251
    {
246
    {
252
      // Iterate the NI change list from the beginning to the end
247
      noiseInterference = it->second.GetPower ();
253
      // until find the position of the event in the NI change list
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
    }
248
    }
273
249
  ni->emplace (event->GetStartTime (), NiChange (0, event));
274
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
250
  while (++it != m_niChanges.end () && event != it->second.GetEvent ())
275
    {
251
    {
276
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
252
      ni->insert (*it);
277
        {
278
          break;
279
        }
280
      ni->push_back (*i);
281
    }
253
    }
282
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
254
  ni->emplace(event->GetEndTime (), NiChange (0, event));
283
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
284
  return noiseInterference;
255
  return noiseInterference;
285
}
256
}
286
257
 Lines 312-331    Link Here 
312
  NS_LOG_FUNCTION (this);
283
  NS_LOG_FUNCTION (this);
313
  const WifiTxVector txVector = event->GetTxVector ();
284
  const WifiTxVector txVector = event->GetTxVector ();
314
  double psr = 1.0; /* Packet Success Rate */
285
  double psr = 1.0; /* Packet Success Rate */
315
  NiChanges::const_iterator j = ni->begin ();
286
  auto j = ni->begin ();
316
  Time previous = (*j).GetTime ();
287
  Time previous = j->first;
317
  WifiMode payloadMode = event->GetPayloadMode ();
288
  WifiMode payloadMode = event->GetPayloadMode ();
318
  WifiPreamble preamble = txVector.GetPreambleType ();
289
  WifiPreamble preamble = txVector.GetPreambleType ();
319
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
290
  Time plcpHeaderStart = j->first + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
320
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
291
  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
292
  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
293
  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 ();
294
  double noiseInterferenceW = m_firstPower;
324
  double powerW = event->GetRxPowerW ();
295
  double powerW = event->GetRxPowerW ();
325
  j++;
296
  ++j;
326
  while (ni->end () != j)
297
  while (ni->end () != j)
327
    {
298
    {
328
      Time current = (*j).GetTime ();
299
      Time current = j->first;
329
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
300
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
330
      NS_ASSERT (current >= previous);
301
      NS_ASSERT (current >= previous);
331
      //Case 1: Both previous and current point to the payload
302
      //Case 1: Both previous and current point to the payload
 Lines 348-356    Link Here 
348
                                            payloadMode, txVector);
319
                                            payloadMode, txVector);
349
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
320
          NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr);
350
        }
321
        }
351
      noiseInterferenceW += (*j).GetDelta ();
322
      noiseInterferenceW = j->second.GetPower () - powerW;
352
      previous = (*j).GetTime ();
323
      previous = j->first;
353
      j++;
324
      ++j;
354
    }
325
    }
355
  double per = 1 - psr;
326
  double per = 1 - psr;
356
  return per;
327
  return per;
 Lines 362-369    Link Here 
362
  NS_LOG_FUNCTION (this);
333
  NS_LOG_FUNCTION (this);
363
  const WifiTxVector txVector = event->GetTxVector ();
334
  const WifiTxVector txVector = event->GetTxVector ();
364
  double psr = 1.0; /* Packet Success Rate */
335
  double psr = 1.0; /* Packet Success Rate */
365
  NiChanges::const_iterator j = ni->begin ();
336
  auto j = ni->begin ();
366
  Time previous = (*j).GetTime ();
337
  Time previous = j->first;
367
  WifiPreamble preamble = txVector.GetPreambleType ();
338
  WifiPreamble preamble = txVector.GetPreambleType ();
368
  WifiMode mcsHeaderMode;
339
  WifiMode mcsHeaderMode;
369
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
340
  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF)
 Lines 382-397    Link Here 
382
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
353
      mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode ();
383
    }
354
    }
384
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
355
  WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector);
385
  Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
356
  Time plcpHeaderStart = j->first + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble
386
  Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG
357
  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
358
  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
359
  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 ();
360
  double noiseInterferenceW = m_firstPower;
390
  double powerW = event->GetRxPowerW ();
361
  double powerW = event->GetRxPowerW ();
391
  j++;
362
  ++j;
392
  while (ni->end () != j)
363
  while (ni->end () != j)
393
    {
364
    {
394
      Time current = (*j).GetTime ();
365
      Time current = j->first;
395
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
366
      NS_LOG_DEBUG ("previous= " << previous << ", current=" << current);
396
      NS_ASSERT (current >= previous);
367
      NS_ASSERT (current >= previous);
397
      //Case 1: previous and current after playload start: nothing to do
368
      //Case 1: previous and current after playload start: nothing to do
 Lines 764-772    Link Here 
764
            }
735
            }
765
        }
736
        }
766
737
767
      noiseInterferenceW += (*j).GetDelta ();
738
      noiseInterferenceW = j->second.GetPower () - powerW;
768
      previous = (*j).GetTime ();
739
      previous = j->first;
769
      j++;
740
      ++j;
770
    }
741
    }
771
742
772
  double per = 1 - psr;
743
  double per = 1 - psr;
 Lines 821-836    Link Here 
821
  m_firstPower = 0;
792
  m_firstPower = 0;
822
}
793
}
823
794
824
InterferenceHelper::NiChanges::const_iterator
795
InterferenceHelper::NiChanges::iterator
825
InterferenceHelper::GetPosition (Time moment)
796
InterferenceHelper::GetNextPosition (Time moment)
826
{
797
{
827
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
798
  return m_niChanges.upper_bound (moment);
828
}
799
}
829
800
830
void
801
InterferenceHelper::NiChanges::iterator
831
InterferenceHelper::AddNiChangeEvent (NiChange change)
802
InterferenceHelper::GetPreviousPosition (Time moment)
832
{
803
{
833
  m_niChanges.insert (GetPosition (change.GetTime ()), change);
804
  auto it = GetNextPosition (moment);
805
  return --it;
806
}
807
808
InterferenceHelper::NiChanges::iterator
809
InterferenceHelper::GetPositionBeforeTime (Time moment)
810
{
811
  auto it = m_niChanges.find (moment);
812
  return --it;
813
}
814
815
InterferenceHelper::NiChanges::iterator
816
InterferenceHelper::AddNiChangeEvent (Time moment, NiChange change)
817
{
818
  return m_niChanges.insert (GetNextPosition (moment), std::make_pair (moment, change));
834
}
819
}
835
820
836
void
821
void
 Lines 845-850    Link Here 
845
{
830
{
846
  NS_LOG_FUNCTION (this);
831
  NS_LOG_FUNCTION (this);
847
  m_rxing = false;
832
  m_rxing = false;
833
  //Update m_firstPower for frame capture
834
  auto it = GetPositionBeforeTime (Simulator::Now ());
835
  m_firstPower = it->second.GetPower ();
848
}
836
}
849
837
850
} //namespace ns3
838
} //namespace ns3
(-)a/src/wifi/model/interference-helper.h (-27 / +37 lines)
 Lines 25-30    Link Here 
25
#include "ns3/packet.h"
25
#include "ns3/packet.h"
26
#include "wifi-tx-vector.h"
26
#include "wifi-tx-vector.h"
27
#include "error-rate-model.h"
27
#include "error-rate-model.h"
28
#include <map>
28
29
29
namespace ns3 {
30
namespace ns3 {
30
31
 Lines 149-155    Link Here 
149
   *          energy on the medium will be higher than
150
   *          energy on the medium will be higher than
150
   *          the requested threshold.
151
   *          the requested threshold.
151
   */
152
   */
152
  Time GetEnergyDuration (double energyW) const;
153
  Time GetEnergyDuration (double energyW);
153
154
154
  /**
155
  /**
155
   * Add the packet-related signal to interference helper.
156
   * Add the packet-related signal to interference helper.
 Lines 212-258    Link Here 
212
    /**
213
    /**
213
     * Create a NiChange at the given time and the amount of NI change.
214
     * Create a NiChange at the given time and the amount of NI change.
214
     *
215
     *
215
     * \param time time of the event
216
     * \param power the power
216
     * \param delta 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 (double power, Ptr<InterferenceHelper::Event> event);
220
    /**
221
     * Return the event time.
222
     *
223
     * \return the event time.
224
     */
225
    Time GetTime (void) const;
226
    /**
220
    /**
227
     * Return the power
221
     * Return the power
228
     *
222
     *
229
     * \return the power
223
     * \return the power
230
     */
224
     */
231
    double GetDelta (void) const;
225
    double GetPower (void) const;
226
    /**
227
     * Add a given amount of power.
228
     *
229
     * \param power the power to be added to the existing value
230
     */
231
    void AddPower (double power);
232
    /**
232
    /**
233
     * Return the event causes the corresponding NI change
233
     * Return the event causes the corresponding NI change
234
     *
234
     *
235
     * \return the event
235
     * \return the event
236
     */
236
     */
237
    Ptr<InterferenceHelper::Event> GetEvent (void) const;
237
    Ptr<InterferenceHelper::Event> GetEvent (void) const;
238
    /**
239
     * Compare the event time of two NiChange objects (a < o).
240
     *
241
     * \param o
242
     * \return true if a < o.time, false otherwise
243
     */
244
    bool operator < (const NiChange& o) const;
245
238
246
239
247
private:
240
private:
248
    Time m_time; ///< time
241
    double m_power; ///< power
249
    double m_delta; ///< delta
250
    Ptr<InterferenceHelper::Event> m_event; ///< event
242
    Ptr<InterferenceHelper::Event> m_event; ///< event
251
  };
243
  };
252
  /**
244
  /**
253
   * typedef for a vector of NiChanges
245
   * typedef for a multimap of NiChanges
254
   */
246
   */
255
  typedef std::vector <NiChange> NiChanges;
247
  typedef std::multimap<Time, NiChange> NiChanges;
256
248
257
  /**
249
  /**
258
   * Append the given Event.
250
   * Append the given Event.
 Lines 268-274    Link Here 
268
   *
260
   *
269
   * \return noise and interference power
261
   * \return noise and interference power
270
   */
262
   */
271
  double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const;
263
  double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni);
272
  /**
264
  /**
273
   * Calculate SNR (linear ratio) from the given signal power and noise+interference power.
265
   * Calculate SNR (linear ratio) from the given signal power and noise+interference power.
274
   * (Mode is not currently used)
266
   * (Mode is not currently used)
 Lines 322-339    Link Here 
322
  bool m_rxing; ///< flag whether it is in receiving state
314
  bool m_rxing; ///< flag whether it is in receiving state
323
315
324
  /**
316
  /**
325
   * Returns a const iterator to the first nichange, which is later than moment
317
   * Returns an iterator to the first nichange that is later than moment
326
   *
318
   *
327
   * \param moment time to check from
319
   * \param moment time to check from
328
   * \returns an iterator to the list of NiChanges
320
   * \returns an iterator to the list of NiChanges
329
   */
321
   */
330
  NiChanges::const_iterator GetPosition (Time moment);
322
  NiChanges::iterator GetNextPosition (Time moment);
331
  /**
323
  /**
332
   * Add NiChange to the list at the appropriate position.
324
   * Returns an iterator to the last nichange that is before than moment
325
   *
326
   * \param moment time to check from
327
   * \returns an iterator to the list of NiChanges
328
   */
329
  NiChanges::iterator GetPreviousPosition (Time moment);
330
  /**
331
   * Returns an iterator to the nichange that occured just before moment
332
   *
333
   * \param moment time to check from
334
   * \returns an iterator to the list of NiChanges
335
   */
336
  NiChanges::iterator GetPositionBeforeTime (Time moment);
337
338
  /**
339
   * Add NiChange to the list at the appropriate position and
340
   * return the iterator of the new event.
333
   *
341
   *
334
   * \param change
342
   * \param change
343
   * \param moment
344
   * \returns the iterator of the new event
335
   */
345
   */
336
  void AddNiChangeEvent (NiChange change);
346
  NiChanges::iterator AddNiChangeEvent (Time moment, NiChange change);
337
};
347
};
338
348
339
} //namespace ns3
349
} //namespace ns3

Return to bug 2791