23 #include "ns3/simulator.h"
39 m_payloadMode (payloadMode),
40 m_preamble (preamble),
42 m_endTime (m_startTime + duration),
54 return m_endTime - m_startTime;
117 return (m_time < o.
m_time);
143 event = Create<InterferenceHelper::Event> (size,
182 double noiseInterferenceW = 0.0;
187 noiseInterferenceW += i->GetDelta ();
193 if (noiseInterferenceW < energyW)
198 return end > now ? end - now : MicroSeconds (0);
207 NiChanges::iterator nowIterator =
GetPosition (now);
208 for (NiChanges::iterator i =
m_niChanges.begin (); i != nowIterator; i++)
228 static const double BOLTZMANN = 1.3803e-23;
233 double noise = noiseFloor + noiseInterference;
234 double snr = signal / noise;
245 if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
251 ni->insert (ni->begin (),
NiChange (event->GetStartTime (), noiseInterference));
252 ni->push_back (
NiChange (event->GetEndTime (), 0));
253 return noiseInterference;
259 if (duration == NanoSeconds (0))
264 uint64_t nbits = (uint64_t)(rate * duration.
GetSeconds ());
265 double csr =
m_errorRateModel->GetChunkSuccessRate (mode, snir, (uint32_t)nbits);
273 NiChanges::iterator j = ni->begin ();
274 Time previous = (*j).GetTime ();
275 WifiMode payloadMode =
event->GetPayloadMode ();
288 double noiseInterferenceW = (*j).GetDelta ();
289 double powerW =
event->GetRxPowerW ();
291 while (ni->end () != j)
296 if (previous >= plcpPayloadStart)
305 else if (previous >= plcpHtTrainingSymbolsStart)
308 if (current >= plcpPayloadStart)
314 current - plcpPayloadStart,
320 else if (previous >=plcpHsigHeaderStart)
323 if (current >=plcpPayloadStart)
328 current - plcpPayloadStart,
334 plcpHtTrainingSymbolsStart - previous,
338 else if (current >=plcpHtTrainingSymbolsStart)
343 plcpHtTrainingSymbolsStart - previous,
359 else if (previous >= plcpHeaderStart)
362 if (current >=plcpPayloadStart)
367 current - plcpPayloadStart,
375 plcpPayloadStart - previous,
383 plcpHtTrainingSymbolsStart - plcpHsigHeaderStart,
388 plcpHsigHeaderStart - previous,
393 else if (current >=plcpHtTrainingSymbolsStart)
398 plcpHtTrainingSymbolsStart - plcpHsigHeaderStart,
403 plcpHsigHeaderStart - previous,
407 else if (current >=plcpHsigHeaderStart)
412 current - plcpHsigHeaderStart,
417 plcpHsigHeaderStart - previous,
446 if (current >= plcpPayloadStart)
452 current - plcpPayloadStart,
460 plcpPayloadStart - plcpHeaderStart,
467 plcpHtTrainingSymbolsStart - plcpHsigHeaderStart,
473 plcpHsigHeaderStart-plcpHeaderStart,
476 else if (current >=plcpHtTrainingSymbolsStart )
483 plcpHtTrainingSymbolsStart - plcpHsigHeaderStart,
489 plcpHsigHeaderStart-plcpHeaderStart,
493 else if (current >=plcpHsigHeaderStart)
498 current- plcpHsigHeaderStart,
505 plcpHsigHeaderStart-plcpHeaderStart,
510 else if (current >= plcpHeaderStart)
517 current - plcpHeaderStart,
525 current - plcpHeaderStart,
531 noiseInterferenceW += (*j).GetDelta ();
532 previous = (*j).GetTime ();
536 double per = 1 - psr;
548 event->GetPayloadMode ());
568 InterferenceHelper::NiChanges::iterator
static uint32_t GetPlcpHeaderDurationMicroSeconds(WifiMode payloadMode, WifiPreamble preamble)
keep track of time values and allow control of global simulation resolution
A struct for both SNR and PER.
smart pointer class similar to boost::intrusive_ptr
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...
double CalculatePer(Ptr< const Event > event, NiChanges *ni) const
Calculate the error rate of the given packet.
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
#define NS_ASSERT(condition)
Time GetEnergyDuration(double energyW)
static WifiMode GetMFPlcpHeaderMode(WifiMode payloadMode, WifiPreamble preamble)
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).
double CalculateChunkSuccessRate(double snir, Time duration, WifiMode mode) const
Calculate the success rate of the chunk given the SINR, duration, and Wi-Fi mode. ...
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
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.
NiChanges m_niChanges
Experimental: needed for energy duration calculation.
void AddNiChangeEvent(NiChange change)
Add NiChange to the list at the appropriate position.
static WifiMode GetPlcpHeaderMode(WifiMode payloadMode, WifiPreamble preamble)
Time GetTime(void) const
Return the event time.
Ptr< InterferenceHelper::Event > Add(uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble, Time duration, double rxPower, WifiTxVector txvector)
Add the packet-related signal to interference helper.
uint32_t GetBandwidth(void) const
double m_noiseFigure
noise figure (linear)
void NotifyRxStart()
Notify that RX has started.
Noise and Interference (thus Ni) event.
void EraseEvents(void)
Erase all events.
uint64_t GetPhyRate(void) const
static uint32_t GetPlcpHtTrainingSymbolDurationMicroSeconds(WifiMode payloadMode, WifiPreamble preamble, WifiTxVector txvector)
double GetDelta(void) const
Return the power.
static Time Now(void)
Return the "current simulation time".
Time GetEndTime(void) const
Return the end time of the signal.
enum WifiPreamble GetPreambleType(void) const
Return the preamble type of the packet.
NS_LOG_COMPONENT_DEFINE("InterferenceHelper")
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.
Time GetDuration(void) const
Return the duration of the signal.
void SetNoiseFigure(double value)
Set the noise figure.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
WifiMode GetPayloadMode(void) const
Return the Wi-Fi mode used for the payload.
Event(uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble, Time duration, double rxPower, WifiTxVector txvector)
Create an Event with the given parameters.
double CalculateSnr(double signal, double noiseInterference, WifiMode mode) const
Calculate SNR (linear ratio) from the given signal power and noise+interference power.
void AppendEvent(Ptr< Event > event)
Append the given Event.
double GetNoiseFigure(void) const
Return the noise figure.
static uint32_t GetPlcpPreambleDurationMicroSeconds(WifiMode payloadMode, WifiPreamble preamble)
static uint32_t GetPlcpHtSigHeaderDurationMicroSeconds(WifiMode payloadMode, WifiPreamble preamble)