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