A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-interference.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "lte-interference.h"
10
11#include "lte-chunk-processor.h"
12
13#include <ns3/log.h>
14#include <ns3/simulator.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("LteInterference");
20
22 : m_receiving(false),
23 m_lastSignalId(0),
24 m_lastSignalIdBeforeReset(0)
25{
26 NS_LOG_FUNCTION(this);
27}
28
33
34void
36{
37 NS_LOG_FUNCTION(this);
41 m_rxSignal = nullptr;
42 m_allSignals = nullptr;
43 m_noise = nullptr;
45}
46
49{
50 static TypeId tid = TypeId("ns3::LteInterference").SetParent<Object>().SetGroupName("Lte");
51 return tid;
52}
53
54void
56{
57 NS_LOG_FUNCTION(this << *rxPsd);
58 if (!m_receiving)
59 {
60 NS_LOG_LOGIC("first signal");
61 m_rxSignal = rxPsd->Copy();
63 m_receiving = true;
64 for (auto it = m_rsPowerChunkProcessorList.begin(); it != m_rsPowerChunkProcessorList.end();
65 ++it)
66 {
67 (*it)->Start();
68 }
69 for (auto it = m_interfChunkProcessorList.begin(); it != m_interfChunkProcessorList.end();
70 ++it)
71 {
72 (*it)->Start();
73 }
74 for (auto it = m_sinrChunkProcessorList.begin(); it != m_sinrChunkProcessorList.end(); ++it)
75 {
76 (*it)->Start();
77 }
78 }
79 else
80 {
81 NS_LOG_LOGIC("additional signal" << *m_rxSignal);
82 // receiving multiple simultaneous signals, make sure they are synchronized
84 // make sure they use orthogonal resource blocks
85 NS_ASSERT(Sum((*rxPsd) * (*m_rxSignal)) == 0.0);
86 (*m_rxSignal) += (*rxPsd);
87 }
88}
89
90void
92{
93 NS_LOG_FUNCTION(this);
94 if (!m_receiving)
95 {
96 NS_LOG_INFO("EndRx was already evaluated or RX was aborted");
97 }
98 else
99 {
101 m_receiving = false;
102 for (auto it = m_rsPowerChunkProcessorList.begin(); it != m_rsPowerChunkProcessorList.end();
103 ++it)
104 {
105 (*it)->End();
106 }
107 for (auto it = m_interfChunkProcessorList.begin(); it != m_interfChunkProcessorList.end();
108 ++it)
109 {
110 (*it)->End();
111 }
112 for (auto it = m_sinrChunkProcessorList.begin(); it != m_sinrChunkProcessorList.end(); ++it)
113 {
114 (*it)->End();
115 }
116 }
117}
118
119void
121{
122 NS_LOG_FUNCTION(this << *spd << duration);
123 DoAddSignal(spd);
124 uint32_t signalId = ++m_lastSignalId;
125 if (signalId == m_lastSignalIdBeforeReset)
126 {
127 // This happens when m_lastSignalId eventually wraps around. Given that so
128 // many signals have elapsed since the last reset, we hope that by now there is
129 // no stale pending signal (i.e., a signal that was scheduled
130 // for subtraction before the reset). So we just move the
131 // boundary further.
132 m_lastSignalIdBeforeReset += 0x10000000;
133 }
134 Simulator::Schedule(duration, &LteInterference::DoSubtractSignal, this, spd, signalId);
135}
136
137void
139{
140 NS_LOG_FUNCTION(this << *spd);
142 (*m_allSignals) += (*spd);
143}
144
145void
147{
148 NS_LOG_FUNCTION(this << *spd);
150 int32_t deltaSignalId = signalId - m_lastSignalIdBeforeReset;
151 if (deltaSignalId > 0)
152 {
153 (*m_allSignals) -= (*spd);
154 }
155 else
156 {
157 NS_LOG_INFO("ignoring signal scheduled for subtraction before last reset");
158 }
159}
160
161void
163{
164 NS_LOG_FUNCTION(this);
165 if (m_receiving)
166 {
167 NS_LOG_DEBUG(this << " Receiving");
168 }
169 NS_LOG_DEBUG(this << " now " << Now() << " last " << m_lastChangeTime);
170 if (m_receiving && (Now() > m_lastChangeTime))
171 {
172 NS_LOG_LOGIC(this << " signal = " << *m_rxSignal << " allSignals = " << *m_allSignals
173 << " noise = " << *m_noise);
174
175 SpectrumValue interf = (*m_allSignals) - (*m_rxSignal) + (*m_noise);
176
177 SpectrumValue sinr = (*m_rxSignal) / interf;
178 Time duration = Now() - m_lastChangeTime;
179 for (auto it = m_sinrChunkProcessorList.begin(); it != m_sinrChunkProcessorList.end(); ++it)
180 {
181 (*it)->EvaluateChunk(sinr, duration);
182 }
183 for (auto it = m_interfChunkProcessorList.begin(); it != m_interfChunkProcessorList.end();
184 ++it)
185 {
186 (*it)->EvaluateChunk(interf, duration);
187 }
188 for (auto it = m_rsPowerChunkProcessorList.begin(); it != m_rsPowerChunkProcessorList.end();
189 ++it)
190 {
191 (*it)->EvaluateChunk(*m_rxSignal, duration);
192 }
194 }
195}
196
197void
199{
200 NS_LOG_FUNCTION(this << *noisePsd);
202 m_noise = noisePsd;
203 // reset m_allSignals (will reset if already set previously)
204 // this is needed since this method can potentially change the SpectrumModel
205 m_allSignals = Create<SpectrumValue>(noisePsd->GetSpectrumModel());
206 if (m_receiving)
207 {
208 // abort rx
209 m_receiving = false;
210 }
211 // record the last SignalId so that we can ignore all signals that
212 // were scheduled for subtraction before m_allSignal
214}
215
216void
222
223void
229
230void
236
237} // namespace ns3
static TypeId GetTypeId()
Get the type ID.
virtual void DoSubtractSignal(Ptr< const SpectrumValue > spd, uint32_t signalId)
Subtract signal.
Ptr< SpectrumValue > m_rxSignal
stores the power spectral density of the signal whose RX is being attempted
bool m_receiving
are we receiving?
virtual void AddSinrChunkProcessor(Ptr< LteChunkProcessor > p)
Add a LteChunkProcessor that will use the time-vs-frequency SINR calculated by this LteInterference i...
virtual void ConditionallyEvaluateChunk()
Conditionally evaluate chunk.
virtual void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Ptr< SpectrumValue > m_allSignals
stores the spectral power density of the sum of incoming signals; does not include noise,...
virtual void EndRx()
notify that the RX attempt has ended.
uint32_t m_lastSignalIdBeforeReset
the last signal ID before reset
std::list< Ptr< LteChunkProcessor > > m_rsPowerChunkProcessorList
all the processor instances that need to be notified whenever a new interference chunk is calculated
virtual void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
notify that a new signal is being perceived in the medium.
virtual void AddInterferenceChunkProcessor(Ptr< LteChunkProcessor > p)
Add a LteChunkProcessor that will use the time-vs-frequency interference calculated by this LteInterf...
Ptr< const SpectrumValue > m_noise
the noise value
virtual void AddRsPowerChunkProcessor(Ptr< LteChunkProcessor > p)
Add a LteChunkProcessor that will use the time-vs-frequency power calculated by this LteInterference ...
Time m_lastChangeTime
the time of the last change in m_TotalPower
std::list< Ptr< LteChunkProcessor > > m_interfChunkProcessorList
all the processor instances that need to be notified whenever a new interference chunk is calculated
virtual void StartRx(Ptr< const SpectrumValue > rxPsd)
Notify that the PHY is starting a RX attempt.
void DoDispose() override
Destructor implementation.
uint32_t m_lastSignalId
the last signal ID
std::list< Ptr< LteChunkProcessor > > m_sinrChunkProcessorList
all the processor instances that need to be notified whenever a new SINR chunk is calculated
virtual void DoAddSignal(Ptr< const SpectrumValue > spd)
Add signal function.
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
Set of values corresponding to a given SpectrumModel.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double Sum(const SpectrumValue &x)