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