1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Manuel Requena <manuel.requena@cttc.es>
19  * Author: Marco Miozzo <marco.miozzo@cttc.es>
20  */
21 #ifndef LTE_COMMON_H
22 #define LTE_COMMON_H
23 
24 #include "ns3/uinteger.h"
25 #include <cmath>
26 
27 // see 36.213 section 8
28 #define UL_PUSCH_TTIS_DELAY 4
29 
30 #define HARQ_PERIOD 7
31 
32 namespace ns3 {
33 
34 
35 /// LteFlowId structure
36 struct LteFlowId_t
37 {
38   uint16_t  m_rnti; ///< RNTI
39   uint8_t   m_lcId; ///< LCID
40 
41 public:
42   LteFlowId_t ();
43   /**
44    * Constructor
45    *
46    * \param a RNTI
47    * \param b LCID
48    */
49   LteFlowId_t (const uint16_t a, const uint8_t b);
50 
51   friend bool operator == (const LteFlowId_t &a, const LteFlowId_t &b);
52   friend bool operator < (const LteFlowId_t &a, const LteFlowId_t &b);
53 };
54 
55 /// ImsiLcidPair structure
56 struct ImsiLcidPair_t
57 {
58   uint64_t  m_imsi; ///< IMSI
59   uint8_t   m_lcId; ///< LCID
60 
61 public:
62   ImsiLcidPair_t ();
63   /**
64    * Constructor
65    *
66    * \param a first pair
67    * \param b second pair
68    */
69   ImsiLcidPair_t (const uint64_t a, const uint8_t b);
70 
71   friend bool operator == (const ImsiLcidPair_t &a, const ImsiLcidPair_t &b);
72   friend bool operator < (const ImsiLcidPair_t &a, const ImsiLcidPair_t &b);
73 };
74 
75 /**
76 * \brief Parameters for configuring the UE
77 */
78 struct LteUeConfig_t
79 {
80   /**
81   * RNTI
82   */
83   uint16_t  m_rnti;
84   /**
85   * When false means that the message is intended for configuring a new UE
86   */
87   bool      m_reconfigureFlag;
88   /**
89   * Transmission mode [1..7] (i.e., SISO, MIMO, etc.)
90   */
91   uint8_t   m_transmissionMode;
92   /**
93   * Srs Configuration index for UE specific SRS, see section 8.2 of TS 36.213
94   */
95   uint16_t  m_srsConfigurationIndex;
96 
97 public:
98   LteUeConfig_t ();
99 
100   /**
101    * Equality operator
102    *
103    * \param a lhs
104    * \param b rhs
105    * \returns true if "equal"
106    */
107   friend bool operator == (const LteUeConfig_t &a, const LteUeConfig_t &b);
108   /**
109    * Less than operator
110    *
111    * \param a lhs
112    * \param b rhs
113    * \returns true if "less than"
114    */
115   friend bool operator < (const LteUeConfig_t &a, const LteUeConfig_t &b);
116 };
117 
118 /// LteFfConverter class
119 class LteFfConverter
120 {
121 
122 public:
123   /**
124    * Convert from double to fixed point S11.3 notation
125    *
126    * \param val double value
127    * \returns fixed point S11.3 value
128    */
129   static uint16_t double2fpS11dot3 (double val);
130   /**
131    * Convert from fixed point S11.3 notation to double
132    *
133    * \param val fixed point S11.3 value
134    * \returns double value
135    */
136   static double fpS11dot3toDouble (uint16_t val);
137   /**
138    * Get minimum fixed point S11.3 value
139    *
140    * \returns double value for the minimum fixed point S11.3 value
141    */
142   static double getMinFpS11dot3Value ();
143 
144   //static const double MIN_FP_S11DOT3_VALUE = -4096;
145 
146 };
147 
148 /// BufferSizeLevelBsr class
149 class BufferSizeLevelBsr
150 {
151 
152 public:
153   /**
154    * Convert BSR ID to buffer size
155    *
156    * \param val BSR ID
157    * \returns buffer size
158    */
159   static uint32_t BsrId2BufferSize (uint8_t val);
160   /**
161    * Convert Buffer size to BSR ID
162    *
163    * \param val buffer size
164    * \returns BSR ID
165    */
166   static uint8_t BufferSize2BsrId (uint32_t val);
167 
168   static int  m_bufferSizeLevelBsr[64]; ///< buffer size level BSR
169 
170 };
171 
172 /// TransmissionModesLayers class
173 class TransmissionModesLayers
174 {
175 public:
176   /**
177    * Transmit mode 2 layer number
178    * \param txMode the transmit mode
179    * \returns the layer 2 number
180    */
181   static uint8_t TxMode2LayerNum (uint8_t txMode);
182 };
183 
184 
185 /// PhyTransmissionStatParameters structure
186 struct PhyTransmissionStatParameters
187 {
188   int64_t  m_timestamp; ///< in millisecond
189   uint16_t m_cellId;  ///< Cell ID of the attached Enb
190   uint64_t m_imsi;    ///< IMSI of the scheduled UE
191   uint16_t m_rnti;    ///< C-RNTI scheduled
192   uint8_t  m_txMode;  ///< the transmission Mode
193   uint8_t  m_layer;   ///< the layer (cw) of the transmission
194   uint8_t  m_mcs;     ///< MCS for transport block
195   uint16_t m_size;    ///< Size of transport block
196   uint8_t  m_rv;      ///< the redundancy version (HARQ)
197   uint8_t  m_ndi;     ///< new data indicator flag
198   uint8_t  m_ccId;    ///< component carrier id
199 
200   /**
201    *  TracedCallback signature.
202    *
203    * \param [in] params Value of the PhyTransmissionionStatParameters.
204    * \todo The argument should be passed by const reference, since it's large.
205    */
206   typedef void (* TracedCallback)(const PhyTransmissionStatParameters params);
207 
208 };
209 
210 
211 /// PhyReceptionStatParameters structure
212 struct PhyReceptionStatParameters
213 {
214   int64_t  m_timestamp;    ///< in millisecond
215   uint16_t m_cellId;       ///< Cell ID of the attached Enb
216   uint64_t m_imsi;         ///< IMSI of the scheduled UE
217   uint16_t m_rnti;         ///< C-RNTI scheduled
218   uint8_t  m_txMode;       ///< the transmission Mode
219   uint8_t  m_layer;        ///< the layer (cw) of the transmission
220   uint8_t  m_mcs;          ///< MCS for transport block
221   uint16_t m_size;         ///< Size of transport block
222   uint8_t  m_rv;           ///< the redundancy version (HARQ)
223   uint8_t  m_ndi;          ///< new data indicator flag
224   uint8_t  m_correctness;  ///< correctness of the TB received
225   uint8_t  m_ccId;        ///< component carrier id
226 
227   /**
228    *  TracedCallback signature.
229    *
230    * \param [in] params Value of the PhyReceptionStatParameters.
231    * \todo The argument should be passed by const reference, since it's large.
232    */
233   typedef void (* TracedCallback)(const PhyReceptionStatParameters params);
234 
235 };
236 
237 
238 /// DlSchedulingCallbackInfo structure
239 struct DlSchedulingCallbackInfo
240 {
241   uint32_t frameNo; ///< frame number
242   uint32_t subframeNo; ///< subframe number
243   uint16_t rnti; ///< RNTI
244   uint8_t  mcsTb1; ///< MCS TB1
245   uint16_t sizeTb1; ///< size TB1
246   uint8_t  mcsTb2; ///< MCS TB2
247   uint16_t sizeTb2; ///< size TB2
248   uint8_t  componentCarrierId; ///< component carrier ID
249 };
250 
251 /**
252  * Implements the E-UTRA measurement mappings defined in  3GPP TS
253  * 36.133 section 9.1 E-UTRAN measurements
254  *
255  */
256 class EutranMeasurementMapping
257 {
258 public:
259   /**
260    * converts an RSRP range to dBm as per
261    * 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
262    *
263    * \param range the RSRP range value
264    *
265    * \return the corresponding RSRP value in dBm
266    */
267   static double RsrpRange2Dbm (uint8_t range);
268 
269   /**
270    * convert an RSRP value in dBm to the corresponding range as per
271    * 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
272    *
273    * \param dbm the RSRP value in dBm
274    *
275    * \return the corresponding range
276    */
277   static uint8_t Dbm2RsrpRange (double dbm);
278 
279   /**
280    * converts an RSRQ range to dB as per
281    * 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
282    *
283    * \param range the RSRQ range value
284    *
285    * \return the corresponding RSRQ value in dB
286    */
287   static double RsrqRange2Db (uint8_t range);
288 
289   /**
290    * convert an RSRQ value in dB to the corresponding range as per
291    * 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
292    *
293    * \param db the RSRQ value in dB
294    *
295    * \return the corresponding range
296    */
297   static uint8_t Db2RsrqRange (double db);
298 
299   /**
300    * Quantize an RSRP value according to the measurement mapping of TS 36.133
301    *
302    * \param v RSRP value in dBm
303    *
304    * \return the quantized RSRP value in dBm
305    */
306   static double QuantizeRsrp (double v);
307 
308   /**
309    * Quantize an RSRQ value according to the measurement mapping of TS 36.133
310    *
311    * \param v RSRQ value in dB
312    *
313    * \return the quantized RSRQ value in dB
314    */
315   static double QuantizeRsrq (double v);
316 
317   /**
318    * \brief Returns the actual value of a hysteresis parameter.
319    * \param hysteresisIeValue IE value of hysteresis
320    * \return actual value in dB, which is IE value * 0.5 dB
321    *
322    * As per section 6.3.5 of 3GPP TS 36.331.
323    *
324    * The allowed values for hysteresis IE value are between 0 and 30.
325    *
326    * \sa LteRrcSap::ReportConfigEutra
327    */
328   static double IeValue2ActualHysteresis (uint8_t hysteresisIeValue);
329 
330   /**
331    * \brief Returns the IE value of hysteresis.
332    * \param hysteresisDb actual hysteresis value in dB
333    * \return IE value of hysteresis in dB, which is actual value * 2, rounded
334    *         to the nearest integer
335    *
336    * The allowed values for hysteresis are between 0 and 15 dB.
337    *
338    * \sa LteRrcSap::ReportConfigEutra
339    */
340   static uint8_t ActualHysteresis2IeValue (double hysteresisDb);
341 
342   /**
343    * \brief Returns the actual value of an a3-Offset parameter.
344    * \param a3OffsetIeValue IE value of a3-Offset
345    * \return actual value in dB, which is IE value * 0.5 dB
346    *
347    * As per section 6.3.5 of 3GPP TS 36.331.
348    *
349    * The allowed values for a3-Offset IE value are between -30 and 30.
350    *
351    * \sa LteRrcSap::ReportConfigEutra
352    */
353   static double IeValue2ActualA3Offset (int8_t a3OffsetIeValue);
354 
355   /**
356    * \brief Returns the IE value of a3-Offset.
357    * \param a3OffsetDb actual A3 Offset value in dB
358    * \return IE value of a3-Offset in dB, which is actual value * 2, rounded
359    *         to the nearest integer
360    *
361    * The allowed values for A3 Offset are between -15 and 15 dB.
362    *
363    * \sa LteRrcSap::ReportConfigEutra
364    */
365   static int8_t ActualA3Offset2IeValue (double a3OffsetDb);
366 
367   /**
368    * \brief Returns the actual value of an Q-RxLevMin parameter.
369    * \param qRxLevMinIeValue IE value of Q-RxLevMin
370    * \return Q-RxLevMin actual value in dBm, which is IE value * 2 dBm
371    *
372    * As per section 6.3.4 of 3GPP TS 36.331.
373    *
374    * \sa LteRrcSap::CellSelectionInfo
375    */
376   static double IeValue2ActualQRxLevMin (int8_t qRxLevMinIeValue);
377 
378   /**
379    * \brief Returns the actual value of an Q-QualMin parameter.
380    * \param qQualMinIeValue IE value of Q-QualMin
381    * \return Q-QualMin actual value in dB, which is IE value dB
382    *
383    * As per section 6.3.4 of 3GPP TS 36.331.
384    *
385    * \sa LteRrcSap::CellSelectionInfo
386    */
387   static double IeValue2ActualQQualMin (int8_t qQualMinIeValue);
388 
389 }; // end of class EutranMeasurementMapping
390 
391 }; // namespace ns3
392 
393 
394 #endif /* LTE_COMMON_H_ */
395