|
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 |
} |
|
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> |
|
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 |
{ |
|
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 |
auto 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 |
auto 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 ())); |
221 |
{ |
|
|
222 |
m_firstPower += i->GetDelta (); |
223 |
} |
224 |
m_niChanges.erase (m_niChanges.begin (), nowIterator); |
225 |
} |
237 |
} |
226 |
AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); |
238 |
auto first = AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart + event->GetRxPowerW (), event)); |
227 |
AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event)); |
239 |
auto last = AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event)); |
|
|
240 |
for (auto i = first + 1; i < last; i++) |
241 |
{ |
242 |
m_niChanges.at (i).AddPower (event->GetRxPowerW ()); |
243 |
} |
228 |
} |
244 |
} |
229 |
|
245 |
|
230 |
double |
246 |
double |
|
262 |
// as the interference. This considers the case that the receiving event |
278 |
// as the interference. This considers the case that the receiving event |
263 |
// arrives while another receiving event is going on. The SINR of |
279 |
// 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 |
280 |
// the newly arrived event is calculated for checking the possibility of frame capture |
265 |
noiseInterference += eventIterator->GetDelta (); |
281 |
noiseInterference = eventIterator->GetPower (); |
266 |
} |
282 |
} |
267 |
else |
283 |
else |
268 |
{ |
284 |
{ |
|
270 |
} |
286 |
} |
271 |
++eventIterator; |
287 |
++eventIterator; |
272 |
} |
288 |
} |
273 |
|
289 |
ni->push_back (NiChange (event->GetStartTime (), 0, event)); |
274 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
290 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
275 |
{ |
291 |
{ |
276 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
292 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
|
279 |
} |
295 |
} |
280 |
ni->push_back (*i); |
296 |
ni->push_back (*i); |
281 |
} |
297 |
} |
282 |
ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); |
|
|
283 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
298 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
284 |
return noiseInterference; |
299 |
return noiseInterference; |
285 |
} |
300 |
} |
|
311 |
const WifiTxVector txVector = event->GetTxVector (); |
326 |
const WifiTxVector txVector = event->GetTxVector (); |
312 |
double psr = 1.0; /* Packet Success Rate */ |
327 |
double psr = 1.0; /* Packet Success Rate */ |
313 |
NiChanges::const_iterator j = ni->begin (); |
328 |
NiChanges::const_iterator j = ni->begin (); |
314 |
Time previous = (*j).GetTime (); |
329 |
Time previous = j->GetTime (); |
315 |
WifiMode payloadMode = event->GetPayloadMode (); |
330 |
WifiMode payloadMode = event->GetPayloadMode (); |
316 |
WifiPreamble preamble = txVector.GetPreambleType (); |
331 |
WifiPreamble preamble = txVector.GetPreambleType (); |
317 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
332 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
318 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
333 |
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 |
334 |
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 |
335 |
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 (); |
336 |
double noiseInterferenceW = m_firstPower; |
322 |
double powerW = event->GetRxPowerW (); |
337 |
double powerW = event->GetRxPowerW (); |
323 |
j++; |
338 |
j++; |
324 |
while (ni->end () != j) |
339 |
while (ni->end () != j) |
325 |
{ |
340 |
{ |
326 |
Time current = (*j).GetTime (); |
341 |
Time current = j->GetTime (); |
327 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
342 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
328 |
NS_ASSERT (current >= previous); |
343 |
NS_ASSERT (current >= previous); |
329 |
//Case 1: Both previous and current point to the payload |
344 |
//Case 1: Both previous and current point to the payload |
|
346 |
payloadMode, txVector); |
361 |
payloadMode, txVector); |
347 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
362 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
348 |
} |
363 |
} |
349 |
noiseInterferenceW += (*j).GetDelta (); |
364 |
noiseInterferenceW = j->GetPower () - powerW; |
350 |
previous = (*j).GetTime (); |
365 |
previous = j->GetTime (); |
351 |
j++; |
366 |
j++; |
352 |
} |
367 |
} |
353 |
double per = 1 - psr; |
368 |
double per = 1 - psr; |
|
361 |
const WifiTxVector txVector = event->GetTxVector (); |
376 |
const WifiTxVector txVector = event->GetTxVector (); |
362 |
double psr = 1.0; /* Packet Success Rate */ |
377 |
double psr = 1.0; /* Packet Success Rate */ |
363 |
NiChanges::const_iterator j = ni->begin (); |
378 |
NiChanges::const_iterator j = ni->begin (); |
364 |
Time previous = (*j).GetTime (); |
379 |
Time previous = j->GetTime (); |
365 |
WifiPreamble preamble = txVector.GetPreambleType (); |
380 |
WifiPreamble preamble = txVector.GetPreambleType (); |
366 |
WifiMode mcsHeaderMode; |
381 |
WifiMode mcsHeaderMode; |
367 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
382 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
|
380 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
395 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
381 |
} |
396 |
} |
382 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
397 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
383 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
398 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
384 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
399 |
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 |
400 |
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 |
401 |
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 (); |
402 |
double noiseInterferenceW = m_firstPower; |
388 |
double powerW = event->GetRxPowerW (); |
403 |
double powerW = event->GetRxPowerW (); |
389 |
j++; |
404 |
j++; |
390 |
while (ni->end () != j) |
405 |
while (ni->end () != j) |
391 |
{ |
406 |
{ |
392 |
Time current = (*j).GetTime (); |
407 |
Time current = j->GetTime (); |
393 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
408 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
394 |
NS_ASSERT (current >= previous); |
409 |
NS_ASSERT (current >= previous); |
395 |
//Case 1: previous and current after playload start: nothing to do |
410 |
//Case 1: previous and current after playload start: nothing to do |
|
762 |
} |
777 |
} |
763 |
} |
778 |
} |
764 |
|
779 |
|
765 |
noiseInterferenceW += (*j).GetDelta (); |
780 |
noiseInterferenceW = j->GetPower () - powerW; |
766 |
previous = (*j).GetTime (); |
781 |
previous = j->GetTime (); |
767 |
j++; |
782 |
j++; |
768 |
} |
783 |
} |
769 |
|
784 |
|
|
819 |
m_firstPower = 0; |
834 |
m_firstPower = 0; |
820 |
} |
835 |
} |
821 |
|
836 |
|
822 |
InterferenceHelper::NiChanges::const_iterator |
837 |
InterferenceHelper::NiChanges::iterator |
823 |
InterferenceHelper::GetPosition (Time moment) |
838 |
InterferenceHelper::GetNextPosition (Time moment) |
824 |
{ |
839 |
{ |
825 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
840 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
826 |
} |
841 |
} |
827 |
|
842 |
|
828 |
void |
843 |
InterferenceHelper::NiChanges::iterator |
|
|
844 |
InterferenceHelper::GetPreviousPosition (Time moment) |
845 |
{ |
846 |
InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment); |
847 |
--it; |
848 |
return it; |
849 |
} |
850 |
|
851 |
int64_t |
829 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
852 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
830 |
{ |
853 |
{ |
831 |
m_niChanges.insert (GetPosition (change.GetTime ()), change); |
854 |
auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change); |
|
|
855 |
return std::distance (m_niChanges.begin (), it); |
832 |
} |
856 |
} |
833 |
|
857 |
|
834 |
void |
858 |
void |
|
843 |
{ |
867 |
{ |
844 |
NS_LOG_FUNCTION (this); |
868 |
NS_LOG_FUNCTION (this); |
845 |
m_rxing = false; |
869 |
m_rxing = false; |
|
|
870 |
Time now = Simulator::Now (); |
871 |
//Update m_firstPower for frame capture |
872 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) |
873 |
{ |
874 |
if (i->GetTime () >= now) |
875 |
{ |
876 |
break; |
877 |
} |
878 |
m_firstPower = i->GetPower (); |
879 |
} |
846 |
} |
880 |
} |
847 |
|
881 |
|
848 |
} //namespace ns3 |
882 |
} //namespace ns3 |