5#include "ns3/antenna-module.h"
6#include "ns3/applications-module.h"
7#include "ns3/boolean.h"
8#include "ns3/callback.h"
10#include "ns3/double.h"
11#include "ns3/integer.h"
12#include "ns3/internet-module.h"
14#include "ns3/mobility-helper.h"
15#include "ns3/nr-module.h"
16#include "ns3/point-to-point-module.h"
17#include "ns3/pointer.h"
18#include "ns3/rng-seed-manager.h"
19#include "ns3/simulator.h"
23NS_LOG_COMPONENT_DEFINE(
"NrUplinkPowerControlTestCase");
32class NrUplinkPowerControlTestSuite :
public TestSuite
35 NrUplinkPowerControlTestSuite();
47class NrUplinkPowerControlTestCase :
public TestCase
57 NrUplinkPowerControlTestCase(std::string name,
bool closedLoop,
bool accumulatedMode);
61 ~NrUplinkPowerControlTestCase()
override;
71 void MoveUe(uint32_t distance,
double expectedPuschTxPower,
double expectedPucchTxPower);
79 void PuschTxPowerTrace(uint16_t cellId, uint16_t rnti,
double txPower);
86 void PucchTxPowerTrace(uint16_t cellId, uint16_t rnti,
double txPower);
89 void DoRun()
override;
91 Ptr<MobilityModel> m_ueMobility;
92 Ptr<NrUePowerControl> m_ueUpc;
94 double m_expectedPuschTxPower{0.0};
95 double m_expectedPucchTxPower{0.0};
96 bool m_closedLoop{
true};
97 bool m_accumulatedMode{
true};
99 bool m_puschTxPowerTraceFired{
101 bool m_pucchTxPowerTraceFired{
105NrUplinkPowerControlTestSuite::NrUplinkPowerControlTestSuite()
106 : TestSuite(
"nr-uplink-power-control-test", Type::SYSTEM)
110 NS_LOG_INFO(
"Creating NrUplinkPowerControlTestSuite");
111 AddTestCase(
new NrUplinkPowerControlTestCase(
"OpenLoopPowerControlTest",
false,
false),
114 new NrUplinkPowerControlTestCase(
"ClosedLoopPowerControlAbsoluteModeTest",
true,
false),
117 new NrUplinkPowerControlTestCase(
"ClosedLoopPowerControlAccumulatedModeTest",
true,
true),
121static NrUplinkPowerControlTestSuite lteUplinkPowerControlTestSuite;
124PuschTxPowerReport(NrUplinkPowerControlTestCase* testcase,
129 testcase->PuschTxPowerTrace(cellId, rnti, txPower);
133PucchTxPowerReport(NrUplinkPowerControlTestCase* testcase,
138 testcase->PucchTxPowerTrace(cellId, rnti, txPower);
141NrUplinkPowerControlTestCase::NrUplinkPowerControlTestCase(std::string name,
143 bool accumulatedMode)
146 NS_LOG_INFO(
"Creating NrUplinkPowerControlTestCase");
147 m_closedLoop = closedLoop;
153NrUplinkPowerControlTestCase::~NrUplinkPowerControlTestCase()
158NrUplinkPowerControlTestCase::MoveUe(uint32_t distance,
159 double expectedPuschTxPower,
160 double expectedPucchTxPower)
162 NS_LOG_FUNCTION(
this);
164 NS_TEST_ASSERT_MSG_EQ(m_pucchTxPowerTraceFired,
166 "Power trace for PUCCH did not get triggered. Test check for PUCCH did "
167 "not execute as expected. ");
168 m_pucchTxPowerTraceFired =
false;
169 NS_TEST_ASSERT_MSG_EQ(m_puschTxPowerTraceFired,
171 "Power trace for PUSCH did not get triggered. Test check did PUSCH not "
172 "execute as expected. ");
173 m_puschTxPowerTraceFired =
false;
174 Vector newPosition = m_ueMobility->GetPosition();
175 newPosition.x = distance;
176 m_ueMobility->SetPosition(newPosition);
177 NS_LOG_DEBUG(
"Move UE to : " << m_ueMobility->GetPosition());
178 m_movingTime = Simulator::Now();
179 m_expectedPuschTxPower = expectedPuschTxPower;
180 m_expectedPucchTxPower = expectedPucchTxPower;
184NrUplinkPowerControlTestCase::PuschTxPowerTrace(uint16_t cellId, uint16_t rnti,
double txPower)
186 NS_LOG_FUNCTION(
this);
187 NS_LOG_DEBUG(
"PuschTxPower for CellId: " << cellId <<
" RNTI: " << rnti
188 <<
" PuschTxPower: " << txPower);
190 if ((Simulator::Now() - m_movingTime) < MilliSeconds(50))
196 if (!m_puschTxPowerTraceFired)
198 m_puschTxPowerTraceFired =
true;
203 NS_TEST_ASSERT_MSG_EQ_TOL(txPower,
204 m_expectedPuschTxPower,
205 1 + std::fabs(m_expectedPuschTxPower * 0.1),
206 "Wrong Pusch Tx Power");
210NrUplinkPowerControlTestCase::PucchTxPowerTrace(uint16_t cellId, uint16_t rnti,
double txPower)
212 NS_LOG_FUNCTION(
this);
213 NS_LOG_DEBUG(
"PucchTxPower : CellId: " << cellId <<
" RNTI: " << rnti
214 <<
" PuschTxPower: " << txPower);
216 if ((Simulator::Now() - m_movingTime) < MilliSeconds(50))
222 if (!m_pucchTxPowerTraceFired)
224 m_pucchTxPowerTraceFired =
true;
229 NS_TEST_ASSERT_MSG_EQ_TOL(txPower,
230 m_expectedPucchTxPower,
231 1 + std::fabs(m_expectedPucchTxPower * 0.1),
232 "Wrong Pucch Tx Power");
236NrUplinkPowerControlTestCase::DoRun()
238 std::string scenario =
"InH-OfficeMixed";
239 double frequency = 2e9;
240 double bandwidth = 4.6e6;
243 double gNBTxPower = 30;
244 double ueTxPower = 10;
245 std::string condition =
"LOS";
246 uint16_t numerology = 0;
247 uint16_t numCcPerBand = 1;
248 Time udpAppStartTime = MilliSeconds(50);
249 Time simTime = MilliSeconds(2500);
253 RngSeedManager::SetSeed(1);
254 RngSeedManager::SetRun(1);
256 Config::SetDefault(
"ns3::NrUePhy::EnableUplinkPowerControl", BooleanValue(
true));
257 Config::SetDefault(
"ns3::NrUePowerControl::ClosedLoop", BooleanValue(m_closedLoop));
258 Config::SetDefault(
"ns3::NrUePowerControl::AccumulationEnabled",
259 BooleanValue(m_accumulatedMode));
260 Config::SetDefault(
"ns3::NrUePowerControl::PoNominalPusch", IntegerValue(-90));
261 Config::SetDefault(
"ns3::NrUePowerControl::PoNominalPucch", IntegerValue(-80));
262 Config::SetDefault(
"ns3::NrUePowerControl::PsrsOffset", IntegerValue(9));
263 Config::SetDefault(
"ns3::ThreeGppPropagationLossModel::ShadowingEnabled", BooleanValue(
false));
265 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
266 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
267 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
268 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
270 channelHelper->ConfigureFactories(scenario, condition,
"ThreeGpp");
272 channelHelper->SetPathlossAttribute(
"ShadowingEnabled", BooleanValue(
false));
273 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
274 nrHelper->SetEpcHelper(nrEpcHelper);
277 NodeContainer gnbNodes;
278 NodeContainer ueNodes;
281 NodeContainer allNodes = NodeContainer(gnbNodes, ueNodes);
284 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
285 positionAlloc->Add(Vector(0.1, 0.0, hBS));
286 positionAlloc->Add(Vector(0, 0.0, hUT));
288 MobilityHelper mobility;
289 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
290 mobility.SetPositionAllocator(positionAlloc);
291 mobility.Install(allNodes);
292 m_ueMobility = ueNodes.Get(0)->GetObject<MobilityModel>();
295 NetDeviceContainer gnbDevs;
296 NetDeviceContainer ueDevs;
297 nrHelper->SetGnbPhyAttribute(
"Numerology", UintegerValue(numerology));
298 nrHelper->SetGnbPhyAttribute(
"TxPower", DoubleValue(gNBTxPower));
299 nrHelper->SetUePhyAttribute(
"TxPower", DoubleValue(ueTxPower));
300 nrHelper->SetUePhyAttribute(
"EnableUplinkPowerControl", BooleanValue(
true));
310 idealBeamformingHelper->SetAttribute(
"BeamformingMethod",
314 nrHelper->SetUeAntennaAttribute(
"NumRows", UintegerValue(1));
315 nrHelper->SetUeAntennaAttribute(
"NumColumns", UintegerValue(1));
316 nrHelper->SetUeAntennaAttribute(
"AntennaElement",
317 PointerValue(CreateObject<IsotropicAntennaModel>()));
320 nrHelper->SetGnbAntennaAttribute(
"NumRows", UintegerValue(1));
321 nrHelper->SetGnbAntennaAttribute(
"NumColumns", UintegerValue(1));
322 nrHelper->SetGnbAntennaAttribute(
"AntennaElement",
323 PointerValue(CreateObject<IsotropicAntennaModel>()));
325 gnbDevs = nrHelper->InstallGnbDevice(gnbNodes, allBwps);
326 ueDevs = nrHelper->InstallUeDevice(ueNodes, allBwps);
328 Ptr<NrUePhy> uePhy = nrHelper->GetUePhy(ueDevs.Get(0), 0);
330 m_ueUpc = uePhy->GetUplinkPowerControl();
332 m_ueUpc->TraceConnectWithoutContext(
"ReportPuschTxPower",
333 MakeBoundCallback(&PuschTxPowerReport,
this));
334 m_ueUpc->TraceConnectWithoutContext(
"ReportPucchTxPower",
335 MakeBoundCallback(&PucchTxPowerReport,
this));
337 Ptr<const NrSpectrumPhy> txSpectrumPhy =
338 nrHelper->GetGnbPhy(gnbDevs.Get(0), 0)->GetSpectrumPhy();
339 Ptr<SpectrumChannel> txSpectrumChannel = txSpectrumPhy->GetSpectrumChannel();
340 Ptr<ThreeGppPropagationLossModel> propagationLossModel =
341 DynamicCast<ThreeGppPropagationLossModel>(txSpectrumChannel->GetPropagationLossModel());
342 NS_ASSERT(propagationLossModel !=
nullptr);
343 propagationLossModel->AssignStreams(1);
344 Ptr<ChannelConditionModel> channelConditionModel =
345 propagationLossModel->GetChannelConditionModel();
346 channelConditionModel->AssignStreams(1);
347 Ptr<ThreeGppSpectrumPropagationLossModel> spectrumLossModel =
348 DynamicCast<ThreeGppSpectrumPropagationLossModel>(
349 txSpectrumChannel->GetPhasedArraySpectrumPropagationLossModel());
351 spectrumLossModel ==
nullptr,
352 "3GPP spectrum model should be disabled in this test to have deterministic behaviour.");
355 Ptr<Node> pgw = nrEpcHelper->GetPgwNode();
356 NodeContainer remoteHostContainer;
357 remoteHostContainer.Create(1);
358 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
359 InternetStackHelper internet;
360 internet.Install(remoteHostContainer);
363 PointToPointHelper p2ph;
364 p2ph.SetDeviceAttribute(
"DataRate", DataRateValue(DataRate(
"100Gb/s")));
365 p2ph.SetDeviceAttribute(
"Mtu", UintegerValue(2500));
366 p2ph.SetChannelAttribute(
"Delay", TimeValue(Seconds(0.000)));
367 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
368 Ipv4AddressHelper ipv4h;
369 Ipv4StaticRoutingHelper ipv4RoutingHelper;
370 ipv4h.SetBase(
"1.0.0.0",
"255.0.0.0");
371 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
372 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
373 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
374 remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address(
"7.0.0.0"), Ipv4Mask(
"255.0.0.0"), 1);
375 internet.Install(ueNodes);
377 Ipv4InterfaceContainer ueIpIface = nrEpcHelper->AssignUeIpv4Address(ueDevs);
379 Ptr<Ipv4StaticRouting> ueStaticRouting =
380 ipv4RoutingHelper.GetStaticRouting(ueNodes.Get(0)->GetObject<Ipv4>());
381 ueStaticRouting->SetDefaultRoute(nrEpcHelper->GetUeDefaultGatewayAddress(), 1);
384 nrHelper->AttachToGnb(ueDevs.Get(0), gnbDevs.Get(0));
390 uint16_t dlPort = 1234;
391 uint16_t ulPort = 1236;
393 ApplicationContainer serverApps;
395 UdpServerHelper dlPacketSink(dlPort);
396 UdpServerHelper ulPacketSink(ulPort);
400 serverApps.Add(dlPacketSink.Install(ueNodes.Get(0)));
401 serverApps.Add(ulPacketSink.Install(remoteHost));
403 UdpClientHelper dlClient;
404 dlClient.SetAttribute(
"RemotePort", UintegerValue(dlPort));
405 dlClient.SetAttribute(
"MaxPackets", UintegerValue(0xFFFFFFFF));
406 dlClient.SetAttribute(
"PacketSize", UintegerValue(100));
407 dlClient.SetAttribute(
"Interval", TimeValue(MilliSeconds(1)));
409 Ptr<NrEpcTft> dlTft = Create<NrEpcTft>();
415 UdpClientHelper ulClient;
416 ulClient.SetAttribute(
"RemotePort", UintegerValue(ulPort));
417 ulClient.SetAttribute(
"MaxPackets", UintegerValue(0xFFFFFFFF));
418 ulClient.SetAttribute(
"PacketSize", UintegerValue(100));
419 ulClient.SetAttribute(
"Interval", TimeValue(MilliSeconds(1)));
421 Ptr<NrEpcTft> ulTft = Create<NrEpcTft>();
428 ApplicationContainer clientApps;
430 Address ueAddress = ueIpIface.GetAddress(0);
431 dlClient.SetAttribute(
"RemoteAddress", AddressValue(ueAddress));
432 clientApps.Add(dlClient.Install(remoteHost));
433 nrHelper->ActivateDedicatedEpsBearer(ueDevs.Get(0), dlBearer, dlTft);
435 ulClient.SetAttribute(
"RemoteAddress", AddressValue(internetIpIfaces.GetAddress(1)));
436 clientApps.Add(ulClient.Install(ueNodes.Get(0)));
437 nrHelper->ActivateDedicatedEpsBearer(ueDevs.Get(0), ulBearer, ulTft);
440 serverApps.Start(udpAppStartTime);
441 clientApps.Start(udpAppStartTime);
442 serverApps.Stop(simTime);
443 clientApps.Stop(simTime);
476 Simulator::Schedule(MilliSeconds(0),
477 &NrUplinkPowerControlTestCase::MoveUe,
482 Simulator::Schedule(MilliSeconds(200),
483 &NrUplinkPowerControlTestCase::MoveUe,
488 Simulator::Schedule(MilliSeconds(400),
489 &NrUplinkPowerControlTestCase::MoveUe,
494 Simulator::Schedule(MilliSeconds(600),
495 &NrUplinkPowerControlTestCase::MoveUe,
500 Simulator::Schedule(MilliSeconds(800),
501 &NrUplinkPowerControlTestCase::MoveUe,
506 Simulator::Schedule(MilliSeconds(1000),
507 &NrUplinkPowerControlTestCase::MoveUe,
512 Simulator::Schedule(MilliSeconds(1200),
513 &NrUplinkPowerControlTestCase::MoveUe,
518 Simulator::Schedule(MilliSeconds(1400),
519 &NrUplinkPowerControlTestCase::MoveUe,
524 Simulator::Schedule(MilliSeconds(1600),
525 &NrUplinkPowerControlTestCase::MoveUe,
530 Simulator::Schedule(MilliSeconds(1800),
531 &NrUplinkPowerControlTestCase::MoveUe,
536 Simulator::Schedule(MilliSeconds(2000),
537 &NrUplinkPowerControlTestCase::MoveUe,
549 if (m_accumulatedMode)
551 Simulator::Schedule(MilliSeconds(0),
552 &NrUplinkPowerControlTestCase::MoveUe,
557 Simulator::Schedule(MilliSeconds(200),
558 &NrUplinkPowerControlTestCase::MoveUe,
563 Simulator::Schedule(MilliSeconds(400),
564 &NrUplinkPowerControlTestCase::MoveUe,
569 Simulator::Schedule(MilliSeconds(600),
570 &NrUplinkPowerControlTestCase::MoveUe,
575 Simulator::Schedule(MilliSeconds(800),
576 &NrUplinkPowerControlTestCase::MoveUe,
581 Simulator::Schedule(MilliSeconds(1000),
582 &NrUplinkPowerControlTestCase::MoveUe,
587 Simulator::Schedule(MilliSeconds(1200),
588 &NrUplinkPowerControlTestCase::MoveUe,
593 Simulator::Schedule(MilliSeconds(1400),
594 &NrUplinkPowerControlTestCase::MoveUe,
599 Simulator::Schedule(MilliSeconds(1600),
600 &NrUplinkPowerControlTestCase::MoveUe,
605 Simulator::Schedule(MilliSeconds(1800),
606 &NrUplinkPowerControlTestCase::MoveUe,
611 Simulator::Schedule(MilliSeconds(2000),
612 &NrUplinkPowerControlTestCase::MoveUe,
620 Simulator::Schedule(MilliSeconds(0),
621 &NrUplinkPowerControlTestCase::MoveUe,
626 Simulator::Schedule(MilliSeconds(200),
627 &NrUplinkPowerControlTestCase::MoveUe,
632 Simulator::Schedule(MilliSeconds(400),
633 &NrUplinkPowerControlTestCase::MoveUe,
638 Simulator::Schedule(MilliSeconds(600),
639 &NrUplinkPowerControlTestCase::MoveUe,
644 Simulator::Schedule(MilliSeconds(800),
645 &NrUplinkPowerControlTestCase::MoveUe,
650 Simulator::Schedule(MilliSeconds(1000),
651 &NrUplinkPowerControlTestCase::MoveUe,
656 Simulator::Schedule(MilliSeconds(1200),
657 &NrUplinkPowerControlTestCase::MoveUe,
662 Simulator::Schedule(MilliSeconds(1400),
663 &NrUplinkPowerControlTestCase::MoveUe,
668 Simulator::Schedule(MilliSeconds(1600),
669 &NrUplinkPowerControlTestCase::MoveUe,
674 Simulator::Schedule(MilliSeconds(1800),
675 &NrUplinkPowerControlTestCase::MoveUe,
680 Simulator::Schedule(MilliSeconds(2000),
681 &NrUplinkPowerControlTestCase::MoveUe,
689 Simulator::Stop(simTime);
692 Simulator::Destroy();
Manages the correct creation of operation bands, component carriers and bandwidth parts.
OperationBandInfo CreateOperationBandContiguousCc(const SimpleOperationBandConf &conf)
Create an operation band with the CC specified.
static BandwidthPartInfoPtrVector GetAllBwps(const std::vector< std::reference_wrapper< OperationBandInfo > > &operationBands)
Get all the BWP pointers from the specified vector of operation bands.
@ INIT_PROPAGATION
Initialize the propagation loss model.
This class contains the specification of EPS Bearers.
@ GBR_CONV_VIDEO
GBR Conversational Video (Live streaming)
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Direction direction
Whether the filter needs to be applied to uplink / downlink only, or in both cases.
uint16_t remotePortEnd
end of the port number range of the remote host
uint16_t localPortStart
start of the port number range of the UE
uint16_t remotePortStart
start of the port number range of the remote host
uint16_t localPortEnd
end of the port number range of the UE
Operation band information structure.