5G-LENA nr-v3.3-120-gdac69c56
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-scheduler-ue-info.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "nr-mac-scheduler-ue-info.h"
6
7#include "ns3/log.h"
8
9#include <numeric>
10
11namespace ns3
12{
13
14NS_LOG_COMPONENT_DEFINE("NrMacSchedulerUeInfo");
15
16NrMacSchedulerUeInfo::NrMacSchedulerUeInfo(uint16_t rnti, BeamId beamId, const GetRbPerRbgFn& fn)
17 : m_rnti(rnti),
18 m_beamId(beamId),
19 m_getNumRbPerRbg(fn)
20{
21}
22
26
27std::vector<uint16_t>&
29{
30 return ue->m_dlRBG;
31}
32
33std::vector<uint16_t>&
35{
36 return ue->m_ulRBG;
37}
38
39std::vector<uint8_t>&
41{
42 return ue->m_dlSym;
43}
44
45std::vector<uint8_t>&
47{
48 return ue->m_ulSym;
49}
50
51uint8_t&
53{
54 return ue->m_dlMcs;
55}
56
57template <typename T>
58uint8_t
59ComputeMcs(const NrMacSchedulerUeInfo* ueInfo,
61 std::function<uint8_t(double)> postProcessing)
62{
63 // Compute average field of allocated RBGs
64 const auto sum = std::transform_reduce(
65 ueInfo->m_dlRBG.begin(),
66 ueInfo->m_dlRBG.end(),
67 0.0,
68 [](auto a, auto b) { return a + b; },
69 [ueInfo, field](auto a) {
70 return ueInfo->m_dlSbMcsInfo.at(ueInfo->m_rbgToSb.at(a)).*field;
71 });
72 const auto avg = sum / ueInfo->m_dlRBG.size();
73 return postProcessing(avg);
74}
75
76uint8_t
78{
79 // Return maximum allowed MCS according to Fronthaul control
80 if (m_fhMaxMcsAssignable.has_value())
81 {
82 return m_fhMaxMcsAssignable.value();
83 }
84
85 // In case there is no sub-band info or no RBG has been allocated, return the wideband MCS
87 {
88 return m_dlMcs;
89 }
90
91 // Otherwise, compute the SINR of allocated RBGs
92 switch (m_mcsCsiSource)
93 {
94 // Estimate MCS based on the average MCS of allocated RBGs
96 return ComputeMcs(this, &SbMcsInfo::mcs, [](double avg) { return (uint8_t)floor(avg); });
97 }
98 // Estimate MCS based on the average spectral efficiency of allocated RBGs
100 return ComputeMcs(this,
101 &SbMcsInfo::specEff,
103 }
104 // Estimate MCS based on the average SINR of allocated RBGs
106 return ComputeMcs(this, &SbMcsInfo::sinr, [amc = m_dlAmc](double avgSinr) {
107 return amc->GetMcsFromSpectralEfficiency(amc->GetSpectralEfficiencyForSinr(avgSinr));
108 });
109 }
110 default:
111 NS_ABORT_MSG("Invalid csi source for MCS computation");
112 }
113}
114
115uint8_t&
117{
118 return ue->m_ulMcs;
119}
120
121uint32_t&
123{
124 return ue->m_dlTbSize;
125}
126
127std::unordered_map<uint8_t, LCGPtr>&
129{
130 return ue->m_dlLCG;
131}
132
133std::unordered_map<uint8_t, LCGPtr>&
135{
136 return ue->m_ulLCG;
137}
138
141{
142 return ue->m_dlHarq;
143}
144
147{
148 return ue->m_ulHarq;
149}
150
151void
153 uint8_t lcgId,
154 uint8_t lcId,
155 uint8_t qci,
156 uint8_t P,
157 uint8_t minP)
158{
159 NS_LOG_DEBUG("UE " << ue << " LCG ID: " << static_cast<uint32_t>(lcgId) << " LC ID "
160 << static_cast<uint32_t>(lcId) << " QCI: " << static_cast<uint32_t>(qci)
161 << " P: " << static_cast<uint32_t>(P) << " minP: " << +minP);
162}
163
164void
166{
167 m_dlMRBRetx = 0;
168 m_dlRBG.clear();
169 m_dlSym.clear();
170 m_dlTbSize = 0;
171}
172
173void
175{
176 m_ulMRBRetx = 0;
177 m_ulRBG.clear();
178 m_ulSym.clear();
179 m_ulTbSize = 0;
180}
181
182void
184{
185 if (m_dlRBG.empty())
186 {
187 m_dlTbSize = 0;
188 }
189 else
190 {
191 m_dlTbSize =
192 m_dlAmc->CalculateTbSize(GetDlMcs(), m_dlRank, m_dlRBG.size() * GetNumRbPerRbg());
193 }
194}
195
196void
201
202void
204{
205 if (m_ulRBG.empty())
206 {
207 m_ulTbSize = 0;
208 }
209 else
210 {
211 m_ulTbSize = m_ulAmc->CalculateTbSize(m_ulMcs, m_ulRank, m_ulRBG.size() * GetNumRbPerRbg());
212 }
213}
214
215void
220
221uint32_t
222NrMacSchedulerUeInfo::GetTotalDlBuffer() const
223{
224 uint32_t totBuffer = 0;
225 for (const auto& lcgInfo : m_dlLCG)
226 {
227 const auto& lcg = lcgInfo.second;
228 totBuffer += lcg->GetTotalSize();
229 }
230 return totBuffer;
231}
232
233uint32_t
235{
236 return m_getNumRbPerRbg();
237}
238
239void
240NrMacSchedulerUeInfo::ReleaseLC(uint8_t lcid)
241{
242 for (auto lcgIt = m_dlLCG.begin(); lcgIt != m_dlLCG.end(); lcgIt++)
243 {
244 lcgIt->second->ReleaseLC(lcid);
245 }
246 for (auto lcgIt = m_ulLCG.begin(); lcgIt != m_ulLCG.end(); lcgIt++)
247 {
248 lcgIt->second->ReleaseLC(lcid);
249 }
250 auto it = m_dlLCG.begin();
251 while (it != m_dlLCG.end())
252 {
253 if (it->second->GetLCId().empty())
254 {
255 m_dlLCG.erase(it);
256 it = m_dlLCG.begin();
257 }
258 else
259 {
260 it++;
261 }
262 }
263 it = m_ulLCG.begin();
264 while (it != m_ulLCG.end())
265 {
266 if (it->second->GetLCId().empty())
267 {
268 m_ulLCG.erase(it);
269 it = m_ulLCG.begin();
270 }
271 else
272 {
273 it++;
274 }
275 }
276}
277
278} // namespace ns3
Representation of a beam id.
Definition beam-id.h:26
uint8_t GetMcsFromSpectralEfficiency(double s) const
Get MCS from a SpectralEfficiency value.
Definition nr-amc.cc:281
Data structure to save all the HARQ process of an UE.
The representation of an user for any Mac scheduler.
std::vector< uint16_t > m_ulRBG
UL Resource Block Group assigned in this slot.
std::vector< uint16_t > m_dlRBG
DL Resource Block Group assigned in this slot.
uint32_t GetNumRbPerRbg() const
Retrieve the number of RB per RBG.
static std::vector< uint8_t > & GetUlSym(const UePtr &ue)
GetUlSym.
Ptr< NrAmc > m_dlAmc
AMC instance of scheduler associated with DL.
virtual void ResetDlSchedInfo()
Reset DL information.
uint8_t m_ulRank
UL rank (number of MIMO layers)
virtual void ResetUlMetric()
ResetUlMetric.
virtual void UpdateUlMetric()
Update UL metrics after resources have been assigned.
virtual void ResetDlMetric()
ResetDlMetric.
static std::unordered_map< uint8_t, LCGPtr > & GetUlLCG(const UePtr &ue)
GetUlLCG.
static void PrintLcInfo(uint16_t ue, uint8_t lcgId, uint8_t lcId, uint8_t cqi, uint8_t P, uint8_t minP)
Prints information related to the QCI of a UEs LC.
static std::vector< uint16_t > & GetUlRBG(const UePtr &ue)
GetUlRBG.
static NrMacHarqVector & GetUlHarqVector(const UePtr &ue)
GetUlHarqVector.
uint8_t m_dlRank
DL rank (number of MIMO layers)
@ AVG_MCS
Estimate MCS based on the average MCS of allocated RBGs.
@ AVG_SPEC_EFF
Estimate MCS based on the average spectral efficiency of allocated RBGs.
@ AVG_SINR
Estimate MCS based on the average SINR of allocated RBGs.
std::vector< uint8_t > m_ulSym
Corresponding symbol of m_ulRBG in this slot.
static std::vector< uint16_t > & GetDlRBG(const UePtr &ue)
GetDlRBG.
std::optional< uint8_t > m_fhMaxMcsAssignable
Maximum DL MCS assignable due to FH limitations.
NrMacSchedulerUeInfo()=delete
Default Constructor (deleted)
virtual ~NrMacSchedulerUeInfo()
~NrMacSchedulerUeInfo deconstructor
std::vector< SbMcsInfo > m_dlSbMcsInfo
static std::unordered_map< uint8_t, LCGPtr > & GetDlLCG(const UePtr &ue)
GetDlLCG.
uint8_t GetDlMcs() const
Get the downlink MCS, given by the wideband CQI, or the sub-band CQIs of the currently allocated RBGs...
std::vector< uint8_t > m_dlSym
Corresponding symbol of m_dlRBG in this slot.
static uint8_t & GetUlMcs(const UePtr &ue)
GetUlMcs.
std::unordered_map< uint8_t, LCGPtr > m_dlLCG
DL LCG.
static std::vector< uint8_t > & GetDlSym(const UePtr &ue)
GetDlSym.
std::unordered_map< uint8_t, LCGPtr > m_ulLCG
UL LCG.
virtual void UpdateDlMetric()
Update DL metrics after resources have been assigned.
virtual void ResetUlSchedInfo()
Reset UL information.
static NrMacHarqVector & GetDlHarqVector(const UePtr &ue)
GetDlHarqVector.
static uint32_t & GetDlTBS(const UePtr &ue)
GetDlTBS.
Ptr< NrAmc > m_ulAmc
AMC instance of scheduler associated with UL.
McsCsiSource m_mcsCsiSource
Source of MCS computation based on CSI feedback.