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_macChTtiDelay (0),
52  m_cellId (0)
53 {
54  NS_LOG_FUNCTION (this);
55 }
56 
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::LtePhy")
62  .SetParent<Object> ()
63  ;
64  return tid;
65 }
66 
67 
69 {
70  NS_LOG_FUNCTION (this);
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this);
77  m_packetBurstQueue.clear ();
78  m_controlMessagesQueue.clear ();
79  m_downlinkSpectrumPhy->Dispose ();
81  m_uplinkSpectrumPhy->Dispose ();
83  m_netDevice = 0;
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION (this << d);
91  m_netDevice = d;
92 }
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 
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 
137 double
138 LtePhy::GetTti (void) const
139 {
140  NS_LOG_FUNCTION (this << m_tti);
141  return m_tti;
142 }
143 
144 
145 uint16_t
146 LtePhy::GetSrsPeriodicity (uint16_t srcCi) const
147 {
148  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
149  uint16_t SrsPeriodicity[9] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
150  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
151  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
152  uint8_t i;
153  for (i = 8; i > 0; i --)
154  {
155  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
156  {
157  break;
158  }
159  }
160  return SrsPeriodicity[i];
161 }
162 
163 uint16_t
164 LtePhy::GetSrsSubframeOffset (uint16_t srcCi) const
165 {
166  // from 3GPP TS 36.213 table 8.2-1 UE Specific SRS Periodicity
167  uint16_t SrsSubframeOffset[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
168  uint16_t SrsCiLow[9] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
169  uint16_t SrsCiHigh[9] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
170  uint8_t i;
171  for (i = 8; i > 0; i --)
172  {
173  if ((srcCi>=SrsCiLow[i])&&(srcCi<=SrsCiHigh[i]))
174  {
175  break;
176  }
177  }
178  return (srcCi - SrsSubframeOffset[i]);
179 }
180 
181 uint8_t
182 LtePhy::GetRbgSize (void) const
183 {
184  return m_rbgSize;
185 }
186 
187 void
189 {
190  m_packetBurstQueue.at (m_packetBurstQueue.size () - 1)->AddPacket (p);
191 }
192 
195 {
196  if (m_packetBurstQueue.at (0)->GetSize () > 0)
197  {
198  Ptr<PacketBurst> ret = m_packetBurstQueue.at (0)->Copy ();
199  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
200  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
201  return (ret);
202  }
203  else
204  {
205  m_packetBurstQueue.erase (m_packetBurstQueue.begin ());
206  m_packetBurstQueue.push_back (CreateObject <PacketBurst> ());
207  return (0);
208  }
209 }
210 
211 
212 void
214 {
215  // In uplink the queue of control messages and packet are of different sizes
216  // for avoiding TTI cancellation due to synchronization of subframe triggers
217  m_controlMessagesQueue.at (m_controlMessagesQueue.size () - 1).push_back (m);
218 }
219 
220 std::list<Ptr<LteControlMessage> >
222 {
223  NS_LOG_FUNCTION (this);
224  if (m_controlMessagesQueue.at (0).size () > 0)
225  {
226  std::list<Ptr<LteControlMessage> > ret = m_controlMessagesQueue.at (0);
228  std::list<Ptr<LteControlMessage> > newlist;
229  m_controlMessagesQueue.push_back (newlist);
230  return (ret);
231  }
232  else
233  {
235  std::list<Ptr<LteControlMessage> > newlist;
236  m_controlMessagesQueue.push_back (newlist);
237  std::list<Ptr<LteControlMessage> > emptylist;
238  return (emptylist);
239  }
240 }
241 
242 
243 void
244 LtePhy::DoSetCellId (uint16_t cellId)
245 {
246  m_cellId = cellId;
247  m_downlinkSpectrumPhy->SetCellId (cellId);
248  m_uplinkSpectrumPhy->SetCellId (cellId);
249 }
250 
251 
252 } // namespace ns3
void SetDevice(Ptr< LteNetDevice > d)
Set the device where the phy layer is attached.
Definition: lte-phy.cc:88
static TypeId GetTypeId(void)
Definition: lte-phy.cc:59
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:244
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
std::vector< Ptr< PacketBurst > > m_packetBurstQueue
A queue of packet bursts to be sent.
Definition: lte-phy.h:273
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
Definition: lte-phy.cc:146
double GetTti(void) const
Definition: lte-phy.cc:138
double m_tti
Transmission time interval.
Definition: lte-phy.h:248
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Ptr< LteSpectrumPhy > m_downlinkSpectrumPhy
The downlink LteSpectrumPhy associated to this LtePhy.
Definition: lte-phy.h:222
void SetUplinkChannel(Ptr< SpectrumChannel > c)
Set the uplink channel.
Definition: lte-phy.cc:123
Ptr< LteSpectrumPhy > GetUplinkSpectrumPhy()
Definition: lte-phy.cc:109
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
Ptr< LteNetDevice > GetDevice()
Get the device where the phy layer is attached.
Definition: lte-phy.cc:96
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
Definition: lte-phy.cc:164
void DoDispose()
Destructor implementation.
Definition: lte-phy.cc:74
uint8_t GetRbgSize(void) const
Definition: lte-phy.cc:182
virtual ~LtePhy()
Definition: lte-phy.cc:68
void SetDownlinkChannel(Ptr< SpectrumChannel > c)
Set the downlink channel.
Definition: lte-phy.cc:116
Ptr< LteSpectrumPhy > GetDownlinkSpectrumPhy()
Definition: lte-phy.cc:103
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetControlMessages(Ptr< LteControlMessage > m)
Definition: lte-phy.cc:213
uint16_t m_cellId
Cell identifier.
Definition: lte-phy.h:292
Ptr< LteNetDevice > m_netDevice
Pointer to the NetDevice where this PHY layer is attached.
Definition: lte-phy.h:216
std::list< Ptr< LteControlMessage > > GetControlMessages(void)
Definition: lte-phy.cc:221
Ptr< PacketBurst > GetPacketBurst(void)
Definition: lte-phy.cc:194
uint8_t m_rbgSize
The RB gruop size according to the bandwidth.
Definition: lte-phy.h:260
std::vector< std::list< Ptr< LteControlMessage > > > m_controlMessagesQueue
A queue of control messages to be sent.
Definition: lte-phy.h:275
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:227
void SetMacPdu(Ptr< Packet > p)
Definition: lte-phy.cc:188
a unique identifier for an interface.
Definition: type-id.h:51
void SetTti(double tti)
Definition: lte-phy.cc:130
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631