5G-LENA nr-v3.0-33-g7aea1e4
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
ideal-beamforming-helper.cc
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "ideal-beamforming-helper.h"
8
9#include <ns3/ideal-beamforming-algorithm.h>
10#include <ns3/log.h>
11#include <ns3/nr-gnb-net-device.h>
12#include <ns3/nr-gnb-phy.h>
13#include <ns3/nr-spectrum-phy.h>
14#include <ns3/nr-ue-net-device.h>
15#include <ns3/nr-ue-phy.h>
16#include <ns3/object-factory.h>
17#include <ns3/vector.h>
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("IdealBeamformingHelper");
23NS_OBJECT_ENSURE_REGISTERED(IdealBeamformingHelper);
24
26{
27 NS_LOG_FUNCTION(this);
28}
29
31{
32 NS_LOG_FUNCTION(this);
33 m_beamformingAlgorithm = nullptr;
34}
35
36void
37IdealBeamformingHelper::DoInitialize()
38{
39 m_beamformingTimer = Simulator::Schedule(m_beamformingPeriodicity,
41 this);
42 BeamformingHelperBase::DoInitialize();
43}
44
45TypeId
47{
48 static TypeId tid =
49 TypeId("ns3::IdealBeamformingHelper")
50 .SetParent<BeamformingHelperBase>()
51 .AddConstructor<IdealBeamformingHelper>()
52 .AddAttribute("BeamformingMethod",
53 "Type of the ideal beamforming method in the case that it is enabled, by "
54 "default is \"cell scan\" method.",
55 TypeIdValue(CellScanBeamforming::GetTypeId()),
57 MakeTypeIdChecker())
58 .AddAttribute("BeamformingPeriodicity",
59 "Interval between consecutive beamforming method executions. If set to 0 "
60 "it will not be updated.",
61 TimeValue(MilliSeconds(100)),
64 MakeTimeChecker());
65 return tid;
66}
67
68void
69IdealBeamformingHelper::AddBeamformingTask(const Ptr<NrGnbNetDevice>& gnbDev,
70 const Ptr<NrUeNetDevice>& ueDev)
71{
72 NS_LOG_FUNCTION(this);
73
75 {
77 }
78
79 for (std::size_t ccId = 0; ccId < gnbDev->GetCcMapSize(); ccId++)
80 {
81 Ptr<NrSpectrumPhy> gnbSpectrumPhy = gnbDev->GetPhy(ccId)->GetSpectrumPhy();
82 Ptr<NrSpectrumPhy> ueSpectrumPhy = ueDev->GetPhy(ccId)->GetSpectrumPhy();
83
84 m_spectrumPhyPair.emplace_back(gnbSpectrumPhy, ueSpectrumPhy);
85 RunTask(gnbSpectrumPhy, ueSpectrumPhy);
86 }
87}
88
89void
91{
92 NS_LOG_FUNCTION(this);
93 NS_LOG_INFO("Running the beamforming method. There are :" << m_spectrumPhyPair.size()
94 << " tasks.");
95
96 for (const auto& task : m_spectrumPhyPair)
97 {
98 RunTask(task.first, task.second);
99 }
100}
101
102BeamformingVectorPair
103IdealBeamformingHelper::GetBeamformingVectors(const Ptr<NrSpectrumPhy>& gnbSpectrumPhy,
104 const Ptr<NrSpectrumPhy>& ueSpectrumPhy) const
105{
106 NS_LOG_FUNCTION(this);
107 return m_beamformingAlgorithm->GetBeamformingVectors(gnbSpectrumPhy, ueSpectrumPhy);
108}
109
110void
111IdealBeamformingHelper::SetBeamformingMethod(const TypeId& beamformingMethod)
112{
113 NS_LOG_FUNCTION(this);
114 NS_ASSERT(beamformingMethod.IsChildOf(IdealBeamformingAlgorithm::GetTypeId()));
115 m_algorithmFactory.SetTypeId(beamformingMethod);
116}
117
118void
120{
121 NS_LOG_FUNCTION(this);
122 NS_LOG_INFO("Beamforming timer expired; programming a beamforming");
123
124 Run(); // Run beamforming tasks
125 m_beamformingTimer.Cancel(); // Cancel any previous beamforming event
126 m_beamformingTimer = Simulator::Schedule(m_beamformingPeriodicity,
128 this);
129}
130
131void
133{
134 NS_LOG_FUNCTION(this);
135 NS_ABORT_MSG_IF(v == MilliSeconds(0), "Periodicity must be greater than 0 ms.");
137}
138
139Time
141{
142 NS_LOG_FUNCTION(this);
144}
145
146} // 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.