5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-scheduler-cqi-management.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#define NS_LOG_APPEND_CONTEXT \
6 if (m_getCellId) \
7 { \
8 std::clog << " [ CellId " << GetCellId() << ", bwpId " << GetBwpId() << "] "; \
9 }
10#include "nr-mac-scheduler-cqi-management.h"
11
12#include "nr-amc.h"
13
14#include <ns3/log.h>
15#include <ns3/nr-spectrum-value-helper.h>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("NrMacSchedulerCQIManagement");
21
22void
24 [[maybe_unused]] const DlCqiInfo& info,
25 [[maybe_unused]] const std::shared_ptr<NrMacSchedulerUeInfo>& ueInfo) const
26{
27 NS_LOG_FUNCTION(this);
28 // TODO
29 NS_ABORT_MSG("SB CQI Type is not supported");
30}
31
32void
34 uint32_t expirationTime,
35 [[maybe_unused]] uint32_t tbs,
37 const std::shared_ptr<NrMacSchedulerUeInfo>& ueInfo,
38 const std::vector<uint8_t>& rbgMask,
39 uint32_t numRbPerRbg,
40 const Ptr<const SpectrumModel>& model) const
41{
42 NS_LOG_FUNCTION(this);
43 NS_ASSERT(!rbgMask.empty());
44
45 NS_LOG_INFO("Computing SB CQI for UE " << ueInfo->m_rnti);
46
47 ueInfo->m_ulCqi.m_sinr = params.m_ulCqi.m_sinr;
48 ueInfo->m_ulCqi.m_cqiType = NrMacSchedulerUeInfo::CqiInfo::SB;
49 ueInfo->m_ulCqi.m_timer = expirationTime;
50
51 std::vector<int> rbAssignment(params.m_ulCqi.m_sinr.size(), 0);
52
53 for (uint32_t i = 0; i < rbgMask.size(); ++i)
54 {
55 if (rbgMask.at(i) == 1)
56 {
57 for (uint32_t k = 0; k < numRbPerRbg; ++k)
58 {
59 rbAssignment[i * numRbPerRbg + k] = 1;
60 }
61 }
62 }
63
64 SpectrumValue specVals(model);
65 Values::iterator specIt = specVals.ValuesBegin();
66
67 std::stringstream out;
68
69 for (uint32_t ichunk = 0; ichunk < model->GetNumBands(); ichunk++)
70 {
71 NS_ASSERT(specIt != specVals.ValuesEnd());
72 if (rbAssignment[ichunk] == 1)
73 {
74 *specIt = ueInfo->m_ulCqi.m_sinr.at(ichunk);
75 out << ueInfo->m_ulCqi.m_sinr.at(ichunk) << " ";
76 }
77 else
78 {
79 out << "0.0 ";
80 *specIt = 0.0;
81 }
82
83 specIt++;
84 }
85
86 NS_LOG_INFO("Values of SINR to pass to the AMC: " << out.str());
87
88 // MCS updated inside the function; crappy API... but we can't fix everything
89 ueInfo->m_ulCqi.m_wbCqi = GetAmcUl()->CreateCqiFeedbackWbTdma(specVals, ueInfo->m_ulMcs);
90 NS_LOG_DEBUG("Calculated MCS for RNTI " << ueInfo->m_rnti << " is " << ueInfo->m_ulMcs);
91}
92
93void
94NrMacSchedulerCQIManagement::InstallGetBwpIdFn(const std::function<uint16_t()>& fn)
95{
96 NS_LOG_FUNCTION(this);
97 m_getBwpId = fn;
98}
99
100void
101NrMacSchedulerCQIManagement::InstallGetCellIdFn(const std::function<uint16_t()>& fn)
102{
103 NS_LOG_FUNCTION(this);
104 m_getCellId = fn;
105}
106
107void
108NrMacSchedulerCQIManagement::InstallGetStartMcsDlFn(const std::function<uint8_t()>& fn)
109{
110 NS_LOG_FUNCTION(this);
111 m_getStartMcsDl = fn;
112}
113
114void
115NrMacSchedulerCQIManagement::InstallGetStartMcsUlFn(const std::function<uint8_t()>& fn)
116{
117 NS_LOG_FUNCTION(this);
118 m_getStartMcsUl = fn;
119}
120
121void
122NrMacSchedulerCQIManagement::InstallGetNrAmcDlFn(const std::function<Ptr<const NrAmc>()>& fn)
123{
124 NS_LOG_FUNCTION(this);
125 m_getAmcDl = fn;
126}
127
128void
129NrMacSchedulerCQIManagement::InstallGetNrAmcUlFn(const std::function<Ptr<const NrAmc>()>& fn)
130{
131 NS_LOG_FUNCTION(this);
132 m_getAmcUl = fn;
133}
134
135void
137 const std::shared_ptr<NrMacSchedulerUeInfo>& ueInfo,
138 uint32_t expirationTime,
139 int8_t maxDlMcs) const
140{
141 NS_LOG_FUNCTION(this);
142
143 ueInfo->m_dlCqi.m_cqiType = NrMacSchedulerUeInfo::CqiInfo::WB;
144 ueInfo->m_dlCqi.m_wbCqi = info.m_wbCqi;
145 ueInfo->m_dlCqi.m_timer = expirationTime;
146 ueInfo->m_dlCqi.m_wbCqi = info.m_wbCqi;
147 ueInfo->m_dlMcs =
148 std::min(static_cast<uint8_t>(GetAmcDl()->GetMcsFromCqi(ueInfo->m_dlCqi.m_wbCqi)),
149 static_cast<uint8_t>(maxDlMcs));
150 NS_LOG_INFO("Calculated MCS for UE " << ueInfo->m_rnti << " is "
151 << static_cast<uint32_t>(ueInfo->m_dlMcs));
152
153 NS_LOG_INFO("Updated WB CQI of UE "
154 << ueInfo->m_rnti << " to " << static_cast<uint32_t>(ueInfo->m_dlCqi.m_wbCqi)
155 << ". It will expire in " << ueInfo->m_dlCqi.m_timer << " slots.");
156
157 if (info.m_optPrecMat)
158 {
159 // Set the number of layers (rank) directly to m_ri (do not decode m_ri)
160 NS_ASSERT(info.m_ri > 0);
161 ueInfo->m_dlRank = info.m_ri;
162
163 // Set the precoding matrix
164 ueInfo->m_dlPrecMats = info.m_optPrecMat;
165 }
166}
167
168void
170 const std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>& ueMap) const
171{
172 NS_LOG_FUNCTION(this);
173
174 for (const auto& itUe : ueMap)
175 {
176 const std::shared_ptr<NrMacSchedulerUeInfo>& ue = itUe.second;
177
178 if (ue->m_dlCqi.m_timer == 0)
179 {
180 ue->m_dlCqi.m_wbCqi = 1; // lowest value for trying a transmission
181 ue->m_dlCqi.m_cqiType = NrMacSchedulerUeInfo::CqiInfo::WB;
182 ue->m_dlMcs = GetStartMcsDl();
183 }
184 else
185 {
186 ue->m_dlCqi.m_timer -= 1;
187 }
188 }
189}
190
191void
193 const std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>& ueMap) const
194{
195 NS_LOG_FUNCTION(this);
196
197 for (const auto& itUe : ueMap)
198 {
199 const std::shared_ptr<NrMacSchedulerUeInfo>& ue = itUe.second;
200
201 if (ue->m_ulCqi.m_timer == 0)
202 {
203 ue->m_ulCqi.m_wbCqi = 1; // lowest value for trying a transmission
204 ue->m_ulCqi.m_cqiType = NrMacSchedulerUeInfo::CqiInfo::WB;
205 ue->m_ulMcs = GetStartMcsUl();
206 }
207 else
208 {
209 ue->m_ulCqi.m_timer -= 1;
210 }
211 }
212}
213
214uint16_t
215NrMacSchedulerCQIManagement::GetBwpId() const
216{
217 return m_getBwpId();
218}
219
220uint16_t
221NrMacSchedulerCQIManagement::GetCellId() const
222{
223 return m_getCellId();
224}
225
226uint8_t
227NrMacSchedulerCQIManagement::GetStartMcsDl() const
228{
229 return m_getStartMcsDl();
230}
231
232uint8_t
233NrMacSchedulerCQIManagement::GetStartMcsUl() const
234{
235 return m_getStartMcsUl();
236}
237
238Ptr<const NrAmc>
239NrMacSchedulerCQIManagement::GetAmcDl() const
240{
241 return m_getAmcDl();
242}
243
244Ptr<const NrAmc>
245NrMacSchedulerCQIManagement::GetAmcUl() const
246{
247 return m_getAmcUl();
248}
249
250} // namespace ns3
void RefreshUlCqiMaps(const std::unordered_map< uint16_t, std::shared_ptr< NrMacSchedulerUeInfo > > &m_ueMap) const
Refresh the UL CQI for all the UE.
void InstallGetCellIdFn(const std::function< uint16_t()> &fn)
Install a function to retrieve the cell id.
void RefreshDlCqiMaps(const std::unordered_map< uint16_t, std::shared_ptr< NrMacSchedulerUeInfo > > &m_ueMap) const
Refresh the DL CQI for all the UE.
void UlSBCQIReported(uint32_t expirationTime, uint32_t tbs, const NrMacSchedSapProvider::SchedUlCqiInfoReqParameters &params, const std::shared_ptr< NrMacSchedulerUeInfo > &ueInfo, const std::vector< uint8_t > &rbgMask, uint32_t numRbPerRbg, const Ptr< const SpectrumModel > &model) const
An UL SB CQI has been reported for the specified UE.
void InstallGetBwpIdFn(const std::function< uint16_t()> &fn)
Install a function to retrieve the bwp id.
void DlSBCQIReported(const DlCqiInfo &info, const std::shared_ptr< NrMacSchedulerUeInfo > &ueInfo) const
SB CQI reported.
void DlWBCQIReported(const DlCqiInfo &info, const std::shared_ptr< NrMacSchedulerUeInfo > &ueInfo, uint32_t expirationTime, int8_t maxDlMcs) const
A wideband CQI has been reported for the specified UE.
The DlCqiInfo struct.
Ptr< const ComplexMatrixArray > m_optPrecMat
Precoding matrix for each RB.
uint8_t m_wbCqi
Wideband CQI.
uint8_t m_ri
the rank indicator, or simply the rank number
enum ns3::NrMacSchedulerUeInfo::CqiInfo::CqiType WB
CQI type.