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
spectrum-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 "
spectrum-interference.h
"
23
#include "
spectrum-error-model.h
"
24
25
#include <ns3/simulator.h>
26
#include <ns3/log.h>
27
28
29
NS_LOG_COMPONENT_DEFINE
(
"SpectrumInterference"
);
30
31
namespace
ns3 {
32
33
34
SpectrumInterference::SpectrumInterference
()
35
: m_receiving (false),
36
m_rxSignal (0),
37
m_allSignals (0),
38
m_noise (0),
39
m_errorModel (0)
40
{
41
NS_LOG_FUNCTION
(
this
);
42
}
43
44
SpectrumInterference::~SpectrumInterference
()
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
49
void
50
SpectrumInterference::DoDispose
()
51
{
52
NS_LOG_FUNCTION
(
this
);
53
m_rxSignal
= 0;
54
m_allSignals
= 0;
55
m_noise
= 0;
56
m_errorModel
= 0;
57
Object::DoDispose
();
58
}
59
60
void
61
SpectrumInterference::StartRx
(
Ptr<const Packet>
p,
Ptr<const SpectrumValue>
rxPsd)
62
{
63
NS_LOG_FUNCTION
(
this
<< p << *rxPsd);
64
m_rxSignal
= rxPsd;
65
m_lastChangeTime
=
Now
();
66
m_receiving
=
true
;
67
m_errorModel
->
StartRx
(p);
68
}
69
70
void
71
SpectrumInterference::AbortRx
()
72
{
73
m_receiving
=
false
;
74
}
75
76
bool
77
SpectrumInterference::EndRx
()
78
{
79
NS_LOG_FUNCTION
(
this
);
80
ConditionallyEvaluateChunk
();
81
m_receiving
=
false
;
82
return
m_errorModel
->
IsRxCorrect
();
83
}
84
85
86
void
87
SpectrumInterference::AddSignal
(
Ptr<const SpectrumValue>
spd,
const
Time
duration)
88
{
89
NS_LOG_FUNCTION
(
this
<< *spd << duration);
90
DoAddSignal
(spd);
91
Simulator::Schedule
(duration, &
SpectrumInterference::DoSubtractSignal
,
this
, spd);
92
}
93
94
95
void
96
SpectrumInterference::DoAddSignal
(
Ptr<const SpectrumValue>
spd)
97
{
98
NS_LOG_FUNCTION
(
this
<< *spd);
99
ConditionallyEvaluateChunk
();
100
(*m_allSignals) += (*spd);
101
m_lastChangeTime
=
Now
();
102
}
103
104
void
105
SpectrumInterference::DoSubtractSignal
(
Ptr<const SpectrumValue>
spd)
106
{
107
NS_LOG_FUNCTION
(
this
<< *spd);
108
ConditionallyEvaluateChunk
();
109
(*m_allSignals) -= (*spd);
110
m_lastChangeTime
=
Now
();
111
}
112
113
114
void
115
SpectrumInterference::ConditionallyEvaluateChunk
()
116
{
117
NS_LOG_FUNCTION
(
this
);
118
NS_LOG_LOGIC
(
"m_receiving: "
<<
m_receiving
);
119
NS_LOG_LOGIC
(
"m_lastChangeTime: "
<<
m_lastChangeTime
<<
" Now: "
<<
Now
());
120
bool
condition =
m_receiving
&& (
Now
() >
m_lastChangeTime
);
121
NS_LOG_LOGIC
(
"if condition: "
<< condition);
122
if
(condition)
123
{
124
SpectrumValue
sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
125
Time
duration =
Now
() -
m_lastChangeTime
;
126
NS_LOG_LOGIC
(
"calling m_errorModel->EvaluateChunk (sinr, duration)"
);
127
m_errorModel
->
EvaluateChunk
(sinr, duration);
128
}
129
}
130
131
void
132
SpectrumInterference::SetNoisePowerSpectralDensity
(
Ptr<const SpectrumValue>
noisePsd)
133
{
134
NS_LOG_FUNCTION
(
this
<< noisePsd);
135
m_noise
= noisePsd;
136
// we can initialize m_allSignal only now, because earlier we
137
// didn't know what spectrum model was going to be used.
138
// we'll now create a zeroed SpectrumValue using the same
139
// SpectrumModel which is being specified for the noise.
140
m_allSignals
= Create<SpectrumValue> (noisePsd->
GetSpectrumModel
());
141
}
142
143
void
144
SpectrumInterference::SetErrorModel
(
Ptr<SpectrumErrorModel>
e)
145
{
146
NS_LOG_FUNCTION
(
this
<< e);
147
m_errorModel
= e;
148
}
149
150
151
152
153
}
// namespace ns3
154
155
src
spectrum
model
spectrum-interference.cc
Generated on Tue May 14 2013 11:08:32 for ns-3 by
1.8.1.2