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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#ifndef SPECTRUM_HELPER_H
10#define SPECTRUM_HELPER_H
11
12#include <ns3/attribute.h>
13#include <ns3/net-device-container.h>
14#include <ns3/node-container.h>
15#include <ns3/object-factory.h>
16#include <ns3/propagation-loss-model.h>
17#include <ns3/spectrum-propagation-loss-model.h>
18
19#include <string>
20
21namespace ns3
22{
23
24class SpectrumPhy;
25class SpectrumChannel;
26class Node;
27class NetDevice;
28
29/**
30 * \ingroup spectrum
31 * \brief Setup a SpectrumChannel
32 */
34{
35 public:
36 /**
37 * \brief Setup a default SpectrumChannel. The Default mode is:
38 * Channel: "ns3::SingleModelSpectrumChannel",
39 * PropagationDelay: "ns3::ConstantSpeedPropagationDelayModel", and
40 * SpectrumPropagationLoss: "ns3::FriisSpectrumPropagationLossModel".
41 *
42 * \returns a Default-configured SpectrumChannelHelper
43 */
45
46 /**
47 * \tparam Ts \deduced Argument types
48 * \param type the type of the SpectrumChannel to use
49 * \param [in] args Name and AttributeValue pairs to set.
50 */
51 template <typename... Ts>
52 void SetChannel(std::string type, Ts&&... args);
53 /**
54 * \tparam Ts \deduced Argument types
55 * \param name the name of the model to set
56 * \param [in] args Name and AttributeValue pairs to set.
57 *
58 * Add a new single-frequency propagation loss model to this channel helper.
59 */
60 template <typename... Ts>
61 void AddPropagationLoss(std::string name, Ts&&... args);
62
63 /**
64 * Add a new single-frequency propagation loss model instance to this channel helper.
65 *
66 * \param m a pointer to the instance of the propagation loss model
67 */
69
70 /**
71 * \tparam Ts \deduced Argument types
72 * \param name the name of the model to set
73 * \param [in] args Name and AttributeValue pairs to set.
74 *
75 * Add a new frequency-dependent propagation loss model to this channel helper.
76 */
77 template <typename... Ts>
78 void AddSpectrumPropagationLoss(std::string name, Ts&&... args);
79
80 /**
81 * Add a new frequency-dependent propagation loss model instance to this channel helper.
82 *
83 * \param m a pointer to the instance of the propagation loss model
84 */
86
87 /**
88 * \tparam Ts \deduced Argument types
89 * \param name the name of the model to set
90 * \param [in] args Name and AttributeValue pairs to set.
91 *
92 * Configure a propagation delay for this channel.
93 */
94 template <typename... Ts>
95 void SetPropagationDelay(std::string name, Ts&&... args);
96
97 /**
98 * \returns a new channel
99 *
100 * Create a channel based on the configuration parameters set previously.
101 */
103
104 private:
106 m_spectrumPropagationLossModel; //!< Spectrum propagation loss model
108 ObjectFactory m_propagationDelay; //!< Propagation delay
110};
111
112/**
113 * \ingroup spectrum
114 *
115 * Create and configure several SpectrumPhy instances and connect them to a channel.
116 */
118{
119 public:
120 /**
121 * \tparam Ts \deduced Argument types
122 * \param name the type of SpectrumPhy to use
123 * \param [in] args Name and AttributeValue pairs to set.
124 */
125 template <typename... Ts>
126 void SetPhy(std::string name, Ts&&... args);
127
128 /**
129 * set the channel that will be used by SpectrumPhy instances created by this helper
130 *
131 * @param channel
132 */
133 void SetChannel(Ptr<SpectrumChannel> channel);
134
135 /**
136 * set the channel that will be used by SpectrumPhy instances created by this helper
137 *
138 * @param channelName
139 */
140 void SetChannel(std::string channelName);
141
142 /**
143 * \param name the name of the attribute to set
144 * \param v the value of the attribute
145 *
146 * Set an attribute of the SpectrumPhy instances to be created
147 */
148 void SetPhyAttribute(std::string name, const AttributeValue& v);
149
150 /**
151 *
152 * @param node
153 * @param device
154 *
155 * @return a newly created SpectrumPhy instance
156 */
158
159 private:
160 ObjectFactory m_phy; //!< Object factory for the phy objects
162};
163
164/***************************************************************
165 * Implementation of the templates declared above.
166 ***************************************************************/
167
168template <typename... Ts>
169void
170SpectrumChannelHelper::SetChannel(std::string type, Ts&&... args)
171{
172 m_channel.SetTypeId(type);
173 m_channel.Set(std::forward<Ts>(args)...);
174}
175
176template <typename... Ts>
177void
178SpectrumChannelHelper::AddPropagationLoss(std::string name, Ts&&... args)
179{
180 ObjectFactory factory(name, std::forward<Ts>(args)...);
183}
184
185template <typename... Ts>
186void
188{
189 ObjectFactory factory(name, std::forward<Ts>(args)...);
192}
193
194template <typename... Ts>
195void
196SpectrumChannelHelper::SetPropagationDelay(std::string name, Ts&&... args)
197{
198 m_propagationDelay = ObjectFactory(name, std::forward<Ts>(args)...);
199}
200
201template <typename... Ts>
202void
203SpectrumPhyHelper::SetPhy(std::string name, Ts&&... args)
204{
205 m_phy.SetTypeId(name);
206 m_phy.Set(std::forward<Ts>(args)...);
207}
208
209} // namespace ns3
210
211#endif /* SPECTRUM_HELPER_H */
Hold a value for an Attribute.
Definition attribute.h:59
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.
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.