author | Nicola Baldo <nbaldo@cttc.es> |
Tue, 05 Jul 2011 19:03:55 +0200 | |
changeset 7343 | b3e668a5949c |
parent 6801 | f07f7f809160 |
child 7553 | 2b93d333dea6 |
permissions | -rw-r--r-- |
6349 | 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 |
||
7343
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
67 |
void |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
68 |
SpectrumChannelHelper::AddPropagationLoss (std::string type, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
69 |
std::string n0, const AttributeValue &v0, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
70 |
std::string n1, const AttributeValue &v1, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
71 |
std::string n2, const AttributeValue &v2, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
72 |
std::string n3, const AttributeValue &v3, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
73 |
std::string n4, const AttributeValue &v4, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
74 |
std::string n5, const AttributeValue &v5, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
75 |
std::string n6, const AttributeValue &v6, |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
76 |
std::string n7, const AttributeValue &v7) |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
77 |
{ |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
78 |
ObjectFactory factory; |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
79 |
factory.SetTypeId (type); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
80 |
factory.Set (n0, v0); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
81 |
factory.Set (n1, v1); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
82 |
factory.Set (n2, v2); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
83 |
factory.Set (n3, v3); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
84 |
factory.Set (n4, v4); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
85 |
factory.Set (n5, v5); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
86 |
factory.Set (n6, v6); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
87 |
factory.Set (n7, v7); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
88 |
Ptr<PropagationLossModel> m = factory.Create<PropagationLossModel> (); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
89 |
AddPropagationLoss (m); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
90 |
} |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
91 |
|
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
92 |
|
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
93 |
void |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
94 |
SpectrumChannelHelper::AddPropagationLoss (Ptr<PropagationLossModel> m) |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
95 |
{ |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
96 |
m->SetNext (m_propagationLossModel); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
97 |
m_propagationLossModel = m; |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
98 |
} |
6349 | 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); |
|
7343
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
121 |
Ptr<SpectrumPropagationLossModel> m = factory.Create<SpectrumPropagationLossModel> (); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
122 |
AddSpectrumPropagationLoss (m); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
123 |
} |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
124 |
|
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
125 |
void |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
126 |
SpectrumChannelHelper::AddSpectrumPropagationLoss (Ptr<SpectrumPropagationLossModel> m) |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
127 |
{ |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
128 |
m->SetNext (m_spectrumPropagationLossModel); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
129 |
m_spectrumPropagationLossModel = m; |
6349 | 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> (); |
|
7343
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
160 |
channel->AddSpectrumPropagationLossModel (m_spectrumPropagationLossModel); |
b3e668a5949c
added support for single-freq PropagationLossModel to SpectrumChannel
Nicola Baldo <nbaldo@cttc.es>
parents:
6801
diff
changeset
|
161 |
channel->AddPropagationLossModel (m_propagationLossModel); |
6349 | 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); |
|
219 |
phy->SetDevice (device); |
|
220 |
return phy; |
|
221 |
} |
|
222 |
||
223 |
||
224 |
} // namespace ns3 |