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

(-)a/src/devices/wifi/interference-helper.cc (-107 / +55 lines)
 Lines 60-78    Link Here 
60
{
60
{
61
  return m_endTime;
61
  return m_endTime;
62
}
62
}
63
bool 
64
InterferenceHelper::Event::Overlaps (Time time) const
65
{
66
  if (m_startTime <= time &&
67
      m_endTime >= time) 
68
    {
69
      return true;
70
    } 
71
  else 
72
    {
73
      return false;
74
    }
75
}
76
double 
63
double 
77
InterferenceHelper::Event::GetRxPowerW (void) const
64
InterferenceHelper::Event::GetRxPowerW (void) const
78
{
65
{
 Lines 123-130    Link Here 
123
 ****************************************************************/
110
 ****************************************************************/
124
111
125
InterferenceHelper::InterferenceHelper ()
112
InterferenceHelper::InterferenceHelper ()
126
  : m_maxPacketDuration (Seconds(0)),
113
  : m_errorRateModel (0),
127
    m_errorRateModel (0)  
114
    m_firstPower (0.0),
115
    m_rxing (false)
128
{}
116
{}
129
InterferenceHelper::~InterferenceHelper ()
117
InterferenceHelper::~InterferenceHelper ()
130
{
118
{
 Lines 145-161    Link Here 
145
     preamble,
133
     preamble,
146
     duration,
134
     duration,
147
     rxPowerW);
135
     rxPowerW);
148
149
  m_maxPacketDuration = std::max(duration, m_maxPacketDuration);
150
  AppendEvent (event);
136
  AppendEvent (event);
151
  return event;
137
  return event;
152
}
138
}
153
139
154
Time 
155
InterferenceHelper::GetMaxPacketDuration (void) const
156
{
157
  return m_maxPacketDuration;
158
}
159
140
160
void 
141
void 
161
InterferenceHelper::SetNoiseFigure (double value)
142
InterferenceHelper::SetNoiseFigure (double value)
 Lines 185-229    Link Here 
185
InterferenceHelper::GetEnergyDuration (double energyW)
166
InterferenceHelper::GetEnergyDuration (double energyW)
186
{
167
{
187
  Time now = Simulator::Now ();
168
  Time now = Simulator::Now ();
188
189
  // first, we iterate over all events and, each event
190
  // which contributes energy to the channel now is 
191
  // appended to the noise interference array.
192
  Events::const_iterator i = m_events.begin ();
193
  double noiseInterferenceW = 0.0;
169
  double noiseInterferenceW = 0.0;
194
  NiChanges ni;
195
  while (i != m_events.end ()) 
196
    {
197
      Ptr<Event> ev = *i;
198
      NS_ASSERT (ev->GetStartTime () <= now);
199
      if (ev->GetEndTime () > now)
200
	{
201
          ni.push_back (NiChange (ev->GetEndTime (), -ev->GetRxPowerW ()));
202
          noiseInterferenceW += ev->GetRxPowerW ();
203
	}
204
      i++;
205
    }
206
  if (noiseInterferenceW < energyW)
207
    {
208
      return MicroSeconds (0);
209
    }
210
211
  /* quicksort vector of NI changes by time. 
212
   */
213
  std::sort (ni.begin (), ni.end (), std::less<NiChange> ());
214
215
  // Now, we iterate the piecewise linear noise function
216
  Time end = now;
170
  Time end = now;
217
  for (NiChanges::const_iterator i = ni.begin (); i != ni.end (); i++) 
171
  noiseInterferenceW = m_firstPower;
172
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++)
218
    {
173
    {
219
      noiseInterferenceW += i->GetDelta ();
174
      noiseInterferenceW += i->GetDelta ();
220
      end = i->GetTime ();
175
      end = i->GetTime ();
221
      if (noiseInterferenceW < energyW) 
176
      if (end < now)
222
	{
177
        {
223
	  break;
178
          continue;
224
	}
179
        }
180
      if (noiseInterferenceW < energyW)
181
	      {
182
	        break;
183
	      }
225
    }
184
    }
226
  return end - now;
185
  return end > now ? end - now : MicroSeconds (0);
227
}
186
}
228
187
229
WifiMode 
188
WifiMode 
 Lines 414-437    Link Here 
