29#include "ns3/he-ppdu.h"
31#include "ns3/packet.h"
32#include "ns3/simulator.h"
51 m_endTime(m_startTime + duration),
52 m_rxPowerW(
std::move(rxPower))
88 [](
const auto& p1,
const auto& p2) { return p1.second < p2.second; });
113 auto band = currentRxPowerW.first;
114 auto it = rxPower.find(band);
115 if (it != rxPower.end())
117 currentRxPowerW.second += it->second;
131 os <<
"start=" <<
event.GetStartTime() <<
", end=" <<
event.GetEndTime()
132 <<
", power=" <<
event.GetRxPowerW() <<
"W"
133 <<
", PPDU=" <<
event.GetPpdu();
192 .SetGroupName(
"Wifi")
215 bool isStartHePortionRxing)
217 Ptr<Event> event = Create<Event>(ppdu, duration, std::move(rxPowerW));
218 AppendEvent(event, freqRange, isStartHePortionRxing);
232 Ptr<WifiPpdu> fakePpdu = Create<WifiPpdu>(Create<WifiPsdu>(Create<Packet>(0), hdr),
235 Add(fakePpdu, duration, rxPowerW, freqRange);
257 auto result =
m_niChanges.insert({band, niChanges});
276 const auto frequencies = it->first.frequencies;
278 std::find_if(bands.cbegin(), bands.cend(), [frequencies](
const auto& item) {
279 return frequencies == item.frequencies;
280 }) != std::end(bands);
293 for (
const auto& band : bands)
336 for (; i != niIt->second.end(); ++i)
338 double noiseInterferenceW = i->second.GetPower();
340 if (noiseInterferenceW < energyW)
351 bool isStartHePortionRxing)
354 for (
const auto& [band, power] : event->GetRxPowerWPerBand())
358 double previousPowerStart = 0;
359 double previousPowerEnd = 0;
361 previousPowerStart = previousPowerPosition->second.GetPower();
363 if (
const auto rxing = (
m_rxing.contains(freqRange) &&
m_rxing.at(freqRange)); !rxing)
367 niIt->second.erase(++(niIt->second.begin()), ++previousPowerPosition);
369 else if (isStartHePortionRxing)
379 for (
auto i =
first; i != last; ++i)
381 i->second.AddPower(power);
391 for (
const auto& [band, power] : rxPower)
397 for (
auto i =
first; i != last; ++i)
399 i->second.AddPower(power);
402 event->UpdateRxPowerW(rxPower);
407 double noiseInterference,
408 uint16_t channelWidth,
411 NS_LOG_FUNCTION(
this << signal << noiseInterference << channelWidth << +nss);
413 static const double BOLTZMANN = 1.3803e-23;
415 double Nt = BOLTZMANN * 290 * channelWidth * 1e6;
418 double noise = noiseFloor + noiseInterference;
419 double snr = signal / noise;
420 NS_LOG_DEBUG(
"bandwidth=" << channelWidth <<
"MHz, signal=" << signal <<
"W, noise="
421 << noiseFloor <<
"W, interference=" << noiseInterference
431 NS_LOG_DEBUG(
"SNR improvement thanks to diversity: " << 10 * std::log10(gain) <<
"dB");
445 double noiseInterferenceW = firstPower_it->second;
449 auto it = niIt->second.find(event->GetStartTime());
453 for (; it != niIt->second.end() && it->first < now; ++it)
456 (
event != it->second.GetEvent()))
462 noiseInterferenceW = it->second.GetPower() -
event->GetRxPowerW(band) - muMimoPowerW;
463 if (std::abs(noiseInterferenceW) < std::numeric_limits<double>::epsilon())
466 noiseInterferenceW = 0.0;
469 it = niIt->second.find(event->GetStartTime());
471 for (; it != niIt->second.end() && it->second.GetEvent() != event; ++it)
476 ni.emplace(event->GetStartTime(),
NiChange(0, event));
477 while (++it != niIt->second.end() && it->second.GetEvent() != event)
481 ni.emplace(event->GetEndTime(),
NiChange(0, event));
482 nis.insert({band, ni});
484 "CalculateNoiseInterferenceW returns negative value " << noiseInterferenceW);
485 return noiseInterferenceW;
494 auto it = niIt->second.begin();
496 double muMimoPowerW = 0.0;
497 for (; it != niIt->second.end() && it->first <
Simulator::Now(); ++it)
501 auto hePpdu = DynamicCast<HePpdu>(it->second.GetEvent()->GetPpdu()->Copy());
507 event->GetPpdu()->GetTxVector().GetHeMuUserInfoMap().cbegin()->first;
508 const auto otherStaId = it->second.GetEvent()
511 .GetHeMuUserInfoMap()
514 if (staId == otherStaId)
518 muMimoPowerW += it->second.GetEvent()->GetRxPowerW(band);
537 auto nbits =
static_cast<uint64_t
>(rate * duration.
GetSeconds());
547 uint16_t staId)
const
555 auto nbits =
static_cast<uint64_t
>(rate * duration.
GetSeconds());
556 nbits /= txVector.
GetNss(staId);
570 uint16_t channelWidth,
574 std::pair<Time, Time> window)
const
576 NS_LOG_FUNCTION(
this << channelWidth << band << staId << window.first << window.second);
578 const auto& niIt = nis->find(band)->second;
579 auto j = niIt.cbegin();
580 Time previous = j->first;
581 double muMimoPowerW = 0.0;
582 WifiMode payloadMode =
event->GetPpdu()->GetTxVector().GetMode(staId);
583 Time phyPayloadStart = j->first;
585 event->GetPpdu()->GetType() !=
589 event->GetPpdu()->GetTxVector());
595 Time windowStart = phyPayloadStart + window.first;
596 Time windowEnd = phyPayloadStart + window.second;
599 double powerW =
event->GetRxPowerW(band);
600 while (++j != niIt.cend())
602 Time current = j->first;
603 NS_LOG_DEBUG(
"previous= " << previous <<
", current=" << current);
608 event->GetPpdu()->GetTxVector().GetNss(staId));
610 if (previous >= windowStart)
613 Min(windowEnd, current) - previous,
614 event->GetPpdu()->GetTxVector(),
616 NS_LOG_DEBUG(
"Both previous and current point to the windowed payload: mode="
617 << payloadMode <<
", psr=" << psr);
620 else if (current >= windowStart)
623 Min(windowEnd, current) - windowStart,
624 event->GetPpdu()->GetTxVector(),
627 "previous is before windowed payload and current is in the windowed payload: mode="
628 << payloadMode <<
", psr=" << psr);
630 noiseInterferenceW = j->second.GetPower() - powerW;
633 muMimoPowerW += j->second.GetEvent()->GetRxPowerW(band);
635 "PPDU belongs to same MU-MIMO transmission: muMimoPowerW=" << muMimoPowerW);
637 noiseInterferenceW -= muMimoPowerW;
639 if (previous > windowEnd)
642 <<
" after time window end=" << windowEnd);
646 double per = 1 - psr;
654 uint16_t channelWidth,
660 auto niIt = nis->find(band)->second;
661 auto j = niIt.begin();
665 for (
const auto& section : phyHeaderSections)
667 stopLastSection =
Max(stopLastSection, section.second.first.second);
670 Time previous = j->first;
673 double powerW =
event->GetRxPowerW(band);
674 while (++j != niIt.end())
676 Time current = j->first;
677 NS_LOG_DEBUG(
"previous= " << previous <<
", current=" << current);
679 double snr =
CalculateSnr(powerW, noiseInterferenceW, channelWidth, 1);
680 for (
const auto& section : phyHeaderSections)
682 Time start = section.second.first.first;
683 Time stop = section.second.first.second;
685 if (previous <= stop || current >= start)
687 Time duration =
Min(stop, current) -
Max(start, previous);
692 section.second.second,
693 event->GetPpdu()->GetTxVector(),
696 << section.first <<
" [" << start <<
", " << stop <<
"] for "
697 << duration.
As(
Time::NS) <<
": mode=" << section.second.second
702 noiseInterferenceW = j->second.GetPower() - powerW;
704 if (previous > stopLastSection)
706 NS_LOG_DEBUG(
"Stop: new previous=" << previous <<
" after stop of last section="
717 uint16_t channelWidth,
722 auto niIt = nis->find(band)->second;
727 for (
const auto& section :
728 phyEntity->GetPhyHeaderSections(event->GetPpdu()->GetTxVector(), niIt.begin()->first))
730 if (section.first == header)
732 sections[header] = section.second;
737 if (!sections.empty())
746 uint16_t channelWidth,
749 std::pair<Time, Time> relativeMpduStartStop)
const
751 NS_LOG_FUNCTION(
this << channelWidth << band << staId << relativeMpduStartStop.first
752 << relativeMpduStartStop.second);
758 event->GetPpdu()->GetTxVector().GetNss(staId));
763 double per =
CalculatePayloadPer(event, channelWidth, &ni, band, staId, relativeMpduStartStop);
770 uint16_t channelWidth,
776 double snr =
CalculateSnr(event->GetRxPowerW(band), noiseInterferenceW, channelWidth, nss);
782 uint16_t channelWidth,
789 double snr =
CalculateSnr(event->GetRxPowerW(band), noiseInterferenceW, channelWidth, 1);
799InterferenceHelper::NiChanges::iterator
802 return niIt->second.upper_bound(moment);
805InterferenceHelper::NiChanges::iterator
815InterferenceHelper::NiChanges::iterator
818 return niIt->second.insert(
GetNextPosition(moment, niIt), {moment, change});
843 m_firstPowers.find(niIt->first)->second = it->second.GetPower();
861 (currentEvent->GetPpdu()->GetUid() == otherEvent->GetPpdu()->GetUid()))
863 const auto currentTxVector = currentEvent->GetPpdu()->GetTxVector();
864 const auto otherTxVector = otherEvent->GetPpdu()->GetTxVector();
865 NS_ASSERT(currentTxVector.GetHeMuUserInfoMap().size() == 1);
866 NS_ASSERT(otherTxVector.GetHeMuUserInfoMap().size() == 1);
867 const auto currentUserInfo = currentTxVector.GetHeMuUserInfoMap().cbegin();
868 const auto otherUserInfo = otherTxVector.GetHeMuUserInfoMap().cbegin();
869 return (currentUserInfo->second.ru == otherUserInfo->second.ru);
handles interference calculations
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.
double GetRxPowerW() const
Return the total received power (W).
RxPowerWattPerChannelBand m_rxPowerW
received power in watts per band
const RxPowerWattPerChannelBand & GetRxPowerWPerBand() const
Return the received power (W) for all bands.
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...
@ PSD_HE_PORTION
HE portion of an HE PPDU.
Noise and Interference (thus Ni) event.
void AddPower(double power)
Add a given amount of power.
NiChange(double power, Ptr< Event > event)
Create a NiChange at the given time and the amount of NI change.
double GetPower() const
Return the power.
Ptr< Event > GetEvent() const
Return the event causes the corresponding NI change.
handles interference calculations
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.
double 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...
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
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
NiChanges::iterator GetNextPosition(Time moment, NiChangesPerBand::iterator niIt)
Returns an iterator to the first NiChange that is later than moment.
FirstPowerPerBand m_firstPowers
first power of each band in watts
Time GetEnergyDuration(double energyW, const WifiSpectrumBandInfo &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.
double CalculatePayloadPer(Ptr< const Event > event, uint16_t 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...
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.
double CalculateNoiseInterferenceW(Ptr< Event > event, NiChangesPerBand &nis, const WifiSpectrumBandInfo &band) const
Calculate noise and interference power in W.
double CalculatePhyHeaderPer(Ptr< const Event > event, NiChangesPerBand *nis, uint16_t channelWidth, const WifiSpectrumBandInfo &band, WifiPpduField header) const
Calculate the error rate of the PHY header.
NiChanges::iterator GetPreviousPosition(Time moment, NiChangesPerBand::iterator niIt)
Returns an iterator to the last NiChange that is before than moment.
void AppendEvent(Ptr< Event > event, const FrequencyRange &freqRange, bool isStartHePortionRxing)
Append the given Event.
double CalculateSnr(Ptr< Event > event, uint16_t channelWidth, uint8_t nss, const WifiSpectrumBandInfo &band) const
Calculate the SNIR for the event (starting from now until the event end).
PhyEntity::SnrPer CalculatePhyHeaderSnrPer(Ptr< Event > event, uint16_t 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.
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 NotifyRxEnd(Time endTime, const FrequencyRange &freqRange)
Notify that RX has ended.
double CalculatePhyHeaderSectionPsr(Ptr< const Event > event, NiChangesPerBand *nis, uint16_t channelWidth, const WifiSpectrumBandInfo &band, PhyEntity::PhyHeaderSections phyHeaderSections) const
Calculate the success rate of the PHY header sections for the provided event.
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
PhyEntity::SnrPer CalculatePayloadSnrPer(Ptr< Event > event, uint16_t 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...
~InterferenceHelper() override
A base class which provides memory management and object aggregation.
std::map< WifiPpduField, PhyHeaderChunkInfo > PhyHeaderSections
A map of PhyHeaderChunkInfo elements per PPDU field.
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
bool IsZero() const
Exactly equivalent to t == 0.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
represent a single transmission mode
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
static const Ptr< const PhyEntity > GetStaticPhyEntity(WifiModulationClass modulation)
Get the implemented PHY entity corresponding to the modulation class.
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
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.
uint16_t GetChannelWidth() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
WifiPpduField
The type of PPDU field (grouped for convenience)
@ WIFI_PPDU_FIELD_DATA
data field
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double RatioToDb(double ratio)
Convert from ratio to dB.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::map< WifiSpectrumBandInfo, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Struct defining a frequency range between minFrequency (MHz) and maxFrequency (MHz).
uint16_t maxFrequency
the maximum frequency in MHz
uint16_t minFrequency
the minimum frequency in MHz
A struct for both SNR and PER.
WifiSpectrumBandInfo structure containing info about a spectrum band.
WifiSpectrumBandFrequencies frequencies
the start and stop frequencies of the band