23 #include <ns3/object-factory.h>
26 #include <ns3/simulator.h>
27 #include <ns3/double.h>
28 #include "lte-ue-phy.h"
29 #include "lte-enb-phy.h"
30 #include "lte-net-device.h"
31 #include "lte-ue-net-device.h"
32 #include "lte-enb-net-device.h"
33 #include "lte-spectrum-value-helper.h"
35 #include "lte-ue-mac.h"
36 #include "ff-mac-common.h"
37 #include "lte-sinr-chunk-processor.h"
38 #include <ns3/lte-common.h>
39 #include <ns3/pointer.h>
52 static const Time UL_DATA_DURATION =
NanoSeconds (1e6 - 71429 - 1);
56 static const Time UL_SRS_DELAY_FROM_SUBFRAME_START =
NanoSeconds (1e6 - 71429);
80 UeMemberLteUePhySapProvider::UeMemberLteUePhySapProvider (
LteUePhy* phy) : m_phy (phy)
94 m_phy->DoSendLteControlMessage (msg);
100 m_phy->DoSendRachPreamble (prachId, raRnti);
109 NS_OBJECT_ENSURE_REGISTERED (
LteUePhy);
124 m_rsReceivedPowerUpdated (false),
125 m_rsrpSinrSampleCounter (0)
127 m_amc = CreateObject <LteAmc> ();
130 m_macChTtiDelay = UL_PUSCH_TTIS_DELAY;
133 "Cannot create UE devices after simulation started");
140 LteUePhy::~LteUePhy ()
142 m_txModeGain.clear ();
149 delete m_uePhySapProvider;
150 delete m_ueCphySapProvider;
157 LteUePhy::GetTypeId (
void)
161 .AddConstructor<LteUePhy> ()
162 .AddAttribute (
"TxPower",
163 "Transmission power in dBm",
167 MakeDoubleChecker<double> ())
168 .AddAttribute (
"NoiseFigure",
169 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
170 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
171 "\"the difference in decibels (dB) between"
172 " the noise output of the actual receiver to the noise output of an "
173 " ideal receiver with the same overall gain and bandwidth when the receivers "
174 " are connected to sources at the standard noise temperature T0.\" "
175 "In this model, we consider T0 = 290K.",
179 MakeDoubleChecker<double> ())
180 .AddAttribute (
"TxMode1Gain",
181 "Transmission mode 1 gain in dB",
183 MakeDoubleAccessor (&LteUePhy::SetTxMode1Gain ),
184 MakeDoubleChecker<double> ())
185 .AddAttribute (
"TxMode2Gain",
186 "Transmission mode 2 gain in dB",
188 MakeDoubleAccessor (&LteUePhy::SetTxMode2Gain ),
189 MakeDoubleChecker<double> ())
190 .AddAttribute (
"TxMode3Gain",
191 "Transmission mode 3 gain in dB",
193 MakeDoubleAccessor (&LteUePhy::SetTxMode3Gain ),
194 MakeDoubleChecker<double> ())
195 .AddAttribute (
"TxMode4Gain",
196 "Transmission mode 4 gain in dB",
198 MakeDoubleAccessor (&LteUePhy::SetTxMode4Gain ),
199 MakeDoubleChecker<double> ())
200 .AddAttribute (
"TxMode5Gain",
201 "Transmission mode 5 gain in dB",
203 MakeDoubleAccessor (&LteUePhy::SetTxMode5Gain ),
204 MakeDoubleChecker<double> ())
205 .AddAttribute (
"TxMode6Gain",
206 "Transmission mode 6 gain in dB",
208 MakeDoubleAccessor (&LteUePhy::SetTxMode6Gain ),
209 MakeDoubleChecker<double> ())
210 .AddAttribute (
"TxMode7Gain",
211 "Transmission mode 7 gain in dB",
213 MakeDoubleAccessor (&LteUePhy::SetTxMode7Gain ),
214 MakeDoubleChecker<double> ())
215 .AddTraceSource (
"ReportCurrentCellRsrpSinr",
216 "RSRP and SINR statistics.",
218 .AddAttribute (
"RsrpSinrSamplePeriod",
219 "The sampling period for reporting RSRP-SINR stats (default value 1)",
221 MakeUintegerAccessor (&LteUePhy::m_rsrpSinrSamplePeriod),
222 MakeUintegerChecker<uint16_t> ())
223 .AddTraceSource (
"UlPhyTransmission",
224 "DL transmission PHY layer statistics.",
226 .AddAttribute (
"DlSpectrumPhy",
227 "The downlink LteSpectrumPhy associated to this LtePhy",
231 MakePointerChecker <LteSpectrumPhy> ())
232 .AddAttribute (
"UlSpectrumPhy",
233 "The uplink LteSpectrumPhy associated to this LtePhy",
237 MakePointerChecker <LteSpectrumPhy> ())
260 return (m_uePhySapProvider);
275 return (m_ueCphySapProvider);
289 return m_noiseFigure;
310 return (m_macChTtiDelay);
316 return m_downlinkSpectrumPhy;
322 return m_uplinkSpectrumPhy;
345 m_subChannelsForTransmission = mask;
348 m_uplinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd);
356 m_subChannelsForReception = mask;
364 return m_subChannelsForTransmission;
372 return m_subChannelsForReception;
391 if (!(m_dlConfigured && m_ulConfigured))
403 DoSendLteControlMessage (msg);
414 DoSendLteControlMessage (msg);
436 m_rsReceivedPowerUpdated =
true;
437 m_rsReceivedPower = power;
454 NS_ASSERT (m_transmissionMode < m_txModeGain.size ());
456 newSinr *= m_txModeGain.at (m_transmissionMode);
458 m_rsrpSinrSampleCounter++;
459 if (m_rsrpSinrSampleCounter==m_rsrpSinrSamplePeriod)
461 NS_ASSERT_MSG (m_rsReceivedPowerUpdated,
" RS received power info obsolete");
465 Values::const_iterator it;
471 double powerTxW = ((*it) * 180000.0) / 12.0;
475 double rsrp = sum / (double)rbNum;
484 double avSinr = sum / (double)rbNum;
485 NS_LOG_INFO (
this <<
" cellId " << m_cellId <<
" rnti " << m_rnti <<
" RSRP " << rsrp <<
" SINR " << avSinr);
488 m_rsrpSinrSampleCounter = 0;
496 std::vector<int> cqi;
499 cqi = m_amc->CreateCqiFeedbacks (newSinr, m_dlBandwidth);
501 int nLayer = TransmissionModesLayers::TxMode2LayerNum (m_transmissionMode);
502 int nbSubChannels = cqi.size ();
504 int activeSubChannels = 0;
506 for (
int i = 0; i < nbSubChannels; i++)
508 if (cqi.at (i) != -1)
510 cqiSum += cqi.at (i);
513 NS_LOG_DEBUG (
this <<
" subch " << i <<
" cqi " << cqi.at (i));
515 dlcqi.m_rnti = m_rnti;
517 dlcqi.m_cqiType = CqiListElement_s::P10;
520 for (
int i = 0; i < nLayer; i++)
522 if (activeSubChannels > 0)
524 dlcqi.m_wbCqi.push_back ((uint16_t) cqiSum / activeSubChannels);
529 dlcqi.m_wbCqi.push_back (1);
538 cqi = m_amc->CreateCqiFeedbacks (newSinr,
GetRbgSize ());
539 int nLayer = TransmissionModesLayers::TxMode2LayerNum (m_transmissionMode);
540 int nbSubChannels = cqi.size ();
546 for (
int i = 0; i < nbSubChannels; i++)
548 if (cqi.at (i) != -1)
550 cqiSum += cqi.at (i);
554 if (cqiNum == rbgSize)
560 for (
int i = 0; i < nLayer; i++)
562 hlCqi.m_sbCqi.push_back ((uint16_t) cqiSum / rbgSize);
564 rbgMeas.m_higherLayerSelected.push_back (hlCqi);
569 dlcqi.m_rnti = m_rnti;
571 dlcqi.m_cqiType = CqiListElement_s::A30;
574 dlcqi.m_sbMeasResult = rbgMeas;
577 msg->SetDlCqi (dlcqi);
592 LteUePhy::DoSendRachPreamble (uint32_t raPreambleId, uint32_t raRnti)
597 Ptr<RachPreambleLteControlMessage> msg = Create<RachPreambleLteControlMessage> ();
598 msg->SetRapId (raPreambleId);
599 m_raPreambleId = raPreambleId;
601 m_controlMessagesQueue.at (0).push_back (msg);
606 LteUePhy::ReceiveLteControlMessageList (std::list<Ptr<LteControlMessage> > msgList)
610 std::list<Ptr<LteControlMessage> >::iterator it;
611 for (it = msgList.begin (); it != msgList.end(); it++)
613 Ptr<LteControlMessage> msg = (*it);
615 if (msg->GetMessageType () == LteControlMessage::DL_DCI)
617 Ptr<DlDciLteControlMessage> msg2 = DynamicCast<DlDciLteControlMessage> (msg);
619 DlDciListElement_s dci = msg2->GetDci ();
620 if (dci.m_rnti != m_rnti)
626 if (dci.m_resAlloc != 0)
631 std::vector <int> dlRb;
635 for (
int i = 0; i < 32; i++)
637 if (((dci.m_rbBitmap & mask) >> i) == 1)
649 NS_LOG_DEBUG (
this <<
" UE " << m_rnti <<
" DL-DCI " << dci.m_rnti <<
" bitmap " << dci.m_rbBitmap);
650 for (uint8_t i = 0; i < dci.m_tbsSize.size (); i++)
652 m_downlinkSpectrumPhy->AddExpectedTb (dci.m_rnti, dci.m_ndi.at (i), dci.m_tbsSize.at (i), dci.m_mcs.at (i), dlRb, i, dci.m_harqProcess, dci.m_rv.at (i),
true );
659 else if (msg->GetMessageType () == LteControlMessage::UL_DCI)
662 Ptr<UlDciLteControlMessage> msg2 = DynamicCast<UlDciLteControlMessage> (msg);
663 UlDciListElement_s dci = msg2->GetDci ();
664 if (dci.m_rnti != m_rnti)
670 std::vector <int> ulRb;
671 for (
int i = 0; i < dci.m_rbLen; i++)
673 ulRb.push_back (i + dci.m_rbStart);
676 QueueSubChannelsForTransmission (ulRb);
678 HarqProcessInfoList_t harqInfoList = m_harqPhyModule->GetHarqProcessInfoUl (m_rnti, 0);
679 PhyTransmissionStatParameters params;
680 params.m_cellId = m_cellId;
683 params.m_rnti = m_rnti;
686 params.m_mcs = dci.m_mcs;
687 params.m_size = dci.m_tbSize;
688 params.m_rv = harqInfoList.size ();
689 params.m_ndi = dci.m_ndi;
694 else if (msg->GetMessageType () == LteControlMessage::RAR)
696 Ptr<RarLteControlMessage> rarMsg = DynamicCast<RarLteControlMessage> (msg);
697 if (rarMsg->GetRaRnti () == m_raRnti)
699 for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin (); it != rarMsg->RarListEnd (); ++it)
701 if (it->rapId != m_raPreambleId)
710 std::vector <int> ulRb;
711 for (
int i = 0; i < it->rarPayload.m_grant.m_rbLen; i++)
713 ulRb.push_back (i + it->rarPayload.m_grant.m_rbStart);
716 QueueSubChannelsForTransmission (ulRb);
720 m_raPreambleId = 255;
726 else if (msg->GetMessageType () == LteControlMessage::MIB)
729 Ptr<MibLteControlMessage> msg2 = DynamicCast<MibLteControlMessage> (msg);
745 LteUePhy::QueueSubChannelsForTransmission (std::vector <int> rbMap)
747 m_subChannelsForTransmissionQueue.at (m_macChTtiDelay - 1) = rbMap;
756 NS_ASSERT_MSG (frameNo > 0,
"the SRS index check code assumes that frameNo starts at 1");
759 m_rsReceivedPowerUpdated =
false;
767 for (uint8_t i = 1; i < m_macChTtiDelay; i++)
769 m_subChannelsForTransmissionQueue.at (i-1) = m_subChannelsForTransmissionQueue.at (i);
771 m_subChannelsForTransmissionQueue.at (m_macChTtiDelay-1).clear ();
776 NS_ASSERT_MSG (subframeNo > 0 && subframeNo <= 10,
"the SRS index check code assumes that subframeNo starts at 1");
777 if ((((frameNo-1)*10 + (subframeNo-1)) % m_srsPeriodicity) == m_srsSubframeOffset)
779 NS_LOG_INFO (
"frame " << frameNo <<
" subframe " << subframeNo <<
" sending SRS (offset=" << m_srsSubframeOffset <<
", period=" << m_srsPeriodicity <<
")");
788 NS_LOG_LOGIC (
this <<
" UE - start slot for PUSCH + PUCCH - RNTI " << m_rnti <<
" CELLID " << m_cellId);
793 m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, UL_DATA_DURATION);
798 if (ctrlMsg.size ()>0)
800 NS_LOG_LOGIC (
this <<
" UE - start TX PUCCH (NO PUSCH)");
801 std::vector <int> dlRb;
803 m_uplinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsg, UL_DATA_DURATION);
830 NS_LOG_FUNCTION (
this <<
" UE " << m_rnti <<
" start tx SRS, cell Id " << (uint32_t) m_cellId);
833 std::vector <int> dlRb;
834 for (uint8_t i = 0; i < m_ulBandwidth; i++)
839 m_uplinkSpectrumPhy->StartTxUlSrsFrame ();
849 m_transmissionMode = 0;
850 m_srsPeriodicity = 0;
851 m_srsConfigured =
false;
852 m_dlConfigured =
false;
853 m_ulConfigured =
false;
854 m_raPreambleId = 255;
856 m_rsrpSinrSampleCounter = 0;
860 m_packetBurstQueue.clear ();
861 m_controlMessagesQueue.clear ();
862 m_subChannelsForTransmissionQueue.clear ();
863 for (
int i = 0; i < m_macChTtiDelay; i++)
866 m_packetBurstQueue.push_back (pb);
867 std::list<Ptr<LteControlMessage> > l;
868 m_controlMessagesQueue.push_back (l);
870 std::vector <int> ulRb;
871 m_subChannelsForTransmissionQueue.resize (m_macChTtiDelay, ulRb);
874 m_downlinkSpectrumPhy->Reset ();
875 m_uplinkSpectrumPhy->Reset ();
879 LteUePhy::DoSyncronizeWithEnb (uint16_t cellId, uint16_t dlEarfcn)
883 m_dlEarfcn = dlEarfcn;
884 m_downlinkSpectrumPhy->SetCellId (cellId);
885 m_uplinkSpectrumPhy->SetCellId (cellId);
890 m_downlinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd);
891 m_downlinkSpectrumPhy->GetChannel ()->AddRx (m_downlinkSpectrumPhy);
893 m_dlConfigured =
false;
894 m_ulConfigured =
false;
898 LteUePhy::DoSetDlBandwidth (uint8_t dlBandwidth)
901 if (m_dlBandwidth != dlBandwidth)
903 m_dlBandwidth = dlBandwidth;
905 int Type0AllocationRbg[4] = {
911 for (
int i = 0; i < 4; i++)
913 if (dlBandwidth < Type0AllocationRbg[i])
921 m_downlinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd);
922 m_downlinkSpectrumPhy->GetChannel ()->AddRx (m_downlinkSpectrumPhy);
924 m_dlConfigured =
true;
929 LteUePhy::DoConfigureUplink (uint16_t ulEarfcn, uint8_t ulBandwidth)
931 m_ulEarfcn = ulEarfcn;
932 m_ulBandwidth = ulBandwidth;
933 m_ulConfigured =
true;
938 LteUePhy::DoSetRnti (uint16_t rnti)
945 LteUePhy::DoSetTransmissionMode (uint8_t txMode)
948 m_transmissionMode = txMode;
949 m_downlinkSpectrumPhy->SetTransmissionMode (txMode);
953 LteUePhy::DoSetSrsConfigurationIndex (uint16_t srcCi)
958 m_srsConfigured =
true;
963 NS_LOG_DEBUG (
this <<
" UE SRS P " << m_srsPeriodicity <<
" RNTI " << m_rnti <<
" offset " << m_srsSubframeOffset <<
" cellId " << m_cellId <<
" CI " << srcCi);
968 LteUePhy::SetTxMode1Gain (
double gain)
970 SetTxModeGain (1, gain);
974 LteUePhy::SetTxMode2Gain (
double gain)
976 SetTxModeGain (2, gain);
980 LteUePhy::SetTxMode3Gain (
double gain)
982 SetTxModeGain (3, gain);
986 LteUePhy::SetTxMode4Gain (
double gain)
988 SetTxModeGain (4, gain);
992 LteUePhy::SetTxMode5Gain (
double gain)
994 SetTxModeGain (5, gain);
998 LteUePhy::SetTxMode6Gain (
double gain)
1000 SetTxModeGain (6, gain);
1004 LteUePhy::SetTxMode7Gain (
double gain)
1006 SetTxModeGain (7, gain);
1011 LteUePhy::SetTxModeGain (uint8_t txMode,
double gain)
1015 double gainLin = std::pow (10.0, (gain / 10.0));
1016 if (m_txModeGain.size () < txMode)
1018 m_txModeGain.resize (txMode);
1020 std::vector <double> temp;
1021 temp = m_txModeGain;
1022 m_txModeGain.clear ();
1023 for (uint8_t i = 0; i < temp.size (); i++)
1027 m_txModeGain.push_back (gainLin);
1031 m_txModeGain.push_back (temp.at (i));
1035 m_downlinkSpectrumPhy->SetTxModeGain (txMode, gain);
1046 msg->SetDlHarqFeedback (m);
1053 m_harqPhyModule = harq;
Values::const_iterator ConstValuesEnd() const
double GetNoiseFigure() const
Time NanoSeconds(uint64_t ns)
create ns3::Time instances in units of nanoseconds.
Ptr< LteSpectrumPhy > GetUlSpectrumPhy() const
#define NS_LOG_FUNCTION(parameters)
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)=0
Receive SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
See section 4.3.25 sbMeasResult.
void SetNoiseFigure(double pow)
virtual void SendMacPdu(Ptr< Packet > p)
Send the MAC PDU to the channel.
virtual void GenerateDataCqiReport(const SpectrumValue &sinr)
uint8_t GetMacChDelay(void) const
std::vector< int > GetSubChannelsForTransmission(void)
Get a list of sub channels to use in RX.
virtual void GenerateCtrlCqiReport(const SpectrumValue &sinr)
TracedCallback< uint16_t, uint16_t, double, double > m_reportCurrentCellRsrpSinrTrace
void SetSubChannelsForTransmission(std::vector< int > mask)
Set a list of sub channels to use in TX.
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
double GetTti(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void SendLteControlMessage(Ptr< LteControlMessage > msg)
Send SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
See section 4.3.24 cqiListElement.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void DoSendMacPdu(Ptr< Packet > p)
Queue the MAC PDU to be sent (according to m_macChTtiDelay)
std::vector< int > GetSubChannelsForReception(void)
Get a list of sub channels to use in RX.
This class defines all functions to create spectrum model for lte.
void SetHarqPhyModule(Ptr< LteHarqPhy > harq)
Set the HARQ PHY module.
Ptr< LteNetDevice > GetDevice()
Get the device where the phy layer is attached.
#define NS_FATAL_ERROR(msg)
fatal error handling
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
uint8_t GetRbgSize(void) const
See section 4.3.27 higherLayerSelected.
void SetLteUePhySapUser(LteUePhySapUser *s)
Set the PHY SAP User.
Hold an unsigned integer type.
Ptr< DlCqiLteControlMessage > CreateDlCqiFeedbackMessage(const SpectrumValue &sinr)
Create the DL CQI feedback from SINR values perceived at the physical layer with the signal received ...
void SendSrs()
Send the SRS signal in the last symbols of the frame.
#define NS_LOG_LOGIC(msg)
See section 4.3.23 dlInfoListElement.
virtual void ReceiveLteDlHarqFeedback(DlInfoListElement_s mes)
PhySpectrum generated a new DL HARQ feedback.
hold objects of type Ptr<T>
void SetControlMessages(Ptr< LteControlMessage > m)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
double GetTxPower() const
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)
trigger from eNB the start from a new frame
virtual void DoInitialize(void)
#define NS_ASSERT_MSG(condition, message)
static Ptr< SpectrumValue > CreateTxPowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double powerTx, std::vector< int > activeRbs)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
std::list< Ptr< LteControlMessage > > GetControlMessages(void)
Ptr< PacketBurst > GetPacketBurst(void)
#define NS_LOG_DEBUG(msg)
void SetTxPower(double pow)
LteUePhySapProvider * GetLteUePhySapProvider()
Get the PHY SAP provider.
virtual void SendRachPreamble(uint32_t prachId, uint32_t raRnti)
void SetLteUeCphySapUser(LteUeCphySapUser *s)
Set the CPHY SAP User.
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
void PhyPduReceived(Ptr< Packet > p)
PhySpectrum received a new PHY-PDU.
Values::const_iterator ConstValuesBegin() const
Ptr< LteSpectrumPhy > GetDlSpectrumPhy() const
virtual void ReportRsReceivedPower(const SpectrumValue &power)
LteUeCphySapProvider * GetLteUeCphySapProvider()
Get the CPHY SAP provider.
Hold an floating point type.
Set of values corresponding to a given SpectrumModel.
void SetMacPdu(Ptr< Packet > p)
a unique identifier for an interface.
int64_t GetMilliSeconds(void) const
TypeId SetParent(TypeId tid)
virtual void DoInitialize(void)
TracedCallback< PhyTransmissionStatParameters > m_ulPhyTransmission
virtual void ReportInterference(const SpectrumValue &interf)
virtual void RecvMasterInformationBlock(LteRrcSap::MasterInformationBlock mib)=0
virtual void ReceivePhyPdu(Ptr< Packet > p)=0
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double noiseFigure)
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity()
Create the PSD for the TX.
virtual void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)=0
Trigger the start from a new frame (input from Phy layer)
void SetSubChannelsForReception(std::vector< int > mask)
Get a list of sub channels to use in RX.
virtual void DoDispose(void)