414
void 
373
void 
415
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
374
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
416
{
375
{
417
  /* attempt to remove the events which are 
376
  Time now = Simulator::Now ();
418
   * not useful anymore. 
377
  if (!m_rxing)
419
   * i.e.: all events which end _before_
420
   *       now - m_maxPacketDuration
421
   */
422
  
423
  if (Simulator::Now () > GetMaxPacketDuration ())
424
    {
378
    {
425
      Time end = Simulator::Now () - GetMaxPacketDuration ();
379
      NiChanges::iterator nowIterator = GetPosition (now);
426
      Events::iterator i = m_events.begin ();
380
      for (NiChanges::iterator i = m_niChanges.begin (); i != nowIterator; i++)
427
      while (i != m_events.end () &&
428
             (*i)->GetEndTime () <= end) 
429
        {
381
        {
430
          i++;
382
          m_firstPower += i->GetDelta ();
431
        }
383
        }
432
      EraseEvents (m_events.begin (), i);
384
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
433
    } 
385
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW ())); 
434
  m_events.push_back (event);
386
    }
387
  else
388
    {
389
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW ()));
390
    }
391
  AddNiChangeEvent(NiChange (event->GetEndTime (), -event->GetRxPowerW ()));
392
435
}
393
}
436
394
437
395
 Lines 452-486    Link Here 
452
double
410
double
453
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
411
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
454
{
412
{
455
  Events::const_iterator i = m_events.begin ();
413
  double noiseInterference = m_firstPower;
456
  double noiseInterference = 0.0;
414
  NS_ASSERT (m_rxing);
457
  while (i != m_events.end ()) 
415
  for (NiChanges::const_iterator i = m_niChanges.begin () + 1; i != m_niChanges.end (); i++)
458
    {
416
    {
459
      if (event == (*i)) 
417
      if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
460
        {
418
        {
461
          i++;
419
          break;
462
          continue;
463
        }
420
        }
464
      if ((*i)->Overlaps (event->GetStartTime ())) 
421
      ni->push_back (*i);
465
        {
466
          noiseInterference += (*i)->GetRxPowerW ();
467
        }
468
      else if (event->Overlaps ((*i)->GetStartTime ())) 
469
        {
470
          ni->push_back (NiChange ((*i)->GetStartTime (), (*i)->GetRxPowerW ()));
471
        }
472
      if (event->Overlaps ((*i)->GetEndTime ())) 
473
        {
474
          ni->push_back (NiChange ((*i)->GetEndTime (), -(*i)->GetRxPowerW ()));
475
        }
476
      i++;
477
    }
422
    }
478
  ni->push_back (NiChange (event->GetStartTime (), noiseInterference));
423
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference));
479
  ni->push_back (NiChange (event->GetEndTime (), 0));
424
  ni->push_back (NiChange (event->GetEndTime (), 0));
480
481
  /* quicksort vector of NI changes by time. */
482
  std::sort (ni->begin (), ni->end (), std::less<NiChange> ());
483
484
  return noiseInterference;
425
  return noiseInterference;
485
}
426
}
486
427
 Lines 607-627    Link Here 
607
void
548
void
608
InterferenceHelper::EraseEvents (void) 
549
InterferenceHelper::EraseEvents (void) 
609
{  
550
{  
610
  for (Events::iterator i = m_events.begin (); i != m_events.end (); ++i)
551
  m_niChanges.clear ();
611
    {
552
  m_firstPower = 0.0;
612
      *i = 0;
613
    }
614
  m_events.clear ();
615
}
553
}
554
InterferenceHelper::NiChanges::iterator
555
InterferenceHelper::GetPosition (Time moment)
556
{
557
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0));
616
558
559
}
617
void
560
void
618
InterferenceHelper::EraseEvents (Events::iterator start, Events::iterator end) 
561
InterferenceHelper::AddNiChangeEvent (NiChange change)
619
{  
562
{
620
  for (Events::iterator i = start; i != end; ++i)
563
  m_niChanges.insert (GetPosition (change.GetTime ()), change);
621
    {
622
      *i = 0;
623
    }
624
  m_events.erase (start, end);
625
}
564
}
626
565
void
566
InterferenceHelper::NotifyRxStart ()
567
{
568
  m_rxing = true;
569
}
570
void
571
InterferenceHelper::NotifyRxEnd ()
572
{
573
  m_rxing = false;
574
}
627
} // namespace ns3
575
} // namespace ns3
(-)a/src/devices/wifi/interference-helper.h (-6 / +9 lines)
 Lines 47-53    Link Here 
47
    Time GetDuration (void) const;
47
    Time GetDuration (void) const;
48
    Time GetStartTime (void) const;
48
    Time GetStartTime (void) const;
49
    Time GetEndTime (void) const;
49
    Time GetEndTime (void) const;
50
    bool Overlaps (Time time) const;
51
    double GetRxPowerW (void) const;
50
    double GetRxPowerW (void) const;
52
    uint32_t GetSize (void) const;
51
    uint32_t GetSize (void) const;
53
    WifiMode GetPayloadMode (void) const;
