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 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 }; // namespace ns3
246 
static uint16_t double2fpS11dot3(double val)
Definition: lte-common.cc:97
static double QuantizeRsrp(double v)
Definition: lte-common.cc:234
NS_LOG_COMPONENT_DEFINE("LteCommon")
#define NS_ASSERT(condition)
Definition: assert.h:64
bool operator<(const Room &a, const Room &b)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
Definition: abort.h:131
static double RsrqRange2Db(uint8_t range)
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 uint8_t TxMode2LayerNum(uint8_t txMode)
Definition: lte-common.cc:170
static double QuantizeRsrq(double v)
Definition: lte-common.cc:240
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
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)
Definition: lte-common.cc:210
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)
Definition: lte-common.cc:226
uint32_t BufferSizeLevelBsrTable[64]
Definition: lte-common.cc:130
uint16_t m_rnti
Definition: lte-common.h:37
static double RsrpRange2Dbm(uint8_t range)
Definition: lte-common.cc:202