A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-uplink-power-control.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Piotr Gawlowicz
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Piotr Gawlowicz <gawlowicz.p@gmail.com>
7 *
8 */
9
11
12#include "lte-ffr-simple.h"
13
14#include "ns3/lte-helper.h"
15#include "ns3/mobility-helper.h"
16#include <ns3/boolean.h>
17#include <ns3/callback.h>
18#include <ns3/config.h>
19#include <ns3/double.h>
20#include <ns3/enum.h>
21#include <ns3/ff-mac-scheduler.h>
22#include <ns3/integer.h>
23#include <ns3/log.h>
24#include <ns3/lte-common.h>
25#include <ns3/lte-enb-net-device.h>
26#include <ns3/lte-enb-phy.h>
27#include <ns3/lte-enb-rrc.h>
28#include <ns3/lte-rrc-sap.h>
29#include <ns3/lte-ue-net-device.h>
30#include <ns3/lte-ue-phy.h>
31#include <ns3/lte-ue-rrc.h>
32#include <ns3/pointer.h>
33#include <ns3/simulator.h>
34#include <ns3/string.h>
35
36using namespace ns3;
37
38NS_LOG_COMPONENT_DEFINE("LteUplinkPowerControlTest");
39
40/**
41 * TestSuite
42 */
43
45 : TestSuite("lte-uplink-power-control", Type::SYSTEM)
46{
47 // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_DEBUG);
48 // LogComponentEnable ("LteUplinkPowerControlTest", logLevel);
49 NS_LOG_INFO("Creating LteUplinkPowerControlTestSuite");
50
52 TestCase::Duration::QUICK);
54 new LteUplinkClosedLoopPowerControlAbsoluteModeTestCase("ClosedLoopAbsoluteModeTest1"),
55 TestCase::Duration::QUICK);
57 "ClosedLoopAccumulatedModeTest1"),
58 TestCase::Duration::QUICK);
59}
60
61/**
62 * @ingroup lte-test
63 * Static variable for test initialization
64 */
66
67/**
68 * TestCase Data
69 */
70void
72 uint16_t cellId,
73 uint16_t rnti,
74 double txPower)
75{
76 testcase->PuschTxPowerTrace(cellId, rnti, txPower);
77}
78
79void
81 uint16_t cellId,
82 uint16_t rnti,
83 double txPower)
84{
85 testcase->PucchTxPowerTrace(cellId, rnti, txPower);
86}
87
88void
90 uint16_t cellId,
91 uint16_t rnti,
92 double txPower)
93{
94 testcase->SrsTxPowerTrace(cellId, rnti, txPower);
95}
96
98 : TestCase(name)
99{
100 NS_LOG_INFO("Creating LteUplinkPowerControlTestCase");
101}
102
106
107void
109 uint32_t y,
110 double expectedPuschTxPower,
111 double expectedPucchTxPower,
112 double expectedSrsTxPower)
113{
114 NS_LOG_FUNCTION(this);
115 NS_LOG_DEBUG("Teleport UE to : (" << x << ", " << y << ", 0)");
116
117 m_ueMobility->SetPosition(Vector(x, y, 0.0));
119
120 m_expectedPuschTxPower = expectedPuschTxPower;
121 m_expectedPucchTxPower = expectedPucchTxPower;
122 m_expectedSrsTxPower = expectedSrsTxPower;
123}
124
125void
127 uint32_t tpcNum,
128 double expectedPuschTxPower,
129 double expectedPucchTxPower,
130 double expectedSrsTxPower)
131{
132 NS_LOG_FUNCTION(this);
133
135
136 m_expectedPuschTxPower = expectedPuschTxPower;
137 m_expectedPucchTxPower = expectedPucchTxPower;
138 m_expectedSrsTxPower = expectedSrsTxPower;
139
140 m_ffrSimple->SetTpc(tpc, tpcNum, m_accumulatedMode);
141}
142
143void
144LteUplinkPowerControlTestCase::PuschTxPowerTrace(uint16_t cellId, uint16_t rnti, double txPower)
145{
146 NS_LOG_FUNCTION(this);
147 NS_LOG_DEBUG("PuschTxPower : CellId: " << cellId << " RNTI: " << rnti
148 << " PuschTxPower: " << txPower);
149 // wait because of RSRP filtering
151 {
152 return;
153 }
154 NS_TEST_ASSERT_MSG_EQ_TOL(txPower, m_expectedPuschTxPower, 0.01, "Wrong Pusch Tx Power");
155}
156
157void
158LteUplinkPowerControlTestCase::PucchTxPowerTrace(uint16_t cellId, uint16_t rnti, double txPower)
159{
160 NS_LOG_FUNCTION(this);
161 NS_LOG_DEBUG("PucchTxPower : CellId: " << cellId << " RNTI: " << rnti
162 << " PuschTxPower: " << txPower);
163 // wait because of RSRP filtering
165 {
166 return;
167 }
168
169 NS_TEST_ASSERT_MSG_EQ_TOL(txPower, m_expectedPucchTxPower, 0.01, "Wrong Pucch Tx Power");
170}
171
172void
173LteUplinkPowerControlTestCase::SrsTxPowerTrace(uint16_t cellId, uint16_t rnti, double txPower)
174{
175 NS_LOG_FUNCTION(this);
176 NS_LOG_DEBUG("SrsTxPower : CellId: " << cellId << " RNTI: " << rnti
177 << " PuschTxPower: " << txPower);
178 // wait because of RSRP filtering
180 {
181 return;
182 }
183 NS_TEST_ASSERT_MSG_EQ_TOL(txPower, m_expectedSrsTxPower, 0.01, "Wrong Srs Tx Power");
184}
185
186void
190
192 : LteUplinkPowerControlTestCase("Uplink Open Loop Power Control: " + name)
193{
194 NS_LOG_INFO("Creating LteUplinkPowerControlTestCase");
195}
196
200
201void
203{
205 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(false));
206
207 double eNbTxPower = 30;
208 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(eNbTxPower));
209 Config::SetDefault("ns3::LteUePhy::TxPower", DoubleValue(10.0));
210 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
211
212 Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(false));
213 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
214 Config::SetDefault("ns3::LteUePowerControl::PoNominalPusch", IntegerValue(-90));
215 Config::SetDefault("ns3::LteUePowerControl::PsrsOffset", IntegerValue(9));
216
218
219 uint16_t bandwidth = 25;
220 double d1 = 0;
221
222 // Create Nodes: eNodeB and UE
223 NodeContainer enbNodes;
224 NodeContainer ueNodes;
225 enbNodes.Create(1);
226 ueNodes.Create(1);
227 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
228
229 /* the topology is the following:
230 *
231 * eNB1-------------------------UE
232 * d1
233 */
234
235 // Install Mobility Model
237 positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB1
238 positionAlloc->Add(Vector(d1, 0.0, 0.0)); // UE1
239
240 MobilityHelper mobility;
241 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
242 mobility.SetPositionAllocator(positionAlloc);
243 mobility.Install(allNodes);
244 m_ueMobility = ueNodes.Get(0)->GetObject<MobilityModel>();
245
246 // Create Devices and install them in the Nodes (eNB and UE)
247 NetDeviceContainer enbDevs;
248 NetDeviceContainer ueDevs;
249 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
250
251 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(bandwidth));
252 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(bandwidth));
253
254 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
255 ueDevs = lteHelper->InstallUeDevice(ueNodes);
256
257 Ptr<LteUePhy> uePhy =
258 DynamicCast<LteUePhy>(ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy());
259 m_ueUpc = uePhy->GetUplinkPowerControl();
260
261 m_ueUpc->TraceConnectWithoutContext("ReportPuschTxPower",
263 m_ueUpc->TraceConnectWithoutContext("ReportPucchTxPower",
265 m_ueUpc->TraceConnectWithoutContext("ReportSrsTxPower",
267
268 // Attach a UE to a eNB
269 lteHelper->Attach(ueDevs, enbDevs.Get(0));
270
271 // Activate a data radio bearer
273 EpsBearer bearer(q);
274 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
275
276 // Changing UE position
279 this,
280 0,
281 0,
282 -40,
283 -40,
284 -40);
287 this,
288 200,
289 0,
290 8.9745,
291 8.9745,
292 11.9745);
295 this,
296 400,
297 0,
298 14.9951,
299 14.9951,
300 17.9951);
303 this,
304 600,
305 0,
306 18.5169,
307 18.5169,
308 21.5169);
311 this,
312 800,
313 0,
314 21.0157,
315 21.0157,
316 23);
319 this,
320 1000,
321 0,
322 22.9539,
323 22.9539,
324 23);
327 this,
328 1200,
329 0,
330 23,
331 10,
332 23);
335 this,
336 400,
337 0,
338 14.9951,
339 14.9951,
340 17.9951);
343 this,
344 800,
345 0,
346 21.0157,
347 21.0157,
348 23);
351 this,
352 0,
353 0,
354 -40,
355 -40,
356 -40);
359 this,
360 100,
361 0,
362 2.9539,
363 2.9539,
364 5.9539);
365 Simulator::Stop(Seconds(1.200));
367
369}
370
373 : LteUplinkPowerControlTestCase("Uplink Closed Loop Power Control: " + name)
374{
375 NS_LOG_INFO("Creating LteUplinkClosedLoopPowerControlAbsoluteModeTestCase");
376}
377
382
383void
385{
387 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(false));
388
389 double eNbTxPower = 30;
390 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(eNbTxPower));
391 Config::SetDefault("ns3::LteUePhy::TxPower", DoubleValue(10.0));
392 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
393
394 Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(true));
395 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(false));
396 Config::SetDefault("ns3::LteUePowerControl::PoNominalPusch", IntegerValue(-90));
397 Config::SetDefault("ns3::LteUePowerControl::PsrsOffset", IntegerValue(9));
398
400 lteHelper->SetFfrAlgorithmType("ns3::LteFfrSimple");
401
402 uint16_t bandwidth = 25;
403 double d1 = 100;
404
405 // Create Nodes: eNodeB and UE
406 NodeContainer enbNodes;
407 NodeContainer ueNodes;
408 enbNodes.Create(1);
409 ueNodes.Create(1);
410 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
411
412 /* the topology is the following:
413 *
414 * eNB1-------------------------UE
415 * d1
416 */
417
418 // Install Mobility Model
420 positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB1
421 positionAlloc->Add(Vector(d1, 0.0, 0.0)); // UE1
422
423 MobilityHelper mobility;
424 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
425 mobility.SetPositionAllocator(positionAlloc);
426 mobility.Install(allNodes);
427 m_ueMobility = ueNodes.Get(0)->GetObject<MobilityModel>();
428
429 // Create Devices and install them in the Nodes (eNB and UE)
430 NetDeviceContainer enbDevs;
431 NetDeviceContainer ueDevs;
432 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
433
434 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(bandwidth));
435 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(bandwidth));
436
437 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
438 ueDevs = lteHelper->InstallUeDevice(ueNodes);
439
440 Ptr<LteUePhy> uePhy =
441 DynamicCast<LteUePhy>(ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy());
442 m_ueUpc = uePhy->GetUplinkPowerControl();
443
444 m_ueUpc->TraceConnectWithoutContext("ReportPuschTxPower",
446 m_ueUpc->TraceConnectWithoutContext("ReportPucchTxPower",
448 m_ueUpc->TraceConnectWithoutContext("ReportSrsTxPower",
450
451 // Attach a UE to a eNB
452 lteHelper->Attach(ueDevs, enbDevs.Get(0));
453
454 // Activate a data radio bearer
456 EpsBearer bearer(q);
457 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
458
459 PointerValue tmp;
460 enbDevs.Get(0)->GetAttribute("LteFfrAlgorithm", tmp);
462 m_accumulatedMode = false;
463
464 // Changing TPC value
467 this,
468 1,
469 0,
470 1.9539,
471 1.9539,
472 4.9539);
475 this,
476 0,
477 0,
478 -1.0461,
479 -1.0461,
480 1.9539);
483 this,
484 2,
485 0,
486 3.9539,
487 3.9539,
488 6.9539);
491 this,
492 3,
493 0,
494 6.9539,
495 6.9539,
496 9.9539);
499 this,
500 0,
501 0,
502 -1.0461,
503 -1.0461,
504 1.9539);
507 this,
508 1,
509 0,
510 1.9539,
511 1.9539,
512 4.9539);
515 this,
516 3,
517 0,
518 6.9539,
519 6.9539,
520 9.9539);
523 this,
524 2,
525 0,
526 3.9539,
527 3.9539,
528 6.9539);
529 Simulator::Stop(Seconds(1.000));
531
533}
534
537 : LteUplinkPowerControlTestCase("Uplink Closed Loop Power Control: " + name)
538{
539 NS_LOG_INFO("Creating LteUplinkClosedLoopPowerControlAccumulatedModeTestCase");
540}
541
546
547void
549{
551 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(false));
552
553 double eNbTxPower = 30;
554 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(eNbTxPower));
555 Config::SetDefault("ns3::LteUePhy::TxPower", DoubleValue(10.0));
556 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(true));
557
558 Config::SetDefault("ns3::LteUePowerControl::ClosedLoop", BooleanValue(true));
559 Config::SetDefault("ns3::LteUePowerControl::AccumulationEnabled", BooleanValue(true));
560 Config::SetDefault("ns3::LteUePowerControl::PoNominalPusch", IntegerValue(-90));
561 Config::SetDefault("ns3::LteUePowerControl::PsrsOffset", IntegerValue(9));
562
564 lteHelper->SetFfrAlgorithmType("ns3::LteFfrSimple");
565
566 uint16_t bandwidth = 25;
567 double d1 = 10;
568
569 // Create Nodes: eNodeB and UE
570 NodeContainer enbNodes;
571 NodeContainer ueNodes;
572 enbNodes.Create(1);
573 ueNodes.Create(1);
574 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
575
576 /* the topology is the following:
577 *
578 * eNB1-------------------------UE
579 * d1
580 */
581
582 // Install Mobility Model
584 positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB1
585 positionAlloc->Add(Vector(d1, 0.0, 0.0)); // UE1
586
587 MobilityHelper mobility;
588 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
589 mobility.SetPositionAllocator(positionAlloc);
590 mobility.Install(allNodes);
591 m_ueMobility = ueNodes.Get(0)->GetObject<MobilityModel>();
592
593 // Create Devices and install them in the Nodes (eNB and UE)
594 NetDeviceContainer enbDevs;
595 NetDeviceContainer ueDevs;
596 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
597
598 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(bandwidth));
599 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(bandwidth));
600
601 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
602 ueDevs = lteHelper->InstallUeDevice(ueNodes);
603
604 Ptr<LteUePhy> uePhy =
605 DynamicCast<LteUePhy>(ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy());
606 m_ueUpc = uePhy->GetUplinkPowerControl();
607
608 m_ueUpc->TraceConnectWithoutContext("ReportPuschTxPower",
610 m_ueUpc->TraceConnectWithoutContext("ReportPucchTxPower",
612 m_ueUpc->TraceConnectWithoutContext("ReportSrsTxPower",
614
615 // Attach a UE to a eNB
616 lteHelper->Attach(ueDevs, enbDevs.Get(0));
617
618 // Activate a data radio bearer
620 EpsBearer bearer(q);
621 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
622
623 PointerValue tmp;
624 enbDevs.Get(0)->GetAttribute("LteFfrAlgorithm", tmp);
626 m_accumulatedMode = true;
627
628 // Changing TPC value
631 this,
632 1,
633 0,
634 -17.0461,
635 -17.0461,
636 -14.0461);
639 this,
640 0,
641 20,
642 -37.0461,
643 -37.0461,
644 -34.0461);
647 this,
648 0,
649 20,
650 -40,
651 10,
652 -37.0461);
655 this,
656 2,
657 1,
658 -39.0461,
659 -39.0461,
660 -36.0461);
663 this,
664 3,
665 10,
666 -9.0461,
667 -9.0461,
668 -6.0461);
671 this,
672 2,
673 15,
674 5.9539,
675 5.9539,
676 8.9539);
679 this,
680 3,
681 1,
682 8.9539,
683 8.9539,
684 11.9539);
687 this,
688 2,
689 10,
690 18.9539,
691 18.9539,
692 21.9539);
695 this,
696 2,
697 20,
698 23,
699 23,
700 23);
703 this,
704 0,
705 1,
706 22.9539,
707 22.9539,
708 23);
711 this,
712 0,
713 20,
714 2.9539,
715 2.9539,
716 5.9539);
719 this,
720 2,
721 5,
722 7.9539,
723 7.9539,
724 10.9539);
725 Simulator::Stop(Seconds(1.200));
727
729}
AttributeValue implementation for Boolean.
Definition boolean.h:26
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
Qci
QoS Class Indicator.
Definition eps-bearer.h:95
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition eps-bearer.h:96
Hold a signed integer type.
Definition integer.h:34
The LteUeNetDevice class implements the UE net device.
Ptr< LteUePhy > GetPhy() const
Get the Phy.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
AttributeValue implementation for Pointer.
Ptr< Object > GetObject() const
Get the Object referenced by the PointerValue.
Definition pointer.cc:46
Ptr< T > Get() const
Definition pointer.h:223
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
void Reset()
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition config.cc:848
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:264
static LteUplinkPowerControlTestSuite lteUplinkPowerControlTestSuite
Static variable for test initialization.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:745
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition test.h:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580