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,
194 double noiseInterferenceW = 0.0;
199 noiseInterferenceW += i->GetDelta ();
205 if (noiseInterferenceW < energyW)
219 NiChanges::iterator nowIterator =
GetPosition (now);
220 for (NiChanges::iterator i =
m_niChanges.begin (); i != nowIterator; i++)
240 static const double BOLTZMANN = 1.3803e-23;
242 double Nt = BOLTZMANN * 290.0 * channelWidth * 1000000;
245 double noise = noiseFloor + noiseInterference;
246 double snr = signal / noise;
247 NS_LOG_DEBUG (
"bandwidth(MHz)=" << channelWidth <<
", signal(W)= " << signal <<
", noise(W)=" << noiseFloor <<
", interference(W)=" << noiseInterference <<
", snr(linear)=" << snr);
258 if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
264 ni->insert (ni->begin (),
NiChange (event->GetStartTime (), noiseInterference));
265 ni->push_back (
NiChange (event->GetEndTime (), 0));
266 return noiseInterference;
277 uint64_t nbits = (uint64_t)(rate * duration.
GetSeconds ());
278 double csr =
m_errorRateModel->GetChunkSuccessRate (mode, txVector, snir, (uint32_t)nbits);
287 NiChanges::iterator j = ni->begin ();
288 Time previous = (*j).GetTime ();
289 WifiMode payloadMode =
event->GetPayloadMode ();
295 double noiseInterferenceW = (*j).GetDelta ();
296 double powerW =
event->GetRxPowerW ();
298 while (ni->end () != j)
300 Time current = (*j).GetTime ();
301 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
304 if (previous >= plcpPayloadStart)
308 event->GetTxVector ().GetChannelWidth ()),
310 payloadMode, event->GetTxVector ());
312 NS_LOG_DEBUG (
"Both previous and current point to the payload: mode=" << payloadMode <<
", psr=" << psr);
315 else if (current >= plcpPayloadStart)
319 event->GetTxVector ().GetChannelWidth ()),
320 current - plcpPayloadStart,
321 payloadMode, event->GetTxVector ());
322 NS_LOG_DEBUG (
"previous is before payload and current is in the payload: mode=" << payloadMode <<
", psr=" << psr);
325 noiseInterferenceW += (*j).GetDelta ();
326 previous = (*j).GetTime ();
330 double per = 1 - psr;
339 NiChanges::iterator j = ni->begin ();
340 Time previous = (*j).GetTime ();
341 WifiMode payloadMode =
event->GetPayloadMode ();
359 double noiseInterferenceW = (*j).GetDelta ();
360 double powerW =
event->GetRxPowerW ();
362 while (ni->end () != j)
364 Time current = (*j).GetTime ();
365 NS_LOG_DEBUG (
"previous= " << previous <<
", current=" << current);
368 if (previous >= plcpPayloadStart)
371 NS_LOG_DEBUG (
"Case 1 - previous and current after playload start: nothing to do");
374 else if (previous >= plcpHtTrainingSymbolsStart)
378 if (current >= plcpPayloadStart)
382 event->GetTxVector ().GetChannelWidth ()),
383 plcpPayloadStart - previous,
384 htHeaderMode, event->GetTxVector ());
386 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);
393 event->GetTxVector ().GetChannelWidth ()),
395 htHeaderMode, event->GetTxVector ());
397 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);
401 else if (previous >= plcpHsigHeaderStart)
405 if (current >= plcpPayloadStart)
409 event->GetTxVector ().GetChannelWidth ()),
410 plcpPayloadStart - plcpHtTrainingSymbolsStart,
411 htHeaderMode, event->GetTxVector ());
419 event->GetTxVector ().GetChannelWidth ()),
420 plcpHtTrainingSymbolsStart - previous,
421 headerMode, event->GetTxVector ());
423 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);
430 event->GetTxVector ().GetChannelWidth ()),
431 plcpHtTrainingSymbolsStart - previous,
432 htHeaderMode, event->GetTxVector ());
434 NS_LOG_DEBUG (
"Case 3aii - previous is in HT-SIG and current after payload start: mode=" << htHeaderMode <<
", psr=" << psr);
438 else if (current >= plcpHtTrainingSymbolsStart)
442 event->GetTxVector ().GetChannelWidth ()),
443 current - plcpHtTrainingSymbolsStart,
444 htHeaderMode, event->GetTxVector ());
452 event->GetTxVector ().GetChannelWidth ()),
453 plcpHtTrainingSymbolsStart - previous,
454 headerMode, event->GetTxVector ());
456 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);
463 event->GetTxVector ().GetChannelWidth ()),
464 plcpHtTrainingSymbolsStart - previous,
465 htHeaderMode, event->GetTxVector ());
467 NS_LOG_DEBUG (
"Case 3bii - previous is in HT-SIG and current is in HT training: mode=" << htHeaderMode <<
", psr=" << psr);
479 event->GetTxVector ().GetChannelWidth ()),
481 headerMode, event->GetTxVector ());
483 NS_LOG_DEBUG (
"Case 3ci - previous with current in VHT-SIG-A: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
490 event->GetTxVector ().GetChannelWidth ()),
492 htHeaderMode, event->GetTxVector ());
494 NS_LOG_DEBUG (
"Case 3cii - previous with current in HT-SIG: mode=" << htHeaderMode <<
", psr=" << psr);
499 else if (previous >= plcpHeaderStart)
503 if (current >= plcpPayloadStart)
510 event->GetTxVector ().GetChannelWidth ()),
511 plcpPayloadStart - previous,
512 headerMode, event->GetTxVector ());
514 NS_LOG_DEBUG (
"Case 4ai - previous in L-SIG and current after payload start: mode=" << headerMode <<
", psr=" << psr);
521 event->GetTxVector ().GetChannelWidth ()),
522 plcpPayloadStart - plcpHtTrainingSymbolsStart,
523 htHeaderMode, event->GetTxVector ());
527 event->GetTxVector ().GetChannelWidth ()),
528 plcpHtTrainingSymbolsStart - previous,
529 headerMode, event->GetTxVector ());
531 NS_LOG_DEBUG (
"Case 4aii - previous is in L-SIG and current after payload start: VHT mode=" << htHeaderMode <<
", non-VHT mode=" << headerMode <<
", psr=" << psr);
538 event->GetTxVector ().GetChannelWidth ()),
539 plcpPayloadStart - plcpHsigHeaderStart,
540 htHeaderMode, event->GetTxVector ());
544 event->GetTxVector ().GetChannelWidth ()),
545 plcpHsigHeaderStart - previous,
546 headerMode, event->GetTxVector ());
548 NS_LOG_DEBUG (
"Case 4aiii - previous in L-SIG and current after payload start: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
552 else if (current >= plcpHtTrainingSymbolsStart)
561 event->GetTxVector ().GetChannelWidth ()),
562 current - plcpHtTrainingSymbolsStart,
563 htHeaderMode, event->GetTxVector ());
567 event->GetTxVector ().GetChannelWidth ()),
568 plcpHtTrainingSymbolsStart - previous,
569 headerMode, event->GetTxVector ());
571 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);
578 event->GetTxVector ().GetChannelWidth ()),
579 current - plcpHsigHeaderStart,
580 htHeaderMode, event->GetTxVector ());
584 event->GetTxVector ().GetChannelWidth ()),
585 plcpHsigHeaderStart - previous,
586 headerMode, event->GetTxVector ());
588 NS_LOG_DEBUG (
"Case 4bii - previous in L-SIG and current in HT training: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
592 else if (current >= plcpHsigHeaderStart)
601 event->GetTxVector ().GetChannelWidth ()),
603 headerMode, event->GetTxVector ());
605 NS_LOG_DEBUG (
"Case 4ci - previous is in L-SIG and current in VHT-SIG-A: mode=" << headerMode <<
", psr=" << psr);
612 event->GetTxVector ().GetChannelWidth ()),
613 current - plcpHsigHeaderStart,
614 htHeaderMode, event->GetTxVector ());
618 event->GetTxVector ().GetChannelWidth ()),
619 plcpHsigHeaderStart - previous,
620 headerMode, event->GetTxVector ());
622 NS_LOG_DEBUG (
"Case 4cii - previous in L-SIG and current in HT-SIG: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
630 event->GetTxVector ().GetChannelWidth ()),
632 headerMode, event->GetTxVector ());
634 NS_LOG_DEBUG (
"Case 3c - current with previous in L-SIG: mode=" << headerMode <<
", psr=" << psr);
641 if (current >= plcpPayloadStart)
648 event->GetTxVector ().GetChannelWidth ()),
649 plcpPayloadStart - plcpHeaderStart,
650 headerMode, event->GetTxVector ());
652 NS_LOG_DEBUG (
"Case 5a - previous is in the preamble and current is after payload start: mode=" << headerMode <<
", psr=" << psr);
659 event->GetTxVector ().GetChannelWidth ()),
660 plcpPayloadStart - plcpHtTrainingSymbolsStart,
661 htHeaderMode, event->GetTxVector ());
665 event->GetTxVector ().GetChannelWidth ()),
666 plcpHtTrainingSymbolsStart - plcpHeaderStart,
667 headerMode, event->GetTxVector ());
669 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);
677 event->GetTxVector ().GetChannelWidth ()),
678 plcpPayloadStart - plcpHsigHeaderStart,
679 htHeaderMode, event->GetTxVector ());
683 event->GetTxVector ().GetChannelWidth ()),
684 plcpHsigHeaderStart - plcpHeaderStart,
685 headerMode, event->GetTxVector ());
687 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);
691 else if (current >= plcpHtTrainingSymbolsStart)
700 event->GetTxVector ().GetChannelWidth ()),
701 current - plcpHtTrainingSymbolsStart,
702 htHeaderMode, event->GetTxVector ());
706 event->GetTxVector ().GetChannelWidth ()),
707 plcpHtTrainingSymbolsStart - plcpHeaderStart,
708 headerMode, event->GetTxVector ());
710 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);
717 event->GetTxVector ().GetChannelWidth ()),
718 current - plcpHsigHeaderStart,
719 htHeaderMode, event->GetTxVector ());
723 event->GetTxVector ().GetChannelWidth ()),
724 plcpHsigHeaderStart - plcpHeaderStart,
725 headerMode, event->GetTxVector ());
727 NS_LOG_DEBUG (
"Case 5bii - previous is in the preamble and current in HT training: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
731 else if (current >= plcpHsigHeaderStart)
740 event->GetTxVector ().GetChannelWidth ()),
741 current - plcpHeaderStart,
742 headerMode, event->GetTxVector ());
744 NS_LOG_DEBUG (
"Case 5ci - previous is in preamble and current in VHT-SIG-A: mode=" << headerMode <<
", psr=" << psr);
751 event->GetTxVector ().GetChannelWidth ()),
752 current - plcpHsigHeaderStart,
753 htHeaderMode, event->GetTxVector ());
757 event->GetTxVector ().GetChannelWidth ()),
758 plcpHsigHeaderStart - plcpHeaderStart,
759 headerMode, event->GetTxVector ());
761 NS_LOG_DEBUG (
"Case 5cii - previous in preamble and current in HT-SIG: HT mode=" << htHeaderMode <<
", non-HT mode=" << headerMode <<
", psr=" << psr);
765 else if (current >= plcpHeaderStart)
771 event->GetTxVector ().GetChannelWidth ()),
772 current - plcpHeaderStart,
773 headerMode, event->GetTxVector ());
775 NS_LOG_DEBUG (
"Case 5d - previous is in the preamble and current is in L-SIG: mode=" << headerMode <<
", psr=" << psr);
779 noiseInterferenceW += (*j).GetDelta ();
780 previous = (*j).GetTime ();
784 double per = 1 - psr;
795 event->GetTxVector ().GetChannelWidth ());
815 event->GetTxVector ().GetChannelWidth ());
836 InterferenceHelper::NiChanges::iterator
Simulation virtual time values and global simulation resolution.
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)