A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 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#include "spectrum-channel.h"
21
22#include <ns3/abort.h>
23#include <ns3/double.h>
24#include <ns3/log.h>
25#include <ns3/pointer.h>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("SpectrumChannel");
31
32NS_OBJECT_ENSURE_REGISTERED(SpectrumChannel);
33
35{
36 NS_LOG_FUNCTION(this);
37}
38
40{
41}
42
43void
45{
46 NS_LOG_FUNCTION(this);
47 m_propagationLoss = nullptr;
48 m_propagationDelay = nullptr;
50}
51
54{
55 static TypeId tid =
56 TypeId("ns3::SpectrumChannel")
58 .SetGroupName("Spectrum")
59 .AddAttribute("MaxLossDb",
60 "If a single-frequency PropagationLossModel is used, "
61 "this value represents the maximum loss in dB for which "
62 "transmissions will be passed to the receiving PHY. "
63 "Signals for which the PropagationLossModel returns "
64 "a loss bigger than this value will not be propagated "
65 "to the receiver. This parameter is to be used to reduce "
66 "the computational load by not propagating signals "
67 "that are far beyond the interference range. Note that "
68 "the default value corresponds to considering all signals "
69 "for reception. Tune this value with care.",
70 DoubleValue(1.0e9),
72 MakeDoubleChecker<double>())
73
74 .AddAttribute("PropagationLossModel",
75 "A pointer to the propagation loss model attached to this channel.",
76 PointerValue(nullptr),
78 MakePointerChecker<PropagationLossModel>())
79
80 .AddTraceSource("Gain",
81 "This trace is fired whenever a new path loss value "
82 "is calculated. The parameters to this trace are : "
83 "Pointer to the mobility model of the transmitter, "
84 "Pointer to the mobility model of the receiver, "
85 "Tx antenna gain, "
86 "Rx antenna gain, "
87 "Propagation gain, "
88 "Pathloss",
90 "ns3::SpectrumChannel::GainTracedCallback")
91
92 .AddTraceSource("PathLoss",
93 "This trace is fired whenever a new path loss value "
94 "is calculated. The first and second parameters "
95 "to the trace are pointers respectively to the TX and "
96 "RX SpectrumPhy instances, whereas the third parameters "
97 "is the loss value in dB. Note that the loss value "
98 "reported by this trace is the single-frequency loss "
99 "value obtained by evaluating only the TX and RX "
100 "AntennaModels and the PropagationLossModel. "
101 "In particular, note that SpectrumPropagationLossModel "
102 "(even if present) is never used to evaluate the "
103 "loss value reported in this trace.",
105 "ns3::SpectrumChannel::LossTracedCallback")
106
107 .AddTraceSource("TxSigParams",
108 "This trace is fired whenever a signal is transmitted. "
109 "The sole parameter is a pointer to a copy of the "
110 "SpectrumSignalParameters provided by the transmitter.",
112 "ns3::SpectrumChannel::SignalParametersTracedCallback");
113 return tid;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << loss);
121 {
122 loss->SetNext(m_propagationLoss);
123 }
124 m_propagationLoss = loss;
125}
126
127void
129{
130 NS_LOG_FUNCTION(this << loss);
132 {
133 loss->SetNext(m_spectrumPropagationLoss);
134 }
136}
137
138void
141{
142 NS_LOG_FUNCTION(this << loss);
144 {
146 }
148}
149
150void
152{
153 NS_LOG_FUNCTION(this << filter);
154
155 if (m_filter)
156 {
157 filter->SetNext(m_filter);
158 }
159 m_filter = filter;
160}
161
164{
165 return m_filter;
166}
167
168void
170{
171 NS_ABORT_MSG_IF(m_propagationDelay, "Error, called SetPropagationDelayModel() twice");
172 m_propagationDelay = delay;
173}
174
177{
179}
180
183{
185}
186
189{
190 return m_propagationLoss;
191}
192
195{
196 return m_propagationDelay;
197}
198
199int64_t
201{
202 NS_LOG_FUNCTION(this << stream);
203 auto currentStream = stream;
204 auto lastCurrentStream = stream;
206 {
207 currentStream += m_propagationLoss->AssignStreams(currentStream);
208 }
209 if (currentStream - lastCurrentStream)
210 {
211 NS_LOG_DEBUG("PropagationLossModel objects used " << currentStream - lastCurrentStream
212 << " streams");
213 }
214 lastCurrentStream = currentStream;
216 {
217 m_propagationDelay->AssignStreams(currentStream);
218 currentStream += 1;
219 }
220 if (currentStream - lastCurrentStream)
221 {
222 NS_LOG_DEBUG("PropagationDelayModel object used " << currentStream - lastCurrentStream
223 << " streams");
224 }
225 lastCurrentStream = currentStream;
227 {
228 currentStream += m_spectrumPropagationLoss->AssignStreams(currentStream);
229 }
230 if (currentStream - lastCurrentStream)
231 {
232 NS_LOG_DEBUG("SpectrumPropagationLossModel objects used "
233 << currentStream - lastCurrentStream << " streams");
234 }
235 lastCurrentStream = currentStream;
237 {
238 currentStream += m_phasedArraySpectrumPropagationLoss->AssignStreams(currentStream);
239 }
240 if (currentStream - lastCurrentStream)
241 {
242 NS_LOG_DEBUG("PhasedArraySpectrumPropagationLossModel objects used "
243 << currentStream - lastCurrentStream << " streams");
244 }
245 lastCurrentStream = currentStream;
246 if (m_filter)
247 {
248 currentStream += m_filter->AssignStreams(currentStream);
249 }
250 if (currentStream - lastCurrentStream)
251 {
252 NS_LOG_DEBUG("SpectrumTransmitFilter objects used " << currentStream - lastCurrentStream
253 << " streams");
254 }
255 currentStream += DoAssignStreams(currentStream);
256 NS_LOG_DEBUG("Assigned a total of " << currentStream - stream << " streams");
257 return (currentStream - stream);
258}
259
260int64_t
262{
263 NS_LOG_FUNCTION(this << stream);
264 return 0;
265}
266
267} // namespace ns3
Abstract Channel Base Class.
Definition: channel.h:45
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
AttributeValue implementation for Pointer.
Definition: pointer.h:48
int64_t AssignStreams(int64_t stream)
If this loss model uses objects of type RandomVariableStream, set the stream numbers to the integers ...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add the single-frequency propagation loss model to be used.
TracedCallback< Ptr< SpectrumSignalParameters > > m_txSigParamsTrace
Traced callback for SpectrumSignalParameters in StartTx requests.
void DoDispose() override
Destructor implementation.
Ptr< SpectrumTransmitFilter > m_filter
Transmit filter to be used with this channel.
void AddSpectrumPropagationLossModel(Ptr< SpectrumPropagationLossModel > loss)
Add the frequency-dependent propagation loss model to be used.
SpectrumChannel()
constructor
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
void AddSpectrumTransmitFilter(Ptr< SpectrumTransmitFilter > filter)
Add the transmit filter to be used to filter possible signal receptions at the StartTx() time.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
Ptr< PhasedArraySpectrumPropagationLossModel > m_phasedArraySpectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
TracedCallback< Ptr< const SpectrumPhy >, Ptr< const SpectrumPhy >, double > m_pathLossTrace
The PathLoss trace source.
Ptr< SpectrumTransmitFilter > GetSpectrumTransmitFilter() const
Get the transmit filter, or first in a chain of transmit filters if more than one is present.
TracedCallback< Ptr< const MobilityModel >, Ptr< const MobilityModel >, double, double, double, double > m_gainTrace
The Gain trace source.
int64_t AssignStreams(int64_t stream)
This method calls AssignStreams() on any/all of the PropagationLossModel, PropagationDelayModel,...
Ptr< PropagationLossModel > m_propagationLoss
Single-frequency propagation loss model to be used with this channel.
static TypeId GetTypeId()
Get the type ID.
Ptr< SpectrumPropagationLossModel > GetSpectrumPropagationLossModel() const
Get the frequency-dependent propagation loss model.
virtual int64_t DoAssignStreams(int64_t stream)
This provides a base class implementation that may be subclassed if needed by subclasses that might n...
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
Ptr< PropagationLossModel > GetPropagationLossModel() const
Get the propagation loss model.
Ptr< PhasedArraySpectrumPropagationLossModel > GetPhasedArraySpectrumPropagationLossModel() const
Get the frequency-dependent propagation loss model that is compatible with the phased antenna arrays ...
Ptr< PropagationDelayModel > GetPropagationDelayModel() const
Get the propagation delay model that has been set on the channel.
double m_maxLossDb
Maximum loss [dB].
void AddPhasedArraySpectrumPropagationLossModel(Ptr< PhasedArraySpectrumPropagationLossModel > loss)
Add the frequency-dependent propagation loss model that is compapatible with the phased antenna array...
~SpectrumChannel() override
destructor
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:259
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.