A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
lr-wpan-interference-helper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013 Fraunhofer FKIE
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:
18
* Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
19
*/
20
#include "
lr-wpan-interference-helper.h
"
21
22
#include <ns3/log.h>
23
#include <ns3/spectrum-model.h>
24
#include <ns3/spectrum-value.h>
25
26
namespace
ns3
27
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"LrWpanInterferenceHelper"
);
30
31
LrWpanInterferenceHelper::LrWpanInterferenceHelper
(
Ptr<const SpectrumModel>
spectrumModel)
32
: m_spectrumModel(spectrumModel),
33
m_dirty(false)
34
{
35
m_signal
= Create<SpectrumValue>(
m_spectrumModel
);
36
}
37
38
LrWpanInterferenceHelper::~LrWpanInterferenceHelper
()
39
{
40
m_spectrumModel
=
nullptr
;
41
m_signal
=
nullptr
;
42
m_signals
.clear();
43
}
44
45
bool
46
LrWpanInterferenceHelper::AddSignal
(
Ptr<const SpectrumValue>
signal)
47
{
48
NS_LOG_FUNCTION
(
this
<< signal);
49
50
bool
result =
false
;
51
52
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
53
{
54
result =
m_signals
.insert(signal).second;
55
if
(result && !
m_dirty
)
56
{
57
*
m_signal
+= *signal;
58
}
59
}
60
return
result;
61
}
62
63
bool
64
LrWpanInterferenceHelper::RemoveSignal
(
Ptr<const SpectrumValue>
signal)
65
{
66
NS_LOG_FUNCTION
(
this
<< signal);
67
68
bool
result =
false
;
69
70
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
71
{
72
result = (
m_signals
.erase(signal) == 1);
73
if
(result)
74
{
75
m_dirty
=
true
;
76
}
77
}
78
return
result;
79
}
80
81
void
82
LrWpanInterferenceHelper::ClearSignals
()
83
{
84
NS_LOG_FUNCTION
(
this
);
85
86
m_signals
.clear();
87
m_dirty
=
true
;
88
}
89
90
Ptr<SpectrumValue>
91
LrWpanInterferenceHelper::GetSignalPsd
()
const
92
{
93
NS_LOG_FUNCTION
(
this
);
94
95
if
(
m_dirty
)
96
{
97
// Sum up the current interference PSD.
98
m_signal
= Create<SpectrumValue>(
m_spectrumModel
);
99
for
(
auto
it =
m_signals
.begin(); it !=
m_signals
.end(); ++it)
100
{
101
*
m_signal
+= *(*it);
102
}
103
m_dirty
=
false
;
104
}
105
106
return
m_signal
->
Copy
();
107
}
108
109
}
// namespace ns3
ns3::LrWpanInterferenceHelper::RemoveSignal
bool RemoveSignal(Ptr< const SpectrumValue > signal)
Remove the given signal to the set of accumulated signals.
Definition:
lr-wpan-interference-helper.cc:64
ns3::LrWpanInterferenceHelper::m_signals
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Definition:
lr-wpan-interference-helper.h:109
ns3::LrWpanInterferenceHelper::GetSignalPsd
Ptr< SpectrumValue > GetSignalPsd() const
Get the sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.cc:91
ns3::LrWpanInterferenceHelper::ClearSignals
void ClearSignals()
Remove all currently accumulated signals.
Definition:
lr-wpan-interference-helper.cc:82
ns3::LrWpanInterferenceHelper::m_spectrumModel
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
Definition:
lr-wpan-interference-helper.h:104
ns3::LrWpanInterferenceHelper::m_dirty
bool m_dirty
Mark m_signal as dirty, whenever a signal is added or removed.
Definition:
lr-wpan-interference-helper.h:120
ns3::LrWpanInterferenceHelper::~LrWpanInterferenceHelper
~LrWpanInterferenceHelper()
Definition:
lr-wpan-interference-helper.cc:38
ns3::LrWpanInterferenceHelper::LrWpanInterferenceHelper
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Definition:
lr-wpan-interference-helper.cc:31
ns3::LrWpanInterferenceHelper::m_signal
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.h:114
ns3::LrWpanInterferenceHelper::AddSignal
bool AddSignal(Ptr< const SpectrumValue > signal)
Add the given signal to the set of accumulated signals.
Definition:
lr-wpan-interference-helper.cc:46
ns3::Ptr< const SpectrumModel >
ns3::SpectrumValue::Copy
Ptr< SpectrumValue > Copy() const
Definition:
spectrum-value.cc:378
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:240
lr-wpan-interference-helper.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lr-wpan
model
lr-wpan-interference-helper.cc
Generated on Sun Mar 3 2024 17:11:00 for ns-3 by
1.9.1