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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author:
7
* Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
8
*/
9
#include "
lr-wpan-interference-helper.h
"
10
11
#include <ns3/log.h>
12
#include <ns3/spectrum-model.h>
13
#include <ns3/spectrum-value.h>
14
15
namespace
ns3
16
{
17
namespace
lrwpan
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"LrWpanInterferenceHelper"
);
21
22
LrWpanInterferenceHelper::LrWpanInterferenceHelper
(
Ptr<const SpectrumModel>
spectrumModel)
23
: m_spectrumModel(spectrumModel),
24
m_dirty(false)
25
{
26
m_signal
=
Create<SpectrumValue>
(
m_spectrumModel
);
27
}
28
29
LrWpanInterferenceHelper::~LrWpanInterferenceHelper
()
30
{
31
m_spectrumModel
=
nullptr
;
32
m_signal
=
nullptr
;
33
m_signals
.clear();
34
}
35
36
bool
37
LrWpanInterferenceHelper::AddSignal
(
Ptr<const SpectrumValue>
signal)
38
{
39
NS_LOG_FUNCTION
(
this
<< signal);
40
41
bool
result =
false
;
42
43
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
44
{
45
result =
m_signals
.insert(signal).second;
46
if
(result && !
m_dirty
)
47
{
48
*
m_signal
+= *signal;
49
}
50
}
51
return
result;
52
}
53
54
bool
55
LrWpanInterferenceHelper::RemoveSignal
(
Ptr<const SpectrumValue>
signal)
56
{
57
NS_LOG_FUNCTION
(
this
<< signal);
58
59
bool
result =
false
;
60
61
if
(signal->GetSpectrumModel() ==
m_spectrumModel
)
62
{
63
result = (
m_signals
.erase(signal) == 1);
64
if
(result)
65
{
66
m_dirty
=
true
;
67
}
68
}
69
return
result;
70
}
71
72
void
73
LrWpanInterferenceHelper::ClearSignals
()
74
{
75
NS_LOG_FUNCTION
(
this
);
76
77
m_signals
.clear();
78
m_dirty
=
true
;
79
}
80
81
Ptr<SpectrumValue>
82
LrWpanInterferenceHelper::GetSignalPsd
()
const
83
{
84
NS_LOG_FUNCTION
(
this
);
85
86
if
(
m_dirty
)
87
{
88
// Sum up the current interference PSD.
89
m_signal
=
Create<SpectrumValue>
(
m_spectrumModel
);
90
for
(
auto
it =
m_signals
.begin(); it !=
m_signals
.end(); ++it)
91
{
92
*
m_signal
+= *(*it);
93
}
94
m_dirty
=
false
;
95
}
96
97
return
m_signal
->Copy();
98
}
99
100
}
// namespace lrwpan
101
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::lrwpan::LrWpanInterferenceHelper::GetSignalPsd
Ptr< SpectrumValue > GetSignalPsd() const
Get the sum of all accumulated signals.
Definition
lr-wpan-interference-helper.cc:82
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:37
ns3::lrwpan::LrWpanInterferenceHelper::ClearSignals
void ClearSignals()
Remove all currently accumulated signals.
Definition
lr-wpan-interference-helper.cc:73
ns3::lrwpan::LrWpanInterferenceHelper::~LrWpanInterferenceHelper
~LrWpanInterferenceHelper()
Definition
lr-wpan-interference-helper.cc:29
ns3::lrwpan::LrWpanInterferenceHelper::m_signals
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Definition
lr-wpan-interference-helper.h:101
ns3::lrwpan::LrWpanInterferenceHelper::m_signal
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
Definition
lr-wpan-interference-helper.h:106
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:112
ns3::lrwpan::LrWpanInterferenceHelper::LrWpanInterferenceHelper
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Definition
lr-wpan-interference-helper.cc:22
ns3::lrwpan::LrWpanInterferenceHelper::m_spectrumModel
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
Definition
lr-wpan-interference-helper.h:96
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:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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:229
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
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 Fri Nov 8 2024 13:59:02 for ns-3 by
1.11.0