5G-LENA nr-v3.3-161-gad18933f
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-simple-ue-component-carrier-manager.cc
1// Copyright (c) 2015 Danilo Abrignani
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Danilo Abrignani <danilo.abrignani@unibo.it>
6//
8
9#include "nr-simple-ue-component-carrier-manager.h"
10
11#include "ns3/log.h"
12
13namespace ns3
14{
15
16NS_LOG_COMPONENT_DEFINE("NrSimpleUeComponentCarrierManager");
17
18NS_OBJECT_ENSURE_REGISTERED(NrSimpleUeComponentCarrierManager);
19
21// SAP forwarders
23
25// MAC SAP PROVIDER SAP forwarders
27
29class NrSimpleUeCcmMacSapProvider : public NrMacSapProvider
30{
31 public:
37 NrSimpleUeCcmMacSapProvider(NrSimpleUeComponentCarrierManager* mac);
38
39 // inherited from NrMacSapProvider
40 void TransmitPdu(NrMacSapProvider::TransmitPduParameters params) override;
41 void BufferStatusReport(NrMacSapProvider::BufferStatusReportParameters params) override;
42
43 private:
44 NrSimpleUeComponentCarrierManager* m_mac;
45};
46
47NrSimpleUeCcmMacSapProvider::NrSimpleUeCcmMacSapProvider(NrSimpleUeComponentCarrierManager* mac)
48 : m_mac(mac)
49{
50}
51
52void
53NrSimpleUeCcmMacSapProvider::TransmitPdu(TransmitPduParameters params)
54{
55 m_mac->DoTransmitPdu(params);
56}
57
58void
59NrSimpleUeCcmMacSapProvider::BufferStatusReport(BufferStatusReportParameters params)
60{
61 m_mac->DoTransmitBufferStatusReport(params);
62}
63
65// MAC SAP USER SAP forwarders
67
69class NrSimpleUeCcmMacSapUser : public NrMacSapUser
70{
71 public:
77 NrSimpleUeCcmMacSapUser(NrSimpleUeComponentCarrierManager* mac);
78
79 // inherited from NrMacSapUser
80 void NotifyTxOpportunity(NrMacSapUser::TxOpportunityParameters txOpParams) override;
81 void ReceivePdu(NrMacSapUser::ReceivePduParameters rxPduParams) override;
82 void NotifyHarqDeliveryFailure() override;
83
84 private:
85 NrSimpleUeComponentCarrierManager* m_mac;
86};
87
88NrSimpleUeCcmMacSapUser::NrSimpleUeCcmMacSapUser(NrSimpleUeComponentCarrierManager* mac)
89 : m_mac(mac)
90{
91}
92
93void
94NrSimpleUeCcmMacSapUser::NotifyTxOpportunity(NrMacSapUser::TxOpportunityParameters txOpParams)
95{
96 NS_LOG_INFO("NrSimpleUeCcmMacSapUser::NotifyTxOpportunity for ccId:"
97 << (uint32_t)txOpParams.componentCarrierId);
98 m_mac->DoNotifyTxOpportunity(txOpParams);
99}
100
101void
102NrSimpleUeCcmMacSapUser::ReceivePdu(NrMacSapUser::ReceivePduParameters rxPduParams)
103{
104 m_mac->DoReceivePdu(rxPduParams);
105}
106
107void
108NrSimpleUeCcmMacSapUser::NotifyHarqDeliveryFailure()
109{
110 m_mac->DoNotifyHarqDeliveryFailure();
111}
112
114// NrSimpleUeComponentCarrierManager methods
116
117NrSimpleUeComponentCarrierManager::NrSimpleUeComponentCarrierManager()
118{
119 NS_LOG_FUNCTION(this);
121 m_ccmMacSapUser = new NrSimpleUeCcmMacSapUser(this);
122 m_ccmMacSapProvider = new NrSimpleUeCcmMacSapProvider(this);
123}
124
125NrSimpleUeComponentCarrierManager::~NrSimpleUeComponentCarrierManager()
126{
127 NS_LOG_FUNCTION(this);
128}
129
130void
131NrSimpleUeComponentCarrierManager::DoDispose()
132{
133 NS_LOG_FUNCTION(this);
134 delete m_ccmRrcSapProvider;
135 delete m_ccmMacSapUser;
136 delete m_ccmMacSapProvider;
137}
138
139TypeId
140NrSimpleUeComponentCarrierManager::GetTypeId()
141{
142 static TypeId tid = TypeId("ns3::NrSimpleUeComponentCarrierManager")
143 .SetParent<NrUeComponentCarrierManager>()
144 .SetGroupName("Nr")
145 .AddConstructor<NrSimpleUeComponentCarrierManager>();
146 return tid;
147}
148
150NrSimpleUeComponentCarrierManager::GetNrMacSapProvider()
151{
152 NS_LOG_FUNCTION(this);
153 return m_ccmMacSapProvider;
154}
155
156void
157NrSimpleUeComponentCarrierManager::DoInitialize()
158{
159 NS_LOG_FUNCTION(this);
160 NrUeComponentCarrierManager::DoInitialize();
161}
162
163void
164NrSimpleUeComponentCarrierManager::DoReportUeMeas(uint16_t rnti, NrRrcSap::MeasResults measResults)
165{
166 NS_LOG_FUNCTION(this << rnti << (uint16_t)measResults.measId);
167}
168
169void
170NrSimpleUeComponentCarrierManager::DoTransmitPdu(NrMacSapProvider::TransmitPduParameters params)
171{
172 NS_LOG_FUNCTION(this);
173 auto it = m_macSapProvidersMap.find(params.componentCarrierId);
174 NS_ABORT_MSG_IF(it == m_macSapProvidersMap.end(),
175 "could not find Sap for NrComponentCarrier "
176 << (uint16_t)params.componentCarrierId);
177 // with this algorithm all traffic is on Primary Carrier, is it?
178 it->second->TransmitPdu(params);
179}
180
181void
182NrSimpleUeComponentCarrierManager::DoTransmitBufferStatusReport(
184{
185 NS_LOG_FUNCTION(this);
186 NS_LOG_DEBUG("BSR from RLC for LCID = " << (uint16_t)params.lcid);
187 auto it = m_macSapProvidersMap.find(0);
188 NS_ABORT_MSG_IF(it == m_macSapProvidersMap.end(), "could not find Sap for NrComponentCarrier");
189
190 NS_LOG_DEBUG("Size of component carrier LC map " << m_componentCarrierLcMap.size());
191
192 for (auto ccLcMapIt = m_componentCarrierLcMap.begin();
193 ccLcMapIt != m_componentCarrierLcMap.end();
194 ccLcMapIt++)
195 {
196 NS_LOG_DEBUG("BSR from RLC for CC id = " << (uint16_t)ccLcMapIt->first);
197 auto it = ccLcMapIt->second.find(params.lcid);
198 if (it != ccLcMapIt->second.end())
199 {
200 it->second->BufferStatusReport(params);
201 }
202 }
203}
204
205void
206NrSimpleUeComponentCarrierManager::DoNotifyHarqDeliveryFailure()
207{
208 NS_LOG_FUNCTION(this);
209}
210
211void
212NrSimpleUeComponentCarrierManager::DoNotifyTxOpportunity(
214{
215 NS_LOG_FUNCTION(this);
216 auto lcidIt = m_lcAttached.find(txOpParams.lcid);
217 NS_ABORT_MSG_IF(lcidIt == m_lcAttached.end(),
218 "could not find LCID" << (uint16_t)txOpParams.lcid);
219 NS_LOG_DEBUG(this << " lcid = " << (uint32_t)txOpParams.lcid
220 << " layer= " << (uint16_t)txOpParams.layer << " componentCarrierId "
221 << (uint16_t)txOpParams.componentCarrierId << " rnti " << txOpParams.rnti);
222
223 NS_LOG_DEBUG(this << " MAC is asking component carrier id = "
224 << (uint16_t)txOpParams.componentCarrierId
225 << " with lcid = " << (uint32_t)txOpParams.lcid << " to transmit "
226 << txOpParams.bytes << " bytes");
227 (*lcidIt).second->NotifyTxOpportunity(txOpParams);
228}
229
230void
231NrSimpleUeComponentCarrierManager::DoReceivePdu(NrMacSapUser::ReceivePduParameters rxPduParams)
232{
233 NS_LOG_FUNCTION(this);
234 auto lcidIt = m_lcAttached.find(rxPduParams.lcid);
235 NS_ABORT_MSG_IF(lcidIt == m_lcAttached.end(),
236 "could not find LCID" << (uint16_t)rxPduParams.lcid);
237 if (lcidIt != m_lcAttached.end())
238 {
239 (*lcidIt).second->ReceivePdu(rxPduParams);
240 }
241}
242
244// Ue CCM RRC SAP PROVIDER SAP forwarders
246std::vector<uint16_t>
247NrSimpleUeComponentCarrierManager::DoRemoveLc(uint8_t lcid)
248{
249 NS_LOG_FUNCTION(this << " lcId" << lcid);
250 std::vector<uint16_t> res;
251 NS_ABORT_MSG_IF(m_lcAttached.find(lcid) == m_lcAttached.end(), "could not find LCID " << lcid);
252 m_lcAttached.erase(lcid);
253
254 // send back all the configuration to the NrComponentCarrier where we want to remove the Lc
255 auto it = m_componentCarrierLcMap.begin();
256 while (it != m_componentCarrierLcMap.end())
257 {
258 auto lcToRemove = it->second.find(lcid);
259 if (lcToRemove != it->second.end())
260 {
261 res.insert(res.end(), it->first);
262 }
263 it->second.erase(lcToRemove);
264 it++;
265 }
266 NS_ABORT_MSG_IF(res.empty(),
267 "LCID " << lcid << " not found in the ComponentCarrierManager map");
268
269 return res;
270}
271
272void
273NrSimpleUeComponentCarrierManager::DoReset()
274{
275 NS_LOG_FUNCTION(this);
276 // same semantics as NrUeMac::DoRest
277 auto it = m_lcAttached.begin();
278 while (it != m_lcAttached.end())
279 {
280 // don't delete CCCH
281 if (it->first == 0)
282 {
283 ++it;
284 }
285 else
286 {
287 // note: use of postfix operator preserves validity of iterator
288 m_lcAttached.erase(it++);
289 }
290 }
291}
292
293std::vector<NrUeCcmRrcSapProvider::LcsConfig>
294NrSimpleUeComponentCarrierManager::DoAddLc(uint8_t lcId,
296 NrMacSapUser* msu)
297{
298 NS_LOG_FUNCTION(this);
299 std::vector<NrUeCcmRrcSapProvider::LcsConfig> res;
300 auto it = m_lcAttached.find(lcId);
301 NS_ABORT_MSG_IF(it != m_lcAttached.end(), "Warning, LCID " << lcId << " already exist");
302 m_lcAttached.insert(std::pair<uint8_t, NrMacSapUser*>(lcId, msu));
304 for (uint8_t ncc = 0; ncc < m_noOfComponentCarriers; ncc++)
305 {
306 elem.componentCarrierId = ncc;
307 elem.lcConfig = lcConfig;
308 elem.msu = m_ccmMacSapUser;
309 res.insert(res.end(), elem);
310
311 auto ccLcMapIt = m_componentCarrierLcMap.find(ncc);
312 if (ccLcMapIt != m_componentCarrierLcMap.end())
313 {
314 ccLcMapIt->second.insert(
315 std::pair<uint8_t, NrMacSapProvider*>(lcId, m_macSapProvidersMap.at(ncc)));
316 }
317 else
318 {
319 std::map<uint8_t, NrMacSapProvider*> empty;
320 auto ret = m_componentCarrierLcMap.insert(
321 std::pair<uint8_t, std::map<uint8_t, NrMacSapProvider*>>(ncc, empty));
322 NS_ABORT_MSG_IF(!ret.second,
323 "element already present, ComponentCarrierId already exist");
324 ccLcMapIt = m_componentCarrierLcMap.find(ncc);
325 ccLcMapIt->second.insert(
326 std::pair<uint8_t, NrMacSapProvider*>(lcId, m_macSapProvidersMap.at(ncc)));
327 }
328 }
329
330 return res;
331}
332
334NrSimpleUeComponentCarrierManager::DoConfigureSignalBearer(
335 uint8_t lcid,
337 NrMacSapUser* msu)
338{
339 NS_LOG_FUNCTION(this);
340 auto it = m_lcAttached.find(lcid);
341 // if the following assert is hit, e.g., in handover scenarios, it means
342 // the DoRest function is not called by UE RRC
343 NS_ABORT_MSG_IF(it != m_lcAttached.end(),
344 "Warning, LCID " << (uint8_t)lcid << " already exist");
345
346 m_lcAttached.insert(std::pair<uint8_t, NrMacSapUser*>(lcid, msu));
347
348 for (uint8_t ncc = 0; ncc < m_noOfComponentCarriers; ncc++)
349 {
350 auto ccLcMapIt = m_componentCarrierLcMap.find(ncc);
351 if (ccLcMapIt != m_componentCarrierLcMap.end())
352 {
353 ccLcMapIt->second.insert(
354 std::pair<uint8_t, NrMacSapProvider*>(lcid, m_macSapProvidersMap.at(ncc)));
355 }
356 else
357 {
358 std::map<uint8_t, NrMacSapProvider*> empty;
359 auto ret = m_componentCarrierLcMap.insert(
360 std::pair<uint8_t, std::map<uint8_t, NrMacSapProvider*>>(ncc, empty));
361 NS_ABORT_MSG_IF(!ret.second,
362 "element already present, ComponentCarrierId already existed");
363 ccLcMapIt = m_componentCarrierLcMap.find(ncc);
364 ccLcMapIt->second.insert(
365 std::pair<uint8_t, NrMacSapProvider*>(lcid, m_macSapProvidersMap.at(ncc)));
366 }
367 }
368
369 return m_ccmMacSapUser;
370}
371
372} // end of namespace ns3
MemberNrUeCcmRrcSapProvider class.
Component carrier manager implementation which simply does nothing.
The abstract base class of a Component Carrier Manager* for UE that operates using the component carr...
MeasResults structure.
Definition nr-rrc-sap.h:723
uint8_t measId
measure ID
Definition nr-rrc-sap.h:724
NrUeCmacSapProvider::LogicalChannelConfig lcConfig
logical channel config
uint8_t componentCarrierId
component carrier ID