A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
lte-interference.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
22
#include "
lte-interference.h
"
23
#include "
lte-sinr-chunk-processor.h
"
24
25
#include <ns3/simulator.h>
26
#include <ns3/log.h>
27
28
29
NS_LOG_COMPONENT_DEFINE
(
"LteInterference"
);
30
31
namespace
ns3 {
32
33
34
LteInterference::LteInterference
()
35
: m_receiving (false)
36
{
37
NS_LOG_FUNCTION
(
this
);
38
}
39
40
LteInterference::~LteInterference
()
41
{
42
NS_LOG_FUNCTION
(
this
);
43
}
44
45
void
46
LteInterference::DoDispose
()
47
{
48
NS_LOG_FUNCTION
(
this
);
49
m_sinrChunkProcessorList
.clear ();
50
m_rxSignal
= 0;
51
m_allSignals
= 0;
52
m_noise
= 0;
53
Object::DoDispose
();
54
}
55
56
57
TypeId
58
LteInterference::GetTypeId
(
void
)
59
{
60
static
TypeId
tid =
TypeId
(
"ns3::LteInterference"
)
61
.
SetParent
<
Object
> ()
62
;
63
return
tid;
64
}
65
66
67
void
68
LteInterference::StartRx
(
Ptr<const SpectrumValue>
rxPsd)
69
{
70
NS_LOG_FUNCTION
(
this
<< *rxPsd);
71
if
(
m_receiving
==
false
)
72
{
73
NS_LOG_LOGIC
(
"first signal"
);
74
m_rxSignal
= rxPsd->
Copy
();
75
m_lastChangeTime
=
Now
();
76
m_receiving
=
true
;
77
for
(
std::list
<
Ptr<LteSinrChunkProcessor>
>::const_iterator it =
m_sinrChunkProcessorList
.begin (); it !=
m_sinrChunkProcessorList
.end (); ++it)
78
{
79
(*it)->Start ();
80
}
81
}
82
else
83
{
84
NS_LOG_LOGIC
(
"additional signal"
<< *
m_rxSignal
);
85
// receiving multiple simultaneous signals, make sure they are synchronized
86
NS_ASSERT
(
m_lastChangeTime
==
Now
());
87
// make sure they use orthogonal resource blocks
88
NS_ASSERT
(
Sum
((*rxPsd) * (*
m_rxSignal
)) == 0.0);
89
(*m_rxSignal) += (*rxPsd);
90
}
91
}
92
93
94
void
95
LteInterference::EndRx
()
96
{
97
NS_LOG_FUNCTION
(
this
);
98
ConditionallyEvaluateChunk
();
99
m_receiving
=
false
;
100
for
(
std::list
<
Ptr<LteSinrChunkProcessor>
>::const_iterator it =
m_sinrChunkProcessorList
.begin (); it !=
m_sinrChunkProcessorList
.end (); ++it)
101
{
102
(*it)->End ();
103
}
104
}
105
106
107
void
108
LteInterference::AddSignal
(
Ptr<const SpectrumValue>
spd,
const
Time
duration)
109
{
110
NS_LOG_FUNCTION
(
this
<< *spd << duration);
111
// if this is the first signal that we see, we need to initialize the interference calculation
112
if
(
m_allSignals
== 0)
113
{
114
m_allSignals
= Create<SpectrumValue> (spd->
GetSpectrumModel
());
115
}
116
DoAddSignal
(spd);
117
Simulator::Schedule
(duration, &
LteInterference::DoSubtractSignal
,
this
, spd);
118
}
119
120
121
void
122
LteInterference::DoAddSignal
(
Ptr<const SpectrumValue>
spd)
123
{
124
NS_LOG_FUNCTION
(
this
<< *spd);
125
ConditionallyEvaluateChunk
();
126
(*m_allSignals) += (*spd);
127
m_lastChangeTime
=
Now
();
128
}
129
130
void
131
LteInterference::DoSubtractSignal
(
Ptr<const SpectrumValue>
spd)
132
{
133
NS_LOG_FUNCTION
(
this
<< *spd);
134
ConditionallyEvaluateChunk
();
135
(*m_allSignals) -= (*spd);
136
m_lastChangeTime
=
Now
();
137
}
138
139
140
void
141
LteInterference::ConditionallyEvaluateChunk
()
142
{
143
NS_LOG_FUNCTION
(
this
);
144
if
(
m_receiving
)
145
{
146
NS_LOG_DEBUG
(
this
<<
" Receiving"
);
147
}
148
NS_LOG_DEBUG
(
this
<<
" now "
<<
Now
() <<
" last "
<<
m_lastChangeTime
);
149
if
(
m_receiving
&& (
Now
() >
m_lastChangeTime
))
150
{
151
NS_LOG_LOGIC
(
this
<<
" signal = "
<< *
m_rxSignal
<<
" allSignals = "
<< *
m_allSignals
<<
" noise = "
<< *
m_noise
);
152
153
SpectrumValue
sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
154
Time
duration =
Now
() -
m_lastChangeTime
;
155
for
(
std::list
<
Ptr<LteSinrChunkProcessor>
>::const_iterator it =
m_sinrChunkProcessorList
.begin (); it !=
m_sinrChunkProcessorList
.end (); ++it)
156
{
157
(*it)->EvaluateSinrChunk (sinr, duration);
158
}
159
}
160
else
161
{
162
NS_LOG_DEBUG
(
this
<<
" NO EV"
);
163
}
164
}
165
166
void
167
LteInterference::SetNoisePowerSpectralDensity
(
Ptr<const SpectrumValue>
noisePsd)
168
{
169
NS_LOG_FUNCTION
(
this
<< *noisePsd);
170
m_noise
= noisePsd;
171
// we can initialize m_allSignal only now, because earlier we
172
// didn't know what spectrum model was going to be used.
173
// we'll now create a zeroed SpectrumValue using the same
174
// SpectrumModel which is being specified for the noise.
175
m_allSignals
= Create<SpectrumValue> (noisePsd->
GetSpectrumModel
());
176
}
177
178
void
179
LteInterference::AddSinrChunkProcessor
(
Ptr<LteSinrChunkProcessor>
p)
180
{
181
NS_LOG_FUNCTION
(
this
<< p);
182
m_sinrChunkProcessorList
.push_back (p);
183
}
184
185
186
187
188
}
// namespace ns3
189
190
src
lte
model
lte-interference.cc
Generated on Fri Dec 21 2012 19:00:39 for ns-3 by
1.8.1.2