|
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->GetDelta (); |
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->GetDelta () < energyW) |
200 |
end = i->GetTime (); |
|
|
201 |
if (end < now) |
202 |
{ |
208 |
{ |
203 |
continue; |
209 |
noiseInterferenceW = i->GetDelta (); |
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 |
// Iterate the NI change list from the beginning to the end |
|
|
264 |
// until find the position of the event in the NI change list |
265 |
// The reason of using the event that causes the NI change to identify |
266 |
// different NI changes is because in some special cases |
267 |
// different NI changes happen at the same time with the same delta |
268 |
// value. Therefore, it may be impossible to identify a NI change that belongs |
269 |
// to which event based on just the NI time and NI power value |
270 |
NiChanges::const_iterator it = GetPreviousPosition (event->GetStartTime ()); |
271 |
while (it != m_niChanges.end () && it->GetEvent () != event) |
257 |
{ |
272 |
{ |
258 |
// Iterate the NI change list from the beginning to the end |
273 |
++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 |
} |
274 |
} |
279 |
|
275 |
|
280 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
276 |
// The NI changes which happen before the event should be considered |
|
|
277 |
// as the interference. This considers the case that the receiving event |
278 |
// arrives while another receiving event is going on. The SINR of |
279 |
// the newly arrived event is calculated for checking the possibility of frame capture |
280 |
--it; |
281 |
noiseInterference = it>GetPower (); |
282 |
ni->push_back (NiChange (event->GetStartTime (), 0, event)); |
283 |
|
284 |
++it; |
285 |
for ( ; it->GetEvent () == event;; ++it) |
281 |
{ |
286 |
{ |
282 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
287 |
ni->push_back (*it); |
283 |
{ |
|
|
284 |
break; |
285 |
} |
286 |
ni->push_back (*i); |
287 |
} |
288 |
} |
288 |
ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); |
|
|
289 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
289 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
290 |
return noiseInterference; |
290 |
return noiseInterference; |
291 |
} |
291 |
} |
|
317 |
const WifiTxVector txVector = event->GetTxVector (); |
317 |
const WifiTxVector txVector = event->GetTxVector (); |
318 |
double psr = 1.0; /* Packet Success Rate */ |
318 |
double psr = 1.0; /* Packet Success Rate */ |
319 |
NiChanges::const_iterator j = ni->begin (); |
319 |
NiChanges::const_iterator j = ni->begin (); |
320 |
Time previous = (*j).GetTime (); |
320 |
Time previous = j->GetTime (); |
321 |
WifiMode payloadMode = event->GetPayloadMode (); |
321 |
WifiMode payloadMode = event->GetPayloadMode (); |
322 |
WifiPreamble preamble = txVector.GetPreambleType (); |
322 |
WifiPreamble preamble = txVector.GetPreambleType (); |
323 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
323 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
324 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
324 |
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 |
325 |
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 |
326 |
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 (); |
327 |
double noiseInterferenceW = m_firstPower; |
328 |
double powerW = event->GetRxPowerW (); |
328 |
double powerW = event->GetRxPowerW (); |
329 |
j++; |
329 |
j++; |
330 |
while (ni->end () != j) |
330 |
while (ni->end () != j) |
331 |
{ |
331 |
{ |
332 |
Time current = (*j).GetTime (); |
332 |
Time current = j->GetTime (); |
333 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
333 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
334 |
NS_ASSERT (current >= previous); |
334 |
NS_ASSERT (current >= previous); |
335 |
//Case 1: Both previous and current point to the payload |
335 |
//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); |
354 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
355 |
} |
355 |
} |
356 |
|
356 |
|
357 |
noiseInterferenceW += (*j).GetDelta (); |
357 |
noiseInterferenceW = j->GetPower () - powerW; |
358 |
previous = (*j).GetTime (); |
358 |
previous = j->GetTime (); |
359 |
j++; |
359 |
j++; |
360 |
} |
360 |
} |
361 |
|
361 |
|
|
370 |
const WifiTxVector txVector = event->GetTxVector (); |
370 |
const WifiTxVector txVector = event->GetTxVector (); |
371 |
double psr = 1.0; /* Packet Success Rate */ |
371 |
double psr = 1.0; /* Packet Success Rate */ |
372 |
NiChanges::const_iterator j = ni->begin (); |
372 |
NiChanges::const_iterator j = ni->begin (); |
373 |
Time previous = (*j).GetTime (); |
373 |
Time previous = j->GetTime (); |
374 |
WifiPreamble preamble = txVector.GetPreambleType (); |
374 |
WifiPreamble preamble = txVector.GetPreambleType (); |
375 |
WifiMode mcsHeaderMode; |
375 |
WifiMode mcsHeaderMode; |
376 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
376 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
|
389 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
389 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
390 |
} |
390 |
} |
391 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
391 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
392 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
392 |
Time plcpHeaderStart = j->GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
393 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
393 |
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 |
394 |
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 |
395 |
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 (); |
396 |
double noiseInterferenceW = m_firstPower; |
397 |
double powerW = event->GetRxPowerW (); |
397 |
double powerW = event->GetRxPowerW (); |
398 |
j++; |
398 |
j++; |
399 |
while (ni->end () != j) |
399 |
while (ni->end () != j) |
400 |
{ |
400 |
{ |
401 |
Time current = (*j).GetTime (); |
401 |
Time current = j->GetTime (); |
402 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
402 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
403 |
NS_ASSERT (current >= previous); |
403 |
NS_ASSERT (current >= previous); |
404 |
//Case 1: previous and current after playload start: nothing to do |
404 |
//Case 1: previous and current after playload start: nothing to do |
|
812 |
} |
812 |
} |
813 |
} |
813 |
} |
814 |
|
814 |
|
815 |
noiseInterferenceW += (*j).GetDelta (); |
815 |
noiseInterferenceW = j->GetPower () - powerW; |
816 |
previous = (*j).GetTime (); |
816 |
previous = j->GetTime (); |
817 |
j++; |
817 |
j++; |
818 |
} |
818 |
} |
819 |
|
819 |
|
|
869 |
m_firstPower = 0.0; |
869 |
m_firstPower = 0.0; |
870 |
} |
870 |
} |
871 |
|
871 |
|
872 |
InterferenceHelper::NiChanges::const_iterator |
872 |
InterferenceHelper::NiChanges::iterator |
873 |
InterferenceHelper::GetPosition (Time moment) |
873 |
InterferenceHelper::GetNextPosition (Time moment) |
874 |
{ |
874 |
{ |
875 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
875 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
876 |
} |
876 |
} |
877 |
|
877 |
|
878 |
void |
878 |
InterferenceHelper::NiChanges::iterator |
|
|
879 |
InterferenceHelper::GetPreviousPosition (Time moment) |
880 |
{ |
881 |
InterferenceHelper::NiChanges::iterator it = GetNextPosition (moment); |
882 |
--it; |
883 |
return it; |
884 |
} |
885 |
|
886 |
int64_t |
879 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
887 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
880 |
{ |
888 |
{ |
881 |
m_niChanges.insert (GetPosition (change.GetTime ()), change); |
889 |
auto it = m_niChanges.insert (GetNextPosition (change.GetTime ()), change); |
|
|
890 |
return std::distance (m_niChanges.begin (), it); |
882 |
} |
891 |
} |
883 |
|
892 |
|
884 |
void |
893 |
void |
|
893 |
{ |
902 |
{ |
894 |
NS_LOG_FUNCTION (this); |
903 |
NS_LOG_FUNCTION (this); |
895 |
m_rxing = false; |
904 |
m_rxing = false; |
|
|
905 |
//Update m_firstPower for frame capture |
906 |
auto it = GetPreviousPosition (Simulator::Now ()); |
907 |
m_firstPower = it->GetPower (); |
896 |
} |
908 |
} |
897 |
|
909 |
|
898 |
} //namespace ns3 |
910 |
} //namespace ns3 |