|
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 (double power, Ptr<InterferenceHelper::Event> event) |
92 |
: m_time (time), |
92 |
: m_power (power), |
93 |
m_delta (delta), |
|
|
94 |
m_event (event) |
93 |
m_event (event) |
95 |
{ |
94 |
{ |
96 |
} |
95 |
} |
97 |
|
96 |
|
98 |
Time |
97 |
double |
99 |
InterferenceHelper::NiChange::GetTime (void) const |
98 |
InterferenceHelper::NiChange::GetPower (void) const |
100 |
{ |
99 |
{ |
101 |
return m_time; |
100 |
return m_power; |
102 |
} |
101 |
} |
103 |
|
102 |
|
104 |
double |
103 |
void |
105 |
InterferenceHelper::NiChange::GetDelta (void) const |
104 |
InterferenceHelper::NiChange::AddPower (double power) |
106 |
{ |
105 |
{ |
107 |
return m_delta; |
106 |
m_power += power; |
108 |
} |
107 |
} |
109 |
|
108 |
|
110 |
Ptr<InterferenceHelper::Event> |
109 |
Ptr<InterferenceHelper::Event> |
|
113 |
return m_event; |
112 |
return m_event; |
114 |
} |
113 |
} |
115 |
|
114 |
|
116 |
bool |
|
|
117 |
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const |
118 |
{ |
119 |
return (m_time < o.m_time); |
120 |
} |
121 |
|
122 |
|
115 |
|
123 |
/**************************************************************** |
116 |
/**************************************************************** |
124 |
* The actual InterferenceHelper |
117 |
* The actual InterferenceHelper |
|
141 |
Ptr<InterferenceHelper::Event> |
134 |
Ptr<InterferenceHelper::Event> |
142 |
InterferenceHelper::Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPowerW) |
135 |
InterferenceHelper::Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPowerW) |
143 |
{ |
136 |
{ |
144 |
Ptr<InterferenceHelper::Event> event; |
137 |
Ptr<InterferenceHelper::Event> event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW); |
145 |
event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW); |
|
|
146 |
AppendEvent (event); |
138 |
AppendEvent (event); |
147 |
return event; |
139 |
return event; |
148 |
} |
140 |
} |
|
188 |
} |
180 |
} |
189 |
|
181 |
|
190 |
Time |
182 |
Time |
191 |
InterferenceHelper::GetEnergyDuration (double energyW) const |
183 |
InterferenceHelper::GetEnergyDuration (double energyW) |
192 |
{ |
184 |
{ |
193 |
Time now = Simulator::Now (); |
185 |
Time now = Simulator::Now (); |
194 |
double noiseInterferenceW = 0; |
186 |
auto i = GetPreviousPosition (now); |
195 |
Time end = now; |
187 |
Time end = i->first; |
196 |
noiseInterferenceW = m_firstPower; |
188 |
while (i != m_niChanges.end ()) |
197 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) |
|
|
198 |
{ |
189 |
{ |
199 |
noiseInterferenceW += i->GetDelta (); |
190 |
double noiseInterferenceW = i->second.GetPower (); |
200 |
end = i->GetTime (); |
191 |
end = i->first; |
201 |
if (end < now) |
|
|
202 |
{ |
203 |
continue; |
204 |
} |
205 |
if (noiseInterferenceW < energyW) |
192 |
if (noiseInterferenceW < energyW) |
206 |
{ |
193 |
{ |
207 |
break; |
194 |
break; |
208 |
} |
195 |
} |
|
|
196 |
++i; |
209 |
} |
197 |
} |
210 |
return end > now ? end - now : MicroSeconds (0); |
198 |
return end > now ? end - now : MicroSeconds (0); |
211 |
} |
199 |
} |
|
213 |
void |
201 |
void |
214 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
202 |
InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event) |
215 |
{ |
203 |
{ |
216 |
Time now = Simulator::Now (); |
204 |
NS_LOG_FUNCTION (this); |
|
|
205 |
double previousPowerStart = 0; |
206 |
double previousPowerEnd = 0; |
207 |
if (m_niChanges.size() > 0) |
208 |
{ |
209 |
previousPowerStart = GetPreviousPosition (event->GetStartTime ())->second.GetPower (); |
210 |
previousPowerEnd = GetPreviousPosition (event->GetEndTime ())->second.GetPower (); |
211 |
} |
217 |
if (!m_rxing) |
212 |
if (!m_rxing) |
218 |
{ |
213 |
{ |
219 |
NiChanges::const_iterator nowIterator = GetPosition (now); |
214 |
m_firstPower = previousPowerStart; |
220 |
for (NiChanges::const_iterator i = m_niChanges.begin (); i != nowIterator; i++) |
215 |
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 |
} |
216 |
} |
226 |
AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event)); |
217 |
auto first = AddNiChangeEvent (event->GetStartTime (), NiChange (previousPowerStart, event)); |
227 |
AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event)); |
218 |
auto last = AddNiChangeEvent (event->GetEndTime (), NiChange (previousPowerEnd, event)); |
|
|
219 |
for (auto i = first; i != last; ++i) |
220 |
{ |
221 |
i->second.AddPower (event->GetRxPowerW ()); |
222 |
} |
228 |
} |
223 |
} |
229 |
|
224 |
|
230 |
double |
225 |
double |
|
243 |
} |
238 |
} |
244 |
|
239 |
|
245 |
double |
240 |
double |
246 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const |
241 |
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) |
247 |
{ |
242 |
{ |
248 |
double noiseInterference = m_firstPower; |
243 |
double noiseInterference = m_firstPower; |
249 |
NiChanges::const_iterator eventIterator = m_niChanges.begin (); |
244 |
auto it = m_niChanges.begin (); |
250 |
while (eventIterator != m_niChanges.end ()) |
245 |
for (; it != m_niChanges.end () && it->second.GetEvent () != event; ++it) |
251 |
{ |
246 |
{ |
252 |
// Iterate the NI change list from the beginning to the end |
247 |
noiseInterference = it->second.GetPower (); |
253 |
// until find the position of the event in the NI change list |
|
|
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 |
} |
248 |
} |
273 |
|
249 |
ni->emplace (event->GetStartTime (), NiChange (0, event)); |
274 |
for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i) |
250 |
while (++it != m_niChanges.end () && event != it->second.GetEvent ()) |
275 |
{ |
251 |
{ |
276 |
if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ()) |
252 |
ni->insert (*it); |
277 |
{ |
|
|
278 |
break; |
279 |
} |
280 |
ni->push_back (*i); |
281 |
} |
253 |
} |
282 |
ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event)); |
254 |
ni->emplace(event->GetEndTime (), NiChange (0, event)); |
283 |
ni->push_back (NiChange (event->GetEndTime (), 0, event)); |
|
|
284 |
return noiseInterference; |
255 |
return noiseInterference; |
285 |
} |
256 |
} |
286 |
|
257 |
|
|
312 |
NS_LOG_FUNCTION (this); |
283 |
NS_LOG_FUNCTION (this); |
313 |
const WifiTxVector txVector = event->GetTxVector (); |
284 |
const WifiTxVector txVector = event->GetTxVector (); |
314 |
double psr = 1.0; /* Packet Success Rate */ |
285 |
double psr = 1.0; /* Packet Success Rate */ |
315 |
NiChanges::const_iterator j = ni->begin (); |
286 |
auto j = ni->begin (); |
316 |
Time previous = (*j).GetTime (); |
287 |
Time previous = j->first; |
317 |
WifiMode payloadMode = event->GetPayloadMode (); |
288 |
WifiMode payloadMode = event->GetPayloadMode (); |
318 |
WifiPreamble preamble = txVector.GetPreambleType (); |
289 |
WifiPreamble preamble = txVector.GetPreambleType (); |
319 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
290 |
Time plcpHeaderStart = j->first + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
320 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
291 |
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 |
292 |
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 |
293 |
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 (); |
294 |
double noiseInterferenceW = m_firstPower; |
324 |
double powerW = event->GetRxPowerW (); |
295 |
double powerW = event->GetRxPowerW (); |
325 |
j++; |
296 |
++j; |
326 |
while (ni->end () != j) |
297 |
while (ni->end () != j) |
327 |
{ |
298 |
{ |
328 |
Time current = (*j).GetTime (); |
299 |
Time current = j->first; |
329 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
300 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
330 |
NS_ASSERT (current >= previous); |
301 |
NS_ASSERT (current >= previous); |
331 |
//Case 1: Both previous and current point to the payload |
302 |
//Case 1: Both previous and current point to the payload |
|
348 |
payloadMode, txVector); |
319 |
payloadMode, txVector); |
349 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
320 |
NS_LOG_DEBUG ("previous is before payload and current is in the payload: mode=" << payloadMode << ", psr=" << psr); |
350 |
} |
321 |
} |
351 |
noiseInterferenceW += (*j).GetDelta (); |
322 |
noiseInterferenceW = j->second.GetPower () - powerW; |
352 |
previous = (*j).GetTime (); |
323 |
previous = j->first; |
353 |
j++; |
324 |
++j; |
354 |
} |
325 |
} |
355 |
double per = 1 - psr; |
326 |
double per = 1 - psr; |
356 |
return per; |
327 |
return per; |
|
362 |
NS_LOG_FUNCTION (this); |
333 |
NS_LOG_FUNCTION (this); |
363 |
const WifiTxVector txVector = event->GetTxVector (); |
334 |
const WifiTxVector txVector = event->GetTxVector (); |
364 |
double psr = 1.0; /* Packet Success Rate */ |
335 |
double psr = 1.0; /* Packet Success Rate */ |
365 |
NiChanges::const_iterator j = ni->begin (); |
336 |
auto j = ni->begin (); |
366 |
Time previous = (*j).GetTime (); |
337 |
Time previous = j->first; |
367 |
WifiPreamble preamble = txVector.GetPreambleType (); |
338 |
WifiPreamble preamble = txVector.GetPreambleType (); |
368 |
WifiMode mcsHeaderMode; |
339 |
WifiMode mcsHeaderMode; |
369 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
340 |
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF) |
|
382 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
353 |
mcsHeaderMode = WifiPhy::GetHePlcpHeaderMode (); |
383 |
} |
354 |
} |
384 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
355 |
WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (txVector); |
385 |
Time plcpHeaderStart = (*j).GetTime () + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
356 |
Time plcpHeaderStart = j->first + WifiPhy::GetPlcpPreambleDuration (txVector); //packet start time + preamble |
386 |
Time plcpHsigHeaderStart = plcpHeaderStart + WifiPhy::GetPlcpHeaderDuration (txVector); //packet start time + preamble + L-SIG |
357 |
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 |
358 |
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 |
359 |
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 (); |
360 |
double noiseInterferenceW = m_firstPower; |
390 |
double powerW = event->GetRxPowerW (); |
361 |
double powerW = event->GetRxPowerW (); |
391 |
j++; |
362 |
++j; |
392 |
while (ni->end () != j) |
363 |
while (ni->end () != j) |
393 |
{ |
364 |
{ |
394 |
Time current = (*j).GetTime (); |
365 |
Time current = j->first; |
395 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
366 |
NS_LOG_DEBUG ("previous= " << previous << ", current=" << current); |
396 |
NS_ASSERT (current >= previous); |
367 |
NS_ASSERT (current >= previous); |
397 |
//Case 1: previous and current after playload start: nothing to do |
368 |
//Case 1: previous and current after playload start: nothing to do |
|
764 |
} |
735 |
} |
765 |
} |
736 |
} |
766 |
|
737 |
|
767 |
noiseInterferenceW += (*j).GetDelta (); |
738 |
noiseInterferenceW = j->second.GetPower () - powerW; |
768 |
previous = (*j).GetTime (); |
739 |
previous = j->first; |
769 |
j++; |
740 |
++j; |
770 |
} |
741 |
} |
771 |
|
742 |
|
772 |
double per = 1 - psr; |
743 |
double per = 1 - psr; |
|
821 |
m_firstPower = 0; |
792 |
m_firstPower = 0; |
822 |
} |
793 |
} |
823 |
|
794 |
|
824 |
InterferenceHelper::NiChanges::const_iterator |
795 |
InterferenceHelper::NiChanges::iterator |
825 |
InterferenceHelper::GetPosition (Time moment) |
796 |
InterferenceHelper::GetNextPosition (Time moment) |
826 |
{ |
797 |
{ |
827 |
return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL)); |
798 |
return m_niChanges.upper_bound (moment); |
828 |
} |
799 |
} |
829 |
|
800 |
|
830 |
void |
801 |
InterferenceHelper::NiChanges::iterator |
831 |
InterferenceHelper::AddNiChangeEvent (NiChange change) |
802 |
InterferenceHelper::GetPreviousPosition (Time moment) |
832 |
{ |
803 |
{ |
833 |
m_niChanges.insert (GetPosition (change.GetTime ()), change); |
804 |
auto it = GetNextPosition (moment); |
|
|
805 |
return --it; |
806 |
} |
807 |
|
808 |
InterferenceHelper::NiChanges::iterator |
809 |
InterferenceHelper::GetPositionBeforeTime (Time moment) |
810 |
{ |
811 |
auto it = m_niChanges.find (moment); |
812 |
return --it; |
813 |
} |
814 |
|
815 |
InterferenceHelper::NiChanges::iterator |
816 |
InterferenceHelper::AddNiChangeEvent (Time moment, NiChange change) |
817 |
{ |
818 |
return m_niChanges.insert (GetNextPosition (moment), std::make_pair (moment, change)); |
834 |
} |
819 |
} |
835 |
|
820 |
|
836 |
void |
821 |
void |
|
845 |
{ |
830 |
{ |
846 |
NS_LOG_FUNCTION (this); |
831 |
NS_LOG_FUNCTION (this); |
847 |
m_rxing = false; |
832 |
m_rxing = false; |
|
|
833 |
//Update m_firstPower for frame capture |
834 |
auto it = GetPositionBeforeTime (Simulator::Now ()); |
835 |
m_firstPower = it->second.GetPower (); |
848 |
} |
836 |
} |
849 |
|
837 |
|
850 |
} //namespace ns3 |
838 |
} //namespace ns3 |