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
40
43{
44 static TypeId tid =
45 TypeId("ns3::SpectrumChannel")
47 .SetGroupName("Spectrum")
48 .AddAttribute("MaxLossDb",
49 "If a single-frequency PropagationLossModel is used, "
50 "this value represents the maximum loss in dB for which "
51 "transmissions will be passed to the receiving PHY. "
52 "Signals for which the PropagationLossModel returns "
53 "a loss bigger than this value will not be propagated "
54 "to the receiver. This parameter is to be used to reduce "
55 "the computational load by not propagating signals "
56 "that are far beyond the interference range. Note that "
57 "the default value corresponds to considering all signals "
58 "for reception. Tune this value with care.",
59 DoubleValue(1.0e9),
62
63 .AddAttribute("PropagationLossModel",
64 "A pointer to the propagation loss model attached to this channel.",
65 PointerValue(nullptr),
68
69 .AddTraceSource("Gain",
70 "This trace is fired whenever a new path loss value "
71 "is calculated. The parameters to this trace are : "
72 "Pointer to the mobility model of the transmitter, "
73 "Pointer to the mobility model of the receiver, "
74 "Tx antenna gain, "
75 "Rx antenna gain, "
76 "Propagation gain, "
77 "Pathloss",
79 "ns3::SpectrumChannel::GainTracedCallback")
80
81 .AddTraceSource("PathLoss",
82 "This trace is fired whenever a new path loss value "
83 "is calculated. The first and second parameters "
84 "to the trace are pointers respectively to the TX and "
85 "RX SpectrumPhy instances, whereas the third parameters "
86 "is the loss value in dB. Note that the loss value "
87 "reported by this trace is the single-frequency loss "
88 "value obtained by evaluating only the TX and RX "
89 "AntennaModels and the PropagationLossModel. "
90 "In particular, note that SpectrumPropagationLossModel "
91 "(even if present) is never used to evaluate the "
92 "loss value reported in this trace.",
94 "ns3::SpectrumChannel::LossTracedCallback")
95
96 .AddTraceSource("TxSigParams",
97 "This trace is fired whenever a signal is transmitted. "
98 "The sole parameter is a pointer to a copy of the "
99 "SpectrumSignalParameters provided by the transmitter.",
101 "ns3::SpectrumChannel::SignalParametersTracedCallback");
102 return tid;
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << loss);
110 {
111 loss->SetNext(m_propagationLoss);
112 }
113 m_propagationLoss = loss;
114}
115
116void
126
127void
138
139void
141{
142 NS_LOG_FUNCTION(this << filter);
143
144 if (m_filter)
145 {
146 filter->SetNext(m_filter);
147 }
148 m_filter = filter;
149}
150
156
157void
159{
160 NS_ABORT_MSG_IF(m_propagationDelay, "Error, called SetPropagationDelayModel() twice");
161 m_propagationDelay = delay;
162}
163
169
175
181
187
188int64_t
190{
191 NS_LOG_FUNCTION(this << stream);
192 auto currentStream = stream;
193 auto lastCurrentStream = stream;
195 {
196 currentStream += m_propagationLoss->AssignStreams(currentStream);
197 }
198 if (currentStream - lastCurrentStream)
199 {
200 NS_LOG_DEBUG("PropagationLossModel objects used " << currentStream - lastCurrentStream
201 << " streams");
202 }
203 lastCurrentStream = currentStream;
205 {
206 m_propagationDelay->AssignStreams(currentStream);
207 currentStream += 1;
208 }
209 if (currentStream - lastCurrentStream)
210 {
211 NS_LOG_DEBUG("PropagationDelayModel object used " << currentStream - lastCurrentStream
212 << " streams");
213 }
214 lastCurrentStream = currentStream;
216 {
217 currentStream += m_spectrumPropagationLoss->AssignStreams(currentStream);
218 }
219 if (currentStream - lastCurrentStream)
220 {
221 NS_LOG_DEBUG("SpectrumPropagationLossModel objects used "
222 << currentStream - lastCurrentStream << " streams");
223 }
224 lastCurrentStream = currentStream;
226 {
227 currentStream += m_phasedArraySpectrumPropagationLoss->AssignStreams(currentStream);
228 }
229 if (currentStream - lastCurrentStream)
230 {
231 NS_LOG_DEBUG("PhasedArraySpectrumPropagationLossModel objects used "
232 << currentStream - lastCurrentStream << " streams");
233 }
234 lastCurrentStream = currentStream;
235 if (m_filter)
236 {
237 currentStream += m_filter->AssignStreams(currentStream);
238 }
239 if (currentStream - lastCurrentStream)
240 {
241 NS_LOG_DEBUG("SpectrumTransmitFilter objects used " << currentStream - lastCurrentStream
242 << " streams");
243 }
244 currentStream += DoAssignStreams(currentStream);
245 NS_LOG_DEBUG("Assigned a total of " << currentStream - stream << " streams");
246 return (currentStream - stream);
247}
248
249int64_t
251{
252 NS_LOG_FUNCTION(this << stream);
253 return 0;
254}
255
256} // 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.