9#include "nr-harq-phy.h"
10#include "nr-phy-sap.h"
12#include "nr-pm-search.h"
13#include "nr-ue-cphy-sap.h"
15#include <ns3/traced-callback.h>
20extern const Time NR_DEFAULT_PMI_INTERVAL_WB;
21extern const Time NR_DEFAULT_PMI_INTERVAL_SB;
23class NrChAccessManager;
26class NrUePowerControl;
61 friend class UeMemberNrUePhySapProvider;
105 void SetEnableUplinkPowerControl(
bool enable);
189 void SetDlAmc(
const Ptr<const NrAmc>& amc);
262 uint16_t
GetRnti()
const __attribute__((warn_unused_result));
314 const uint16_t nodeId,
317 Ptr<NrControlMessage> ptr);
329 const uint16_t nodeId,
332 Ptr<NrControlMessage>);
348 const uint16_t nodeId,
368 const uint16_t nodeId,
378 void SetCam(
const Ptr<NrChAccessManager>& cam);
398 uint16_t slot)
override;
421 uint8_t
ComputeCqi(
const SpectrumValue& sinr);
429 void ReceivePss(uint16_t cellId,
const Ptr<SpectrumValue>& p);
446 Ptr<const SpectrumValue> v,
474 uint8_t componentCarrierId);
489 void CsiRsReceived(
const std::vector<MimoSignalChunk>& csiRsSignal);
510 void CsiImEnded(
const std::vector<MimoSignalChunk>& csiImSignalChunks);
608 void ReportUeMeasurements();
614 void SetCsiFeedbackType(uint8_t csiFeedbackType);
621 static double ComputeAvgSinr(
const SpectrumValue& sinr);
623 void StartEventLoop(uint16_t frame, uint8_t subframe, uint16_t slot);
630 void ChannelAccessGranted(
const Time& time);
635 void ChannelAccessDenied();
640 void RequestAccess();
646 void DoReceiveRar(Ptr<NrRarMessage> rarMsg);
652 Ptr<NrDlCqiMessage> CreateDlCqiFeedbackMessage(
const SpectrumValue& sinr)
653 __attribute__((warn_unused_result));
659 Time DlCtrl(
const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
665 Time UlCtrl(
const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
671 Time UlSrs(
const std::shared_ptr<DciInfoElementTdma>& dci);
677 Time DlData(
const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
684 Time UlData(
const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
693 void TryToPerformLbt();
699 virtual void StartSlot(
const SfnSf& s);
716 void StartVarTti(
const std::shared_ptr<DciInfoElementTdma>& dci);
730 void EndVarTti(
const std::shared_ptr<DciInfoElementTdma>& dci);
736 void DoSendControlMessage(Ptr<NrControlMessage> msg);
741 void DoSendControlMessageNow(Ptr<NrControlMessage> msg);
748 void ProcessDataDci(
const SfnSf& ulSfnSf,
749 const std::shared_ptr<DciInfoElementTdma>& dciInfoElem);
756 void ProcessSrsDci(
const SfnSf& ulSfnSf,
757 const std::shared_ptr<DciInfoElementTdma>& dciInfoElem);
766 void SendDataChannels(
const Ptr<PacketBurst>& pb,
767 const std::list<Ptr<NrControlMessage>>& ctrlMsg,
768 const std::shared_ptr<DciInfoElementTdma>& dci,
769 const Time& duration);
777 void SendCtrlChannels(Time duration);
780 virtual void DoReset();
781 void DoStartCellSearch(uint16_t dlEarfcn);
782 void DoSynchronizeWithGnb(uint16_t cellId);
783 void DoSynchronizeWithGnb(uint16_t cellId, uint16_t dlEarfcn);
784 void DoSetPa(
double pa);
791 void DoSetRsrpFilterCoefficient(uint8_t rsrpFilterCoefficient);
797 void DoSetInitialBandwidth();
803 uint16_t DoGetCellId()
const;
808 uint32_t DoGetDlEarfcn();
813 void DoSetDlBandwidth(uint16_t ulBandwidth);
818 void DoConfigureUplink(uint16_t ulEarfcn, uint8_t ulBandwidth);
819 void DoConfigureReferenceSignalPower(int8_t referenceSignalPower);
820 void DoSetRnti(uint16_t rnti);
821 void DoSetTransmissionMode(uint8_t txMode);
822 void DoSetSrsConfigurationIndex(uint16_t srcCi);
830 void DoResetPhyAfterRlf();
839 void DoResetRlfParams();
841 void InitializeRlfParams();
843 void RlfDetection(
double sinrDb);
854 void DoStartInSyncDetection();
861 void DoSetImsi(uint64_t imsi);
871 void PushCtrlAllocations(
const SfnSf currentSfnSf);
877 void InsertAllocation(
const std::shared_ptr<DciInfoElementTdma>& dci);
883 void InsertFutureAllocation(
const SfnSf& sfnSf,
const std::shared_ptr<DciInfoElementTdma>& dci);
894 void SendRachPreamble(uint32_t PreambleId, uint32_t Rnti)
override;
903 void ProcessRar(
const Ptr<NrRarMessage>& rarMsg);
909 bool m_enableUplinkPowerControl{
911 Ptr<NrUePowerControl> m_powerControl;
913 Ptr<const NrAmc> m_amc;
915 Ptr<NrPmSearch> m_pmSearch{
nullptr};
917 Time m_sbPmiLastUpdate{};
918 Time m_wbPmiLastUpdate{};
919 Time m_wbPmiUpdateInterval{NR_DEFAULT_PMI_INTERVAL_WB};
920 Time m_sbPmiUpdateInterval{NR_DEFAULT_PMI_INTERVAL_SB};
923 Time m_lastSlotStart;
925 bool m_ulConfigured{
false};
926 bool m_receptionEnabled{
false};
928 uint32_t m_currTbs{0};
930 std::unordered_map<uint8_t, uint32_t>
933 int64_t m_numRbPerRbg{
949 ChannelStatus m_channelStatus{NONE};
950 Ptr<NrChAccessManager> m_cam;
951 Time m_lbtThresholdForCtrl;
952 bool m_tryToPerformLbt{
false};
954 uint8_t m_dlCtrlSyms{1};
955 uint8_t m_ulCtrlSyms{1};
960 struct UeMeasurementsElement
973 std::map<uint16_t, UeMeasurementsElement> m_ueMeasurementsMap;
978 Time m_ueMeasurementsFilterPeriod;
980 NrMimoSignal m_csiRsMimoSignal;
981 Time m_lastCsiRsMimoSignalTime{Seconds(0.0)};
982 NrCovMat m_avgIntCovMat;
983 double m_alphaCovMat = {0.1};
984 uint8_t m_csiImDuration = {1};
989 TracedCallback<uint16_t, uint16_t, double, uint16_t> m_dlDataSinrTrace;
994 TracedCallback<uint16_t, uint16_t, double, uint16_t> m_dlCtrlSinrTrace;
995 TracedCallback<uint64_t, uint64_t> m_reportUlTbSize;
996 TracedCallback<uint64_t, uint64_t> m_reportDlTbSize;
997 TracedCallback<
const SfnSf&,
998 Ptr<const SpectrumValue>,
1004 m_reportPowerSpectralDensity;
1010 TracedCallback<uint16_t, uint8_t, uint8_t, uint8_t> m_cqiFeedbackTrace;
1016 TracedCallback<uint16_t, uint16_t, uint16_t, double, uint8_t> m_reportRsrpTrace;
1023 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
1024 m_phyRxedCtrlMsgsTrace;
1031 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
1032 m_phyTxedCtrlMsgsTrace;
1039 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, uint8_t, uint32_t> m_phyUeRxedDlDciTrace;
1046 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, uint8_t, uint32_t>
1047 m_phyUeTxedHarqFeedbackTrace;
1055 TracedCallback<uint16_t, uint16_t, double, double, bool, uint8_t> m_reportUeMeasurements;
1058 void DoNotifyConnectionSuccessful();
1073 uint16_t m_numOfQoutEvalSf;
1075 uint16_t m_numOfQinEvalSf;
1077 bool m_downlinkInSync;
1079 uint16_t m_numOfSubframes;
1081 uint16_t m_numOfFrames;
1083 double m_sinrDbFrame;
1084 SpectrumValue m_ctrlSinrForRlf;
1085 bool m_enableRlfDetection;
1086 uint8_t m_csiFeedbackType;
Representation of a beam id.
Helper to set up single- or multi-cell scenarios with NR.
The base class for gNb and UE physical layer.
void SetUplinkPowerControl(Ptr< NrUePowerControl > pc)
Allow configuration of uplink power control algorithm. E.g. necessary in FDD, when measurements are r...
void SetPhySapUser(NrUePhySapUser *ptr)
Install the PHY sap user (AKA the UE MAC)
void ReportRsrpSinrTrace(const SpectrumValue &sinr)
Report the SINR value in the RSRP and SINR trace. In OSS code, this functionality is piggy-backed ont...
void ScheduleStartEventLoop(uint32_t nodeId, uint16_t frame, uint8_t subframe, uint16_t slot) override
Start the ue Event Loop.
void ReceivePss(uint16_t cellId, const Ptr< SpectrumValue > &p)
Receive PSS and calculate RSRQ in dBm.
void CalcAvgIntCovMat(NrCovMat *avgIntCovMat, const NrCovMat &newCovMat) const
Calculates the moving average of the interference covariance matrix.
uint8_t GetCsiImDuration() const
void EnqueueDlHarqFeedback(const DlHarqInfo &m)
Get the HARQ feedback (on the transmission) from NrSpectrumPhy and send it through ideal PUCCH to gNB...
void SetTxPower(double pow)
Set the transmission power for the UE.
void SetSubChannelsForTransmission(const std::vector< int > &mask, uint32_t numSym)
Set the Tx power spectral density based on the RB index vector.
NrUePhy()
NrUePhy default constructor.
void SetNumRbPerRbg(uint32_t numRbPerRbg)
Function that sets the number of RBs per RBG. This function will be soon deprecated,...
BeamId GetBeamId(uint16_t rnti) const override
Get the beam id for the specified user.
NrUePhySapUser * GetPhySapUser() const
Get pointer to PhySapUser.
~NrUePhy() override
~NrUePhy
Ptr< NrPmSearch > GetPmSearch() const
Get the precoding matrix search engine.
void GenerateCsiRsCqi()
Function that will be called in the case that CSI-RS is received, but CSI-IM is disabled and there is...
void CsiRsReceived(const std::vector< MimoSignalChunk > &csiRsSignal)
A callback function that is called from NrMimoChunkProcessor when CSI-RS is being received....
void(* TxedUePhyHarqFeedbackTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, uint8_t harqId, uint32_t K1Delay)
NrPmSearch::PmiUpdate CheckUpdatePmi()
Check if updates to wideband and/or subband PMI are necessary. This function is used to limit the fre...
void SetPmSearch(Ptr< NrPmSearch > pmSearch)
Set the precoding matrix search engine.
uint32_t GetNumRbPerRbg() const override
NrUeCphySapProvider * GetUeCphySapProvider() __attribute__((warn_unused_result))
Retrieve the pointer for the C PHY SAP provider (AKA the PHY interface towards the RRC)
void(* TxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Time GetLastSlotStart() const
Get Time of last slot start.
uint8_t ComputeCqi(const SpectrumValue &sinr)
Compute the CQI based on the SINR.
void(* CqiFeedbackTracedCallback)(uint16_t, uint8_t, uint8_t, uint8_t)
void SetAlphaCovMat(double alpha)
Set alpha parameter for the calculation of the CSI interference covariance matrix moving average.
void SetDlAmc(const Ptr< const NrAmc > &amc)
Set the AMC pointer from the GNB.
double GetTxPower() const override
Retrieve the TX power of the UE.
void(* RxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage > ptr)
void(* RxedUePhyDlDciTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, uint8_t harqId, uint32_t K1Delay)
void SetCsiImDuration(uint8_t csiImDuration)
Sets CSI-IM duration in the number of OFDM symbols, if enabled.
void SetDlCtrlSyms(uint8_t dlCtrlSyms)
Set the number of DL CTRL symbols.
uint8_t GetCsiFeedbackType() const
double GetRsrp() const
Returns the latest measured RSRP value Called by NrUePowerControl.
void DoDispose() override
DoDispose method inherited from Object.
Ptr< NrUePowerControl > GetUplinkPowerControl() const
Get NR uplink power control entity.
void GenerateDlCqiReportMimo(const NrMimoSignal &cqiMimoFeedbackSignal, NrPmSearch::PmiUpdate pmiUpdateParams)
Generate DL CQI, PMI, and RI (channel quality precoding matrix and rank indicators)
void(* RsrpRsrqTracedCallback)(uint16_t rnti, uint16_t cellId, double rsrp, double rsrq, bool isServingCell, uint8_t componentCarrierId)
void SetCurrentSfnSf(const SfnSf ¤tSfnSf)
Set current SfnSf.
void GenerateDlCqiReport(const SpectrumValue &sinr)
Generate a DL CQI report.
void SetCam(const Ptr< NrChAccessManager > &cam)
Set the channel access manager interface for this instance of the PHY.
void SetPattern(const std::string &pattern)
Set the UE pattern.
void(* DlCtrlSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t)
void(* DlDataSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t)
void SetUlCtrlSyms(uint8_t ulCtrlSyms)
Set the number of UL CTRL symbols.
uint16_t GetRnti() const __attribute__((warn_unused_result))
Get the current RNTI of the user.
void RegisterToGnb(uint16_t bwpId)
Register the UE to a certain Gnb.
void FinishSlotProcessing(const SfnSf &s, bool nrAllocationExists)
Finish the StartSlot processing.
const SfnSf & GetCurrentSfnSf() const override
Get the current SfnSf.
void SetUeCphySapUser(NrUeCphySapUser *s)
Install ue C PHY SAP user (AKA the PHY interface towards the RRC)
void PhyCtrlMessagesReceived(const Ptr< NrControlMessage > &msg)
Receive a list of CTRL messages.
double GetAlphaCovMat() const
void TriggerDlCqiGeneration(const NrMimoSignal &csiFeedbackSignal, NrPmSearch::PmiUpdate pmiUpdateParams)
Function is called in different possible scenarios to generate CQI information. For example,...
void(* PowerSpectralDensityTracedCallback)(const SfnSf &sfnSf, Ptr< const SpectrumValue > v, const Time &time, uint16_t rnti, uint64_t imsi, uint16_t bwpId, uint16_t cellId)
TracedCallback signature for power trace source.
void PdschMimoReceived(const std::vector< MimoSignalChunk > &pdschMimoChunks)
Function is called when PDSCH is received by the UE. It contains the channel and interference informa...
void SetLastSlotStart(Time startTime)
Set last slot start.
void ReportDlCtrlSinr(const SpectrumValue &sinr)
Called when DlCtrlSinr is fired.
void PhyDataPacketReceived(const Ptr< Packet > &p)
Receive a PHY data packet.
void ReportRsReceivedPower(const SpectrumValue &power)
Called when rsReceivedPower is fired.
void CsiImEnded(const std::vector< MimoSignalChunk > &csiImSignalChunks)
Function is called when CSI-IM finishes, and this function triggers the update of the interference co...
static TypeId GetTypeId()
Get the object TypeId.
SAP interface between the UE PHY and the UE MAC.
A struct that contains info for the DL HARQ.
Helper struct for processing and storing received signals for use in CSI feedback.
Parameters that define if PMI should be updated or if previous PMI values are used.