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-analyzer-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 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
#include "ns3/propagation-delay-model.h"
21
#include "ns3/spectrum-propagation-loss-model.h"
22
#include "ns3/mobility-model.h"
23
#include "ns3/log.h"
24
#include "ns3/config.h"
25
#include "ns3/simulator.h"
26
#include "ns3/names.h"
27
#include "ns3/antenna-model.h"
28
#include "ns3/spectrum-channel.h"
29
#include "ns3/spectrum-analyzer.h"
30
#include "ns3/non-communicating-net-device.h"
31
#include "ns3/output-stream-wrapper.h"
32
#include "ns3/trace-helper.h"
33
#include "
spectrum-analyzer-helper.h
"
34
35
36
37
38
NS_LOG_COMPONENT_DEFINE
(
"SpectrumAnalyzerHelper"
);
39
40
namespace
ns3 {
41
42
43
static
void
44
WriteAveragePowerSpectralDensityReport
(
Ptr<OutputStreamWrapper>
streamWrapper,
45
Ptr<const SpectrumValue>
avgPowerSpectralDensity)
46
{
47
NS_LOG_FUNCTION
(streamWrapper << avgPowerSpectralDensity);
48
std::ostream* ostream = streamWrapper->
GetStream
();
49
if
(ostream->good ())
50
{
51
Bands::const_iterator fi = avgPowerSpectralDensity->
ConstBandsBegin
();
52
Values::const_iterator vi = avgPowerSpectralDensity->
ConstValuesBegin
();
53
while
(fi != avgPowerSpectralDensity->
ConstBandsEnd
())
54
{
55
NS_ASSERT
(vi != avgPowerSpectralDensity->
ConstValuesEnd
());
56
*ostream <<
Now
().
GetSeconds
() <<
" "
57
<< fi->fc <<
" "
58
<< *vi << std::endl;
59
++fi;
60
++vi;
61
}
62
// An additional line separates different spectrums sweeps
63
*ostream << std::endl;
64
}
65
}
66
67
68
69
SpectrumAnalyzerHelper::SpectrumAnalyzerHelper
()
70
{
71
NS_LOG_FUNCTION
(
this
);
72
m_phy
.
SetTypeId
(
"ns3::SpectrumAnalyzer"
);
73
m_device
.
SetTypeId
(
"ns3::NonCommunicatingNetDevice"
);
74
m_antenna
.
SetTypeId
(
"ns3::IsotropicAntennaModel"
);
75
}
76
77
SpectrumAnalyzerHelper::~SpectrumAnalyzerHelper
()
78
{
79
NS_LOG_FUNCTION
(
this
);
80
}
81
82
void
83
SpectrumAnalyzerHelper::SetChannel
(
Ptr<SpectrumChannel>
channel)
84
{
85
NS_LOG_FUNCTION
(
this
);
86
m_channel
= channel;
87
}
88
89
void
90
SpectrumAnalyzerHelper::SetChannel
(std::string channelName)
91
{
92
NS_LOG_FUNCTION
(
this
);
93
Ptr<SpectrumChannel>
channel = Names::Find<SpectrumChannel> (channelName);
94
m_channel
= channel;
95
}
96
97
98
void
99
SpectrumAnalyzerHelper::SetPhyAttribute
(std::string name,
const
AttributeValue
&v)
100
{
101
NS_LOG_FUNCTION
(
this
);
102
m_phy
.
Set
(name, v);
103
}
104
105
106
void
107
SpectrumAnalyzerHelper::SetDeviceAttribute
(std::string name,
const
AttributeValue
&v)
108
{
109
NS_LOG_FUNCTION
(
this
);
110
m_device
.
Set
(name, v);
111
}
112
113
void
114
SpectrumAnalyzerHelper::SetAntenna
(std::string type,
115
std::string n0,
const
AttributeValue
&v0,
116
std::string n1,
const
AttributeValue
&v1,
117
std::string n2,
const
AttributeValue
&v2,
118
std::string n3,
const
AttributeValue
&v3,
119
std::string n4,
const
AttributeValue
&v4,
120
std::string n5,
const
AttributeValue
&v5,
121
std::string n6,
const
AttributeValue
&v6,
122
std::string n7,
const
AttributeValue
&v7)
123
{
124
ObjectFactory
factory;
125
factory.
SetTypeId
(type);
126
factory.
Set
(n0, v0);
127
factory.
Set
(n1, v1);
128
factory.
Set
(n2, v2);
129
factory.
Set
(n3, v3);
130
factory.
Set
(n4, v4);
131
factory.
Set
(n5, v5);
132
factory.
Set
(n6, v6);
133
factory.
Set
(n7, v7);
134
m_antenna
= factory;
135
}
136
137
138
void
139
SpectrumAnalyzerHelper::SetRxSpectrumModel
(
Ptr<SpectrumModel>
m)
140
{
141
NS_LOG_FUNCTION
(
this
);
142
m_rxSpectrumModel
= m;
143
}
144
145
void
146
SpectrumAnalyzerHelper::EnableAsciiAll
(std::string prefix)
147
{
148
NS_LOG_FUNCTION
(
this
);
149
m_prefix
= prefix;
150
}
151
152
153
154
NetDeviceContainer
155
SpectrumAnalyzerHelper::Install
(
NodeContainer
c)
const
156
{
157
NS_LOG_FUNCTION
(
this
);
158
NetDeviceContainer
devices;
159
for
(
NodeContainer::Iterator
i = c.
Begin
(); i != c.
End
(); ++i)
160
{
161
Ptr<Node>
node = *i;
162
163
Ptr<NonCommunicatingNetDevice>
dev =
m_device
.
Create
()->
GetObject
<
NonCommunicatingNetDevice
> ();
164
165
Ptr<SpectrumAnalyzer>
phy =
m_phy
.
Create
()->
GetObject
<
SpectrumAnalyzer
> ();
166
NS_ASSERT
(phy);
167
168
dev->SetPhy (phy);
169
170
NS_ASSERT
(node);
171
phy->SetMobility (node->
GetObject
<
MobilityModel
> ());
172
173
NS_ASSERT
(dev);
174
phy->SetDevice (dev);
175
176
NS_ASSERT_MSG
(
m_rxSpectrumModel
,
"you forgot to call SpectrumAnalyzerHelper::SetRxSpectrumModel ()"
);
177
phy->SetRxSpectrumModel (
m_rxSpectrumModel
);
178
179
NS_ASSERT_MSG
(
m_channel
,
"you forgot to call SpectrumAnalyzerHelper::SetChannel ()"
);
180
m_channel
->
AddRx
(phy);
181
182
dev->SetChannel (
m_channel
);
183
184
Ptr<AntennaModel>
antenna = (
m_antenna
.
Create
())->GetObject<AntennaModel> ();
185
NS_ASSERT_MSG
(antenna,
"error in creating the AntennaModel object"
);
186
phy->SetAntenna (antenna);
187
188
uint32_t devId = node->
AddDevice
(dev);
189
devices.
Add
(dev);
190
191
if
(!
m_prefix
.empty ())
192
{
193
NS_LOG_LOGIC
(
"creating new output stream and binding it to the callback"
);
194
AsciiTraceHelper
asciiTraceHelper;
195
std::string filename;
196
filename = asciiTraceHelper.
GetFilenameFromDevice
(
m_prefix
, dev);
197
Ptr<OutputStreamWrapper>
stream = asciiTraceHelper.
CreateFileStream
(filename);
198
199
// note that we don't use AsciiTraceHelper to connect the trace sink, since we use a custom trace sink
200
201
// the following is inspired from YansWifiPhyHelper::EnableAsciiInternal
202
std::ostringstream oss;
203
oss.str (
""
);
204
oss <<
"/NodeList/"
<< node->
GetId
() <<
"/DeviceList/"
<< devId <<
"/$ns3::NonCommunicatingNetDevice/Phy/AveragePowerSpectralDensityReport"
;
205
Config::ConnectWithoutContext
(oss.str (),
MakeBoundCallback
(&
WriteAveragePowerSpectralDensityReport
, stream));
206
207
phy->Start ();
208
209
}
210
}
211
return
devices;
212
}
213
214
NetDeviceContainer
215
SpectrumAnalyzerHelper::Install
(
Ptr<Node>
node)
const
216
{
217
NS_LOG_FUNCTION
(
this
);
218
return
Install
(
NodeContainer
(node));
219
}
220
221
NetDeviceContainer
222
SpectrumAnalyzerHelper::Install
(std::string nodeName)
const
223
{
224
NS_LOG_FUNCTION
(
this
);
225
Ptr<Node>
node = Names::Find<Node> (nodeName);
226
return
Install
(node);
227
}
228
229
230
}
// namespace ns3
src
spectrum
helper
spectrum-analyzer-helper.cc
Generated on Tue Oct 9 2012 16:45:46 for ns-3 by
1.8.1.2