52
    WifiMode GetPayloadMode (void) const;
 Lines 95-100    Link Here 
95
				      Time duration, double rxPower);
94
				      Time duration, double rxPower);
96
95
97
  struct InterferenceHelper::SnrPer CalculateSnrPer (Ptr<InterferenceHelper::Event> event);
96
  struct InterferenceHelper::SnrPer CalculateSnrPer (Ptr<InterferenceHelper::Event> event);
97
  void NotifyRxStart ();
98
  void NotifyRxEnd ();
98
  void EraseEvents (void); 
99
  void EraseEvents (void); 
99
private:
100
private:
100
  class NiChange {
101
  class NiChange {
 Lines 110-117    Link Here 
110
  typedef std::vector <NiChange> NiChanges;
111
  typedef std::vector <NiChange> NiChanges;
111
  typedef std::list<Ptr<Event> > Events;
112
  typedef std::list<Ptr<Event> > Events;
112
113
113
  void EraseEvents (Events::iterator start, Events::iterator end); 
114
115
  InterferenceHelper (const InterferenceHelper &o);
114
  InterferenceHelper (const InterferenceHelper &o);
116
  InterferenceHelper &operator = (const InterferenceHelper &o);
115
  InterferenceHelper &operator = (const InterferenceHelper &o);
117
  void AppendEvent (Ptr<Event> event);
116
  void AppendEvent (Ptr<Event> event);
 Lines 119-130    Link Here 
119
  double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const;
118
  double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const;
120
  double CalculateChunkSuccessRate (double snir, Time delay, WifiMode mode) const;
119
  double CalculateChunkSuccessRate (double snir, Time delay, WifiMode mode) const;
121
  double CalculatePer (Ptr<const Event> event, NiChanges *ni) const;
120
  double CalculatePer (Ptr<const Event> event, NiChanges *ni) const;
122
  Time GetMaxPacketDuration (void) const;
123
121
124
  Time m_maxPacketDuration;
125
  double m_noiseFigure; /**< noise figure (linear) */
122
  double m_noiseFigure; /**< noise figure (linear) */
126
  Events m_events;
127
  Ptr<ErrorRateModel> m_errorRateModel;
123
  Ptr<ErrorRateModel> m_errorRateModel;
124
  ///Experimental: needed for energy duration calculation
125
  NiChanges m_niChanges;
126
  double m_firstPower;
127
  bool m_rxing;
128
  /// Returns an iterator to the first nichange, which is later than moment
129
  NiChanges::iterator GetPosition (Time moment);
130
  void AddNiChangeEvent (NiChange change);
128
};
131
};
129
132
130
} // namespace ns3
133
} // namespace ns3
(-)a/src/devices/wifi/yans-wifi-phy.cc (+3 lines)
 Lines 459-464    Link Here 
459
        m_state->SwitchToRx (rxDuration);
459
        m_state->SwitchToRx (rxDuration);
460
        NS_ASSERT (m_endRxEvent.IsExpired ());
460
        NS_ASSERT (m_endRxEvent.IsExpired ());
461
        NotifyRxBegin (packet);
461
        NotifyRxBegin (packet);
462
        m_interference.NotifyRxStart();
462
        m_endRxEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndReceive, this, 
463
        m_endRxEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndReceive, this, 
463
                                            packet,
464
                                            packet,
464
                                            event);
465
                                            event);
 Lines 504-509    Link Here 
504
  if (m_state->IsStateRx ())
505
  if (m_state->IsStateRx ())
505
    {
506
    {
506
      m_endRxEvent.Cancel ();
507
      m_endRxEvent.Cancel ();
508
      m_interference.NotifyRxEnd ();
507
    }
509
    }
508
  NotifyTxBegin (packet);
510
  NotifyTxBegin (packet);
509
  uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000;   
511
  uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000;   
 Lines 739-744    Link Here 
739
741
740
  struct InterferenceHelper::SnrPer snrPer;
742
  struct InterferenceHelper::SnrPer snrPer;
741
  snrPer = m_interference.CalculateSnrPer (event);
743
  snrPer = m_interference.CalculateSnrPer (event);
744
  m_interference.NotifyRxEnd();
742
745
743
  NS_LOG_DEBUG ("mode="<<(event->GetPayloadMode ().GetDataRate ())<<
746
  NS_LOG_DEBUG ("mode="<<(event->GetPayloadMode ().GetDataRate ())<<
744
                ", snr="<<snrPer.snr<<", per="<<snrPer.per<<", size="<<packet->GetSize ());
747
                ", snr="<<snrPer.snr<<", per="<<snrPer.per<<", size="<<packet->GetSize ());

Return to bug 799