A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("RemSpectrumPhy");
35 
36 namespace ns3 {
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  .AddConstructor<RemSpectrumPhy> ()
72  ;
73  return tid;
74 }
75 
76 
77 
78 void
80 {
81  // this is a no-op, RemSpectrumPhy does not transmit hence it does not need a reference to the channel
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION (this << m);
88  m_mobility = m;
89 }
90 
91 void
93 {
94  NS_LOG_FUNCTION (this << d);
95  // this is a no-op, RemSpectrumPhy does not handle any data hence it does not support the use of a NetDevice
96 }
97 
100 {
101  return m_mobility;
102 }
103 
106 {
107  return 0;
108 }
109 
112 {
113  return m_rxSpectrumModel;
114 }
115 
118 {
119  return 0;
120 }
121 
122 
123 void
125 {
126  NS_LOG_FUNCTION ( this << params);
127 
128  if (m_active)
129  {
130  if (m_useDataChannel)
131  {
132  Ptr<LteSpectrumSignalParametersDataFrame> lteDlDataRxParams = DynamicCast<LteSpectrumSignalParametersDataFrame> (params);
133  if (lteDlDataRxParams != 0)
134  {
135  NS_LOG_DEBUG ("StartRx data");
136  double power = 0;
137  if (m_rbId >= 0)
138  {
139  power = (*(params->psd))[m_rbId] * 180000;
140  }
141  else
142  {
143  power = Integral (*(params->psd));
144  }
145 
146  m_sumPower += power;
147  if (power > m_referenceSignalPower)
148  {
149  m_referenceSignalPower = power;
150  }
151  }
152  }
153  else
154  {
155  Ptr<LteSpectrumSignalParametersDlCtrlFrame> lteDlCtrlRxParams = DynamicCast<LteSpectrumSignalParametersDlCtrlFrame> (params);
156  if (lteDlCtrlRxParams != 0)
157  {
158  NS_LOG_DEBUG ("StartRx control");
159  double power = 0;
160  if (m_rbId >= 0)
161  {
162  power = (*(params->psd))[m_rbId] * 180000;
163  }
164  else
165  {
166  power = Integral (*(params->psd));
167  }
168 
169  m_sumPower += power;
170  if (power > m_referenceSignalPower)
171  {
172  m_referenceSignalPower = power;
173  }
174  }
175  }
176  }
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION (this << m);
183  m_rxSpectrumModel = m;
184 }
185 
186 double
187 RemSpectrumPhy::GetSinr (double noisePower)
188 {
189  return m_referenceSignalPower / (m_sumPower - m_referenceSignalPower + noisePower);
190 }
191 
192 void
194 {
195  m_active = false;
196 }
197 
198 bool
200 {
201  return m_active;
202 }
203 
204 void
206 {
208  m_sumPower = 0;
209 }
210 
211 void
213 {
214  m_useDataChannel = value;
215 }
216 
217 void
219 {
220  m_rbId = rbId;
221 }
222 
223 
224 } // namespace ns3
Ptr< MobilityModel > GetMobility()
get the associated MobilityModel instance
double GetSinr(double noisePower)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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 the class in the ns-3 factory.
Definition: object-base.h:38
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:170
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
Ptr< AntennaModel > GetRxAntenna()
get the AntennaModel used by the NetDevice for reception
Ptr< NetDevice > GetDevice()
get the associated NetDevice instance
void Reset()
Reset the SINR calculator.
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
Ptr< MobilityModel > m_mobility
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
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:213
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
void SetRbId(int32_t rbId)
set RB Id
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
static TypeId GetTypeId(void)
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
Ptr< const SpectrumModel > GetRxSpectrumModel() const
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance