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 ();
80  m_downlinkSpectrumPhy->Dispose ();
82  m_uplinkSpectrumPhy->Dispose ();
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);
120  m_downlinkSpectrumPhy->SetChannel (c);
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << c);
127  m_uplinkSpectrumPhy->SetChannel (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 
146 uint16_t
147 LtePhy::GetSrsPeriodicity (uint16_t srcCi) const
148 {
149  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
150  uint16_t SrsPeriodicity[9] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
151  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
152  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
153  uint8_t i;
154  for (i = 8; i > 0; i --)
155  {
156  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
157  {
158  break;
159  }
160  }
161  return SrsPeriodicity[i];
162 }
163 
164 uint16_t
165 LtePhy::GetSrsSubframeOffset (uint16_t srcCi) const
166 {
167  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
168  uint16_t SrsSubframeOffset[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
169  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
170  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
171  uint8_t i;
172  for (i = 8; i > 0; i --)
173  {
174  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
175  {
176  break;
177  }
178  }
179  return (srcCi - SrsSubframeOffset[i]);
180 }
181 
182 uint8_t
183 LtePhy::GetRbgSize (void) const
184 {
185  return m_rbgSize;
186 }
187 
188 void
190 {
191  m_packetBurstQueue.at (m_packetBurstQueue.size () - 1)->AddPacket (p);
192 }
193 
196 {
197  if (m_packetBurstQueue.at (0)->GetSize () > 0)
198  {
199  Ptr<PacketBurst> ret = m_packetBurstQueue.at (0)->Copy ();
200  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
201  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
202  return (ret);
203  }
204  else
205  {
206  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
207  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
208  return (0);
209  }
210 }
211 
212 
213 void
215 {
216  // In uplink the queue of control messages and packet are of different sizes
217  // for avoiding TTI cancellation due to synchronization of subframe triggers
218  m_controlMessagesQueue.at (m_controlMessagesQueue.size () - 1).push_back (m);
219 }
220 
221 std::list<Ptr<LteControlMessage> >
223 {
224  NS_LOG_FUNCTION (this);
225  if (m_controlMessagesQueue.at (0).size () > 0)
226  {
227  std::list<Ptr<LteControlMessage> > ret = m_controlMessagesQueue.at (0);
229  std::list<Ptr<LteControlMessage> > newlist;
230  m_controlMessagesQueue.push_back (newlist);
231  return (ret);
232  }
233  else
234  {
236  std::list<Ptr<LteControlMessage> > newlist;
237  m_controlMessagesQueue.push_back (newlist);
238  std::list<Ptr<LteControlMessage> > emptylist;
239  return (emptylist);
240  }
241 }
242 
243 
244 void
245 LtePhy::DoSetCellId (uint16_t cellId)
246 {
247  m_cellId = cellId;
248  m_downlinkSpectrumPhy->SetCellId (cellId);
249  m_uplinkSpectrumPhy->SetCellId (cellId);
250 }
251 
252 
253 } // namespace ns3
void SetDevice(Ptr< LteNetDevice > d)
Set the device where the phy layer is attached.
Definition: lte-phy.cc:89
static TypeId GetTypeId(void)
Definition: lte-phy.cc:60
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 "...
void DoSetCellId(uint16_t cellId)
Definition: lte-phy.cc:245
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
std::vector< Ptr< PacketBurst > > m_packetBurstQueue
Definition: lte-phy.h:231
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
Definition: lte-phy.cc:147
double GetTti(void) const
Definition: lte-phy.cc:139
double m_tti
Definition: lte-phy.h:223
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Ptr< LteSpectrumPhy > m_downlinkSpectrumPhy
Definition: lte-phy.h:217
void SetUplinkChannel(Ptr< SpectrumChannel > c)
Set the uplink channel.
Definition: lte-phy.cc:124
Ptr< LteSpectrumPhy > GetUplinkSpectrumPhy()
Definition: lte-phy.cc:110
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
Ptr< LteNetDevice > GetDevice()
Get the device where the phy layer is attached.
Definition: lte-phy.cc:97
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
Definition: lte-phy.cc:165
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: lte-phy.cc:75
uint8_t GetRbgSize(void) const
Definition: lte-phy.cc:183
virtual ~LtePhy()
Definition: lte-phy.cc:69
void SetDownlinkChannel(Ptr< SpectrumChannel > c)
Set the downlink channel.
Definition: lte-phy.cc:117
Ptr< LteSpectrumPhy > GetDownlinkSpectrumPhy()
Definition: lte-phy.cc:104
void SetControlMessages(Ptr< LteControlMessage > m)
Definition: lte-phy.cc:214
uint16_t m_cellId
Definition: lte-phy.h:235
Ptr< LteNetDevice > m_netDevice
Definition: lte-phy.h:215
std::list< Ptr< LteControlMessage > > GetControlMessages(void)
Definition: lte-phy.cc:222
Ptr< PacketBurst > GetPacketBurst(void)
Definition: lte-phy.cc:195
uint8_t m_rbgSize
Definition: lte-phy.h:226
std::vector< std::list< Ptr< LteControlMessage > > > m_controlMessagesQueue
Definition: lte-phy.h:232
a base class which provides memory management and object aggregation
Definition: object.h:64
Ptr< LteSpectrumPhy > m_uplinkSpectrumPhy
Definition: lte-phy.h:218
void SetMacPdu(Ptr< Packet > p)
Definition: lte-phy.cc:189
a unique identifier for an interface.
Definition: type-id.h:49
void SetTti(double tti)
Definition: lte-phy.cc:131
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610