5#define NS_LOG_APPEND_CONTEXT \
8 std::clog << " [ CellId " << GetCellId() << ", bwpId " << GetBwpId() << "] "; \
10#include "nr-mac-scheduler-cqi-management.h"
15#include "ns3/nr-spectrum-value-helper.h"
20NS_LOG_COMPONENT_DEFINE(
"NrMacSchedulerCQIManagement");
24 uint32_t expirationTime,
25 [[maybe_unused]] uint32_t tbs,
27 const std::shared_ptr<NrMacSchedulerUeInfo>& ueInfo,
28 const std::vector<bool>& rbgMask,
30 const Ptr<const SpectrumModel>& model)
const
32 NS_LOG_FUNCTION(
this);
33 NS_ASSERT(!rbgMask.empty());
35 NS_LOG_INFO(
"Computing SB CQI for UE " << ueInfo->m_rnti);
37 ueInfo->m_ulCqi.m_sinr = params.
m_ulCqi.m_sinr;
39 ueInfo->m_ulCqi.m_timer = expirationTime;
41 std::vector<int> rbAssignment(params.
m_ulCqi.m_sinr.size(), 0);
43 for (uint32_t i = 0; i < rbgMask.size(); ++i)
45 if (rbgMask.at(i) == 1)
47 for (uint32_t k = 0; k < numRbPerRbg; ++k)
49 rbAssignment[i * numRbPerRbg + k] = 1;
54 SpectrumValue specVals(model);
55 Values::iterator specIt = specVals.ValuesBegin();
57 std::stringstream out;
59 for (uint32_t ichunk = 0; ichunk < model->GetNumBands(); ichunk++)
61 NS_ASSERT(specIt != specVals.ValuesEnd());
62 if (rbAssignment[ichunk] == 1)
64 *specIt = ueInfo->m_ulCqi.m_sinr.at(ichunk);
65 out << ueInfo->m_ulCqi.m_sinr.at(ichunk) <<
" ";
76 NS_LOG_INFO(
"Values of SINR to pass to the AMC: " << out.str());
79 ueInfo->m_ulCqi.m_wbCqi = GetAmcUl()->CreateCqiFeedbackWbTdma(specVals, ueInfo->m_ulMcs);
80 NS_LOG_DEBUG(
"Calculated MCS for RNTI " << ueInfo->m_rnti <<
" is " << ueInfo->m_ulMcs);
86 NS_LOG_FUNCTION(
this);
93 NS_LOG_FUNCTION(
this);
98NrMacSchedulerCQIManagement::InstallGetStartMcsDlFn(
const std::function<uint8_t()>& fn)
100 NS_LOG_FUNCTION(
this);
101 m_getStartMcsDl = fn;
105NrMacSchedulerCQIManagement::InstallGetStartMcsUlFn(
const std::function<uint8_t()>& fn)
107 NS_LOG_FUNCTION(
this);
108 m_getStartMcsUl = fn;
112NrMacSchedulerCQIManagement::InstallGetNrAmcDlFn(
const std::function<Ptr<const NrAmc>()>& fn)
114 NS_LOG_FUNCTION(
this);
119NrMacSchedulerCQIManagement::InstallGetNrAmcUlFn(
const std::function<Ptr<const NrAmc>()>& fn)
121 NS_LOG_FUNCTION(
this);
127 const std::shared_ptr<NrMacSchedulerUeInfo>& ueInfo,
128 uint32_t expirationTime,
130 uint16_t bandwidthInRbgs)
const
132 NS_LOG_FUNCTION(
this);
134 ueInfo->m_dlCqi.m_timer = expirationTime;
136 ueInfo->m_dlCqi.m_wbCqi = info.
m_wbCqi;
138 std::min(
static_cast<uint8_t
>(GetAmcDl()->GetMcsFromCqi(ueInfo->m_dlCqi.m_wbCqi)),
139 static_cast<uint8_t
>(maxDlMcs));
141 ueInfo->m_dlCqi.m_sbCqi = info.
m_sbCqis;
142 ueInfo->m_dlSbMcsInfo.clear();
146 ueInfo->m_dlSbMcsInfo.resize(info.
m_sbCqis.size());
147 ueInfo->m_rbgToSb.resize(bandwidthInRbgs);
150 size_t rbgsPerSb = 1;
151 while (
static_cast<std::size_t
>(bandwidthInRbgs / rbgsPerSb) >
152 ueInfo->m_dlCqi.m_sbCqi.size())
160 for (
auto sbCqi : ueInfo->m_dlCqi.m_sbCqi)
162 auto mcs = m_getAmcDl()->GetMcsFromCqi(sbCqi);
163 auto specEff = m_getAmcDl()->GetSpectralEfficiencyForCqi(sbCqi);
164 auto sinr = m_getAmcDl()->GetSinrFromSpectralEfficiency(specEff);
170 ueInfo->m_dlSbMcsInfo[sb] = {sbCqi, mcs, (float)specEff, (
float)sinr};
172 for (
auto rbg = sb * rbgsPerSb;
173 rbg < std::min<size_t>(bandwidthInRbgs, (sb + 1) * rbgsPerSb);
176 ueInfo->m_rbgToSb[rbg] = sb;
182 NS_LOG_INFO(
"Calculated MCS for UE " << ueInfo->m_rnti <<
" is "
183 <<
static_cast<uint32_t
>(ueInfo->m_dlMcs));
185 NS_LOG_INFO(
"Updated WB CQI of UE "
186 << ueInfo->m_rnti <<
" to " <<
static_cast<uint32_t
>(ueInfo->m_dlCqi.m_wbCqi)
187 <<
". It will expire in " << ueInfo->m_dlCqi.m_timer <<
" slots.");
192 NS_ASSERT(info.
m_ri > 0);
193 ueInfo->m_dlRank = info.
m_ri;
202 const std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>& ueMap)
const
204 NS_LOG_FUNCTION(
this);
206 for (
const auto& itUe : ueMap)
208 const std::shared_ptr<NrMacSchedulerUeInfo>& ue = itUe.second;
210 if (ue->m_dlCqi.m_timer == 0)
212 ue->m_dlCqi.m_wbCqi = 1;
214 ue->m_dlMcs = GetStartMcsDl();
218 ue->m_dlCqi.m_timer -= 1;
225 const std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>& ueMap)
const
227 NS_LOG_FUNCTION(
this);
229 for (
const auto& itUe : ueMap)
231 const std::shared_ptr<NrMacSchedulerUeInfo>& ue = itUe.second;
233 if (ue->m_ulCqi.m_timer == 0)
235 ue->m_ulCqi.m_wbCqi = 1;
237 ue->m_ulMcs = GetStartMcsUl();
241 ue->m_ulCqi.m_timer -= 1;
247NrMacSchedulerCQIManagement::GetBwpId()
const
253NrMacSchedulerCQIManagement::GetCellId()
const
255 return m_getCellId();
259NrMacSchedulerCQIManagement::GetStartMcsDl()
const
261 return m_getStartMcsDl();
265NrMacSchedulerCQIManagement::GetStartMcsUl()
const
267 return m_getStartMcsUl();
271NrMacSchedulerCQIManagement::GetAmcDl()
const
277NrMacSchedulerCQIManagement::GetAmcUl()
const
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 InstallGetBwpIdFn(const std::function< uint16_t()> &fn)
Install a function to retrieve the bwp id.
void UlSBCQIReported(uint32_t expirationTime, uint32_t tbs, const NrMacSchedSapProvider::SchedUlCqiInfoReqParameters ¶ms, const std::shared_ptr< NrMacSchedulerUeInfo > &ueInfo, const std::vector< bool > &rbgMask, uint32_t numRbPerRbg, const Ptr< const SpectrumModel > &model) const
An UL SB CQI has been reported for the specified UE.
void DlCqiReported(const DlCqiInfo &info, const std::shared_ptr< NrMacSchedulerUeInfo > &ueInfo, uint32_t expirationTime, int8_t maxDlMcs, uint16_t bandwidthInRbgs) const
A wideband CQI has been reported for the specified UE.
Ptr< const ComplexMatrixArray > m_optPrecMat
Precoding matrix for each RB.
uint8_t m_wbCqi
Wideband CQI.
std::vector< uint8_t > m_sbCqis
Subband CQI values.
uint8_t m_ri
the rank indicator, or simply the rank number
The SchedUlCqiInfoReqParameters struct.
struct UlCqiInfo m_ulCqi
UL CQI.
enum ns3::NrMacSchedulerUeInfo::CqiInfo::CqiType WB
CQI type.