A Discrete-Event Network Simulator
API
spectrum-interference.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 CTTC
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Nicola Baldo <nbaldo@cttc.es>
18  */
19 
20 #include "spectrum-interference.h"
21 
22 #include "spectrum-error-model.h"
23 
24 #include <ns3/log.h>
25 #include <ns3/simulator.h>
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("SpectrumInterference");
31 
33  : m_receiving(false),
34  m_rxSignal(nullptr),
35  m_allSignals(nullptr),
36  m_noise(nullptr),
37  m_errorModel(nullptr)
38 {
39  NS_LOG_FUNCTION(this);
40 }
41 
43 {
44  NS_LOG_FUNCTION(this);
45 }
46 
47 TypeId
49 {
50  static TypeId tid = TypeId("ns3::SpectrumInterference")
51  .SetParent<Object>()
52  .SetGroupName("Spectrum")
53  .AddConstructor<SpectrumInterference>();
54  return tid;
55 }
56 
57 void
59 {
60  NS_LOG_FUNCTION(this);
61  m_rxSignal = nullptr;
62  m_allSignals = nullptr;
63  m_noise = nullptr;
64  m_errorModel = nullptr;
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION(this << p << *rxPsd);
72  m_rxSignal = rxPsd;
74  m_receiving = true;
75  m_errorModel->StartRx(p);
76 }
77 
78 void
80 {
81  m_receiving = false;
82 }
83 
84 bool
86 {
87  NS_LOG_FUNCTION(this);
89  m_receiving = false;
90  return m_errorModel->IsRxCorrect();
91 }
92 
93 void
95 {
96  NS_LOG_FUNCTION(this << *spd << duration);
97  DoAddSignal(spd);
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this << *spd);
106  (*m_allSignals) += (*spd);
107  m_lastChangeTime = Now();
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION(this << *spd);
115  (*m_allSignals) -= (*spd);
116  m_lastChangeTime = Now();
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION(this);
123  NS_LOG_LOGIC("m_receiving: " << m_receiving);
124  NS_LOG_LOGIC("m_lastChangeTime: " << m_lastChangeTime << " Now: " << Now());
125  bool condition = m_receiving && (Now() > m_lastChangeTime);
126  NS_LOG_LOGIC("if condition: " << condition);
127  if (condition)
128  {
129  SpectrumValue sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
130  Time duration = Now() - m_lastChangeTime;
131  NS_LOG_LOGIC("calling m_errorModel->EvaluateChunk (sinr, duration)");
132  m_errorModel->EvaluateChunk(sinr, duration);
133  }
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION(this << noisePsd);
140  m_noise = noisePsd;
141  // we can initialize m_allSignal only now, because earlier we
142  // didn't know what spectrum model was going to be used.
143  // we'll now create a zeroed SpectrumValue using the same
144  // SpectrumModel which is being specified for the noise.
145  m_allSignals = Create<SpectrumValue>(noisePsd->GetSpectrumModel());
146 }
147 
148 void
150 {
151  NS_LOG_FUNCTION(this << e);
152  m_errorModel = e;
153 }
154 
155 } // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
This class implements a gaussian interference model, i.e., all incoming signals are added to the tota...
void AbortRx()
Notify that the PHY has aborted RX.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the Noise Power Spectral Density.
void ConditionallyEvaluateChunk()
Evaluate a Chunk, depending on the Rx status and the last update time.
Ptr< SpectrumValue > m_allSignals
Stores the spectral power density of the sum of incoming signals; does not include noise,...
bool EndRx()
Notify that the RX attempt has ended.
Time m_lastChangeTime
the time of the last change in m_TotalPower
bool m_receiving
True if in Rx status.
static TypeId GetTypeId()
Register this type.
Ptr< const SpectrumValue > m_noise
Noise spectral power density.
void SetErrorModel(Ptr< SpectrumErrorModel > e)
Set the SpectrumErrorModel to be used.
void DoSubtractSignal(Ptr< const SpectrumValue > spd)
Removes a signal perceived in the medium.
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
Notify that the PHY is starting a RX attempt.
Ptr< SpectrumErrorModel > m_errorModel
Error model.
void DoAddSignal(Ptr< const SpectrumValue > spd)
Adds a signal perceived in the medium.
void DoDispose() override
Destructor implementation.
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
Notify that a new signal is being perceived in the medium.
Ptr< const SpectrumValue > m_rxSignal
Stores the power spectral density of the signal whose RX is being attempted.
Set of values corresponding to a given SpectrumModel.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
Every class exported by the ns3 library is enclosed in the ns3 namespace.