5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-realistic-beamforming-test.cc
Go to the documentation of this file.
1// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
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>
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("NrRealisticBeamformingTest");
18
40class NrRealisticBeamformingTestSuite : public TestSuite
41{
42 public:
43 NrRealisticBeamformingTestSuite();
44};
45
46class NrRealisticBeamformingTestCase : public TestCase
47{
48 public:
49 NrRealisticBeamformingTestCase(std::string name, Duration duration);
50 ~NrRealisticBeamformingTestCase() override;
51
52 private:
53 void DoRun() override;
54
55 Duration m_testDuration;
56};
57
61NrRealisticBeamformingTestSuite::NrRealisticBeamformingTestSuite()
62 : TestSuite("nr-realistic-beamforming-test", Type::SYSTEM)
63{
64 NS_LOG_INFO("Creating NrRealisticBeamformingTestSuite");
65
66 auto durationQuick = Duration::QUICK;
67 auto durationExtensive = Duration::EXTENSIVE;
68
69 AddTestCase(
70 new NrRealisticBeamformingTestCase("RealisticBeamforming basic test case", durationQuick),
71 durationQuick);
72 AddTestCase(new NrRealisticBeamformingTestCase("RealisticBeamforming basic test case",
73 durationExtensive),
74 durationExtensive);
75}
76
81NrRealisticBeamformingTestCase::NrRealisticBeamformingTestCase(std::string name, Duration duration)
82 : TestCase(name)
83{
84 m_testDuration = duration;
85}
86
87NrRealisticBeamformingTestCase::~NrRealisticBeamformingTestCase()
88{
89}
90
91void
92NrRealisticBeamformingTestCase::DoRun()
93{
94 RngSeedManager::SetSeed(1);
95
96 std::list<Vector> uePositionsExtensive = {Vector(10, -10, 1.5),
97 Vector(0, 10, 1.5),
98 Vector(0, -10, 1.5)};
99
100 uint16_t totalCounter = 0;
101 uint16_t highSinrCounter = 0;
102 uint16_t lowSinrCounter = 0;
103
104 std::list<uint16_t> rngList = (m_testDuration == Duration::EXTENSIVE)
105 ? std::list<uint16_t>({2, 3})
106 : std::list<uint16_t>({1});
107
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)});
112
113 std::list<uint16_t> antennaConfList = (m_testDuration == Duration::EXTENSIVE)
114 ? std::list<uint16_t>({3, 4})
115 : std::list<uint16_t>({2});
116
117 for (auto rng : rngList)
118 {
119 RngSeedManager::SetRun(rng);
120
121 for (const auto& pos : uePositions)
122 {
123 for (const auto& antennaConf : antennaConfList)
124 {
125 for (auto iso : {false, true})
126 {
127 totalCounter++;
128
129 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
130 // Create Nodes: eNodeB and UE
131 NodeContainer gnbNodes;
132 NodeContainer ueNodes;
133 gnbNodes.Create(1);
134 ueNodes.Create(1);
135 NodeContainer allNodes = NodeContainer(gnbNodes, ueNodes);
136
137 // Install Mobility Model
138 Ptr<ListPositionAllocator> positionAlloc =
139 CreateObject<ListPositionAllocator>();
140 positionAlloc->Add(Vector(0, 0.0, 10)); // gNB
141 positionAlloc->Add(pos); // UE
142
143 MobilityHelper mobility;
144 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
145 mobility.SetPositionAllocator(positionAlloc);
146 mobility.Install(allNodes);
147
148 // Create Devices and install them in the Nodes (gNB and UE)
149 NetDeviceContainer gnbDevs;
150 NetDeviceContainer ueDevs;
151 nrHelper->SetPathlossAttribute("ShadowingEnabled", BooleanValue(false));
152
153 CcBwpCreator::SimpleOperationBandConf bandConf(29e9,
154 100e6,
155 1,
156 BandwidthPartInfo::UMa_LoS);
157 CcBwpCreator ccBwpCreator;
158 OperationBandInfo band = ccBwpCreator.CreateOperationBandContiguousCc(bandConf);
159 // Initialize channel and pathloss, plus other things inside band.
160 nrHelper->InitializeOperationBand(&band);
161 BandwidthPartInfoPtrVector allBwps = CcBwpCreator::GetAllBwps({band});
162
163 // Antennas for the gNbs
164 nrHelper->SetGnbAntennaAttribute("NumRows", UintegerValue(antennaConf));
165 nrHelper->SetGnbAntennaAttribute("NumColumns", UintegerValue(antennaConf));
166
167 // Antennas for the UEs
168 nrHelper->SetUeAntennaAttribute("NumRows", UintegerValue(antennaConf));
169 nrHelper->SetUeAntennaAttribute("NumColumns", UintegerValue(antennaConf));
170
171 // Antenna element type for both gNB and UE
172 if (iso)
173 {
174 nrHelper->SetGnbAntennaAttribute(
175 "AntennaElement",
176 PointerValue(CreateObject<IsotropicAntennaModel>()));
177 nrHelper->SetUeAntennaAttribute(
178 "AntennaElement",
179 PointerValue(CreateObject<IsotropicAntennaModel>()));
180 }
181 else
182 {
183 nrHelper->SetGnbAntennaAttribute(
184 "AntennaElement",
185 PointerValue(CreateObject<ThreeGppAntennaModel>()));
186 nrHelper->SetUeAntennaAttribute(
187 "AntennaElement",
188 PointerValue(CreateObject<ThreeGppAntennaModel>()));
189 }
190
191 nrHelper->SetGnbBeamManagerTypeId(RealisticBfManager::GetTypeId());
192
193 gnbDevs = nrHelper->InstallGnbDevice(gnbNodes, allBwps);
194 ueDevs = nrHelper->InstallUeDevice(ueNodes, allBwps);
195
196 for (auto it = gnbDevs.Begin(); it != gnbDevs.End(); ++it)
197 {
198 DynamicCast<NrGnbNetDevice>(*it)->UpdateConfig();
199 }
200
201 for (auto it = ueDevs.Begin(); it != ueDevs.End(); ++it)
202 {
203 DynamicCast<NrUeNetDevice>(*it)->UpdateConfig();
204 }
205
206 Ptr<NrUePhy> uePhy = nrHelper->GetUePhy(ueDevs.Get(0), 0);
207
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);
226
227 double sinrSrsHighLineal = std::pow(10.0, 0.1 * 40);
228 double sinrSrsLowLineal = std::pow(10.0, 0.1 * (-10));
229
230 Ptr<CellScanBeamforming> cellScanBeamforming =
231 CreateObject<CellScanBeamforming>();
232
233 BeamformingVectorPair bfPairIdeal =
234 cellScanBeamforming->GetBeamformingVectors(txSpectrumPhy,
235 uePhy->GetSpectrumPhy());
236
237 Ptr<RealisticBeamformingAlgorithm> realisticBeamforming =
238 CreateObject<RealisticBeamformingAlgorithm>();
239 realisticBeamforming->Install(
240 txSpectrumPhy,
241 uePhy->GetSpectrumPhy(),
242 DynamicCast<NrGnbNetDevice>(gnbDevs.Get(0))->GetScheduler(0));
243
244 // directly update max SINR SRS to a high value, skipping other set functions of
245 // the algorithm
246 realisticBeamforming->m_maxSrsSinrPerSlot = sinrSrsHighLineal;
247
248 BeamformingVectorPair bfPairReal1 =
249 realisticBeamforming->GetBeamformingVectors();
250
251 // directly update max SINR SRS to a new lower value, skipping other set
252 // functions of the algorithm,
253 realisticBeamforming->m_maxSrsSinrPerSlot = sinrSrsLowLineal;
254
255 BeamformingVectorPair bfPairReal2 =
256 realisticBeamforming->GetBeamformingVectors();
257
258 if ((bfPairIdeal.first.second == bfPairReal1.first.second) &&
259 (bfPairIdeal.second.second == bfPairReal1.second.second))
260 {
261 highSinrCounter++;
262 }
263
264 if (!((bfPairIdeal.first.second == bfPairReal2.first.second) &&
265 (bfPairIdeal.second.second == bfPairReal2.second.second)))
266 {
267 lowSinrCounter++;
268 }
269 }
270 }
271 }
272 }
273
274 double tolerance = 0.2;
275 if (m_testDuration == Duration::EXTENSIVE)
276 {
277 tolerance = 0.2;
278 }
279 else
280 {
281 tolerance =
282 0.3; // relax tolerance for QUICK mode since there are only 4 test configurations, e.g.,
283 // if 3 results of 4 are as expected that is already enough, but that gives 0.75
284 // thus it needs larger tolerance than 0.2 which is fine for EXTENSIVE mode
285 }
286
287 NS_TEST_ASSERT_MSG_EQ_TOL(highSinrCounter / (double)totalCounter,
288 1,
289 tolerance,
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,
293 1,
294 tolerance,
295 "The pair of beamforming vectors should not be equal in most of the "
296 "cases when SINR is low, and they are");
297
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.");
302
303 Simulator::Destroy();
304}
305
306// Do not forget to allocate an instance of this TestSuite
307static NrRealisticBeamformingTestSuite nrTestSuite;
308
309} // namespace ns3
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo