A Discrete-Event Network Simulator
API
lte-common.cc
Go to the documentation of this file.
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 
22 #include "lte-common.h"
23 #include <ns3/log.h>
24 #include <ns3/abort.h>
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("LteCommon");
29 
31 {
32 }
33 
34 LteFlowId_t::LteFlowId_t (const uint16_t a, const uint8_t b)
35  : m_rnti (a),
36  m_lcId (b)
37 {
38 }
39 
40 bool
42 {
43  return ( (a.m_rnti == b.m_rnti) && (a.m_lcId == b.m_lcId) );
44 }
45 
46 bool
47 operator < (const LteFlowId_t& a, const LteFlowId_t& b)
48 {
49  return ( (a.m_rnti < b.m_rnti) || ( (a.m_rnti == b.m_rnti) && (a.m_lcId < b.m_lcId) ) );
50 }
51 
53 {
54 }
55 
56 ImsiLcidPair_t::ImsiLcidPair_t (const uint64_t a, const uint8_t b)
57  : m_imsi (a),
58  m_lcId (b)
59 {
60 }
61 
62 bool
64 {
65  return ((a.m_imsi == b.m_imsi) && (a.m_lcId == b.m_lcId));
66 }
67 
68 bool
70 {
71  return ((a.m_imsi < b.m_imsi) || ((a.m_imsi == b.m_imsi) && (a.m_lcId
72  < b.m_lcId)));
73 }
74 
75 
77 {
78 }
79 
80 
81 
82 bool
84 {
85  return (a.m_rnti == b.m_rnti);
86 }
87 
88 bool
90 {
91  return (a.m_rnti < b.m_rnti);
92 }
93 
94 
95 uint16_t
97 {
98  // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
99  // truncate val to notation limits
100  if (val > 4095.88)
101  {
102  val = 4095.88;
103  }
104  if (val < -4096)
105  {
106  val = -4096;
107  }
108  int16_t valFp = (int16_t)(val * 8);
109  return (valFp);
110 }
111 
112 double
114 {
115  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
116  double valD = ((int16_t)val) / 8.0;
117  return (valD);
118 }
119 
120 double
122 {
123  return (-4096); // -4096 = 0x8000 = 1000 0000 0000 0000 b
124 }
125 
126 //static double g_lowestFpS11dot3Value = -4096; // 0x8001 (1000 0000 0000 0000)
127 
128 
129 static const uint32_t BufferSizeLevelBsrTable[64] = {
130 
131  0, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57, 67, 78, 91,
132  107, 125, 146, 171, 200, 234, 274, 321, 376, 440, 515, 603,
133  706, 826, 967, 1132, 1326, 1552, 1817, 2127, 2490, 2915, 3413,
134  3995, 4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099, 16507,
135  19325, 22624, 26487, 31009, 36304, 42502, 49759, 58255,
136  68201, 79846, 93749, 109439, 128125, 150000, 150000
137 
138 };
139 
140 uint32_t
142 {
143  NS_ABORT_MSG_UNLESS (val < 64, "val = " << val << " is out of range");
144  return BufferSizeLevelBsrTable[val];
145 }
146 
147 uint8_t
149 {
150  int index = 0;
151  if (BufferSizeLevelBsrTable[63] < val)
152  {
153  index = 63;
154  }
155  else
156  {
157  while (BufferSizeLevelBsrTable[index] < val)
158  {
159  NS_ASSERT (index < 64);
160  index++;
161  }
162  }
163 
164  return (index);
165 }
166 
167 
168 uint8_t
170 {
171  uint8_t nLayer = 0;
172  switch (txMode)
173  {
174  case 0: // Tx MODE 1: SISO
175  nLayer = 1;
176  break;
177  case 1: // Tx MODE 2: MIMO Tx Diversity
178  nLayer = 1;
179  break;
180  case 2: // Tx MODE 3: MIMO Spatial Multiplexity Open Loop
181  nLayer = 2;
182  break;
183  case 3: // Tx MODE 4: MIMO Spatial Multiplexity Closed Loop
184  nLayer = 2;
185  break;
186  case 4: // Tx MODE 5: MIMO Multi-User
187  nLayer = 2;
188  break;
189  case 5: // Tx MODE 6: Closer loop single layer percoding
190  nLayer = 1;
191  break;
192  case 6: // Tx MODE 7: Single antenna port 5
193  nLayer = 1;
194  break;
195  }
196  return (nLayer);
197 }
198 
199 
200 double
202 {
203  // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
204  NS_ASSERT_MSG (range <= 97, "value " << range << " is out of range");
205  return (double) range - 141.0;
206 }
207 
208 uint8_t
210 {
211  // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
212  double range = std::min (std::max (std::floor (dbm + 141), 0.0), 97.0);
213  return (uint8_t) range;
214 }
215 
216 double
218 {
219  // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
220  NS_ASSERT_MSG (range <= 34, "value " << (uint16_t) range << " is out of range");
221  return ((double) range - 40.0)*0.5;
222 }
223 
224 uint8_t
226 {
227  // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
228  double range = std::min (std::max (std::floor (db*2 + 40), 0.0), 34.0);
229  return (uint8_t) range;
230 }
231 
232 double
234 {
235  return RsrpRange2Dbm (Dbm2RsrpRange (v));
236 }
237 
238 double
240 {
241  return RsrqRange2Db (Db2RsrqRange (v));
242 }
243 
244 double
246 {
247  if (hysteresisIeValue > 30)
248  {
249  NS_FATAL_ERROR ("The value " << (uint16_t) hysteresisIeValue
250  << " is out of the allowed range (0..30)"
251  << " for Hysteresis IE value");
252  }
253 
254  double actual = static_cast<double> (hysteresisIeValue) * 0.5;
255  NS_ASSERT (actual >= 0.0);
256  NS_ASSERT (actual <= 15.0);
257  return actual;
258 }
259 
260 uint8_t
262 {
263  if ((hysteresisDb < 0.0) || (hysteresisDb > 15.0))
264  {
265  NS_FATAL_ERROR ("The value " << hysteresisDb
266  << " is out of the allowed range (0..15) dB"
267  << " for hysteresis");
268  }
269 
270  uint8_t ieValue = lround (hysteresisDb * 2.0);
271  NS_ASSERT (ieValue <= 30);
272  return ieValue;
273 }
274 
275 double
277 {
278  if ((a3OffsetIeValue < -30) || (a3OffsetIeValue > 30))
279  {
280  NS_FATAL_ERROR ("The value " << (int16_t) a3OffsetIeValue
281  << " is out of the allowed range (-30..30)"
282  << " for a3-Offset IE value");
283  }
284 
285  double actual = static_cast<double> (a3OffsetIeValue) * 0.5;
286  NS_ASSERT (actual >= -15.0);
287  NS_ASSERT (actual <= 15.0);
288  return actual;
289 }
290 
291 int8_t
293 {
294  if ((a3OffsetDb < -15.0) || (a3OffsetDb > 15.0))
295  {
296  NS_FATAL_ERROR ("The value " << a3OffsetDb
297  << " is out of the allowed range (-15..15) dB"
298  << " for A3 Offset");
299  }
300 
301  int8_t ieValue = lround (a3OffsetDb * 2.0);
302  NS_ASSERT (ieValue >= -30);
303  NS_ASSERT (ieValue <= 30);
304  return ieValue;
305 }
306 
307 double
309 {
310  if ((qRxLevMinIeValue < -70) || (qRxLevMinIeValue > -22))
311  {
312  NS_FATAL_ERROR ("The value " << (int16_t) qRxLevMinIeValue
313  << " is out of the allowed range (-70..-22)"
314  << " for Q-RxLevMin IE value");
315  }
316 
317  double actual = static_cast<double> (qRxLevMinIeValue) * 2;
318  NS_ASSERT (actual >= -140.0);
319  NS_ASSERT (actual <= -44.0);
320  return actual;
321 }
322 
323 double
325 {
326  if ((qQualMinIeValue < -34) || (qQualMinIeValue > -3))
327  {
328  NS_FATAL_ERROR ("The value " << (int16_t) qQualMinIeValue
329  << " is out of the allowed range (-34..-3)"
330  << " for Q-QualMin IE value");
331  }
332 
333  double actual = static_cast<double> (qQualMinIeValue);
334  NS_ASSERT (actual >= -34.0);
335  NS_ASSERT (actual <= -3.0);
336  return actual;
337 }
338 
339 }; // namespace ns3
340 
static uint16_t double2fpS11dot3(double val)
Definition: lte-common.cc:96
static double IeValue2ActualHysteresis(uint8_t hysteresisIeValue)
Returns the actual value of a hysteresis parameter.
Definition: lte-common.cc:245
static double QuantizeRsrp(double v)
Quantize an RSRP value according to the measurement mapping of TS 36.133.
Definition: lte-common.cc:233
#define min(a, b)
Definition: 80211b.c:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
static int8_t ActualA3Offset2IeValue(double a3OffsetDb)
Returns the IE value of a3-Offset.
Definition: lte-common.cc:292
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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:217
static uint8_t BufferSize2BsrId(uint32_t val)
Definition: lte-common.cc:148
#define max(a, b)
Definition: 80211b.c:45
static double getMinFpS11dot3Value()
Definition: lte-common.cc:121
static double IeValue2ActualA3Offset(int8_t a3OffsetIeValue)
Returns the actual value of an a3-Offset parameter.
Definition: lte-common.cc:276
static uint8_t TxMode2LayerNum(uint8_t txMode)
Definition: lte-common.cc:169
static double QuantizeRsrq(double v)
Quantize an RSRQ value according to the measurement mapping of TS 36.133.
Definition: lte-common.cc:239
static const uint32_t BufferSizeLevelBsrTable[64]
Definition: lte-common.cc:129
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:356
static double IeValue2ActualQRxLevMin(int8_t qRxLevMinIeValue)
Returns the actual value of an Q-RxLevMin parameter.
Definition: lte-common.cc:308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#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:90
static uint8_t ActualHysteresis2IeValue(double hysteresisDb)
Returns the IE value of hysteresis.
Definition: lte-common.cc:261
static double fpS11dot3toDouble(uint16_t val)
Definition: lte-common.cc:113
Parameters for configuring the UE.
Definition: lte-common.h:64
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:209
static double IeValue2ActualQQualMin(int8_t qQualMinIeValue)
Returns the actual value of an Q-QualMin parameter.
Definition: lte-common.cc:324
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
static uint32_t BsrId2BufferSize(uint8_t val)
Definition: lte-common.cc:141
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:95
uint8_t m_lcId
Definition: lte-common.h:38
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:225
uint16_t m_rnti
Definition: lte-common.h:37
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:201