A Discrete-Event Network Simulator
API
lte-common.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Manuel Requena <manuel.requena@cttc.es>
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  */
20 
21 #include "lte-common.h"
22 
23 #include <ns3/abort.h>
24 #include <ns3/log.h>
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("LteCommon");
30 
32 {
33 }
34 
35 LteFlowId_t::LteFlowId_t(const uint16_t a, const uint8_t b)
36  : m_rnti(a),
37  m_lcId(b)
38 {
39 }
40 
48 bool
49 operator==(const LteFlowId_t& a, const LteFlowId_t& b)
50 {
51  return ((a.m_rnti == b.m_rnti) && (a.m_lcId == b.m_lcId));
52 }
53 
61 bool
62 operator<(const LteFlowId_t& a, const LteFlowId_t& b)
63 {
64  return ((a.m_rnti < b.m_rnti) || ((a.m_rnti == b.m_rnti) && (a.m_lcId < b.m_lcId)));
65 }
66 
68 {
69 }
70 
71 ImsiLcidPair_t::ImsiLcidPair_t(const uint64_t a, const uint8_t b)
72  : m_imsi(a),
73  m_lcId(b)
74 {
75 }
76 
84 bool
86 {
87  return ((a.m_imsi == b.m_imsi) && (a.m_lcId == b.m_lcId));
88 }
89 
97 bool
98 operator<(const ImsiLcidPair_t& a, const ImsiLcidPair_t& b)
99 {
100  return ((a.m_imsi < b.m_imsi) || ((a.m_imsi == b.m_imsi) && (a.m_lcId < b.m_lcId)));
101 }
102 
104 {
105 }
106 
114 bool
116 {
117  return (a.m_rnti == b.m_rnti);
118 }
119 
127 bool
128 operator<(const LteUeConfig_t& a, const LteUeConfig_t& b)
129 {
130  return (a.m_rnti < b.m_rnti);
131 }
132 
133 uint16_t
135 {
136  // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
137  // truncate val to notation limits
138  if (val > 4095.88)
139  {
140  val = 4095.88;
141  }
142  if (val < -4096)
143  {
144  val = -4096;
145  }
146  auto valFp = (int16_t)(val * 8);
147  return valFp;
148 }
149 
150 double
152 {
153  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
154  double valD = ((int16_t)val) / 8.0;
155  return valD;
156 }
157 
158 double
160 {
161  return -4096; // -4096 = 0x8000 = 1000 0000 0000 0000 b
162 }
163 
164 // static double g_lowestFpS11dot3Value = -4096; // 0x8001 (1000 0000 0000 0000)
165 
167 static const uint32_t BufferSizeLevelBsrTable[64] = {
168  0, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57,
169  67, 78, 91, 107, 125, 146, 171, 200, 234, 274, 321, 376, 440,
170  515, 603, 706, 826, 967, 1132, 1326, 1552, 1817, 2127, 2490, 2915, 3413,
171  3995, 4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099, 16507, 19325, 22624, 26487,
172  31009, 36304, 42502, 49759, 58255, 68201, 79846, 93749, 109439, 128125, 150000, 150000,
173 };
174 
175 uint32_t
177 {
178  NS_ABORT_MSG_UNLESS(val < 64, "val = " << val << " is out of range");
179  return BufferSizeLevelBsrTable[val];
180 }
181 
182 uint8_t
184 {
185  int index = 0;
186  if (BufferSizeLevelBsrTable[63] < val)
187  {
188  index = 63;
189  }
190  else
191  {
192  while (BufferSizeLevelBsrTable[index] < val)
193  {
194  NS_ASSERT(index < 64);
195  index++;
196  }
197  }
198 
199  return index;
200 }
201 
202 uint8_t
204 {
205  uint8_t nLayer = 0;
206  switch (txMode)
207  {
208  case 0: // Tx MODE 1: SISO
209  nLayer = 1;
210  break;
211  case 1: // Tx MODE 2: MIMO Tx Diversity
212  nLayer = 1;
213  break;
214  case 2: // Tx MODE 3: MIMO Spatial Multiplexity Open Loop
215  nLayer = 2;
216  break;
217  case 3: // Tx MODE 4: MIMO Spatial Multiplexity Closed Loop
218  nLayer = 2;
219  break;
220  case 4: // Tx MODE 5: MIMO Multi-User
221  nLayer = 2;
222  break;
223  case 5: // Tx MODE 6: Closer loop single layer percoding
224  nLayer = 1;
225  break;
226  case 6: // Tx MODE 7: Single antenna port 5
227  nLayer = 1;
228  break;
229  }
230  return nLayer;
231 }
232 
233 double
235 {
236  // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
237  NS_ASSERT_MSG(range <= 97, "value " << range << " is out of range");
238  return (double)range - 141.0;
239 }
240 
241 uint8_t
243 {
244  // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
245  double range = std::min(std::max(std::floor(dbm + 141), 0.0), 97.0);
246  return (uint8_t)range;
247 }
248 
249 double
251 {
252  // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
253  NS_ASSERT_MSG(range <= 34, "value " << (uint16_t)range << " is out of range");
254  return ((double)range - 40.0) * 0.5;
255 }
256 
257 uint8_t
259 {
260  // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
261  double range = std::min(std::max(std::floor(db * 2 + 40), 0.0), 34.0);
262  return (uint8_t)range;
263 }
264 
265 double
267 {
268  return RsrpRange2Dbm(Dbm2RsrpRange(v));
269 }
270 
271 double
273 {
274  return RsrqRange2Db(Db2RsrqRange(v));
275 }
276 
277 double
279 {
280  if (hysteresisIeValue > 30)
281  {
282  NS_FATAL_ERROR("The value " << (uint16_t)hysteresisIeValue
283  << " is out of the allowed range (0..30)"
284  << " for Hysteresis IE value");
285  }
286 
287  double actual = static_cast<double>(hysteresisIeValue) * 0.5;
288  NS_ASSERT(actual >= 0.0);
289  NS_ASSERT(actual <= 15.0);
290  return actual;
291 }
292 
293 uint8_t
295 {
296  if ((hysteresisDb < 0.0) || (hysteresisDb > 15.0))
297  {
298  NS_FATAL_ERROR("The value " << hysteresisDb << " is out of the allowed range (0..15) dB"
299  << " for hysteresis");
300  }
301 
302  uint8_t ieValue = lround(hysteresisDb * 2.0);
303  NS_ASSERT(ieValue <= 30);
304  return ieValue;
305 }
306 
307 double
309 {
310  if ((a3OffsetIeValue < -30) || (a3OffsetIeValue > 30))
311  {
312  NS_FATAL_ERROR("The value " << (int16_t)a3OffsetIeValue
313  << " is out of the allowed range (-30..30)"
314  << " for a3-Offset IE value");
315  }
316 
317  double actual = static_cast<double>(a3OffsetIeValue) * 0.5;
318  NS_ASSERT(actual >= -15.0);
319  NS_ASSERT(actual <= 15.0);
320  return actual;
321 }
322 
323 int8_t
325 {
326  if ((a3OffsetDb < -15.0) || (a3OffsetDb > 15.0))
327  {
328  NS_FATAL_ERROR("The value " << a3OffsetDb << " is out of the allowed range (-15..15) dB"
329  << " for A3 Offset");
330  }
331 
332  int8_t ieValue = lround(a3OffsetDb * 2.0);
333  NS_ASSERT(ieValue >= -30);
334  NS_ASSERT(ieValue <= 30);
335  return ieValue;
336 }
337 
338 double
340 {
341  if ((qRxLevMinIeValue < -70) || (qRxLevMinIeValue > -22))
342  {
343  NS_FATAL_ERROR("The value " << (int16_t)qRxLevMinIeValue
344  << " is out of the allowed range (-70..-22)"
345  << " for Q-RxLevMin IE value");
346  }
347 
348  double actual = static_cast<double>(qRxLevMinIeValue) * 2;
349  NS_ASSERT(actual >= -140.0);
350  NS_ASSERT(actual <= -44.0);
351  return actual;
352 }
353 
354 double
356 {
357  if ((qQualMinIeValue < -34) || (qQualMinIeValue > -3))
358  {
359  NS_FATAL_ERROR("The value " << (int16_t)qQualMinIeValue
360  << " is out of the allowed range (-34..-3)"
361  << " for Q-QualMin IE value");
362  }
363 
364  auto actual = static_cast<double>(qQualMinIeValue);
365  NS_ASSERT(actual >= -34.0);
366  NS_ASSERT(actual <= -3.0);
367  return actual;
368 }
369 
370 }; // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
static uint8_t BufferSize2BsrId(uint32_t val)
Convert Buffer size to BSR ID.
Definition: lte-common.cc:183
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Definition: lte-common.cc:176
static double QuantizeRsrp(double v)
Quantize an RSRP value according to the measurement mapping of TS 36.133.
Definition: lte-common.cc:266
static int8_t ActualA3Offset2IeValue(double a3OffsetDb)
Returns the IE value of a3-Offset.
Definition: lte-common.cc:324
static uint8_t Dbm2RsrpRange(double dbm)
convert an RSRP value in dBm to the corresponding range as per 3GPP TS 36.133 section 9....
Definition: lte-common.cc:242
static uint8_t ActualHysteresis2IeValue(double hysteresisDb)
Returns the IE value of hysteresis.
Definition: lte-common.cc:294
static double RsrpRange2Dbm(uint8_t range)
converts an RSRP range to dBm as per 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
Definition: lte-common.cc:234
static double RsrqRange2Db(uint8_t range)
converts an RSRQ range to dB as per 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
Definition: lte-common.cc:250
static double QuantizeRsrq(double v)
Quantize an RSRQ value according to the measurement mapping of TS 36.133.
Definition: lte-common.cc:272
static double IeValue2ActualQQualMin(int8_t qQualMinIeValue)
Returns the actual value of an Q-QualMin parameter.
Definition: lte-common.cc:355
static double IeValue2ActualQRxLevMin(int8_t qRxLevMinIeValue)
Returns the actual value of an Q-RxLevMin parameter.
Definition: lte-common.cc:339
static double IeValue2ActualHysteresis(uint8_t hysteresisIeValue)
Returns the actual value of a hysteresis parameter.
Definition: lte-common.cc:278
static uint8_t Db2RsrqRange(double db)
convert an RSRQ value in dB to the corresponding range as per 3GPP TS 36.133 section 9....
Definition: lte-common.cc:258
static double IeValue2ActualA3Offset(int8_t a3OffsetIeValue)
Returns the actual value of an a3-Offset parameter.
Definition: lte-common.cc:308
static double getMinFpS11dot3Value()
Get minimum fixed point S11.3 value.
Definition: lte-common.cc:159
static uint16_t double2fpS11dot3(double val)
Convert from double to fixed point S11.3 notation.
Definition: lte-common.cc:134
static double fpS11dot3toDouble(uint16_t val)
Convert from fixed point S11.3 notation to double.
Definition: lte-common.cc:151
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
Definition: lte-common.cc:203
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
static const uint32_t BufferSizeLevelBsrTable[64]
Buffer size level BSR table.
Definition: lte-common.cc:167
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
ImsiLcidPair structure.
Definition: lte-common.h:63
uint8_t m_lcId
LCID.
Definition: lte-common.h:65
uint64_t m_imsi
IMSI.
Definition: lte-common.h:64
LteFlowId structure.
Definition: lte-common.h:43
uint8_t m_lcId
LCID.
Definition: lte-common.h:45
uint16_t m_rnti
RNTI.
Definition: lte-common.h:44
Parameters for configuring the UE.
Definition: lte-common.h:85
uint16_t m_rnti
RNTI.
Definition: lte-common.h:89