A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("LtePhy");
32 
33 namespace ns3 {
34 
35 
37 
38 
40 {
41  NS_LOG_FUNCTION (this);
42  NS_FATAL_ERROR ("This constructor should not be called");
43 }
44 
46  : m_downlinkSpectrumPhy (dlPhy),
47  m_uplinkSpectrumPhy (ulPhy),
48  m_tti (0.001),
49  m_ulBandwidth (0),
50  m_dlBandwidth (0),
51  m_rbgSize (0),
52  m_macChTtiDelay (0),
53  m_cellId (0)
54 {
55  NS_LOG_FUNCTION (this);
56 }
57 
58 
59 TypeId
61 {
62  static TypeId tid = TypeId ("ns3::LtePhy")
63  .SetParent<Object> ()
64  ;
65  return tid;
66 }
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 ();
84  m_netDevice = 0;
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION (this << d);
92  m_netDevice = d;
93 }
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 
116 void
118 {
119  NS_LOG_FUNCTION (this << c);
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << c);
128 }
129 
130 void
131 LtePhy::SetTti (double tti)
132 {
133  NS_LOG_FUNCTION (this << tti);
134  m_tti = tti;
135 }
136 
137 
138 double
139 LtePhy::GetTti (void) const
140 {
141  NS_LOG_FUNCTION (this << m_tti);
142  return m_tti;
143 }
144 
145 void
146 LtePhy::DoSetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
147 {
148  m_ulBandwidth = ulBandwidth;
149  m_dlBandwidth = dlBandwidth;
150 
151  int Type0AllocationRbg[4] = {
152  10, // RGB size 1
153  26, // RGB size 2
154  63, // RGB size 3
155  110 // RGB size 4
156  }; // see table 7.1.6.1-1 of 36.213
157  for (int i = 0; i < 4; i++)
158  {
159  if (dlBandwidth < Type0AllocationRbg[i])
160  {
161  m_rbgSize = i + 1;
162  break;
163  }
164  }
165 }
166 
167 
168 uint16_t
169 LtePhy::GetSrsPeriodicity (uint16_t srcCi) const
170 {
171  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
172  uint16_t SrsPeriodicity[9] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
173  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
174  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
175  uint8_t i;
176  for (i = 8; i > 0; i --)
177  {
178  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
179  {
180  break;
181  }
182  }
183  return SrsPeriodicity[i];
184 }
185 
186 uint16_t
187 LtePhy::GetSrsSubframeOffset (uint16_t srcCi) const
188 {
189  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
190  uint16_t SrsSubframeOffset[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
191  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
192  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
193  uint8_t i;
194  for (i = 8; i > 0; i --)
195  {
196  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
197  {
198  break;
199  }
200  }
201  return (srcCi - SrsSubframeOffset[i]);
202 }
203 
204 void
205 LtePhy::DoSetEarfcn (uint16_t dlEarfcn, uint16_t ulEarfcn)
206 {
207  m_dlEarfcn = dlEarfcn;
208  m_ulEarfcn = ulEarfcn;
209 }
210 
211 uint8_t
212 LtePhy::GetRbgSize (void) const
213 {
214  return m_rbgSize;
215 }
216 
217 void
219 {
220  m_packetBurstQueue.at (m_packetBurstQueue.size () - 1)->AddPacket (p);
221 }
222 
225 {
226  if (m_packetBurstQueue.at (0)->GetSize () > 0)
227  {
228  Ptr<PacketBurst> ret = m_packetBurstQueue.at (0)->Copy ();
229  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
230  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
231  return (ret);
232  }
233  else
234  {
235  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
236  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
237  return (0);
238  }
239 }
240 
241 
242 void
244 {
245  // In uplink the queue of control messages and packet are of different sizes
246  // for avoiding TTI cancellation due to synchronization of subframe triggers
247  m_controlMessagesQueue.at (m_controlMessagesQueue.size () - 1).push_back (m);
248 }
249 
250 std::list<Ptr<LteControlMessage> >
252 {
253  if (m_controlMessagesQueue.at (0).size () > 0)
254  {
255  std::list<Ptr<LteControlMessage> > ret = m_controlMessagesQueue.at (0);
257  std::list<Ptr<LteControlMessage> > newlist;
258  m_controlMessagesQueue.push_back (newlist);
259  return (ret);
260  }
261  else
262  {
264  std::list<Ptr<LteControlMessage> > newlist;
265  m_controlMessagesQueue.push_back (newlist);
266  std::list<Ptr<LteControlMessage> > emptylist;
267  return (emptylist);
268  }
269 }
270 
271 
272 void
273 LtePhy::DoSetCellId (uint16_t cellId)
274 {
275  m_cellId = cellId;
277  m_uplinkSpectrumPhy->SetCellId (cellId);
278 }
279 
280 
281 } // namespace ns3