5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
realistic-beamforming-helper.cc
1// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "realistic-beamforming-helper.h"
6
7#include <ns3/log.h>
8#include <ns3/nr-gnb-net-device.h>
9#include <ns3/nr-gnb-phy.h>
10#include <ns3/nr-spectrum-phy.h>
11#include <ns3/nr-ue-net-device.h>
12#include <ns3/nr-ue-phy.h>
13#include <ns3/nr-ue-rrc.h>
14#include <ns3/vector.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("RealisticBeamformingHelper");
20NS_OBJECT_ENSURE_REGISTERED(RealisticBeamformingHelper);
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::RealisticBeamformingHelper")
26 .SetParent<BeamformingHelperBase>()
27 .AddConstructor<RealisticBeamformingHelper>();
28 return tid;
29}
30
31void
32RealisticBeamformingHelper::DoDispose()
33{
34 for (auto& it : m_spectrumPhyPairToAlgorithm)
35 {
36 it.second->Dispose();
37 }
38 m_spectrumPhyPairToAlgorithm.clear();
39}
40
41void
42RealisticBeamformingHelper::AddBeamformingTask(const Ptr<NrGnbNetDevice>& gNbDev,
43 const Ptr<NrUeNetDevice>& ueDev)
44{
45 NS_LOG_FUNCTION(this);
46 for (std::size_t ccId = 0; ccId < gNbDev->GetCcMapSize(); ccId++)
47 {
48 Ptr<NrSpectrumPhy> gnbSpectrumPhy = gNbDev->GetPhy(ccId)->GetSpectrumPhy();
49 Ptr<NrSpectrumPhy> ueSpectrumPhy = ueDev->GetPhy(ccId)->GetSpectrumPhy();
50
51 auto itAlgorithms =
52 m_spectrumPhyPairToAlgorithm.find(std::make_pair(gnbSpectrumPhy, ueSpectrumPhy));
53 NS_ABORT_MSG_IF(itAlgorithms != m_spectrumPhyPairToAlgorithm.end(),
54 "Realistic beamforming task already created for the provided devices");
55
56 // for each pair of antenna arrays of transmitter and receiver create an instance of
57 // beamforming algorithm
58 Ptr<RealisticBeamformingAlgorithm> beamformingAlgorithm =
60
61 beamformingAlgorithm->Install(gnbSpectrumPhy, ueSpectrumPhy, gNbDev->GetScheduler(ccId));
62
63 m_spectrumPhyPairToAlgorithm[std::make_pair(gnbSpectrumPhy, ueSpectrumPhy)] =
64 beamformingAlgorithm;
65 // connect trace of the corresponding gNB PHY to the RealisticBeamformingAlgorithm
66 // function
67 gnbSpectrumPhy->AddSrsSinrReportCallback(
69 beamformingAlgorithm));
70 gnbSpectrumPhy->AddSrsSnrReportCallback(
71 MakeCallback(&RealisticBeamformingAlgorithm::NotifySrsSnrReport, beamformingAlgorithm));
72 beamformingAlgorithm->SetTriggerCallback(
73 MakeCallback(&RealisticBeamformingHelper::RunTask, this));
74 }
75}
76
77BeamformingVectorPair
78RealisticBeamformingHelper::GetBeamformingVectors(const Ptr<NrSpectrumPhy>& gnbSpectrumPhy,
79 const Ptr<NrSpectrumPhy>& ueSpectrumPhy) const
80{
81 auto itAlgo = m_spectrumPhyPairToAlgorithm.find(std::make_pair(gnbSpectrumPhy, ueSpectrumPhy));
82 NS_ABORT_MSG_IF(itAlgo == m_spectrumPhyPairToAlgorithm.end(),
83 "There is no created task/algorithm for the specified pair of antenna arrays.");
84 return itAlgo->second->GetBeamformingVectors();
85}
86
87void
89{
90 NS_LOG_FUNCTION(this);
91 NS_ASSERT(beamformingMethod == RealisticBeamformingAlgorithm::GetTypeId() ||
92 beamformingMethod.IsChildOf(RealisticBeamformingAlgorithm::GetTypeId()));
93
94 m_algorithmFactory.SetTypeId(beamformingMethod);
95}
96
97} // namespace ns3
The BeamformingHelperBase class that is being used as the general interface for beamforming helper cl...
ObjectFactory m_algorithmFactory
Object factory that will be used to create beamforming algorithms.
virtual void RunTask(const Ptr< NrSpectrumPhy > &gnbSpectrumPhy, const Ptr< NrSpectrumPhy > &ueSpectrumPhy) const
This function runs the beamforming algorithm among the provided gNB and UE device,...
Generate "Real" beamforming vectors This class is inherited by all algorithms that do not assume the ...
void NotifySrsSnrReport(uint16_t cellId, uint16_t rnti, double srsSnr)
Saves SRS SNR report.
void NotifySrsSinrReport(uint16_t cellId, uint16_t rnti, double srsSinr)
Saves SRS SINR report.
void AddBeamformingTask(const Ptr< NrGnbNetDevice > &gNbDev, const Ptr< NrUeNetDevice > &ueDev) override
Adds the beamforming task to the list of tasks \gnbDev gNbDev pointer to gNB device \ueDev ueDev poin...
void SetBeamformingMethod(const TypeId &beamformingMethod) override
SetBeamformingMethod.
static TypeId GetTypeId()
Get the Type ID.