A Discrete-Event Network Simulator
API
rem-spectrum-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Nicola Baldo <nbaldo@cttc.es>
19  * Modified by: Marco Miozzo <mmiozzo@cttc.es> convert to
20  * LteSpectrumSignalParametersDlCtrlFrame framework
21  */
22 
23 
24 #include <ns3/object-factory.h>
25 #include <ns3/log.h>
26 #include <ns3/double.h>
27 #include <ns3/simulator.h>
28 #include <ns3/trace-source-accessor.h>
29 #include <ns3/lte-spectrum-signal-parameters.h>
30 #include <ns3/antenna-model.h>
31 
32 #include "rem-spectrum-phy.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("RemSpectrumPhy");
37 
38 NS_OBJECT_ENSURE_REGISTERED (RemSpectrumPhy);
39 
41  : m_mobility (0),
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 
51 
52 
54 {
55  NS_LOG_FUNCTION (this);
56 }
57 
58 void
60 {
61  NS_LOG_FUNCTION (this);
62  m_mobility = 0;
64 }
65 
66 TypeId
68 {
69  static TypeId tid = TypeId ("ns3::RemSpectrumPhy")
71  .SetGroupName("Lte")
72  .AddConstructor<RemSpectrumPhy> ()
73  ;
74  return tid;
75 }
76 
77 
78 
79 void
81 {
82  // this is a no-op, RemSpectrumPhy does not transmit hence it does not need a reference to the channel
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION (this << m);
89  m_mobility = m;
90 }
91 
92 void
94 {
95  NS_LOG_FUNCTION (this << d);
96  // this is a no-op, RemSpectrumPhy does not handle any data hence it does not support the use of a NetDevice
97 }
98 
101 {
102  return m_mobility;
103 }
104 
107 {
108  return 0;
109 }
110 
113 {
114  return m_rxSpectrumModel;
115 }
116 
119 {
120  return 0;
121 }
122 
123 
124 void
126 {
127  NS_LOG_FUNCTION ( this << params);
128 
129  if (m_active)
130  {
131  if (m_useDataChannel)
132  {
133  Ptr<LteSpectrumSignalParametersDataFrame> lteDlDataRxParams = DynamicCast<LteSpectrumSignalParametersDataFrame> (params);
134  if (lteDlDataRxParams != 0)
135  {
136  NS_LOG_DEBUG ("StartRx data");
137  double power = 0;
138  if (m_rbId >= 0)
139  {
140  power = (*(params->psd))[m_rbId] * 180000;
141  }
142  else
143  {
144  power = Integral (*(params->psd));
145  }
146 
147  m_sumPower += power;
148  if (power > m_referenceSignalPower)
149  {
150  m_referenceSignalPower = power;
151  }
152  }
153  }
154  else
155  {
156  Ptr<LteSpectrumSignalParametersDlCtrlFrame> lteDlCtrlRxParams = DynamicCast<LteSpectrumSignalParametersDlCtrlFrame> (params);
157  if (lteDlCtrlRxParams != 0)
158  {
159  NS_LOG_DEBUG ("StartRx control");
160  double power = 0;
161  if (m_rbId >= 0)
162  {
163  power = (*(params->psd))[m_rbId] * 180000;
164  }
165  else
166  {
167  power = Integral (*(params->psd));
168  }
169 
170  m_sumPower += power;
171  if (power > m_referenceSignalPower)
172  {
173  m_referenceSignalPower = power;
174  }
175  }
176  }
177  }
178 }
179 
180 void
182 {
183  NS_LOG_FUNCTION (this << m);
184  m_rxSpectrumModel = m;
185 }
186 
187 double
188 RemSpectrumPhy::GetSinr (double noisePower)
189 {
190  return m_referenceSignalPower / (m_sumPower - m_referenceSignalPower + noisePower);
191 }
192 
193 void
195 {
196  m_active = false;
197 }
198 
199 bool
201 {
202  return m_active;
203 }
204 
205 void
207 {
209  m_sumPower = 0;
210 }
211 
212 void
214 {
215  m_useDataChannel = value;
216 }
217 
218 void
220 {
221  m_rbId = rbId;
222 }
223 
224 
225 } // namespace ns3
Ptr< MobilityModel > GetMobility()
Get the associated MobilityModel instance.
double GetSinr(double noisePower)
Ptr< NetDevice > GetDevice() const
Get the associated NetDevice instance.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
double Integral(const SpectrumValue &arg)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool m_active
is active?
void SetRxSpectrumModel(Ptr< const SpectrumModel > m)
set the RX spectrum model to be used
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
double m_referenceSignalPower
reference signal power
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
Ptr< AntennaModel > GetRxAntenna()
Get the AntennaModel used by the NetDevice for reception.
void Reset()
Reset the SINR calculator.
This minimal SpectrumPhy implementation calculates the SINR with respect to the strongest signal for ...
void Deactivate()
make StartRx a no-op from now on, and mark instance as inactive
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
double m_sumPower
sum power
Ptr< MobilityModel > m_mobility
the mobility model
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const SpectrumModel > GetRxSpectrumModel() const
void SetUseDataChannel(bool value)
set usage of DataChannel
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
void SetRbId(int32_t rbId)
set RB Id
void DoDispose()
Destructor implementation.
static TypeId GetTypeId(void)
Get the type ID.
bool m_useDataChannel
use data channel
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.