A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-interference.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
10
12
13#include <ns3/log.h>
14#include <ns3/simulator.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("SpectrumInterference");
20
22 : m_receiving(false),
23 m_rxSignal(nullptr),
24 m_allSignals(nullptr),
25 m_noise(nullptr),
26 m_errorModel(nullptr)
27{
28 NS_LOG_FUNCTION(this);
29}
30
35
38{
39 static TypeId tid = TypeId("ns3::SpectrumInterference")
41 .SetGroupName("Spectrum")
42 .AddConstructor<SpectrumInterference>();
43 return tid;
44}
45
46void
48{
49 NS_LOG_FUNCTION(this);
50 m_rxSignal = nullptr;
51 m_allSignals = nullptr;
52 m_noise = nullptr;
53 m_errorModel = nullptr;
55}
56
57void
59{
60 NS_LOG_FUNCTION(this << p << *rxPsd);
61 m_rxSignal = rxPsd;
63 m_receiving = true;
64 m_errorModel->StartRx(p);
65}
66
67void
72
73bool
75{
76 NS_LOG_FUNCTION(this);
78 m_receiving = false;
79 return m_errorModel->IsRxCorrect();
80}
81
82void
84{
85 NS_LOG_FUNCTION(this << *spd << duration);
86 DoAddSignal(spd);
88}
89
90void
92{
93 NS_LOG_FUNCTION(this << *spd);
95 (*m_allSignals) += (*spd);
97}
98
99void
101{
102 NS_LOG_FUNCTION(this << *spd);
104 (*m_allSignals) -= (*spd);
106}
107
108void
110{
111 NS_LOG_FUNCTION(this);
112 NS_LOG_LOGIC("m_receiving: " << m_receiving);
113 NS_LOG_LOGIC("m_lastChangeTime: " << m_lastChangeTime << " Now: " << Now());
114 bool condition = m_receiving && (Now() > m_lastChangeTime);
115 NS_LOG_LOGIC("if condition: " << condition);
116 if (condition)
117 {
118 SpectrumValue sinr = (*m_rxSignal) / ((*m_allSignals) - (*m_rxSignal) + (*m_noise));
119 Time duration = Now() - m_lastChangeTime;
120 NS_LOG_LOGIC("calling m_errorModel->EvaluateChunk (sinr, duration)");
121 m_errorModel->EvaluateChunk(sinr, duration);
122 }
123}
124
125void
127{
128 NS_LOG_FUNCTION(this << noisePsd);
129 m_noise = noisePsd;
130 // we can initialize m_allSignal only now, because earlier we
131 // didn't know what spectrum model was going to be used.
132 // we'll now create a zeroed SpectrumValue using the same
133 // SpectrumModel which is being specified for the noise.
134 m_allSignals = Create<SpectrumValue>(noisePsd->GetSpectrumModel());
135}
136
137void
143
144} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
This class implements a gaussian interference model, i.e., all incoming signals are added to the tota...
void AbortRx()
Notify that the PHY has aborted RX.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the Noise Power Spectral Density.
void ConditionallyEvaluateChunk()
Evaluate a Chunk, depending on the Rx status and the last update time.
Ptr< SpectrumValue > m_allSignals
Stores the spectral power density of the sum of incoming signals; does not include noise,...
bool EndRx()
Notify that the RX attempt has ended.
Time m_lastChangeTime
the time of the last change in m_TotalPower
bool m_receiving
True if in Rx status.
static TypeId GetTypeId()
Register this type.
Ptr< const SpectrumValue > m_noise
Noise spectral power density.
void SetErrorModel(Ptr< SpectrumErrorModel > e)
Set the SpectrumErrorModel to be used.
void DoSubtractSignal(Ptr< const SpectrumValue > spd)
Removes a signal perceived in the medium.
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
Notify that the PHY is starting a RX attempt.
Ptr< SpectrumErrorModel > m_errorModel
Error model.
void DoAddSignal(Ptr< const SpectrumValue > spd)
Adds a signal perceived in the medium.
void DoDispose() override
Destructor implementation.
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
Notify that a new signal is being perceived in the medium.
Ptr< const SpectrumValue > m_rxSignal
Stores the power spectral density of the signal whose RX is being attempted.
Set of values corresponding to a given SpectrumModel.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.