5G-LENA nr-v3.3-81-g75c7590d
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-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_PHY_H
6#define NR_PHY_H
7
8#include "nr-phy-mac-common.h"
9#include "nr-phy-sap.h"
10
11#include <ns3/nr-spectrum-value-helper.h>
12
13namespace ns3
14{
15
16class NrNetDevice;
17class NrControlMessage;
18class NrSpectrumPhy;
19class AntennaArrayBasicModel;
20class UniformPlanarArray;
21
66class NrPhy : public Object
67{
68 public:
72 NrPhy();
73
77 ~NrPhy() override;
78
83 static TypeId GetTypeId();
84
85 // Called by SAP
90 void EnqueueCtrlMessage(const Ptr<NrControlMessage>& m);
91
101 void SetMacPdu(const Ptr<Packet>& p, const SfnSf& sfn, uint8_t symStart, uint16_t rnti);
102
112 virtual void SendRachPreamble(uint32_t PreambleId, uint32_t Rnti);
113
121 void PushBackSlotAllocInfo(const SlotAllocInfo& slotAllocInfo);
122
128
133 virtual void SetTbDecodeLatency(const Time& us);
134
139 virtual Time GetTbDecodeLatency() const;
140
146 virtual BeamId GetBeamId(uint16_t rnti) const = 0;
147
152 Ptr<const SpectrumModel> GetSpectrumModel();
153
158 uint32_t GetSymbolsPerSlot() const;
159
164 Time GetSlotPeriod() const;
165
171 Time GetSymbolPeriod() const;
172
177 void SetNoiseFigure(double d);
178
183 double GetNoiseFigure() const;
184
190 virtual double GetTxPower() const = 0;
191
192 // Installation / Helpers
198
203 void SetDevice(Ptr<NrNetDevice> d);
204
211 void InstallCentralFrequency(double f);
212
220 void SetNumerology(uint16_t numerology);
221
226 uint16_t GetNumerology() const;
227
232 void SetSymbolsPerSlot(uint16_t symbolsPerSlot);
233
238 void SetRbOverhead(double oh);
239
244 double GetRbOverhead() const;
245
253 Ptr<NrSpectrumPhy> GetSpectrumPhy() const;
254
259 void InstallSpectrumPhy(const Ptr<NrSpectrumPhy>& spectrumPhy);
260
271 virtual void ScheduleStartEventLoop(uint32_t nodeId,
272 uint16_t frame,
273 uint8_t subframe,
274 uint16_t slot) = 0;
275
279 void SetBwpId(uint16_t bwpId);
280
284 uint16_t GetBwpId() const;
285
289 uint16_t GetCellId() const;
290
296 uint32_t GetRbNum() const;
297
302 uint32_t GetChannelBandwidth() const;
303
309 uint32_t GetSubcarrierSpacing() const;
310
318 uint32_t GetL1L2CtrlLatency() const;
319
320 // SAP
327 void DoSetCellId(uint16_t cellId);
328
333 void EncodeCtrlMsg(const Ptr<NrControlMessage>& msg);
334
340 bool HasDlSlot() const;
341
347 bool HasUlSlot() const;
348
355 static bool HasDlSlot(const std::vector<LteNrTddSlotType>& pattern);
356
363 static bool HasUlSlot(const std::vector<LteNrTddSlotType>& pattern);
364
371 double GetCentralFrequency() const;
372
377 virtual const SfnSf& GetCurrentSfnSf() const = 0;
378
384 static std::string GetPattern(const std::vector<LteNrTddSlotType>& pattern);
385
393 enum NrSpectrumValueHelper::PowerAllocationType powerAllocationType);
394
398 enum NrSpectrumValueHelper::PowerAllocationType GetPowerAllocationType() const;
399
400 protected:
404 void DoDispose() override;
408 void DoInitialize() override;
412 void DoUpdateRbNum();
413
423 void SetChannelBandwidth(uint16_t bandwidth);
424
430 static bool IsTdd(const std::vector<LteNrTddSlotType>& pattern);
431
446 std::vector<int> FromRBGBitmaskToRBAssignment(const std::vector<bool> rbgBitmask) const;
447
453 virtual uint32_t GetNumRbPerRbg() const = 0;
454
462 Ptr<PacketBurst> GetPacketBurst(SfnSf sf, uint8_t sym, uint16_t rnti);
463
469 Ptr<SpectrumValue> GetNoisePowerSpectralDensity();
470
480 Ptr<SpectrumValue> GetTxPowerSpectralDensity(const std::vector<int>& rbIndexVector);
481
488 void PushFrontSlotAllocInfo(const SfnSf& newSfnSf, const SlotAllocInfo& slotAllocInfo);
489
495 bool SlotAllocInfoExists(const SfnSf& sfnsf) const;
496
503
512
521
526 size_t SlotAllocInfoSize() const;
527
532 bool IsCtrlMsgListEmpty() const;
533
538 void EnqueueCtrlMsgNow(const Ptr<NrControlMessage>& msg);
539
544 void EnqueueCtrlMsgNow(const std::list<Ptr<NrControlMessage>>& listOfMsgs);
545
554 virtual std::list<Ptr<NrControlMessage>> PopCurrentSlotCtrlMsgs();
555
556 protected:
557 Ptr<NrNetDevice> m_netDevice;
558 Ptr<NrSpectrumPhy> m_spectrumPhy;
559
560 double m_txPower{0.0};
561 double m_noiseFigure{0.0};
562
563 std::unordered_map<uint64_t, Ptr<PacketBurst>>
565
567
569
570 uint32_t m_raPreambleId{0};
571 std::list<Ptr<NrControlMessage>> m_ctrlMsgs;
572
573 std::vector<LteNrTddSlotType> m_tddPattern = {F, F, F, F, F, F, F, F, F, F};
574
575 private:
576 std::list<SlotAllocInfo> m_slotAllocInfo;
577 std::vector<std::list<Ptr<NrControlMessage>>> m_controlMessageQueue;
578
579 Time m_tbDecodeLatencyUs{MicroSeconds(100)};
580 double m_centralFrequency{-1.0};
581 uint16_t m_channelBandwidth{
582 0};
583 // E.g. if set to 200, the bandwidth will be 20 MHz (= 200 * 100 KHz)
584
585 uint16_t m_cellId{0};
586 uint16_t m_bwpId{
587 UINT16_MAX};
588 uint16_t m_numerology{
589 0};
590 uint16_t m_symbolsPerSlot{14};
591
592 uint16_t m_slotsPerSubframe{0};
593 Time m_slotPeriod{0};
594 Time m_symbolPeriod{0};
595 uint32_t m_subcarrierSpacing{0};
597 uint32_t m_rbNum{0};
598 double m_rbOh{0.04};
599
600 enum NrSpectrumValueHelper::PowerAllocationType m_powerAllocationType{
601 NrSpectrumValueHelper::UNIFORM_POWER_ALLOCATION_USED};
605};
606
607} // namespace ns3
608
609#endif /* NR_PHY_H */
Representation of a beam id.
Definition beam-id.h:26
The base class for gNb and UE physical layer.
Definition nr-phy.h:67
Time GetSymbolPeriod() const
Get SymbolPeriod.
Definition nr-phy.cc:859
Ptr< NrSpectrumPhy > m_spectrumPhy
Pointer to the (owned) spectrum phy.
Definition nr-phy.h:558
SlotAllocInfo RetrieveSlotAllocInfo()
Get the head for the slot allocation info, and delete it from the internal list.
Definition nr-phy.cc:789
uint16_t GetCellId() const
Definition nr-phy.cc:658
virtual const SfnSf & GetCurrentSfnSf() const =0
Get the current SfnSf.
uint16_t GetNumerology() const
Get the configured numerology.
Definition nr-phy.cc:290
Ptr< NrSpectrumPhy > GetSpectrumPhy() const
Retrieve the SpectrumPhy pointer.
Definition nr-phy.cc:670
void EncodeCtrlMsg(const Ptr< NrControlMessage > &msg)
Take the control messages, and put it in a list that will be sent at the first occasion.
Definition nr-phy.cc:470
void SetNumerology(uint16_t numerology)
Set GNB or UE numerology.
Definition nr-phy.cc:262
virtual void SetTbDecodeLatency(const Time &us)
Configures TB decode latency.
Definition nr-phy.cc:883
std::list< Ptr< NrControlMessage > > m_ctrlMsgs
CTRL messages to be sent.
Definition nr-phy.h:571
void DoInitialize() override
DoInitialize method inherited from Object.
Definition nr-phy.cc:218
void SetRbOverhead(double oh)
Set the bandwidth overhead for calculating the usable RB number.
Definition nr-phy.cc:304
void PushBackSlotAllocInfo(const SlotAllocInfo &slotAllocInfo)
Store the slot allocation info.
Definition nr-phy.cc:683
void NotifyConnectionSuccessful()
Notify PHY about the successful RRC connection establishment.
Definition nr-phy.cc:359
void InstallCentralFrequency(double f)
Install the PHY over a particular central frequency.
Definition nr-phy.cc:235
~NrPhy() override
~NrPhy
Definition nr-phy.cc:194
Ptr< PacketBurst > GetPacketBurst(SfnSf sf, uint8_t sym, uint16_t rnti)
Retrieve the PacketBurst at the slot/symbol specified.
Definition nr-phy.cc:365
void SetPowerAllocationType(enum NrSpectrumValueHelper::PowerAllocationType powerAllocationType)
Set power allocation type. There are currently supported two types: one that distributes uniformly en...
Definition nr-phy.cc:433
static std::string GetPattern(const std::vector< LteNrTddSlotType > &pattern)
Get a string representation of a pattern.
Definition nr-phy.cc:414
void InstallSpectrumPhy(const Ptr< NrSpectrumPhy > &spectrumPhy)
Set the SpectrumPhy associated with this PHY.
Definition nr-phy.cc:639
Time GetSlotPeriod() const
Get the slot period.
Definition nr-phy.cc:322
virtual std::list< Ptr< NrControlMessage > > PopCurrentSlotCtrlMsgs()
Extract and return the message list that is at the beginning of the queue.
Definition nr-phy.cc:611
virtual void SendRachPreamble(uint32_t PreambleId, uint32_t Rnti)
Send the RachPreamble.
Definition nr-phy.cc:336
virtual void ScheduleStartEventLoop(uint32_t nodeId, uint16_t frame, uint8_t subframe, uint16_t slot)=0
Schedule the start of the NR event loop.
SlotAllocInfo m_currSlotAllocInfo
Current slot allocation.
Definition nr-phy.h:566
NrPhy()
NrPhy constructor.
Definition nr-phy.cc:185
enum NrSpectrumValueHelper::PowerAllocationType GetPowerAllocationType() const
Get the power allocation type.
Definition nr-phy.cc:439
void EnqueueCtrlMsgNow(const Ptr< NrControlMessage > &msg)
Enqueue a CTRL message without considering L1L2CtrlLatency.
Definition nr-phy.cc:453
uint32_t GetChannelBandwidth() const
Retrieve the channel bandwidth, in Hz.
Definition nr-phy.cc:521
virtual Time GetTbDecodeLatency() const
Returns Transport Block decode latency.
Definition nr-phy.cc:889
static TypeId GetTypeId()
Get the TypeId of the Object.
Definition nr-phy.cc:151
SlotAllocInfo & PeekSlotAllocInfo(const SfnSf &sfnsf)
Peek the SlotAllocInfo at the SfnSf specified.
Definition nr-phy.cc:818
double GetCentralFrequency() const
Retrieve the frequency (in Hz) of this PHY's channel.
Definition nr-phy.cc:406
void SetMacPdu(const Ptr< Packet > &p, const SfnSf &sfn, uint8_t symStart, uint16_t rnti)
Store a MAC PDU.
Definition nr-phy.cc:342
double m_noiseFigure
Noise figure (attribute)
Definition nr-phy.h:561
virtual uint32_t GetNumRbPerRbg() const =0
Protected function that is used to get the number of resource blocks per resource block group.
void SetSymbolsPerSlot(uint16_t symbolsPerSlot)
Set the number of symbol per slot.
Definition nr-phy.cc:296
void SetDevice(Ptr< NrNetDevice > d)
Set the owner device.
Definition nr-phy.cc:228
uint32_t m_raPreambleId
Preamble ID.
Definition nr-phy.h:570
Ptr< const SpectrumModel > GetSpectrumModel()
Get the spectrum model of the PHY.
Definition nr-phy.cc:848
size_t SlotAllocInfoSize() const
Retrieve the size of the SlotAllocInfo list.
Definition nr-phy.cc:834
double GetNoiseFigure() const
Get the NoiseFigure value.
Definition nr-phy.cc:877
void SetNoiseFigure(double d)
Set the NoiseFigure value.
Definition nr-phy.cc:866
double m_txPower
Transmission power (attribute)
Definition nr-phy.h:560
void InitializeMessageList()
Initialize the message list.
Definition nr-phy.cc:599
void DoUpdateRbNum()
Update the number of RB. Usually called after bandwidth changes.
Definition nr-phy.cc:534
Ptr< SpectrumValue > GetTxPowerSpectralDensity(const std::vector< int > &rbIndexVector)
Definition nr-phy.cc:395
virtual double GetTxPower() const =0
Retrieve the Tx power.
void SetChannelBandwidth(uint16_t bandwidth)
Function to set the channel bandwidth, used also by child classes, i.e., see functions DoSetDlBanwidt...
Definition nr-phy.cc:243
uint16_t GetBwpId() const
Definition nr-phy.cc:652
void PushFrontSlotAllocInfo(const SfnSf &newSfnSf, const SlotAllocInfo &slotAllocInfo)
Store the slot allocation info at the front.
Definition nr-phy.cc:718
Ptr< NrNetDevice > m_netDevice
Pointer to the owner netDevice.
Definition nr-phy.h:557
virtual BeamId GetBeamId(uint16_t rnti) const =0
Get the beam id for the specified user.
uint32_t GetL1L2CtrlLatency() const
Definition nr-phy.cc:664
bool HasDlSlot() const
Go through the current pattern and see if at least one slot is DL, F or S.
Definition nr-phy.cc:477
bool SlotAllocInfoExists(const SfnSf &sfnsf) const
Check if the SlotAllocationInfo for that slot exists.
Definition nr-phy.cc:774
std::unordered_map< uint64_t, Ptr< PacketBurst > > m_packetBurstMap
Map between SfnSf and PacketBurst.
Definition nr-phy.h:564
uint32_t GetSubcarrierSpacing() const
Retrieve the subcarrier spacing in Hz. Subcarrier spacing is updated when the numerology is being upd...
Definition nr-phy.cc:528
uint32_t GetSymbolsPerSlot() const
Get the number of symbols in a slot.
Definition nr-phy.cc:316
std::vector< LteNrTddSlotType > m_tddPattern
Pattern.
Definition nr-phy.h:573
Ptr< SpectrumValue > GetNoisePowerSpectralDensity()
Create Noise Power Spectral density.
Definition nr-phy.cc:388
bool IsCtrlMsgListEmpty() const
Check if there are no control messages queued for this slot.
Definition nr-phy.cc:841
NrPhySapProvider * m_phySapProvider
Pointer to the MAC.
Definition nr-phy.h:568
double GetRbOverhead() const
Get the bandwidth overhead used when calculating the usable RB number.
Definition nr-phy.cc:310
bool HasUlSlot() const
Go through the current pattern and see if at least one slot is UL, F or S.
Definition nr-phy.cc:483
void SetBwpId(uint16_t bwpId)
Set the bwp id. Called by helper.
Definition nr-phy.cc:646
uint32_t GetRbNum() const
Get the number of Resource block configured.
Definition nr-phy.cc:515
std::vector< int > FromRBGBitmaskToRBAssignment(const std::vector< bool > rbgBitmask) const
Transform a MAC-made vector of RBG to a PHY-ready vector of SINR indices.
Definition nr-phy.cc:165
void EnqueueCtrlMessage(const Ptr< NrControlMessage > &m)
Enqueue a ctrl message, keeping in consideration L1L2CtrlDelay.
Definition nr-phy.cc:445
static bool IsTdd(const std::vector< LteNrTddSlotType > &pattern)
Check if a pattern is TDD.
Definition nr-phy.cc:572
NrPhySapProvider * GetPhySapProvider()
Retrieve a pointer to an instance of NrPhySapProvider.
Definition nr-phy.cc:676
void DoDispose() override
DoDispose method inherited from Object.
Definition nr-phy.cc:200
void DoSetCellId(uint16_t cellId)
Set the cell ID.
Definition nr-phy.cc:329
SAP interface between the MAC and the PHY.
Definition nr-phy-sap.h:36
The SfnSf class.
Definition sfnsf.h:32
@ F
DL CTRL + DL DATA + UL DATA + UL CTRL.
The SlotAllocInfo struct.