A Discrete-Event Network Simulator
API
lte-phy.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
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: Giuseppe Piro <g.piro@poliba.it>
18  * Marco Miozzo <mmiozzo@cttc.es>
19  */
20 
21 #include "lte-phy.h"
22 
23 #include "lte-net-device.h"
24 
25 #include "ns3/spectrum-error-model.h"
26 #include <ns3/log.h>
27 #include <ns3/object-factory.h>
28 #include <ns3/simulator.h>
29 #include <ns3/waveform-generator.h>
30 
31 #include <cmath>
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("LtePhy");
37 
39 
41 {
42  NS_LOG_FUNCTION(this);
43  NS_FATAL_ERROR("This constructor should not be called");
44 }
45 
47  : m_downlinkSpectrumPhy(dlPhy),
48  m_uplinkSpectrumPhy(ulPhy),
49  m_tti(0.001),
50  m_ulBandwidth(0),
51  m_dlBandwidth(0),
52  m_rbgSize(0),
53  m_dlEarfcn(0),
54  m_ulEarfcn(0),
55  m_macChTtiDelay(0),
56  m_cellId(0),
57  m_componentCarrierId(0)
58 {
59  NS_LOG_FUNCTION(this);
60 }
61 
62 TypeId
64 {
65  static TypeId tid = TypeId("ns3::LtePhy").SetParent<Object>().SetGroupName("Lte");
66  return tid;
67 }
68 
70 {
71  NS_LOG_FUNCTION(this);
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION(this);
78  m_packetBurstQueue.clear();
79  m_controlMessagesQueue.clear();
80  m_downlinkSpectrumPhy->Dispose();
81  m_downlinkSpectrumPhy = nullptr;
82  m_uplinkSpectrumPhy->Dispose();
83  m_uplinkSpectrumPhy = nullptr;
84  m_netDevice = nullptr;
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION(this << d);
92  m_netDevice = d;
93 }
94 
97 {
98  NS_LOG_FUNCTION(this);
99  return m_netDevice;
100 }
101 
104 {
105  return m_downlinkSpectrumPhy;
106 }
107 
110 {
111  return m_uplinkSpectrumPhy;
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION(this << c);
118  m_downlinkSpectrumPhy->SetChannel(c);
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION(this << c);
125  m_uplinkSpectrumPhy->SetChannel(c);
126 }
127 
128 void
129 LtePhy::SetTti(double tti)
130 {
131  NS_LOG_FUNCTION(this << tti);
132  m_tti = tti;
133 }
134 
135 double
137 {
138  NS_LOG_FUNCTION(this << m_tti);
139  return m_tti;
140 }
141 
142 uint16_t
143 LtePhy::GetSrsPeriodicity(uint16_t srcCi) const
144 {
145  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
146  uint16_t SrsPeriodicity[9] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
147  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
148  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
149  uint8_t i;
150  for (i = 8; i > 0; i--)
151  {
152  if ((srcCi >= SrsCiLow[i]) && (srcCi <= SrsCiHigh[i]))
153  {
154  break;
155  }
156  }
157  return SrsPeriodicity[i];
158 }
159 
160 uint16_t
161 LtePhy::GetSrsSubframeOffset(uint16_t srcCi) const
162 {
163  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
164  uint16_t SrsSubframeOffset[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
165  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
166  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
167  uint8_t i;
168  for (i = 8; i > 0; i--)
169  {
170  if ((srcCi >= SrsCiLow[i]) && (srcCi <= SrsCiHigh[i]))
171  {
172  break;
173  }
174  }
175  return (srcCi - SrsSubframeOffset[i]);
176 }
177 
178 uint8_t
180 {
181  return m_rbgSize;
182 }
183 
184 void
186 {
187  m_packetBurstQueue.at(m_packetBurstQueue.size() - 1)->AddPacket(p);
188 }
189 
192 {
193  if (m_packetBurstQueue.at(0)->GetSize() > 0)
194  {
195  Ptr<PacketBurst> ret = m_packetBurstQueue.at(0)->Copy();
196  m_packetBurstQueue.erase(m_packetBurstQueue.begin());
197  m_packetBurstQueue.push_back(CreateObject<PacketBurst>());
198  return (ret);
199  }
200  else
201  {
202  m_packetBurstQueue.erase(m_packetBurstQueue.begin());
203  m_packetBurstQueue.push_back(CreateObject<PacketBurst>());
204  return (nullptr);
205  }
206 }
207 
208 void
210 {
211  // In uplink the queue of control messages and packet are of different sizes
212  // for avoiding TTI cancellation due to synchronization of subframe triggers
213  m_controlMessagesQueue.at(m_controlMessagesQueue.size() - 1).push_back(m);
214 }
215 
216 std::list<Ptr<LteControlMessage>>
218 {
219  NS_LOG_FUNCTION(this);
220  if (!m_controlMessagesQueue.at(0).empty())
221  {
222  std::list<Ptr<LteControlMessage>> ret = m_controlMessagesQueue.at(0);
224  std::list<Ptr<LteControlMessage>> newlist;
225  m_controlMessagesQueue.push_back(newlist);
226  return (ret);
227  }
228  else
229  {
231  std::list<Ptr<LteControlMessage>> newlist;
232  m_controlMessagesQueue.push_back(newlist);
233  std::list<Ptr<LteControlMessage>> emptylist;
234  return (emptylist);
235  }
236 }
237 
238 void
239 LtePhy::DoSetCellId(uint16_t cellId)
240 {
241  m_cellId = cellId;
242  m_downlinkSpectrumPhy->SetCellId(cellId);
243  m_uplinkSpectrumPhy->SetCellId(cellId);
244 }
245 
246 void
248 {
249  m_componentCarrierId = index;
250  m_downlinkSpectrumPhy->SetComponentCarrierId(index);
251  m_uplinkSpectrumPhy->SetComponentCarrierId(index);
252 }
253 
254 uint8_t
256 {
257  return m_componentCarrierId;
258 }
259 
260 } // namespace ns3
void DoSetCellId(uint16_t cellId)
Definition: lte-phy.cc:239
static TypeId GetTypeId()
Get the type ID.
Definition: lte-phy.cc:63
uint8_t GetRbgSize() const
Definition: lte-phy.cc:179
uint8_t GetComponentCarrierId() const
Get the component carrier ID.
Definition: lte-phy.cc:255
void DoDispose() override
Destructor implementation.
Definition: lte-phy.cc:75
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
Definition: lte-phy.cc:143
std::vector< Ptr< PacketBurst > > m_packetBurstQueue
A queue of packet bursts to be sent.
Definition: lte-phy.h:280
Ptr< PacketBurst > GetPacketBurst()
Definition: lte-phy.cc:191
Ptr< LteNetDevice > GetDevice() const
Get the device where the phy layer is attached.
Definition: lte-phy.cc:96
void SetDownlinkChannel(Ptr< SpectrumChannel > c)
Set the downlink channel.
Definition: lte-phy.cc:115
void SetUplinkChannel(Ptr< SpectrumChannel > c)
Set the uplink channel.
Definition: lte-phy.cc:122
uint8_t m_componentCarrierId
component carrier Id used to address sap
Definition: lte-phy.h:302
void SetComponentCarrierId(uint8_t index)
Set the component carrier ID.
Definition: lte-phy.cc:247
Ptr< LteSpectrumPhy > GetDownlinkSpectrumPhy()
Definition: lte-phy.cc:103
Ptr< LteSpectrumPhy > m_downlinkSpectrumPhy
The downlink LteSpectrumPhy associated to this LtePhy.
Definition: lte-phy.h:229
Ptr< LteSpectrumPhy > GetUplinkSpectrumPhy()
Definition: lte-phy.cc:109
void SetMacPdu(Ptr< Packet > p)
Definition: lte-phy.cc:185
std::list< Ptr< LteControlMessage > > GetControlMessages()
Definition: lte-phy.cc:217
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
Definition: lte-phy.cc:161
void SetDevice(Ptr< LteNetDevice > d)
Set the device where the phy layer is attached.
Definition: lte-phy.cc:89
Ptr< LteNetDevice > m_netDevice
Pointer to the NetDevice where this PHY layer is attached.
Definition: lte-phy.h:223
uint16_t m_cellId
Cell identifier.
Definition: lte-phy.h:299
void SetControlMessages(Ptr< LteControlMessage > m)
Definition: lte-phy.cc:209
double m_tti
Transmission time interval.
Definition: lte-phy.h:255
Ptr< LteSpectrumPhy > m_uplinkSpectrumPhy
The uplink LteSpectrumPhy associated to this LtePhy.
Definition: lte-phy.h:234
double GetTti() const
Definition: lte-phy.cc:136
std::vector< std::list< Ptr< LteControlMessage > > > m_controlMessagesQueue
A queue of control messages to be sent.
Definition: lte-phy.h:282
uint8_t m_rbgSize
The RB group size according to the bandwidth.
Definition: lte-phy.h:267
~LtePhy() override
Definition: lte-phy.cc:69
void SetTti(double tti)
Definition: lte-phy.cc:129
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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.