A Discrete-Event Network Simulator
API
rem-spectrum-phy.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  * Modified by: Marco Miozzo <mmiozzo@cttc.es> convert to
19  * LteSpectrumSignalParametersDlCtrlFrame framework
20  */
21 
22 #include "rem-spectrum-phy.h"
23 
24 #include <ns3/antenna-model.h>
25 #include <ns3/double.h>
26 #include <ns3/log.h>
27 #include <ns3/lte-spectrum-signal-parameters.h>
28 #include <ns3/object-factory.h>
29 #include <ns3/simulator.h>
30 #include <ns3/trace-source-accessor.h>
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("RemSpectrumPhy");
36 
37 NS_OBJECT_ENSURE_REGISTERED(RemSpectrumPhy);
38 
40  : m_mobility(nullptr),
41  m_referenceSignalPower(0),
42  m_sumPower(0),
43  m_active(true),
44  m_useDataChannel(false),
45  m_rbId(-1)
46 {
47  NS_LOG_FUNCTION(this);
48 }
49 
51 {
52  NS_LOG_FUNCTION(this);
53 }
54 
55 void
57 {
58  NS_LOG_FUNCTION(this);
59  m_mobility = nullptr;
61 }
62 
63 TypeId
65 {
66  static TypeId tid = TypeId("ns3::RemSpectrumPhy")
68  .SetGroupName("Lte")
69  .AddConstructor<RemSpectrumPhy>();
70  return tid;
71 }
72 
73 void
75 {
76  // this is a no-op, RemSpectrumPhy does not transmit hence it does not need a reference to the
77  // channel
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION(this << m);
84  m_mobility = m;
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION(this << d);
91  // this is a no-op, RemSpectrumPhy does not handle any data hence it does not support the use of
92  // a NetDevice
93 }
94 
97 {
98  return m_mobility;
99 }
100 
103 {
104  return nullptr;
105 }
106 
109 {
110  return m_rxSpectrumModel;
111 }
112 
115 {
116  return nullptr;
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION(this << params);
123 
124  if (m_active)
125  {
126  if (m_useDataChannel)
127  {
129  DynamicCast<LteSpectrumSignalParametersDataFrame>(params);
130  if (lteDlDataRxParams)
131  {
132  NS_LOG_DEBUG("StartRx data");
133  double power = 0;
134  if (m_rbId >= 0)
135  {
136  power = (*(params->psd))[m_rbId] * 180000;
137  }
138  else
139  {
140  power = Integral(*(params->psd));
141  }
142 
143  m_sumPower += power;
144  if (power > m_referenceSignalPower)
145  {
146  m_referenceSignalPower = power;
147  }
148  }
149  }
150  else
151  {
153  DynamicCast<LteSpectrumSignalParametersDlCtrlFrame>(params);
154  if (lteDlCtrlRxParams)
155  {
156  NS_LOG_DEBUG("StartRx control");
157  double power = 0;
158  if (m_rbId >= 0)
159  {
160  power = (*(params->psd))[m_rbId] * 180000;
161  }
162  else
163  {
164  power = Integral(*(params->psd));
165  }
166 
167  m_sumPower += power;
168  if (power > m_referenceSignalPower)
169  {
170  m_referenceSignalPower = power;
171  }
172  }
173  }
174  }
175 }
176 
177 void
179 {
180  NS_LOG_FUNCTION(this << m);
182 }
183 
184 double
185 RemSpectrumPhy::GetSinr(double noisePower) const
186 {
187  return m_referenceSignalPower / (m_sumPower - m_referenceSignalPower + noisePower);
188 }
189 
190 void
192 {
193  m_active = false;
194 }
195 
196 bool
198 {
199  return m_active;
200 }
201 
202 void
204 {
206  m_sumPower = 0;
207 }
208 
209 void
211 {
213 }
214 
215 void
217 {
218  m_rbId = rbId;
219 }
220 
221 } // namespace ns3
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This minimal SpectrumPhy implementation calculates the SINR with respect to the strongest signal for ...
double m_referenceSignalPower
reference signal power
Ptr< MobilityModel > m_mobility
the mobility model
void DoDispose() override
Destructor implementation.
void Reset()
Reset the SINR calculator.
double GetSinr(double noisePower) const
void Deactivate()
make StartRx a no-op from now on, and mark instance as inactive
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
void StartRx(Ptr< SpectrumSignalParameters > params) override
Notify the SpectrumPhy instance of an incoming signal.
Ptr< Object > GetAntenna() const override
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
void SetRbId(int32_t rbId)
set RB Id
static TypeId GetTypeId()
Get the type ID.
double m_sumPower
sum power
void SetRxSpectrumModel(Ptr< const SpectrumModel > m)
set the RX spectrum model to be used
Ptr< const SpectrumModel > GetRxSpectrumModel() const override
Ptr< NetDevice > GetDevice() const override
Get the associated NetDevice instance.
bool m_active
is active?
void SetMobility(Ptr< MobilityModel > m) override
Set the mobility model associated with this device.
void SetUseDataChannel(bool value)
set usage of DataChannel
Ptr< MobilityModel > GetMobility() const override
Get the associated MobilityModel instance.
void SetChannel(Ptr< SpectrumChannel > c) override
Set the channel attached to this device.
bool m_useDataChannel
use data channel
void SetDevice(Ptr< NetDevice > d) override
Set the associated NetDevice instance.
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:46
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double Integral(const SpectrumValue &arg)
value
Definition: second.py:41
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.