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  *         Nicola Baldo <nbaldo@cttc.es>
21  */
22 
23 #ifndef LTE_PHY_H
24 #define LTE_PHY_H
25 
26 
27 #include <ns3/spectrum-value.h>
28 #include <ns3/mobility-model.h>
29 #include <ns3/packet.h>
30 #include <ns3/nstime.h>
31 #include <ns3/spectrum-phy.h>
32 #include <ns3/spectrum-channel.h>
33 #include <ns3/spectrum-signal-parameters.h>
34 #include <ns3/spectrum-interference.h>
35 #include <ns3/generic-phy.h>
36 #include <ns3/lte-spectrum-phy.h>
37 
38 namespace ns3 {
39 
40 class PacketBurst;
41 class LteNetDevice;
42 class LteControlMessage;
43 
44 
45 
46 /**
47  * \ingroup lte
48  *
49  * The LtePhy models the physical layer of LTE. It is composed by two
50  * LteSpectrumPhy, one for the downlink and one for the uplink.
51  */
52 class LtePhy : public Object
53 {
54 
55 public:
56   /**
57    * @warning the default constructor should not be used
58    */
59   LtePhy ();
60 
61   /**
62    *
63    * \param dlPhy the downlink LteSpectrumPhy instance
64    * \param ulPhy the uplink LteSpectrumPhy instance
65    */
66   LtePhy (Ptr<LteSpectrumPhy> dlPhy, Ptr<LteSpectrumPhy> ulPhy);
67 
68   virtual ~LtePhy ();
69 
70   /**
71    * \brief Get the type ID.
72    * \return the object TypeId
73    */
74   static TypeId GetTypeId (void);
75 
76   /**
77    * \brief Set the device where the phy layer is attached
78    * \param d the device
79    */
80   void SetDevice (Ptr<LteNetDevice> d);
81   /**
82    * \brief Get the device where the phy layer is attached
83    * \return the pointer to the device
84    */
85   Ptr<LteNetDevice> GetDevice () const;
86 
87   /**
88    *
89    * \return a pointer to the LteSpectrumPhy instance that manages the downlink
90    */
91   Ptr<LteSpectrumPhy> GetDownlinkSpectrumPhy ();
92 
93 
94   /**
95    *
96    * \return a pointer to the LteSpectrumPhy instance that manages the uplink
97    */
98   Ptr<LteSpectrumPhy> GetUplinkSpectrumPhy ();
99 
100   /**
101   * \brief Queue the MAC PDU to be sent (according to m_macChTtiDelay)
102   * \param p the MAC PDU to sent
103   */
104   virtual void DoSendMacPdu (Ptr<Packet> p) = 0;
105 
106   /**
107    * Set the downlink channel
108    * \param c the downlink channel
109    */
110   void SetDownlinkChannel (Ptr<SpectrumChannel> c);
111 
112   /**
113    * Set the uplink channel
114    * \param c the uplink channel
115    */
116   void SetUplinkChannel (Ptr<SpectrumChannel> c);
117 
118 
119   /**
120    * \brief Compute the TX Power Spectral Density
121    * \return a pointer to a newly allocated SpectrumValue representing the TX Power Spectral Density in W/Hz for each Resource Block
122    */
123   virtual Ptr<SpectrumValue> CreateTxPowerSpectralDensity () = 0;
124 
125   void DoDispose ();
126 
127   /**
128    * \param tti transmission time interval
129    */
130   void SetTti (double tti);
131   /**
132    * \returns transmission time interval
133    */
134   double GetTti (void) const;
135 
136   /**
137    *
138    * \param cellId the Cell Identifier
139    */
140   void DoSetCellId (uint16_t cellId);
141 
142 
143   /**
144   * \returns the RB group size according to the bandwidth
145   */
146   uint8_t GetRbgSize (void) const;
147 
148 
149   /**
150   * \returns the SRS periodicity (see Table 8.2-1 of 36.213)
151   * \param srcCi the SRS Configuration Index
152   */
153   uint16_t GetSrsPeriodicity (uint16_t srcCi) const;
154 
155   /**
156   * \returns the SRS Subframe offset (see Table 8.2-1 of 36.213)
157   * \param srcCi the SRS Configuration Index
158   */
159   uint16_t GetSrsSubframeOffset (uint16_t srcCi) const;
160 
161 
162   /**
163   * \param p queue MAC PDU to be sent
164   */
165   void SetMacPdu (Ptr<Packet> p);
166 
167   /**
168   * \returns the packet burst to be sent
169   */
170   Ptr<PacketBurst> GetPacketBurst (void);
171 
172   /**
173   * \param m the control message to be sent
174   */
175   void SetControlMessages (Ptr<LteControlMessage> m);
176 
177   /**
178   * \returns the list of control messages to be sent
179   */
180   std::list<Ptr<LteControlMessage> > GetControlMessages (void);
181 
182 
183   /**
184    * generate a CQI report based on the given SINR of Ctrl frame
185    *
186    * \param sinr the SINR vs frequency measured by the device
187    */
188   virtual void GenerateCtrlCqiReport (const SpectrumValue& sinr) = 0;
189 
190   /**
191   * generate a CQI report based on the given SINR of Data frame
192   * (used for PUSCH CQIs)
193   *
194   * \param sinr the SINR vs frequency measured by the device
195   */
196   virtual void GenerateDataCqiReport (const SpectrumValue& sinr) = 0;
197 
198   /**
199   * generate a report based on the linear interference and noise power
200   * perceived during DATA frame
201   * NOTE: used only by eNB
202   *
203   * \param interf the interference + noise power measured by the device
204   */
205   virtual void ReportInterference (const SpectrumValue& interf) = 0;
206 
207   /**
208   * generate a report based on the linear RS power perceived during CTRL
209   * frame
210   * NOTE: used only by UE for evaluating RSRP
211   *
212   * \param power the RS power measured by the device
213   */
214   virtual void ReportRsReceivedPower (const SpectrumValue& power) = 0;
215 
216   /**
217   * Set the component carrier ID
218   *
219   * \param index the component carrier ID index
220   */
221   void SetComponentCarrierId (uint8_t index);
222 
223   /**
224   * Get the component carrier ID
225   *
226   * \returns the component carrier ID index
227   */
228   uint8_t GetComponentCarrierId ();
229 
230 protected:
231   /// Pointer to the NetDevice where this PHY layer is attached.
232   Ptr<LteNetDevice> m_netDevice;
233 
234   /**
235    * The downlink LteSpectrumPhy associated to this LtePhy. Also available as
236    * attribute `DlSpectrumPhy` in the child classes LteEnbPhy and LteUePhy.
237    */
238   Ptr<LteSpectrumPhy> m_downlinkSpectrumPhy;
239   /**
240    * The uplink LteSpectrumPhy associated to this LtePhy. Also available as
241    * attribute `UlSpectrumPhy` in the child classes LteEnbPhy and LteUePhy.
242    */
243   Ptr<LteSpectrumPhy> m_uplinkSpectrumPhy;
244 
245   /**
246    * Transmission power in dBm. Also available as attribute `TxPower` in the
247    * child classes LteEnbPhy and LteUePhy.
248    */
249   double m_txPower;
250   /**
251    * Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the
252    * receiver. Also available as attribute `NoiseFigure` in the child classes
253    * LteEnbPhy and LteUePhy.
254    *
255    * According to [Wikipedia](http://en.wikipedia.org/wiki/Noise_figure), this
256    * is "the difference in decibels (dB) between the noise output of the actual
257    * receiver to the noise output of an ideal receiver with the same overall
258    * gain and bandwidth when the receivers are connected to sources at the
259    * standard noise temperature T0." In this model, we consider T0 = 290K.
260    */
261   double m_noiseFigure;
262 
263   /// Transmission time interval.
264   double m_tti;
265   /**
266    * The UL bandwidth in number of PRBs.
267    * Specified by the upper layer through CPHY SAP.
268    */
269   uint16_t m_ulBandwidth;
270   /**
271    * The DL bandwidth in number of PRBs.
272    * Specified by the upper layer through CPHY SAP.
273    */
274   uint16_t m_dlBandwidth;
275   /// The RB group size according to the bandwidth.
276   uint8_t m_rbgSize;
277   /**
278    * The downlink carrier frequency.
279    * Specified by the upper layer through CPHY SAP.
280    */
281   uint32_t m_dlEarfcn;
282   /**
283    * The uplink carrier frequency.
284    * Specified by the upper layer through CPHY SAP.
285    */
286   uint32_t m_ulEarfcn;
287 
288   /// A queue of packet bursts to be sent.
289   std::vector< Ptr<PacketBurst> > m_packetBurstQueue;
290   /// A queue of control messages to be sent.
291   std::vector< std::list<Ptr<LteControlMessage> > > m_controlMessagesQueue;
292   /**
293    * Delay between MAC and channel layer in terms of TTIs. It is the delay that
294    * occurs between a scheduling decision in the MAC and the actual start of
295    * the transmission by the PHY. This is intended to be used to model the
296    * latency of real PHY and MAC implementations.
297    *
298    * In LteEnbPhy, it is 2 TTIs by default and can be configured through the
299    * `MacToChannelDelay` attribute. In LteUePhy, it is 4 TTIs.
300    */
301   uint8_t m_macChTtiDelay;
302 
303   /**
304    * Cell identifier. In LteEnbPhy, this corresponds to the ID of the cell
305    * which hosts this PHY layer. In LteUePhy, this corresponds to the ID of the
306    * eNodeB which this PHY layer is synchronized with.
307    */
308   uint16_t m_cellId;
309 
310   /// component carrier Id used to address sap
311   uint8_t m_componentCarrierId;
312 
313 }; // end of `class LtePhy`
314 
315 
316 }
317 
318 #endif /* LTE_PHY_H */
319