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