5G-LENA nr-v4.1
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-scheduler-tdma-rr.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-tdma-rr.h"
6
7#include "nr-mac-scheduler-ue-info-rr.h"
8
9#include "ns3/log.h"
10
11#include <algorithm>
12#include <functional>
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("NrMacSchedulerTdmaRR");
18NS_OBJECT_ENSURE_REGISTERED(NrMacSchedulerTdmaRR);
19
20TypeId
22{
23 static TypeId tid = TypeId("ns3::NrMacSchedulerTdmaRR")
24 .SetParent<NrMacSchedulerTdma>()
25 .AddConstructor<NrMacSchedulerTdmaRR>();
26 return tid;
27}
28
31{
32 NS_LOG_FUNCTION(this);
33}
34
35std::shared_ptr<NrMacSchedulerUeInfo>
38{
39 NS_LOG_FUNCTION(this);
40 return std::make_shared<NrMacSchedulerUeInfoRR>(
41 params.m_rnti,
42 params.m_beamId,
43 std::bind(&NrMacSchedulerTdmaRR::GetNumRbPerRbg, this));
44}
45
46void
48 [[maybe_unused]] const FTResources& assigned,
49 [[maybe_unused]] const FTResources& totAssigned) const
50{
51 NS_LOG_FUNCTION(this);
52 GetFirst GetUe;
53 auto oldTbSize = GetUe(ue)->m_dlTbSize;
54 GetUe(ue)->UpdateDlMetric();
55 auto newTbSize = GetUe(ue)->m_dlTbSize;
56
57 if (m_dlRntiSet.find(GetUe(ue)->m_rnti) == m_dlRntiSet.end())
58 {
59 m_dlRntiSet.emplace(GetUe(ue)->m_rnti);
60 m_dlRrRntiDeque.push_front(GetUe(ue)->m_rnti);
61 }
62 auto it = std::find(m_dlRrRntiDeque.begin(), m_dlRrRntiDeque.end(), GetUe(ue)->m_rnti);
63
64 // If transport block size increased, move to end of list
65 if (newTbSize > oldTbSize)
66 {
67 m_dlRrRntiDeque.erase(it);
68 m_dlRrRntiDeque.push_back(GetUe(ue)->m_rnti);
69 }
70 // If it decreased (resources were reaped), move to beginning of list
71 else if (newTbSize < oldTbSize)
72 {
73 m_dlRrRntiDeque.erase(it);
74 m_dlRrRntiDeque.push_front(GetUe(ue)->m_rnti);
75 }
76}
77
78void
80 [[maybe_unused]] const FTResources& assigned,
81 [[maybe_unused]] const FTResources& totAssigned) const
82{
83 NS_LOG_FUNCTION(this);
84 GetFirst GetUe;
85 GetUe(ue)->UpdateUlMetric();
86}
87
88std::function<bool(const NrMacSchedulerNs3::UePtrAndBufferReq& lhs,
91{
92 return [this](const NrMacSchedulerNs3::UePtrAndBufferReq& a,
94 for (const auto& c : {a, b})
95 {
96 if (m_dlRntiSet.find(c.first->m_rnti) == m_dlRntiSet.end())
97 {
98 m_dlRntiSet.emplace(c.first->m_rnti);
99 m_dlRrRntiDeque.push_front(c.first->m_rnti);
100 }
101 }
102 // Search for either A or B RNTI
103 auto it = std::find_if(m_dlRrRntiDeque.begin(),
104 m_dlRrRntiDeque.end(),
105 [aRnti = a.first->m_rnti, bRnti = b.first->m_rnti](auto& cRnti) {
106 return (cRnti == aRnti) | (cRnti == bRnti);
107 });
108 // If first found RNTI is A, then A < B
109 return *it == a.first->m_rnti;
110 };
111}
112
113std::function<bool(const NrMacSchedulerNs3::UePtrAndBufferReq& lhs,
119
120} // namespace ns3
uint64_t GetNumRbPerRbg() const
Private function that is used to get the number of resource blocks per resource block group and also ...
std::pair< UePtr, uint32_t > UePtrAndBufferReq
Pair between a pointer to NrMacSchedulerUeInfo and its buffer occupancy.
The base for all the TDMA schedulers.
std::shared_ptr< NrMacSchedulerUeInfo > CreateUeRepresentation(const NrMacCschedSapProvider::CschedUeConfigReqParameters &params) const override
Create an UE representation of the type NrMacSchedulerUeInfoRR.
NrMacSchedulerTdmaRR()
NrMacSchedulerTdmaRR constructor.
std::function< bool(const NrMacSchedulerNs3::UePtrAndBufferReq &lhs, const NrMacSchedulerNs3::UePtrAndBufferReq &rhs)> GetUeCompareUlFn() const override
Return the comparison function to sort UL UE according to the scheduler policy.
std::function< bool(const NrMacSchedulerNs3::UePtrAndBufferReq &lhs, const NrMacSchedulerNs3::UePtrAndBufferReq &rhs)> GetUeCompareDlFn() const override
Return the comparison function to sort DL UE according to the scheduler policy.
void AssignedDlResources(const UePtrAndBufferReq &ue, const FTResources &assigned, const FTResources &totAssigned) const override
Update the UE representation after a symbol (DL) has been assigned to it.
static TypeId GetTypeId()
GetTypeId.
void AssignedUlResources(const UePtrAndBufferReq &ue, const FTResources &assigned, const FTResources &totAssigned) const override
Update the UE representation after a symbol (DL) has been assigned to it.
static bool CompareUeWeightsUl(const NrMacSchedulerNs3::UePtrAndBufferReq &lue, const NrMacSchedulerNs3::UePtrAndBufferReq &rue)
comparison function object (i.e. an object that satisfies the requirements of Compare) which returns ...
Point in the Frequency/Time plane.