A Discrete-Event Network Simulator
API
interference-helper.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef INTERFERENCE_HELPER_H
22 #define INTERFERENCE_HELPER_H
23 
24 #include "ns3/nstime.h"
25 #include "ns3/packet.h"
26 #include "wifi-tx-vector.h"
27 #include "error-rate-model.h"
28 #include <map>
29 
30 namespace ns3 {
31 
37 {
38 public:
42  class Event : public SimpleRefCount<InterferenceHelper::Event>
43  {
44 public:
53  Event (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPower);
54  ~Event ();
55 
60  Ptr<const Packet> GetPacket (void) const;
66  Time GetStartTime (void) const;
72  Time GetEndTime (void) const;
78  double GetRxPowerW (void) const;
84  WifiTxVector GetTxVector (void) const;
90  WifiMode GetPayloadMode (void) const;
91 
92 
93 private:
98  double m_rxPowerW;
99  };
100 
104  struct SnrPer
105  {
106  double snr;
107  double per;
108  };
109 
112 
118  void SetNoiseFigure (double value);
124  void SetErrorRateModel (const Ptr<ErrorRateModel> rate);
125 
131  double GetNoiseFigure (void) const;
144  void SetNumberOfReceiveAntennas (uint8_t rx);
145 
153  Time GetEnergyDuration (double energyW) const;
154 
165  Ptr<InterferenceHelper::Event> Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPower);
166 
172  void AddForeignSignal (Time duration, double rxPower);
190  struct InterferenceHelper::SnrPer CalculatePlcpHeaderSnrPer (Ptr<InterferenceHelper::Event> event) const;
191 
195  void NotifyRxStart ();
199  void NotifyRxEnd ();
203  void EraseEvents (void);
204 
205 
206 private:
210  class NiChange
211  {
212 public:
219  NiChange (double power, Ptr<InterferenceHelper::Event> event);
225  double GetPower (void) const;
231  void AddPower (double power);
237  Ptr<InterferenceHelper::Event> GetEvent (void) const;
238 
239 
240 private:
241  double m_power;
243  };
244 
248  typedef std::multimap<Time, NiChange> NiChanges;
249 
255  void AppendEvent (Ptr<Event> event);
264  double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const;
275  double CalculateSnr (double signal, double noiseInterference, uint8_t channelWidth) const;
287  double CalculateChunkSuccessRate (double snir, Time duration, WifiMode mode, WifiTxVector txVector) const;
297  double CalculatePlcpPayloadPer (Ptr<const Event> event, NiChanges *ni) const;
307  double CalculatePlcpHeaderPer (Ptr<const Event> event, NiChanges *ni) const;
308 
309  double m_noiseFigure;
311  uint8_t m_numRxAntennas;
312  NiChanges m_niChanges;
314  double m_firstPower;
315  bool m_rxing;
316 
323  NiChanges::const_iterator GetNextPosition (Time moment) const;
330  //NiChanges::iterator GetNextPosition (Time moment);
337  NiChanges::const_iterator GetPreviousPosition (Time moment) const;
338 
347  NiChanges::iterator AddNiChangeEvent (Time moment, NiChange change);
348 };
349 
350 } //namespace ns3
351 
352 #endif /* INTERFERENCE_HELPER_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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.
NiChanges::iterator AddNiChangeEvent(Time moment, NiChange change)
Add NiChange to the list at the appropriate position and return the iterator of the new event...
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...
Signal event for a packet.
handles interference calculations
Ptr< const Packet > m_packet
packet
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...
Definition: wifi-mode.h:97
Ptr< const Packet > GetPacket(void) const
Return the packet.
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.
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.
Ptr< InterferenceHelper::Event > m_event
event
NiChanges m_niChanges
Experimental: needed for energy duration calculation.
double CalculatePlcpPayloadPer(Ptr< const Event > event, NiChanges *ni) const
Calculate the error rate of the given plcp payload.
struct InterferenceHelper::SnrPer CalculatePlcpHeaderSnrPer(Ptr< InterferenceHelper::Event > event) const
Calculate the SNIR at the start of the plcp header and accumulate all SNIR changes in the snir vector...
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.
uint8_t m_numRxAntennas
the number of RX antennas in the corresponding receiver
Time GetEndTime(void) const
Return the end time of the signal.
double m_rxPowerW
receive power in watts
WifiTxVector m_txVector
TXVECTOR.
void NotifyRxEnd()
Notify that RX has ended.
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.
void AppendEvent(Ptr< Event > event)
Append the given Event.
NiChanges::const_iterator GetPreviousPosition(Time moment) const
Returns an iterator to the first nichange that is later than moment.
double GetNoiseFigure(void) const
Return the noise figure.
A template-based reference counting class.
NiChanges::const_iterator GetNextPosition(Time moment) const
Returns an iterator to the first nichange that is later than moment.
double CalculateSnr(double signal, double noiseInterference, uint8_t channelWidth) const
Calculate SNR (linear ratio) from the given signal power and noise+interference power.
struct InterferenceHelper::SnrPer CalculatePlcpPayloadSnrPer(Ptr< InterferenceHelper::Event > event) const
Calculate the SNIR at the start of the plcp payload and accumulate all SNIR changes in the snir vecto...
std::multimap< Time, NiChange > NiChanges
typedef for a multimap of NiChanges
bool m_rxing
flag whether it is in receiving state