25 #include "ns3/simulator.h"
39 Time duration,
double rxPower)
41 m_txVector (txVector),
42 m_preamble (preamble),
44 m_endTime (m_startTime + duration),
56 return m_endTime - m_startTime;
92 return m_txVector.GetMode ();
128 return (m_time < o.
m_time);
152 Time duration,
double rxPowerW)
156 event = Create<InterferenceHelper::Event> (size,
202 double noiseInterferenceW = 0.0;
207 noiseInterferenceW += i->GetDelta ();
213 if (noiseInterferenceW < energyW)
227 NiChanges::iterator nowIterator =
GetPosition (now);
228 for (NiChanges::iterator i =
m_niChanges.begin (); i != nowIterator; i++)
248 static const double BOLTZMANN = 1.3803e-23;
250 double Nt = BOLTZMANN * 290.0 * channelWidth * 1000000;
253 double noise = noiseFloor + noiseInterference;
254 double snr = signal / noise;
255 NS_LOG_DEBUG (
"bandwidth(MHz)=" << channelWidth <<
", signal(W)= " << signal <<
", noise(W)=" << noiseFloor <<
", interference(W)=" << noiseInterference <<
", snr(linear)=" << snr);
266 if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
272 ni->insert (ni->begin (),
NiChange (event->GetStartTime (), noiseInterference));
273 ni->push_back (
NiChange (event->GetEndTime (), 0));
274 return noiseInterference;
285 uint64_t nbits = (uint64_t)(rate * duration.
GetSeconds ());
286 double csr =
m_errorRateModel->GetChunkSuccessRate (mode, txVector, snir, (uint32_t)nbits);
295 NiChanges::iterator j = ni->begin ();
296 Time previous = (*j).GetTime ();
297 WifiMode payloadMode =
event->GetPayloadMode ();
303 double noiseInterferenceW = (*j).GetDelta ();
304 double powerW =
event->GetRxPowerW ();
306 while (ni->end () != j)
308 Time current = (*j).GetTime ();
309 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
312 if (previous >= plcpPayloadStart)
316 event->GetTxVector ().GetChannelWidth ()),
318 payloadMode, event->GetTxVector ());
320 NS_LOG_DEBUG (
"Both previous and current point to the payload: mode=" << payloadMode <<
", psr=" << psr);
323 else if (current >= plcpPayloadStart)
327 event->GetTxVector ().GetChannelWidth ()),
328 current - plcpPayloadStart,
329 payloadMode, event->GetTxVector ());
330 NS_LOG_DEBUG (
"previous is before payload and current is in the payload: mode=" << payloadMode <<
", psr=" << psr);
333 noiseInterferenceW += (*j).GetDelta ();
334 previous = (*j).GetTime ();
338 double per = 1 - psr;
347 NiChanges::iterator j = ni->begin ();
348 Time previous = (*j).GetTime ();
349 WifiMode payloadMode =
event->GetPayloadMode ();
367 double noiseInterferenceW = (*j).GetDelta ();
368 double powerW =
event->GetRxPowerW ();
370 while (ni->end () != j)
372 Time current = (*j).GetTime ();
373 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
376 if (previous >= plcpPayloadStart)
379 NS_LOG_DEBUG (
"Case 1 - previous and current after playload start: nothing to do");
382 else if (previous >= plcpHtTrainingSymbolsStart)
386 if (current >= plcpPayloadStart)
390 event->GetTxVector ().GetChannelWidth ()),
391 plcpPayloadStart - previous,
392 htHeaderMode, event->GetTxVector ());
394 NS_LOG_DEBUG (
"Case 2a - previous is in (V)HT training or in VHT-SIG-B and current after payload start: mode=" << htHeaderMode <<
", psr=" << psr);
401 event->GetTxVector ().GetChannelWidth ()),
403 htHeaderMode, event->GetTxVector ());
405 NS_LOG_DEBUG (
"Case 2b - previous is in (V)HT training or in VHT-SIG-B and current is in (V)HT training or in VHT-SIG-B: mode=" << htHeaderMode <<
", psr=" << psr);
409 else if (previous >= plcpHsigHeaderStart)
413 if (current >= plcpPayloadStart)
417 event->GetTxVector ().GetChannelWidth ()),
418 plcpPayloadStart - plcpHtTrainingSymbolsStart,
419 htHeaderMode, event->GetTxVector ());
427 event->GetTxVector ().GetChannelWidth ()),
428 plcpHtTrainingSymbolsStart - previous,
429 headerMode, event->GetTxVector ());
431 NS_LOG_DEBUG (
"Case 3ai - previous is in VHT-SIG-A and current after payload start: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
438 event->GetTxVector ().GetChannelWidth ()),
439 plcpHtTrainingSymbolsStart - previous,
440 htHeaderMode, event->GetTxVector ());
442 NS_LOG_DEBUG (
"Case 3aii - previous is in HT-SIG and current after payload start: mode=" << htHeaderMode <<
", psr=" << psr);
446 else if (current >= plcpHtTrainingSymbolsStart)
450 event->GetTxVector ().GetChannelWidth ()),
451 current - plcpHtTrainingSymbolsStart,
452 htHeaderMode, event->GetTxVector ());
460 event->GetTxVector ().GetChannelWidth ()),
461 plcpHtTrainingSymbolsStart - previous,
462 headerMode, event->GetTxVector ());
464 NS_LOG_DEBUG (
"Case 3bi - previous is in VHT-SIG-A and current is in VHT training or in VHT-SIG-B: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
471 event->GetTxVector ().GetChannelWidth ()),
472 plcpHtTrainingSymbolsStart - previous,
473 htHeaderMode, event->GetTxVector ());
475 NS_LOG_DEBUG (
"Case 3bii - previous is in HT-SIG and current is in HT training: mode=" << htHeaderMode <<
", psr=" << psr);
487 event->GetTxVector ().GetChannelWidth ()),
489 headerMode, event->GetTxVector ());
491 NS_LOG_DEBUG (
"Case 3ci - previous with current in VHT-SIG-A: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
498 event->GetTxVector ().GetChannelWidth ()),
500 htHeaderMode, event->GetTxVector ());
502 NS_LOG_DEBUG (
"Case 3cii - previous with current in HT-SIG: mode=" << htHeaderMode <<
", psr=" << psr);
507 else if (previous >= plcpHeaderStart)
511 if (current >= plcpPayloadStart)
518 event->GetTxVector ().GetChannelWidth ()),
519 plcpPayloadStart - previous,
520 headerMode, event->GetTxVector ());
522 NS_LOG_DEBUG (
"Case 4ai - previous in L-SIG and current after payload start: mode=" << headerMode <<
", psr=" << psr);
529 event->GetTxVector ().GetChannelWidth ()),
530 plcpPayloadStart - plcpHtTrainingSymbolsStart,
531 htHeaderMode, event->GetTxVector ());
535 event->GetTxVector ().GetChannelWidth ()),
536 plcpHtTrainingSymbolsStart - previous,
537 headerMode, event->GetTxVector ());
539 NS_LOG_DEBUG (
"Case 4aii - previous is in L-SIG and current after payload start: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
546 event->GetTxVector ().GetChannelWidth ()),
547 plcpPayloadStart - plcpHsigHeaderStart,
548 htHeaderMode, event->GetTxVector ());
552 event->GetTxVector ().GetChannelWidth ()),
553 plcpHsigHeaderStart - previous,
554 headerMode, event->GetTxVector ());
556 NS_LOG_DEBUG (
"Case 4aiii - previous in L-SIG and current after payload start: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
560 else if (current >= plcpHtTrainingSymbolsStart)
569 event->GetTxVector ().GetChannelWidth ()),
570 current - plcpHtTrainingSymbolsStart,
571 htHeaderMode, event->GetTxVector ());
575 event->GetTxVector ().GetChannelWidth ()),
576 plcpHtTrainingSymbolsStart - previous,
577 headerMode, event->GetTxVector ());
579 NS_LOG_DEBUG (
"Case 4bi - previous is in L-SIG and current in VHT training or in VHT-SIG-B: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
586 event->GetTxVector ().GetChannelWidth ()),
587 current - plcpHsigHeaderStart,
588 htHeaderMode, event->GetTxVector ());
592 event->GetTxVector ().GetChannelWidth ()),
593 plcpHsigHeaderStart - previous,
594 headerMode, event->GetTxVector ());
596 NS_LOG_DEBUG (
"Case 4bii - previous in L-SIG and current in HT training: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
600 else if (current >= plcpHsigHeaderStart)
609 event->GetTxVector ().GetChannelWidth ()),
611 headerMode, event->GetTxVector ());
613 NS_LOG_DEBUG (
"Case 4ci - previous is in L-SIG and current in VHT-SIG-A: mode=" << headerMode <<
", psr=" << psr);
620 event->GetTxVector ().GetChannelWidth ()),
621 current - plcpHsigHeaderStart,
622 htHeaderMode, event->GetTxVector ());
626 event->GetTxVector ().GetChannelWidth ()),
627 plcpHsigHeaderStart - previous,
628 headerMode, event->GetTxVector ());
630 NS_LOG_DEBUG (
"Case 4cii - previous in L-SIG and current in HT-SIG: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
638 event->GetTxVector ().GetChannelWidth ()),
640 headerMode, event->GetTxVector ());
642 NS_LOG_DEBUG (
"Case 3c - current with previous in L-SIG: mode=" << headerMode <<
", psr=" << psr);
649 if (current >= plcpPayloadStart)
656 event->GetTxVector ().GetChannelWidth ()),
657 plcpPayloadStart - plcpHeaderStart,
658 headerMode, event->GetTxVector ());
660 NS_LOG_DEBUG (
"Case 5a - previous is in the preamble and current is after payload start: mode=" << headerMode <<
", psr=" << psr);
667 event->GetTxVector ().GetChannelWidth ()),
668 plcpPayloadStart - plcpHtTrainingSymbolsStart,
669 htHeaderMode, event->GetTxVector ());
673 event->GetTxVector ().GetChannelWidth ()),
674 plcpHtTrainingSymbolsStart - plcpHeaderStart,
675 headerMode, event->GetTxVector ());
677 NS_LOG_DEBUG (
"Case 5aii - previous is in the preamble and current is after payload start: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
685 event->GetTxVector ().GetChannelWidth ()),
686 plcpPayloadStart - plcpHsigHeaderStart,
687 htHeaderMode, event->GetTxVector ());
691 event->GetTxVector ().GetChannelWidth ()),
692 plcpHsigHeaderStart - plcpHeaderStart,
693 headerMode, event->GetTxVector ());
695 NS_LOG_DEBUG (
"Case 4a - previous is in the preamble and current is after payload start: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
699 else if (current >= plcpHtTrainingSymbolsStart)
708 event->GetTxVector ().GetChannelWidth ()),
709 current - plcpHtTrainingSymbolsStart,
710 htHeaderMode, event->GetTxVector ());
714 event->GetTxVector ().GetChannelWidth ()),
715 plcpHtTrainingSymbolsStart - plcpHeaderStart,
716 headerMode, event->GetTxVector ());
718 NS_LOG_DEBUG (
"Case 5bi - previous is in the preamble and current in VHT training or in VHT-SIG-B: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
725 event->GetTxVector ().GetChannelWidth ()),
726 current - plcpHsigHeaderStart,
727 htHeaderMode, event->GetTxVector ());
731 event->GetTxVector ().GetChannelWidth ()),
732 plcpHsigHeaderStart - plcpHeaderStart,
733 headerMode, event->GetTxVector ());
735 NS_LOG_DEBUG (
"Case 5bii - previous is in the preamble and current in HT training: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
739 else if (current >= plcpHsigHeaderStart)
748 event->GetTxVector ().GetChannelWidth ()),
749 current - plcpHeaderStart,
750 headerMode, event->GetTxVector ());
752 NS_LOG_DEBUG (
"Case 5ci - previous is in preamble and current in VHT-SIG-A: mode=" << headerMode <<
", psr=" << psr);
759 event->GetTxVector ().GetChannelWidth ()),
760 current - plcpHsigHeaderStart,
761 htHeaderMode, event->GetTxVector ());
765 event->GetTxVector ().GetChannelWidth ()),
766 plcpHsigHeaderStart - plcpHeaderStart,
767 headerMode, event->GetTxVector ());
769 NS_LOG_DEBUG (
"Case 5cii - previous in preamble and current in HT-SIG: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
773 else if (current >= plcpHeaderStart)
779 event->GetTxVector ().GetChannelWidth ()),
780 current - plcpHeaderStart,
781 headerMode, event->GetTxVector ());
783 NS_LOG_DEBUG (
"Case 5d - previous is in the preamble and current is in L-SIG: mode=" << headerMode <<
", psr=" << psr);
787 noiseInterferenceW += (*j).GetDelta ();
788 previous = (*j).GetTime ();
792 double per = 1 - psr;
803 event->GetTxVector ().GetChannelWidth ());
823 event->GetTxVector ().GetChannelWidth ());
844 InterferenceHelper::NiChanges::iterator
Simulation virtual time values and global simulation resolution.
void AddForeignSignal(Time duration, double rxPower)
Add a non-Wifi signal to interference helper.
A struct for both SNR and PER.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Control the scheduling of simulation events.
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Return the error rate model.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
bool operator<(const NiChange &o) const
Compare the event time of two NiChange objects (a < o).
std::vector< NiChange > NiChanges
typedef for a vector of NiChanges
handles interference calculations
static WifiMode GetHtPlcpHeaderMode(WifiMode payloadMode)
static Time GetPlcpHtSigHeaderDuration(WifiPreamble preamble)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Time GetEnergyDuration(double energyW)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double CalculateChunkSuccessRate(double snir, Time duration, WifiMode mode, WifiTxVector txVector) const
Calculate the success rate of the chunk given the SINR, duration, and Wi-Fi mode. ...
double GetRxPowerW(void) const
Return the receive power (w).
Ptr< ErrorRateModel > m_errorRateModel
NiChanges::iterator GetPosition(Time moment)
Returns an iterator to the first nichange, which is later than moment.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
uint32_t GetSize(void) const
Return the size of the packet (bytes).
static WifiMode GetVhtPlcpHeaderMode(WifiMode payloadMode)
uint64_t GetPhyRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
void SetErrorRateModel(Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
double CalculateNoiseInterferenceW(Ptr< Event > event, NiChanges *ni) const
Calculate noise and interference power in W.
Time GetStartTime(void) const
Return the start time of the signal.
WifiTxVector GetTxVector(void) const
Return the TXVECTOR of the packet.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
static WifiMode GetPlcpHeaderMode(WifiMode payloadMode, WifiPreamble preamble, WifiTxVector txVector)
NiChanges m_niChanges
Experimental: needed for energy duration calculation.
void AddNiChangeEvent(NiChange change)
Add NiChange to the list at the appropriate position.
Time GetTime(void) const
Return the event time.
double CalculatePlcpPayloadPer(Ptr< const Event > event, NiChanges *ni) const
Calculate the error rate of the given plcp payload.
double m_noiseFigure
noise figure (linear)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void NotifyRxStart()
Notify that RX has started.
Noise and Interference (thus Ni) event.
void EraseEvents(void)
Erase all events.
Ptr< InterferenceHelper::Event > Add(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, Time duration, double rxPower)
Add the packet-related signal to interference helper.
Event(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, Time duration, double rxPower)
Create an Event with the given parameters.
double CalculatePlcpHeaderPer(Ptr< const Event > event, NiChanges *ni) const
Calculate the error rate of the plcp header.
double GetDelta(void) const
Return the power.
static Time GetPlcpVhtSigA1Duration(WifiPreamble preamble)
static Time Now(void)
Return the current simulation virtual time.
Time GetEndTime(void) const
Return the end time of the signal.
enum WifiPreamble GetPreambleType(void) const
Return the preamble type of the packet.
void NotifyRxEnd()
Notify that RX has ended.
NiChange(Time time, double delta)
Create a NiChange at the given time and the amount of NI change.
double CalculateSnr(double signal, double noiseInterference, uint32_t channelWidth) const
Calculate SNR (linear ratio) from the given signal power and noise+interference power.
Time GetDuration(void) const
Return the duration of the signal.
void SetNoiseFigure(double value)
Set the noise figure.
WifiMode GetPayloadMode(void) const
Return the Wi-Fi mode used for the payload.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
static Time GetPlcpHeaderDuration(WifiTxVector txVector, WifiPreamble preamble)
void AppendEvent(Ptr< Event > event)
Append the given Event.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
double GetNoiseFigure(void) const
Return the noise figure.
static Time GetPlcpHtTrainingSymbolDuration(WifiPreamble preamble, WifiTxVector txVector)
static Time GetPlcpVhtSigBDuration(WifiPreamble preamble)
static Time GetPlcpPreambleDuration(WifiTxVector txVector, WifiPreamble preamble)
static Time GetPlcpVhtSigA2Duration(WifiPreamble preamble)