5G-LENA nr-v4.0
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
bwp-manager-gnb.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "bwp-manager-gnb.h"
6
7#include "bwp-manager-algorithm.h"
8#include "nr-control-messages.h"
9
10#include "ns3/log.h"
11#include "ns3/object-map.h"
12#include "ns3/pointer.h"
13#include "ns3/uinteger.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("BwpManagerGnb");
19NS_OBJECT_ENSURE_REGISTERED(BwpManagerGnb);
20
21BwpManagerGnb::BwpManagerGnb()
22 : NrRrComponentCarrierManager()
23{
24 NS_LOG_FUNCTION(this);
25}
26
27BwpManagerGnb::~BwpManagerGnb()
28{
29 NS_LOG_FUNCTION(this);
30}
31
32TypeId
33BwpManagerGnb::GetTypeId()
34{
35 static TypeId tid = TypeId("ns3::BwpManagerGnb")
36 .SetParent<NrNoOpComponentCarrierManager>()
37 .SetGroupName("nr")
38 .AddConstructor<BwpManagerGnb>()
39 .AddAttribute("BwpManagerAlgorithm",
40 "The algorithm pointer",
41 PointerValue(),
42 MakePointerAccessor(&BwpManagerGnb::m_algorithm),
43 MakePointerChecker<BwpManagerAlgorithm>());
44 return tid;
45}
46
47void
48BwpManagerGnb::SetBwpManagerAlgorithm(const Ptr<BwpManagerAlgorithm>& algorithm)
49{
50 NS_LOG_FUNCTION(this);
51 m_algorithm = algorithm;
52}
53
54uint8_t
55BwpManagerGnb::GetResourceType(NrMacSapProvider::BufferStatusReportParameters params)
56{
57 NS_ASSERT_MSG(m_ueInfo.find(params.rnti) != m_ueInfo.end(),
58 "Trying to check the QoS of unknown UE");
59 NS_ASSERT_MSG(m_ueInfo.at(params.rnti).m_rlcLcInstantiated.find(params.lcid) !=
60 m_ueInfo.at(params.rnti).m_rlcLcInstantiated.end(),
61 "Trying to check the QoS of unknown logical channel");
62 return (m_ueInfo[params.rnti].m_rlcLcInstantiated[params.lcid]).resourceType;
63}
64
65std::vector<NrCcmRrcSapProvider::LcsConfig>
66BwpManagerGnb::DoSetupDataRadioBearer(NrEpsBearer bearer,
67 uint8_t bearerId,
68 uint16_t rnti,
69 uint8_t lcid,
70 uint8_t lcGroup,
71 NrMacSapUser* msu)
72{
73 NS_LOG_FUNCTION(this);
74
75 std::vector<NrCcmRrcSapProvider::LcsConfig> lcsConfig =
76 NrRrComponentCarrierManager::DoSetupDataRadioBearer(bearer,
77 bearerId,
78 rnti,
79 lcid,
80 lcGroup,
81 msu);
82 return lcsConfig;
83}
84
85uint8_t
86BwpManagerGnb::GetBwpIndex(uint16_t rnti, uint8_t lcid)
87{
88 NS_LOG_FUNCTION(this);
89 NS_ASSERT(m_algorithm != nullptr);
90 NS_ASSERT_MSG(m_ueInfo.find(rnti) != m_ueInfo.end(), "Unknown UE");
91 NS_ASSERT_MSG(m_ueInfo.at(rnti).m_rlcLcInstantiated.find(lcid) !=
92 m_ueInfo.at(rnti).m_rlcLcInstantiated.end(),
93 "Unknown logical channel of UE");
94
95 uint8_t qci = m_ueInfo[rnti].m_rlcLcInstantiated[lcid].qci;
96
97 // Force a conversion between the uint8_t type that comes from the LcInfo
98 // struct (yeah, using the NrEpsBearer::Qci type was too hard ...)
99 return m_algorithm->GetBwpForEpsBearer(static_cast<NrEpsBearer::Qci>(qci));
100}
101
102uint8_t
103BwpManagerGnb::PeekBwpIndex(uint16_t rnti, uint8_t lcid) const
104{
105 NS_LOG_FUNCTION(this);
106 NS_ASSERT(m_algorithm != nullptr);
107 // For the moment, Get and Peek are the same, but they'll change
108 NS_ASSERT_MSG(m_ueInfo.find(rnti) != m_ueInfo.end(), "Unknown UE");
109 NS_ASSERT_MSG(m_ueInfo.at(rnti).m_rlcLcInstantiated.find(lcid) !=
110 m_ueInfo.at(rnti).m_rlcLcInstantiated.end(),
111 "Unknown logical channel of UE");
112
113 uint8_t qci = m_ueInfo.at(rnti).m_rlcLcInstantiated.at(lcid).qci;
114
115 // Force a conversion between the uint8_t type that comes from the LcInfo
116 // struct (yeah, using the NrEpsBearer::Qci type was too hard ...)
117 return m_algorithm->GetBwpForEpsBearer(static_cast<NrEpsBearer::Qci>(qci));
118}
119
120uint8_t
121BwpManagerGnb::RouteIngoingCtrlMsgs(const Ptr<NrControlMessage>& msg, uint8_t sourceBwpId) const
122{
123 NS_LOG_FUNCTION(this);
124
125 NS_LOG_INFO("Msg type " << msg->GetMessageType() << " from bwp " << +sourceBwpId
126 << " that wants to go in the gnb, goes in BWP " << msg->GetSourceBwp());
127 return msg->GetSourceBwp();
128}
129
130uint8_t
131BwpManagerGnb::RouteOutgoingCtrlMsg(const Ptr<NrControlMessage>& msg, uint8_t sourceBwpId) const
132{
133 NS_LOG_FUNCTION(this);
134
135 NS_LOG_INFO("Msg type " << msg->GetMessageType() << " from bwp " << +sourceBwpId
136 << " that wants to go out from gnb");
137
138 if (m_outputLinks.empty())
139 {
140 NS_LOG_INFO("No linked BWP, routing outgoing msg to the source: " << +sourceBwpId);
141 return sourceBwpId;
142 }
143
144 auto it = m_outputLinks.find(sourceBwpId);
145 if (it == m_outputLinks.end())
146 {
147 NS_LOG_INFO("Source BWP not in the map, routing outgoing msg to itself: " << +sourceBwpId);
148 return sourceBwpId;
149 }
150
151 NS_LOG_INFO("routing outgoing msg to bwp: " << +it->second);
152 return it->second;
153}
154
155void
156BwpManagerGnb::SetOutputLink(uint32_t sourceBwp, uint32_t outputBwp)
157{
158 NS_LOG_FUNCTION(this);
159 m_outputLinks.insert(std::make_pair(sourceBwp, outputBwp));
160}
161
162void
163BwpManagerGnb::DoTransmitBufferStatusReport(NrMacSapProvider::BufferStatusReportParameters params)
164{
165 NS_LOG_FUNCTION(this);
166
167 uint8_t bwpIndex = GetBwpIndex(params.rnti, params.lcid);
168
169 if (m_macSapProvidersMap.find(bwpIndex) != m_macSapProvidersMap.end())
170 {
171 m_macSapProvidersMap.find(bwpIndex)->second->BufferStatusReport(params);
172 }
173 else
174 {
175 NS_ABORT_MSG("Bwp index " << +bwpIndex << " not valid.");
176 }
177}
178
179void
180BwpManagerGnb::DoNotifyTxOpportunity(NrMacSapUser::TxOpportunityParameters txOpParams)
181{
182 NS_LOG_FUNCTION(this);
183 std::map<uint16_t, NrUeInfo>::iterator rntiIt = m_ueInfo.find(txOpParams.rnti);
184 NS_ASSERT_MSG(rntiIt != m_ueInfo.end(), "could not find RNTI" << txOpParams.rnti);
185
186 std::map<uint8_t, NrMacSapUser*>::iterator lcidIt =
187 rntiIt->second.m_ueAttached.find(txOpParams.lcid);
188 NS_ASSERT_MSG(lcidIt != rntiIt->second.m_ueAttached.end(),
189 "could not find LCID " << (uint16_t)txOpParams.lcid);
190
191 (*lcidIt).second->NotifyTxOpportunity(txOpParams);
192}
193
194void
195BwpManagerGnb::DoUlReceiveMacCe(nr::MacCeListElement_s bsr, uint8_t componentCarrierId)
196{
197 NS_LOG_FUNCTION(this);
198 NS_ASSERT(m_algorithm != nullptr);
199 NS_ASSERT_MSG(bsr.m_macCeType == nr::MacCeListElement_s::BSR,
200 "Received a Control Message not allowed " << bsr.m_macCeType);
201 NS_ASSERT_MSG(m_ccmMacSapProviderMap.find(componentCarrierId) != m_ccmMacSapProviderMap.end(),
202 "Mac sap provider does not exist.");
203
204 NS_LOG_DEBUG("Routing BSR for UE " << bsr.m_rnti << " to source CC id "
205 << static_cast<uint32_t>(componentCarrierId));
206
207 if (m_ccmMacSapProviderMap.find(componentCarrierId) != m_ccmMacSapProviderMap.end())
208 {
209 m_ccmMacSapProviderMap.find(componentCarrierId)->second->ReportMacCeToScheduler(bsr);
210 }
211 else
212 {
213 NS_ABORT_MSG("Bwp index not valid.");
214 }
215}
216
217void
218BwpManagerGnb::DoUlReceiveSr(uint16_t rnti, uint8_t componentCarrierId)
219{
220 NS_LOG_FUNCTION(this);
221 NS_ASSERT(m_algorithm != nullptr);
222
223 NS_LOG_DEBUG("Routing SR for UE " << rnti << " to source CC id "
224 << static_cast<uint32_t>(componentCarrierId));
225
226 auto it = m_ccmMacSapProviderMap.find(componentCarrierId);
227 NS_ABORT_IF(it == m_ccmMacSapProviderMap.end());
228
229 m_ccmMacSapProviderMap.find(componentCarrierId)->second->ReportSrToScheduler(rnti);
230}
231
232} // end of namespace ns3
This class contains the specification of EPS Bearers.
See section 4.3.14 macCEListElement.