A Discrete-Event Network Simulator
API
lte-ue-power-control.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Piotr Gawlowicz
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Piotr Gawlowicz <gawlowicz.p@gmail.com>
18  *
19  */
20 
21 #include "lte-ue-power-control.h"
22 
23 #include <ns3/boolean.h>
24 #include <ns3/double.h>
25 #include <ns3/integer.h>
26 #include <ns3/log.h>
27 #include <ns3/math.h>
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("LteUePowerControl");
33 
34 NS_OBJECT_ENSURE_REGISTERED(LteUePowerControl);
35 
37 {
38  NS_LOG_FUNCTION(this);
39  m_deltaTF = 0;
40  m_fc = 0;
41  m_pathLoss = 100; // initial value
42  m_curPuschTxPower = 10;
43  m_curPucchTxPower = 10;
44  m_curSrsTxPower = 10;
45  m_txPower = 10;
46 
47  m_cellId = 0;
48  m_rnti = 0;
49 
50  m_M_Pusch = 0;
51  m_rsrpSet = false;
52  m_pcRsrpFilterCoefficient = 4; // Default value similar to the eNB (see lte-enb-rrc.cc)
53 }
54 
56 {
57  NS_LOG_FUNCTION(this);
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION(this);
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION(this);
70 }
71 
72 TypeId
74 {
75  static TypeId tid =
76  TypeId("ns3::LteUePowerControl")
77  .SetParent<Object>()
78  .SetGroupName("Lte")
79  .AddConstructor<LteUePowerControl>()
80  .AddAttribute("ClosedLoop",
81  "If true Closed Loop mode will be active, otherwise Open Loop",
82  BooleanValue(true),
85  .AddAttribute("AccumulationEnabled",
86  "If true TCP accumulation mode will be active, otherwise absolute mode "
87  "will be active",
88  BooleanValue(true),
91  .AddAttribute("Alpha",
92  "Value of Alpha parameter",
93  DoubleValue(1.0),
95  MakeDoubleChecker<double>())
96  .AddAttribute("Pcmax",
97  "Max Transmission power in dBm, Default value 23 dBm"
98  "TS36.101 section 6.2.3",
99  DoubleValue(23.0),
101  MakeDoubleChecker<double>())
102  .AddAttribute("Pcmin",
103  "Min Transmission power in dBm, Default value -40 dBm"
104  "TS36.101 section 6.2.3",
105  DoubleValue(-40),
107  MakeDoubleChecker<double>())
108  .AddAttribute("PoNominalPusch",
109  "P_O_NOMINAL_PUSCH INT (-126 ... 24), Default value -80",
110  IntegerValue(-80),
112  MakeIntegerChecker<int16_t>())
113  .AddAttribute("PoUePusch",
114  "P_O_UE_PUSCH INT(-8...7), Default value 0",
115  IntegerValue(0),
117  MakeIntegerChecker<int16_t>())
118  .AddAttribute("PsrsOffset",
119  "P_SRS_OFFSET INT(0...15), Default value 7",
120  IntegerValue(7),
122  MakeIntegerChecker<int16_t>())
123  .AddTraceSource("ReportPuschTxPower",
124  "Report PUSCH TxPower in dBm",
126  "ns3::LteUePowerControl::TxPowerTracedCallback")
127  .AddTraceSource("ReportPucchTxPower",
128  "Report PUCCH TxPower in dBm",
130  "ns3::LteUePowerControl::TxPowerTracedCallback")
131  .AddTraceSource("ReportSrsTxPower",
132  "Report SRS TxPower in dBm",
134  "ns3::LteUePowerControl::TxPowerTracedCallback");
135  return tid;
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION(this);
142  m_Pcmax = value;
143 }
144 
145 double
147 {
148  NS_LOG_FUNCTION(this);
149  return m_Pcmax;
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION(this);
156  m_txPower = value;
157  m_curPuschTxPower = value;
158  m_curPucchTxPower = value;
159  m_curSrsTxPower = value;
160 }
161 
162 void
164 {
165  NS_LOG_FUNCTION(this);
166  m_referenceSignalPower = referenceSignalPower;
167 }
168 
169 void
171 {
172  NS_LOG_FUNCTION(this);
173  m_cellId = cellId;
174 }
175 
176 void
178 {
179  NS_LOG_FUNCTION(this);
180  m_rnti = rnti;
181 }
182 
183 void
185 {
186  NS_LOG_FUNCTION(this);
187 
188  if (m_PoNominalPusch.empty())
189  {
190  m_PoNominalPusch.push_back(value);
191  m_PoNominalPusch.push_back(value);
192  m_PoNominalPusch.push_back(value);
193  }
194  else
195  {
196  m_PoNominalPusch[0] = value;
197  m_PoNominalPusch[1] = value;
198  m_PoNominalPusch[2] = value;
199  }
200 }
201 
202 void
204 {
205  NS_LOG_FUNCTION(this);
206  if (m_PoUePusch.empty())
207  {
208  m_PoUePusch.push_back(value);
209  m_PoUePusch.push_back(value);
210  m_PoUePusch.push_back(0);
211  }
212  else
213  {
214  m_PoUePusch[0] = value;
215  m_PoUePusch[1] = value;
216  m_PoUePusch[2] = 0;
217  }
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION(this);
224 
225  uint32_t temp = value * 10;
226  switch (temp)
227  {
228  case 0:
229  case 4:
230  case 5:
231  case 6:
232  case 7:
233  case 8:
234  case 9:
235  case 10:
236  break;
237  default:
238  NS_FATAL_ERROR("Unexpected Alpha value");
239  }
240 
241  if (m_alpha.empty())
242  {
243  m_alpha.push_back(value);
244  m_alpha.push_back(value);
245  m_alpha.push_back(0);
246  }
247  else
248  {
249  m_alpha[0] = value;
250  m_alpha[1] = value;
251  m_alpha[2] = 1;
252  }
253 }
254 
255 void
257 {
258  NS_LOG_FUNCTION(this);
259 
260  if (!m_rsrpSet)
261  {
262  m_rsrp = value;
263  m_rsrpSet = true;
264  return;
265  }
266 
267  double alphaRsrp = std::pow(0.5, m_pcRsrpFilterCoefficient / 4.0);
268  m_rsrp = (1 - alphaRsrp) * m_rsrp + alphaRsrp * value;
269 
271 }
272 
273 void
274 LteUePowerControl::SetRsrpFilterCoefficient(uint8_t rsrpFilterCoefficient)
275 {
276  NS_LOG_FUNCTION(this);
277  m_pcRsrpFilterCoefficient = rsrpFilterCoefficient;
278 }
279 
280 void
282 {
283  NS_LOG_FUNCTION(this);
284 
285  int delta = 0;
287  {
288  switch (tpc)
289  {
290  case 0:
291  delta = -1;
292  break;
293  case 1:
294  delta = 0;
295  break;
296  case 2:
297  delta = 1;
298  break;
299  case 3:
300  delta = 3;
301  break;
302  default:
303  NS_FATAL_ERROR("Unexpected TPC value");
304  }
305  }
306  else
307  {
308  switch (tpc)
309  {
310  case 0:
311  delta = -4;
312  break;
313  case 1:
314  delta = -1;
315  break;
316  case 2:
317  delta = 1;
318  break;
319  case 3:
320  delta = 4;
321  break;
322  default:
323  NS_FATAL_ERROR("Unexpected TPC value");
324  }
325  }
326 
327  m_deltaPusch.push_back(delta);
328 
329  if (m_closedLoop)
330  {
332  {
333  if (m_deltaPusch.size() == 4)
334  {
335  if ((m_curPuschTxPower <= m_Pcmin && m_deltaPusch.at(0) < 0) ||
336  (m_curPuschTxPower >= m_Pcmax && m_deltaPusch.at(0) > 0))
337  {
338  // TPC commands for serving cell shall not be accumulated
339  m_deltaPusch.erase(m_deltaPusch.begin());
340  }
341  else
342  {
343  m_fc = m_fc + m_deltaPusch.at(0);
344  m_deltaPusch.erase(m_deltaPusch.begin());
345  }
346  }
347  else
348  {
349  m_fc = 0;
350  }
351  }
352  else
353  {
354  m_fc = m_deltaPusch.at(0);
355  m_deltaPusch.erase(m_deltaPusch.begin());
356  }
357  }
358  else
359  {
360  m_fc = 0;
361  }
362 
363  NS_LOG_INFO("ReportTpc: " << (int)tpc << " delta: " << delta << " Fc: " << m_fc);
364 }
365 
366 void
368 {
369  NS_LOG_FUNCTION(this);
370  m_M_Pusch = mask.size();
371 }
372 
373 void
375 {
376  NS_LOG_FUNCTION(this);
377  int32_t j = 1;
378  int32_t PoPusch = m_PoNominalPusch[j] + m_PoUePusch[j];
379 
380  NS_LOG_INFO("RB: " << m_M_Pusch << " m_PoPusch: " << PoPusch << " Alpha: " << m_alpha[j]
381  << " PathLoss: " << m_pathLoss << " deltaTF: " << m_deltaTF
382  << " fc: " << m_fc);
383 
384  if (m_M_Pusch > 0)
385  {
387  10 * log10(1.0 * m_M_Pusch) + PoPusch + m_alpha[j] * m_pathLoss + m_deltaTF + m_fc;
388  m_M_Pusch = 0;
389  }
390  else
391  {
392  m_curPuschTxPower = PoPusch + m_alpha[j] * m_pathLoss + m_fc;
393  }
394 
395  NS_LOG_INFO("CalcPower: " << m_curPuschTxPower << " MinPower: " << m_Pcmin
396  << " MaxPower:" << m_Pcmax);
397 
400  NS_LOG_INFO("PuschTxPower: " << m_curPuschTxPower);
401 }
402 
403 void
405 {
406  NS_LOG_FUNCTION(this);
408  NS_LOG_INFO("PucchTxPower: " << m_curPucchTxPower);
409 }
410 
411 void
413 {
414  NS_LOG_FUNCTION(this);
415  int32_t j = 1;
416  int32_t PoPusch = m_PoNominalPusch[j] + m_PoUePusch[j];
417 
418  NS_LOG_INFO("RB: " << m_M_Pusch << " m_PoPusch: " << PoPusch << " Alpha: " << m_alpha[j]
419  << " PathLoss: " << m_pathLoss << " deltaTF: " << m_deltaTF
420  << " fc: " << m_fc);
421 
422  double pSrsOffsetValue = -10.5 + m_PsrsOffset * 1.5;
423 
425  pSrsOffsetValue + 10 * log10(m_srsBandwidth) + PoPusch + m_alpha[j] * m_pathLoss + m_fc;
426 
427  NS_LOG_INFO("CalcPower: " << m_curSrsTxPower << " MinPower: " << m_Pcmin
428  << " MaxPower:" << m_Pcmax);
429 
432  NS_LOG_INFO("SrsTxPower: " << m_curSrsTxPower);
433 }
434 
435 double
437 {
438  NS_LOG_FUNCTION(this);
439 
440  m_M_Pusch = dlRb.size();
442 
444 
445  return m_curPuschTxPower;
446 }
447 
448 double
450 {
451  NS_LOG_FUNCTION(this);
452 
454 
456 
457  return m_curPucchTxPower;
458 }
459 
460 double
461 LteUePowerControl::GetSrsTxPower(std::vector<int> dlRb)
462 {
463  NS_LOG_FUNCTION(this);
464 
465  m_srsBandwidth = dlRb.size();
467 
469 
470  return m_curSrsTxPower;
471 }
472 
473 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold a signed integer type.
Definition: integer.h:45
This class realizes Uplink Power Control functionality.
void SetPoNominalPusch(int16_t value)
Set PO nominal PUSCH function.
bool m_closedLoop
is closed loop
double m_referenceSignalPower
reference signal power in dBm
TracedCallback< uint16_t, uint16_t, double > m_reportSrsTxPower
Trace information regarding Uplink TxPower uint16_t cellId, uint16_t rnti, double txPower.
void DoDispose() override
Destructor implementation.
TracedCallback< uint16_t, uint16_t, double > m_reportPucchTxPower
Trace information regarding Uplink TxPower uint16_t cellId, uint16_t rnti, double txPower.
void SetCellId(uint16_t cellId)
Set the cell ID function.
double m_txPower
transmit power
double m_curPucchTxPower
current PUCCH transmit power
void SetPoUePusch(int16_t value)
Set PO UE PUSCH function.
std::vector< double > m_alpha
alpha values
std::vector< int16_t > m_PoUePusch
PO US PUSCH.
void SetRsrp(double value)
Set RSRP function.
void SetPcmax(double value)
Set PC maximum function.
double m_pathLoss
path loss value in dB
void ConfigureReferenceSignalPower(int8_t referenceSignalPower)
Configure reference signal power (dBm) function.
void DoInitialize() override
Initialize() implementation.
std::vector< int16_t > m_PoNominalPusch
PO nominal PUSCH.
void SetRnti(uint16_t rnti)
Set the RNTI function.
double GetPucchTxPower(std::vector< int > rb)
Get PUCCH transmit power function.
int16_t m_PsrsOffset
PSRS offset.
static TypeId GetTypeId()
Get the type ID.
double m_curPuschTxPower
current PUSCH transmit power
void SetTxPower(double value)
Set transmit power function.
std::vector< int8_t > m_deltaPusch
delta PUSCH
void CalculatePuschTxPower()
Calculate PUSCH transmit power function.
double GetPcmax()
Get PC maximum function.
void SetSubChannelMask(std::vector< int > mask)
Set subchannel mask function.
void SetRsrpFilterCoefficient(uint8_t rsrpFilterCoefficient)
Set RSRP function.
uint16_t m_srsBandwidth
SRS bandwidth.
uint8_t m_pcRsrpFilterCoefficient
The RsrpFilterCoefficient attribute.
void CalculatePucchTxPower()
Calculate PUCCH transmit power function.
double GetPuschTxPower(std::vector< int > rb)
Get PUSCH transmit power function.
uint16_t m_M_Pusch
size of DL RB list
void ReportTpc(uint8_t tpc)
Set RSRP function.
double GetSrsTxPower(std::vector< int > rb)
Get SRS transmit power function.
void SetAlpha(double value)
Set alpha function.
double m_rsrp
RSRP value in dBm.
void CalculateSrsTxPower()
Calculate SRS transmit power function.
double m_curSrsTxPower
current SRS transmit power
TracedCallback< uint16_t, uint16_t, double > m_reportPuschTxPower
Trace information regarding Uplink TxPower uint16_t cellId, uint16_t rnti, double txPower.
bool m_accumulationEnabled
accumulation enabled
A base class which provides memory management and object aggregation.
Definition: object.h:89
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Definition: integer.h:46
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43