5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
ideal-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 "ideal-beamforming-helper.h"
6
7#include <ns3/ideal-beamforming-algorithm.h>
8#include <ns3/log.h>
9#include <ns3/nr-gnb-net-device.h>
10#include <ns3/nr-gnb-phy.h>
11#include <ns3/nr-spectrum-phy.h>
12#include <ns3/nr-ue-net-device.h>
13#include <ns3/nr-ue-phy.h>
14#include <ns3/object-factory.h>
15#include <ns3/vector.h>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("IdealBeamformingHelper");
21NS_OBJECT_ENSURE_REGISTERED(IdealBeamformingHelper);
22
24{
25 NS_LOG_FUNCTION(this);
26}
27
29{
30 NS_LOG_FUNCTION(this);
31 m_beamformingAlgorithm = nullptr;
32}
33
34void
35IdealBeamformingHelper::DoInitialize()
36{
37 m_beamformingTimer = Simulator::Schedule(m_beamformingPeriodicity,
39 this);
40 BeamformingHelperBase::DoInitialize();
41}
42
43TypeId
45{
46 static TypeId tid =
47 TypeId("ns3::IdealBeamformingHelper")
48 .SetParent<BeamformingHelperBase>()
49 .AddConstructor<IdealBeamformingHelper>()
50 .AddAttribute("BeamformingMethod",
51 "Type of the ideal beamforming method in the case that it is enabled, by "
52 "default is \"cell scan\" method.",
53 TypeIdValue(CellScanBeamforming::GetTypeId()),
55 MakeTypeIdChecker())
56 .AddAttribute("BeamformingPeriodicity",
57 "Interval between consecutive beamforming method executions. If set to 0 "
58 "it will not be updated.",
59 TimeValue(MilliSeconds(100)),
62 MakeTimeChecker());
63 return tid;
64}
65
66void
67IdealBeamformingHelper::AddBeamformingTask(const Ptr<NrGnbNetDevice>& gnbDev,
68 const Ptr<NrUeNetDevice>& ueDev)
69{
70 NS_LOG_FUNCTION(this);
71
73 {
75 }
76
77 for (std::size_t ccId = 0; ccId < gnbDev->GetCcMapSize(); ccId++)
78 {
79 Ptr<NrSpectrumPhy> gnbSpectrumPhy = gnbDev->GetPhy(ccId)->GetSpectrumPhy();
80 Ptr<NrSpectrumPhy> ueSpectrumPhy = ueDev->GetPhy(ccId)->GetSpectrumPhy();
81
82 m_spectrumPhyPair.emplace_back(gnbSpectrumPhy, ueSpectrumPhy);
83 RunTask(gnbSpectrumPhy, ueSpectrumPhy);
84 }
85}
86
87void
89{
90 NS_LOG_FUNCTION(this);
91 NS_LOG_INFO("Running the beamforming method. There are :" << m_spectrumPhyPair.size()
92 << " tasks.");
93
94 for (const auto& task : m_spectrumPhyPair)
95 {
96 RunTask(task.first, task.second);
97 }
98}
99
100BeamformingVectorPair
101IdealBeamformingHelper::GetBeamformingVectors(const Ptr<NrSpectrumPhy>& gnbSpectrumPhy,
102 const Ptr<NrSpectrumPhy>& ueSpectrumPhy) const
103{
104 NS_LOG_FUNCTION(this);
105 return m_beamformingAlgorithm->GetBeamformingVectors(gnbSpectrumPhy, ueSpectrumPhy);
106}
107
108void
109IdealBeamformingHelper::SetBeamformingMethod(const TypeId& beamformingMethod)
110{
111 NS_LOG_FUNCTION(this);
112 NS_ASSERT(beamformingMethod.IsChildOf(IdealBeamformingAlgorithm::GetTypeId()));
113 m_algorithmFactory.SetTypeId(beamformingMethod);
114}
115
116void
118{
119 NS_LOG_FUNCTION(this);
120 NS_LOG_INFO("Beamforming timer expired; programming a beamforming");
121
122 Run(); // Run beamforming tasks
123 m_beamformingTimer.Cancel(); // Cancel any previous beamforming event
124 m_beamformingTimer = Simulator::Schedule(m_beamformingPeriodicity,
126 this);
127}
128
129void
131{
132 NS_LOG_FUNCTION(this);
133 NS_ABORT_MSG_IF(v == MilliSeconds(0), "Periodicity must be greater than 0 ms.");
135}
136
137Time
139{
140 NS_LOG_FUNCTION(this);
142}
143
144} // 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,...
static TypeId GetTypeId()
Get the type id.
Generate "Ideal" beamforming vectors.
static TypeId GetTypeId()
Get the type id.
virtual void ExpireBeamformingTimer()
The beamforming timer has expired; at the next slot, perform beamforming.
virtual void Run() const
Run beamforming task.
static TypeId GetTypeId()
Get the Type ID.
IdealBeamformingHelper()
IdealBeamformingHelper.
std::list< SpectrumPhyPair > m_spectrumPhyPair
The list of beamforming tasks to be executed.
Ptr< IdealBeamformingAlgorithm > m_beamformingAlgorithm
The beamforming algorithm that will be used.
void SetPeriodicity(const Time &v)
SetIdealBeamformingPeriodicity.
void AddBeamformingTask(const Ptr< NrGnbNetDevice > &gNbDev, const Ptr< NrUeNetDevice > &ueDev) override
Specify among which devices the beamforming algorithm should be performed.
BeamformingVectorPair GetBeamformingVectors(const Ptr< NrSpectrumPhy > &gnbSpectrumPhy, const Ptr< NrSpectrumPhy > &ueSpectrumPhy) const override
Function that will call the configured algorithm for the specified devices and obtain the beamforming...
~IdealBeamformingHelper() override
~IdealBeamformingHelper
void SetBeamformingMethod(const TypeId &beamformingMethod) override
SetBeamformingMethod.
Time GetPeriodicity() const
GetIdealBeamformingPeriodicity.