30#include <ns3/antenna-model.h>
31#include <ns3/boolean.h>
32#include <ns3/config.h>
33#include <ns3/double.h>
35#include <ns3/lte-mi-error-model.h>
36#include <ns3/lte-radio-bearer-tag.h>
37#include <ns3/object-factory.h>
38#include <ns3/simulator.h>
39#include <ns3/trace-source-accessor.h>
58 0.08, 0.1, 0.11, 0.15, 0.19, 0.24, 0.3, 0.37, 0.44, 0.51, 0.3, 0.33, 0.37, 0.42, 0.48,
59 0.54, 0.6, 0.43, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.89, 0.92};
102 m_componentCarrierId(0),
103 m_transmissionMode(0),
107 m_random = CreateObject<UniformRandomVariable>();
113 for (uint8_t i = 0; i < 7; i++)
188 TypeId(
"ns3::LteSpectrumPhy")
191 .AddTraceSource(
"TxStart",
192 "Trace fired when a new transmission is started",
194 "ns3::PacketBurst::TracedCallback")
195 .AddTraceSource(
"TxEnd",
196 "Trace fired when a previously started transmission is finished",
198 "ns3::PacketBurst::TracedCallback")
199 .AddTraceSource(
"RxStart",
200 "Trace fired when the start of a signal is detected",
202 "ns3::PacketBurst::TracedCallback")
203 .AddTraceSource(
"RxEndOk",
204 "Trace fired when a previously started RX terminates successfully",
206 "ns3::Packet::TracedCallback")
207 .AddTraceSource(
"RxEndError",
208 "Trace fired when a previously started RX terminates with an error",
210 "ns3::Packet::TracedCallback")
211 .AddAttribute(
"DataErrorModelEnabled",
212 "Activate/Deactivate the error model of data (TBs of PDSCH and PUSCH) "
213 "[by default is active].",
217 .AddAttribute(
"CtrlErrorModelEnabled",
218 "Activate/Deactivate the error model of control (PCFICH-PDCCH "
219 "decodification) [by default is active].",
223 .AddTraceSource(
"DlPhyReception",
224 "DL reception PHY layer statistics.",
226 "ns3::PhyReceptionStatParameters::TracedCallback")
227 .AddTraceSource(
"UlPhyReception",
228 "DL reception PHY layer statistics.",
230 "ns3::PhyReceptionStatParameters::TracedCallback");
422 NS_FATAL_ERROR(
"cannot TX while RX: according to FDD channel access, the physical layer "
423 "for transmission cannot be used for reception");
429 NS_FATAL_ERROR(
"cannot TX while already TX: the MAC should avoid this");
448 Create<LteSpectrumSignalParametersDataFrame>();
449 txParams->duration = duration;
450 txParams->txPhy = GetObject<SpectrumPhy>();
453 txParams->packetBurst = pb;
454 txParams->ctrlMsgList = ctrlMsgList;
480 NS_FATAL_ERROR(
"cannot TX while RX: according to FDD channel access, the physical layer "
481 "for transmission cannot be used for reception");
487 NS_FATAL_ERROR(
"cannot TX while already TX: the MAC should avoid this");
506 Create<LteSpectrumSignalParametersDlCtrlFrame>();
508 txParams->txPhy = GetObject<SpectrumPhy>();
513 txParams->ctrlMsgList = ctrlMsgList;
538 NS_FATAL_ERROR(
"cannot TX while RX: according to FDD channel access, the physical layer "
539 "for transmission cannot be used for reception");
545 NS_FATAL_ERROR(
"cannot TX while already TX: the MAC should avoid this");
564 Create<LteSpectrumSignalParametersUlSrsFrame>();
566 txParams->txPhy = GetObject<SpectrumPhy>();
629 DynamicCast<LteSpectrumSignalParametersDataFrame>(spectrumRxParams);
631 DynamicCast<LteSpectrumSignalParametersDlCtrlFrame>(spectrumRxParams);
633 DynamicCast<LteSpectrumSignalParametersUlSrsFrame>(spectrumRxParams);
639 else if (lteDlCtrlRxParams)
644 else if (lteUlSrsRxParams)
666 NS_FATAL_ERROR(
"cannot RX while TX: according to FDD channel access, the physical layer "
667 "for transmission cannot be used for reception");
683 NS_LOG_LOGIC(
this <<
" synchronized with this signal (cellId=" << params->cellId
693 << params->duration.As(
Time::S));
709 if (params->packetBurst)
716 NS_LOG_DEBUG(
this <<
" insert msgs " << params->ctrlMsgList.size());
718 params->ctrlMsgList.begin(),
719 params->ctrlMsgList.end());
725 NS_LOG_LOGIC(
this <<
" not in sync with this signal (cellId=" << params->cellId
726 <<
", m_cellId=" <<
m_cellId <<
")");
749 cellId = lteDlCtrlRxParams->cellId;
766 if (lteDlCtrlRxParams->pss ==
true)
779 NS_LOG_LOGIC(
this <<
" ignoring other DlCtrl (cellId=" << cellId
780 <<
", m_cellId=" <<
m_cellId <<
")");
786 NS_LOG_LOGIC(
this <<
" synchronized with this signal (cellId=" << cellId <<
")");
792 << lteDlCtrlRxParams->duration);
804 NS_LOG_LOGIC(
this <<
" not synchronizing with this signal (cellId=" << cellId
805 <<
", m_cellId=" <<
m_cellId <<
")");
832 NS_FATAL_ERROR(
"cannot RX while TX: according to FDD channel access, the physical layer "
833 "for transmission cannot be used for reception");
851 cellId = lteUlSrsRxParams->cellId;
854 NS_LOG_LOGIC(
this <<
" synchronized with this signal (cellId=" << cellId <<
")");
863 << lteUlSrsRxParams->duration);
883 NS_LOG_LOGIC(
this <<
" not in sync with this signal (cellId=" << cellId
884 <<
", m_cellId=" <<
m_cellId <<
")");
909 std::vector<int> map,
915 NS_LOG_FUNCTION(
this <<
" rnti: " << rnti <<
" NDI " << (uint16_t)ndi <<
" size " << size
916 <<
" mcs " << (uint16_t)mcs <<
" layer " << (uint16_t)layer <<
" rv "
921 expectedTbs_t::iterator it;
929 tbInfo_t tbInfo = {ndi, size, mcs, map, harqId, rv, 0.0, downlink,
false,
false};
930 m_expectedTbs.insert(std::pair<TbId_t, tbInfo_t>(tbId, tbInfo));
940 for (uint8_t i = 0; i < 2; i++)
943 expectedTbs_t::iterator it;
981 if ((*itTb).second.ndi == 0)
984 uint16_t ulHarqId = 0;
985 if ((*itTb).second.downlink)
989 (*itTb).first.m_layer);
998 (*itTb).second.rbBitmap,
1002 (*itTb).second.mi = tbStats.
mi;
1004 NS_LOG_DEBUG(
this <<
"RNTI " << (*itTb).first.m_rnti <<
" size " << (*itTb).second.size
1005 <<
" mcs " << (
uint32_t)(*itTb).second.mcs <<
" bitmap "
1006 << (*itTb).second.rbBitmap.size() <<
" layer "
1007 << (uint16_t)(*itTb).first.m_layer <<
" TBLER " << tbStats.
tbler
1008 <<
" corrupted " << (*itTb).second.corrupt);
1014 params.
m_rnti = (*itTb).first.m_rnti;
1016 params.
m_layer = (*itTb).first.m_layer;
1017 params.
m_mcs = (*itTb).second.mcs;
1018 params.
m_size = (*itTb).second.size;
1019 params.
m_rv = (*itTb).second.rv;
1020 params.
m_ndi = (*itTb).second.ndi;
1023 if ((*itTb).second.downlink)
1031 params.
m_rv = harqInfoList.size();
1038 std::map<uint16_t, DlInfoListElement_s> harqDlInfoMap;
1047 (*j)->PeekPacketTag(tag);
1056 if (!(*itTb).second.corrupt)
1072 if (!(*itTb).second.harqFeedbackSent)
1074 (*itTb).second.harqFeedbackSent =
true;
1075 if (!(*itTb).second.downlink)
1079 harqUlInfo.
m_tpc = 0;
1080 if ((*itTb).second.corrupt)
1087 (*itTb).second.size,
1095 (*itTb).second.harqProcessId);
1104 std::map<uint16_t, DlInfoListElement_s>::iterator itHarq =
1105 harqDlInfoMap.find(tbId.
m_rnti);
1106 if (itHarq == harqDlInfoMap.end())
1112 if ((*itTb).second.corrupt)
1117 << (uint16_t)(*itTb).second.harqProcessId
1118 <<
" layer " << (uint16_t)tbId.
m_layer
1119 <<
" send DL-HARQ-NACK");
1121 (*itTb).second.harqProcessId,
1124 (*itTb).second.size,
1131 << (uint16_t)(*itTb).second.harqProcessId
1132 <<
" layer " << (uint16_t)tbId.
m_layer <<
" size "
1133 << (*itTb).second.size <<
" send DL-HARQ-ACK");
1135 (*itTb).second.harqProcessId);
1137 harqDlInfoMap.insert(
1138 std::pair<uint16_t, DlInfoListElement_s>(tbId.
m_rnti, harqDlInfo));
1142 if ((*itTb).second.corrupt)
1144 (*itHarq).second.m_harqStatus.at(tbId.
m_layer) =
1147 << (uint16_t)(*itTb).second.harqProcessId
1148 <<
" layer " << (uint16_t)tbId.
m_layer <<
" size "
1149 << (*itHarq).second.m_harqStatus.size()
1150 <<
" send DL-HARQ-NACK");
1152 (*itTb).second.harqProcessId,
1155 (*itTb).second.size,
1161 " layer " << (uint16_t)tbId.
m_layer);
1162 (*itHarq).second.m_harqStatus.at(tbId.
m_layer) =
1165 << (uint16_t)(*itTb).second.harqProcessId
1166 <<
" layer " << (uint16_t)tbId.
m_layer <<
" size "
1167 << (*itHarq).second.m_harqStatus.size()
1168 <<
" send DL-HARQ-ACK");
1170 (*itTb).second.harqProcessId);
1180 std::map<uint16_t, DlInfoListElement_s>::iterator itHarq;
1181 for (itHarq = harqDlInfoMap.begin(); itHarq != harqDlInfoMap.end(); itHarq++)
1228 NS_LOG_DEBUG(
this <<
" PCFICH-PDCCH Decodification, errorRate " << errorRate <<
" error "
1314 "TransmissionMode not available: 1.." <<
m_txModeGain.size());
1322 NS_LOG_FUNCTION(
this <<
" txmode " << (uint16_t)txMode <<
" gain " << gain);
1326 double gainLin = std::pow(10.0, (gain / 10.0));
AttributeValue implementation for Boolean.
bool IsNull() const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
static TbStats_t GetTbDecodificationStats(const SpectrumValue &sinr, const std::vector< int > &map, uint16_t size, uint8_t mcs, HarqProcessInfoList_t miHistory)
run the error-model algorithm for the specified TB
static double GetPcfichPdcchError(const SpectrumValue &sinr)
run the error-model algorithm for the specified PCFICH+PDCCH channels
Tag used to define the RNTI and LC id for each MAC packet trasmitted.
uint16_t GetRnti() const
Get RNTI function.
uint8_t GetLayer() const
Get layer function.
The LteSpectrumPhy models the physical layer of LTE.
void RemoveExpectedTb(uint16_t rnti)
Remove expected transport block.
Ptr< const SpectrumModel > m_rxSpectrumModel
the spectrum model
TracedCallback< Ptr< const PacketBurst > > m_phyTxEndTrace
the phy transmit end trace callback
bool m_dataErrorModelEnabled
when true (default) the phy error model is enabled
void SetState(State newState)
Set the state of the phy layer.
Ptr< LteInterference > m_interferenceData
the data interference
uint8_t m_transmissionMode
for UEs: store the transmission mode
EventId m_endRxDlCtrlEvent
end receive DL control event
void AddCtrlSinrChunkProcessor(Ptr< LteChunkProcessor > p)
void AddDataSinrChunkProcessor(Ptr< LteChunkProcessor > p)
LtePhyUlHarqFeedbackCallback m_ltePhyUlHarqFeedbackCallback
the LTE phy UL HARQ feedback callback
void AddExpectedTb(uint16_t rnti, uint8_t ndi, uint16_t size, uint8_t mcs, std::vector< int > map, uint8_t layer, uint8_t harqId, uint8_t rv, bool downlink)
Ptr< MobilityModel > GetMobility() const override
Get the associated MobilityModel instance.
Ptr< const SpectrumModel > GetRxSpectrumModel() const override
void SetHarqPhyModule(Ptr< LteHarqPhy > harq)
Set HARQ phy function.
LtePhyRxPssCallback m_ltePhyRxPssCallback
the LTE phy receive PSS callback
void StartRxDlCtrl(Ptr< LteSpectrumSignalParametersDlCtrlFrame > lteDlCtrlRxParams)
Start receive DL control function.
void StartRxUlSrs(Ptr< LteSpectrumSignalParametersUlSrsFrame > lteUlSrsRxParams)
Start receive UL SRS function.
void AddDataPowerChunkProcessor(Ptr< LteChunkProcessor > p)
EventId m_endRxDataEvent
end receive data event
void SetLtePhyRxPssCallback(LtePhyRxPssCallback c)
set the callback for the reception of the PSS as part of the interconnections between the LteSpectrum...
void SetAntenna(Ptr< AntennaModel > a)
set the AntennaModel to be used
bool StartTxDataFrame(Ptr< PacketBurst > pb, std::list< Ptr< LteControlMessage > > ctrlMsgList, Time duration)
Start a transmission of data frame in DL and UL.
void StartRxData(Ptr< LteSpectrumSignalParametersDataFrame > params)
Start receive data function.
TracedCallback< PhyReceptionStatParameters > m_dlPhyReception
Trace information regarding PHY stats from DL Rx perspective PhyReceptionStatParameters (see lte-comm...
Ptr< NetDevice > m_device
the device
Ptr< SpectrumChannel > GetChannel()
TracedCallback< Ptr< const PacketBurst > > m_phyTxStartTrace
the phy transmit start trace callback
void DoDispose() override
Destructor implementation.
void EndTxData()
End transmit data function.
void SetTransmissionMode(uint8_t txMode)
void SetLtePhyRxDataEndErrorCallback(LtePhyRxDataEndErrorCallback c)
set the callback for the end of a RX in error, as part of the interconnections between the PHY and th...
SpectrumValue m_sinrPerceived
the preceived SINR
Ptr< SpectrumValue > m_txPsd
the transmit PSD
void AddInterferenceDataChunkProcessor(Ptr< LteChunkProcessor > p)
LteChunkProcessor devoted to evaluate interference + noise power in data symbols of the subframe.
void SetDevice(Ptr< NetDevice > d) override
Set the associated NetDevice instance.
void ChangeState(State newState)
Change state function.
void SetTxModeGain(uint8_t txMode, double gain)
Set transmit mode gain function.
std::vector< double > m_txModeGain
duplicate value of LteUePhy
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< NetDevice > GetDevice() const override
Get the associated NetDevice instance.
Time m_firstRxStart
the first receive start
Ptr< LteHarqPhy > m_harqPhyModule
the HARQ phy module
void SetLtePhyRxDataEndOkCallback(LtePhyRxDataEndOkCallback c)
set the callback for the successful end of a RX, as part of the interconnections between the PHY and ...
void EndRxUlSrs()
End receive UL SRS function.
void SetLtePhyUlHarqFeedbackCallback(LtePhyUlHarqFeedbackCallback c)
set the callback for the UL HARQ feedback as part of the interconnections between the LteSpectrumPhy ...
void SetChannel(Ptr< SpectrumChannel > c) override
Set the channel attached to this device.
void SetComponentCarrierId(uint8_t componentCarrierId)
TracedCallback< Ptr< const PacketBurst > > m_phyRxStartTrace
the phy receive start trace callback
expectedTbs_t m_expectedTbs
the expected TBS
void EndTxUlSrs()
End transmit UL SRS function.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
set the noise power spectral density
void UpdateSinrPerceived(const SpectrumValue &sinr)
Ptr< SpectrumChannel > m_channel
the channel
void EndRxDlCtrl()
End receive DL control function.
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
set the Power Spectral Density of outgoing signals in W/Hz.
EventId m_endTxEvent
end transmit event
LtePhyRxDataEndOkCallback m_ltePhyRxDataEndOkCallback
the LTE phy receive data end ok callback
void SetLtePhyRxCtrlEndErrorCallback(LtePhyRxCtrlEndErrorCallback c)
set the callback for the erroneous end of a RX ctrl frame, as part of the interconnections between th...
uint16_t m_cellId
the cell ID
Ptr< AntennaModel > m_antenna
the antenna model
void SetLtePhyDlHarqFeedbackCallback(LtePhyDlHarqFeedbackCallback c)
set the callback for the DL HARQ feedback as part of the interconnections between the LteSpectrumPhy ...
Time m_firstRxDuration
the first receive duration
Ptr< PacketBurst > m_txPacketBurst
the transmit packet burst
uint8_t m_componentCarrierId
the component carrier ID
void StartRx(Ptr< SpectrumSignalParameters > params) override
Notify the SpectrumPhy instance of an incoming signal.
Ptr< Object > GetAntenna() const override
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
LtePhyRxDataEndErrorCallback m_ltePhyRxDataEndErrorCallback
the LTE phy receive data end error callback
bool StartTxDlCtrlFrame(std::list< Ptr< LteControlMessage > > ctrlMsgList, bool pss)
Start a transmission of control frame in DL.
static TypeId GetTypeId()
Get the type ID.
uint8_t m_layersNum
layers num
Ptr< MobilityModel > m_mobility
the modility model
~LteSpectrumPhy() override
TracedCallback< PhyReceptionStatParameters > m_ulPhyReception
Trace information regarding PHY stats from UL Rx perspective PhyReceptionStatParameters (see lte-comm...
void SetMobility(Ptr< MobilityModel > m) override
Set the mobility model associated with this device.
LtePhyDlHarqFeedbackCallback m_ltePhyDlHarqFeedbackCallback
the LTE phy DL HARQ feedback callback
void EndTxDlCtrl()
End transmit DL control function.
std::list< Ptr< LteControlMessage > > m_rxControlMessageList
the receive control message list
void AddRsPowerChunkProcessor(Ptr< LteChunkProcessor > p)
Ptr< LteInterference > m_interferenceCtrl
the control interference
TracedCallback< Ptr< const Packet > > m_phyRxEndErrorTrace
the phy receive end error trace callback
void EndRxData()
End receive data function.
std::list< Ptr< LteControlMessage > > m_txControlMessageList
the transmit control message list
bool m_ctrlErrorModelEnabled
when true (default) the phy error model is enabled for DL ctrl frame
std::list< Ptr< PacketBurst > > m_rxPacketBurstList
the receive burst list
void AddInterferenceCtrlChunkProcessor(Ptr< LteChunkProcessor > p)
LteChunkProcessor devoted to evaluate interference + noise power in control symbols of the subframe.
TracedCallback< Ptr< const Packet > > m_phyRxEndOkTrace
the phy receive end ok trace callback
bool StartTxUlSrsFrame()
Start a transmission of control frame in UL.
LtePhyRxCtrlEndErrorCallback m_ltePhyRxCtrlEndErrorCallback
the LTE phy receive control end error callback
void SetLtePhyRxCtrlEndOkCallback(LtePhyRxCtrlEndOkCallback c)
set the callback for the successful end of a RX ctrl frame, as part of the interconnections between t...
void Reset()
reset the internal state
EventId m_endRxUlSrsEvent
end receive UL SRS event
void SetCellId(uint16_t cellId)
LtePhyRxCtrlEndOkCallback m_ltePhyRxCtrlEndOkCallback
the LTE phy receive control end ok callback
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Abstract base class for Spectrum-aware PHY layers.
Set of values corresponding to a given SpectrumModel.
Simulation virtual time values and global simulation resolution.
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
std::ostream & operator<<(std::ostream &os, const Angles &a)
bool operator<(const EventId &a, const EventId &b)
std::vector< HarqProcessInfoElement_t > HarqProcessInfoList_t
HarqProcessInfoList_t typedef.
static const Time DL_CTRL_DURATION
duration of the control portion of a subframe = 0.001 / 14 * 3 (ctrl fixed to 3 symbols) -1ns as marg...
static const Time UL_SRS_DURATION
duration of SRS portion of UL subframe = 1 symbol for SRS -1ns as margin to avoid overlapping simulat...
static const double EffectiveCodingRate[29]
Effective coding rate.
@ IDLE
Channel is IDLE, no packet is being transmitted.
See section 4.3.23 dlInfoListElement.
uint8_t m_harqProcessId
HARQ process ID.
std::vector< enum HarqStatus_e > m_harqStatus
HARQ status.
PhyReceptionStatParameters structure.
uint8_t m_txMode
the transmission Mode
uint8_t m_rv
the redundancy version (HARQ)
uint8_t m_layer
the layer (cw) of the transmission
uint64_t m_imsi
IMSI of the scheduled UE.
uint8_t m_correctness
correctness of the TB received
uint16_t m_rnti
C-RNTI scheduled.
uint16_t m_cellId
Cell ID of the attached Enb.
uint8_t m_ndi
new data indicator flag
uint8_t m_mcs
MCS for transport block.
int64_t m_timestamp
in millisecond
uint16_t m_size
Size of transport block.
uint8_t m_ccId
component carrier id
Time duration
The duration of the packet transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.
double mi
Mutual information.
double tbler
Transport block BLER.
See section 4.3.12 ulInfoListElement.
uint8_t m_tpc
Tx power control command.