A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
interference-helper.h
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 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef INTERFERENCE_HELPER_H
10#define INTERFERENCE_HELPER_H
11
12#include "phy-entity.h"
13
14#include "ns3/object.h"
15
16namespace ns3
17{
18
19class WifiPpdu;
20class WifiPsdu;
21class ErrorRateModel;
22
23/**
24 * @ingroup wifi
25 * @brief handles interference calculations
26 * @brief signal event for a PPDU.
27 */
28class Event : public SimpleRefCount<Event>
29{
30 public:
31 /**
32 * Create an Event with the given parameters. Note that <i>rxPower</i> will
33 * be moved into this object.
34 *
35 * @param ppdu the PPDU
36 * @param duration duration of the PPDU
37 * @param rxPower the received power per band (W)
38 */
40
41 /**
42 * Return the PPDU.
43 *
44 * @return the PPDU
45 */
47 /**
48 * Return the start time of the signal.
49 *
50 * @return the start time of the signal
51 */
52 Time GetStartTime() const;
53 /**
54 * Return the end time of the signal.
55 *
56 * @return the end time of the signal
57 */
58 Time GetEndTime() const;
59 /**
60 * Return the duration of the signal.
61 *
62 * @return the duration of the signal
63 */
64 Time GetDuration() const;
65 /**
66 * Return the total received power.
67 *
68 * @return the total received power
69 */
70 Watt_u GetRxPower() const;
71 /**
72 * Return the received power for a given band.
73 *
74 * @param band the band for which the power should be returned
75 * @return the received power for a given band
76 */
77 Watt_u GetRxPower(const WifiSpectrumBandInfo& band) const;
78 /**
79 * Return the received power (W) for all bands.
80 *
81 * @return the received power (W) for all bands.
82 */
84 /**
85 * Update the received power (W) for all bands, i.e. add up the received power
86 * to the current received power, for each band.
87 *
88 * @param rxPower the received power (W) for all bands.
89 */
91 /**
92 * Update the PPDU that initially generated the event.
93 * This is needed to have the PPDU holding the correct TXVECTOR
94 * upon reception of multiple signals carrying the same content
95 * but over different channel width (typically non-HT duplicates).
96 *
97 * @param ppdu the new PPDU to use for this event.
98 */
100
101 private:
103 Time m_startTime; //!< start time
104 Time m_endTime; //!< end time
105 RxPowerWattPerChannelBand m_rxPowerW; //!< received power in watts per band
106};
107
108/**
109 * @brief Stream insertion operator.
110 *
111 * @param os the stream
112 * @param event the event
113 * @returns a reference to the stream
114 */
115std::ostream& operator<<(std::ostream& os, const Event& event);
116
117/**
118 * @ingroup wifi
119 * @brief handles interference calculations
120 */
122{
123 public:
125 ~InterferenceHelper() override;
126
127 /**
128 * @brief Get the type ID.
129 * @return the object TypeId
130 */
131 static TypeId GetTypeId();
132
133 /**
134 * Add a frequency band.
135 *
136 * @param band the band to be added
137 */
138 void AddBand(const WifiSpectrumBandInfo& band);
139
140 /**
141 * Remove a frequency band.
142 *
143 * @param band the band to be removed
144 */
145 void RemoveBand(const WifiSpectrumBandInfo& band);
146
147 /**
148 * Check whether bands are already tracked by this interference helper.
149 *
150 * @return true if bands are tracked by this interference helper, false otherwise
151 */
152 bool HasBands() const;
153
154 /**
155 * Update the frequency bands that belongs to a given frequency range when the spectrum model is
156 * changed.
157 *
158 * @param bands the bands to be added in the new spectrum model
159 * @param freqRange the frequency range the bands belong to
160 */
161 void UpdateBands(const std::vector<WifiSpectrumBandInfo>& bands,
163
164 /**
165 * Set the noise figure.
166 *
167 * @param value noise figure in linear scale
168 */
169 void SetNoiseFigure(double value);
170 /**
171 * Set the error rate model for this interference helper.
172 *
173 * @param rate Error rate model
174 */
175 void SetErrorRateModel(const Ptr<ErrorRateModel> rate);
176
177 /**
178 * Return the error rate model.
179 *
180 * @return Error rate model
181 */
183 /**
184 * Set the number of RX antennas in the receiver corresponding to this
185 * interference helper.
186 *
187 * @param rx the number of RX antennas
188 */
189 void SetNumberOfReceiveAntennas(uint8_t rx);
190
191 /**
192 * @param energy the minimum energy requested
193 * @param band identify the requested band
194 *
195 * @returns the expected amount of time the observed
196 * energy on the medium for a given band will
197 * be higher than the requested threshold.
198 */
200
201 /**
202 * Add the PPDU-related signal to interference helper.
203 *
204 * @param ppdu the PPDU
205 * @param duration the PPDU duration
206 * @param rxPower received power per band (W)
207 * @param freqRange the frequency range in which the received signal is detected
208 * @param isStartHePortionRxing flag whether the event corresponds to the start of the HE
209 * portion reception (only used for MU)
210 *
211 * @return Event
212 */
214 Time duration,
217 bool isStartHePortionRxing = false);
218
219 /**
220 * Add a non-Wifi signal to interference helper.
221 * @param duration the duration of the signal
222 * @param rxPower received power per band (W)
223 * @param freqRange the frequency range in which the received signal is detected
224 */
225 void AddForeignSignal(Time duration,
228 /**
229 * Calculate the SNIR at the start of the payload and accumulate
230 * all SNIR changes in the SNIR vector for each MPDU of an A-MPDU.
231 * This workaround is required in order to provide one PER per MPDU, for
232 * reception success/failure evaluation, while hiding aggregation details from
233 * this class.
234 *
235 * @param event the event corresponding to the first time the corresponding PPDU arrives
236 * @param channelWidth the channel width used to transmit the PSDU
237 * @param band identify the band used by the PSDU
238 * @param staId the station ID of the PSDU (only used for MU)
239 * @param relativeMpduStartStop the time window (pair of start and end times) of PHY payload to
240 * focus on
241 *
242 * @return struct of SNR and PER (with PER being evaluated over the provided time window)
243 */
245 MHz_u channelWidth,
246 const WifiSpectrumBandInfo& band,
247 uint16_t staId,
248 std::pair<Time, Time> relativeMpduStartStop) const;
249 /**
250 * Calculate the SNIR for the event (starting from now until the event end).
251 *
252 * @param event the event corresponding to the first time the corresponding PPDU arrives
253 * @param channelWidth the channel width
254 * @param nss the number of spatial streams
255 * @param band identify the band used by the PSDU
256 *
257 * @return the SNR for the PPDU in linear scale
258 */
259 double CalculateSnr(Ptr<Event> event,
260 MHz_u channelWidth,
261 uint8_t nss,
262 const WifiSpectrumBandInfo& band) const;
263 /**
264 * Calculate the SNIR at the start of the PHY header and accumulate
265 * all SNIR changes in the SNIR vector.
266 *
267 * @param event the event corresponding to the first time the corresponding PPDU arrives
268 * @param channelWidth the channel width for header measurement
269 * @param band identify the band used by the PSDU
270 * @param header the PHY header to consider
271 *
272 * @return struct of SNR and PER
273 */
275 MHz_u channelWidth,
276 const WifiSpectrumBandInfo& band,
277 WifiPpduField header) const;
278
279 /**
280 * Notify that RX has started.
281 * @param freqRange the frequency range in which the received signal event is detected
282 */
284 /**
285 * Notify that RX has ended.
286 *
287 * @param endTime the end time of the signal
288 * @param freqRange the frequency range in which the received signal event was detected
289 */
291
292 /**
293 * Update event to scale its received power (W) per band.
294 *
295 * @param event the event to be updated
296 * @param rxPower the received power (W) per band to be added to the current event
297 */
299
300 protected:
301 void DoDispose() override;
302
303 /**
304 * Calculate SNR (linear ratio) from the given signal power and noise+interference power.
305 *
306 * @param signal signal power
307 * @param noiseInterference noise and interference power
308 * @param channelWidth signal width
309 * @param nss the number of spatial streams
310 *
311 * @return SNR in linear scale
312 */
313 double CalculateSnr(Watt_u signal,
315 MHz_u channelWidth,
316 uint8_t nss) const;
317 /**
318 * Calculate the success rate of the chunk given the SINR, duration, and TXVECTOR.
319 * The duration and TXVECTOR are used to calculate how many bits are present in the chunk.
320 *
321 * @param snir the SINR
322 * @param duration the duration of the chunk
323 * @param mode the WifiMode
324 * @param txVector the TXVECTOR
325 * @param field the PPDU field to which the chunk belongs to
326 *
327 * @return the success rate
328 */
329 double CalculateChunkSuccessRate(double snir,
330 Time duration,
331 WifiMode mode,
332 const WifiTxVector& txVector,
333 WifiPpduField field) const;
334 /**
335 * Calculate the success rate of the payload chunk given the SINR, duration, and TXVECTOR.
336 * The duration and TXVECTOR are used to calculate how many bits are present in the payload
337 * chunk.
338 *
339 * @param snir the SINR
340 * @param duration the duration of the chunk
341 * @param txVector the TXVECTOR
342 * @param staId the station ID of the PSDU (only used for MU)
343 *
344 * @return the success rate
345 */
347 Time duration,
348 const WifiTxVector& txVector,
349 uint16_t staId = SU_STA_ID) const;
350
351 protected:
352 std::map<FrequencyRange, bool>
353 m_rxing; //!< flag whether it is in receiving state for a given FrequencyRange
354
355 /**
356 * Noise and Interference (thus Ni) event.
357 */
359 {
360 public:
361 /**
362 * Create a NiChange at the given time and the amount of NI change.
363 *
364 * @param power the power
365 * @param event causes this NI change
366 */
367 NiChange(Watt_u power, Ptr<Event> event);
368 ~NiChange();
369 /**
370 * Return the power
371 *
372 * @return the power
373 */
374 Watt_u GetPower() const;
375 /**
376 * Add a given amount of power.
377 *
378 * @param power the power to be added to the existing value
379 */
380 void AddPower(Watt_u power);
381 /**
382 * Return the event causes the corresponding NI change
383 *
384 * @return the event
385 */
386 Ptr<Event> GetEvent() const;
387
388 private:
389 Watt_u m_power; ///< power
390 Ptr<Event> m_event; ///< event
391 };
392
393 /**
394 * typedef for a multimap of NiChange
395 */
396 using NiChanges = std::multimap<Time, NiChange>;
397
398 /**
399 * Map of NiChanges per band
400 */
401 using NiChangesPerBand = std::map<WifiSpectrumBandInfo, NiChanges>;
402
403 /**
404 * Map of first power per band
405 */
406 using FirstPowerPerBand = std::map<WifiSpectrumBandInfo, Watt_u>;
407
408 NiChangesPerBand m_niChanges; //!< NI Changes for each band
409
410 private:
411 /**
412 * Check whether a given band is tracked by this interference helper.
413 *
414 * @param band the band to be checked
415 * @return true if the band is already tracked by this interference helper, false otherwise
416 */
417 bool HasBand(const WifiSpectrumBandInfo& band) const;
418
419 /**
420 * Check whether a given band belongs to a given frequency range.
421 *
422 * @param band the band to be checked
423 * @param freqRange the frequency range to check whether the band belong to
424 * @return true if the band belongs to the frequency range, false otherwise
425 */
427 const FrequencyRange& freqRange) const;
428
429 /**
430 * Append the given Event.
431 *
432 * @param event the event to be appended
433 * @param freqRange the frequency range in which the received signal event is detected
434 * @param isStartHePortionRxing flag whether event corresponds to the start of the HE portion
435 * reception (only used for MU)
436 */
438
439 /**
440 * Calculate noise and interference power.
441 *
442 * @param event the event
443 * @param nis the NiChanges
444 * @param band the band
445 *
446 * @return noise and interference power
447 */
450 const WifiSpectrumBandInfo& band) const;
451
452 /**
453 * Calculate power of all other events preceding a given event that belong to the same MU-MIMO
454 * transmission.
455 *
456 * @param event the event
457 * @param band the band
458 *
459 * @return the power of all other events preceding the event that belong to the same MU-MIMO
460 * transmission
461 */
463
464 /**
465 * Calculate the error rate of the given PHY payload only in the provided time
466 * window (thus enabling per MPDU PER information). The PHY payload can be divided into
467 * multiple chunks (e.g. due to interference from other transmissions).
468 *
469 * @param event the event
470 * @param channelWidth the channel width used to transmit the PSDU
471 * @param nis the NiChanges
472 * @param band identify the band used by the PSDU
473 * @param staId the station ID of the PSDU (only used for MU)
474 * @param window time window (pair of start and end times) of PHY payload to focus on
475 *
476 * @return the error rate of the payload
477 */
479 MHz_u channelWidth,
481 const WifiSpectrumBandInfo& band,
482 uint16_t staId,
483 std::pair<Time, Time> window) const;
484 /**
485 * Calculate the error rate of the PHY header. The PHY header
486 * can be divided into multiple chunks (e.g. due to interference from other transmissions).
487 *
488 * @param event the event
489 * @param nis the NiChanges
490 * @param channelWidth the channel width for header measurement
491 * @param band the band
492 * @param header the PHY header to consider
493 *
494 * @return the error rate of the HT PHY header
495 */
498 MHz_u channelWidth,
499 const WifiSpectrumBandInfo& band,
500 WifiPpduField header) const;
501 /**
502 * Calculate the success rate of the PHY header sections for the provided event.
503 *
504 * @param event the event
505 * @param nis the NiChanges
506 * @param channelWidth the channel width for header measurement
507 * @param band the band
508 * @param phyHeaderSections the map of PHY header sections (\see PhyEntity::PhyHeaderSections)
509 *
510 * @return the success rate of the PHY header sections
511 */
514 MHz_u channelWidth,
515 const WifiSpectrumBandInfo& band,
517
518 double m_noiseFigure; //!< noise figure (linear)
520 uint8_t m_numRxAntennas; //!< the number of RX antennas in the corresponding receiver
521 FirstPowerPerBand m_firstPowers; //!< first power of each band
522
523 /**
524 * Returns an iterator to the first NiChange that is later than moment
525 *
526 * @param moment time to check from
527 * @param niIt iterator of the band to check
528 * @returns an iterator to the list of NiChanges
529 */
530 NiChanges::iterator GetNextPosition(Time moment, NiChangesPerBand::iterator niIt);
531 /**
532 * Returns an iterator to the last NiChange that is before than moment
533 *
534 * @param moment time to check from
535 * @param niIt iterator of the band to check
536 * @returns an iterator to the list of NiChanges
537 */
538 NiChanges::iterator GetPreviousPosition(Time moment, NiChangesPerBand::iterator niIt);
539
540 /**
541 * Add NiChange to the list at the appropriate position and
542 * return the iterator of the new event.
543 *
544 * @param moment time to check from
545 * @param change the NiChange to add
546 * @param niIt iterator of the band to check
547 * @returns the iterator of the new event
548 */
549 NiChanges::iterator AddNiChangeEvent(Time moment,
551 NiChangesPerBand::iterator niIt);
552
553 /**
554 * Return whether another event is a MU-MIMO event that belongs to the same transmission and to
555 * the same RU.
556 *
557 * @param currentEvent the current event that is being inspected
558 * @param otherEvent the other event to compare against
559 *
560 * @return whether both events belong to the same transmission and to the same RU
561 */
563};
564
565} // namespace ns3
566
567#endif /* INTERFERENCE_HELPER_H */
handles interference calculations
Time m_endTime
end time
Watt_u GetRxPower() const
Return the total received power.
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.
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.
Noise and Interference (thus Ni) event.
void AddPower(Watt_u power)
Add a given amount of power.
Watt_u GetPower() const
Return the power.
Ptr< Event > GetEvent() const
Return the event causes the corresponding NI change.
handles interference calculations
std::map< WifiSpectrumBandInfo, Watt_u > FirstPowerPerBand
Map of first power per band.
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.
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.
PhyEntity::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...
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
double CalculatePhyHeaderSectionPsr(Ptr< const Event > event, NiChangesPerBand *nis, MHz_u channelWidth, const WifiSpectrumBandInfo &band, PhyEntity::PhyHeaderSections phyHeaderSections) const
Calculate the success rate of the PHY header sections for the provided event.
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
PhyEntity::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...
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.
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.
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...
A base class which provides memory management and object aggregation.
Definition object.h:78
std::map< WifiPpduField, PhyHeaderChunkInfo > PhyHeaderSections
A map of PhyHeaderChunkInfo elements per PPDU field.
Definition phy-entity.h:294
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:49
represent a single transmission mode
Definition wifi-mode.h:40
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
WifiPpduField
The type of PPDU field (grouped for convenience)
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
static unsigned int value(char c)
std::map< WifiSpectrumBandInfo, Watt_u > RxPowerWattPerChannelBand
A map of the received power for each band.
Definition phy-entity.h:45
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition wifi-mode.h:24
Declaration of:
Struct defining a frequency range between minFrequency and maxFrequency.
A struct for both SNR and PER.
Definition phy-entity.h:115
WifiSpectrumBandInfo structure containing info about a spectrum band.