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