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
52const Time&
54{
55 return m_startTime;
56}
57
58const Time&
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 const 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 m_bandStates.clear();
187 m_errorRateModel = nullptr;
188}
189
192 Time duration,
194 const FrequencyRange& freqRange,
195 bool isStartHePortionRxing)
196{
197 Ptr<Event> event = Create<Event>(ppdu, duration, std::move(rxPowerW));
198 AppendEvent(event, freqRange, isStartHePortionRxing);
199 return event;
200}
201
202void
205 const FrequencyRange& freqRange)
206{
207 // Parameters other than duration and rxPowerW are unused for this type
208 // of signal, so we provide dummy versions
209 WifiMacHeader hdr;
211 hdr.SetQosTid(0);
213 WifiTxVector(),
215 Add(fakePpdu, duration, rxPowerW, freqRange);
216}
217
218bool
220{
221 return !m_bandStates.empty();
222}
223
224bool
226{
227 return m_bandStates.contains(band);
228}
229
230void
232{
233 NS_LOG_FUNCTION(this << band);
234 NS_ASSERT(!m_bandStates.contains(band));
235 auto result = m_bandStates.emplace(band, BandState{});
236 NS_ASSERT(result.second);
237 // Always have a zero power noise event in the list
238 AddNiChangeEvent(Time(0), NiChange(Watt_u{0}, nullptr), result.first);
239}
240
241void
243{
244 NS_LOG_FUNCTION(this << band);
245 auto it = m_bandStates.find(band);
246 NS_ASSERT(it != std::end(m_bandStates));
247 m_bandStates.erase(it);
248}
249
250void
251InterferenceHelper::UpdateBands(const std::vector<WifiSpectrumBandInfo>& bands,
252 const FrequencyRange& freqRange)
253{
254 NS_LOG_FUNCTION(this << freqRange);
255 std::vector<WifiSpectrumBandInfo> bandsToRemove{};
256 for (auto it = m_bandStates.begin(); it != m_bandStates.end(); ++it)
257 {
258 if (!IsBandInFrequencyRange(it->first, freqRange))
259 {
260 continue;
261 }
262 const auto& frequencies = it->first.frequencies;
263 const auto found =
264 std::find_if(bands.cbegin(), bands.cend(), [&frequencies](const auto& item) {
265 return frequencies == item.frequencies;
266 }) != std::end(bands);
267 if (!found)
269 // band does not belong to the new bands, erase it
270 bandsToRemove.emplace_back(it->first);
271 }
272 }
273 for (const auto& band : bandsToRemove)
274 {
275 RemoveBand(band);
276 }
277 for (const auto& band : bands)
278 {
279 if (!HasBand(band))
280 {
281 // this is a new band, add it
282 AddBand(band);
283 }
284 }
285}
286
287void
289{
290 m_noiseFigure = value;
291}
292
293void
298
304
305void
310
311Time
313{
314 NS_LOG_FUNCTION(this << energy << band);
315 Time now = Simulator::Now();
316 auto bandIt = m_bandStates.find(band);
317 NS_ABORT_IF(bandIt == m_bandStates.end());
318 auto& niChanges = bandIt->second.niChanges;
319 auto i = GetPreviousPosition(now, bandIt);
320 Time end = i->first;
321 for (; i != niChanges.end(); ++i)
323 const auto noiseInterference = i->second.GetPower();
324 end = i->first;
325 if (noiseInterference < energy)
326 {
327 break;
328 }
329 }
330 return end > now ? end - now : Time{0};
331}
332
333void
335 const FrequencyRange& freqRange,
336 bool isStartHePortionRxing)
337{
338 NS_LOG_FUNCTION(this << event << freqRange << isStartHePortionRxing);
339 for (const auto& [band, power] : event->GetRxPowerPerBand())
340 {
341 auto bandIt = m_bandStates.find(band);
342 NS_ABORT_IF(bandIt == m_bandStates.end());
343 auto& niChanges = bandIt->second.niChanges;
344 Watt_u previousPowerStart{0.0};
345 Watt_u previousPowerEnd{0.0};
346 auto previousPowerPosition = GetPreviousPosition(event->GetStartTime(), bandIt);
347 previousPowerStart = previousPowerPosition->second.GetPower();
348 previousPowerEnd = GetPreviousPosition(event->GetEndTime(), bandIt)->second.GetPower();
349 if (const auto rxing = (m_rxing.contains(freqRange) && m_rxing.at(freqRange)); !rxing)
350 {
351 bandIt->second.firstPower = previousPowerStart;
352 // Always leave the first zero power noise event in the list
353 niChanges.erase(++(niChanges.begin()), ++previousPowerPosition);
354 }
355 else if (isStartHePortionRxing)
356 {
357 // When the first HE portion is received, we need to set the band's first power
358 // so that it takes into account interferences that arrived between the start of the
359 // HE TB PPDU transmission and the start of HE TB payload.
360 bandIt->second.firstPower = previousPowerStart;
361 }
362 // With NiChanges backed by a sorted vector, a second insert may invalidate the
363 // iterator returned by the first. Capture both insert positions as indices --
364 // since GetStartTime() <= GetEndTime(), the second insert lands at an index
365 // >= the first, so the first index remains stable across the second insert.
366 const auto firstIt =
367 AddNiChangeEvent(event->GetStartTime(), NiChange(previousPowerStart, event), bandIt);
368 const auto firstIdx = std::distance(niChanges.begin(), firstIt);
369 const auto lastIt =
370 AddNiChangeEvent(event->GetEndTime(), NiChange(previousPowerEnd, event), bandIt);
371 const auto lastIdx = std::distance(niChanges.begin(), lastIt);
372 for (auto i = firstIdx; i != lastIdx; ++i)
373 {
374 niChanges.at(i).second.AddPower(power);
375 }
376 }
377}
378
379void
381{
382 NS_LOG_FUNCTION(this << event);
383 // This is called for UL MU events, in order to scale power as long as UL MU PPDUs arrive
384 for (const auto& [band, power] : rxPower)
385 {
386 auto bandIt = m_bandStates.find(band);
387 NS_ABORT_IF(bandIt == m_bandStates.end());
388 auto first = GetPreviousPosition(event->GetStartTime(), bandIt);
389 auto last = GetPreviousPosition(event->GetEndTime(), bandIt);
390 for (auto i = first; i != last; ++i)
391 {
392 i->second.AddPower(power);
393 }
394 }
395 event->UpdateRxPowerW(rxPower);
396}
397
398double
400 Watt_u noiseInterference,
401 MHz_u channelWidth,
402 uint8_t nss) const
403{
404 NS_LOG_FUNCTION(this << signal << noiseInterference << channelWidth << +nss);
405 // thermal noise at 290K in J/s = W
406 static const double BOLTZMANN = 1.3803e-23;
407 // Nt is the power of thermal noise in W
408 const auto Nt = BOLTZMANN * 290 * MHzToHz(channelWidth);
409 // receiver noise Floor which accounts for thermal noise and non-idealities of the receiver
410 Watt_u noiseFloor{m_noiseFigure * Nt};
411 Watt_u noise = noiseFloor + noiseInterference;
412 auto snr = signal / noise; // linear scale
413 NS_LOG_DEBUG("bandwidth=" << channelWidth << "MHz, signal=" << signal << "W, noise="
414 << noiseFloor << "W, interference=" << noiseInterference
415 << "W, snr=" << RatioToDb(snr) << "dB");
416 if (m_errorRateModel->IsAwgn())
417 {
418 double gain = 1;
419 if (m_numRxAntennas > nss)
420 {
421 gain = static_cast<double>(m_numRxAntennas) /
422 nss; // compute gain offered by diversity for AWGN
423 }
424 NS_LOG_DEBUG("SNR improvement thanks to diversity: " << 10 * std::log10(gain) << "dB");
425 snr *= gain;
426 }
427 return snr;
428}
429
430Watt_u
432 NiChanges& ni,
433 const WifiSpectrumBandInfo& band) const
434{
435 NS_LOG_FUNCTION(this << band);
436 auto bandIt = m_bandStates.find(band);
437 NS_ABORT_IF(bandIt == m_bandStates.end());
438 auto& niChanges = bandIt->second.niChanges;
439 auto noiseInterference = bandIt->second.firstPower;
440 const auto now = Simulator::Now();
441 const auto eventRxPower = event->GetRxPower(band);
442 auto it = niChanges.lower_bound(event->GetStartTime());
443 const auto muMimoPower = (event->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU)
444 ? CalculateMuMimoPowerW(event, band)
445 : Watt_u{0.0};
446 for (; it != niChanges.end() && it->first < now; ++it)
447 {
448 if (IsSameMuMimoTransmission(event, it->second.GetEvent()) &&
449 (event != it->second.GetEvent()))
450 {
451 // Do not calculate noiseInterferenceW if events belong to the same MU-MIMO transmission
452 // unless this is the same event
453 continue;
454 }
455 noiseInterference = it->second.GetPower() - eventRxPower - muMimoPower;
456 if (std::abs(noiseInterference) < std::numeric_limits<double>::epsilon())
457 {
458 // fix some possible rounding issues with double values
459 noiseInterference = Watt_u{0.0};
460 }
461 }
462 it = niChanges.lower_bound(event->GetStartTime());
463 NS_ABORT_IF(it == niChanges.end());
464 for (; it != niChanges.end() && it->second.GetEvent() != event; ++it)
465 {
466 ;
467 }
468 ni.emplace(event->GetStartTime(), NiChange(Watt_u{0}, event));
469 while (++it != niChanges.end() && it->second.GetEvent() != event)
470 {
471 ni.insert(*it);
472 }
473 ni.emplace(event->GetEndTime(), NiChange(Watt_u{0}, event));
474 NS_ASSERT_MSG(noiseInterference >= Watt_u{0.0},
475 "CalculateNoiseInterferenceW returns negative value " << noiseInterference);
476 return noiseInterference;
477}
478
479Watt_u
481 const WifiSpectrumBandInfo& band) const
482{
483 auto bandIt = m_bandStates.find(band);
484 NS_ASSERT(bandIt != m_bandStates.end());
485 const auto& niChanges = bandIt->second.niChanges;
486 auto it = niChanges.begin();
487 ++it;
488 Watt_u muMimoPower{0.0};
489 for (; it != niChanges.end() && it->first < Simulator::Now(); ++it)
490 {
491 if (IsSameMuMimoTransmission(event, it->second.GetEvent()))
492 {
493 auto hePpdu = DynamicCast<HePpdu>(it->second.GetEvent()->GetPpdu()->Copy());
494 NS_ASSERT(hePpdu);
495 HePpdu::TxPsdFlag psdFlag = hePpdu->GetTxPsdFlag();
496 if (psdFlag == HePpdu::PSD_HE_PORTION)
497 {
498 const auto staId =
499 event->GetPpdu()->GetTxVector().GetHeMuUserInfoMap().cbegin()->first;
500 const auto otherStaId = it->second.GetEvent()
501 ->GetPpdu()
502 ->GetTxVector()
503 .GetHeMuUserInfoMap()
504 .cbegin()
505 ->first;
506 if (staId == otherStaId)
507 {
508 break;
509 }
510 muMimoPower += it->second.GetEvent()->GetRxPower(band);
511 }
512 }
513 }
514 return muMimoPower;
515}
516
517double
519 Time duration,
520 WifiMode mode,
521 const WifiTxVector& txVector,
522 WifiPpduField field) const
523{
524 if (duration.IsZero())
525 {
526 return 1.0;
527 }
528 const auto rate = mode.GetDataRate(txVector.GetChannelWidth());
529 auto nbits = static_cast<uint64_t>(rate * duration.GetSeconds());
530 const auto csr =
531 m_errorRateModel->GetChunkSuccessRate(mode, txVector, snir, nbits, m_numRxAntennas, field);
532 return csr;
533}
534
535double
537 Time duration,
538 const WifiTxVector& txVector,
539 uint16_t staId) const
540{
541 if (duration.IsZero())
542 {
543 return 1.0;
544 }
545 const auto mode = txVector.GetMode(staId);
546 const auto rate = mode.GetDataRate(txVector, staId);
547 auto nbits = static_cast<uint64_t>(rate * duration.GetSeconds());
548 nbits /= txVector.GetNss(staId); // divide effective number of bits by NSS to achieve same chunk
549 // error rate as SISO for AWGN
550 double csr = m_errorRateModel->GetChunkSuccessRate(mode,
551 txVector,
552 snir,
553 nbits,
556 staId);
557 return csr;
558}
559
560double
562 MHz_u channelWidth,
563 const NiChanges& ni,
564 const WifiSpectrumBandInfo& band,
565 uint16_t staId,
566 std::pair<Time, Time> window) const
567{
568 NS_LOG_FUNCTION(this << channelWidth << band << staId << window.first << window.second);
569 double psr = 1.0; /* Packet Success Rate */
570 auto j = ni.cbegin();
571 auto previous = j->first;
572 Watt_u muMimoPower{0.0};
573 const auto payloadMode = event->GetPpdu()->GetTxVector().GetMode(staId);
574 auto phyPayloadStart = j->first;
575 if (event->GetPpdu()->GetType() != WIFI_PPDU_TYPE_UL_MU &&
576 event->GetPpdu()->GetType() !=
577 WIFI_PPDU_TYPE_DL_MU) // j->first corresponds to the start of the MU payload
578 {
579 phyPayloadStart = j->first + WifiPhy::CalculatePhyPreambleAndHeaderDuration(
580 event->GetPpdu()->GetTxVector());
581 }
582 else
583 {
584 muMimoPower = CalculateMuMimoPowerW(event, band);
585 }
586 const auto windowStart = phyPayloadStart + window.first;
587 const auto windowEnd = phyPayloadStart + window.second;
588 const auto bandIt = m_bandStates.find(band);
589 NS_ABORT_IF(bandIt == m_bandStates.end());
590 auto noiseInterference = bandIt->second.firstPower;
591 auto power = event->GetRxPower(band);
592 while (++j != ni.cend())
593 {
594 Time current = j->first;
595 NS_LOG_DEBUG("previous= " << previous << ", current=" << current);
596 NS_ASSERT(current >= previous);
597 const auto snr = CalculateSnr(power,
598 noiseInterference,
599 channelWidth,
600 event->GetPpdu()->GetTxVector().GetNss(staId));
601 // Case 1: Both previous and current point to the windowed payload
602 if (previous >= windowStart)
603 {
605 Min(windowEnd, current) - previous,
606 event->GetPpdu()->GetTxVector(),
607 staId);
608 NS_LOG_DEBUG("Both previous and current point to the windowed payload: mode="
609 << payloadMode << ", psr=" << psr);
610 }
611 // Case 2: previous is before windowed payload and current is in the windowed payload
612 else if (current >= windowStart)
613 {
615 Min(windowEnd, current) - windowStart,
616 event->GetPpdu()->GetTxVector(),
617 staId);
619 "previous is before windowed payload and current is in the windowed payload: mode="
620 << payloadMode << ", psr=" << psr);
621 }
622 noiseInterference = j->second.GetPower() - power;
623 if (IsSameMuMimoTransmission(event, j->second.GetEvent()))
624 {
625 muMimoPower += j->second.GetEvent()->GetRxPower(band);
626 NS_LOG_DEBUG("PPDU belongs to same MU-MIMO transmission: muMimoPowerW=" << muMimoPower);
627 }
628 noiseInterference -= muMimoPower;
629 previous = j->first;
630 if (previous > windowEnd)
631 {
632 NS_LOG_DEBUG("Stop: new previous=" << previous
633 << " after time window end=" << windowEnd);
634 break;
635 }
636 }
637 const auto per = 1.0 - psr;
638 return per;
639}
640
641double
643 const NiChanges& ni,
644 MHz_u channelWidth,
645 const WifiSpectrumBandInfo& band,
646 PhyHeaderSections phyHeaderSections) const
647{
648 NS_LOG_FUNCTION(this << band);
649 double psr = 1.0; /* Packet Success Rate */
650 auto j = ni.begin();
651
652 NS_ASSERT(!phyHeaderSections.empty());
653 Time stopLastSection;
654 for (const auto& section : phyHeaderSections)
655 {
656 stopLastSection = Max(stopLastSection, section.second.first.second);
657 }
658
659 auto previous = j->first;
660 const auto bandIt = m_bandStates.find(band);
661 NS_ABORT_IF(bandIt == m_bandStates.end());
662 auto noiseInterference = bandIt->second.firstPower;
663 const auto power = event->GetRxPower(band);
664 while (++j != ni.end())
665 {
666 auto current = j->first;
667 NS_LOG_DEBUG("previous= " << previous << ", current=" << current);
668 NS_ASSERT(current >= previous);
669 const auto snr = CalculateSnr(power, noiseInterference, channelWidth, 1);
670 for (const auto& section : phyHeaderSections)
671 {
672 const auto start = section.second.first.first;
673 const auto stop = section.second.first.second;
674
675 if (previous <= stop || current >= start)
676 {
677 const auto duration = Min(stop, current) - Max(start, previous);
678 if (duration.IsStrictlyPositive())
679 {
680 psr *= CalculateChunkSuccessRate(snr,
681 duration,
682 section.second.second,
683 event->GetPpdu()->GetTxVector(),
684 section.first);
685 NS_LOG_DEBUG("Current NI change in "
686 << section.first << " [" << start << ", " << stop << "] for "
687 << duration.As(Time::NS) << ": mode=" << section.second.second
688 << ", psr=" << psr);
689 }
690 }
691 }
692 noiseInterference = j->second.GetPower() - power;
693 previous = j->first;
694 if (previous > stopLastSection)
695 {
696 NS_LOG_DEBUG("Stop: new previous=" << previous << " after stop of last section="
697 << stopLastSection);
698 break;
699 }
700 }
701 return psr;
702}
703
704double
706 const NiChanges& ni,
707 MHz_u channelWidth,
708 const WifiSpectrumBandInfo& band,
709 WifiPpduField header) const
710{
711 NS_LOG_FUNCTION(this << band << header);
712 auto phyEntity =
713 WifiPhy::GetStaticPhyEntity(event->GetPpdu()->GetTxVector().GetModulationClass());
714
715 PhyHeaderSections sections;
716 for (const auto& section :
717 phyEntity->GetPhyHeaderSections(event->GetPpdu()->GetTxVector(), ni.begin()->first))
718 {
719 if (section.first == header)
720 {
721 sections[header] = section.second;
722 }
723 }
724
725 double psr = 1.0;
726 if (!sections.empty())
727 {
728 psr = CalculatePhyHeaderSectionPsr(event, ni, channelWidth, band, sections);
729 }
730 return 1 - psr;
731}
732
733SnrPer
735 MHz_u channelWidth,
736 const WifiSpectrumBandInfo& band,
737 uint16_t staId,
738 std::pair<Time, Time> relativeMpduStartStop) const
739{
740 NS_LOG_FUNCTION(this << channelWidth << band << staId << relativeMpduStartStop.first
741 << relativeMpduStartStop.second);
742 NiChanges ni;
743 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
744 const auto snr = CalculateSnr(event->GetRxPower(band),
745 noiseInterference,
746 channelWidth,
747 event->GetPpdu()->GetTxVector().GetNss(staId));
748
749 /* calculate the SNIR at the start of the MPDU (located through windowing) and accumulate
750 * all SNIR changes in the SNIR vector.
751 */
752 const auto per =
753 CalculatePayloadPer(event, channelWidth, ni, band, staId, relativeMpduStartStop);
754
755 return SnrPer{snr, per};
756}
757
758double
760 MHz_u channelWidth,
761 uint8_t nss,
762 const WifiSpectrumBandInfo& band) const
763{
764 NiChanges ni;
765 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
766 return CalculateSnr(event->GetRxPower(band), noiseInterference, channelWidth, nss);
767}
768
769SnrPer
771 MHz_u channelWidth,
772 const WifiSpectrumBandInfo& band,
773 WifiPpduField header) const
774{
775 NS_LOG_FUNCTION(this << band << header);
776 NiChanges ni;
777 const auto noiseInterference = CalculateNoiseInterferenceW(event, ni, band);
778 const auto snr = CalculateSnr(event->GetRxPower(band), noiseInterference, channelWidth, 1);
779
780 /* calculate the SNIR at the start of the PHY header and accumulate
781 * all SNIR changes in the SNIR vector.
782 */
783 const auto per = CalculatePhyHeaderPer(event, ni, channelWidth, band, header);
784
785 return SnrPer{snr, per};
786}
787
789InterferenceHelper::GetNextPosition(const Time& moment, BandStateMap::iterator bandIt) const
790{
791 return bandIt->second.niChanges.upper_bound(moment);
792}
793
795InterferenceHelper::GetPreviousPosition(const Time& moment, BandStateMap::iterator bandIt) const
796{
797 // This is safe since there is always an NiChange at time 0, before moment.
798 return std::prev(GetNextPosition(moment, bandIt));
799}
800
803 NiChange change,
804 BandStateMap::iterator bandIt)
805{
806 return bandIt->second.niChanges.insert(GetNextPosition(moment, bandIt), {moment, change});
807}
808
809void
811{
812 NS_LOG_FUNCTION(this << freqRange);
813 m_rxing[freqRange] = true;
814}
815
816void
818{
819 NS_LOG_FUNCTION(this << endTime << freqRange);
820 m_rxing.at(freqRange) = false;
821 // Update firstPower for frame capture on each tracked band in this frequency range
822 for (auto bandIt = m_bandStates.begin(); bandIt != m_bandStates.end(); ++bandIt)
823 {
824 if (!IsBandInFrequencyRange(bandIt->first, freqRange))
825 {
826 continue;
827 }
828 NS_ASSERT(bandIt->second.niChanges.size() > 1);
829 auto it = std::prev(GetPreviousPosition(endTime, bandIt));
830 bandIt->second.firstPower = it->second.GetPower();
831 }
832}
833
834bool
836 const FrequencyRange& freqRange) const
837{
838 return std::all_of(band.frequencies.cbegin(),
839 band.frequencies.cend(),
840 [&freqRange](const auto& freqs) {
841 return ((freqs.second > MHzToHz(freqRange.minFrequency)) &&
842 (freqs.first < MHzToHz(freqRange.maxFrequency)));
843 });
844}
845
846bool
848 Ptr<const Event> otherEvent) const
849{
850 if ((currentEvent->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU) &&
851 (otherEvent->GetPpdu()->GetType() == WIFI_PPDU_TYPE_UL_MU) &&
852 (currentEvent->GetPpdu()->GetUid() == otherEvent->GetPpdu()->GetUid()))
853 {
854 const auto currentTxVector = currentEvent->GetPpdu()->GetTxVector();
855 const auto otherTxVector = otherEvent->GetPpdu()->GetTxVector();
856 NS_ASSERT(currentTxVector.GetHeMuUserInfoMap().size() == 1);
857 NS_ASSERT(otherTxVector.GetHeMuUserInfoMap().size() == 1);
858 const auto currentUserInfo = currentTxVector.GetHeMuUserInfoMap().cbegin();
859 const auto otherUserInfo = otherTxVector.GetHeMuUserInfoMap().cbegin();
860 return (currentUserInfo->second.ru == otherUserInfo->second.ru);
861 }
862 return false;
863}
864
865} // namespace ns3
#define Max(a, b)
#define Min(a, b)
return result
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.
const 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.
const Time & GetStartTime() const
Return the start time of the signal.
RxPowerWattPerChannelBand m_rxPowerW
received power in watts per band
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:102
@ PSD_HE_PORTION
HE portion of an HE PPDU.
Definition he-ppdu.h:104
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.
Sorted-by-time list of NI changes for a single band.
iterator emplace(Args &&... args)
Construct a value_type from args and insert it at its sorted position.
std::vector< value_type >::iterator iterator
iterator type
iterator insert(const_iterator hint, value_type value)
Insert at a caller-provided position (typically the result of upper_bound(t)).
handles interference calculations
void SetNoiseFigure(double value)
Set the noise figure.
BandStateMap m_bandStates
Per-band interference state.
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.
void NotifyRxStart(const FrequencyRange &freqRange)
Notify that RX has started.
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.
double CalculatePhyHeaderPer(Ptr< const Event > event, const NiChanges &ni, MHz_u channelWidth, const WifiSpectrumBandInfo &band, WifiPpduField header) const
Calculate the error rate of the PHY header.
Time GetEnergyDuration(Watt_u energy, const WifiSpectrumBandInfo &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 CalculatePhyHeaderSectionPsr(Ptr< const Event > event, const NiChanges &ni, MHz_u channelWidth, const WifiSpectrumBandInfo &band, PhyHeaderSections phyHeaderSections) const
Calculate the success rate of the PHY header sections for the provided event.
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
Watt_u CalculateNoiseInterferenceW(Ptr< Event > event, NiChanges &ni, const WifiSpectrumBandInfo &band) const
Calculate noise and interference power.
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.
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.
double CalculatePayloadPer(Ptr< const Event > event, MHz_u channelWidth, const NiChanges &ni, 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...
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
NiChanges::iterator GetPreviousPosition(const Time &moment, BandStateMap::iterator bandIt) const
Returns an iterator to the last NiChange that is before than moment.
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 GetNextPosition(const Time &moment, BandStateMap::iterator bandIt) const
Returns an iterator to the first NiChange that is later than moment.
NiChanges::iterator AddNiChangeEvent(const Time &moment, NiChange change, BandStateMap::iterator bandIt)
Add NiChange to the list at the appropriate position and return the iterator of the new event.
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).
A base class which provides memory management and object aggregation.
Definition object.h:81
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Received power (W) per spectrum band.
iterator find(const WifiSpectrumBandInfo &band)
Map-like find by band.
Control the scheduling of simulation events.
Definition simulator.h:57
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
@ NS
nanosecond
Definition nstime.h:109
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:398
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:305
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
const_iterator cend() const
const_iterator cbegin() const
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:39
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:763
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition wifi-phy.cc:1567
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:76
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#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:492
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:288
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::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:643
@ WIFI_MAC_QOSDATA
Hz_u MHzToHz(MHz_u val)
Convert from MHz to Hz.
Definition wifi-utils.h:122
double Watt_u
Watt weak type.
Definition wifi-units.h:25
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:45
STL namespace.
Declaration of:
Struct defining a frequency range between minFrequency (MHz) and maxFrequency (MHz).
Definition wifi-types.h:94
Per-band interference state: the NI changes timeline together with the noise+interference power captu...
A struct for both SNR and PER.
WifiSpectrumBandInfo structure containing info about a spectrum band.
WifiBandSegments< WifiSpectrumBandFrequencies, WIFI_SPECTRUM_BAND_MAX_SEGMENTS > frequencies
Start and stop frequencies per segment of the band.