A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
interference-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Sébastien Deronne <sebastien.deronne@gmail.com>
8 */
9
10#include "interference-helper.h"
11
12#include "error-rate-model.h"
13#include "phy-entity.h"
15#include "wifi-phy.h"
16#include "wifi-psdu.h"
17#include "wifi-utils.h"
18
19#include "ns3/he-ppdu.h"
20#include "ns3/log.h"
21#include "ns3/packet.h"
22#include "ns3/simulator.h"
23
24#include <algorithm>
25#include <numeric>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("InterferenceHelper");
31
33
34/****************************************************************
35 * PHY event class
36 ****************************************************************/
37
39 : m_ppdu(ppdu),
41 m_endTime(m_startTime + duration),
42 m_rxPowerW(std::move(rxPower))
43{
44}
45
48{
49 return m_ppdu;
50}
51
52Time
54{
55 return m_startTime;
56}
57
58Time
60{
61 return m_endTime;
62}
63
64Time
66{
67 return m_endTime - m_startTime;
68}
69
72{
73 NS_ASSERT(!m_rxPowerW.empty());
74 // The total RX power corresponds to the maximum over all the bands
75 auto it =
76 std::max_element(m_rxPowerW.cbegin(),
77 m_rxPowerW.cend(),
78 [](const auto& p1, const auto& p2) { return p1.second < p2.second; });
79 return it->second;
80}
81
84{
85 const auto it = m_rxPowerW.find(band);
86 NS_ASSERT(it != m_rxPowerW.cend());
87 return it->second;
88}
89
92{
93 return m_rxPowerW;
94}
95
96void
98{
99 NS_ASSERT(rxPower.size() == m_rxPowerW.size());
100 // Update power band per band
101 for (auto& currentRxPowerW : m_rxPowerW)
102 {
103 auto band = currentRxPowerW.first;
104 auto it = rxPower.find(band);
105 if (it != rxPower.end())
106 {
107 currentRxPowerW.second += it->second;
108 }
109 }
110}
111
112void
114{
115 m_ppdu = ppdu;
116}
117
118std::ostream&
119operator<<(std::ostream& os, const Event& event)
120{
121 os << "start=" << event.GetStartTime() << ", end=" << event.GetEndTime()
122 << ", power=" << event.GetRxPower() << "W"
123 << ", PPDU=" << event.GetPpdu();
124 return os;
125}
126
127/****************************************************************
128 * Class which records SNIR change events for a
129 * short period of time.
130 ****************************************************************/
131
133 : m_power(power),
134 m_event(event)
135{
136}
137
138Watt_u
143
144void
149
155
156/****************************************************************
157 * The actual InterferenceHelper
158 ****************************************************************/
159
166
171
172TypeId
174{
175 static TypeId tid = TypeId("ns3::InterferenceHelper")
177 .SetGroupName("Wifi")
178 .AddConstructor<InterferenceHelper>();
179 return tid;
180}
181
182void
184{
185 NS_LOG_FUNCTION(this);
186 for (auto it : m_niChanges)
187 {
188 it.second.clear();
189 }
190 m_niChanges.clear();
191 m_firstPowers.clear();
192 m_errorRateModel = nullptr;
193}
194
197 Time duration,
199 const FrequencyRange& freqRange,
200 bool isStartHePortionRxing)
201{
202 Ptr<Event> event = Create<Event>(ppdu, duration, std::move(rxPowerW));
203 AppendEvent(event, freqRange, isStartHePortionRxing);
204 return event;
205}
206
207void
210 const FrequencyRange& freqRange)
211{
212 // Parameters other than duration and rxPowerW are unused for this type
213 // of signal, so we provide dummy versions
214 WifiMacHeader hdr;
216 hdr.SetQosTid(0);
218 WifiTxVector(),
220 Add(fakePpdu, duration, rxPowerW, freqRange);
221}
222
223bool
225{
226 return !m_niChanges.empty();
227}
228
229bool
231{
232 return m_niChanges.contains(band);
233}
234
235void
237{
238 NS_LOG_FUNCTION(this << band);
239 NS_ASSERT(!m_niChanges.contains(band));
240 NS_ASSERT(!m_firstPowers.contains(band));
241 NiChanges niChanges;
242 auto result = m_niChanges.insert({band, niChanges});
243 NS_ASSERT(result.second);
244 // Always have a zero power noise event in the list
245 AddNiChangeEvent(Time(0), NiChange(Watt_u{0}, nullptr), result.first);
246 m_firstPowers.insert({band, Watt_u{0}});
247}
248
249void
251{
252 NS_LOG_FUNCTION(this << band);
253 NS_ASSERT(m_firstPowers.count(band) != 0);
254 m_firstPowers.erase(band);
255 auto it = m_niChanges.find(band);
256 NS_ASSERT(it != std::end(m_niChanges));
257 it->second.clear();
258 m_niChanges.erase(it);
259}
260
261void
262InterferenceHelper::UpdateBands(const std::vector<WifiSpectrumBandInfo>& bands,
263 const FrequencyRange& freqRange)
264{
265 NS_LOG_FUNCTION(this << freqRange);
266 std::vector<WifiSpectrumBandInfo> bandsToRemove{};
267 for (auto it = m_niChanges.begin(); it != m_niChanges.end(); ++it)
269 if (!IsBandInFrequencyRange(it->first, freqRange))
270 {
271 continue;
272 }
273 const auto frequencies = it->first.frequencies;
274 const auto found =
275 std::find_if(bands.cbegin(), bands.cend(), [frequencies](const auto& item) {
276 return frequencies == item.frequencies;
277 }) != std::end(bands);
278 if (!found)
279 {
280 // band does not belong to the new bands, erase it
281 bandsToRemove.emplace_back(it->first);
282 }
283 }
284 for (const auto& band : bandsToRemove)
285 {
286 RemoveBand(band);
287 }
288 for (const auto& band : bands)
289 {
290 if (!HasBand(band))
291 {
292 // this is a new band, add it
293 AddBand(band);
294 }
295 }
296}
297
298void
300{
301 m_noiseFigure = value;
302}
303
304void
309
315
316void
321
324{
325 NS_LOG_FUNCTION(this << energy << band);
326 Time now = Simulator::Now();
327 auto niIt = m_niChanges.find(band);
328 NS_ABORT_IF(niIt == m_niChanges.end());
329 auto i = GetPreviousPosition(now, niIt);
330 Time end = i->first;
331 for (; i != niIt->second.end(); ++i)
332 {
333 const auto noiseInterference = i->second.GetPower();
334 end = i->first;
335 if (noiseInterference < energy)
336 {
337 break;
338 }
339 }
340 return end > now ? end - now : Time{0};
341}
342
343void
345 const FrequencyRange& freqRange,
346 bool isStartHePortionRxing)
347{
348 NS_LOG_FUNCTION(this << event << freqRange << isStartHePortionRxing);
349 for (const auto& [band, power] : event->GetRxPowerPerBand())
350 {
351 auto niIt = m_niChanges.find(band);
352 NS_ABORT_IF(niIt == m_niChanges.end());
353 Watt_u previousPowerStart{0.0};
354 Watt_u previousPowerEnd{0.0};
355 auto previousPowerPosition = GetPreviousPosition(event->GetStartTime(), niIt);
356 previousPowerStart = previousPowerPosition->second.GetPower();
357 previousPowerEnd = GetPreviousPosition(event->GetEndTime(), niIt)->second.GetPower();
358 if (const auto rxing = (m_rxing.contains(freqRange) && m_rxing.at(freqRange)); !rxing)
359 {
360 m_firstPowers.find(band)->second = previousPowerStart;
361 // Always leave the first zero power noise event in the list
362 niIt->second.erase(++(niIt->second.begin()), ++previousPowerPosition);
363 }
364 else if (isStartHePortionRxing)
365 {
366 // When the first HE portion is received, we need to set m_firstPowerPerBand
367 // so that it takes into account interferences that arrived between the start of the
368 // HE TB PPDU transmission and the start of HE TB payload.
369 m_firstPowers.find(band)->second = previousPowerStart;
370 }
371 auto first =
372 AddNiChangeEvent(event->GetStartTime(), NiChange(previousPowerStart, event), niIt);
373 auto last = AddNiChangeEvent(event->GetEndTime(), NiChange(previousPowerEnd, event), niIt);
374 for (auto i = first; i != last; ++i)
375 {
376 i->second.AddPower(power);
377 }
378 }
379}
380
381void
383{
384 NS_LOG_FUNCTION(this << event);
385 // This is called for UL MU events, in order to scale power as long as UL MU PPDUs arrive
386 for (const auto& [band, power] : rxPower)
387 {
388 auto niIt = m_niChanges.find(band);
389 NS_ABORT_IF(niIt == m_niChanges.end());
390 auto first = GetPreviousPosition(event->GetStartTime(), niIt);
391 auto last = GetPreviousPosition(event->GetEndTime(), niIt);
392 for (auto i = first; i != last; ++i)
393 {
394 i->second.AddPower(power);
395 }
396 }
397 event->UpdateRxPowerW(rxPower);
398}
399
400double
402 Watt_u noiseInterference,
403 MHz_u channelWidth,
404 uint8_t nss) const
405{
406 NS_LOG_FUNCTION(this << signal << noiseInterference << channelWidth << +nss);
407 // thermal noise at 290K in J/s = W
408 static const double BOLTZMANN = 1.3803e-23;
409 // Nt is the power of thermal noise in W
410 const auto Nt = BOLTZMANN * 290 * MHzToHz(channelWidth);
411 // receiver noise Floor which accounts for thermal noise and non-idealities of the receiver
412 Watt_u noiseFloor{m_noiseFigure * Nt};
413 Watt_u noise = noiseFloor + noiseInterference;
414 auto snr = signal / noise; // linear scale
415 NS_LOG_DEBUG("bandwidth=" << channelWidth << "MHz, signal=" << signal << "W, noise="
416 << noiseFloor << "W, interference=" << noiseInterference
417 << "W, snr=" << RatioToDb(snr) << "dB");
418 if (m_errorRateModel->IsAwgn())
419 {
420 double gain = 1;
421 if (m_numRxAntennas > nss)
422 {
423 gain = static_cast<double>(m_numRxAntennas) /
424 nss; // compute gain offered by diversity for AWGN
425 }
426 NS_LOG_DEBUG("SNR improvement thanks to diversity: " << 10 * std::log10(gain) << "dB");
427 snr *= gain;
428 }
429 return snr;
430}
431
432Watt_u
434 NiChangesPerBand& nis,
435 const WifiSpectrumBandInfo& band) const
436{
437 NS_LOG_FUNCTION(this << band);
438 auto firstPower_it = m_firstPowers.find(band);
439 NS_ABORT_IF(firstPower_it == m_firstPowers.end());
440 auto noiseInterference = firstPower_it->second;
441 auto niIt = m_niChanges.find(band);
442 NS_ABORT_IF(niIt == m_niChanges.end());
443 const auto now = Simulator::Now();
444 auto it = niIt->second.find(event->GetStartTime());
445 const auto muMimoPower = (event->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU)
446 ? CalculateMuMimoPowerW(event, band)
447 : Watt_u{0.0};
448 for (; it != niIt->second.end() && it->first < now; ++it)
449 {
450 if (IsSameMuMimoTransmission(event, it->second.GetEvent()) &&
451 (event != it->second.GetEvent()))
452 {
453 // Do not calculate noiseInterferenceW if events belong to the same MU-MIMO transmission
454 // unless this is the same event
455 continue;
456 }
457 noiseInterference = it->second.GetPower() - event->GetRxPower(band) - muMimoPower;
458 if (std::abs(noiseInterference) < std::numeric_limits<double>::epsilon())
459 {
460 // fix some possible rounding issues with double values
461 noiseInterference = Watt_u{0.0};
462 }
463 }
464 it = niIt->second.find(event->GetStartTime());
465 NS_ABORT_IF(it == niIt->second.end());
466 for (; it != niIt->second.end() && it->second.GetEvent() != event; ++it)
467 {
468 ;
469 }
470 NiChanges ni;
471 ni.emplace(event->GetStartTime(), NiChange(Watt_u{0}, event));
472 while (++it != niIt->second.end() && it->second.GetEvent() != event)
473 {
474 ni.insert(*it);
475 }
476 ni.emplace(event->GetEndTime(), NiChange(Watt_u{0}, event));
477 nis.insert({band, ni});
478 NS_ASSERT_MSG(noiseInterference >= Watt_u{0.0},
479 "CalculateNoiseInterferenceW returns negative value " << noiseInterference);
480 return noiseInterference;
481}
482
483Watt_u
485 const WifiSpectrumBandInfo& band) const
486{
487 auto niIt = m_niChanges.find(band);
488 NS_ASSERT(niIt != m_niChanges.end());
489 auto it = niIt->second.begin();
490 ++it;
491 Watt_u muMimoPower{0.0};
492 for (; it != niIt->second.end() && it->first < Simulator::Now(); ++it)
493 {
494 if (IsSameMuMimoTransmission(event, it->second.GetEvent()))
495 {
496 auto hePpdu = DynamicCast<HePpdu>(it->second.GetEvent()->GetPpdu()->Copy());
497 NS_ASSERT(hePpdu);
498 HePpdu::TxPsdFlag psdFlag = hePpdu->GetTxPsdFlag();
499 if (psdFlag == HePpdu::PSD_HE_PORTION)
500 {
501 const auto staId =
502 event->GetPpdu()->GetTxVector().GetHeMuUserInfoMap().cbegin()->first;
503 const auto otherStaId = it->second.GetEvent()
504 ->GetPpdu()
505 ->GetTxVector()
506 .GetHeMuUserInfoMap()
507 .cbegin()
508 ->first;
509 if (staId == otherStaId)
510 {
511 break;
512 }
513 muMimoPower += it->second.GetEvent()->GetRxPower(band);
514 }
515 }
516 }
517 return muMimoPower;
518}
519
520double
522 Time duration,
523 WifiMode mode,
524 const WifiTxVector& txVector,
525 WifiPpduField field) const
526{
527 if (duration.IsZero())
528 {
529 return 1.0;
530 }
531 const auto rate = mode.GetDataRate(txVector.GetChannelWidth());
532 auto nbits = static_cast<uint64_t>(rate * duration.GetSeconds());
533 const auto csr =
534 m_errorRateModel->GetChunkSuccessRate(mode, txVector, snir, nbits, m_numRxAntennas, field);
535 return csr;
536}
537
538double
540 Time duration,
541 const WifiTxVector& txVector,
542 uint16_t staId) const
543{
544 if (duration.IsZero())
545 {
546 return 1.0;
547 }
548 const auto mode = txVector.GetMode(staId);
549 const auto rate = mode.GetDataRate(txVector, staId);
550 auto nbits = static_cast<uint64_t>(rate * duration.GetSeconds());
551 nbits /= txVector.GetNss(staId); // divide effective number of bits by NSS to achieve same chunk
552 // error rate as SISO for AWGN
553 double csr = m_errorRateModel->GetChunkSuccessRate(mode,
554 txVector,
555 snir,
556 nbits,
559 staId);
560 return csr;
561}
562
563double
565 MHz_u channelWidth,
566 NiChangesPerBand* nis,
567 const WifiSpectrumBandInfo& band,
568 uint16_t staId,
569 std::pair<Time, Time> window) const
570{
571 NS_LOG_FUNCTION(this << channelWidth << band << staId << window.first << window.second);
572 double psr = 1.0; /* Packet Success Rate */
573 const auto& niIt = nis->find(band)->second;
574 auto j = niIt.cbegin();
575 auto previous = j->first;
576 Watt_u muMimoPower{0.0};
577 const auto payloadMode = event->GetPpdu()->GetTxVector().GetMode(staId);
578 auto phyPayloadStart = j->first;
579 if (event->GetPpdu()->GetType() != WIFI_PPDU_TYPE_UL_MU &&
580 event->GetPpdu()->GetType() !=
581 WIFI_PPDU_TYPE_DL_MU) // j->first corresponds to the start of the MU payload
582 {
583 phyPayloadStart = j->first + WifiPhy::CalculatePhyPreambleAndHeaderDuration(
584 event->GetPpdu()->GetTxVector());
585 }
586 else
587 {
588 muMimoPower = CalculateMuMimoPowerW(event, band);
589 }
590 const auto windowStart = phyPayloadStart + window.first;
591 const auto windowEnd = phyPayloadStart + window.second;
592 NS_ABORT_IF(!m_firstPowers.contains(band));
593 auto noiseInterference = m_firstPowers.at(band);
594 auto power = event->GetRxPower(band);
595 while (++j != niIt.cend())
596 {
597 Time current = j->first;
598 NS_LOG_DEBUG("previous= " << previous << ", current=" << current);
599 NS_ASSERT(current >= previous);
600 const auto snr = CalculateSnr(power,
601 noiseInterference,
602 channelWidth,
603 event->GetPpdu()->GetTxVector().GetNss(staId));
604 // Case 1: Both previous and current point to the windowed payload
605 if (previous >= windowStart)
606 {
608 Min(windowEnd, current) - previous,
609 event->GetPpdu()->GetTxVector(),
610 staId);
611 NS_LOG_DEBUG("Both previous and current point to the windowed payload: mode="
612 << payloadMode << ", psr=" << psr);
613 }
614 // Case 2: previous is before windowed payload and current is in the windowed payload
615 else if (current >= windowStart)
616 {
618 Min(windowEnd, current) - windowStart,
619 event->GetPpdu()->GetTxVector(),
620 staId);
622 "previous is before windowed payload and current is in the windowed payload: mode="
623 << payloadMode << ", psr=" << psr);
624 }
625 noiseInterference = j->second.GetPower() - power;
626 if (IsSameMuMimoTransmission(event, j->second.GetEvent()))
627 {
628 muMimoPower += j->second.GetEvent()->GetRxPower(band);
629 NS_LOG_DEBUG("PPDU belongs to same MU-MIMO transmission: muMimoPowerW=" << muMimoPower);
630 }
631 noiseInterference -= muMimoPower;
632 previous = j->first;
633 if (previous > windowEnd)
634 {
635 NS_LOG_DEBUG("Stop: new previous=" << previous
636 << " after time window end=" << windowEnd);
637 break;
638 }
639 }
640 const auto per = 1.0 - psr;
641 return per;
642}
643
644double
646 NiChangesPerBand* nis,
647 MHz_u channelWidth,
648 const WifiSpectrumBandInfo& band,
649 PhyHeaderSections phyHeaderSections) const
650{
651 NS_LOG_FUNCTION(this << band);
652 double psr = 1.0; /* Packet Success Rate */
653 auto niIt = nis->find(band)->second;
654 auto j = niIt.begin();
655
656 NS_ASSERT(!phyHeaderSections.empty());
657 Time stopLastSection;
658 for (const auto& section : phyHeaderSections)
659 {
660 stopLastSection = Max(stopLastSection, section.second.first.second);
661 }
662
663 auto previous = j->first;
664 NS_ABORT_IF(!m_firstPowers.contains(band));
665 auto noiseInterference = m_firstPowers.at(band);
666 const auto power = event->GetRxPower(band);
667 while (++j != niIt.end())
668 {
669 auto current = j->first;
670 NS_LOG_DEBUG("previous= " << previous << ", current=" << current);
671 NS_ASSERT(current >= previous);
672 const auto snr = CalculateSnr(power, noiseInterference, channelWidth, 1);
673 for (const auto& section : phyHeaderSections)
674 {
675 const auto start = section.second.first.first;
676 const auto stop = section.second.first.second;
677
678 if (previous <= stop || current >= start)
679 {
680 const auto duration = Min(stop, current) - Max(start, previous);
681 if (duration.IsStrictlyPositive())
682 {
683 psr *= CalculateChunkSuccessRate(snr,
684 duration,
685 section.second.second,
686 event->GetPpdu()->GetTxVector(),
687 section.first);
688 NS_LOG_DEBUG("Current NI change in "
689 << section.first << " [" << start << ", " << stop << "] for "
690 << duration.As(Time::NS) << ": mode=" << section.second.second
691 << ", psr=" << psr);
692 }
693 }
694 }
695 noiseInterference = j->second.GetPower() - power;
696 previous = j->first;
697 if (previous > stopLastSection)
698 {
699 NS_LOG_DEBUG("Stop: new previous=" << previous << " after stop of last section="
700 << stopLastSection);
701 break;
702 }
703 }
704 return psr;
705}
706
707double
709 NiChangesPerBand* nis,
710 MHz_u channelWidth,
711 const WifiSpectrumBandInfo& band,
712 WifiPpduField header) const
713{
714 NS_LOG_FUNCTION(this << band << header);
715 auto niIt = nis->find(band)->second;
716 auto phyEntity =
717 WifiPhy::GetStaticPhyEntity(event->GetPpdu()->GetTxVector().GetModulationClass());
718
719 PhyHeaderSections sections;
720 for (const auto& section :
721 phyEntity->GetPhyHeaderSections(event->GetPpdu()->GetTxVector(), niIt.begin()->first))
722 {
723 if (section.first == header)
724 {
725 sections[header] = section.second;
726 }
727 }
728
729 double psr = 1.0;
730 if (!sections.empty())
731 {
732 psr = CalculatePhyHeaderSectionPsr(event, nis, channelWidth, band, sections);
733 }
734 return 1 - psr;
735}
736
737SnrPer
739 MHz_u channelWidth,
740 const WifiSpectrumBandInfo& band,
741 uint16_t staId,
742 std::pair<Time, Time> relativeMpduStartStop) const
743{
744 NS_LOG_FUNCTION(this << channelWidth << band << staId << relativeMpduStartStop.first
745 << relativeMpduStartStop.second);
747 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
748 const auto snr = CalculateSnr(event->GetRxPower(band),
749 noiseInterference,
750 channelWidth,
751 event->GetPpdu()->GetTxVector().GetNss(staId));
752
753 /* calculate the SNIR at the start of the MPDU (located through windowing) and accumulate
754 * all SNIR changes in the SNIR vector.
755 */
756 const auto per =
757 CalculatePayloadPer(event, channelWidth, &ni, band, staId, relativeMpduStartStop);
758
759 return SnrPer(snr, per);
760}
761
762double
764 MHz_u channelWidth,
765 uint8_t nss,
766 const WifiSpectrumBandInfo& band) const
767{
769 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
770 return CalculateSnr(event->GetRxPower(band), noiseInterference, channelWidth, nss);
771}
772
773SnrPer
775 MHz_u channelWidth,
776 const WifiSpectrumBandInfo& band,
777 WifiPpduField header) const
778{
779 NS_LOG_FUNCTION(this << band << header);
781 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
782 const auto snr = CalculateSnr(event->GetRxPower(band), noiseInterference, channelWidth, 1);
783
784 /* calculate the SNIR at the start of the PHY header and accumulate
785 * all SNIR changes in the SNIR vector.
786 */
787 const auto per = CalculatePhyHeaderPer(event, &ni, channelWidth, band, header);
788
789 return SnrPer(snr, per);
790}
791
792InterferenceHelper::NiChanges::iterator
793InterferenceHelper::GetNextPosition(Time moment, NiChangesPerBand::iterator niIt) const
794{
795 return niIt->second.upper_bound(moment);
796}
797
798InterferenceHelper::NiChanges::iterator
799InterferenceHelper::GetPreviousPosition(Time moment, NiChangesPerBand::iterator niIt) const
800{
801 // This is safe since there is always an NiChange at time 0, before moment.
802 return std::prev(GetNextPosition(moment, niIt));
803}
804
805InterferenceHelper::NiChanges::iterator
806InterferenceHelper::AddNiChangeEvent(Time moment, NiChange change, NiChangesPerBand::iterator niIt)
807{
808 return niIt->second.insert(GetNextPosition(moment, niIt), {moment, change});
809}
810
811void
813{
814 NS_LOG_FUNCTION(this << freqRange);
815 m_rxing[freqRange] = true;
816}
817
818void
820{
821 NS_LOG_FUNCTION(this << endTime << freqRange);
822 m_rxing.at(freqRange) = false;
823 // Update m_firstPowers for frame capture
824 for (auto niIt = m_niChanges.begin(); niIt != m_niChanges.end(); ++niIt)
825 {
826 if (!IsBandInFrequencyRange(niIt->first, freqRange))
827 {
828 continue;
829 }
830 NS_ASSERT(niIt->second.size() > 1);
831 auto it = std::prev(GetPreviousPosition(endTime, niIt));
832 m_firstPowers.find(niIt->first)->second = it->second.GetPower();
833 }
834}
835
836bool
838 const FrequencyRange& freqRange) const
839{
840 return std::all_of(band.frequencies.cbegin(),
841 band.frequencies.cend(),
842 [&freqRange](const auto& freqs) {
843 return ((freqs.second > MHzToHz(freqRange.minFrequency)) &&
844 (freqs.first < MHzToHz(freqRange.maxFrequency)));
845 });
846}
847
848bool
850 Ptr<const Event> otherEvent) const
851{
852 if ((currentEvent->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU) &&
853 (otherEvent->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU) &&
854 (currentEvent->GetPpdu()->GetUid() == otherEvent->GetPpdu()->GetUid()))
855 {
856 const auto currentTxVector = currentEvent->GetPpdu()->GetTxVector();
857 const auto otherTxVector = otherEvent->GetPpdu()->GetTxVector();
858 NS_ASSERT(currentTxVector.GetHeMuUserInfoMap().size() == 1);
859 NS_ASSERT(otherTxVector.GetHeMuUserInfoMap().size() == 1);
860 const auto currentUserInfo = currentTxVector.GetHeMuUserInfoMap().cbegin();
861 const auto otherUserInfo = otherTxVector.GetHeMuUserInfoMap().cbegin();
862 return (currentUserInfo->second.ru == otherUserInfo->second.ru);
863 }
864 return false;
865}
866
867} // namespace ns3
#define Max(a, b)
#define Min(a, b)
handles interference calculations
Time m_endTime
end time
Watt_u GetRxPower() const
Return the total received power.
Time m_startTime
start time
Event(Ptr< const WifiPpdu > ppdu, Time duration, RxPowerWattPerChannelBand &&rxPower)
Create an Event with the given parameters.
Ptr< const WifiPpdu > GetPpdu() const
Return the PPDU.
Ptr< const WifiPpdu > m_ppdu
PPDU.
void UpdateRxPowerW(const RxPowerWattPerChannelBand &rxPower)
Update the received power (W) for all bands, i.e.
Time GetEndTime() const
Return the end time of the signal.
Time GetDuration() const
Return the duration of the signal.
const RxPowerWattPerChannelBand & GetRxPowerPerBand() const
Return the received power (W) for all bands.
RxPowerWattPerChannelBand m_rxPowerW
received power in watts per band
Time GetStartTime() const
Return the start time of the signal.
void UpdatePpdu(Ptr< const WifiPpdu > ppdu)
Update the PPDU that initially generated the event.
TxPsdFlag
The transmit power spectral density flag, namely used to correctly build PSDs for pre-HE and HE porti...
Definition he-ppdu.h:104
@ PSD_HE_PORTION
HE portion of an HE PPDU.
Definition he-ppdu.h:106
Noise and Interference (thus Ni) event.
void AddPower(Watt_u power)
Add a given amount of power.
NiChange(Watt_u power, Ptr< Event > event)
Create a NiChange at the given time and the amount of NI change.
Watt_u GetPower() const
Return the power.
Ptr< Event > GetEvent() const
Return the event causes the corresponding NI change.
handles interference calculations
double CalculatePhyHeaderPer(Ptr< const Event > event, NiChangesPerBand *nis, MHz_u channelWidth, const WifiSpectrumBandInfo &band, WifiPpduField header) const
Calculate the error rate of the PHY header.
void SetNoiseFigure(double value)
Set the noise figure.
Ptr< Event > Add(Ptr< const WifiPpdu > ppdu, Time duration, RxPowerWattPerChannelBand &rxPower, const FrequencyRange &freqRange, bool isStartHePortionRxing=false)
Add the PPDU-related signal to interference helper.
double m_noiseFigure
noise figure (linear)
std::map< FrequencyRange, bool > m_rxing
flag whether it is in receiving state for a given FrequencyRange
Ptr< ErrorRateModel > GetErrorRateModel() const
Return the error rate model.
NiChanges::iterator AddNiChangeEvent(Time moment, NiChange change, NiChangesPerBand::iterator niIt)
Add NiChange to the list at the appropriate position and return the iterator of the new event.
std::map< WifiSpectrumBandInfo, NiChanges > NiChangesPerBand
Map of NiChanges per band.
void NotifyRxStart(const FrequencyRange &freqRange)
Notify that RX has started.
NiChanges::iterator GetNextPosition(Time moment, NiChangesPerBand::iterator niIt) const
Returns an iterator to the first NiChange that is later than moment.
uint8_t m_numRxAntennas
the number of RX antennas in the corresponding receiver
bool IsBandInFrequencyRange(const WifiSpectrumBandInfo &band, const FrequencyRange &freqRange) const
Check whether a given band belongs to a given frequency range.
void DoDispose() override
Destructor implementation.
std::multimap< Time, NiChange > NiChanges
typedef for a multimap of NiChange
Time GetEnergyDuration(Watt_u energy, const WifiSpectrumBandInfo &band)
NiChangesPerBand m_niChanges
NI Changes for each band.
void UpdateBands(const std::vector< WifiSpectrumBandInfo > &bands, const FrequencyRange &freqRange)
Update the frequency bands that belongs to a given frequency range when the spectrum model is changed...
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
bool HasBands() const
Check whether bands are already tracked by this interference helper.
void AddForeignSignal(Time duration, RxPowerWattPerChannelBand &rxPower, const FrequencyRange &freqRange)
Add a non-Wifi signal to interference helper.
double CalculatePayloadChunkSuccessRate(double snir, Time duration, const WifiTxVector &txVector, uint16_t staId=SU_STA_ID) const
Calculate the success rate of the payload chunk given the SINR, duration, and TXVECTOR.
Ptr< ErrorRateModel > m_errorRateModel
error rate model
SnrPer CalculatePhyHeaderSnrPer(Ptr< Event > event, MHz_u channelWidth, const WifiSpectrumBandInfo &band, WifiPpduField header) const
Calculate the SNIR at the start of the PHY header and accumulate all SNIR changes in the SNIR vector.
FirstPowerPerBand m_firstPowers
first power of each band
bool IsSameMuMimoTransmission(Ptr< const Event > currentEvent, Ptr< const Event > otherEvent) const
Return whether another event is a MU-MIMO event that belongs to the same transmission and to the same...
double CalculateChunkSuccessRate(double snir, Time duration, WifiMode mode, const WifiTxVector &txVector, WifiPpduField field) const
Calculate the success rate of the chunk given the SINR, duration, and TXVECTOR.
bool HasBand(const WifiSpectrumBandInfo &band) const
Check whether a given band is tracked by this interference helper.
void AddBand(const WifiSpectrumBandInfo &band)
Add a frequency band.
Watt_u CalculateMuMimoPowerW(Ptr< const Event > event, const WifiSpectrumBandInfo &band) const
Calculate power of all other events preceding a given event that belong to the same MU-MIMO transmiss...
void AppendEvent(Ptr< Event > event, const FrequencyRange &freqRange, bool isStartHePortionRxing)
Append the given Event.
static TypeId GetTypeId()
Get the type ID.
void UpdateEvent(Ptr< Event > event, const RxPowerWattPerChannelBand &rxPower)
Update event to scale its received power (W) per band.
void RemoveBand(const WifiSpectrumBandInfo &band)
Remove a frequency band.
void NotifyRxEnd(Time endTime, const FrequencyRange &freqRange)
Notify that RX has ended.
Watt_u CalculateNoiseInterferenceW(Ptr< Event > event, NiChangesPerBand &nis, const WifiSpectrumBandInfo &band) const
Calculate noise and interference power.
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
SnrPer CalculatePayloadSnrPer(Ptr< Event > event, MHz_u channelWidth, const WifiSpectrumBandInfo &band, uint16_t staId, std::pair< Time, Time > relativeMpduStartStop) const
Calculate the SNIR at the start of the payload and accumulate all SNIR changes in the SNIR vector for...
NiChanges::iterator GetPreviousPosition(Time moment, NiChangesPerBand::iterator niIt) const
Returns an iterator to the last NiChange that is before than moment.
double CalculateSnr(Ptr< Event > event, MHz_u channelWidth, uint8_t nss, const WifiSpectrumBandInfo &band) const
Calculate the SNIR for the event (starting from now until the event end).
double CalculatePayloadPer(Ptr< const Event > event, MHz_u channelWidth, NiChangesPerBand *nis, const WifiSpectrumBandInfo &band, uint16_t staId, std::pair< Time, Time > window) const
Calculate the error rate of the given PHY payload only in the provided time window (thus enabling per...
double CalculatePhyHeaderSectionPsr(Ptr< const Event > event, NiChangesPerBand *nis, MHz_u channelWidth, const WifiSpectrumBandInfo &band, PhyHeaderSections phyHeaderSections) const
Calculate the success rate of the PHY header sections for the provided event.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Control the scheduling of simulation events.
Definition simulator.h:57
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:394
@ NS
nanosecond
Definition nstime.h:110
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:306
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Implements the IEEE 802.11 MAC header.
virtual void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
represent a single transmission mode
Definition wifi-mode.h:38
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
static const std::shared_ptr< const PhyEntity > GetStaticPhyEntity(WifiModulationClass modulation)
Get the implemented PHY entity corresponding to the modulation class.
Definition wifi-phy.cc:761
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition wifi-phy.cc:1557
Class that keeps track of all information about the current PHY operating channel.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
MHz_u GetChannelWidth() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:439
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
WifiPpduField
The type of PPDU field (grouped for convenience)
@ WIFI_PPDU_TYPE_DL_MU
@ WIFI_PPDU_TYPE_UL_MU
@ WIFI_PPDU_FIELD_DATA
data field
Definition first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< WifiSpectrumBandInfo, Watt_u > RxPowerWattPerChannelBand
A map of the received power for each band.
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:45
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::map< WifiPpduField, PhyHeaderChunkInfo > PhyHeaderSections
A map of PhyHeaderChunkInfo elements per PPDU field.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
@ WIFI_MAC_QOSDATA
Hz_u MHzToHz(MHz_u val)
Convert from MHz to Hz.
Definition wifi-utils.h:113
double Watt_u
Watt weak type.
Definition wifi-units.h:25
STL namespace.
Declaration of:
Struct defining a frequency range between minFrequency and maxFrequency.
A struct for both SNR and PER.
WifiSpectrumBandInfo structure containing info about a spectrum band.
std::vector< WifiSpectrumBandFrequencies > frequencies
the start and stop frequencies for each segment of the band