5G-LENA nr-v4.0-29-g6d8085cd
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-ue-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_UE_MAC_H
6#define NR_UE_MAC_H
7
8#include "nr-ccm-mac-sap.h"
9#include "nr-phy-mac-common.h"
10#include "nr-ue-cmac-sap.h"
11
12#include "ns3/traced-callback.h"
13
14#include <unordered_map>
15
16namespace ns3
17{
18
19class NrUePhySapUser;
20class NrPhySapProvider;
21class NrControlMessage;
22class UniformRandomVariable;
23class PacketBurst;
24class NrUlDciMessage;
25
103class NrUeMac : public Object
104{
105 friend class UeMemberNrUeCmacSapProvider;
106 friend class UeMemberNrMacSapProvider;
107 friend class MacUeMemberPhySapUser;
108
109 public:
114 static TypeId GetTypeId();
115
119 NrUeMac();
123 ~NrUeMac() override;
124
143 enum SrBsrMachine : uint8_t
144 {
147 ACTIVE
148 };
149
155
161
167
173
179
188 typedef void (*RxedUeMacCtrlMsgsTracedCallback)(const SfnSf sfnSf,
189 const uint16_t nodeId,
190 const uint16_t rnti,
191 const uint8_t bwpId,
192 Ptr<NrControlMessage> ctrlMessage);
201 typedef void (*TxedUeMacCtrlMsgsTracedCallback)(const SfnSf sfnSf,
202 const uint16_t nodeId,
203 const uint16_t rnti,
204 const uint8_t bwpId,
205 Ptr<NrControlMessage> ctrlMessage);
206
219 const SfnSf sfnSf,
220 const uint16_t nodeId,
221 const uint16_t rnti,
222 const uint8_t bwpId,
223 const enum SrBsrMachine srState,
224 std::unordered_map<uint8_t, NrMacSapProvider::BufferStatusReportParameters> ulBsrReceived,
225 int retx,
226 std::string nameFunc);
227
233 void SetNumHarqProcess(uint8_t numHarqProcesses);
234
241 uint8_t GetNumHarqProcess() const;
242
247 uint16_t GetBwpId() const;
248
253 uint16_t GetCellId() const;
254
259 uint16_t GetRnti() const;
260
265 uint64_t GetImsi() const;
266
275 int64_t AssignStreams(int64_t stream);
276
277 protected:
281 void DoDispose() override;
282
287 void SetCurrentSlot(const SfnSf& sfn);
288
298 virtual int64_t DoAssignStreams(int64_t stream);
299
300 private:
305 void RecvRaResponse(NrBuildRarListElement_s raResponse);
309 void SetRnti(uint16_t);
314 virtual void DoSlotIndication(const SfnSf& sfn);
315
320 uint32_t GetTotalBufSize() const __attribute__((warn_unused_result));
321
325 void SendSR() const;
338 void DoTransmitPdu(NrMacSapProvider::TransmitPduParameters params);
339
350 void DoTransmitBufferStatusReport(NrMacSapProvider::BufferStatusReportParameters params);
351
352 // forwarded from PHY SAP
353 void DoReceivePhyPdu(Ptr<Packet> p);
354 void DoReceiveControlMessage(Ptr<NrControlMessage> msg);
355 // void DoNotifyHarqDeliveryFailure (uint8_t harqId);
356 void RaResponseTimeout(bool contention);
357
358 // forwarded from UE CMAC SAP
359 void DoConfigureRach(NrUeCmacSapProvider::RachConfig rc);
360 void DoStartContentionBasedRandomAccessProcedure();
361 void DoStartNonContentionBasedRandomAccessProcedure(uint16_t rnti,
362 uint8_t rapId,
363 uint8_t prachMask);
364 void AddLc(uint8_t lcId, NrUeCmacSapProvider::LogicalChannelConfig lcConfig, NrMacSapUser* msu);
365 void DoRemoveLc(uint8_t lcId);
366 void DoReset();
367 void DoNotifyConnectionSuccessful();
368 void DoSetImsi(uint64_t imsi);
369
370 void RandomlySelectAndSendRaPreamble();
371 void SendRaPreamble(bool contention);
372
381 void SendBufferStatusReport(const SfnSf& dataSfn, uint8_t symStart);
382 void RefreshHarqProcessesPacketBuffer();
383
394 void ProcessUlDci(const Ptr<NrUlDciMessage>& dciMsg);
395
403 void TransmitRetx();
404
416 void SendNewData();
417
424 void SendNewStatusData();
425
437 void SendRetxData(uint32_t usefulTbs, uint32_t activeRetx);
438
450 void SendTxData(uint32_t usefulTbs, uint32_t activeTx);
451
452 private:
453 NrUeCmacSapUser* m_cmacSapUser{nullptr};
454 NrUeCmacSapProvider* m_cmacSapProvider{nullptr};
455 NrPhySapProvider* m_phySapProvider{nullptr};
456 NrUePhySapUser* m_phySapUser{nullptr};
457 NrMacSapProvider* m_macSapProvider{nullptr};
458
459 SfnSf m_currentSlot;
460 uint8_t m_numHarqProcess{20};
461
462 std::shared_ptr<DciInfoElementTdma>
463 m_ulDci;
464 SfnSf m_ulDciSfnsf;
465 uint32_t m_ulDciTotalUsed{0};
466
467 std::unordered_map<uint8_t, NrMacSapProvider::BufferStatusReportParameters>
468 m_ulBsrReceived;
469
470 SrBsrMachine m_srState{INACTIVE};
471
472 Ptr<UniformRandomVariable> m_raPreambleUniformVariable;
473 uint8_t m_raPreambleId{0};
474 uint8_t m_raRnti{0};
475 uint64_t m_imsi{0};
476
477 // The HARQ part has to be reviewed
478 struct UlHarqProcessInfo
479 {
480 Ptr<PacketBurst> m_pktBurst;
481 // maintain list of LCs contained in this TB
482 // used to signal HARQ failure to RLC handlers
483 std::vector<uint8_t> m_lcidList;
484 };
485
486 // uint8_t m_harqProcessId;
487 std::vector<UlHarqProcessInfo>
488 m_miUlHarqProcessesPacket;
489 std::vector<uint8_t> m_miUlHarqProcessesPacketTimer;
490
491 struct LcInfo
492 {
493 NrUeCmacSapProvider::LogicalChannelConfig lcConfig;
494 NrMacSapUser* macSapUser;
495 };
496
497 std::unordered_map<uint8_t, LcInfo> m_lcInfoMap;
498 uint16_t m_rnti{std::numeric_limits<uint16_t>::max()};
499
500 bool m_waitingForRaResponse{true};
501 static uint8_t g_raPreambleId;
502
508 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
509 m_macRxedCtrlMsgsTrace;
510
516 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
517 m_macTxedCtrlMsgsTrace;
518
524 TracedCallback<uint64_t, bool, uint8_t, uint8_t> m_raResponseTimeoutTrace;
525
531 TracedCallback<SfnSf,
532 uint16_t,
533 uint16_t,
534 uint8_t,
536 std::unordered_map<uint8_t, NrMacSapProvider::BufferStatusReportParameters>,
537 int,
538 std::string>
539 m_macUeStateMachine;
540
541 void StartWaitingForRaResponse();
542 bool m_rachConfigured = false;
543 NrUeCmacSapProvider::RachConfig m_rachConfig;
544 uint8_t m_preambleTransmissionCounter{0};
545 EventId m_noRaResponseReceivedEvent;
546};
547
548} // namespace ns3
549
550#endif /* NR_UE_MAC_H */
The NrControlMessage class.
SAP interface between the MAC and the PHY.
Definition nr-phy-sap.h:36
The MAC class for the UE.
Definition nr-ue-mac.h:104
void SetCurrentSlot(const SfnSf &sfn)
Set the frame/subframe/slot counter.
Definition nr-ue-mac.cc:323
void(* UeMacStateMachineTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, const enum SrBsrMachine srState, std::unordered_map< uint8_t, NrMacSapProvider::BufferStatusReportParameters > ulBsrReceived, int retx, std::string nameFunc)
Definition nr-ue-mac.h:218
NrUePhySapUser * GetPhySapUser()
Get the PHY SAP User (AKA the MAC representation for the PHY)
uint64_t GetImsi() const
Get the IMSI.
Definition nr-ue-mac.cc:317
void DoDispose() override
DoDispose method inherited from Object.
Definition nr-ue-mac.cc:251
void SetPhySapProvider(NrPhySapProvider *ptr)
Set PHY SAP provider (AKA the PHY representation for the MAC)
uint8_t GetNumHarqProcess() const
Please remember that this number is obtained by the GNB, the UE cannot configure it.
Definition nr-ue-mac.cc:364
static TypeId GetTypeId()
Get the Type id.
Definition nr-ue-mac.cc:205
void(* TxedUeMacCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage > ctrlMessage)
Definition nr-ue-mac.h:201
NrMacSapProvider * GetUeMacSapProvider()
Get the Mac SAP provider (AKA the MAC representation for the RLC)
virtual int64_t DoAssignStreams(int64_t stream)
NrUeMac()
NrUeMac constructor.
Definition nr-ue-mac.cc:236
void SetNumHarqProcess(uint8_t numHarqProcesses)
Sets the number of HARQ processes. Called by the helper at the moment of UE attachment.
Definition nr-ue-mac.cc:344
NrUeCmacSapProvider * GetUeCmacSapProvider()
Get the C MAC SAP provider (AKA the MAC representation for the RRC)
Definition nr-ue-mac.cc:569
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model....
void(* RxedUeMacCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage > ctrlMessage)
Definition nr-ue-mac.h:188
uint16_t GetCellId() const
Get the cell id of this MAC.
Definition nr-ue-mac.cc:298
uint16_t GetBwpId() const
Get the bwp id of this MAC.
Definition nr-ue-mac.cc:285
uint16_t GetRnti() const
Get the RNTI.
Definition nr-ue-mac.cc:311
void SetUeCmacSapUser(NrUeCmacSapUser *s)
Set the C MAC SAP user (AKA the RRC representation for the MAC)
Definition nr-ue-mac.cc:563
~NrUeMac() override
Deconstructor.
Definition nr-ue-mac.cc:246
SrBsrMachine
States for the SR/BSR mechanism.
Definition nr-ue-mac.h:144
@ INACTIVE
no SR nor BSR.. initial state
Definition nr-ue-mac.h:145
@ TO_SEND
We have to send the BSR when possible.
Definition nr-ue-mac.h:146
@ ACTIVE
SR or BSR sent; now the source of information is the vector m_bsrReservedSpace.
Definition nr-ue-mac.h:147
SAP interface between the UE PHY and the UE MAC.
Definition nr-phy-sap.h:264
The message that represents a UL DCI message.
The SfnSf class.
Definition sfnsf.h:32