5G-LENA nr-v3.0-32-g83aee33
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-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_PHY_H
8#define NR_PHY_H
9
10#include "nr-phy-mac-common.h"
11#include "nr-phy-sap.h"
12
13#include <ns3/nr-spectrum-value-helper.h>
14
15namespace ns3
16{
17
18class NrNetDevice;
19class NrControlMessage;
20class NrSpectrumPhy;
21class AntennaArrayBasicModel;
22class UniformPlanarArray;
23
68class NrPhy : public Object
69{
70 public:
74 NrPhy();
75
79 ~NrPhy() override;
80
85 static TypeId GetTypeId();
86
87 // Called by SAP
92 void EnqueueCtrlMessage(const Ptr<NrControlMessage>& m);
93
103 void SetMacPdu(const Ptr<Packet>& p, const SfnSf& sfn, uint8_t symStart, uint16_t rnti);
104
114 void SendRachPreamble(uint32_t PreambleId, uint32_t Rnti);
115
123 void PushBackSlotAllocInfo(const SlotAllocInfo& slotAllocInfo);
124
130
135 virtual void SetTbDecodeLatency(const Time& us);
136
141 virtual Time GetTbDecodeLatency() const;
142
148 virtual BeamId GetBeamId(uint16_t rnti) const = 0;
149
154 Ptr<const SpectrumModel> GetSpectrumModel();
155
160 uint32_t GetSymbolsPerSlot() const;
161
166 Time GetSlotPeriod() const;
167
173 Time GetSymbolPeriod() const;
174
179 void SetNoiseFigure(double d);
180
185 double GetNoiseFigure() const;
186
192 virtual double GetTxPower() const = 0;
193
194 // Installation / Helpers
200
205 void SetDevice(Ptr<NrNetDevice> d);
206
213 void InstallCentralFrequency(double f);
214
222 void SetNumerology(uint16_t numerology);
223
228 uint16_t GetNumerology() const;
229
234 void SetSymbolsPerSlot(uint16_t symbolsPerSlot);
235
240 void SetRbOverhead(double oh);
241
246 double GetRbOverhead() const;
247
255 Ptr<NrSpectrumPhy> GetSpectrumPhy() const;
256
261 void InstallSpectrumPhy(const Ptr<NrSpectrumPhy>& spectrumPhy);
262
273 virtual void ScheduleStartEventLoop(uint32_t nodeId,
274 uint16_t frame,
275 uint8_t subframe,
276 uint16_t slot) = 0;
277
281 void SetBwpId(uint16_t bwpId);
282
286 uint16_t GetBwpId() const;
287
291 uint16_t GetCellId() const;
292
298 uint32_t GetRbNum() const;
299
304 uint32_t GetChannelBandwidth() const;
305
311 uint32_t GetSubcarrierSpacing() const;
312
320 uint32_t GetL1L2CtrlLatency() const;
321
322 // SAP
329 void DoSetCellId(uint16_t cellId);
330
335 void EncodeCtrlMsg(const Ptr<NrControlMessage>& msg);
336
342 bool HasDlSlot() const;
343
349 bool HasUlSlot() const;
350
357 static bool HasDlSlot(const std::vector<LteNrTddSlotType>& pattern);
358
365 static bool HasUlSlot(const std::vector<LteNrTddSlotType>& pattern);
366
373 double GetCentralFrequency() const;
374
379 virtual const SfnSf& GetCurrentSfnSf() const = 0;
380
386 static std::string GetPattern(const std::vector<LteNrTddSlotType>& pattern);
387
395 enum NrSpectrumValueHelper::PowerAllocationType powerAllocationType);
396
400 enum NrSpectrumValueHelper::PowerAllocationType GetPowerAllocationType() const;
401
402 protected:
406 void DoDispose() override;
410 void DoUpdateRbNum();
411
421 void SetChannelBandwidth(uint16_t bandwidth);
422
428 static bool IsTdd(const std::vector<LteNrTddSlotType>& pattern);
429
444 std::vector<int> FromRBGBitmaskToRBAssignment(const std::vector<uint8_t> rbgBitmask) const;
445
451 virtual uint32_t GetNumRbPerRbg() const = 0;
452
460 Ptr<PacketBurst> GetPacketBurst(SfnSf sf, uint8_t sym, uint16_t rnti);
461
467 Ptr<SpectrumValue> GetNoisePowerSpectralDensity();
468
478 Ptr<SpectrumValue> GetTxPowerSpectralDensity(const std::vector<int>& rbIndexVector);
479
486 void PushFrontSlotAllocInfo(const SfnSf& newSfnSf, const SlotAllocInfo& slotAllocInfo);
487
493 bool SlotAllocInfoExists(const SfnSf& sfnsf) const;
494
501
510
519
524 size_t SlotAllocInfoSize() const;
525
530 bool IsCtrlMsgListEmpty() const;
531
536 void EnqueueCtrlMsgNow(const Ptr<NrControlMessage>& msg);
537
542 void EnqueueCtrlMsgNow(const std::list<Ptr<NrControlMessage>>& listOfMsgs);
543
552 virtual std::list<Ptr<NrControlMessage>> PopCurrentSlotCtrlMsgs();
553
554 protected:
555 Ptr<NrNetDevice> m_netDevice;
556 Ptr<NrSpectrumPhy> m_spectrumPhy;
557
558 double m_txPower{0.0};
559 double m_noiseFigure{0.0};
560
561 std::unordered_map<uint64_t, Ptr<PacketBurst>>
563
565
567
568 uint32_t m_raPreambleId{0};
569 std::list<Ptr<NrControlMessage>> m_ctrlMsgs;
570
571 std::vector<LteNrTddSlotType> m_tddPattern = {F, F, F, F, F, F, F, F, F, F};
572
573 private:
574 std::list<SlotAllocInfo> m_slotAllocInfo;
575 std::vector<std::list<Ptr<NrControlMessage>>> m_controlMessageQueue;
576
577 Time m_tbDecodeLatencyUs{MicroSeconds(100)};
578 double m_centralFrequency{-1.0};
579 uint16_t m_channelBandwidth{
580 0};
581 // E.g. if set to 200, the bandwidth will be 20 MHz (= 200 * 100 KHz)
582
583 uint16_t m_cellId{0};
584 uint16_t m_bwpId{
585 UINT16_MAX};
586 uint16_t m_numerology{
587 0};
588 uint16_t m_symbolsPerSlot{14};
589
590 uint16_t m_slotsPerSubframe{0};
591 Time m_slotPeriod{0};
592 Time m_symbolPeriod{0};
593 uint32_t m_subcarrierSpacing{0};
595 uint32_t m_rbNum{0};
596 double m_rbOh{0.04};
597
598 enum NrSpectrumValueHelper::PowerAllocationType m_powerAllocationType{
599 NrSpectrumValueHelper::UNIFORM_POWER_ALLOCATION_USED};
603};
604
605} // namespace ns3
606
607#endif /* NR_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
Time GetSymbolPeriod() const
Get SymbolPeriod.
Definition nr-phy.cc:848
Ptr< NrSpectrumPhy > m_spectrumPhy
Pointer to the (owned) spectrum phy.
Definition nr-phy.h:556
SlotAllocInfo RetrieveSlotAllocInfo()
Get the head for the slot allocation info, and delete it from the internal list.
Definition nr-phy.cc:778
uint16_t GetCellId() const
Definition nr-phy.cc:647
virtual const SfnSf & GetCurrentSfnSf() const =0
Get the current SfnSf.
uint16_t GetNumerology() const
Get the configured numerology.
Definition nr-phy.cc:274
Ptr< NrSpectrumPhy > GetSpectrumPhy() const
Retrieve the SpectrumPhy pointer.
Definition nr-phy.cc:659
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:459
void SetNumerology(uint16_t numerology)
Set GNB or UE numerology.
Definition nr-phy.cc:246
virtual void SetTbDecodeLatency(const Time &us)
Configures TB decode latency.
Definition nr-phy.cc:872
std::list< Ptr< NrControlMessage > > m_ctrlMsgs
CTRL messages to be sent.
Definition nr-phy.h:569
void SetRbOverhead(double oh)
Set the bandwidth overhead for calculating the usable RB number.
Definition nr-phy.cc:288
void PushBackSlotAllocInfo(const SlotAllocInfo &slotAllocInfo)
Store the slot allocation info.
Definition nr-phy.cc:672
void NotifyConnectionSuccessful()
Notify PHY about the successful RRC connection establishment.
Definition nr-phy.cc:348
void InstallCentralFrequency(double f)
Install the PHY over a particular central frequency.
Definition nr-phy.cc:219
~NrPhy() override
~NrPhy
Definition nr-phy.cc:188
Ptr< PacketBurst > GetPacketBurst(SfnSf sf, uint8_t sym, uint16_t rnti)
Retrieve the PacketBurst at the slot/symbol specified.
Definition nr-phy.cc:354
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:422
static std::string GetPattern(const std::vector< LteNrTddSlotType > &pattern)
Get a string representation of a pattern.
Definition nr-phy.cc:403
void InstallSpectrumPhy(const Ptr< NrSpectrumPhy > &spectrumPhy)
Set the SpectrumPhy associated with this PHY.
Definition nr-phy.cc:628
Time GetSlotPeriod() const
Get the slot period.
Definition nr-phy.cc:306
virtual std::list< Ptr< NrControlMessage > > PopCurrentSlotCtrlMsgs()
Extract and return the message list that is at the beginning of the queue.
Definition nr-phy.cc:600
void SendRachPreamble(uint32_t PreambleId, uint32_t Rnti)
Send the RachPreamble.
Definition nr-phy.cc:320
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:564
NrPhy()
NrPhy constructor.
Definition nr-phy.cc:180
enum NrSpectrumValueHelper::PowerAllocationType GetPowerAllocationType() const
Get the power allocation type.
Definition nr-phy.cc:428
void EnqueueCtrlMsgNow(const Ptr< NrControlMessage > &msg)
Enqueue a CTRL message without considering L1L2CtrlLatency.
Definition nr-phy.cc:442
uint32_t GetChannelBandwidth() const
Retrieve the channel bandwidth, in Hz.
Definition nr-phy.cc:510
virtual Time GetTbDecodeLatency() const
Returns Transport Block decode latency.
Definition nr-phy.cc:878
static TypeId GetTypeId()
Get the TypeId of the Object.
Definition nr-phy.cc:152
SlotAllocInfo & PeekSlotAllocInfo(const SfnSf &sfnsf)
Peek the SlotAllocInfo at the SfnSf specified.
Definition nr-phy.cc:807
double GetCentralFrequency() const
Retrieve the frequency (in Hz) of this PHY's channel.
Definition nr-phy.cc:395
void SetMacPdu(const Ptr< Packet > &p, const SfnSf &sfn, uint8_t symStart, uint16_t rnti)
Store a MAC PDU.
Definition nr-phy.cc:331
double m_noiseFigure
Noise figure (attribute)
Definition nr-phy.h:559
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:280
void SetDevice(Ptr< NrNetDevice > d)
Set the owner device.
Definition nr-phy.cc:212
uint32_t m_raPreambleId
Preamble ID.
Definition nr-phy.h:568
Ptr< const SpectrumModel > GetSpectrumModel()
Get the spectrum model of the PHY.
Definition nr-phy.cc:837
size_t SlotAllocInfoSize() const
Retrieve the size of the SlotAllocInfo list.
Definition nr-phy.cc:823
double GetNoiseFigure() const
Get the NoiseFigure value.
Definition nr-phy.cc:866
void SetNoiseFigure(double d)
Set the NoiseFigure value.
Definition nr-phy.cc:855
double m_txPower
Transmission power (attribute)
Definition nr-phy.h:558
void InitializeMessageList()
Initialize the message list.
Definition nr-phy.cc:588
void DoUpdateRbNum()
Update the number of RB. Usually called after bandwidth changes.
Definition nr-phy.cc:523
Ptr< SpectrumValue > GetTxPowerSpectralDensity(const std::vector< int > &rbIndexVector)
Definition nr-phy.cc:384
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:227
uint16_t GetBwpId() const
Definition nr-phy.cc:641
void PushFrontSlotAllocInfo(const SfnSf &newSfnSf, const SlotAllocInfo &slotAllocInfo)
Store the slot allocation info at the front.
Definition nr-phy.cc:707
std::vector< int > FromRBGBitmaskToRBAssignment(const std::vector< uint8_t > rbgBitmask) const
Transform a MAC-made vector of RBG to a PHY-ready vector of SINR indices.
Definition nr-phy.cc:160
Ptr< NrNetDevice > m_netDevice
Pointer to the owner netDevice.
Definition nr-phy.h:555
virtual BeamId GetBeamId(uint16_t rnti) const =0
Get the beam id for the specified user.
uint32_t GetL1L2CtrlLatency() const
Definition nr-phy.cc:653
bool HasDlSlot() const
Go through the current pattern and see if at least one slot is DL, F or S.
Definition nr-phy.cc:466
bool SlotAllocInfoExists(const SfnSf &sfnsf) const
Check if the SlotAllocationInfo for that slot exists.
Definition nr-phy.cc:763
std::unordered_map< uint64_t, Ptr< PacketBurst > > m_packetBurstMap
Map between SfnSf and PacketBurst.
Definition nr-phy.h:562
uint32_t GetSubcarrierSpacing() const
Retrieve the subcarrier spacing in Hz. Subcarrier spacing is updated when the numerology is being upd...
Definition nr-phy.cc:517
uint32_t GetSymbolsPerSlot() const
Get the number of symbols in a slot.
Definition nr-phy.cc:300
std::vector< LteNrTddSlotType > m_tddPattern
Pattern.
Definition nr-phy.h:571
Ptr< SpectrumValue > GetNoisePowerSpectralDensity()
Create Noise Power Spectral density.
Definition nr-phy.cc:377
bool IsCtrlMsgListEmpty() const
Check if there are no control messages queued for this slot.
Definition nr-phy.cc:830
NrPhySapProvider * m_phySapProvider
Pointer to the MAC.
Definition nr-phy.h:566
double GetRbOverhead() const
Get the bandwidth overhead used when calculating the usable RB number.
Definition nr-phy.cc:294
bool HasUlSlot() const
Go through the current pattern and see if at least one slot is UL, F or S.
Definition nr-phy.cc:472
void SetBwpId(uint16_t bwpId)
Set the bwp id. Called by helper.
Definition nr-phy.cc:635
uint32_t GetRbNum() const
Get the number of Resource block configured.
Definition nr-phy.cc:504
void EnqueueCtrlMessage(const Ptr< NrControlMessage > &m)
Enqueue a ctrl message, keeping in consideration L1L2CtrlDelay.
Definition nr-phy.cc:434
static bool IsTdd(const std::vector< LteNrTddSlotType > &pattern)
Check if a pattern is TDD.
Definition nr-phy.cc:561
NrPhySapProvider * GetPhySapProvider()
Retrieve a pointer to an instance of NrPhySapProvider.
Definition nr-phy.cc:665
void DoDispose() override
DoDispose method inherited from Object.
Definition nr-phy.cc:194
void DoSetCellId(uint16_t cellId)
Set the cell ID.
Definition nr-phy.cc:313
SAP interface between the MAC and the PHY.
Definition nr-phy-sap.h:38
The SfnSf class.
Definition sfnsf.h:34
@ F
DL CTRL + DL DATA + UL DATA + UL CTRL.
The SlotAllocInfo struct.