A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#ifndef SPECTRUM_HELPER_H
21#define SPECTRUM_HELPER_H
22
23#include <ns3/attribute.h>
24#include <ns3/net-device-container.h>
25#include <ns3/node-container.h>
26#include <ns3/object-factory.h>
27#include <ns3/propagation-loss-model.h>
28#include <ns3/spectrum-propagation-loss-model.h>
29
30#include <string>
31
32namespace ns3
33{
34
35class SpectrumPhy;
36class SpectrumChannel;
37class Node;
38class NetDevice;
39
40/**
41 * \ingroup spectrum
42 * \brief Setup a SpectrumChannel
43 */
45{
46 public:
47 /**
48 * \brief Setup a default SpectrumChannel. The Default mode is:
49 * Channel: "ns3::SingleModelSpectrumChannel",
50 * PropagationDelay: "ns3::ConstantSpeedPropagationDelayModel", and
51 * SpectrumPropagationLoss: "ns3::FriisSpectrumPropagationLossModel".
52 *
53 * \returns a Default-configured SpectrumChannelHelper
54 */
56
57 /**
58 * \tparam Ts \deduced Argument types
59 * \param type the type of the SpectrumChannel to use
60 * \param [in] args Name and AttributeValue pairs to set.
61 */
62 template <typename... Ts>
63 void SetChannel(std::string type, Ts&&... args);
64 /**
65 * \tparam Ts \deduced Argument types
66 * \param name the name of the model to set
67 * \param [in] args Name and AttributeValue pairs to set.
68 *
69 * Add a new single-frequency propagation loss model to this channel helper.
70 */
71 template <typename... Ts>
72 void AddPropagationLoss(std::string name, Ts&&... args);
73
74 /**
75 * Add a new single-frequency propagation loss model instance to this channel helper.
76 *
77 * \param m a pointer to the instance of the propagation loss model
78 */
80
81 /**
82 * \tparam Ts \deduced Argument types
83 * \param name the name of the model to set
84 * \param [in] args Name and AttributeValue pairs to set.
85 *
86 * Add a new frequency-dependent propagation loss model to this channel helper.
87 */
88 template <typename... Ts>
89 void AddSpectrumPropagationLoss(std::string name, Ts&&... args);
90
91 /**
92 * Add a new frequency-dependent propagation loss model instance to this channel helper.
93 *
94 * \param m a pointer to the instance of the propagation loss model
95 */
97
98 /**
99 * \tparam Ts \deduced Argument types
100 * \param name the name of the model to set
101 * \param [in] args Name and AttributeValue pairs to set.
102 *
103 * Configure a propagation delay for this channel.
104 */
105 template <typename... Ts>
106 void SetPropagationDelay(std::string name, Ts&&... args);
107
108 /**
109 * \returns a new channel
110 *
111 * Create a channel based on the configuration parameters set previously.
112 */
114
115 private:
117 m_spectrumPropagationLossModel; //!< Spectrum propagation loss model
119 ObjectFactory m_propagationDelay; //!< Propagation delay
121};
122
123/**
124 * \ingroup spectrum
125 *
126 * Create and configure several SpectrumPhy instances and connect them to a channel.
127 */
129{
130 public:
131 /**
132 * \tparam Ts \deduced Argument types
133 * \param name the type of SpectrumPhy to use
134 * \param [in] args Name and AttributeValue pairs to set.
135 */
136 template <typename... Ts>
137 void SetPhy(std::string name, Ts&&... args);
138
139 /**
140 * set the channel that will be used by SpectrumPhy instances created by this helper
141 *
142 * @param channel
143 */
144 void SetChannel(Ptr<SpectrumChannel> channel);
145
146 /**
147 * set the channel that will be used by SpectrumPhy instances created by this helper
148 *
149 * @param channelName
150 */
151 void SetChannel(std::string channelName);
152
153 /**
154 * \param name the name of the attribute to set
155 * \param v the value of the attribute
156 *
157 * Set an attribute of the SpectrumPhy instances to be created
158 */
159 void SetPhyAttribute(std::string name, const AttributeValue& v);
160
161 /**
162 *
163 * @param node
164 * @param device
165 *
166 * @return a newly created SpectrumPhy instance
167 */
169
170 private:
171 ObjectFactory m_phy; //!< Object factory for the phy objects
173};
174
175/***************************************************************
176 * Implementation of the templates declared above.
177 ***************************************************************/
178
179template <typename... Ts>
180void
181SpectrumChannelHelper::SetChannel(std::string type, Ts&&... args)
182{
183 m_channel.SetTypeId(type);
184 m_channel.Set(std::forward<Ts>(args)...);
185}
186
187template <typename... Ts>
188void
189SpectrumChannelHelper::AddPropagationLoss(std::string name, Ts&&... args)
190{
191 ObjectFactory factory(name, std::forward<Ts>(args)...);
194}
195
196template <typename... Ts>
197void
199{
200 ObjectFactory factory(name, std::forward<Ts>(args)...);
203}
204
205template <typename... Ts>
206void
207SpectrumChannelHelper::SetPropagationDelay(std::string name, Ts&&... args)
208{
209 m_propagationDelay = ObjectFactory(name, std::forward<Ts>(args)...);
210}
211
212template <typename... Ts>
213void
214SpectrumPhyHelper::SetPhy(std::string name, Ts&&... args)
215{
216 m_phy.SetTypeId(name);
217 m_phy.Set(std::forward<Ts>(args)...);
218}
219
220} // namespace ns3
221
222#endif /* SPECTRUM_HELPER_H */
Hold a value for an Attribute.
Definition: attribute.h:70
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Models the propagation loss through a transmission medium.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Setup a SpectrumChannel.
ObjectFactory m_propagationDelay
Propagation delay.
ObjectFactory m_channel
Channel.
Ptr< SpectrumChannel > Create() const
void AddPropagationLoss(std::string name, Ts &&... args)
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void AddSpectrumPropagationLoss(std::string name, Ts &&... args)
void SetPropagationDelay(std::string name, Ts &&... args)
void SetChannel(std::string type, Ts &&... args)
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLossModel
Spectrum propagation loss model.
Ptr< PropagationLossModel > m_propagationLossModel
Propagation loss model.
Create and configure several SpectrumPhy instances and connect them to a channel.
void SetChannel(Ptr< SpectrumChannel > channel)
set the channel that will be used by SpectrumPhy instances created by this helper
Ptr< SpectrumChannel > m_channel
Channel.
ObjectFactory m_phy
Object factory for the phy objects.
void SetPhyAttribute(std::string name, const AttributeValue &v)
Ptr< SpectrumPhy > Create(Ptr< Node > node, Ptr< NetDevice > device) const
void SetPhy(std::string name, Ts &&... args)
spectrum-aware propagation loss model
Every class exported by the ns3 library is enclosed in the ns3 namespace.