5#include "ns3/antenna-module.h"
6#include "ns3/core-module.h"
7#include "ns3/mobility-module.h"
8#include "ns3/nr-module.h"
9#include "ns3/spectrum-model.h"
10#include "ns3/three-gpp-channel-model.h"
11#include "ns3/three-gpp-propagation-loss-model.h"
12#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
17NS_LOG_COMPONENT_DEFINE(
"NrRealisticBeamformingTest");
40class NrRealisticBeamformingTestSuite :
public TestSuite
43 NrRealisticBeamformingTestSuite();
46class NrRealisticBeamformingTestCase :
public TestCase
49 NrRealisticBeamformingTestCase(std::string name, Duration duration);
50 ~NrRealisticBeamformingTestCase()
override;
53 void DoRun()
override;
55 Duration m_testDuration;
61NrRealisticBeamformingTestSuite::NrRealisticBeamformingTestSuite()
62 : TestSuite(
"nr-realistic-beamforming-test", Type::SYSTEM)
64 NS_LOG_INFO(
"Creating NrRealisticBeamformingTestSuite");
66 auto durationQuick = Duration::QUICK;
67 auto durationExtensive = Duration::EXTENSIVE;
70 new NrRealisticBeamformingTestCase(
"RealisticBeamforming basic test case", durationQuick),
72 AddTestCase(
new NrRealisticBeamformingTestCase(
"RealisticBeamforming basic test case",
81NrRealisticBeamformingTestCase::NrRealisticBeamformingTestCase(std::string name, Duration duration)
84 m_testDuration = duration;
87NrRealisticBeamformingTestCase::~NrRealisticBeamformingTestCase()
92NrRealisticBeamformingTestCase::DoRun()
94 RngSeedManager::SetSeed(1);
96 std::list<Vector> uePositionsExtensive = {Vector(10, -10, 1.5),
100 uint16_t totalCounter = 0;
101 uint16_t highSinrCounter = 0;
102 uint16_t lowSinrCounter = 0;
104 std::list<uint16_t> rngList = (m_testDuration == Duration::EXTENSIVE)
105 ? std::list<uint16_t>({2, 3})
106 : std::list<uint16_t>({1});
108 std::list<Vector> uePositions =
109 (m_testDuration == Duration::EXTENSIVE)
110 ? uePositionsExtensive
111 : std::list<Vector>({Vector(10, 10, 1.5), Vector(-10, 10, 1.5)});
113 std::list<uint16_t> antennaConfList = (m_testDuration == Duration::EXTENSIVE)
114 ? std::list<uint16_t>({3, 4})
115 : std::list<uint16_t>({2});
117 for (
auto rng : rngList)
119 RngSeedManager::SetRun(rng);
121 for (
const auto& pos : uePositions)
123 for (
const auto& antennaConf : antennaConfList)
125 for (
auto iso : {
false,
true})
129 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
130 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
131 channelHelper->ConfigureFactories(
"UMa",
"LOS");
132 channelHelper->SetPathlossAttribute(
"ShadowingEnabled", BooleanValue(
false));
134 NodeContainer gnbNodes;
135 NodeContainer ueNodes;
138 NodeContainer allNodes = NodeContainer(gnbNodes, ueNodes);
141 Ptr<ListPositionAllocator> positionAlloc =
142 CreateObject<ListPositionAllocator>();
143 positionAlloc->Add(Vector(0, 0.0, 10));
144 positionAlloc->Add(pos);
146 MobilityHelper mobility;
147 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
148 mobility.SetPositionAllocator(positionAlloc);
149 mobility.Install(allNodes);
152 NetDeviceContainer gnbDevs;
153 NetDeviceContainer ueDevs;
155 CcBwpCreator::SimpleOperationBandConf bandConf(29e9, 100e6, 1);
156 CcBwpCreator ccBwpCreator;
157 OperationBandInfo band = ccBwpCreator.CreateOperationBandContiguousCc(bandConf);
159 channelHelper->AssignChannelsToBands({band});
164 nrHelper->SetGnbAntennaAttribute(
"NumRows", UintegerValue(antennaConf));
165 nrHelper->SetGnbAntennaAttribute(
"NumColumns", UintegerValue(antennaConf));
168 nrHelper->SetUeAntennaAttribute(
"NumRows", UintegerValue(antennaConf));
169 nrHelper->SetUeAntennaAttribute(
"NumColumns", UintegerValue(antennaConf));
174 nrHelper->SetGnbAntennaAttribute(
176 PointerValue(CreateObject<IsotropicAntennaModel>()));
177 nrHelper->SetUeAntennaAttribute(
179 PointerValue(CreateObject<IsotropicAntennaModel>()));
183 nrHelper->SetGnbAntennaAttribute(
185 PointerValue(CreateObject<ThreeGppAntennaModel>()));
186 nrHelper->SetUeAntennaAttribute(
188 PointerValue(CreateObject<ThreeGppAntennaModel>()));
191 nrHelper->SetGnbBeamManagerTypeId(RealisticBfManager::GetTypeId());
193 gnbDevs = nrHelper->InstallGnbDevice(gnbNodes, allBwps);
194 ueDevs = nrHelper->InstallUeDevice(ueNodes, allBwps);
201 for (
auto it = gnbDevs.Begin(); it != gnbDevs.End(); ++it)
203 DynamicCast<NrGnbNetDevice>(*it)->ConfigureCell();
206 Ptr<NrUePhy> uePhy = nrHelper->GetUePhy(ueDevs.Get(0), 0);
208 Ptr<NrSpectrumPhy> txSpectrumPhy =
209 nrHelper->GetGnbPhy(gnbDevs.Get(0), 0)->GetSpectrumPhy();
210 Ptr<SpectrumChannel> txSpectrumChannel = txSpectrumPhy->GetSpectrumChannel();
211 Ptr<ThreeGppPropagationLossModel> propagationLossModel =
212 DynamicCast<ThreeGppPropagationLossModel>(
213 txSpectrumChannel->GetPropagationLossModel());
214 NS_ASSERT(propagationLossModel !=
nullptr);
215 propagationLossModel->AssignStreams(1);
216 Ptr<ChannelConditionModel> channelConditionModel =
217 propagationLossModel->GetChannelConditionModel();
218 channelConditionModel->AssignStreams(1);
219 Ptr<ThreeGppSpectrumPropagationLossModel> spectrumLossModel =
220 DynamicCast<ThreeGppSpectrumPropagationLossModel>(
221 txSpectrumChannel->GetPhasedArraySpectrumPropagationLossModel());
222 NS_ASSERT(spectrumLossModel !=
nullptr);
223 Ptr<ThreeGppChannelModel> channel =
224 DynamicCast<ThreeGppChannelModel>(spectrumLossModel->GetChannelModel());
225 channel->AssignStreams(1);
227 double sinrSrsHighLineal = std::pow(10.0, 0.1 * 40);
228 double sinrSrsLowLineal = std::pow(10.0, 0.1 * (-10));
230 Ptr<CellScanBeamforming> cellScanBeamforming =
231 CreateObject<CellScanBeamforming>();
233 BeamformingVectorPair bfPairIdeal =
234 cellScanBeamforming->GetBeamformingVectors(txSpectrumPhy,
235 uePhy->GetSpectrumPhy());
237 Ptr<RealisticBeamformingAlgorithm> realisticBeamforming =
238 CreateObject<RealisticBeamformingAlgorithm>();
239 realisticBeamforming->Install(
241 uePhy->GetSpectrumPhy(),
242 DynamicCast<NrGnbNetDevice>(gnbDevs.Get(0))->GetScheduler(0));
246 realisticBeamforming->m_maxSrsSinrPerSlot = sinrSrsHighLineal;
248 BeamformingVectorPair bfPairReal1 =
249 realisticBeamforming->GetBeamformingVectors();
253 realisticBeamforming->m_maxSrsSinrPerSlot = sinrSrsLowLineal;
255 BeamformingVectorPair bfPairReal2 =
256 realisticBeamforming->GetBeamformingVectors();
258 if ((bfPairIdeal.first.second == bfPairReal1.first.second) &&
259 (bfPairIdeal.second.second == bfPairReal1.second.second))
264 if (!((bfPairIdeal.first.second == bfPairReal2.first.second) &&
265 (bfPairIdeal.second.second == bfPairReal2.second.second)))
274 double tolerance = 0.21;
275 if (m_testDuration == Duration::EXTENSIVE)
287 NS_TEST_ASSERT_MSG_EQ_TOL(highSinrCounter / (
double)totalCounter,
290 "The pair of beamforming vectors should be equal in most of the "
291 "cases when SINR is high, and they are not");
292 NS_TEST_ASSERT_MSG_EQ_TOL(lowSinrCounter / (
double)totalCounter,
295 "The pair of beamforming vectors should not be equal in most of the "
296 "cases when SINR is low, and they are");
298 NS_LOG_INFO(
"The result is as expected when high SINR in " << highSinrCounter <<
" out of "
299 << totalCounter <<
" total cases.");
300 NS_LOG_INFO(
"The result is as expected when low SINR in " << lowSinrCounter <<
" out of "
301 << totalCounter <<
" total cases.");
303 Simulator::Destroy();
307static NrRealisticBeamformingTestSuite nrTestSuite;
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo