A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
lr-wpan
model
lr-wpan-interference-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013 Fraunhofer FKIE
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:
19
* Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
20
*/
21
#include "
lr-wpan-interference-helper.h
"
22
#include <ns3/spectrum-value.h>
23
#include <ns3/spectrum-model.h>
24
#include <ns3/log.h>
25
26
namespace
ns3
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"LrWpanInterferenceHelper"
);
29
30
LrWpanInterferenceHelper::LrWpanInterferenceHelper
(
Ptr<const SpectrumModel>
spectrumModel)
31
: m_spectrumModel (spectrumModel),
32
m_dirty (false)
33
{
34
m_signal
= Create<SpectrumValue> (
m_spectrumModel
);
35
}
36
37
LrWpanInterferenceHelper::~LrWpanInterferenceHelper
(
void
)
38
{
39
m_spectrumModel
= 0;
40
m_signal
= 0;
41
m_signals
.clear ();
42
}
43
44
bool
45
LrWpanInterferenceHelper::AddSignal
(
Ptr<const SpectrumValue>
signal)
46
{
47
NS_LOG_FUNCTION
(
this
<< signal);
48
49
bool
result =
false
;
50
51
if
(signal->GetSpectrumModel () ==
m_spectrumModel
)
52
{
53
result =
m_signals
.insert (signal).second;
54
if
(result && !
m_dirty
)
55
{
56
*
m_signal
+= *signal;
57
}
58
}
59
return
result;
60
}
61
62
bool
63
LrWpanInterferenceHelper::RemoveSignal
(
Ptr<const SpectrumValue>
signal)
64
{
65
NS_LOG_FUNCTION
(
this
<< signal);
66
67
bool
result =
false
;
68
69
if
(signal->GetSpectrumModel () ==
m_spectrumModel
)
70
{
71
result = (
m_signals
.erase (signal) == 1);
72
if
(result)
73
{
74
m_dirty
=
true
;
75
}
76
}
77
return
result;
78
}
79
80
void
81
LrWpanInterferenceHelper::ClearSignals
(
void
)
82
{
83
NS_LOG_FUNCTION
(
this
);
84
85
m_signals
.clear ();
86
m_dirty
=
true
;
87
}
88
89
Ptr<SpectrumValue>
90
LrWpanInterferenceHelper::GetSignalPsd
(
void
)
const
91
{
92
NS_LOG_FUNCTION
(
this
);
93
94
if
(
m_dirty
)
95
{
96
// Sum up the current interference PSD.
97
std::set<Ptr<const SpectrumValue> >::const_iterator it;
98
m_signal
= Create<SpectrumValue> (
m_spectrumModel
);
99
for
(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
}
ns3::Ptr< const SpectrumModel >
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:213
ns3::LrWpanInterferenceHelper::m_signals
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Definition:
lr-wpan-interference-helper.h:107
ns3::LrWpanInterferenceHelper::GetSignalPsd
Ptr< SpectrumValue > GetSignalPsd(void) const
Get the sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.cc:90
ns3::LrWpanInterferenceHelper::~LrWpanInterferenceHelper
~LrWpanInterferenceHelper(void)
Definition:
lr-wpan-interference-helper.cc:37
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::LrWpanInterferenceHelper::m_signal
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
Definition:
lr-wpan-interference-helper.h:112
ns3::LrWpanInterferenceHelper::LrWpanInterferenceHelper
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Definition:
lr-wpan-interference-helper.cc:30
ns3::LrWpanInterferenceHelper::m_spectrumModel
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
Definition:
lr-wpan-interference-helper.h:102
ns3::SpectrumValue::Copy
Ptr< SpectrumValue > Copy() const
Definition:
spectrum-value.cc:409
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:63
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:118
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:45
lr-wpan-interference-helper.h
ns3::LrWpanInterferenceHelper::ClearSignals
void ClearSignals(void)
Remove all currently accumulated signals.
Definition:
lr-wpan-interference-helper.cc:81
Generated on Wed Nov 7 2018 10:01:58 for ns-3 by
1.8.14