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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "spectrum-channel.h"
10
11#include "ns3/abort.h"
12#include "ns3/double.h"
13#include "ns3/log.h"
14#include "ns3/pointer.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("SpectrumChannel");
20
21NS_OBJECT_ENSURE_REGISTERED(SpectrumChannel);
22
27
31
32void
34{
35 NS_LOG_FUNCTION(this);
36
37 // Any propagation model that holds a pointer
38 // back to the spectrum channel should not call Dispose()
39 // of its channel pointer, or else a loop may occur.
40 m_propagationLoss = nullptr;
41 m_propagationDelay = nullptr;
44 {
46 }
48}
49
52{
53 static TypeId tid =
54 TypeId("ns3::SpectrumChannel")
56 .SetGroupName("Spectrum")
57 .AddAttribute("MaxLossDb",
58 "If a single-frequency PropagationLossModel is used, "
59 "this value represents the maximum loss in dB for which "
60 "transmissions will be passed to the receiving PHY. "
61 "Signals for which the PropagationLossModel returns "
62 "a loss bigger than this value will not be propagated "
63 "to the receiver. This parameter is to be used to reduce "
64 "the computational load by not propagating signals "
65 "that are far beyond the interference range. Note that "
66 "the default value corresponds to considering all signals "
67 "for reception. Tune this value with care.",
68 DoubleValue(1.0e9),
71
72 .AddAttribute("PropagationLossModel",
73 "A pointer to the propagation loss model attached to this channel.",
74 PointerValue(nullptr),
77
78 .AddTraceSource("Gain",
79 "This trace is fired whenever a new path loss value "
80 "is calculated. The parameters to this trace are : "
81 "Pointer to the mobility model of the transmitter, "
82 "Pointer to the mobility model of the receiver, "
83 "Tx antenna gain, "
84 "Rx antenna gain, "
85 "Propagation gain, "
86 "Pathloss",
88 "ns3::SpectrumChannel::GainTracedCallback")
89
90 .AddTraceSource("PathLoss",
91 "This trace is fired whenever a new path loss value "
92 "is calculated. The first and second parameters "
93 "to the trace are pointers respectively to the TX and "
94 "RX SpectrumPhy instances, whereas the third parameters "
95 "is the loss value in dB. Note that the loss value "
96 "reported by this trace is the single-frequency loss "
97 "value obtained by evaluating only the TX and RX "
98 "AntennaModels and the PropagationLossModel. "
99 "In particular, note that SpectrumPropagationLossModel "
100 "(even if present) is never used to evaluate the "
101 "loss value reported in this trace.",
103 "ns3::SpectrumChannel::LossTracedCallback")
104
105 .AddTraceSource("TxSigParams",
106 "This trace is fired whenever a signal is transmitted. "
107 "The sole parameter is a pointer to a copy of the "
108 "SpectrumSignalParameters provided by the transmitter.",
110 "ns3::SpectrumChannel::SignalParametersTracedCallback");
111 return tid;
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << loss);
119 {
120 loss->SetNext(m_propagationLoss);
121 }
122 m_propagationLoss = loss;
123}
124
125void
135
136void
147
148void
150{
151 NS_LOG_FUNCTION(this << filter);
152
153 if (m_filter)
154 {
155 filter->SetNext(m_filter);
156 }
157 m_filter = filter;
158}
159
165
166void
168{
169 NS_ABORT_MSG_IF(m_propagationDelay, "Error, called SetPropagationDelayModel() twice");
170 m_propagationDelay = delay;
171}
172
178
184
190
196
197int64_t
199{
200 NS_LOG_FUNCTION(this << stream);
201 auto currentStream = stream;
202 auto lastCurrentStream = stream;
204 {
205 currentStream += m_propagationLoss->AssignStreams(currentStream);
206 }
207 if (currentStream - lastCurrentStream)
208 {
209 NS_LOG_DEBUG("PropagationLossModel objects used " << currentStream - lastCurrentStream
210 << " streams");
211 }
212 lastCurrentStream = currentStream;
214 {
215 m_propagationDelay->AssignStreams(currentStream);
216 currentStream += 1;
217 }
218 if (currentStream - lastCurrentStream)
219 {
220 NS_LOG_DEBUG("PropagationDelayModel object used " << currentStream - lastCurrentStream
221 << " streams");
222 }
223 lastCurrentStream = currentStream;
225 {
226 currentStream += m_spectrumPropagationLoss->AssignStreams(currentStream);
227 }
228 if (currentStream - lastCurrentStream)
229 {
230 NS_LOG_DEBUG("SpectrumPropagationLossModel objects used "
231 << currentStream - lastCurrentStream << " streams");
232 }
233 lastCurrentStream = currentStream;
235 {
236 currentStream += m_phasedArraySpectrumPropagationLoss->AssignStreams(currentStream);
237 }
238 if (currentStream - lastCurrentStream)
239 {
240 NS_LOG_DEBUG("PhasedArraySpectrumPropagationLossModel objects used "
241 << currentStream - lastCurrentStream << " streams");
242 }
243 lastCurrentStream = currentStream;
244 if (m_filter)
245 {
246 currentStream += m_filter->AssignStreams(currentStream);
247 }
248 if (currentStream - lastCurrentStream)
249 {
250 NS_LOG_DEBUG("SpectrumTransmitFilter objects used " << currentStream - lastCurrentStream
251 << " streams");
252 }
253 currentStream += DoAssignStreams(currentStream);
254 NS_LOG_DEBUG("Assigned a total of " << currentStream - stream << " streams");
255 return (currentStream - stream);
256}
257
258int64_t
260{
261 NS_LOG_FUNCTION(this << stream);
262 return 0;
263}
264
265} // namespace ns3
Abstract Channel Base Class.
Definition channel.h:34
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
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.
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:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition double.h:32
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
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.