22 #include <ns3/object-factory.h>
25 #include <ns3/simulator.h>
26 #include <ns3/attribute-accessor-helper.h>
27 #include <ns3/double.h>
30 #include "lte-enb-phy.h"
31 #include "lte-ue-phy.h"
32 #include "lte-net-device.h"
33 #include "lte-spectrum-value-helper.h"
34 #include "lte-control-messages.h"
35 #include "lte-enb-net-device.h"
36 #include "lte-ue-rrc.h"
37 #include "lte-enb-mac.h"
38 #include <ns3/lte-common.h>
39 #include <ns3/lte-vendor-specific-parameters.h>
42 #include <ns3/node-list.h>
44 #include <ns3/lte-ue-net-device.h>
45 #include <ns3/pointer.h>
51 NS_OBJECT_ENSURE_REGISTERED (LteEnbPhy);
55 static const Time DL_DATA_DURATION =
NanoSeconds (785714 -1);
59 static const Time DL_CTRL_DELAY_FROM_SUBFRAME_START =
NanoSeconds (214286);
73 virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth);
74 virtual void SetCellId (uint16_t cellId);
83 EnbMemberLteEnbPhySapProvider::EnbMemberLteEnbPhySapProvider (
LteEnbPhy* phy) : m_phy (phy)
95 EnbMemberLteEnbPhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
97 m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth);
101 EnbMemberLteEnbPhySapProvider::SetCellId (uint16_t cellId)
109 m_phy->DoSendLteControlMessage (msg);
115 return (m_phy->DoGetMacChTtiDelay ());
134 m_enbCphySapUser (0),
137 m_srsPeriodicity (0),
139 m_currentSrsOffset (0),
140 m_interferenceSampleCounter (0)
144 m_harqPhyModule = Create <LteHarqPhy> ();
145 m_downlinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
146 m_uplinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
151 LteEnbPhy::GetTypeId (
void)
155 .AddConstructor<LteEnbPhy> ()
156 .AddAttribute (
"TxPower",
157 "Transmission power in dBm",
161 MakeDoubleChecker<double> ())
162 .AddAttribute (
"NoiseFigure",
163 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
164 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
165 "\"the difference in decibels (dB) between"
166 " the noise output of the actual receiver to the noise output of an "
167 " ideal receiver with the same overall gain and bandwidth when the receivers "
168 " are connected to sources at the standard noise temperature T0.\" "
169 "In this model, we consider T0 = 290K.",
173 MakeDoubleChecker<double> ())
174 .AddAttribute (
"MacToChannelDelay",
175 "The delay in TTI units that occurs between a scheduling decision in the MAC and the actual start of the transmission by the PHY. This is intended to be used to model the latency of real PHY and MAC implementations.",
179 MakeUintegerChecker<uint8_t> ())
180 .AddTraceSource (
"ReportUeSinr",
181 "Report UEs' averaged linear SINR",
183 .AddAttribute (
"UeSinrSamplePeriod",
184 "The sampling period for reporting UEs' SINR stats (default value 1)",
186 MakeUintegerAccessor (&LteEnbPhy::m_srsSamplePeriod),
187 MakeUintegerChecker<uint16_t> ())
188 .AddTraceSource (
"ReportInterference",
189 "Report linear interference power per PHY RB",
191 .AddAttribute (
"InterferenceSamplePeriod",
192 "The sampling period for reporting interference stats (default value 1)",
194 MakeUintegerAccessor (&LteEnbPhy::m_interferenceSamplePeriod),
195 MakeUintegerChecker<uint16_t> ())
196 .AddTraceSource (
"DlPhyTransmission",
197 "DL transmission PHY layer statistics.",
199 .AddAttribute (
"DlSpectrumPhy",
200 "The downlink LteSpectrumPhy associated to this LtePhy",
204 MakePointerChecker <LteSpectrumPhy> ())
205 .AddAttribute (
"UlSpectrumPhy",
206 "The uplink LteSpectrumPhy associated to this LtePhy",
210 MakePointerChecker <LteSpectrumPhy> ())
216 LteEnbPhy::~LteEnbPhy ()
224 m_ueAttached.clear ();
225 m_srsUeOffset.clear ();
226 delete m_enbPhySapProvider;
227 delete m_enbCphySapProvider;
236 m_uplinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd);
250 return (m_enbPhySapProvider);
257 m_enbCphySapUser = s;
264 return (m_enbCphySapProvider);
292 return m_noiseFigure;
299 m_macChTtiDelay = delay;
300 for (
int i = 0; i < m_macChTtiDelay; i++)
303 m_packetBurstQueue.push_back (pb);
304 std::list<Ptr<LteControlMessage> > l;
305 m_controlMessagesQueue.push_back (l);
306 std::list<UlDciLteControlMessage> l1;
307 m_ulDciQueue.push_back (l1);
309 for (
int i = 0; i < UL_PUSCH_TTIS_DELAY; i++)
311 std::list<UlDciLteControlMessage> l1;
312 m_ulDciQueue.push_back (l1);
319 return (m_macChTtiDelay);
325 return m_downlinkSpectrumPhy;
331 return m_uplinkSpectrumPhy;
335 LteEnbPhy::AddUePhy (uint16_t rnti)
338 std::set <uint16_t>::iterator it;
339 it = m_ueAttached.find (rnti);
340 if (it == m_ueAttached.end ())
342 m_ueAttached.insert (rnti);
353 LteEnbPhy::DeleteUePhy (uint16_t rnti)
356 std::set <uint16_t>::iterator it;
357 it = m_ueAttached.find (rnti);
358 if (it == m_ueAttached.end ())
365 m_ueAttached.erase (it);
380 LteEnbPhy::DoGetMacChTtiDelay ()
382 return (m_macChTtiDelay);
397 m_listOfDownlinkSubchannel = mask;
399 m_downlinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd);
406 return m_listOfDownlinkSubchannel;
449 std::list<Ptr<LteControlMessage> >::iterator it;
450 for (it = msgList.begin (); it != msgList.end(); it++)
452 switch ((*it)->GetMessageType ())
454 case LteControlMessage::RACH_PREAMBLE:
476 NS_LOG_INFO (
"-----frame " << m_nrFrames <<
"-----");
480 m_mib.systemFrameNumber = m_nrSubFrames;
482 mibMsg->SetMib (m_mib);
483 m_controlMessagesQueue.at (0).push_back (mibMsg);
495 if (m_srsPeriodicity>0)
498 NS_ASSERT_MSG (m_nrFrames > 1,
"the SRS index check code assumes that frameNo starts at 1");
499 NS_ASSERT_MSG (m_nrSubFrames > 0 && m_nrSubFrames <= 10,
"the SRS index check code assumes that subframeNo starts at 1");
500 m_currentSrsOffset = (((m_nrFrames-1)*10 + (m_nrSubFrames-1)) % m_srsPeriodicity);
502 NS_LOG_INFO (
"-----sub frame " << m_nrSubFrames <<
"-----");
503 m_harqPhyModule->SubframeIndication (m_nrFrames, m_nrSubFrames);
506 std::list<UlDciLteControlMessage> uldcilist =
DequeueUlDci ();
507 std::list<UlDciLteControlMessage>::iterator dciIt = uldcilist.begin ();
508 NS_LOG_DEBUG (
this <<
" eNB Expected TBs " << uldcilist.size ());
509 for (dciIt = uldcilist.begin (); dciIt!=uldcilist.end (); dciIt++)
511 std::set <uint16_t>::iterator it2;
512 it2 = m_ueAttached.find ((*dciIt).GetDci ().m_rnti);
514 if (it2 == m_ueAttached.end ())
522 std::vector <int> rbMap;
523 for (
int i = (*dciIt).GetDci ().m_rbStart; i < (*dciIt).GetDci ().m_rbStart + (*dciIt).GetDci ().m_rbLen; i++)
527 m_uplinkSpectrumPhy->AddExpectedTb ((*dciIt).GetDci ().m_rnti, (*dciIt).GetDci ().m_ndi, (*dciIt).GetDci ().m_tbSize, (*dciIt).GetDci ().m_mcs, rbMap, 0 , 0 , 0 ,
false );
528 if ((*dciIt).GetDci ().m_ndi==1)
530 NS_LOG_DEBUG (
this <<
" RNTI " << (*dciIt).GetDci ().m_rnti <<
" NEW TB");
534 NS_LOG_DEBUG (
this <<
" RNTI " << (*dciIt).GetDci ().m_rnti <<
" HARQ RETX");
541 m_dlDataRbMap.clear ();
542 if (ctrlMsg.size () > 0)
544 std::list<Ptr<LteControlMessage> >::iterator it;
545 it = ctrlMsg.begin ();
546 while (it != ctrlMsg.end ())
549 if (msg->GetMessageType () == LteControlMessage::DL_DCI)
555 for (
int i = 0; i < 32; i++)
557 if (((dci->GetDci ().m_rbBitmap & mask) >> i) == 1)
561 m_dlDataRbMap.push_back ((i * GetRbgSize ()) + k);
568 for (uint8_t i = 0; i < dci->GetDci ().m_mcs.size (); i++)
571 params.m_cellId = m_cellId;
574 params.m_rnti = dci->GetDci ().m_rnti;
577 params.m_mcs = dci->GetDci ().m_mcs.at (i);
578 params.m_size = dci->GetDci ().m_tbsSize.at (i);
579 params.m_rv = dci->GetDci ().m_rv.at (i);
580 params.m_ndi = dci->GetDci ().m_ndi.at (i);
585 else if (msg->GetMessageType () == LteControlMessage::UL_DCI)
590 else if (msg->GetMessageType () == LteControlMessage::RAR)
593 for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin (); it != rarMsg->RarListEnd (); ++it)
595 if (it->rarPayload.m_grant.m_ulDelay ==
true)
599 UlGrant_s ulGrant = it->rarPayload.m_grant;
602 dci.m_rnti = ulGrant.m_rnti;
603 dci.m_rbStart = ulGrant.m_rbStart;
604 dci.m_rbLen = ulGrant.m_rbLen;
605 dci.m_tbSize = ulGrant.m_tbSize;
606 dci.m_mcs = ulGrant.m_mcs;
607 dci.m_hopping = ulGrant.m_hopping;
608 dci.m_tpc = ulGrant.m_tpc;
609 dci.m_cqiRequest = ulGrant.m_cqiRequest;
644 NS_LOG_FUNCTION (
this <<
" eNB " << m_cellId <<
" start tx ctrl frame");
646 std::vector <int> dlRb;
647 for (uint8_t i = 0; i < m_dlBandwidth; i++)
653 m_downlinkSpectrumPhy->StartTxDlCtrlFrame (ctrlMsgList);
664 std::list<Ptr<LteControlMessage> > ctrlMsgList;
665 ctrlMsgList.clear ();
666 m_downlinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsgList, DL_DATA_DURATION);
674 if (m_nrSubFrames == 10)
718 m_interferenceSampleCounter++;
719 if (m_interferenceSampleCounter == m_interferenceSamplePeriod)
722 m_interferenceSampleCounter = 0;
738 Values::const_iterator it;
740 ulcqi.m_ulCqi.m_type = UlCqi_s::PUSCH;
744 double sinrdb = 10 * std::log10 ((*it));
747 int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
748 ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
757 LteEnbPhy::DoSetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
759 NS_LOG_FUNCTION (
this << (uint32_t) ulBandwidth << (uint32_t) dlBandwidth);
760 m_ulBandwidth = ulBandwidth;
761 m_dlBandwidth = dlBandwidth;
763 int Type0AllocationRbg[4] = {
769 for (
int i = 0; i < 4; i++)
771 if (dlBandwidth < Type0AllocationRbg[i])
780 LteEnbPhy::DoSetEarfcn (uint16_t ulEarfcn, uint16_t dlEarfcn)
783 m_ulEarfcn = ulEarfcn;
784 m_dlEarfcn = dlEarfcn;
789 LteEnbPhy::DoAddUe (uint16_t rnti)
793 bool success = AddUePhy (rnti);
798 LteEnbPhy::DoRemoveUe (uint16_t rnti)
802 bool success = DeleteUePhy (rnti);
807 FfMacSchedSapProvider::SchedUlCqiInfoReqParameters
811 Values::const_iterator it;
813 ulcqi.m_ulCqi.m_type = UlCqi_s::SRS;
818 double sinrdb = 10 * log10 ((*it));
821 int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
823 ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
827 NS_LOG_DEBUG (
this <<
" ENB RX UL-CQI of " << m_srsUeOffset.at (m_currentSrsOffset));
829 vsp.m_type = SRS_CQI_RNTI_VSP;
831 Ptr<SrsCqiRntiVsp> rnti = Create <SrsCqiRntiVsp> (m_srsUeOffset.at (m_currentSrsOffset));
833 ulcqi.m_vendorSpecificList.push_back (vsp);
835 CreateSrsReport (m_srsUeOffset.at (m_currentSrsOffset), srsSum / i);
842 LteEnbPhy::CreateSrsReport(uint16_t rnti,
double srs)
845 std::map <uint16_t,uint16_t>::iterator it = m_srsSampleCounterMap.find (rnti);
846 if (it==m_srsSampleCounterMap.end ())
849 m_srsSampleCounterMap.insert (std::pair <uint16_t,uint16_t> (rnti, 0));
850 it = m_srsSampleCounterMap.find (rnti);
853 if ((*it).second == m_srsSamplePeriod)
861 LteEnbPhy::DoSetTransmissionMode (uint16_t rnti, uint8_t txMode)
871 m_ulDciQueue.at (UL_PUSCH_TTIS_DELAY - 1).push_back (m);
874 std::list<UlDciLteControlMessage>
878 if (m_ulDciQueue.at (0).size ()>0)
880 std::list<UlDciLteControlMessage> ret = m_ulDciQueue.at (0);
881 m_ulDciQueue.erase (m_ulDciQueue.begin ());
882 std::list<UlDciLteControlMessage> l;
883 m_ulDciQueue.push_back (l);
888 m_ulDciQueue.erase (m_ulDciQueue.begin ());
889 std::list<UlDciLteControlMessage> l;
890 m_ulDciQueue.push_back (l);
891 std::list<UlDciLteControlMessage> emptylist;
897 LteEnbPhy::DoSetSrsConfigurationIndex (uint16_t rnti, uint16_t srcCi)
901 if (p!=m_srsPeriodicity)
904 m_srsUeOffset.clear ();
905 m_srsUeOffset.resize (p, 0);
906 m_srsPeriodicity = p;
915 std::map <uint16_t,uint16_t>::iterator it = m_srsCounter.find (rnti);
916 if (it != m_srsCounter.end ())
930 LteEnbPhy::DoSetMasterInformationBlock (LteRrcSap::MasterInformationBlock mib)
938 LteEnbPhy::SetHarqPhyModule (Ptr<LteHarqPhy> harq)
940 m_harqPhyModule = harq;
Values::const_iterator ConstValuesEnd() const
Time NanoSeconds(uint64_t ns)
create ns3::Time instances in units of nanoseconds.
#define NS_LOG_FUNCTION(parameters)
void DoSetCellId(uint16_t cellId)
virtual void SendMacPdu(Ptr< Packet > p)
Send the MAC PDU to the channel.
void SetDownlinkSubChannels(std::vector< int > mask)
set the resource blocks (a.k.a. sub channels) to be used in the downlink for transmission ...
void CalcChannelQualityForUe(std::vector< double > sinr, Ptr< LteSpectrumPhy > ue)
Calculate the channel quality for a given UE.
std::list< UlDciLteControlMessage > DequeueUlDci(void)
virtual uint8_t GetMacChTtiDelay()
Get the delay from MAC to Channel expressed in TTIs.
virtual void ReceiveLteControlMessageList(std::list< Ptr< LteControlMessage > >)
PhySpectrum received a new list of LteControlMessage.
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
double GetTti(void) const
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity()
Create the PSD for TX.
virtual void SendLteControlMessage(Ptr< LteControlMessage > msg)
Send SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
#define NS_LOG_COMPONENT_DEFINE(name)
See section 4.3.2 ulDciListElement.
TracedCallback< uint16_t, uint16_t, double > m_reportUeSinr
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
See section 4.3.12 ulInfoListElement.
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual void ReceiveRachPreamble(uint32_t prachId)=0
double GetNoiseFigure() const
void SetMacChDelay(uint8_t delay)
virtual void GenerateCtrlCqiReport(const SpectrumValue &sinr)
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
virtual void DoInitialize(void)
virtual void GenerateDataCqiReport(const SpectrumValue &sinr)
uint8_t GetRbgSize(void) const
Ptr< LteSpectrumPhy > GetDlSpectrumPhy() const
virtual void ReceiveLteUlHarqFeedback(UlInfoListElement_s mes)
PhySpectrum generated a new UL HARQ feedback.
Hold an unsigned integer type.
Define the RNTI that has generated the.
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)
Receive the control message.
void StartSubFrame(void)
Start a LTE sub frame.
#define NS_LOG_LOGIC(msg)
See section 4.3.3 vendorSpecifiListElement.
virtual void ReportInterference(const SpectrumValue &interf)
Substitutive structure for specifying BuildRarListElement_s::m_grant field.
void SendControlChannels(std::list< Ptr< LteControlMessage > > ctrlMsgList)
Send the PDCCH and PCFICH in the first 3 symbols.
double GetTxPower() const
virtual void UlInfoListElementHarqFeeback(UlInfoListElement_s params)=0
LteEnbPhySapProvider * GetLteEnbPhySapProvider()
Get the PHY SAP provider.
hold objects of type Ptr<T>
void SetControlMessages(Ptr< LteControlMessage > m)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void SetTxPower(double pow)
void SetDci(UlDciListElement_s dci)
add a DCI into the message
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
LteEnbCphySapProvider * GetLteEnbCphySapProvider()
Get the CPHY SAP provider.
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters CreatePuschCqiReport(const SpectrumValue &sinr)
Create the UL CQI feedback from SINR values perceived at the physical layer with the PUSCH signal rec...
#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)
void SetNoiseFigure(double pow)
void SetLteEnbPhySapUser(LteEnbPhySapUser *s)
Set the PHY SAP User.
#define NS_LOG_DEBUG(msg)
void StartFrame(void)
Start a LTE frame.
std::vector< int > GetDownlinkSubChannels(void)
virtual void UlCqiReport(FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi)=0
Returns to MAC level the UL-CQI evaluated.
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters CreateSrsCqiReport(const SpectrumValue &sinr)
Create the UL CQI feedback from SINR values perceived at the physical layer with the SRS signal recei...
void QueueUlDci(UlDciLteControlMessage m)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
#define NS_LOG_ERROR(msg)
Values::const_iterator ConstValuesBegin() const
virtual void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)=0
Trigger the start from a new frame (input from Phy layer)
TracedCallback< uint16_t, Ptr< SpectrumValue > > m_reportInterferenceTrace
void SendDataChannels(Ptr< PacketBurst > pb)
Send the PDSCH.
virtual void ReceivePhyPdu(Ptr< Packet > p)=0
Hold an floating point type.
virtual void ReportRsReceivedPower(const SpectrumValue &interf)
Set of values corresponding to a given SpectrumModel.
virtual void DoDispose(void)
void PhyPduReceived(Ptr< Packet > p)
PhySpectrum received a new PHY-PDU.
Ptr< LteSpectrumPhy > GetUlSpectrumPhy() const
void SetMacPdu(Ptr< Packet > p)
a unique identifier for an interface.
uint8_t GetMacChDelay(void) const
int64_t GetMilliSeconds(void) const
TypeId SetParent(TypeId tid)
void SetLteEnbCphySapUser(LteEnbCphySapUser *s)
Set the CPHY SAP User.
virtual void DoInitialize(void)
TracedCallback< PhyTransmissionStatParameters > m_dlPhyTransmission
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double noiseFigure)
void EndFrame(void)
End a LTE frame.
void DoSendMacPdu(Ptr< Packet > p)
Queue the MAC PDU to be sent (according to m_macChTtiDelay)
void EndSubFrame(void)
End a LTE sub frame.
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)=0
Receive SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.