|
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 |
{ |
|
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 |
{ |
|
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) |
|
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 |
|
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 |
|
|
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 |
|
|
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 |