5G-LENA nr-v3.3-161-gad18933f
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-gnb-phy.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_PHY_H
6#define NR_GNB_PHY_H
7
8#include "ideal-beamforming-algorithm.h"
9#include "nr-control-messages.h"
10#include "nr-fh-phy-sap.h"
11#include "nr-gnb-cphy-sap.h"
12#include "nr-harq-phy.h"
13#include "nr-phy-sap.h"
14#include "nr-phy.h"
15
16#include <functional>
17
18namespace ns3
19{
20
21class PacketBurst;
22class NrNetDevice;
23class NrUePhy;
24class NrGnbMac;
25class NrChAccessManager;
26class BeamManager;
27class NrFhPhySapUser;
28class NrFhPhySapProvider;
29
89class NrGnbPhy : public NrPhy
90{
92 friend class NrMemberPhySapProvider;
93 friend class NrHelper;
94
95 public:
104
109 static TypeId GetTypeId();
110
114 NrGnbPhy();
115
119 ~NrGnbPhy() override;
120
131
132 // FH Control SAPs
133 void SetNrFhPhySapProvider(NrFhPhySapProvider* s);
134 NrFhPhySapUser* GetNrFhPhySapUser();
135
141 void SetN0Delay(uint32_t delay);
142
156 void SetN1Delay(uint32_t delay);
157
171 void SetN2Delay(uint32_t delay);
172
177 uint32_t GetN0Delay() const;
178
183 uint32_t GetN1Delay() const;
184
189 uint32_t GetN2Delay() const;
190
196 BeamId GetBeamId(uint16_t rnti) const override;
197
202 void SetCam(const Ptr<NrChAccessManager>& s);
203
208 Ptr<NrChAccessManager> GetCam() const;
209
216 void SetTxPower(double pow);
217
224 double GetTxPower() const override;
225
233 void SetSubChannels(const std::vector<int>& rbIndexVector, size_t nTotalAllocRbs);
234
243 bool RegisterUe(uint64_t imsi, const Ptr<NrUeNetDevice>& ueDevice);
244
249 void AssignCsiRsOffset(const Ptr<NrUeNetDevice>& ueDevice);
250
258 void PhyDataPacketReceived(const Ptr<Packet>& p);
259
267 void GenerateDataCqiReport(const SpectrumValue& sinr);
268
276 void PhyCtrlMessagesReceived(const Ptr<NrControlMessage>& msg);
277
282 int8_t DoGetReferenceSignalPower() const;
283
290
299 void ReportUlHarqFeedback(const UlHarqInfo& mes);
300
314 void SetPattern(const std::string& pattern);
315
320 std::string GetPattern() const;
321
326 void SetCsiRsModel(enum CsiRsModel csiRsModel);
327
331 enum CsiRsModel GetCsiRsModel() const;
332
337 void SetCsiRsPeriodicity(uint16_t csiRsPeriodicity);
338
343 uint16_t GetCsiRsPeriodicity() const;
344
350 void SetPrimary();
351
359 void ScheduleStartEventLoop(uint32_t nodeId,
360 uint16_t frame,
361 uint8_t subframe,
362 uint16_t slot) override;
363
376 typedef void (*RxedGnbPhyCtrlMsgsTracedCallback)(const SfnSf sfn,
377 const uint16_t nodeId,
378 const uint16_t rnti,
379 const uint8_t bwpId,
380 Ptr<NrControlMessage>);
381
394 typedef void (*TxedGnbPhyCtrlMsgsTracedCallback)(const SfnSf sfn,
395 const uint16_t nodeId,
396 const uint16_t rnti,
397 const uint8_t bwpId,
398 Ptr<NrControlMessage>);
399
412 typedef void (*SlotStatsTracedCallback)(const SfnSf& sfnSf,
413 uint32_t scheduledUe,
414 uint32_t usedReg,
415 uint32_t usedSym,
416 uint32_t availableRb,
417 uint32_t availableSym,
418 uint16_t bwpId,
419 uint16_t cellId);
420
430 typedef void (*RBStatsTracedCallback)(const SfnSf& sfnSf,
431 uint8_t sym,
432 const std::vector<int>& rbMap,
433 uint16_t bwpId,
434 uint16_t cellId);
435
442 uint32_t GetNumRbPerRbg() const override;
443
444 const SfnSf& GetCurrentSfnSf() const override;
445
449 void ChangeBeamformingVector(Ptr<NrNetDevice> dev);
454
455 protected:
459 void DoDispose() override;
460
472 bool DoesFhAllocationFit(uint16_t bwpId, uint32_t mcs, uint32_t nRegs, uint8_t dlRank) const;
473
474 // FFR SAPs
477
478 private:
483 void EnableCsiRs();
490 void SetTddPattern(const std::vector<LteNrTddSlotType>& pattern);
491
502 void StartSlot(const SfnSf& startSlot);
503
512 void EndSlot();
513
529 void StartVarTti(const std::shared_ptr<DciInfoElementTdma>& dci);
530
543 void EndVarTti(const std::shared_ptr<DciInfoElementTdma>& lastDci);
544
552 void SendDataChannels(const Ptr<PacketBurst>& pb,
553 const Time& varTtiPeriod,
554 const std::shared_ptr<DciInfoElementTdma>& dci);
555
563 void SendCtrlChannels(const Time& varTtiPeriod);
564
570 std::list<Ptr<NrControlMessage>> RetrieveMsgsFromDCIs(const SfnSf& sfn)
571 __attribute__((warn_unused_result));
572
578 void ChannelAccessGranted(const Time& time);
579
583 void ChannelAccessLost();
584
591 bool TimeToTransmitCsiRs(uint16_t currentOffset) const;
592
597 void TransmitCsiRsPerUe(Ptr<NrUeNetDevice> ueDev);
598
606 Time ScheduleCsiRs(Time varTti, uint16_t currentOffset);
607
617 Time DlCtrl(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
626 Time UlCtrl(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
627
637 Time DlData(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
638
647 Time UlData(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
648
657 Time UlSrs(const std::shared_ptr<DciInfoElementTdma>& dci) __attribute__((warn_unused_result));
658
664 void QueueMib();
670 void QueueSib();
671
679 void DoStartSlot();
680
681 void GenerateAllocationStatistics(const SlotAllocInfo& allocInfo) const;
682
683 // NrGnbCphySapProvider forwarded methods
684 void DoSetBandwidth(uint16_t ulBandwidth, uint16_t dlBandwidth);
685 void DoSetEarfcn(uint16_t dlEarfcn, uint16_t ulEarfcn);
686 void DoAddUe(uint16_t rnti);
687 void DoRemoveUe(uint16_t rnti);
688 void DoSetPa(uint16_t rnti, double pa);
689 void DoSetTransmissionMode(uint16_t rnti, uint8_t txMode);
690 void DoSetSrsConfigurationIndex(uint16_t rnti, uint16_t srcCi);
691 void DoSetMasterInformationBlock(NrRrcSap::MasterInformationBlock mib);
692 void DoSetSystemInformationBlockType1(NrRrcSap::SystemInformationBlockType1 sib1);
693 void DoSetEarfcn(uint16_t Earfcn);
694
701 void StoreRBGAllocation(std::unordered_map<uint8_t, std::vector<bool>>* map,
702 const std::shared_ptr<DciInfoElementTdma>& dci) const;
703
717 static void GenerateStructuresFromPattern(const std::vector<LteNrTddSlotType>& pattern,
718 std::map<uint32_t, std::vector<uint32_t>>* toSendDl,
719 std::map<uint32_t, std::vector<uint32_t>>* toSendUl,
720 std::map<uint32_t, std::vector<uint32_t>>* generateDl,
721 std::map<uint32_t, std::vector<uint32_t>>* generateUl,
722 std::map<uint32_t, uint32_t>* dlHarqfbPosition,
723 uint32_t n0,
724 uint32_t n2,
725 uint32_t n1,
726 uint32_t l1l2CtrlLatency);
727
732 void CallMacForSlotIndication(const SfnSf& currentSlot);
733
743 std::list<Ptr<NrControlMessage>> RetrieveDciFromAllocation(
744 const SlotAllocInfo& alloc,
745 const DciInfoElementTdma::DciFormat& format,
746 uint32_t kDelay,
747 uint32_t k1Delay);
748
756 void PushDlAllocation(const SfnSf& sfnSf) const;
757
765 void PushUlAllocation(const SfnSf& sfnSf) const;
766
773 void StartEventLoop(uint16_t frame, uint8_t subframe, uint16_t slot);
774
781 void DoCheckOrReleaseChannel();
782
789 void RetrievePrepareEncodeCtrlMsgs();
790
796 void PrepareRbgAllocationMap(const std::deque<VarTtiAllocInfo>& allocations);
797
801 void FillTheEvent();
802
803 private:
804 NrGnbPhySapUser* m_phySapUser{nullptr};
806 NrGnbCphySapProvider* m_gnbCphySapProvider{
807 nullptr};
809 NrGnbCphySapUser* m_gnbCphySapUser{
810 nullptr};
812
813 std::set<uint64_t> m_ueAttached;
814 std::set<uint16_t> m_ueAttachedRnti;
815 std::vector<Ptr<NrUeNetDevice>> m_deviceMap;
816
817 NrRrcSap::SystemInformationBlockType1 m_sib1;
818 Time m_lastSlotStart;
819 uint8_t m_currSymStart{0};
820 std::unordered_map<uint8_t, std::vector<bool>>
821 m_rbgAllocationPerSym;
822 std::unordered_map<uint8_t, std::vector<bool>>
823 m_rbgAllocationPerSymDataStat;
825
826 TracedCallback<uint64_t, SpectrumValue&, SpectrumValue&> m_ulSinrTrace;
827
833 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
834 m_phyRxedCtrlMsgsTrace;
835
841 TracedCallback<SfnSf, uint16_t, uint16_t, uint8_t, Ptr<const NrControlMessage>>
842 m_phyTxedCtrlMsgsTrace;
843
847 TracedCallback<const SfnSf&,
848 uint32_t,
849 uint32_t,
850 uint32_t,
851 uint32_t,
852 uint32_t,
853 uint16_t,
854 uint16_t>
855 m_phySlotCtrlStats;
859 TracedCallback<const SfnSf&,
860 uint32_t,
861 uint32_t,
862 uint32_t,
863 uint32_t,
864 uint32_t,
865 uint16_t,
866 uint16_t>
867 m_phySlotDataStats;
868
869 TracedCallback<const SfnSf&, uint8_t, const std::vector<int>&, uint16_t, uint16_t>
870 m_rbStatistics;
871
872 std::map<uint32_t, std::vector<uint32_t>>
873 m_toSendDl;
874 std::map<uint32_t, std::vector<uint32_t>>
875 m_toSendUl;
876 std::map<uint32_t, std::vector<uint32_t>>
877 m_generateUl;
878 std::map<uint32_t, std::vector<uint32_t>>
879 m_generateDl;
880
881 std::map<uint32_t, uint32_t> m_dlHarqfbPosition;
883
887 enum ChannelStatus
888 {
889 NONE,
890 REQUESTED,
891 GRANTED,
892 TO_LOSE
893 };
894
895 ChannelStatus m_channelStatus{NONE};
896 EventId m_channelLostTimer;
897
898 Ptr<NrChAccessManager> m_cam;
899
900 friend class NrPatternTestCase;
901
902 uint32_t m_n0Delay{0};
904 uint32_t m_n1Delay{
905 0};
907 uint32_t m_n2Delay{0};
909
910 SfnSf m_currentSlot;
911 bool m_isPrimary{false};
912
913 bool m_enableCsiRs{false};
915 uint16_t m_csiRsPeriodicity{10};
916 std::map<uint16_t, std::set<Ptr<NrUeNetDevice>>> m_csiRsOffsetToUes;
917
918 Time m_lastBfChange;
919};
920
921} // namespace ns3
922
923#endif /* NR_GNB_PHY_H */
Representation of a beam id.
Definition beam-id.h:26
Service Access Point (SAP) offered by the FhControl instance to the gnb PHY instance.
Service Access Point (SAP) offered by the gnb PHY instance to the FhControl instance.
The gNb physical layer.
Definition nr-gnb-phy.h:90
void GenerateDataCqiReport(const SpectrumValue &sinr)
Generate a DL CQI report.
void SetN1Delay(uint32_t delay)
: Set the minimum processing delay (in slots) to decode DL Data and send Harq feedback.
void(* TxedGnbPhyCtrlMsgsTracedCallback)(const SfnSf sfn, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-gnb-phy.h:394
NrGnbCphySapProvider * GetGnbCphySapProvider()
Get the C PHY SAP provider.
void ChangeToQuasiOmniBeamformingVector()
void ReportUlHarqFeedback(const UlHarqInfo &mes)
Get the HARQ feedback from NrSpectrumPhy and forward it to the scheduler.
int8_t DoGetReferenceSignalPower() const
Get the power of the gnb.
Ptr< NrChAccessManager > GetCam() const
Get the channel access manager for the PHY.
void DoDispose() override
DoDispose method inherited from Object.
Definition nr-gnb-phy.cc:57
bool DoesFhAllocationFit(uint16_t bwpId, uint32_t mcs, uint32_t nRegs, uint8_t dlRank) const
Returns a boolean indicating whether the current allocation can fit in the available FH bandwidth.
void SetPrimary()
Set this PHY as primary.
void SetN0Delay(uint32_t delay)
: Set the minimum processing delay (in slots) to decode DL DCI and decode DL data....
void ScheduleStartEventLoop(uint32_t nodeId, uint16_t frame, uint8_t subframe, uint16_t slot) override
Start the ue Event Loop.
void(* RBStatsTracedCallback)(const SfnSf &sfnSf, uint8_t sym, const std::vector< int > &rbMap, uint16_t bwpId, uint16_t cellId)
TracedCallback signature for RB statistics.
Definition nr-gnb-phy.h:430
~NrGnbPhy() override
~NrGnbPhy
Definition nr-gnb-phy.cc:52
const SfnSf & GetCurrentSfnSf() const override
Get the current SfnSf.
void AssignCsiRsOffset(const Ptr< NrUeNetDevice > &ueDevice)
void SetCsiRsModel(enum CsiRsModel csiRsModel)
Set the CSI-RS model.
void SetCam(const Ptr< NrChAccessManager > &s)
Set the channel access manager interface for this instance of the PHY.
CsiRsModel
CSI-RS model to be used.
Definition nr-gnb-phy.h:100
@ CSI_RS_PER_UE
CSI-RS per UE periodically.
Definition nr-gnb-phy.h:101
@ CSI_RS_PER_BEAM
CSI-RS per beam periodically.
Definition nr-gnb-phy.h:102
void SetSubChannels(const std::vector< int > &rbIndexVector, size_t nTotalAllocRbs)
Set the Tx power spectral density based on the RB index vector.
BeamId GetBeamId(uint16_t rnti) const override
Get the BeamId for the selected user.
void SetGnbCphySapUser(NrGnbCphySapUser *s)
Set the C PHY SAP user.
bool RegisterUe(uint64_t imsi, const Ptr< NrUeNetDevice > &ueDevice)
Add the UE to the list of this gnb UEs.
NrFhPhySapProvider * m_nrFhPhySapProvider
FH Control SAP provider.
Definition nr-gnb-phy.h:476
void(* RxedGnbPhyCtrlMsgsTracedCallback)(const SfnSf sfn, const uint16_t nodeId, const uint16_t rnti, const uint8_t bwpId, Ptr< NrControlMessage >)
Definition nr-gnb-phy.h:376
void(* SlotStatsTracedCallback)(const SfnSf &sfnSf, uint32_t scheduledUe, uint32_t usedReg, uint32_t usedSym, uint32_t availableRb, uint32_t availableSym, uint16_t bwpId, uint16_t cellId)
TracedCallback signature for slot statistics.
Definition nr-gnb-phy.h:412
void SetCsiRsPeriodicity(uint16_t csiRsPeriodicity)
void SetPattern(const std::string &pattern)
Set the pattern that the gnb will utilize.
void SetN2Delay(uint32_t delay)
: Set the minimum processing delay (in slots) to decode UL DCI and prepare UL data.
NrGnbPhy()
NrGnbPhy constructor. Please use the other one.
Definition nr-gnb-phy.cc:43
uint32_t GetN2Delay() const
: Get the minimum processing delay (in slots) to decode UL DCI and prepare UL data
uint32_t GetN1Delay() const
: Get the minimum processing delay (in slots) to decode DL Data and send Harq feedback
void PhyDataPacketReceived(const Ptr< Packet > &p)
Receive a PHY data packet.
void PhyCtrlMessagesReceived(const Ptr< NrControlMessage > &msg)
Receive a list of CTRL messages.
void SetTxPower(double pow)
Set the transmission power for the UE.
uint16_t GetCsiRsPeriodicity() const
Retrieve CSI-RS periodicity.
enum CsiRsModel GetCsiRsModel() const
Gets the CSI-RS model in use.
double GetTxPower() const override
Retrieve the TX power of the gNB.
void SetPhySapUser(NrGnbPhySapUser *ptr)
Install the PHY SAP user (which is in this case the MAC)
NrFhPhySapUser * m_nrFhPhySapUser
FH Control SAP user.
Definition nr-gnb-phy.h:475
uint32_t GetN0Delay() const
: Get the minimum processing delay (in slots) to decode DL DCI and decode DL Data
uint32_t GetNumRbPerRbg() const override
Retrieve the number of RB per RBG.
std::string GetPattern() const
Retrieve the currently installed pattern.
void ChangeBeamformingVector(Ptr< NrNetDevice > dev)
static TypeId GetTypeId()
Get Type id.
Definition nr-gnb-phy.cc:74
SAP interface between the gNB PHY and the gNB MAC.
Definition nr-phy-sap.h:155
Helper to set up single- or multi-cell scenarios with NR.
Definition nr-helper.h:207
The base class for gNb and UE physical layer.
Definition nr-phy.h:67
The SfnSf class.
Definition sfnsf.h:32
DciFormat
Format of the DCI.
MasterInformationBlock structure.
Definition nr-rrc-sap.h:627
SystemInformationBlockType1 structure.
Definition nr-rrc-sap.h:635
The SlotAllocInfo struct.
A struct that contains info for the UL HARQ.