24 #include "ns3/simulator.h"
38 m_txVector (txVector),
40 m_endTime (m_startTime + duration),
58 return m_endTime - m_startTime;
88 return m_txVector.GetMode ();
125 return (m_time < o.
m_time);
151 event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW);
163 Add (packet, fakeTxVector, duration, rxPowerW);
200 double noiseInterferenceW = 0.0;
205 noiseInterferenceW += i->GetDelta ();
211 if (noiseInterferenceW < energyW)
225 NiChanges::const_iterator nowIterator =
GetPosition (now);
226 for (NiChanges::const_iterator i =
m_niChanges.begin (); i != nowIterator; i++)
246 static const double BOLTZMANN = 1.3803e-23;
248 double Nt = BOLTZMANN * 290.0 * channelWidth * 1000000;
251 double noise = noiseFloor + noiseInterference;
252 double snr = signal / noise;
253 NS_LOG_DEBUG (
"bandwidth(MHz)=" << (uint16_t)channelWidth <<
", signal(W)= " << signal <<
", noise(W)=" << noiseFloor <<
", interference(W)=" << noiseInterference <<
", snr(linear)=" << snr);
261 NiChanges::const_iterator eventIterator =
m_niChanges.begin ();
271 if (eventIterator->GetEvent () != event)
277 noiseInterference += eventIterator->GetDelta ();
286 for (NiChanges::const_iterator i = eventIterator + 1; i !=
m_niChanges.end (); ++i)
288 if (event->GetEndTime () == i->GetTime () &&
event == i->GetEvent ())
294 ni->insert (ni->begin (),
NiChange (event->GetStartTime (), noiseInterference, event));
295 ni->push_back (
NiChange (event->GetEndTime (), 0, event));
296 return noiseInterference;
307 uint64_t nbits = (uint64_t)(rate * duration.
GetSeconds ());
310 nbits /= txVector.
GetNss ();
315 double csr =
m_errorRateModel->GetChunkSuccessRate (mode, txVector, snir, (uint32_t)nbits);
325 NiChanges::const_iterator j = ni->begin ();
326 Time previous = (*j).GetTime ();
327 WifiMode payloadMode =
event->GetPayloadMode ();
333 double noiseInterferenceW = (*j).GetDelta ();
334 double powerW =
event->GetRxPowerW ();
336 while (ni->end () != j)
338 Time current = (*j).GetTime ();
339 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
342 if (previous >= plcpPayloadStart)
348 payloadMode, txVector);
350 NS_LOG_DEBUG (
"Both previous and current point to the payload: mode=" << payloadMode <<
", psr=" << psr);
353 else if (current >= plcpPayloadStart)
358 current - plcpPayloadStart,
359 payloadMode, txVector);
360 NS_LOG_DEBUG (
"previous is before payload and current is in the payload: mode=" << payloadMode <<
", psr=" << psr);
363 noiseInterferenceW += (*j).GetDelta ();
364 previous = (*j).GetTime ();
368 double per = 1 - psr;
378 NiChanges::const_iterator j = ni->begin ();
379 Time previous = (*j).GetTime ();
402 double noiseInterferenceW = (*j).GetDelta ();
403 double powerW =
event->GetRxPowerW ();
405 while (ni->end () != j)
407 Time current = (*j).GetTime ();
408 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
411 if (previous >= plcpPayloadStart)
414 NS_LOG_DEBUG (
"Case 1 - previous and current after playload start: nothing to do");
417 else if (previous >= plcpTrainingSymbolsStart)
421 if (current >= plcpPayloadStart)
426 plcpPayloadStart - previous,
427 mcsHeaderMode, txVector);
429 NS_LOG_DEBUG (
"Case 2a - previous is in training or in SIG-B and current after payload start: mode=" << mcsHeaderMode <<
", psr=" << psr);
438 mcsHeaderMode, txVector);
440 NS_LOG_DEBUG (
"Case 2b - previous is in training or in SIG-B and current is in training or in SIG-B: mode=" << mcsHeaderMode <<
", psr=" << psr);
444 else if (previous >= plcpHsigHeaderStart)
448 if (current >= plcpPayloadStart)
453 plcpPayloadStart - plcpTrainingSymbolsStart,
454 mcsHeaderMode, txVector);
463 plcpTrainingSymbolsStart - previous,
464 headerMode, txVector);
466 NS_LOG_DEBUG (
"Case 3ai - previous is in SIG-A and current after payload start: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
474 plcpTrainingSymbolsStart - previous,
475 mcsHeaderMode, txVector);
477 NS_LOG_DEBUG (
"Case 3aii - previous is in HT-SIG and current after payload start: mode=" << mcsHeaderMode <<
", psr=" << psr);
481 else if (current >= plcpTrainingSymbolsStart)
486 current - plcpTrainingSymbolsStart,
487 mcsHeaderMode, txVector);
496 plcpTrainingSymbolsStart - previous,
497 headerMode, txVector);
499 NS_LOG_DEBUG (
"Case 3bi - previous is in SIG-A and current is in training or in SIG-B: mode=" << headerMode <<
", psr=" << psr);
507 plcpTrainingSymbolsStart - previous,
508 mcsHeaderMode, txVector);
510 NS_LOG_DEBUG (
"Case 3bii - previous is in HT-SIG and current is in HT training: mode=" << mcsHeaderMode <<
", psr=" << psr);
524 headerMode, txVector);
526 NS_LOG_DEBUG (
"Case 3ci - previous with current in SIG-A: mode=" << headerMode <<
", psr=" << psr);
535 mcsHeaderMode, txVector);
537 NS_LOG_DEBUG (
"Case 3cii - previous with current in HT-SIG: mode=" << mcsHeaderMode <<
", psr=" << psr);
542 else if (previous >= plcpHeaderStart)
546 if (current >= plcpPayloadStart)
554 plcpPayloadStart - previous,
555 headerMode, txVector);
557 NS_LOG_DEBUG (
"Case 4ai - previous in L-SIG and current after payload start: mode=" << headerMode <<
", psr=" << psr);
565 plcpPayloadStart - plcpTrainingSymbolsStart,
566 mcsHeaderMode, txVector);
571 plcpTrainingSymbolsStart - previous,
572 headerMode, txVector);
574 NS_LOG_DEBUG (
"Case 4aii - previous is in L-SIG and current after payload start: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
582 plcpPayloadStart - plcpHsigHeaderStart,
583 mcsHeaderMode, txVector);
588 plcpHsigHeaderStart - previous,
589 headerMode, txVector);
591 NS_LOG_DEBUG (
"Case 4aiii - previous in L-SIG and current after payload start: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
595 else if (current >= plcpTrainingSymbolsStart)
605 current - plcpTrainingSymbolsStart,
606 mcsHeaderMode, txVector);
610 plcpTrainingSymbolsStart - previous,
611 headerMode, txVector);
613 NS_LOG_DEBUG (
"Case 4bi - previous is in L-SIG and current in training or in SIG-B: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
621 current - plcpHsigHeaderStart,
622 mcsHeaderMode, txVector);
627 plcpHsigHeaderStart - previous,
628 headerMode, txVector);
630 NS_LOG_DEBUG (
"Case 4bii - previous in L-SIG and current in HT training: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
634 else if (current >= plcpHsigHeaderStart)
645 headerMode, txVector);
647 NS_LOG_DEBUG (
"Case 4ci - previous is in L-SIG and current in SIG-A: mode=" << headerMode <<
", psr=" << psr);
655 current - plcpHsigHeaderStart,
656 mcsHeaderMode, txVector);
661 plcpHsigHeaderStart - previous,
662 headerMode, txVector);
664 NS_LOG_DEBUG (
"Case 4cii - previous in L-SIG and current in HT-SIG: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
674 headerMode, txVector);
676 NS_LOG_DEBUG (
"Case 3c - current with previous in L-SIG: mode=" << headerMode <<
", psr=" << psr);
683 if (current >= plcpPayloadStart)
691 plcpPayloadStart - plcpHeaderStart,
692 headerMode, txVector);
694 NS_LOG_DEBUG (
"Case 5a - previous is in the preamble and current is after payload start: mode=" << headerMode <<
", psr=" << psr);
702 plcpPayloadStart - plcpTrainingSymbolsStart,
703 mcsHeaderMode, txVector);
708 plcpTrainingSymbolsStart - plcpHeaderStart,
709 headerMode, txVector);
711 NS_LOG_DEBUG (
"Case 5aii - previous is in the preamble and current is after payload start: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
720 plcpPayloadStart - plcpHsigHeaderStart,
721 mcsHeaderMode, txVector);
726 plcpHsigHeaderStart - plcpHeaderStart,
727 headerMode, txVector);
729 NS_LOG_DEBUG (
"Case 5aiii - previous is in the preamble and current is after payload start: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
733 else if (current >= plcpTrainingSymbolsStart)
743 current - plcpTrainingSymbolsStart,
744 mcsHeaderMode, txVector);
749 plcpTrainingSymbolsStart - plcpHeaderStart,
750 headerMode, txVector);
752 NS_LOG_DEBUG (
"Case 5bi - previous is in the preamble and current in training or in SIG-B: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
760 current - plcpHsigHeaderStart,
761 mcsHeaderMode, txVector);
766 plcpHsigHeaderStart - plcpHeaderStart,
767 headerMode, txVector);
769 NS_LOG_DEBUG (
"Case 5bii - previous is in the preamble and current in HT training: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
773 else if (current >= plcpHsigHeaderStart)
783 current - plcpHeaderStart,
784 headerMode, txVector);
786 NS_LOG_DEBUG (
"Case 5ci - previous is in preamble and current in SIG-A: mode=" << headerMode <<
", psr=" << psr);
794 current - plcpHsigHeaderStart,
795 mcsHeaderMode, txVector);
800 plcpHsigHeaderStart - plcpHeaderStart,
801 headerMode, txVector);
803 NS_LOG_DEBUG (
"Case 5cii - previous in preamble and current in HT-SIG: mcs mode=" << mcsHeaderMode <<
", legacy mode=" << headerMode <<
", psr=" << psr);
807 else if (current >= plcpHeaderStart)
814 current - plcpHeaderStart,
815 headerMode, txVector);
817 NS_LOG_DEBUG (
"Case 5d - previous is in the preamble and current is in L-SIG: mode=" << headerMode <<
", psr=" << psr);
821 noiseInterferenceW += (*j).GetDelta ();
822 previous = (*j).GetTime ();
826 double per = 1 - psr;
837 event->GetTxVector ().GetChannelWidth ());
857 event->GetTxVector ().GetChannelWidth ());
878 InterferenceHelper::NiChanges::const_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.
Ptr< InterferenceHelper::Event > Add(Ptr< const Packet > packet, WifiTxVector txVector, Time duration, double rxPower)
Add the packet-related signal to interference helper.
#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.
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
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 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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
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
error rate model
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
static Time GetPlcpSigA1Duration(WifiPreamble preamble)
uint8_t GetChannelWidth(void) const
Ptr< const Packet > GetPacket(void) const
Return the packet.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
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.
static Time GetPlcpSigA2Duration(WifiPreamble preamble)
Event(Ptr< const Packet > packet, WifiTxVector txVector, Time duration, double rxPower)
Create an Event with the given parameters.
WifiTxVector GetTxVector(void) const
Return the TXVECTOR of the packet.
NiChange(Time time, double delta, Ptr< InterferenceHelper::Event > event)
Create a NiChange at the given time and the amount of NI change.
static Time GetPlcpPreambleDuration(WifiTxVector txVector)
static Time GetPlcpSigBDuration(WifiPreamble preamble)
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.
Time GetEnergyDuration(double energyW) const
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.
double CalculatePlcpHeaderPer(Ptr< const Event > event, NiChanges *ni) const
Calculate the error rate of the plcp header.
double GetDelta(void) const
Return the power.
uint8_t m_numRxAntennas
the number of RX antennas in the corresponding receiver
static Time Now(void)
Return the current simulation virtual time.
Time GetEndTime(void) const
Return the end time of the signal.
Ptr< InterferenceHelper::Event > GetEvent(void) const
Return the event causes the corresponding NI change.
WifiPreamble GetPreambleType(void) const
uint8_t GetNss(void) const
void NotifyRxEnd()
Notify that RX has ended.
uint64_t GetPhyRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Time GetDuration(void) const
Return the duration of the signal.
void SetNoiseFigure(double value)
Set the noise figure.
double m_firstPower
first power
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 WifiMode GetVhtPlcpHeaderMode()
NiChanges::const_iterator GetPosition(Time moment)
Returns a const iterator to the first nichange, which is later than moment.
uint8_t GetNTx(void) const
static WifiMode GetHePlcpHeaderMode()
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.
WifiModulationClass GetModulationClass() const
WifiMode GetMode(void) const
double GetNoiseFigure(void) const
Return the noise figure.
static WifiMode GetPlcpHeaderMode(WifiTxVector txVector)
static Time GetPlcpTrainingSymbolDuration(WifiTxVector txVector)
static Time GetPlcpHeaderDuration(WifiTxVector txVector)
double CalculateSnr(double signal, double noiseInterference, uint8_t channelWidth) const
Calculate SNR (linear ratio) from the given signal power and noise+interference power.
static WifiMode GetHtPlcpHeaderMode()
bool m_rxing
flag whether it is in receiving state