29 #include "ns3/packet.h"
30 #include "ns3/simulator.h"
53 m_endTime(m_startTime + duration),
54 m_rxPowerW(std::move(rxPower))
93 auto it = std::max_element(
96 [](
const std::pair<WifiSpectrumBand, double>& p1,
97 const std::pair<WifiSpectrumBand, double>& p2) { return p1.second < p2.second; });
128 auto band = currentRxPowerW.first;
129 auto it = rxPower.find(band);
130 if (it != rxPower.end())
132 currentRxPowerW.second += it->second;
140 os <<
"start=" <<
event.GetStartTime() <<
", end=" <<
event.GetEndTime()
141 <<
", TXVECTOR=" <<
event.GetTxVector() <<
", power=" <<
event.GetRxPowerW() <<
"W"
142 <<
", PPDU=" <<
event.GetPpdu();
202 .SetGroupName(
"Wifi")
220 bool isStartOfdmaRxing)
222 Ptr<Event> event = Create<Event>(ppdu, txVector, duration, std::move(rxPowerW));
236 Create<WifiPpdu>(Create<WifiPsdu>(Create<Packet>(0), hdr),
WifiTxVector(), 0);
297 for (; i != niIt->second.end(); ++i)
299 double noiseInterferenceW = i->second.GetPower();
301 if (noiseInterferenceW < energyW)
313 for (
const auto& it : event->GetRxPowerWPerBand())
318 double previousPowerStart = 0;
319 double previousPowerEnd = 0;
321 previousPowerStart = previousPowerPosition->second.GetPower();
327 niIt->second.erase(++(niIt->second.begin()), ++previousPowerPosition);
329 else if (isStartOfdmaRxing)
339 for (
auto i =
first; i != last; ++i)
341 i->second.AddPower(it.second);
351 for (
const auto& it : rxPower)
358 for (
auto i =
first; i != last; ++i)
360 i->second.AddPower(it.second);
363 event->UpdateRxPowerW(rxPower);
368 double noiseInterference,
369 uint16_t channelWidth,
372 NS_LOG_FUNCTION(
this << signal << noiseInterference << channelWidth << +nss);
374 static const double BOLTZMANN = 1.3803e-23;
376 double Nt = BOLTZMANN * 290 * channelWidth * 1e6;
379 double noise = noiseFloor + noiseInterference;
380 double snr = signal / noise;
381 NS_LOG_DEBUG(
"bandwidth(MHz)=" << channelWidth <<
", signal(W)= " << signal <<
", noise(W)="
382 << noiseFloor <<
", interference(W)=" << noiseInterference
392 NS_LOG_DEBUG(
"SNR improvement thanks to diversity: " << 10 * std::log10(gain) <<
"dB");
406 double noiseInterferenceW = firstPower_it->second;
409 auto it = niIt->second.find(event->GetStartTime());
410 for (; it != niIt->second.end() && it->first <
Simulator::Now(); ++it)
412 noiseInterferenceW = it->second.GetPower() -
event->GetRxPowerW(band);
414 it = niIt->second.find(event->GetStartTime());
416 for (; it != niIt->second.end() && it->second.GetEvent() != event; ++it)
421 ni.emplace(event->GetStartTime(),
NiChange(0, event));
422 while (++it != niIt->second.end() && it->second.GetEvent() != event)
426 ni.emplace(event->GetEndTime(),
NiChange(0, event));
427 nis->insert({band, ni});
429 "CalculateNoiseInterferenceW returns negative value " << noiseInterferenceW);
430 return noiseInterferenceW;
445 uint64_t nbits =
static_cast<uint64_t
>(rate * duration.
GetSeconds());
455 uint16_t staId)
const
463 uint64_t nbits =
static_cast<uint64_t
>(rate * duration.
GetSeconds());
464 nbits /= txVector.
GetNss(staId);
478 uint16_t channelWidth,
482 std::pair<Time, Time>
window)
const
487 const auto& niIt = nis->find(band)->second;
488 auto j = niIt.cbegin();
489 Time previous = j->first;
490 WifiMode payloadMode =
event->GetTxVector().GetMode(staId);
491 Time phyPayloadStart = j->first;
493 event->GetPpdu()->GetType() !=
499 Time windowStart = phyPayloadStart +
window.first;
500 Time windowEnd = phyPayloadStart +
window.second;
502 double powerW =
event->GetRxPowerW(band);
503 while (++j != niIt.cend())
505 Time current = j->first;
506 NS_LOG_DEBUG(
"previous= " << previous <<
", current=" << current);
511 event->GetTxVector().GetNss(staId));
513 if (previous >= windowStart)
516 Min(windowEnd, current) - previous,
517 event->GetTxVector(),
519 NS_LOG_DEBUG(
"Both previous and current point to the windowed payload: mode="
520 << payloadMode <<
", psr=" << psr);
523 else if (current >= windowStart)
526 Min(windowEnd, current) - windowStart,
527 event->GetTxVector(),
530 "previous is before windowed payload and current is in the windowed payload: mode="
531 << payloadMode <<
", psr=" << psr);
533 noiseInterferenceW = j->second.GetPower() - powerW;
535 if (previous > windowEnd)
538 <<
" after time window end=" << windowEnd);
542 double per = 1 - psr;
550 uint16_t channelWidth,
556 auto niIt = nis->find(band)->second;
557 auto j = niIt.begin();
561 for (
const auto& section : phyHeaderSections)
563 stopLastSection =
Max(stopLastSection, section.second.first.second);
566 Time previous = j->first;
568 double powerW =
event->GetRxPowerW(band);
569 while (++j != niIt.end())
571 Time current = j->first;
572 NS_LOG_DEBUG(
"previous= " << previous <<
", current=" << current);
574 double snr =
CalculateSnr(powerW, noiseInterferenceW, channelWidth, 1);
575 for (
const auto& section : phyHeaderSections)
578 Time stop = section.second.first.second;
580 if (previous <= stop || current >=
start)
587 section.second.second,
588 event->GetTxVector(),
591 << section.first <<
" [" <<
start <<
", " <<
stop <<
"] for "
592 << duration.
As(
Time::NS) <<
": mode=" << section.second.second
597 noiseInterferenceW = j->second.GetPower() - powerW;
599 if (previous > stopLastSection)
601 NS_LOG_DEBUG(
"Stop: new previous=" << previous <<
" after stop of last section="
612 uint16_t channelWidth,
617 auto niIt = nis->find(band)->second;
621 for (
const auto& section :
622 phyEntity->GetPhyHeaderSections(event->GetTxVector(), niIt.begin()->first))
624 if (section.first == header)
626 sections[header] = section.second;
631 if (!sections.empty())
640 uint16_t channelWidth,
641 WifiSpectrumBand band,
643 std::pair<Time, Time> relativeMpduStartStop) const
645 NS_LOG_FUNCTION(
this << channelWidth << band.first << band.second << staId
646 << relativeMpduStartStop.first << relativeMpduStartStop.second);
648 double noiseInterferenceW = CalculateNoiseInterferenceW(event, &ni, band);
649 double snr = CalculateSnr(event->GetRxPowerW(band),
652 event->GetTxVector().GetNss(staId));
657 double per = CalculatePayloadPer(event, channelWidth, &ni, band, staId, relativeMpduStartStop);
664 uint16_t channelWidth,
670 double snr =
CalculateSnr(event->GetRxPowerW(band), noiseInterferenceW, channelWidth, nss);
676 uint16_t channelWidth,
677 WifiSpectrumBand band,
678 WifiPpduField header) const
682 double noiseInterferenceW = CalculateNoiseInterferenceW(event, &ni, band);
683 double snr = CalculateSnr(event->GetRxPowerW(band), noiseInterferenceW, channelWidth, 1);
688 double per = CalculatePhyHeaderPer(event, &ni, channelWidth, band, header);
698 niIt->second.clear();
706 InterferenceHelper::NiChanges::iterator
709 return niIt->second.upper_bound(moment);
712 InterferenceHelper::NiChanges::iterator
722 InterferenceHelper::NiChanges::iterator
725 return niIt->second.insert(
GetNextPosition(moment, niIt), std::make_pair(moment, change));
handles interference calculations
WifiTxVector m_txVector
TXVECTOR.
Time m_startTime
start time
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.
Event(Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector, Time duration, RxPowerWattPerChannelBand &&rxPower)
Create an Event with the given parameters.
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).
const WifiTxVector & GetTxVector() const
Return the TXVECTOR of the PPDU.
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.
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.
double m_noiseFigure
noise figure (linear)
Ptr< ErrorRateModel > GetErrorRateModel() const
Return the error rate model.
void AddForeignSignal(Time duration, RxPowerWattPerChannelBand &rxPower)
Add a non-Wifi signal to interference helper.
bool m_rxing
flag whether it is in receiving state
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< WifiSpectrumBand, NiChanges > NiChangesPerBand
Map of NiChanges per band.
uint8_t m_numRxAntennas
the number of RX antennas in the corresponding receiver
void DoDispose() override
Destructor implementation.
void RemoveBands()
Remove the frequency bands.
void NotifyRxEnd(Time endTime)
Notify that RX has ended.
double CalculateNoiseInterferenceW(Ptr< Event > event, NiChangesPerBand *nis, WifiSpectrumBand band) const
Calculate noise and interference power in W.
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
std::multimap< Time, NiChange > NiChanges
typedef for a multimap of NiChange
Time GetEnergyDuration(double energyW, WifiSpectrumBand band)
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.
void EraseEvents()
Erase all events.
Ptr< ErrorRateModel > m_errorRateModel
error rate model
void AppendEvent(Ptr< Event > event, bool isStartOfdmaRxing)
Append the given Event.
void NotifyRxStart()
Notify that RX has started.
NiChanges::iterator GetNextPosition(Time moment, NiChangesPerBand::iterator niIt)
Returns an iterator to the first NiChange that is later than moment.
double CalculateSnr(Ptr< Event > event, uint16_t channelWidth, uint8_t nss, WifiSpectrumBand band) const
Calculate the SNIR for the event (starting from now until the event end).
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, WifiSpectrumBand 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...
NiChanges::iterator GetPreviousPosition(Time moment, NiChangesPerBand::iterator niIt)
Returns an iterator to the last NiChange that is before than moment.
double CalculatePhyHeaderSectionPsr(Ptr< const Event > event, NiChangesPerBand *nis, uint16_t channelWidth, WifiSpectrumBand band, PhyEntity::PhyHeaderSections phyHeaderSections) const
Calculate the success rate of the PHY header sections for the provided event.
Ptr< Event > Add(Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector, Time duration, RxPowerWattPerChannelBand &rxPower, bool isStartOfdmaRxing=false)
Add the PPDU-related signal to interference helper.
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 SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
void AddBand(WifiSpectrumBand band)
Add a frequency band.
double CalculatePhyHeaderPer(Ptr< const Event > event, NiChangesPerBand *nis, uint16_t channelWidth, WifiSpectrumBand band, WifiPpduField header) const
Calculate the error rate of the PHY header.
NiChangesPerBand m_niChangesPerBand
NI Changes for each band.
std::map< WifiSpectrumBand, double > m_firstPowerPerBand
first power of each band in watts
~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)
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...
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
#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
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double RatioToDb(double ratio)
Convert from ratio to dB.
std::pair< uint32_t, uint32_t > WifiSpectrumBand
typedef for a pair of start and stop sub-band indexes
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
std::ostream & operator<<(std::ostream &os, const Angles &a)
A struct for both SNR and PER.
double snr
SNR in linear scale.