5G-LENA nr-v3.3-18-g7e4df5bb
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-gnb-mac.h
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#ifndef NR_GNB_MAC_H
6#define NR_GNB_MAC_H
7
8#include "nr-ccm-mac-sap.h"
9#include "nr-gnb-cmac-sap.h"
10#include "nr-mac-pdu-info.h"
11#include "nr-mac-sap.h"
12#include "nr-mac-sched-sap.h"
13#include "nr-mac-scheduler.h"
14#include "nr-phy-mac-common.h"
15#include "nr-phy-sap.h"
16
17#include <ns3/traced-callback.h>
18
19namespace ns3
20{
21
22class NrControlMessage;
23class NrRarMessage;
24class BeamId;
25
47class NrGnbMac : public Object
48{
49 friend class NrGnbMacMemberGnbCmacSapProvider;
50 friend class NrMacGnbMemberPhySapUser;
51 friend class NrMacMemberMacCschedSapUser;
52 friend class NrMacMemberMacSchedSapUser;
55
56 public:
61 static TypeId GetTypeId();
65 NrGnbMac();
69 ~NrGnbMac() override;
70
77 void SetNumRbPerRbg(uint32_t rbgSize);
78
88 uint32_t GetNumRbPerRbg() const;
89
94 void SetNumHarqProcess(uint8_t numHarqProcess);
95
99 uint8_t GetNumHarqProcess() const;
100
105 virtual uint8_t GetDlCtrlSyms() const;
106
111 virtual uint8_t GetUlCtrlSyms() const;
112
122 virtual void DoSlotDlIndication(const SfnSf& sfnSf, LteNrTddSlotType type);
123
133 virtual void DoSlotUlIndication(const SfnSf& sfnSf, LteNrTddSlotType type);
134
139 virtual void SetCurrentSfn(const SfnSf& sfn);
140
141 void SetForwardUpCallback(Callback<void, Ptr<Packet>> cb);
142
143 NrGnbPhySapUser* GetPhySapUser();
144 void SetPhySapProvider(NrPhySapProvider* ptr);
145
146 NrMacSchedSapUser* GetNrMacSchedSapUser();
147 void SetNrMacSchedSapProvider(NrMacSchedSapProvider* ptr);
148
149 NrMacCschedSapUser* GetNrMacCschedSapUser();
150 void SetNrMacCschedSapProvider(NrMacCschedSapProvider* ptr);
151
152 NrMacSapProvider* GetMacSapProvider();
153 NrGnbCmacSapProvider* GetGnbCmacSapProvider();
154
155 void SetGnbCmacSapUser(NrGnbCmacSapUser* s);
156
162
168
174 void BeamChangeReport(BeamId beamId, uint8_t rnti);
175
190 typedef void (*SchedulingTracedCallback)(uint32_t frameNum,
191 uint32_t subframeNum,
192 uint32_t slotNum,
193 uint8_t symStart,
194 uint8_t numSym,
195 uint32_t tbSize,
196 uint32_t mcs,
197 uint32_t rnti,
198 uint8_t bwpId);
199
206 typedef void (*SrTracedCallback)(const uint8_t bwpId, const uint16_t rnti);
207
220 typedef void (*RxedGnbMacCtrlMsgsTracedCallback)(const SfnSf sfn,
221 const uint16_t nodeId,
222 const uint16_t rnti,
223 const uint8_t bwpId,
224 Ptr<NrControlMessage>);
225
238 typedef void (*TxedGnbMacCtrlMsgsTracedCallback)(const SfnSf sfn,
239 const uint16_t nodeId,
240 const uint16_t rnti,
241 const uint8_t bwpId,
242 Ptr<NrControlMessage>);
243
244 protected:
248 void DoDispose() override;
253 uint16_t GetBwpId() const;
254
259 uint16_t GetCellId() const;
260
265 std::shared_ptr<DciInfoElementTdma> GetDlCtrlDci() const;
266
271 std::shared_ptr<DciInfoElementTdma> GetUlCtrlDci() const;
272
273 private:
274 void ReceiveRachPreamble(uint32_t raId);
275 void DoReceiveRachPreamble(uint32_t raId);
276 void ReceiveBsrMessage(MacCeElement bsr);
277 void DoReportMacCeToScheduler(nr::MacCeListElement_s bsr);
282 void DoReportSrToScheduler(uint16_t rnti);
283 void DoReceivePhyPdu(Ptr<Packet> p);
284 void DoReceiveControlMessage(Ptr<NrControlMessage> msg);
285 virtual void DoSchedConfigIndication(NrMacSchedSapUser::SchedConfigIndParameters ind);
286 // forwarded from NrMacSapProvider
287 void DoTransmitPdu(NrMacSapProvider::TransmitPduParameters);
288 void DoReportBufferStatus(NrMacSapProvider::ReportBufferStatusParameters);
290 // forwarded from NrMacCchedSapUser
291 void DoCschedCellConfigCnf(NrMacCschedSapUser::CschedCellConfigCnfParameters params);
292 void DoCschedUeConfigCnf(NrMacCschedSapUser::CschedUeConfigCnfParameters params);
293 void DoCschedLcConfigCnf(NrMacCschedSapUser::CschedLcConfigCnfParameters params);
294 void DoCschedLcReleaseCnf(NrMacCschedSapUser::CschedLcReleaseCnfParameters params);
295 void DoCschedUeReleaseCnf(NrMacCschedSapUser::CschedUeReleaseCnfParameters params);
296 void DoCschedUeConfigUpdateInd(NrMacCschedSapUser::CschedUeConfigUpdateIndParameters params);
297 void DoCschedCellConfigUpdateInd(
299 // forwarded from NrGnbCmacSapProvider
300 void DoConfigureMac(uint16_t ulBandwidth, uint16_t dlBandwidth);
301 void DoAddUe(uint16_t rnti);
302 void DoRemoveUe(uint16_t rnti);
303 void DoAddLc(NrGnbCmacSapProvider::LcInfo lcinfo, NrMacSapUser* msu);
304 void DoReconfigureLc(NrGnbCmacSapProvider::LcInfo lcinfo);
305 void DoReleaseLc(uint16_t rnti, uint8_t lcid);
306 void UeUpdateConfigurationReq(NrGnbCmacSapProvider::UeConfig params);
307 NrGnbCmacSapProvider::RachConfig DoGetRachConfig();
308 NrGnbCmacSapProvider::AllocateNcRaPreambleReturnValue DoAllocateNcRaPreamble(uint16_t rnti);
309
314 void DoDlHarqFeedback(const DlHarqInfo& params);
319 void DoUlHarqFeedback(const UlHarqInfo& params);
320
329 void DoBuildRarList(SlotAllocInfo& slotAllocInfo);
330
331 private:
332 bool HasMsg3Allocations(const SlotAllocInfo& slotInfo);
333
334 struct NrDlHarqProcessInfo
335 {
336 Ptr<PacketBurst> m_pktBurst;
337 // maintain list of LCs contained in this TB
338 // used to signal HARQ failure to RLC handlers
339 std::vector<uint8_t> m_lcidList;
340 };
341
342 typedef std::vector<NrDlHarqProcessInfo> NrDlHarqProcessesBuffer_t;
343
344 NrMacSapProvider* m_macSapProvider;
345 NrGnbCmacSapProvider* m_cmacSapProvider;
346 NrGnbCmacSapUser* m_cmacSapUser;
347 NrPhySapProvider* m_phySapProvider{nullptr};
348 NrGnbPhySapUser* m_phySapUser;
349
350 NrMacSchedSapProvider* m_macSchedSapProvider;
351 NrMacSchedSapUser* m_macSchedSapUser;
352 NrMacCschedSapProvider* m_macCschedSapProvider;
353 NrMacCschedSapUser* m_macCschedSapUser;
354
355 // Sap For ComponentCarrierManager 'Uplink case'
356 NrCcmMacSapProvider* m_ccmMacSapProvider;
357 NrCcmMacSapUser* m_ccmMacSapUser;
358
359 int32_t m_numRbPerRbg{-1};
360
361 uint8_t m_numHarqProcess{20};
362
363 std::unordered_map<uint32_t, struct NrMacPduInfo> m_macPduMap;
364
365 Callback<void, Ptr<Packet>> m_forwardUpCallback;
366
367 std::vector<DlCqiInfo> m_dlCqiReceived;
368 std::vector<NrMacSchedSapProvider::SchedUlCqiInfoReqParameters> m_ulCqiReceived;
369 std::vector<MacCeElement> m_ulCeReceived; // CE received (BSR up to now)
370
371 // start of RACH related member variables
372 uint8_t m_numberOfRaPreambles;
373 uint8_t m_preambleTransMax;
374 uint8_t m_raResponseWindowSize;
375 uint8_t m_connEstFailCount;
376
381 struct NcRaPreambleInfo
382 {
383 uint16_t rnti;
384 Time expiryTime;
386 };
387
393 std::map<uint8_t, NcRaPreambleInfo> m_allocatedNcRaPreambleMap;
394 std::map<uint8_t, uint32_t> m_receivedRachPreambleCount;
395 // end of RACH related member variables
396
397 std::unordered_map<uint16_t, std::unordered_map<uint8_t, NrMacSapUser*>> m_rlcAttached;
398
399 std::vector<DlHarqInfo> m_dlHarqInfoReceived; // DL HARQ feedback received
400 std::vector<UlHarqInfo> m_ulHarqInfoReceived; // UL HARQ feedback received
401 std::unordered_map<uint16_t, NrDlHarqProcessesBuffer_t>
402 m_miDlHarqProcessesPackets; // Packet under transmission of the DL HARQ process
403
404 TracedCallback<NrSchedulingCallbackInfo> m_dlScheduling;
405 TracedCallback<NrSchedulingCallbackInfo> m_ulScheduling;
406
407 std::list<uint16_t> m_srRntiList;
408
409 std::unordered_map<uint8_t, uint32_t> m_rapIdRntiMap;
410
411 TracedCallback<uint8_t, uint16_t> m_srCallback;
412
413 uint16_t m_bandwidthInRbg{0};
414
415 SfnSf m_currentSlot;
416
422 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
423 m_macRxedCtrlMsgsTrace;
424
430 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
431 m_macTxedCtrlMsgsTrace;
432
436 TracedCallback<const DlHarqInfo&> m_dlHarqFeedback;
437
438 void ProcessRaPreambles(const SfnSf& sfnSf);
439 void SetNumberOfRaPreambles(uint8_t numberOfRaPreambles);
440 void SetPreambleTransMax(uint8_t preambleTransMax);
441 void SetRaResponseWindowSize(uint8_t raResponseWindowSize);
442 void SetConnEstFailCount(uint8_t connEstFailCount);
443};
444
445} // namespace ns3
446
447#endif /* NR_GNB_MAC_H */
Representation of a beam id.
Definition beam-id.h:26
GnbMacMemberNrMacSapProvider class.
Definition nr-mac-sap.h:190
MemberNrCcmMacSapProvider class.
Service Access Point (SAP) offered by the component carrier manager (CCM) by MAC to CCM.
Service Access Point (SAP) offered by MAC to the component carrier manager (CCM).
The MAC class for the gnb.
Definition nr-gnb-mac.h:48
virtual uint8_t GetUlCtrlSyms() const
Retrieve the number of UL ctrl symbols configured in the scheduler.
uint8_t GetNumHarqProcess() const
NrCcmMacSapProvider * GetNrCcmMacSapProvider()
Get the gNB-ComponentCarrierManager SAP User.
virtual void DoSlotDlIndication(const SfnSf &sfnSf, LteNrTddSlotType type)
Perform DL scheduling decision for the indicated slot.
void(* SrTracedCallback)(const uint8_t bwpId, const uint16_t rnti)
Definition nr-gnb-mac.h:206
void(* RxedGnbMacCtrlMsgsTracedCallback)(const SfnSf sfn, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-gnb-mac.h:220
std::shared_ptr< DciInfoElementTdma > GetUlCtrlDci() const
Get a DCI for the UL CTRL symbol.
uint16_t GetBwpId() const
Get the bwp id of this MAC.
void SetNumRbPerRbg(uint32_t rbgSize)
Sets the number of RBs per RBG. Currently it can be configured by the user, while in the future it wi...
void(* SchedulingTracedCallback)(uint32_t frameNum, uint32_t subframeNum, uint32_t slotNum, uint8_t symStart, uint8_t numSym, uint32_t tbSize, uint32_t mcs, uint32_t rnti, uint8_t bwpId)
Definition nr-gnb-mac.h:190
void SetNumHarqProcess(uint8_t numHarqProcess)
Sets the number of HARQ processes.
void SetNrCcmMacSapUser(NrCcmMacSapUser *s)
Set the ComponentCarrierManager SAP user.
~NrGnbMac() override
~NrGnbMac
std::shared_ptr< DciInfoElementTdma > GetDlCtrlDci() const
Get a DCI for the DL CTRL symbol.
void BeamChangeReport(BeamId beamId, uint8_t rnti)
A Beam for a user has changed.
NrGnbMac()
NrGnbMac constructor.
uint16_t GetCellId() const
Get the cell id of this MAC.
uint32_t GetNumRbPerRbg() const
virtual void SetCurrentSfn(const SfnSf &sfn)
Set the current sfn.
virtual void DoSlotUlIndication(const SfnSf &sfnSf, LteNrTddSlotType type)
Perform UL scheduling decision for the indicated slot.
virtual uint8_t GetDlCtrlSyms() const
Retrieve the number of DL ctrl symbols configured in the scheduler.
static TypeId GetTypeId()
Get the TypeId.
void(* TxedGnbMacCtrlMsgsTracedCallback)(const SfnSf sfn, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-gnb-mac.h:238
void DoDispose() override
DoDispose method inherited from Object.
SAP interface between the gNB PHY and the gNB MAC.
Definition nr-phy-sap.h:155
Provides the CSCHED SAP.
The SAP interface between MAC and scheduler.
The Interface between Scheduler and MAC.
SAP interface between the MAC and the PHY.
Definition nr-phy-sap.h:36
The SfnSf class.
Definition sfnsf.h:32
LteNrTddSlotType
Available TDD slot types. Ordering is important.
A struct that contains info for the DL HARQ.
See section 4.3.14 macCEListElement.
AllocateNcRaPreambleReturnValue structure.
Parameters for [re]configuring the UE.
The SchedConfigIndParameters struct.
The SlotAllocInfo struct.
A struct that contains info for the UL HARQ.
See section 4.3.14 macCEListElement.