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-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 "
spectrum-helper.h
"
21
#include <ns3/simulator.h>
22
#include <ns3/config.h>
23
#include <ns3/names.h>
24
#include <ns3/spectrum-channel.h>
25
#include <ns3/spectrum-phy.h>
26
#include <ns3/single-model-spectrum-channel.h>
27
#include <ns3/multi-model-spectrum-channel.h>
28
#include <ns3/half-duplex-ideal-phy.h>
29
30
31
namespace
ns3 {
32
33
34
SpectrumChannelHelper
35
SpectrumChannelHelper::Default
(
void
)
36
{
37
SpectrumChannelHelper
h;
38
h.
SetChannel
(
"ns3::SingleModelSpectrumChannel"
);
39
h.
SetPropagationDelay
(
"ns3::ConstantSpeedPropagationDelayModel"
);
40
h.
AddSpectrumPropagationLoss
(
"ns3::FriisSpectrumPropagationLossModel"
);
41
return
h;
42
}
43
44
void
45
SpectrumChannelHelper::SetChannel
(std::string type,
46
std::string n0,
const
AttributeValue
&v0,
47
std::string n1,
const
AttributeValue
&v1,
48
std::string n2,
const
AttributeValue
&v2,
49
std::string n3,
const
AttributeValue
&v3,
50
std::string n4,
const
AttributeValue
&v4,
51
std::string n5,
const
AttributeValue
&v5,
52
std::string n6,
const
AttributeValue
&v6,
53
std::string n7,
const
AttributeValue
&v7)
54
{
55
ObjectFactory
factory;
56
m_channel
.
SetTypeId
(type);
57
m_channel
.
Set
(n0, v0);
58
m_channel
.
Set
(n1, v1);
59
m_channel
.
Set
(n2, v2);
60
m_channel
.
Set
(n3, v3);
61
m_channel
.
Set
(n4, v4);
62
m_channel
.
Set
(n5, v5);
63
m_channel
.
Set
(n6, v6);
64
m_channel
.
Set
(n7, v7);
65
}
66
67
void
68
SpectrumChannelHelper::AddPropagationLoss
(std::string type,
69
std::string n0,
const
AttributeValue
&v0,
70
std::string n1,
const
AttributeValue
&v1,
71
std::string n2,
const
AttributeValue
&v2,
72
std::string n3,
const
AttributeValue
&v3,
73
std::string n4,
const
AttributeValue
&v4,
74
std::string n5,
const
AttributeValue
&v5,
75
std::string n6,
const
AttributeValue
&v6,
76
std::string n7,
const
AttributeValue
&v7)
77
{
78
ObjectFactory
factory;
79
factory.
SetTypeId
(type);
80
factory.
Set
(n0, v0);
81
factory.
Set
(n1, v1);
82
factory.
Set
(n2, v2);
83
factory.
Set
(n3, v3);
84
factory.
Set
(n4, v4);
85
factory.
Set
(n5, v5);
86
factory.
Set
(n6, v6);
87
factory.
Set
(n7, v7);
88
Ptr<PropagationLossModel>
m = factory.
Create
<
PropagationLossModel
> ();
89
AddPropagationLoss
(m);
90
}
91
92
93
void
94
SpectrumChannelHelper::AddPropagationLoss
(
Ptr<PropagationLossModel>
m)
95
{
96
m->
SetNext
(
m_propagationLossModel
);
97
m_propagationLossModel
= m;
98
}
99
100
void
101
SpectrumChannelHelper::AddSpectrumPropagationLoss
(std::string type,
102
std::string n0,
const
AttributeValue
&v0,
103
std::string n1,
const
AttributeValue
&v1,
104
std::string n2,
const
AttributeValue
&v2,
105
std::string n3,
const
AttributeValue
&v3,
106
std::string n4,
const
AttributeValue
&v4,
107
std::string n5,
const
AttributeValue
&v5,
108
std::string n6,
const
AttributeValue
&v6,
109
std::string n7,
const
AttributeValue
&v7)
110
{
111
ObjectFactory
factory;
112
factory.
SetTypeId
(type);
113
factory.
Set
(n0, v0);
114
factory.
Set
(n1, v1);
115
factory.
Set
(n2, v2);
116
factory.
Set
(n3, v3);
117
factory.
Set
(n4, v4);
118
factory.
Set
(n5, v5);
119
factory.
Set
(n6, v6);
120
factory.
Set
(n7, v7);
121
Ptr<SpectrumPropagationLossModel>
m = factory.
Create
<
SpectrumPropagationLossModel
> ();
122
AddSpectrumPropagationLoss
(m);
123
}
124
125
void
126
SpectrumChannelHelper::AddSpectrumPropagationLoss
(
Ptr<SpectrumPropagationLossModel>
m)
127
{
128
m->
SetNext
(
m_spectrumPropagationLossModel
);
129
m_spectrumPropagationLossModel
= m;
130
}
131
132
void
133
SpectrumChannelHelper::SetPropagationDelay
(std::string type,
134
std::string n0,
const
AttributeValue
&v0,
135
std::string n1,
const
AttributeValue
&v1,
136
std::string n2,
const
AttributeValue
&v2,
137
std::string n3,
const
AttributeValue
&v3,
138
std::string n4,
const
AttributeValue
&v4,
139
std::string n5,
const
AttributeValue
&v5,
140
std::string n6,
const
AttributeValue
&v6,
141
std::string n7,
const
AttributeValue
&v7)
142
{
143
ObjectFactory
factory;
144
factory.
SetTypeId
(type);
145
factory.
Set
(n0, v0);
146
factory.
Set
(n1, v1);
147
factory.
Set
(n2, v2);
148
factory.
Set
(n3, v3);
149
factory.
Set
(n4, v4);
150
factory.
Set
(n5, v5);
151
factory.
Set
(n6, v6);
152
factory.
Set
(n7, v7);
153
m_propagationDelay
= factory;
154
}
155
156
Ptr<SpectrumChannel>
157
SpectrumChannelHelper::Create
(
void
)
const
158
{
159
Ptr<SpectrumChannel>
channel = (
m_channel
.
Create
())->GetObject<SpectrumChannel> ();
160
channel->
AddSpectrumPropagationLossModel
(
m_spectrumPropagationLossModel
);
161
channel->
AddPropagationLossModel
(
m_propagationLossModel
);
162
Ptr<PropagationDelayModel>
delay =
m_propagationDelay
.
Create
<
PropagationDelayModel
> ();
163
channel->
SetPropagationDelayModel
(delay);
164
return
channel;
165
}
166
167
168
void
169
SpectrumPhyHelper::SetPhy
(std::string type,
170
std::string n0,
const
AttributeValue
&v0,
171
std::string n1,
const
AttributeValue
&v1,
172
std::string n2,
const
AttributeValue
&v2,
173
std::string n3,
const
AttributeValue
&v3,
174
std::string n4,
const
AttributeValue
&v4,
175
std::string n5,
const
AttributeValue
&v5,
176
std::string n6,
const
AttributeValue
&v6,
177
std::string n7,
const
AttributeValue
&v7)
178
{
179
m_phy
.
SetTypeId
(type);
180
m_phy
.
Set
(n0, v0);
181
m_phy
.
Set
(n1, v1);
182
m_phy
.
Set
(n2, v2);
183
m_phy
.
Set
(n3, v3);
184
m_phy
.
Set
(n4, v4);
185
m_phy
.
Set
(n5, v5);
186
m_phy
.
Set
(n6, v6);
187
m_phy
.
Set
(n7, v7);
188
}
189
190
191
192
void
193
SpectrumPhyHelper::SetChannel
(
Ptr<SpectrumChannel>
channel)
194
{
195
m_channel
= channel;
196
}
197
198
void
199
SpectrumPhyHelper::SetChannel
(std::string channelName)
200
{
201
Ptr<SpectrumChannel>
channel = Names::Find<SpectrumChannel> (channelName);
202
m_channel
= channel;
203
}
204
205
void
206
SpectrumPhyHelper::SetPhyAttribute
(std::string name,
const
AttributeValue
&v)
207
{
208
m_phy
.
Set
(name, v);
209
}
210
211
212
Ptr<SpectrumPhy>
213
SpectrumPhyHelper::Create
(
Ptr<Node>
node,
Ptr<NetDevice>
device)
const
214
{
215
NS_ASSERT
(
m_channel
);
216
Ptr<SpectrumPhy>
phy = (
m_phy
.
Create
())->GetObject<SpectrumPhy> ();
217
phy->
SetChannel
(
m_channel
);
218
phy->
SetMobility
(node->
GetObject
<
MobilityModel
> ());
219
phy->
SetDevice
(device);
220
return
phy;
221
}
222
223
224
}
// namespace ns3
src
spectrum
helper
spectrum-helper.cc
Generated on Tue May 14 2013 11:08:32 for ns-3 by
1.8.1.2