5G-LENA nr-v3.0-32-g83aee33
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-ue-phy.h
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#ifndef NR_UE_PHY_H
8#define NR_UE_PHY_H
9
10#include "nr-amc.h"
11#include "nr-harq-phy.h"
12#include "nr-phy.h"
13#include "nr-pm-search.h"
14
15#include <ns3/lte-ue-cphy-sap.h>
16#include <ns3/lte-ue-phy-sap.h>
17#include <ns3/traced-callback.h>
18
19namespace ns3
20{
21
22extern const Time NR_DEFAULT_PMI_INTERVAL_WB; // Wideband PMI update interval
23extern const Time NR_DEFAULT_PMI_INTERVAL_SB; // Subband PMI update interval
24
25class NrChAccessManager;
26class BeamManager;
27class BeamId;
28class NrUePowerControl;
29
61class NrUePhy : public NrPhy
62{
63 friend class UeMemberLteUePhySapProvider;
64 friend class MemberLteUeCphySapProvider<NrUePhy>;
65
66 public:
71 static TypeId GetTypeId();
72
76 NrUePhy();
77
81 ~NrUePhy() override;
82
87 LteUeCphySapProvider* GetUeCphySapProvider() __attribute__((warn_unused_result));
88
93 void SetUeCphySapUser(LteUeCphySapUser* s);
94
100 void SetPhySapUser(NrUePhySapUser* ptr);
101
102 /*
103 * \brief Enable or disable uplink power control
104 * \param enable parameter that enables or disables power control
105 */
106 void SetEnableUplinkPowerControl(bool enable);
107
114 void SetTxPower(double pow);
115
122 double GetTxPower() const override;
123
128 double GetRsrp() const;
129
135 Ptr<NrUePowerControl> GetUplinkPowerControl() const;
136
148 void SetUplinkPowerControl(Ptr<NrUePowerControl> pc);
149
159 void RegisterToEnb(uint16_t bwpId);
160
171 void SetDlAmc(const Ptr<const NrAmc>& amc);
172
181 void SetUlCtrlSyms(uint8_t ulCtrlSyms);
182
191 void SetDlCtrlSyms(uint8_t dlCtrlSyms);
192
202 void SetNumRbPerRbg(uint32_t numRbPerRbg);
203
210 void SetPattern(const std::string& pattern);
211
219 void PhyCtrlMessagesReceived(const Ptr<NrControlMessage>& msg);
220
228 void PhyDataPacketReceived(const Ptr<Packet>& p);
229
237 void GenerateDlCqiReport(const SpectrumValue& sinr);
238
244 uint16_t GetRnti() const __attribute__((warn_unused_result));
245
254 void EnqueueDlHarqFeedback(const DlHarqInfo& m);
255
264 typedef void (*DlCtrlSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t);
265
274 typedef void (*DlDataSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t);
275
288 typedef void (*RxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf,
289 const uint16_t nodeId,
290 const uint16_t rnti,
291 const uint8_t bwpId,
292 Ptr<NrControlMessage>);
293
306 typedef void (*TxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf,
307 const uint16_t nodeId,
308 const uint16_t rnti,
309 const uint8_t bwpId,
310 Ptr<NrControlMessage>);
311
325 typedef void (*RxedUePhyDlDciTracedCallback)(const SfnSf sfnSf,
326 const uint16_t nodeId,
327 const uint16_t rnti,
328 const uint8_t bwpId,
329 uint8_t harqId,
330 uint32_t K1Delay);
331
345 typedef void (*TxedUePhyHarqFeedbackTracedCallback)(const SfnSf sfnSf,
346 const uint16_t nodeId,
347 const uint16_t rnti,
348 const uint8_t bwpId,
349 uint8_t harqId,
350 uint32_t K1Delay);
351
356 void SetCam(const Ptr<NrChAccessManager>& cam);
357
358 const SfnSf& GetCurrentSfnSf() const override;
359
360 // From nr phy. Not used in the UE
361 BeamId GetBeamId(uint16_t rnti) const override;
362
373 void ScheduleStartEventLoop(uint32_t nodeId,
374 uint16_t frame,
375 uint8_t subframe,
376 uint16_t slot) override;
377
382 void ReportRsReceivedPower(const SpectrumValue& power);
383
388 void ReportDlCtrlSinr(const SpectrumValue& sinr);
389
399 uint8_t ComputeCqi(const SpectrumValue& sinr);
400
407 void ReceivePss(uint16_t cellId, const Ptr<SpectrumValue>& p);
408
423 typedef void (*PowerSpectralDensityTracedCallback)(const SfnSf& sfnSf,
424 Ptr<const SpectrumValue> v,
425 const Time& time,
426 uint16_t rnti,
427 uint64_t imsi,
428 uint16_t bwpId,
429 uint16_t cellId);
430
435 void ReportRsrpSinrTrace(const SpectrumValue& sinr);
436
439 void GenerateDlCqiReportMimo(const std::vector<MimoSignalChunk>& mimoChunks);
440
445
448 void SetPmSearch(Ptr<NrPmSearch> pmSearch);
449
451 Ptr<NrPmSearch> GetPmSearch() const;
452
453 protected:
457 void DoDispose() override;
458 uint32_t GetNumRbPerRbg() const override;
459
460 private:
469 void ReportUeMeasurements();
470
476 static double ComputeAvgSinr(const SpectrumValue& sinr);
477
478 void StartEventLoop(uint16_t frame, uint8_t subframe, uint16_t slot);
479
485 void ChannelAccessGranted(const Time& time);
486
490 void ChannelAccessDenied();
491
495 void RequestAccess();
496
501 void DoReceiveRar(Ptr<NrRarMessage> rarMsg);
507 Ptr<NrDlCqiMessage> CreateDlCqiFeedbackMessage(const SpectrumValue& sinr)
508 __attribute__((warn_unused_result));
514 Time DlCtrl(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
520 Time UlCtrl(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
526 Time UlSrs(const std::shared_ptr<DciInfoElementTdma>& dci);
532 Time DlData(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
533
539 Time UlData(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
540
548 void TryToPerformLbt();
549
554 void StartSlot(const SfnSf& s);
555
571 void StartVarTti(const std::shared_ptr<DciInfoElementTdma>& dci);
572
585 void EndVarTti(const std::shared_ptr<DciInfoElementTdma>& dci);
586
593 void SetSubChannelsForTransmission(const std::vector<int>& mask, uint32_t numSym);
598 void DoSendControlMessage(Ptr<NrControlMessage> msg);
603 void DoSendControlMessageNow(Ptr<NrControlMessage> msg);
604
610 void ProcessDataDci(const SfnSf& ulSfnSf,
611 const std::shared_ptr<DciInfoElementTdma>& dciInfoElem);
612
618 void ProcessSrsDci(const SfnSf& ulSfnSf,
619 const std::shared_ptr<DciInfoElementTdma>& dciInfoElem);
620
628 void SendDataChannels(const Ptr<PacketBurst>& pb,
629 const std::list<Ptr<NrControlMessage>>& ctrlMsg,
630 const std::shared_ptr<DciInfoElementTdma>& dci,
631 const Time& duration);
639 void SendCtrlChannels(Time duration);
640
641 // SAP methods
642 void DoReset();
643 void DoStartCellSearch(uint16_t dlEarfcn);
644 void DoSynchronizeWithEnb(uint16_t cellId);
645 void DoSynchronizeWithEnb(uint16_t cellId, uint16_t dlEarfcn);
646 void DoSetPa(double pa);
653 void DoSetRsrpFilterCoefficient(uint8_t rsrpFilterCoefficient);
654
659 void DoSetInitialBandwidth();
665 uint16_t DoGetCellId();
670 uint32_t DoGetDlEarfcn();
675 void DoSetDlBandwidth(uint16_t ulBandwidth);
680 void DoConfigureUplink(uint16_t ulEarfcn, uint8_t ulBandwidth);
681 void DoConfigureReferenceSignalPower(int8_t referenceSignalPower);
682 void DoSetRnti(uint16_t rnti);
683 void DoSetTransmissionMode(uint8_t txMode);
684 void DoSetSrsConfigurationIndex(uint16_t srcCi);
692 void DoResetPhyAfterRlf();
701 void DoResetRlfParams();
702
712 void DoStartInSyncDetection();
713
719 void DoSetImsi(uint64_t imsi);
720
729 void PushCtrlAllocations(const SfnSf currentSfnSf);
730
735 void InsertAllocation(const std::shared_ptr<DciInfoElementTdma>& dci);
736
741 void InsertFutureAllocation(const SfnSf& sfnSf, const std::shared_ptr<DciInfoElementTdma>& dci);
742
743 NrUePhySapUser* m_phySapUser;
744 LteUeCphySapProvider* m_ueCphySapProvider;
745 LteUeCphySapUser* m_ueCphySapUser;
746
747 bool m_enableUplinkPowerControl{
748 false};
749 Ptr<NrUePowerControl> m_powerControl;
750
751 Ptr<const NrAmc> m_amc;
752
753 Ptr<NrPmSearch> m_pmSearch{nullptr};
754
755 Time m_sbPmiLastUpdate{};
756 Time m_wbPmiLastUpdate{};
757 Time m_wbPmiUpdateInterval{NR_DEFAULT_PMI_INTERVAL_WB};
758 Time m_sbPmiUpdateInterval{NR_DEFAULT_PMI_INTERVAL_SB};
759
760 Time m_wbCqiLast;
761 Time m_lastSlotStart;
762
763 bool m_ulConfigured{false};
764 bool m_receptionEnabled{false};
765 uint16_t m_rnti{0};
766 uint32_t m_currTbs{0};
767 uint64_t m_imsi{0};
768 std::unordered_map<uint8_t, uint32_t>
769 m_harqIdToK1Map;
770
771 int64_t m_numRbPerRbg{
772 -1};
774
775 SfnSf m_currentSlot;
776
780 enum ChannelStatus
781 {
782 NONE,
783 REQUESTED,
784 GRANTED
785 };
786
787 ChannelStatus m_channelStatus{NONE};
788 Ptr<NrChAccessManager> m_cam;
789 Time m_lbtThresholdForCtrl;
790 bool m_tryToPerformLbt{false};
791 EventId m_lbtEvent;
792 uint8_t m_dlCtrlSyms{1};
793 uint8_t m_ulCtrlSyms{1};
794
795 double m_rsrp{0};
796
798 struct UeMeasurementsElement
799 {
800 double rsrpSum;
801 uint8_t rsrpNum;
802 // For the moment rsrq is not supported so set to 0
803 double rsrqSum;
804 uint8_t rsrqNum;
805 };
806
811 std::map<uint16_t, UeMeasurementsElement> m_ueMeasurementsMap;
816 Time m_ueMeasurementsFilterPeriod;
817
822 TracedCallback<uint16_t, uint16_t, double, uint16_t> m_dlDataSinrTrace;
827 TracedCallback<uint16_t, uint16_t, double, uint16_t> m_dlCtrlSinrTrace;
828 TracedCallback<uint64_t, uint64_t> m_reportUlTbSize;
829 TracedCallback<uint64_t, uint64_t> m_reportDlTbSize;
830 TracedCallback<const SfnSf&,
831 Ptr<const SpectrumValue>,
832 const Time&,
833 uint16_t,
834 uint64_t,
835 uint16_t,
836 uint16_t>
837 m_reportPowerSpectralDensity;
838
843 TracedCallback<uint16_t, uint16_t, uint16_t, double, uint8_t> m_reportRsrpTrace;
844
850 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
851 m_phyRxedCtrlMsgsTrace;
852
858 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
859 m_phyTxedCtrlMsgsTrace;
860
866 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, uint8_t, uint32_t> m_phyUeRxedDlDciTrace;
867
873 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, uint8_t, uint32_t>
874 m_phyUeTxedHarqFeedbackTrace;
875};
876
877} // namespace ns3
878
879#endif /* NR_UE_PHY_H */
Representation of a beam id.
Definition beam-id.h:28
The base class for gNb and UE physical layer.
Definition nr-phy.h:69
The UE PHY class.
Definition nr-ue-phy.h:62
void SetUplinkPowerControl(Ptr< NrUePowerControl > pc)
Allow configuration of uplink power control algorithm. E.g. necessary in FDD, when measurements are r...
Definition nr-ue-phy.cc:259
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 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.
Definition nr-ue-phy.cc:233
void SetUeCphySapUser(LteUeCphySapUser *s)
Install ue C PHY SAP user (AKA the PHY interface towards the RRC)
Definition nr-ue-phy.cc:213
NrUePhy()
NrUePhy default constructor.
Definition nr-ue-phy.cc:43
void SetNumRbPerRbg(uint32_t numRbPerRbg)
Function that sets the number of RBs per RBG. This function will be soon deprecated,...
Definition nr-ue-phy.cc:365
BeamId GetBeamId(uint16_t rnti) const override
Get the beam id for the specified user.
~NrUePhy() override
~NrUePhy
Definition nr-ue-phy.cc:53
Ptr< NrPmSearch > GetPmSearch() const
Get the precoding matrix search engine.
void RegisterToEnb(uint16_t bwpId)
Register the UE to a certain Enb.
Definition nr-ue-phy.cc:344
void(* TxedUePhyHarqFeedbackTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, uint8_t harqId, uint32_t K1Delay)
Definition nr-ue-phy.h:345
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
Protected function that is used to get the number of resource blocks per resource block group.
Definition nr-ue-phy.cc:402
void(* TxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-ue-phy.h:306
uint8_t ComputeCqi(const SpectrumValue &sinr)
Compute the CQI based on the SINR.
void SetDlAmc(const Ptr< const NrAmc > &amc)
Set the AMC pointer from the GNB.
Definition nr-ue-phy.cc:265
double GetTxPower() const override
Retrieve the TX power of the UE.
Definition nr-ue-phy.cc:240
void(* RxedUePhyDlDciTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, uint8_t harqId, uint32_t K1Delay)
Definition nr-ue-phy.h:325
void SetDlCtrlSyms(uint8_t dlCtrlSyms)
Set the number of DL CTRL symbols.
Definition nr-ue-phy.cc:359
double GetRsrp() const
Returns the latest measured RSRP value Called by NrUePowerControl.
Definition nr-ue-phy.cc:246
void DoDispose() override
DoDispose method inherited from Object.
Definition nr-ue-phy.cc:59
Ptr< NrUePowerControl > GetUplinkPowerControl() const
Get LTE uplink power control entity.
Definition nr-ue-phy.cc:252
void(* RxedUePhyCtrlMsgsTracedCallback)(const SfnSf sfnSf, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-ue-phy.h:288
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.
Definition nr-ue-phy.cc:371
void GenerateDlCqiReportMimo(const std::vector< MimoSignalChunk > &mimoChunks)
Generate DL CQI, PMI, and RI (channel quality precoding matrix and rank indicators)
void(* DlCtrlSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t)
Definition nr-ue-phy.h:264
void(* DlDataSinrTracedCallback)(uint16_t, uint16_t, double, uint16_t)
Definition nr-ue-phy.h:274
void SetUlCtrlSyms(uint8_t ulCtrlSyms)
Set the number of UL CTRL symbols.
Definition nr-ue-phy.cc:353
uint16_t GetRnti() const __attribute__((warn_unused_result))
Get the current RNTI of the user.
const SfnSf & GetCurrentSfnSf() const override
Get the current SfnSf.
void PhyCtrlMessagesReceived(const Ptr< NrControlMessage > &msg)
Receive a list of CTRL messages.
Definition nr-ue-phy.cc:458
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.
Definition nr-ue-phy.h:423
void ReportDlCtrlSinr(const SpectrumValue &sinr)
Called when DlCtrlSinr is fired.
void PhyDataPacketReceived(const Ptr< Packet > &p)
Receive a PHY data packet.
LteUeCphySapProvider * GetUeCphySapProvider() __attribute__((warn_unused_result))
Retrieve the pointer for the C PHY SAP provider (AKA the PHY interface towards the RRC)
Definition nr-ue-phy.cc:220
void ReportRsReceivedPower(const SpectrumValue &power)
Called when rsReceivedPower is fired.
static TypeId GetTypeId()
Get the object TypeId.
Definition nr-ue-phy.cc:77
SAP interface between the UE PHY and the UE MAC.
Definition nr-phy-sap.h:268
The SfnSf class.
Definition sfnsf.h:34
A struct that contains info for the DL HARQ.
Parameters that define if PMI should be updated or if previous PMI values are used.