A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
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
namespace
lrwpan
29
{
30
31
NS_LOG_COMPONENT_DEFINE
(
"LrWpanInterferenceHelper"
);
32
33
LrWpanInterferenceHelper::LrWpanInterferenceHelper
(
Ptr<const SpectrumModel>
spectrumModel)
34
: m_spectrumModel(spectrumModel),
35
m_dirty(false)
36
{
37
m_signal
= Create<SpectrumValue>(
m_spectrumModel
);
38
}
39
40
LrWpanInterferenceHelper::~LrWpanInterferenceHelper
()
41
{
42
m_spectrumModel
=
nullptr
;
43
m_signal
=
nullptr
;
44
m_signals
.clear();
45
}
46
47
bool
48
LrWpanInterferenceHelper::AddSignal
(
Ptr<const SpectrumValue>
signal)
49
{
50
NS_LOG_FUNCTION
(
this
<< signal);
51
52
bool
result =
false
;
53
54
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
55
{
56
result =
m_signals
.insert(signal).second;
57
if
(result && !
m_dirty
)
58
{
59
*
m_signal
+= *signal;
60
}
61
}
62
return
result;
63
}
64
65
bool
66
LrWpanInterferenceHelper::RemoveSignal
(
Ptr<const SpectrumValue>
signal)
67
{
68
NS_LOG_FUNCTION
(
this
<< signal);
69
70
bool
result =
false
;
71
72
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
73
{
74
result = (
m_signals
.erase(signal) == 1);
75
if
(result)
76
{
77
m_dirty
=
true
;
78
}
79
}
80
return
result;
81
}
82
83
void
84
LrWpanInterferenceHelper::ClearSignals
()
85
{
86
NS_LOG_FUNCTION
(
this
);
87
88
m_signals
.clear();
89
m_dirty
=
true
;
90
}
91
92
Ptr<SpectrumValue>
93
LrWpanInterferenceHelper::GetSignalPsd
()
const
94
{
95
NS_LOG_FUNCTION
(
this
);
96
97
if
(
m_dirty
)
98
{
99
// Sum up the current interference PSD.
100
m_signal
= Create<SpectrumValue>(
m_spectrumModel
);
101
for
(
auto
it =
m_signals
.begin(); it !=
m_signals
.end(); ++it)
102
{
103
*
m_signal
+= *(*it);
104
}
105
m_dirty
=
false
;
106
}
107
108
return
m_signal
->
Copy
();
109
}
110
111
}
// namespace lrwpan
112
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::SpectrumValue::Copy
Ptr< SpectrumValue > Copy() const
Definition:
spectrum-value.cc:378
ns3::lrwpan::LrWpanInterferenceHelper::GetSignalPsd
Ptr< SpectrumValue > GetSignalPsd() const
Get the sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.cc:93
ns3::lrwpan::LrWpanInterferenceHelper::AddSignal
bool AddSignal(Ptr< const SpectrumValue > signal)
Add the given signal to the set of accumulated signals.
Definition:
lr-wpan-interference-helper.cc:48
ns3::lrwpan::LrWpanInterferenceHelper::ClearSignals
void ClearSignals()
Remove all currently accumulated signals.
Definition:
lr-wpan-interference-helper.cc:84
ns3::lrwpan::LrWpanInterferenceHelper::~LrWpanInterferenceHelper
~LrWpanInterferenceHelper()
Definition:
lr-wpan-interference-helper.cc:40
ns3::lrwpan::LrWpanInterferenceHelper::m_signals
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Definition:
lr-wpan-interference-helper.h:112
ns3::lrwpan::LrWpanInterferenceHelper::m_signal
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.h:117
ns3::lrwpan::LrWpanInterferenceHelper::m_dirty
bool m_dirty
Mark m_signal as dirty, whenever a signal is added or removed.
Definition:
lr-wpan-interference-helper.h:123
ns3::lrwpan::LrWpanInterferenceHelper::LrWpanInterferenceHelper
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Definition:
lr-wpan-interference-helper.cc:33
ns3::lrwpan::LrWpanInterferenceHelper::m_spectrumModel
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
Definition:
lr-wpan-interference-helper.h:107
ns3::lrwpan::LrWpanInterferenceHelper::RemoveSignal
bool RemoveSignal(Ptr< const SpectrumValue > signal)
Remove the given signal to the set of accumulated signals.
Definition:
lr-wpan-interference-helper.cc:66
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 Tue May 28 2024 23:36:50 for ns-3 by
1.9.6