5G-LENA nr-v3.0-32-g83aee33
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-spectrum-phy.h
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#ifndef NR_SPECTRUM_PHY_H
8#define NR_SPECTRUM_PHY_H
9
10#include "beam-manager.h"
11#include "nr-control-messages.h"
12#include "nr-harq-phy.h"
13#include "nr-interference.h"
14#include "nr-phy.h"
15#include "nr-spectrum-signal-parameters.h"
16
17#include <ns3/lte-chunk-processor.h>
18#include <ns3/net-device.h>
19#include <ns3/random-variable-stream.h>
20#include <ns3/spectrum-channel.h>
21#include <ns3/traced-callback.h>
22
23#include <functional>
24
25namespace ns3
26{
27
28class UniformPlanarArray;
29
72class NrSpectrumPhy : public SpectrumPhy
73{
74 public:
79 static TypeId GetTypeId();
80
85
89 ~NrSpectrumPhy() override;
90
104
105 // callbacks typefefs and setters
109 typedef Callback<void, const Ptr<Packet>&> NrPhyRxDataEndOkCallback;
113 typedef std::function<void(const std::list<Ptr<NrControlMessage>>&, uint8_t)>
115
120 typedef Callback<void, uint16_t, const Ptr<SpectrumValue>&> NrPhyRxPssCallback;
121
126 typedef Callback<void, const DlHarqInfo&> NrPhyDlHarqFeedbackCallback;
131 typedef Callback<void, const UlHarqInfo&> NrPhyUlHarqFeedbackCallback;
132
143
151
160
161 // Methods inherited from spectrum phy
162 void SetDevice(Ptr<NetDevice> d) override;
163 Ptr<NetDevice> GetDevice() const override;
164 void SetMobility(Ptr<MobilityModel> m) override;
165 Ptr<MobilityModel> GetMobility() const override;
166 void SetChannel(Ptr<SpectrumChannel> c) override;
167 Ptr<const SpectrumModel> GetRxSpectrumModel() const override;
168 /*
169 * \brief Sets the beam manager of this spectrum phy, and that beam manager
170 * is responsible of the antena array of this spectrum phy
171 */
172 void SetBeamManager(Ptr<BeamManager> b);
173
174 /*
175 * \brief Gets the beam manager of this spectrum phy.
176 */
177 Ptr<BeamManager> GetBeamManager();
178
179 /*
180 * \brief Sets the error model of this spectrum phy, overriding the default
181 * that is created by the attribute NrSpectrumPhy::ErrorModelType
182 *
183 * \param em The error model
184 */
185 void SetErrorModel(Ptr<NrErrorModel> em);
186
187 /*
188 * \brief Gets a pointer to the error model (if instantiated)
189 */
190 Ptr<NrErrorModel> GetErrorModel() const;
191
197 Ptr<Object> GetAntenna() const override;
198
199 /*
200 * \brief Used to enable generation and triggering of DL DATA pathloss trace
201 */
202 void EnableDlDataPathlossTrace();
203
204 /*
205 * \brief Used to enable generation and triggering of DL CTRL pahtloss trace
206 */
207 void EnableDlCtrlPathlossTrace();
208
214 void StartRx(Ptr<SpectrumSignalParameters> params) override;
215
216 void SetRnti(uint16_t rnti);
217
218 // Attributes setters
223 void SetCcaMode1Threshold(double thresholdDBm);
228 double GetCcaMode1Threshold() const;
233 void SetUnlicensedMode(bool unlicensedMode);
238 void SetDataErrorModelEnabled(bool dataErrorModelEnabled);
242 void SetErrorModelType(TypeId errorModelType);
243
244 // other methods
249 void SetNoisePowerSpectralDensity(const Ptr<const SpectrumValue>& noisePsd);
255 void SetTxPowerSpectralDensity(const Ptr<SpectrumValue>& txPsd);
256 /*
257 * \brief Returns the TX PSD
258 * \return the TX PSD
259 */
260 Ptr<const SpectrumValue> GetTxPowerSpectralDensity();
268 void StartTxDataFrames(const Ptr<PacketBurst>& pb,
269 const std::list<Ptr<NrControlMessage>>& ctrlMsgList,
270 const std::shared_ptr<DciInfoElementTdma> dci,
271 const Time& duration);
272
276 bool IsTransmitting();
277
282 void StartTxDlControlFrames(const std::list<Ptr<NrControlMessage>>& ctrlMsgList,
283 const Time& duration); // control frames from enb to ue
289 void StartTxUlControlFrames(const std::list<Ptr<NrControlMessage>>& ctrlMsgList,
290 const Time& duration);
295 void AddDataPowerChunkProcessor(const Ptr<LteChunkProcessor>& p);
300 void AddDataSinrChunkProcessor(const Ptr<LteChunkProcessor>& p);
301
302 /*
303 * \brief Adds the chunk processort that will process the interference for SRS signals at gNBs
304 * \param p the chunk processor
305 */
306 void AddSrsSinrChunkProcessor(const Ptr<LteChunkProcessor>& p);
307
312 void AddRsPowerChunkProcessor(const Ptr<LteChunkProcessor>& p);
313
318 void AddDlCtrlSinrChunkProcessor(const Ptr<LteChunkProcessor>& p);
325 void UpdateSinrPerceived(const SpectrumValue& sinr);
326
331 void ReportDlCtrlSinr(const SpectrumValue& sinr);
332
339 void UpdateSrsSinrPerceived(const SpectrumValue& srsSinr);
345 void UpdateSrsSnrPerceived(const double srsSnr);
350 void InstallHarqPhyModule(const Ptr<NrHarqPhy>& harq);
355 void InstallPhy(const Ptr<NrPhy>& phyModel);
356
357 Ptr<NrPhy> GetPhy() const;
363 void SetAntenna(Ptr<Object> antenna);
367 Ptr<SpectrumChannel> GetSpectrumChannel() const;
371 Ptr<NrHarqPhy> GetHarqPhyModule() const;
375 Ptr<NrInterference> GetNrInterference() const;
391 void AddExpectedTb(uint16_t rnti,
392 uint8_t ndi,
393 uint32_t size,
394 uint8_t mcs,
395 uint8_t rank,
396 const std::vector<int>& rbMap,
397 uint8_t harqId,
398 uint8_t rv,
399 bool downlink,
400 uint8_t symStart,
401 uint8_t numSym,
402 const SfnSf& sfn);
403
412 int64_t AssignStreams(int64_t stream);
413
423 typedef void (*RxDataTracedCallback)(const SfnSf& sfnSf,
424 Ptr<const SpectrumValue> v,
425 const Time& t,
426 uint16_t bwpId,
427 uint16_t cellId);
428
429 void AddExpectedSrsRnti(uint16_t rnti);
430
431 /*
432 * \brief SRS SINR callback whose input parameters are cellid, rnti, SRS SINR value
433 */
434 typedef Callback<void, uint16_t, uint16_t, double> SrsSinrReportCallback;
435 typedef Callback<void, uint16_t, uint16_t, double> SrsSnrReportCallback;
436
442 void AddSrsSinrReportCallback(SrsSinrReportCallback callback);
448 void AddSrsSnrReportCallback(SrsSnrReportCallback callback);
454 void SetIsEnb(bool isEnb);
458 uint16_t GetCellId() const;
462 uint16_t GetBwpId() const;
470 typedef void (*DataSnrTracedCallback)(const SfnSf& sfnSf,
471 const uint16_t cellId,
472 const uint8_t bwpId,
473 const uint64_t imsi,
474 const double snr);
480 void ReportWbDlDataSnrPerceived(const double dlDataSnr);
481
482 void AddDataMimoChunkProcessor(const Ptr<NrMimoChunkProcessor>& p);
483
488 void UpdateMimoSinrPerceived(const std::vector<MimoSinrChunk>& sinr);
489
490 protected:
494 void DoDispose() override;
495
496 private:
497 std::vector<MimoSinrChunk>
498 m_mimoSinrPerceived;
500
505 void StartRxData(const Ptr<NrSpectrumSignalParametersDataFrame>& params);
510 void StartRxDlCtrl(const Ptr<NrSpectrumSignalParametersDlCtrlFrame>& params);
515 void StartRxUlCtrl(const Ptr<NrSpectrumSignalParametersUlCtrlFrame>& params);
521 void StartRxSrs(const Ptr<NrSpectrumSignalParametersUlCtrlFrame>& params);
525 bool IsEnb() const;
532 void ChangeState(State newState, Time duration);
537 void EndTx();
538
544 std::vector<MimoSinrChunk> GetMimoSinrForRnti(uint16_t rnti, uint8_t rank);
545
551 void EndRxData();
556 void EndRxCtrl();
563 void EndRxSrs();
567 void MaybeCcaBusy();
575 void CheckIfStillBusy();
583 bool IsOnlySrs(const std::list<Ptr<NrControlMessage>>& ctrlMsgList);
584
590 struct ExpectedTb
591 {
592 ExpectedTb(uint8_t ndi,
593 uint32_t tbSize,
594 uint8_t mcs,
595 uint8_t rank,
596 uint16_t rnti,
597 const std::vector<int>& rbBitmap,
598 uint8_t harqProcessId,
599 uint8_t rv,
600 bool isDownlink,
601 uint8_t symStart,
602 uint8_t numSym,
603 const SfnSf& sfn)
604 : m_ndi(ndi),
605 m_tbSize(tbSize),
606 m_mcs(mcs),
607 m_rank(rank),
608 m_rnti(rnti),
609 m_rbBitmap(rbBitmap),
610 m_harqProcessId(harqProcessId),
611 m_rv(rv),
612 m_isDownlink(isDownlink),
613 m_symStart(symStart),
614 m_numSym(numSym),
615 m_sfn(sfn)
616 {
617 }
618
619 ExpectedTb() = delete;
620 ExpectedTb(const ExpectedTb& o) = default;
621
622 uint8_t m_ndi{0};
623 uint32_t m_tbSize{0};
624 uint8_t m_mcs{0};
625 uint8_t m_rank{1};
626 uint16_t m_rnti{0};
627 std::vector<int> m_rbBitmap;
628 uint8_t m_harqProcessId{0};
629 uint8_t m_rv{0};
630 bool m_isDownlink{false};
631 uint8_t m_symStart{0};
632 uint8_t m_numSym{0};
633 SfnSf m_sfn;
634 };
635
636 struct TransportBlockInfo
637 {
638 TransportBlockInfo(const ExpectedTb& expected)
639 : m_expected(expected)
640 {
641 }
642
643 TransportBlockInfo() = delete;
644
645 ExpectedTb m_expected;
646 bool m_isCorrupted{false};
647 // Filled at the end of data rx/tx
648 bool m_harqFeedbackSent{false};
649 Ptr<NrErrorModelOutput>
650 m_outputOfEM;
651 double m_sinrAvg{0.0};
652 double m_sinrMin{0.0};
653 };
654
655 // attributes
656 TypeId m_errorModelType{
657 Object::GetTypeId()};
658 bool m_dataErrorModelEnabled{
659 true};
660 double m_ccaMode1ThresholdW{0};
662 // CcaMode1Threshold and is configured in dBm
663 bool m_unlicensedMode{
664 false};
665 // Unlicensed mode additionally to licensed mode allows channel monitoring to
666 // discover if is busy before transmission.
667
668 Ptr<SpectrumChannel> m_channel{
669 nullptr};
671 Ptr<const SpectrumModel> m_rxSpectrumModel{
672 nullptr};
673 Ptr<BeamManager> m_beamManager{
674 nullptr};
675 Ptr<MobilityModel> m_mobility{
676 nullptr};
677 Ptr<NetDevice> m_device{nullptr};
678 Ptr<NrPhy> m_phy{nullptr};
679 Ptr<NrErrorModel> m_errorModel{nullptr};
680 Ptr<Object> m_antenna{nullptr};
682 Ptr<NrHarqPhy> m_harqPhyModule{nullptr};
683 Ptr<NrInterference> m_interferenceData{nullptr};
685 Ptr<NrInterference> m_interferenceCtrl{nullptr};
687 Ptr<NrInterference> m_interferenceSrs{
688 nullptr};
690 Ptr<SpectrumValue> m_txPsd{nullptr};
691 Ptr<UniformRandomVariable> m_random{nullptr};
692
693 std::unordered_map<uint16_t, TransportBlockInfo>
694 m_transportBlocks;
696 std::list<Ptr<PacketBurst>> m_rxPacketBurstList;
697 std::list<Ptr<NrControlMessage>>
698 m_rxControlMessageList;
699
700 Time m_firstRxStart{
701 Seconds(0)};
702 Time m_firstRxDuration{Seconds(0)};
703 State m_state{IDLE};
704 SpectrumValue m_sinrPerceived;
706
707 uint16_t m_rnti{0};
708 bool m_hasRnti{false};
709 uint16_t m_activeTransmissions{0};
711
712 std::list<SrsSinrReportCallback> m_srsSinrReportCallback;
713 std::list<SrsSnrReportCallback> m_srsSnrReportCallback;
714 uint16_t m_currentSrsRnti{0};
715 EventId m_checkIfIsIdleEvent;
717 Time m_busyTimeEnds{
718 Seconds(0)};
719
720 // callbacks for CTRL and DATA, and UL/DL HARQ
722 m_phyRxCtrlEndOkCallback;
724 m_phyRxDataEndOkCallback;
725 NrPhyRxPssCallback m_phyRxPssCallback;
727 m_phyDlHarqFeedbackCallback;
730 m_phyUlHarqFeedbackCallback;
732
733 // traces
734 TracedCallback<Time>
735 m_channelOccupied;
737 TracedCallback<Time> m_txDataTrace;
739 TracedCallback<Time> m_txCtrlTrace;
741 TracedCallback<RxPacketTraceParams>
742 m_rxPacketTraceEnb;
743 TracedCallback<RxPacketTraceParams>
744 m_rxPacketTraceUe;
745 TracedCallback<GnbPhyPacketCountParameter>
746 m_txPacketTraceEnb;
747 TracedCallback<const SfnSf&, Ptr<const SpectrumValue>, const Time&, uint16_t, uint16_t>
748 m_rxDataTrace;
749 TracedCallback<const SfnSf,
750 const uint16_t,
751 const uint8_t,
752 const uint64_t,
753 const double>
754 m_dlDataSnrTrace;
755
756 /*
757 * \brief Trace source that reports the following: Cell ID, Bwp ID, UE node ID, DL
758 * CTRL pathloss
759 */
760 typedef TracedCallback<uint16_t, uint8_t, uint32_t, double> DlPathlossTrace;
761 DlPathlossTrace m_dlCtrlPathlossTrace;
762 bool m_enableDlCtrlPathlossTrace =
763 false;
764 /*
765 * \brief Trace source that reports the following: Cell ID, Bwp ID, UE node ID, DL
766 * CTRL pathloss, CQI that corresponds to the current SINR
767 */
768 typedef TracedCallback<uint16_t, uint8_t, uint32_t, double, uint8_t> DlDataPathlossTrace;
769 DlDataPathlossTrace m_dlDataPathlossTrace;
770 bool m_enableDlDataPathlossTrace =
771 false;
772 bool m_isEnb = false;
773};
774
775} // namespace ns3
776
777#endif /* NR_SPECTRUM_PHY_H */
Interface between the physical layer and the channel.
void SetUnlicensedMode(bool unlicensedMode)
Sets whether to perform in unclicensed mode in which the channel monitoring is enabled.
void SetErrorModelType(TypeId errorModelType)
Sets the error model type.
void(* DataSnrTracedCallback)(const SfnSf &sfnSf, const uint16_t cellId, const uint8_t bwpId, const uint64_t imsi, const double snr)
void UpdateSrsSnrPerceived(const double srsSnr)
SpectrumPhy that will be called when the SNR for the received SRS at gNB is being calculated.
void ReportWbDlDataSnrPerceived(const double dlDataSnr)
Report wideband perceived downlink data SNR.
void UpdateSinrPerceived(const SpectrumValue &sinr)
SpectrumPhy that will be called when the SINR for the received DATA is being calculated by the interf...
NrSpectrumPhy()
NrSpectrumPhy constructor.
void SetPhyRxCtrlEndOkCallback(const NrPhyRxCtrlEndOkCallback &c)
Sets the callback to be called when CTRL is received successfully.
void SetIsEnb(bool isEnb)
Set whether this spectrum PHY belongs to eNB or UE TODO NrHelper should be declared as friend and thi...
static TypeId GetTypeId()
Get the object TypeId.
void StartTxUlControlFrames(const std::list< Ptr< NrControlMessage > > &ctrlMsgList, const Time &duration)
Start transmission of UL CTRL.
~NrSpectrumPhy() override
~NrSpectrumPhy
std::function< void(const std::list< Ptr< NrControlMessage > > &, uint8_t)> NrPhyRxCtrlEndOkCallback
This callback method type is used to notify that CTRL is received.
Ptr< NrHarqPhy > GetHarqPhyModule() const
void InstallHarqPhyModule(const Ptr< NrHarqPhy > &harq)
Install HARQ phy module of this spectrum phy.
void AddSrsSnrReportCallback(SrsSnrReportCallback callback)
It adds callback to the list of callbacks that will be notified once SRS is being received.
void SetPhyDlHarqFeedbackCallback(const NrPhyDlHarqFeedbackCallback &c)
Sets the callback to be called when DL HARQ feedback is generated.
void AddDataSinrChunkProcessor(const Ptr< LteChunkProcessor > &p)
Adds the chunk processor that will process the interference.
Ptr< NrInterference > GetNrInterference() const
void DoDispose() override
DoDispose method inherited from Object.
void UpdateSrsSinrPerceived(const SpectrumValue &srsSinr)
SpectrumPhy that will be called when the SINR for the received SRS at gNB is being calculated by the ...
Callback< void, const UlHarqInfo & > NrPhyUlHarqFeedbackCallback
void SetNoisePowerSpectralDensity(const Ptr< const SpectrumValue > &noisePsd)
Sets noise power spectral density to be used by this device.
void SetCcaMode1Threshold(double thresholdDBm)
Set clear channel assessment (CCA) threshold.
void StartTxDlControlFrames(const std::list< Ptr< NrControlMessage > > &ctrlMsgList, const Time &duration)
Starts transmission of DL CTRL.
void InstallPhy(const Ptr< NrPhy > &phyModel)
Set NrPhy of this spectrum phy in order to be able to obtain information such as cellId,...
void AddDlCtrlSinrChunkProcessor(const Ptr< LteChunkProcessor > &p)
Adds the chunk processor that will process the received power.
void UpdateMimoSinrPerceived(const std::vector< MimoSinrChunk > &sinr)
Store the SINR chunks for all received signals at end of interference calculations.
bool IsTransmitting()
Return true if the current Phy State is TX.
double GetCcaMode1Threshold() const
Callback< void, const DlHarqInfo & > NrPhyDlHarqFeedbackCallback
void AddDataPowerChunkProcessor(const Ptr< LteChunkProcessor > &p)
Adds the chunk processor that will process the power for the data.
int64_t AssignStreams(int64_t stream)
Ptr< SpectrumChannel > GetSpectrumChannel() const
Returns spectrum channel object to which is attached this spectrum phy instance.
uint16_t GetCellId() const
Callback< void, uint16_t, const Ptr< SpectrumValue > & > NrPhyRxPssCallback
void SetDataErrorModelEnabled(bool dataErrorModelEnabled)
Enables or disabled data error model.
void AddExpectedTb(uint16_t rnti, uint8_t ndi, uint32_t size, uint8_t mcs, uint8_t rank, const std::vector< int > &rbMap, uint8_t harqId, uint8_t rv, bool downlink, uint8_t symStart, uint8_t numSym, const SfnSf &sfn)
Instruct the Spectrum Model of a incoming transmission.
void SetPhyRxDataEndOkCallback(const NrPhyRxDataEndOkCallback &c)
Sets the callback to be called when DATA is received successfully.
void AddRsPowerChunkProcessor(const Ptr< LteChunkProcessor > &p)
Adds the chunk processor that will process the received power.
void ReportDlCtrlSinr(const SpectrumValue &sinr)
Called when DlCtrlSinr is fired.
void SetTxPowerSpectralDensity(const Ptr< SpectrumValue > &txPsd)
Sets transmit power spectral density.
void SetPhyUlHarqFeedbackCallback(const NrPhyUlHarqFeedbackCallback &c)
Sets the callback to be called when UL HARQ feedback is generated.
void SetAntenna(Ptr< Object > antenna)
Sets the antenna of this NrSpectrumPhy instance, currently in NR module it is expected to be of type ...
void AddSrsSinrReportCallback(SrsSinrReportCallback callback)
It adds callback to the list of callbacks that will be notified once SRS is being received.
void StartTxDataFrames(const Ptr< PacketBurst > &pb, const std::list< Ptr< NrControlMessage > > &ctrlMsgList, const std::shared_ptr< DciInfoElementTdma > dci, const Time &duration)
Starts transmission of data frames on connected spectrum channel object.
void(* RxDataTracedCallback)(const SfnSf &sfnSf, Ptr< const SpectrumValue > v, const Time &t, uint16_t bwpId, uint16_t cellId)
TracedCallback signature for RB statistics.
Callback< void, const Ptr< Packet > & > NrPhyRxDataEndOkCallback
This callback method type is used to notify that DATA is received.
State
Enum that defines possible states of the spectrum phy.
@ RX_DATA
Receiving data.
@ TX
Transmitting state (data or ctrl)
@ RX_UL_SRS
Receiving SRS.
@ CCA_BUSY
BUSY state (channel occupied by another entity)
@ RX_UL_CTRL
Receiving UL CTRL.
@ RX_DL_CTRL
receiving DL CTRL
@ IDLE
IDLE state (no action in progress)
uint16_t GetBwpId() const
void StartRx(Ptr< SpectrumSignalParameters > params) override
Inherited from SpectrumPhy. When this function is called this spectrum phy starts receiving a signal ...
Ptr< Object > GetAntenna() const override
Inherited from SpectrumPhy Note: Implements GetAntenna function from SpectrumPhy.
void SetPhyRxPssCallback(const NrPhyRxPssCallback &c)
The SfnSf class.
Definition sfnsf.h:34