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 
25 
26 #include <ns3/antenna-model.h>
27 #include <ns3/double.h>
28 #include <ns3/log.h>
29 #include <ns3/object-factory.h>
30 #include <ns3/simulator.h>
31 #include <ns3/trace-source-accessor.h>
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("RemSpectrumPhy");
37 
38 NS_OBJECT_ENSURE_REGISTERED(RemSpectrumPhy);
39 
41  : m_mobility(nullptr),
42  m_referenceSignalPower(0),
43  m_sumPower(0),
44  m_active(true),
45  m_useDataChannel(false),
46  m_rbId(-1)
47 {
48  NS_LOG_FUNCTION(this);
49 }
50 
52 {
53  NS_LOG_FUNCTION(this);
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION(this);
60  m_mobility = nullptr;
62 }
63 
64 TypeId
66 {
67  static TypeId tid = TypeId("ns3::RemSpectrumPhy")
69  .SetGroupName("Lte")
70  .AddConstructor<RemSpectrumPhy>();
71  return tid;
72 }
73 
74 void
76 {
77  // this is a no-op, RemSpectrumPhy does not transmit hence it does not need a reference to the
78  // channel
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION(this << m);
85  m_mobility = m;
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION(this << d);
92  // this is a no-op, RemSpectrumPhy does not handle any data hence it does not support the use of
93  // a NetDevice
94 }
95 
98 {
99  return m_mobility;
100 }
101 
104 {
105  return nullptr;
106 }
107 
110 {
111  return m_rxSpectrumModel;
112 }
113 
116 {
117  return nullptr;
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION(this << params);
124 
125  if (m_active)
126  {
127  if (m_useDataChannel)
128  {
130  DynamicCast<LteSpectrumSignalParametersDataFrame>(params);
131  if (lteDlDataRxParams)
132  {
133  NS_LOG_DEBUG("StartRx data");
134  double power = 0;
135  if (m_rbId >= 0)
136  {
137  power = (*(params->psd))[m_rbId] * 180000;
138  }
139  else
140  {
141  power = Integral(*(params->psd));
142  }
143 
144  m_sumPower += power;
145  if (power > m_referenceSignalPower)
146  {
147  m_referenceSignalPower = power;
148  }
149  }
150  }
151  else
152  {
154  DynamicCast<LteSpectrumSignalParametersDlCtrlFrame>(params);
155  if (lteDlCtrlRxParams)
156  {
157  NS_LOG_DEBUG("StartRx control");
158  double power = 0;
159  if (m_rbId >= 0)
160  {
161  power = (*(params->psd))[m_rbId] * 180000;
162  }
163  else
164  {
165  power = Integral(*(params->psd));
166  }
167 
168  m_sumPower += power;
169  if (power > m_referenceSignalPower)
170  {
171  m_referenceSignalPower = power;
172  }
173  }
174  }
175  }
176 }
177 
178 void
180 {
181  NS_LOG_FUNCTION(this << m);
183 }
184 
185 double
186 RemSpectrumPhy::GetSinr(double noisePower) const
187 {
188  return m_referenceSignalPower / (m_sumPower - m_referenceSignalPower + noisePower);
189 }
190 
191 void
193 {
194  m_active = false;
195 }
196 
197 bool
199 {
200  return m_active;
201 }
202 
203 void
205 {
207  m_sumPower = 0;
208 }
209 
210 void
212 {
213  m_useDataChannel = value;
214 }
215 
216 void
218 {
219  m_rbId = rbId;
220 }
221 
222 } // namespace ns3
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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)
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.