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
15#include <array>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("LteCommon");
21
22namespace
23{
24
25/// Upper bandwidth bounds (exclusive) for each Type 0 RBG size (3GPP TS 36.213, table 7.1.6.1-1)
26constexpr std::array<uint16_t, 4> TYPE0_ALLOCATION_RBG = {
27 10, // RBG size 1
28 26, // RBG size 2
29 63, // RBG size 3
30 110, // RBG size 4
31};
32
33} // namespace
34
35std::size_t
36GetLteRbgSize(uint16_t dlBandwidth)
37{
38 for (std::size_t i = 0; i < TYPE0_ALLOCATION_RBG.size(); i++)
39 {
40 if (dlBandwidth < TYPE0_ALLOCATION_RBG[i])
41 {
42 return i + 1;
43 }
44 }
45 NS_ABORT_MSG("Unsupported downlink bandwidth of " << dlBandwidth << " resource blocks");
46}
47
51
52LteFlowId_t::LteFlowId_t(const uint16_t a, const uint8_t b)
53 : m_rnti(a),
54 m_lcId(b)
55{
56}
57
58/**
59 * Equality operator
60 *
61 * @param a lhs
62 * @param b rhs
63 * @returns true if "equal"
64 */
65bool
67{
68 return ((a.m_rnti == b.m_rnti) && (a.m_lcId == b.m_lcId));
69}
70
71/**
72 * Less than operator
73 *
74 * @param a lhs
75 * @param b rhs
76 * @returns true if "less than"
77 */
78bool
79operator<(const LteFlowId_t& a, const LteFlowId_t& b)
80{
81 return ((a.m_rnti < b.m_rnti) || ((a.m_rnti == b.m_rnti) && (a.m_lcId < b.m_lcId)));
82}
83
87
88ImsiLcidPair_t::ImsiLcidPair_t(const uint64_t a, const uint8_t b)
89 : m_imsi(a),
90 m_lcId(b)
91{
92}
93
94/**
95 * Equality operator
96 *
97 * @param a lhs
98 * @param b rhs
99 * @returns true if "equal"
100 */
101bool
103{
104 return ((a.m_imsi == b.m_imsi) && (a.m_lcId == b.m_lcId));
105}
106
107/**
108 * Less than operator
109 *
110 * @param a lhs
111 * @param b rhs
112 * @returns true if "less than"
113 */
114bool
115operator<(const ImsiLcidPair_t& a, const ImsiLcidPair_t& b)
116{
117 return ((a.m_imsi < b.m_imsi) || ((a.m_imsi == b.m_imsi) && (a.m_lcId < b.m_lcId)));
118}
119
123
124/**
125 * Equality operator
126 *
127 * @param a lhs
128 * @param b rhs
129 * @returns true if "equal"
130 */
131bool
133{
134 return (a.m_rnti == b.m_rnti);
135}
136
137/**
138 * Less than operator
139 *
140 * @param a lhs
141 * @param b rhs
142 * @returns true if "less than"
143 */
144bool
145operator<(const LteUeConfig_t& a, const LteUeConfig_t& b)
146{
147 return (a.m_rnti < b.m_rnti);
148}
149
150uint16_t
152{
153 // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
154 // truncate val to notation limits
155 if (val > 4095.88)
156 {
157 val = 4095.88;
158 }
159 if (val < -4096)
160 {
161 val = -4096;
162 }
163 auto valFp = (int16_t)(val * 8);
164 return valFp;
165}
166
167double
169{
170 // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
171 double valD = ((int16_t)val) / 8.0;
172 return valD;
173}
174
175double
177{
178 return -4096; // -4096 = 0x8000 = 1000 0000 0000 0000 b
179}
180
181// static double g_lowestFpS11dot3Value = -4096; // 0x8001 (1000 0000 0000 0000)
182
183/// Buffer size level BSR table
185 0, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57,
186 67, 78, 91, 107, 125, 146, 171, 200, 234, 274, 321, 376, 440,
187 515, 603, 706, 826, 967, 1132, 1326, 1552, 1817, 2127, 2490, 2915, 3413,
188 3995, 4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099, 16507, 19325, 22624, 26487,
189 31009, 36304, 42502, 49759, 58255, 68201, 79846, 93749, 109439, 128125, 150000, 150000,
190};
191
194{
195 NS_ABORT_MSG_UNLESS(val < 64, "val = " << val << " is out of range");
196 return BufferSizeLevelBsrTable[val];
197}
198
199uint8_t
201{
202 int index = 0;
203 if (BufferSizeLevelBsrTable[63] < val)
204 {
205 index = 63;
206 }
207 else
208 {
209 while (BufferSizeLevelBsrTable[index] < val)
210 {
211 NS_ASSERT(index < 64);
212 index++;
213 }
214 }
215
216 return index;
217}
218
219uint8_t
221{
222 uint8_t nLayer = 0;
223 switch (txMode)
224 {
225 case 0: // Tx MODE 1: SISO
226 case 1: // Tx MODE 2: MIMO Tx Diversity
227 nLayer = 1;
228 break;
229 case 2: // Tx MODE 3: MIMO Spatial Multiplexity Open Loop
230 case 3: // Tx MODE 4: MIMO Spatial Multiplexity Closed Loop
231 case 4: // Tx MODE 5: MIMO Multi-User
232 nLayer = 2;
233 break;
234 case 5: // Tx MODE 6: Closer loop single layer percoding
235 case 6: // Tx MODE 7: Single antenna port 5
236 nLayer = 1;
237 break;
238 }
239 return nLayer;
240}
241
242double
244{
245 // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
246 NS_ASSERT_MSG(range <= 97, "value " << range << " is out of range");
247 return (double)range - 141.0;
248}
249
250uint8_t
252{
253 // 3GPP TS 36.133 section 9.1.4 RSRP Measurement Report Mapping
254 double range = std::min(std::max(std::floor(dbm + 141), 0.0), 97.0);
255 return (uint8_t)range;
256}
257
258double
260{
261 // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
262 NS_ASSERT_MSG(range <= 34, "value " << (uint16_t)range << " is out of range");
263 return ((double)range - 40.0) * 0.5;
264}
265
266uint8_t
268{
269 // 3GPP TS 36.133 section 9.1.7 RSRQ Measurement Report Mapping
270 double range = std::min(std::max(std::floor(db * 2 + 40), 0.0), 34.0);
271 return (uint8_t)range;
272}
273
274double
279
280double
285
286double
288{
289 if (hysteresisIeValue > 30)
290 {
291 NS_FATAL_ERROR("The value " << (uint16_t)hysteresisIeValue
292 << " is out of the allowed range (0..30)"
293 << " for Hysteresis IE value");
294 }
295
296 double actual = static_cast<double>(hysteresisIeValue) * 0.5;
297 NS_ASSERT(actual >= 0.0);
298 NS_ASSERT(actual <= 15.0);
299 return actual;
300}
301
302uint8_t
304{
305 if ((hysteresisDb < 0.0) || (hysteresisDb > 15.0))
306 {
307 NS_FATAL_ERROR("The value " << hysteresisDb << " is out of the allowed range (0..15) dB"
308 << " for hysteresis");
309 }
310
311 uint8_t ieValue = lround(hysteresisDb * 2.0);
312 NS_ASSERT(ieValue <= 30);
313 return ieValue;
314}
315
316double
318{
319 if ((a3OffsetIeValue < -30) || (a3OffsetIeValue > 30))
320 {
321 NS_FATAL_ERROR("The value " << (int16_t)a3OffsetIeValue
322 << " is out of the allowed range (-30..30)"
323 << " for a3-Offset IE value");
324 }
325
326 double actual = static_cast<double>(a3OffsetIeValue) * 0.5;
327 NS_ASSERT(actual >= -15.0);
328 NS_ASSERT(actual <= 15.0);
329 return actual;
330}
331
332int8_t
334{
335 if ((a3OffsetDb < -15.0) || (a3OffsetDb > 15.0))
336 {
337 NS_FATAL_ERROR("The value " << a3OffsetDb << " is out of the allowed range (-15..15) dB"
338 << " for A3 Offset");
339 }
340
341 int8_t ieValue = lround(a3OffsetDb * 2.0);
342 NS_ASSERT(ieValue >= -30);
343 NS_ASSERT(ieValue <= 30);
344 return ieValue;
345}
346
347double
349{
350 if ((qRxLevMinIeValue < -70) || (qRxLevMinIeValue > -22))
351 {
352 NS_FATAL_ERROR("The value " << (int16_t)qRxLevMinIeValue
353 << " is out of the allowed range (-70..-22)"
354 << " for Q-RxLevMin IE value");
355 }
356
357 double actual = static_cast<double>(qRxLevMinIeValue) * 2;
358 NS_ASSERT(actual >= -140.0);
359 NS_ASSERT(actual <= -44.0);
360 return actual;
361}
362
363double
365{
366 if ((qQualMinIeValue < -34) || (qQualMinIeValue > -3))
367 {
368 NS_FATAL_ERROR("The value " << (int16_t)qQualMinIeValue
369 << " is out of the allowed range (-34..-3)"
370 << " for Q-QualMin IE value");
371 }
372
373 auto actual = static_cast<double>(qQualMinIeValue);
374 NS_ASSERT(actual >= -34.0);
375 NS_ASSERT(actual <= -3.0);
376 return actual;
377}
378
379}; // namespace ns3
uint32_t v
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:76
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:136
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
constexpr std::array< uint16_t, 4 > TYPE0_ALLOCATION_RBG
Upper bandwidth bounds (exclusive) for each Type 0 RBG size (3GPP TS 36.213, table 7....
Definition lte-common.cc:26
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:167
static const uint32_t BufferSizeLevelBsrTable[64]
Buffer size level BSR table.
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:174
std::size_t GetLteRbgSize(uint16_t dlBandwidth)
Get the Type 0 resource block group (RBG) size for a downlink bandwidth, according to 3GPP TS 36....
Definition lte-common.cc:36
uint8_t m_lcId
LCID.
Definition lte-common.h:64
uint64_t m_imsi
IMSI.
Definition lte-common.h:63
uint8_t m_lcId
LCID.
Definition lte-common.h:44
uint16_t m_rnti
RNTI.
Definition lte-common.h:43
uint16_t m_rnti
RNTI.
Definition lte-common.h:88