|
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.0; |
200 |
|
195 |
Time end = now; |
201 |
auto i = GetPreviousPosition (now); |
196 |
noiseInterferenceW = m_firstPower; |
202 |
double noiseInterferenceW = i->GetPower (); |
197 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) |
203 |
Time end = i->GetTime (); |
|
|
204 |
|
205 |
for ( ; i != m_niChanges.end (); i++) |
198 |
{ |
206 |
{ |
199 |
noiseInterferenceW += i->GetDelta (); |
207 |
if (i->GetPower () < energyW) |
200 |
end = i->GetTime (); |
|
|
201 |
if (end < now) |
202 |
{ |
208 |
{ |
203 |
continue; |
209 |
noiseInterferenceW = i->GetPower (); |
204 |
} |
210 |
end = i->GetTime (); |
205 |
if (noiseInterferenceW < energyW) |
|
|
206 |
{ |
207 |
break; |
211 |
break; |
208 |
} |
212 |
} |
209 |
} |
213 |
} |
|
213 |
void |
217 |
void |
214 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
218 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
215 |
{ |
219 |
{ |
216 |
Time now = Simulator::Now (); |
220 |
double previousPowerStart = 0; |
|
|
221 |
auto itPreviousEvent = GetPreviousPosition (event->GetStartTime ()); |
222 |
double previousPowerEnd = 0; |
223 |
auto itNextEvent = GetPreviousPosition (event->GetEndTime ()); |
224 |
if ( m_niChanges.size() > 0 ) { |
225 |
previousPowerStart = itPreviousEvent->GetPower (); |
226 |
previousPowerEnd = itNextEvent->GetPower (); |
227 |
} |
228 |
|
217 |
if (!m_rxing) |
229 |
if (!m_rxing) |
218 |
{ |
230 |
{ |
219 |
NiChanges::const_iterator nowIterator = GetPosition (now); |
231 |
m_firstPower = previousPowerStart; |
220 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++) |
232 |
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 |
m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); |
226 |
} |
233 |
} |
227 |
else |
234 |
auto first = AddNiChangeEvent (NiChange (event->GetStartTime (), previousPowerStart, event)); |
|
|
235 |
auto last = AddNiChangeEvent (NiChange (event->GetEndTime (), previousPowerEnd, event)); |
236 |
for (auto i = first; i < last; i++) |
228 |
{ |
237 |
{ |
229 |
AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); |
238 |
m_niChanges.at (i).AddPower (event->GetRxPowerW ()); |
230 |
} |
239 |
} |
231 |
AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event)); |
|
|
232 |
|
233 |
} |
240 |
} |
234 |
|
241 |
|
235 |
|
242 |
|
|
252 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const |
259 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const |
253 |
{ |
260 |
{ |
254 |
double noiseInterference = m_firstPower; |
261 |
double noiseInterference = m_firstPower; |
255 |
NiChanges::const_iterator eventIterator = m_niChanges.begin (); |
262 |
|
256 |
while (eventIterator != m_niChanges.end ()) |
263 |
// Find this event in the NiChanges list. |
|
|
264 |
// Should be multimap::find() |
265 |
NiChanges::const_iterator it = GetPreviousPosition (event->GetStartTime ()); |
266 |
while (it != m_niChanges.end () && it->GetEvent () != event) |
257 |
{ |
267 |
{ |
258 |
// Iterate the NI change list from the beginning to the end |
268 |
++it; |
259 |
// until find the position of the event in the NI change list |
|
|
260 |
// The reason of using the event that causes the NI change to identify |
261 |
// different NI changes is because in some special cases |
262 |
// different NI changes happen at the same time with the same delta |
263 |
// value. Therefore, it may be impossible to identify a NI change that belongs |
264 |
// to which event based on just the NI time and NI delta value |
265 |
if (eventIterator->GetEvent () != event) |
266 |
{ |
267 |
// The NI changes which happen before the event should be considered |
268 |
// as the interference. This considers the case that the receiving event |
269 |
// arrives while another receiving event is going on. The SINR of |
270 |
// the newly arrived event is calculated for checking the possibility of frame capture |
271 |
noiseInterference += eventIterator->GetDelta (); |
272 |
} |
273 |
else |
274 |
{ |
275 |
break; |
276 |
} |
277 |
++eventIterator; |
278 |
} |
269 |
} |
279 |
|
270 |
|
280 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
271 |
// The existing NI power at the start of this event is in the prior |
|
|
272 |
// NiChange event. |
273 |
// This considers the case that the receiving event |
274 |
// arrives while another receiving event is going on. The SINR of |
275 |
// the newly arrived event is calculated for checking the possibility of frame capture |
276 |
--it; |
277 |
noiseInterference = it>GetPower (); |
278 |
ni->push_back (NiChange (event->GetStartTime (), 0, event)); |
279 |
|
280 |
++it; |
281 |
for ( ; it->GetEvent () == event;; ++it) |
281 |
{ |
282 |
{ |
282 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
283 |
ni->push_back (*it); |
283 |
{ |
|
|
284 |
break; |
285 |
} |
286 |
ni->push_back (*i); |
287 |
} |
284 |
} |
288 |
ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); |
|
|
289 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
285 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
290 |
return noiseInterference; |
286 |
return noiseInterference; |
291 |
} |
287 |
} |
|
317 |
const WifiTxVector txVector = event->GetTxVector (); |
313 |
const WifiTxVector txVector = event->GetTxVector (); |
318 |
double psr = 1.0; /* Packet Success Rate */ |
314 |
double psr = 1.0; /* Packet Success Rate */ |
319 |
NiChanges::const_iterator j = ni->begin (); |
315 |
NiChanges::const_iterator j = ni->begin (); |
320 |
Time previous = (*j).GetTime (); |
316 |
Time previous = j->GetTime (); |
321 |
WifiMode payloadMode = event->GetPayloadMode (); |
317 |
WifiMode payloadMode = event->GetPayloadMode (); |
322 |
WifiPreamble preamble = txVector.GetPreambleType (); |
318 |
WifiPreamble preamble = txVector.GetPreambleType (); |
323 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
319 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
324 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
320 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
325 |
Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A |
321 |
Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A |
326 |
Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B |
322 |
Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B |
327 |
double noiseInterferenceW = (*j).GetDelta (); |
323 |
double noiseInterferenceW = m_firstPower; |
328 |
double powerW = event->GetRxPowerW (); |
324 |
double powerW = event->GetRxPowerW (); |
329 |
j++; |
325 |
j++; |
330 |
while (ni->end () != j) |
326 |
while (ni->end () != j) |
331 |
{ |
327 |
{ |
332 |
Time current = (*j).GetTime (); |
328 |
Time current = j->GetTime (); |
333 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
329 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
334 |
NS_ASSERT (current >= previous); |
330 |
NS_ASSERT (current >= previous); |
335 |
//Case 1: Both previous and current point to the payload |
331 |
//Case 1: Both previous and current point to the payload |
|
354 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
350 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
355 |
} |
351 |
} |
356 |
|
352 |
|
357 |
noiseInterferenceW += (*j).GetDelta (); |
353 |
noiseInterferenceW = j->GetPower () - powerW; |
358 |
previous = (*j).GetTime (); |
354 |
previous = j->GetTime (); |
359 |
j++; |
355 |
j++; |
360 |
} |
356 |
} |
361 |
|
357 |
|
|
370 |
const WifiTxVector txVector = event->GetTxVector (); |
366 |
const WifiTxVector txVector = event->GetTxVector (); |
371 |
double psr = 1.0; /* Packet Success Rate */ |
367 |
double psr = 1.0; /* Packet Success Rate */ |
372 |
NiChanges::const_iterator j = ni->begin (); |
368 |
NiChanges::const_iterator j = ni->begin (); |
373 |
Time previous = (*j).GetTime (); |
369 |
Time previous = j->GetTime (); |
374 |
WifiPreamble preamble = txVector.GetPreambleType (); |
370 |
WifiPreamble preamble = txVector.GetPreambleType (); |
375 |
WifiMode mcsHeaderMode; |
371 |
WifiMode mcsHeaderMode; |
376 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
372 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
|
389 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
385 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
390 |
} |
386 |
} |
391 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
387 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
392 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
388 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
393 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
389 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
394 |
Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A |
390 |
Time plcpTrainingSymbolsStart = plcpHsigHeaderStart + WifiPhy::GetPlcpHtSigHeaderDuration (preamble) + WifiPhy::GetPlcpSigA1Duration (preamble) + WifiPhy::GetPlcpSigA2Duration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A |
395 |
Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B |
391 |
Time plcpPayloadStart = plcpTrainingSymbolsStart + WifiPhy::GetPlcpTrainingSymbolDuration (txVector) + WifiPhy::GetPlcpSigBDuration (preamble); //packet start time + preamble + L-SIG + HT-SIG or SIG-A + Training + SIG-B |
396 |
double noiseInterferenceW = (*j).GetDelta (); |
392 |
double noiseInterferenceW = m_firstPower; |
397 |
double powerW = event->GetRxPowerW (); |
393 |
double powerW = event->GetRxPowerW (); |
398 |
j++; |
394 |
j++; |
399 |
while (ni->end () != j) |
395 |
while (ni->end () != j) |
400 |
{ |
396 |
{ |
401 |
Time current = (*j).GetTime (); |
397 |
Time current = j->GetTime (); |
402 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
398 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
403 |
NS_ASSERT (current >= previous); |
399 |
NS_ASSERT (current >= previous); |
404 |
//Case 1: previous and current after playload start: nothing to do |
400 |
//Case 1: previous and current after playload start: nothing to do |
|
812 |
} |
808 |
} |
813 |
} |
809 |
} |
814 |
|
810 |
|
815 |
noiseInterferenceW += (*j).GetDelta (); |
811 |
noiseInterferenceW = j->GetPower () - powerW; |
816 |
previous = (*j).GetTime (); |
812 |
previous = j->GetTime (); |
817 |
j++; |
813 |
j++; |
818 |
} |
814 |
} |
819 |
|
815 |
|
|
869 |
m_firstPower = 0.0; |
865 |
m_firstPower = 0.0; |
870 |
} |
866 |
} |
871 |
|
867 |
|
872 |
InterferenceHelper::NiChanges::const_iterator |
868 |
InterferenceHelper::NiChanges::iterator |
873 |
InterferenceHelper::GetPosition (Time moment) |
869 |
InterferenceHelper::GetNextPosition (Time moment) |
874 |
{ |
870 |
{ |
875 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
871 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
876 |
} |
872 |
} |
877 |
|
873 |
|
878 |
void |
874 |
InterferenceHelper::NiChanges::iterator |
|
|
875 |
InterferenceHelper::GetPreviousPosition (Time moment) |
876 |
{ |
877 |
InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment); |
878 |
--it; |
879 |
return it; |
880 |
} |
881 |
|
882 |
int64_t |
879 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
883 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
880 |
{ |
884 |
{ |
881 |
m_niChanges.insert (GetPosition (change.GetTime ()), change); |
885 |
auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change); |
|
|
886 |
return std::distance (m_niChanges.begin (), it); |
882 |
} |
887 |
} |
883 |
|
888 |
|
884 |
void |
889 |
void |
|
893 |
{ |
898 |
{ |
894 |
NS_LOG_FUNCTION (this); |
899 |
NS_LOG_FUNCTION (this); |
895 |
m_rxing = false; |
900 |
m_rxing = false; |
|
|
901 |
//Update m_firstPower for frame capture |
902 |
auto it = GetPreviousPosition (Simulator::Now ()); |
903 |
m_firstPower = it->GetPower (); |
896 |
} |
904 |
} |
897 |
|
905 |
|
898 |
} //namespace ns3 |
906 |
} //namespace ns3 |