|
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> |
|
188 |
} |
194 |
} |
189 |
|
195 |
|
190 |
Time |
196 |
Time |
191 |
InterferenceHelper::GetEnergyDuration (double energyW) const |
197 |
InterferenceHelper::GetEnergyDuration (double energyW) |
192 |
{ |
198 |
{ |
193 |
Time now = Simulator::Now (); |
199 |
Time now = Simulator::Now (); |
194 |
double noiseInterferenceW = 0; |
200 |
auto i = GetPreviousPosition (now); |
195 |
Time end = now; |
201 |
Time end = i->GetTime (); |
196 |
noiseInterferenceW = m_firstPower; |
202 |
while (i != m_niChanges.end ()) |
197 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) |
|
|
198 |
{ |
203 |
{ |
199 |
noiseInterferenceW += i->GetDelta (); |
204 |
double noiseInterferenceW = i->GetPower (); |
200 |
end = i->GetTime (); |
205 |
end = i->GetTime (); |
201 |
if (end < now) |
|
|
202 |
{ |
203 |
continue; |
204 |
} |
205 |
if (noiseInterferenceW < energyW) |
206 |
if (noiseInterferenceW < energyW) |
206 |
{ |
207 |
{ |
207 |
break; |
208 |
break; |
208 |
} |
209 |
} |
|
|
210 |
++i; |
209 |
} |
211 |
} |
210 |
return end > now ? end - now : MicroSeconds (0); |
212 |
return end > now ? end - now : MicroSeconds (0); |
211 |
} |
213 |
} |
|
213 |
void |
215 |
void |
214 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
216 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
215 |
{ |
217 |
{ |
216 |
Time now = Simulator::Now (); |
218 |
double previousPowerStart = 0; |
|
|
219 |
double previousPowerEnd = 0; |
220 |
auto itPreviousEvent = GetPreviousPosition (event->GetStartTime ()); |
221 |
auto itNextEvent = GetPreviousPosition (event->GetEndTime ()); |
222 |
if (m_niChanges.size() > 0) |
223 |
{ |
224 |
previousPowerStart = itPreviousEvent->GetPower (); |
225 |
previousPowerEnd = itNextEvent->GetPower (); |
226 |
} |
217 |
if (!m_rxing) |
227 |
if (!m_rxing) |
218 |
{ |
228 |
{ |
219 |
NiChanges::const_iterator nowIterator = GetPosition (now); |
229 |
m_firstPower = previousPowerStart; |
220 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++) |
230 |
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 |
} |
231 |
} |
226 |
AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); |
232 |
auto first = AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart, event)); |
227 |
AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event)); |
233 |
auto last = AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event)); |
|
|
234 |
for (auto i = first; i < last; i++) |
235 |
{ |
236 |
m_niChanges.at (i).AddPower (event->GetRxPowerW ()); |
237 |
} |
228 |
} |
238 |
} |
229 |
|
239 |
|
230 |
double |
240 |
double |
|
243 |
} |
253 |
} |
244 |
|
254 |
|
245 |
double |
255 |
double |
246 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const |
256 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) |
247 |
{ |
257 |
{ |
248 |
double noiseInterference = m_firstPower; |
258 |
double noiseInterference = m_firstPower; |
249 |
NiChanges::const_iterator eventIterator = m_niChanges.begin (); |
259 |
auto it = m_niChanges.begin (); |
250 |
while (eventIterator != m_niChanges.end ()) |
260 |
while (it != m_niChanges.end () && it->GetEvent () != event) |
251 |
{ |
261 |
{ |
252 |
// Iterate the NI change list from the beginning to the end |
262 |
noiseInterference = it->GetPower (); |
253 |
// until find the position of the event in the NI change list |
263 |
++it; |
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 |
} |
264 |
} |
273 |
|
265 |
ni->push_back (NiChange (event->GetStartTime (), 0, event)); |
274 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
266 |
++it; |
|
|
267 |
while (it != m_niChanges.end () && event != it->GetEvent ()) |
275 |
{ |
268 |
{ |
276 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
269 |
ni->push_back (*it); |
277 |
{ |
270 |
++it; |
278 |
break; |
|
|
279 |
} |
280 |
ni->push_back (*i); |
281 |
} |
271 |
} |
282 |
ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); |
|
|
283 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
272 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
284 |
return noiseInterference; |
273 |
return noiseInterference; |
285 |
} |
274 |
} |
|
313 |
const WifiTxVector txVector = event->GetTxVector (); |
302 |
const WifiTxVector txVector = event->GetTxVector (); |
314 |
double psr = 1.0; /* Packet Success Rate */ |
303 |
double psr = 1.0; /* Packet Success Rate */ |
315 |
NiChanges::const_iterator j = ni->begin (); |
304 |
NiChanges::const_iterator j = ni->begin (); |
316 |
Time previous = (*j).GetTime (); |
305 |
Time previous = j->GetTime (); |
317 |
WifiMode payloadMode = event->GetPayloadMode (); |
306 |
WifiMode payloadMode = event->GetPayloadMode (); |
318 |
WifiPreamble preamble = txVector.GetPreambleType (); |
307 |
WifiPreamble preamble = txVector.GetPreambleType (); |
319 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
308 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
320 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
309 |
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 |
310 |
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 |
311 |
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 (); |
312 |
double noiseInterferenceW = m_firstPower; |
324 |
double powerW = event->GetRxPowerW (); |
313 |
double powerW = event->GetRxPowerW (); |
325 |
j++; |
314 |
++j; |
326 |
while (ni->end () != j) |
315 |
while (ni->end () != j) |
327 |
{ |
316 |
{ |
328 |
Time current = (*j).GetTime (); |
317 |
Time current = j->GetTime (); |
329 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
318 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
330 |
NS_ASSERT (current >= previous); |
319 |
NS_ASSERT (current >= previous); |
331 |
//Case 1: Both previous and current point to the payload |
320 |
//Case 1: Both previous and current point to the payload |
|
348 |
payloadMode, txVector); |
337 |
payloadMode, txVector); |
349 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
338 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
350 |
} |
339 |
} |
351 |
noiseInterferenceW += (*j).GetDelta (); |
340 |
noiseInterferenceW = j->GetPower () - powerW; |
352 |
previous = (*j).GetTime (); |
341 |
previous = j->GetTime (); |
353 |
j++; |
342 |
++j; |
354 |
} |
343 |
} |
355 |
double per = 1 - psr; |
344 |
double per = 1 - psr; |
356 |
return per; |
345 |
return per; |
|
363 |
const WifiTxVector txVector = event->GetTxVector (); |
352 |
const WifiTxVector txVector = event->GetTxVector (); |
364 |
double psr = 1.0; /* Packet Success Rate */ |
353 |
double psr = 1.0; /* Packet Success Rate */ |
365 |
NiChanges::const_iterator j = ni->begin (); |
354 |
NiChanges::const_iterator j = ni->begin (); |
366 |
Time previous = (*j).GetTime (); |
355 |
Time previous = j->GetTime (); |
367 |
WifiPreamble preamble = txVector.GetPreambleType (); |
356 |
WifiPreamble preamble = txVector.GetPreambleType (); |
368 |
WifiMode mcsHeaderMode; |
357 |
WifiMode mcsHeaderMode; |
369 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
358 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
|
382 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
371 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
383 |
} |
372 |
} |
384 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
373 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
385 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
374 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
386 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
375 |
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 |
376 |
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 |
377 |
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 (); |
378 |
double noiseInterferenceW = m_firstPower; |
390 |
double powerW = event->GetRxPowerW (); |
379 |
double powerW = event->GetRxPowerW (); |
391 |
j++; |
380 |
++j; |
392 |
while (ni->end () != j) |
381 |
while (ni->end () != j) |
393 |
{ |
382 |
{ |
394 |
Time current = (*j).GetTime (); |
383 |
Time current = j->GetTime (); |
395 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
384 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
396 |
NS_ASSERT (current >= previous); |
385 |
NS_ASSERT (current >= previous); |
397 |
//Case 1: previous and current after playload start: nothing to do |
386 |
//Case 1: previous and current after playload start: nothing to do |
|
764 |
} |
753 |
} |
765 |
} |
754 |
} |
766 |
|
755 |
|
767 |
noiseInterferenceW += (*j).GetDelta (); |
756 |
noiseInterferenceW = j->GetPower () - powerW; |
768 |
previous = (*j).GetTime (); |
757 |
previous = j->GetTime (); |
769 |
j++; |
758 |
++j; |
770 |
} |
759 |
} |
771 |
|
760 |
|
772 |
double per = 1 - psr; |
761 |
double per = 1 - psr; |
|
821 |
m_firstPower = 0; |
810 |
m_firstPower = 0; |
822 |
} |
811 |
} |
823 |
|
812 |
|
824 |
InterferenceHelper::NiChanges::const_iterator |
813 |
InterferenceHelper::NiChanges::iterator |
825 |
InterferenceHelper::GetPosition (Time moment) |
814 |
InterferenceHelper::GetNextPosition (Time moment) |
826 |
{ |
815 |
{ |
827 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
816 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
828 |
} |
817 |
} |
829 |
|
818 |
|
830 |
void |
819 |
InterferenceHelper::NiChanges::iterator |
|
|
820 |
InterferenceHelper::GetPreviousPosition (Time moment) |
821 |
{ |
822 |
InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment); |
823 |
--it; |
824 |
return it; |
825 |
} |
826 |
|
827 |
InterferenceHelper::NiChanges::iterator |
828 |
InterferenceHelper::GetPositionBeforeTime (Time moment) |
829 |
{ |
830 |
InterferenceHelper::NiChanges::iterator it = std::lower_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
831 |
--it; |
832 |
return it; |
833 |
} |
834 |
|
835 |
int64_t |
831 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
836 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
832 |
{ |
837 |
{ |
833 |
m_niChanges.insert (GetPosition (change.GetTime ()), change); |
838 |
auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change); |
|
|
839 |
return std::distance (m_niChanges.begin (), it); |
834 |
} |
840 |
} |
835 |
|
841 |
|
836 |
void |
842 |
void |
|
845 |
{ |
851 |
{ |
846 |
NS_LOG_FUNCTION (this); |
852 |
NS_LOG_FUNCTION (this); |
847 |
m_rxing = false; |
853 |
m_rxing = false; |
|
|
854 |
//Update m_firstPower for frame capture |
855 |
auto it = GetPositionBeforeTime (Simulator::Now ()); |
856 |
m_firstPower = it->GetPower (); |
848 |
} |
857 |
} |
849 |
|
858 |
|
850 |
} //namespace ns3 |
859 |
} //namespace ns3 |