23 #include <ns3/object-factory.h>
27 #include <ns3/simulator.h>
28 #include <ns3/double.h>
39 #include <ns3/lte-common.h>
40 #include <ns3/pointer.h>
133 m_p10CqiPeriocity (MilliSeconds (1)),
134 m_a30CqiPeriocity (MilliSeconds (1)),
137 m_state (CELL_SEARCH),
139 m_rsReceivedPowerUpdated (false),
140 m_rsInterferencePowerUpdated (false),
141 m_pssReceived (false),
142 m_ueMeasurementsFilterPeriod (MilliSeconds (200)),
143 m_ueMeasurementsFilterLast (MilliSeconds (0)),
144 m_rsrpSinrSampleCounter (0)
146 m_amc = CreateObject <LteAmc> ();
152 "Cannot create UE devices after simulation started");
181 .AddConstructor<LteUePhy> ()
182 .AddAttribute (
"TxPower",
183 "Transmission power in dBm",
187 MakeDoubleChecker<double> ())
188 .AddAttribute (
"NoiseFigure",
189 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
190 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
191 "\"the difference in decibels (dB) between"
192 " the noise output of the actual receiver to the noise output of an "
193 " ideal receiver with the same overall gain and bandwidth when the receivers "
194 " are connected to sources at the standard noise temperature T0.\" "
195 "In this model, we consider T0 = 290K.",
199 MakeDoubleChecker<double> ())
200 .AddAttribute (
"TxMode1Gain",
201 "Transmission mode 1 gain in dB",
204 MakeDoubleChecker<double> ())
205 .AddAttribute (
"TxMode2Gain",
206 "Transmission mode 2 gain in dB",
209 MakeDoubleChecker<double> ())
210 .AddAttribute (
"TxMode3Gain",
211 "Transmission mode 3 gain in dB",
214 MakeDoubleChecker<double> ())
215 .AddAttribute (
"TxMode4Gain",
216 "Transmission mode 4 gain in dB",
219 MakeDoubleChecker<double> ())
220 .AddAttribute (
"TxMode5Gain",
221 "Transmission mode 5 gain in dB",
224 MakeDoubleChecker<double> ())
225 .AddAttribute (
"TxMode6Gain",
226 "Transmission mode 6 gain in dB",
229 MakeDoubleChecker<double> ())
230 .AddAttribute (
"TxMode7Gain",
231 "Transmission mode 7 gain in dB",
234 MakeDoubleChecker<double> ())
235 .AddTraceSource (
"ReportCurrentCellRsrpSinr",
236 "RSRP and SINR statistics.",
238 .AddAttribute (
"RsrpSinrSamplePeriod",
239 "The sampling period for reporting RSRP-SINR stats (default value 1)",
242 MakeUintegerChecker<uint16_t> ())
243 .AddTraceSource (
"UlPhyTransmission",
244 "DL transmission PHY layer statistics.",
246 .AddAttribute (
"DlSpectrumPhy",
247 "The downlink LteSpectrumPhy associated to this LtePhy",
251 MakePointerChecker <LteSpectrumPhy> ())
252 .AddAttribute (
"UlSpectrumPhy",
253 "The uplink LteSpectrumPhy associated to this LtePhy",
257 MakePointerChecker <LteSpectrumPhy> ())
258 .AddAttribute (
"RsrqUeMeasThreshold",
259 "Receive threshold for PSS on RSRQ [dB]",
262 MakeDoubleChecker<double> ())
263 .AddAttribute (
"UeMeasurementsFilterPeriod",
264 "Time period for reporting UE measurements (default 200 ms.) ",
268 .AddTraceSource (
"ReportUeMeasurements",
269 "Report UE measurements RSRP (dBm) and RSRQ (dB).",
271 .AddTraceSource (
"StateTransition",
272 "Trace fired upon every UE PHY state transition",
464 Values::const_iterator it;
470 double powerTxW = ((*it) * 180000.0) / 12.0;
474 double rsrp = (rbNum > 0) ? (sum / rbNum) : DBL_MAX;
483 double avSinr = (rbNum > 0) ? (sum / rbNum) : DBL_MAX;
495 std::list <PssElement>::iterator itPss =
m_pssList.begin ();
499 double rsrqSum = 0.0;
509 double noisePowerTxW = ((*itIntN) * 180000.0) / 12.0;
510 double intPowerTxW = ((*itPj) * 180000.0) / 12.0;
511 rsrqSum += (2 * (noisePowerTxW + intPowerTxW));
515 double rsrq_dB = 10 * log10 ((*itPss).pssPsdSum / rsrqSum);
520 <<
" has RSRQ " << rsrq_dB <<
" and RBnum " << rbNum);
522 std::map <uint16_t, UeMeasurementsElement>::iterator itMeasMap;
525 (*itMeasMap).second.rsrqSum += rsrq_dB;
526 (*itMeasMap).second.rsrqNum++;
577 std::vector<int> cqi;
583 int nbSubChannels = cqi.size ();
585 int activeSubChannels = 0;
587 for (
int i = 0; i < nbSubChannels; i++)
589 if (cqi.at (i) != -1)
591 cqiSum += cqi.at (i);
594 NS_LOG_DEBUG (
this <<
" subch " << i <<
" cqi " << cqi.at (i));
601 for (
int i = 0; i < nLayer; i++)
603 if (activeSubChannels > 0)
605 dlcqi.m_wbCqi.push_back ((uint16_t) cqiSum / activeSubChannels);
610 dlcqi.m_wbCqi.push_back (1);
621 int nbSubChannels = cqi.size ();
627 for (
int i = 0; i < nbSubChannels; i++)
629 if (cqi.at (i) != -1)
631 cqiSum += cqi.at (i);
635 if (cqiNum == rbgSize)
641 for (
int i = 0; i < nLayer; i++)
643 hlCqi.
m_sbCqi.push_back ((uint16_t) cqiSum / rbgSize);
655 dlcqi.m_sbMeasResult = rbgMeas;
658 msg->SetDlCqi (dlcqi);
671 std::map <uint16_t, UeMeasurementsElement>::iterator it;
674 double avg_rsrp = (*it).second.rsrpSum / (double)(*it).second.rsrpNum;
675 double avg_rsrq = (*it).second.rsrqSum / (
double)(*it).second.rsrqNum;
682 <<
" RSRP " << avg_rsrp
683 <<
" (nSamples " << (uint16_t)(*it).second.rsrpNum <<
")"
684 <<
" RSRQ " << avg_rsrq
685 <<
" (nSamples " << (uint16_t)(*it).second.rsrqNum <<
")");
719 msg->SetRapId (raPreambleId);
731 std::list<Ptr<LteControlMessage> >::iterator it;
732 for (it = msgList.begin (); it != msgList.end(); it++)
747 if (dci.m_resAlloc != 0)
752 std::vector <int> dlRb;
756 for (
int i = 0; i < 32; i++)
758 if (((dci.m_rbBitmap & mask) >> i) == 1)
762 dlRb.push_back ((i * GetRbgSize ()) + k);
770 NS_LOG_DEBUG (
this <<
" UE " <<
m_rnti <<
" DL-DCI " << dci.m_rnti <<
" bitmap " << dci.m_rbBitmap);
771 for (uint8_t i = 0; i < dci.m_tbsSize.size (); i++)
773 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 );
791 std::vector <int> ulRb;
792 for (
int i = 0; i < dci.m_rbLen; i++)
794 ulRb.push_back (i + dci.m_rbStart);
807 params.
m_mcs = dci.m_mcs;
808 params.
m_size = dci.m_tbSize;
809 params.
m_rv = harqInfoList.size ();
810 params.
m_ndi = dci.m_ndi;
818 if (rarMsg->GetRaRnti () ==
m_raRnti)
820 for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin (); it != rarMsg->RarListEnd (); ++it)
831 std::vector <int> ulRb;
832 for (
int i = 0; i < it->rarPayload.m_grant.m_rbLen; i++)
834 ulRb.push_back (i + it->rarPayload.m_grant.m_rbStart);
880 Values::const_iterator itPi;
881 for (itPi = p->ConstValuesBegin (); itPi != p->ConstValuesEnd (); itPi++)
884 double powerTxW = ((*itPi) * 180000.0) / 12.0;
890 double rsrp_dBm = 10 * log10 (1000 * (sum / (
double)nRB));
892 <<
" has RSRP " << rsrp_dBm <<
" and RBnum " << nRB);
896 std::map <uint16_t, UeMeasurementsElement>::iterator itMeasMap =
m_ueMeasurementsMap.find (cellId);
909 (*itMeasMap).second.rsrpSum += rsrp_dBm;
910 (*itMeasMap).second.rsrpNum++;
939 NS_ASSERT_MSG (frameNo > 0,
"the SRS index check code assumes that frameNo starts at 1");
961 NS_ASSERT_MSG (subframeNo > 0 && subframeNo <= 10,
"the SRS index check code assumes that subframeNo starts at 1");
983 if (ctrlMsg.size ()>0)
985 NS_LOG_LOGIC (
this <<
" UE - start TX PUCCH (NO PUSCH)");
986 std::vector <int> dlRb;
1002 if (subframeNo > 10)
1019 std::vector <int> dlRb;
1053 std::list<Ptr<LteControlMessage> > l;
1056 std::vector <int> ulRb;
1119 for (
int i = 0; i < 4; i++)
1121 if (dlBandwidth < Type0AllocationRbg[i])
1223 double gainLin = std::pow (10.0, (gain / 10.0));
1228 std::vector <double> temp;
1231 for (uint8_t i = 0; i < temp.size (); i++)
1254 msg->SetDlHarqFeedback (m);
1280 <<
" UePhy " <<
ToString (oldState)
1281 <<
" --> " <<
ToString (newState));
Values::const_iterator ConstValuesEnd() const
See section 4.3.1 dlDciListElement.
double GetNoiseFigure() const
Ptr< LteSpectrumPhy > GetUlSpectrumPhy() const
keep track of time values and allow control of global simulation resolution
uint8_t m_txMode
the transmission Mode
#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.
std::vector< struct UeMeasurementsElement > m_ueMeasurementsList
LteUePhySapUser * m_uePhySapUser
void SetTxMode5Gain(double gain)
virtual void SendMacPdu(Ptr< Packet > p)
Send the MAC PDU to the channel.
virtual void GenerateDataCqiReport(const SpectrumValue &sinr)
generate a CQI report based on the given SINR of Data frame (used for PUSCH CQIs) ...
std::list< PssElement > m_pssList
void SetTxMode2Gain(double gain)
uint8_t GetMacChDelay(void) const
void DoConfigureUplink(uint16_t ulEarfcn, uint8_t ulBandwidth)
std::vector< Ptr< PacketBurst > > m_packetBurstQueue
std::vector< int > GetSubChannelsForTransmission(void)
Get a list of sub channels to use in RX.
virtual void GenerateCtrlCqiReport(const SpectrumValue &sinr)
generate a CQI report based on the given SINR of Ctrl frame
TracedCallback< uint16_t, uint16_t, double, double > m_reportCurrentCellRsrpSinrTrace
Trace information regarding RSRP and average SINR (see TS 36.214) uint16_t cellId, uint16_t rnti, double rsrp, double sinr.
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
LteUePhySapProvider * m_uePhySapProvider
#define NS_ASSERT(condition)
void SetTxMode6Gain(double gain)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Ptr< LteSpectrumPhy > m_downlinkSpectrumPhy
See section 4.3.2 ulDciListElement.
Service Access Point (SAP) offered by the UE PHY to the UE RRC for control purposes.
virtual void SendLteControlMessage(Ptr< LteControlMessage > msg)
Send SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
See section 4.3.24 cqiListElement.
std::vector< double > m_txModeGain
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
void QueueSubChannelsForTransmission(std::vector< int > rbMap)
uint8_t m_rv
the redundancy version (HARQ)
Service Access Point (SAP) offered by the PHY to the MAC.
void SetTxModeGain(uint8_t txMode, double gain)
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.
uint8_t m_transmissionMode
NS_LOG_COMPONENT_DEFINE("LteUePhy")
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
void DoSetSrsConfigurationIndex(uint16_t srcCi)
State
The states of the UE PHY entity.
void DoSetTransmissionMode(uint8_t txMode)
The attribute can be read.
UeMemberLteUePhySapProvider(LteUePhy *phy)
Template for the implementation of the LteUeCphySapProvider as a member of an owner class of type C t...
double m_pssReceptionThreshold
TracedCallback< uint16_t, uint16_t, double, double, bool > m_reportUeMeasurements
Trace information regarding RSRP and RSRQ (see TS 36.214) uint16_t rnti, uint16_t cellId...
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
void DoSynchronizeWithEnb(uint16_t cellId)
LteUeCphySapUser * m_ueCphySapUser
void DoSetDlBandwidth(uint8_t ulBandwidth)
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
hold objects of type ns3::Time
uint8_t GetRbgSize(void) const
uint16_t m_rsrpSinrSamplePeriod
uint64_t m_imsi
IMSI of the scheduled UE.
See section 4.3.27 higherLayerSelected.
Service Access Point (SAP) offered by the UE PHY to the UE RRC for control purposes.
void SetLteUePhySapUser(LteUePhySapUser *s)
Set the PHY SAP User.
Hold an unsigned integer type.
void SetTxMode3Gain(double gain)
static uint8_t TxMode2LayerNum(uint8_t txMode)
Ptr< DlCqiLteControlMessage > CreateDlCqiFeedbackMessage(const SpectrumValue &sinr)
Create the DL CQI feedback from SINR values perceived at the physical layer with the signal received ...
void SetTxMode4Gain(double gain)
void SwitchToState(State s)
TracedCallback< uint16_t, uint16_t, State, State > m_stateTransitionTrace
void SendSrs()
Send the SRS signal in the last symbols of the frame.
bool m_rsInterferencePowerUpdated
virtual void RecvSystemInformationBlockType1(uint16_t cellId, LteRrcSap::SystemInformationBlockType1 sib1)=0
Relay an SIB1 message from the PHY entity to the RRC layer.
#define NS_LOG_LOGIC(msg)
std::vector< uint8_t > m_sbCqi
void SetTxMode7Gain(double gain)
virtual void RecvMasterInformationBlock(uint16_t cellId, LteRrcSap::MasterInformationBlock mib)=0
Relay an MIB message from the PHY entity to the RRC layer.
See section 4.3.23 dlInfoListElement.
virtual void DoSendRachPreamble(uint32_t prachId, uint32_t raRnti)
uint8_t m_mcs
MCS for transport block.
virtual void ReceiveLteDlHarqFeedback(DlInfoListElement_s mes)
PhySpectrum generated a new DL HARQ feedback.
static const Time UL_DATA_DURATION
Ptr< LteHarqPhy > m_harqPhyModule
void DoStartCellSearch(uint16_t dlEarfcn)
void SetControlMessages(Ptr< LteControlMessage > m)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
uint16_t m_rsrpSinrSampleCounter
SpectrumValue m_rsReceivedPower
double GetTxPower() const
uint16_t m_srsSubframeOffset
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
uint16_t m_size
Size of transport block.
static Time Now(void)
Return the "current simulation time".
uint8_t m_ndi
new data indicator flag
void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)
trigger from eNB the start from a new frame
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
#define NS_ASSERT_MSG(condition, message)
static Ptr< SpectrumValue > CreateTxPowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double powerTx, std::vector< int > activeRbs)
create a spectrum value representing the power spectral density of a signal to be transmitted...
void SetTxMode1Gain(double gain)
std::vector< int > m_subChannelsForTransmission
Time m_p10CqiPeriocity
Wideband Periodic CQI: 2, 5, 10, 16, 20, 32, 40, 64, 80 or 160 ms.
std::string ToString(EpcUeNas::State s)
std::vector< std::vector< int > > m_subChannelsForTransmissionQueue
std::list< Ptr< LteControlMessage > > GetControlMessages(void)
LteUeCphySapProvider * m_ueCphySapProvider
std::map< uint16_t, UeMeasurementsElement > m_ueMeasurementsMap
Ptr< PacketBurst > GetPacketBurst(void)
uint16_t m_cellId
Cell ID of the attached Enb.
std::vector< int > m_subChannelsForReception
Service Access Point (SAP) offered by the UE-PHY to the UE-MAC.
static const Time UL_SRS_DELAY_FROM_SUBFRAME_START
int Type0AllocationRbg[4]
#define NS_LOG_DEBUG(msg)
uint8_t m_layer
the layer (cw) of the transmission
virtual void ReceiveLteControlMessageList(std::list< Ptr< LteControlMessage > >)
void SetTxPower(double pow)
virtual void ReceivePss(uint16_t cellId, Ptr< SpectrumValue > p)
uint16_t m_srsPeriodicity
LteUePhySapProvider * GetLteUePhySapProvider()
Get the PHY SAP provider.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
virtual void SendRachPreamble(uint32_t prachId, uint32_t raRnti)
send a preamble on the PRACH
void SetLteUeCphySapUser(LteUeCphySapUser *s)
Set the CPHY SAP User.
SpectrumValue m_rsInterferencePower
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
friend class UeMemberLteUePhySapProvider
void PhyPduReceived(Ptr< Packet > p)
PhySpectrum received a new PHY-PDU.
Values::const_iterator ConstValuesBegin() const
virtual void DoSendLteControlMessage(Ptr< LteControlMessage > msg)
std::vector< std::list< Ptr< LteControlMessage > > > m_controlMessagesQueue
bool m_rsReceivedPowerUpdated
The LteSpectrumPhy models the physical layer of LTE.
Ptr< LteSpectrumPhy > GetDlSpectrumPhy() const
Ptr< LteSpectrumPhy > m_uplinkSpectrumPhy
virtual void ReportRsReceivedPower(const SpectrumValue &power)
generate a report based on the linear RS power perceived during CTRL frame NOTE: used only by UE for ...
Time m_p10CqiLast
SubBand Aperiodic CQI: activated by DCI format 0 or Random Access Response Grant. ...
Parameters of the ReportUeMeasurements primitive: RSRP [dBm] and RSRQ [dB] See section 5...
LteUeCphySapProvider * GetLteUeCphySapProvider()
Get the CPHY SAP provider.
Hold a floating point type.
Set of values corresponding to a given SpectrumModel.
void SetMacPdu(Ptr< Packet > p)
std::vector< struct HigherLayerSelected_s > m_higherLayerSelected
a unique identifier for an interface.
const char * g_uePhyStateName[LteUePhy::NUM_STATES]
int64_t GetMilliSeconds(void) const
TypeId SetParent(TypeId tid)
void SetNoiseFigure(double nf)
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
TracedCallback< PhyTransmissionStatParameters > m_ulPhyTransmission
Trace information regarding PHY stats from DL Tx perspective PhyTrasmissionStatParameters see lte-com...
uint16_t m_rnti
C-RNTI scheduled.
static TypeId GetTypeId(void)
The LtePhy models the physical layer of LTE.
void ReportUeMeasurements()
Layer-1 filtering of RSRP and RSRQ measurements and reporting to the RRC entity.
virtual void ReportInterference(const SpectrumValue &interf)
generate a report based on the linear interference and noise power perceived during DATA frame NOTE: ...
virtual void ReceivePhyPdu(Ptr< Packet > p)=0
Called by the Phy to notify the MAC of the reception of a new PHY-PDU.
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double noiseFigure)
create a SpectrumValue that models the power spectral density of AWGN
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity()
Create the PSD for the TX.
#define UL_PUSCH_TTIS_DELAY
void DoSetRnti(uint16_t rnti)
virtual void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)=0
Trigger the start from a new frame (input from Phy layer)
virtual void ReportUeMeasurements(UeMeasurementsParameters params)=0
Send a report of RSRP and RSRQ values perceived from PSS by the PHY entity (after applying layer-1 fi...
std::vector< HarqProcessInfoElement_t > HarqProcessInfoList_t
void SetSubChannelsForReception(std::vector< int > mask)
Get a list of sub channels to use in RX.
The LteUeNetDevice class implements the UE net device.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Time m_ueMeasurementsFilterPeriod