A Discrete-Event Network Simulator
API
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
36 {
38  h.SetChannel ("ns3::SingleModelSpectrumChannel");
39  h.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
40  h.AddSpectrumPropagationLoss ("ns3::FriisSpectrumPropagationLossModel");
41  return h;
42 }
43 
44 void
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
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);
90 }
91 
92 
93 void
95 {
98 }
99 
100 void
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);
123 }
124 
125 void
127 {
128  m->SetNext (m_spectrumPropagationLossModel);
130 }
131 
132 void
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 
158 {
159  Ptr<SpectrumChannel> channel = (m_channel.Create ())->GetObject<SpectrumChannel> ();
160  channel->AddSpectrumPropagationLossModel (m_spectrumPropagationLossModel);
161  channel->AddPropagationLossModel (m_propagationLossModel);
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
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
207 {
208  m_phy.Set (name, v);
209 }
210 
211 
214 {
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
void SetChannel(Ptr< SpectrumChannel > channel)
set the channel that will be used by SpectrumPhy instances created by this helper ...
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
Hold a value for an Attribute.
Definition: attribute.h:68
ObjectFactory m_propagationDelay
Propagation delay.
Ptr< SpectrumChannel > m_channel
Channel.
ObjectFactory m_channel
Channel.
ObjectFactory m_phy
Object factory for the phy objects.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLossModel
Spectrum propagation loss model.
channel
Definition: third.py:85
phy
Definition: third.py:86
Keep track of the current position and velocity of an object.
void AddPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
calculate a propagation delay.
void SetPropagationDelay(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< PropagationLossModel > m_propagationLossModel
Propagation loss model.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
void SetPhy(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetChannel(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
void AddSpectrumPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Instantiate subclasses of ns3::Object.
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
Models the propagation loss through a transmission medium.
void SetPhyAttribute(std::string name, const AttributeValue &v)
spectrum-aware propagation loss model
Setup a SpectrumChannel.
Ptr< SpectrumChannel > Create(void) const
Ptr< SpectrumPhy > Create(Ptr< Node > node, Ptr< NetDevice > device) const