A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-enb-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Giuseppe Piro <g.piro@poliba.it>
19  * Marco Miozzo <mmiozzo@cttc.es>
20  */
21 
22 #include <ns3/object-factory.h>
23 #include <ns3/log.h>
24 #include <cfloat>
25 #include <cmath>
26 #include <ns3/simulator.h>
27 #include <ns3/attribute-accessor-helper.h>
28 #include <ns3/double.h>
29 
30 
31 #include "lte-enb-phy.h"
32 #include "lte-ue-phy.h"
33 #include "lte-net-device.h"
35 #include "lte-control-messages.h"
36 #include "lte-enb-net-device.h"
37 #include "lte-ue-rrc.h"
38 #include "lte-enb-mac.h"
39 #include <ns3/lte-common.h>
40 #include <ns3/lte-vendor-specific-parameters.h>
41 
42 // WILD HACK for the inizialization of direct eNB-UE ctrl messaging
43 #include <ns3/node-list.h>
44 #include <ns3/node.h>
45 #include <ns3/lte-ue-net-device.h>
46 #include <ns3/pointer.h>
47 
48 NS_LOG_COMPONENT_DEFINE ("LteEnbPhy");
49 
50 namespace ns3 {
51 
52 NS_OBJECT_ENSURE_REGISTERED (LteEnbPhy);
53 
54 // duration of the data part of a subframe in DL
55 // = 0.001 / 14 * 11 (fixed to 11 symbols) -1ns as margin to avoid overlapping simulator events
56 static const Time DL_DATA_DURATION = NanoSeconds (785714 -1);
57 
58 // delay from subframe start to transmission of the data in DL
59 // = 0.001 / 14 * 3 (ctrl fixed to 3 symbols)
60 static const Time DL_CTRL_DELAY_FROM_SUBFRAME_START = NanoSeconds (214286);
61 
63 // member SAP forwarders
65 
66 
68 {
69 public:
71 
72  // inherited from LteEnbPhySapProvider
73  virtual void SendMacPdu (Ptr<Packet> p);
74  virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth);
75  virtual void SetCellId (uint16_t cellId);
77  virtual uint8_t GetMacChTtiDelay ();
78 
79 
80 private:
82 };
83 
85 {
86 
87 }
88 
89 void
91 {
92  m_phy->DoSendMacPdu (p);
93 }
94 
95 void
96 EnbMemberLteEnbPhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
97 {
98  m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth);
99 }
100 
101 void
103 {
104  m_phy->DoSetCellId (cellId);
105 }
106 
107 void
109 {
111 }
112 
113 uint8_t
115 {
116  return (m_phy->DoGetMacChTtiDelay ());
117 }
118 
119 
121 // generic LteEnbPhy methods
123 
124 
125 
127 {
128  NS_LOG_FUNCTION (this);
129  NS_FATAL_ERROR ("This constructor should not be called");
130 }
131 
133  : LtePhy (dlPhy, ulPhy),
134  m_enbPhySapUser (0),
135  m_enbCphySapUser (0),
136  m_nrFrames (0),
137  m_nrSubFrames (0),
138  m_srsPeriodicity (0),
139  m_srsStartTime (Seconds (0)),
140  m_currentSrsOffset (0),
141  m_interferenceSampleCounter (0)
142 {
145  m_harqPhyModule = Create <LteHarqPhy> ();
146  m_downlinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
147  m_uplinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
149 }
150 
151 TypeId
153 {
154  static TypeId tid = TypeId ("ns3::LteEnbPhy")
155  .SetParent<LtePhy> ()
156  .AddConstructor<LteEnbPhy> ()
157  .AddAttribute ("TxPower",
158  "Transmission power in dBm",
159  DoubleValue (30.0),
160  MakeDoubleAccessor (&LteEnbPhy::SetTxPower,
162  MakeDoubleChecker<double> ())
163  .AddAttribute ("NoiseFigure",
164  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
165  " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
166  "\"the difference in decibels (dB) between"
167  " the noise output of the actual receiver to the noise output of an "
168  " ideal receiver with the same overall gain and bandwidth when the receivers "
169  " are connected to sources at the standard noise temperature T0.\" "
170  "In this model, we consider T0 = 290K.",
171  DoubleValue (5.0),
172  MakeDoubleAccessor (&LteEnbPhy::SetNoiseFigure,
174  MakeDoubleChecker<double> ())
175  .AddAttribute ("MacToChannelDelay",
176  "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.",
177  UintegerValue (2),
178  MakeUintegerAccessor (&LteEnbPhy::SetMacChDelay,
180  MakeUintegerChecker<uint8_t> ())
181  .AddTraceSource ("ReportUeSinr",
182  "Report UEs' averaged linear SINR",
184  .AddAttribute ("UeSinrSamplePeriod",
185  "The sampling period for reporting UEs' SINR stats (default value 1)",
186  UintegerValue (1),
187  MakeUintegerAccessor (&LteEnbPhy::m_srsSamplePeriod),
188  MakeUintegerChecker<uint16_t> ())
189  .AddTraceSource ("ReportInterference",
190  "Report linear interference power per PHY RB",
192  .AddAttribute ("InterferenceSamplePeriod",
193  "The sampling period for reporting interference stats (default value 1)",
194  UintegerValue (1),
195  MakeUintegerAccessor (&LteEnbPhy::m_interferenceSamplePeriod),
196  MakeUintegerChecker<uint16_t> ())
197  .AddTraceSource ("DlPhyTransmission",
198  "DL transmission PHY layer statistics.",
200  .AddAttribute ("DlSpectrumPhy",
201  "The downlink LteSpectrumPhy associated to this LtePhy",
203  PointerValue (),
204  MakePointerAccessor (&LteEnbPhy::GetDlSpectrumPhy),
205  MakePointerChecker <LteSpectrumPhy> ())
206  .AddAttribute ("UlSpectrumPhy",
207  "The uplink LteSpectrumPhy associated to this LtePhy",
209  PointerValue (),
210  MakePointerAccessor (&LteEnbPhy::GetUlSpectrumPhy),
211  MakePointerChecker <LteSpectrumPhy> ())
212  ;
213  return tid;
214 }
215 
216 
218 {
219 }
220 
221 void
223 {
224  NS_LOG_FUNCTION (this);
225  m_ueAttached.clear ();
226  m_srsUeOffset.clear ();
227  delete m_enbPhySapProvider;
228  delete m_enbCphySapProvider;
230 }
231 
232 void
234 {
235  NS_LOG_FUNCTION (this);
237  m_uplinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd);
239 }
240 
241 
242 void
244 {
245  m_enbPhySapUser = s;
246 }
247 
250 {
251  return (m_enbPhySapProvider);
252 }
253 
254 void
256 {
257  NS_LOG_FUNCTION (this);
259 }
260 
263 {
264  NS_LOG_FUNCTION (this);
265  return (m_enbCphySapProvider);
266 }
267 
268 void
270 {
271  NS_LOG_FUNCTION (this << pow);
272  m_txPower = pow;
273 }
274 
275 double
277 {
278  NS_LOG_FUNCTION (this);
279  return m_txPower;
280 }
281 
282 void
284 {
285  NS_LOG_FUNCTION (this << nf);
286  m_noiseFigure = nf;
287 }
288 
289 double
291 {
292  NS_LOG_FUNCTION (this);
293  return m_noiseFigure;
294 }
295 
296 void
298 {
299  NS_LOG_FUNCTION (this);
300  m_macChTtiDelay = delay;
301  for (int i = 0; i < m_macChTtiDelay; i++)
302  {
303  Ptr<PacketBurst> pb = CreateObject <PacketBurst> ();
304  m_packetBurstQueue.push_back (pb);
305  std::list<Ptr<LteControlMessage> > l;
306  m_controlMessagesQueue.push_back (l);
307  std::list<UlDciLteControlMessage> l1;
308  m_ulDciQueue.push_back (l1);
309  }
310  for (int i = 0; i < UL_PUSCH_TTIS_DELAY; i++)
311  {
312  std::list<UlDciLteControlMessage> l1;
313  m_ulDciQueue.push_back (l1);
314  }
315 }
316 
317 uint8_t
319 {
320  return (m_macChTtiDelay);
321 }
322 
325 {
326  return m_downlinkSpectrumPhy;
327 }
328 
331 {
332  return m_uplinkSpectrumPhy;
333 }
334 
335 bool
336 LteEnbPhy::AddUePhy (uint16_t rnti)
337 {
338  NS_LOG_FUNCTION (this << rnti);
339  std::set <uint16_t>::iterator it;
340  it = m_ueAttached.find (rnti);
341  if (it == m_ueAttached.end ())
342  {
343  m_ueAttached.insert (rnti);
344  return (true);
345  }
346  else
347  {
348  NS_LOG_ERROR ("UE already attached");
349  return (false);
350  }
351 }
352 
353 bool
354 LteEnbPhy::DeleteUePhy (uint16_t rnti)
355 {
356  NS_LOG_FUNCTION (this << rnti);
357  std::set <uint16_t>::iterator it;
358  it = m_ueAttached.find (rnti);
359  if (it == m_ueAttached.end ())
360  {
361  NS_LOG_ERROR ("UE not attached");
362  return (false);
363  }
364  else
365  {
366  m_ueAttached.erase (it);
367  return (true);
368  }
369 }
370 
371 
372 
373 void
375 {
376  NS_LOG_FUNCTION (this);
377  SetMacPdu (p);
378 }
379 
380 uint8_t
382 {
383  return (m_macChTtiDelay);
384 }
385 
386 
387 void
389 {
390  NS_LOG_FUNCTION (this);
392 }
393 
394 void
395 LteEnbPhy::SetDownlinkSubChannels (std::vector<int> mask)
396 {
397  NS_LOG_FUNCTION (this);
400  m_downlinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd);
401 }
402 
403 std::vector<int>
405 {
406  NS_LOG_FUNCTION (this);
408 }
409 
412 {
413  NS_LOG_FUNCTION (this);
414 
416 
417  return psd;
418 }
419 
420 
421 void
423 {
424  NS_LOG_FUNCTION (this);
425 }
426 
427 
428 void
430 {
431  NS_LOG_FUNCTION (this << msg);
432  // queues the message (wait for MAC-PHY delay)
433  SetControlMessages (msg);
434 }
435 
436 
437 
438 void
440 {
441  NS_FATAL_ERROR ("Obsolete function");
442  NS_LOG_FUNCTION (this << msg);
444 }
445 
446 void
448 {
449  NS_LOG_FUNCTION (this);
450  std::list<Ptr<LteControlMessage> >::iterator it;
451  for (it = msgList.begin (); it != msgList.end(); it++)
452  {
453  switch ((*it)->GetMessageType ())
454  {
456  {
457  Ptr<RachPreambleLteControlMessage> rachPreamble = DynamicCast<RachPreambleLteControlMessage> (*it);
458  m_enbPhySapUser->ReceiveRachPreamble (rachPreamble->GetRapId ());
459  }
460  break;
462  {
463  Ptr<DlCqiLteControlMessage> dlcqiMsg = DynamicCast<DlCqiLteControlMessage> (*it);
464  CqiListElement_s dlcqi = dlcqiMsg->GetDlCqi ();
465  // check whether the UE is connected
466  if (m_ueAttached.find (dlcqi.m_rnti) != m_ueAttached.end ())
467  {
469  }
470  }
471  break;
473  {
474  Ptr<BsrLteControlMessage> bsrMsg = DynamicCast<BsrLteControlMessage> (*it);
475  MacCeListElement_s bsr = bsrMsg->GetBsr ();
476  // check whether the UE is connected
477  if (m_ueAttached.find (bsr.m_rnti) != m_ueAttached.end ())
478  {
480  }
481  }
482  break;
484  {
485  Ptr<DlHarqFeedbackLteControlMessage> dlharqMsg = DynamicCast<DlHarqFeedbackLteControlMessage> (*it);
486  DlInfoListElement_s dlharq = dlharqMsg->GetDlHarqFeedback ();
487  // check whether the UE is connected
488  if (m_ueAttached.find (dlharq.m_rnti) != m_ueAttached.end ())
489  {
491  }
492  }
493  break;
494  default:
495  NS_FATAL_ERROR ("Unexpected LteControlMessage type");
496  break;
497  }
498  }
499 }
500 
501 
502 
503 void
505 {
506  NS_LOG_FUNCTION (this);
507 
508  ++m_nrFrames;
509  NS_LOG_INFO ("-----frame " << m_nrFrames << "-----");
510  m_nrSubFrames = 0;
511 
512  // send MIB at beginning of every frame
514  Ptr<MibLteControlMessage> mibMsg = Create<MibLteControlMessage> ();
515  mibMsg->SetMib (m_mib);
516  m_controlMessagesQueue.at (0).push_back (mibMsg);
517 
518  StartSubFrame ();
519 }
520 
521 
522 void
524 {
525  NS_LOG_FUNCTION (this);
526 
527  ++m_nrSubFrames;
528  if (m_srsPeriodicity>0)
529  {
530  // might be 0 in case the eNB has no UEs attached
531  NS_ASSERT_MSG (m_nrFrames > 1, "the SRS index check code assumes that frameNo starts at 1");
532  NS_ASSERT_MSG (m_nrSubFrames > 0 && m_nrSubFrames <= 10, "the SRS index check code assumes that subframeNo starts at 1");
534  }
535  NS_LOG_INFO ("-----sub frame " << m_nrSubFrames << "-----");
536  m_harqPhyModule->SubframeIndication (m_nrFrames, m_nrSubFrames);
537 
538  // update info on TB to be received
539  std::list<UlDciLteControlMessage> uldcilist = DequeueUlDci ();
540  std::list<UlDciLteControlMessage>::iterator dciIt = uldcilist.begin ();
541  NS_LOG_DEBUG (this << " eNB Expected TBs " << uldcilist.size ());
542  for (dciIt = uldcilist.begin (); dciIt!=uldcilist.end (); dciIt++)
543  {
544  std::set <uint16_t>::iterator it2;
545  it2 = m_ueAttached.find ((*dciIt).GetDci ().m_rnti);
546 
547  if (it2 == m_ueAttached.end ())
548  {
549  NS_LOG_ERROR ("UE not attached");
550  }
551  else
552  {
553  // send info of TB to LteSpectrumPhy
554  // translate to allocation map
555  std::vector <int> rbMap;
556  for (int i = (*dciIt).GetDci ().m_rbStart; i < (*dciIt).GetDci ().m_rbStart + (*dciIt).GetDci ().m_rbLen; i++)
557  {
558  rbMap.push_back (i);
559  }
560  m_uplinkSpectrumPhy->AddExpectedTb ((*dciIt).GetDci ().m_rnti, (*dciIt).GetDci ().m_ndi, (*dciIt).GetDci ().m_tbSize, (*dciIt).GetDci ().m_mcs, rbMap, 0 /* always SISO*/, 0 /* no HARQ proc id in UL*/, 0 /*evaluated by LteSpectrumPhy*/, false /* UL*/);
561  if ((*dciIt).GetDci ().m_ndi==1)
562  {
563  NS_LOG_DEBUG (this << " RNTI " << (*dciIt).GetDci ().m_rnti << " NEW TB");
564  }
565  else
566  {
567  NS_LOG_DEBUG (this << " RNTI " << (*dciIt).GetDci ().m_rnti << " HARQ RETX");
568  }
569  }
570  }
571 
572  // process the current burst of control messages
573  std::list<Ptr<LteControlMessage> > ctrlMsg = GetControlMessages ();
574  m_dlDataRbMap.clear ();
575  if (ctrlMsg.size () > 0)
576  {
577  std::list<Ptr<LteControlMessage> >::iterator it;
578  it = ctrlMsg.begin ();
579  while (it != ctrlMsg.end ())
580  {
581  Ptr<LteControlMessage> msg = (*it);
582  if (msg->GetMessageType () == LteControlMessage::DL_DCI)
583  {
584  Ptr<DlDciLteControlMessage> dci = DynamicCast<DlDciLteControlMessage> (msg);
585  // get the tx power spectral density according to DL-DCI(s)
586  // translate the DCI to Spectrum framework
587  uint32_t mask = 0x1;
588  for (int i = 0; i < 32; i++)
589  {
590  if (((dci->GetDci ().m_rbBitmap & mask) >> i) == 1)
591  {
592  for (int k = 0; k < GetRbgSize (); k++)
593  {
594  m_dlDataRbMap.push_back ((i * GetRbgSize ()) + k);
595  //NS_LOG_DEBUG(this << " [enb]DL-DCI allocated PRB " << (i*GetRbgSize()) + k);
596  }
597  }
598  mask = (mask << 1);
599  }
600  // fire trace of DL Tx PHY stats
601  for (uint8_t i = 0; i < dci->GetDci ().m_mcs.size (); i++)
602  {
604  params.m_cellId = m_cellId;
605  params.m_imsi = 0; // it will be set by DlPhyTransmissionCallback in LteHelper
607  params.m_rnti = dci->GetDci ().m_rnti;
608  params.m_txMode = 0; // TBD
609  params.m_layer = i;
610  params.m_mcs = dci->GetDci ().m_mcs.at (i);
611  params.m_size = dci->GetDci ().m_tbsSize.at (i);
612  params.m_rv = dci->GetDci ().m_rv.at (i);
613  params.m_ndi = dci->GetDci ().m_ndi.at (i);
614  m_dlPhyTransmission (params);
615  }
616 
617  }
618  else if (msg->GetMessageType () == LteControlMessage::UL_DCI)
619  {
620  Ptr<UlDciLteControlMessage> dci = DynamicCast<UlDciLteControlMessage> (msg);
621  QueueUlDci (*dci);
622  }
623  else if (msg->GetMessageType () == LteControlMessage::RAR)
624  {
625  Ptr<RarLteControlMessage> rarMsg = DynamicCast<RarLteControlMessage> (msg);
626  for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin (); it != rarMsg->RarListEnd (); ++it)
627  {
628  if (it->rarPayload.m_grant.m_ulDelay == true)
629  {
630  NS_FATAL_ERROR (" RAR delay is not yet implemented");
631  }
632  UlGrant_s ulGrant = it->rarPayload.m_grant;
633  // translate the UL grant in a standard UL-DCI and queue it
634  UlDciListElement_s dci;
635  dci.m_rnti = ulGrant.m_rnti;
636  dci.m_rbStart = ulGrant.m_rbStart;
637  dci.m_rbLen = ulGrant.m_rbLen;
638  dci.m_tbSize = ulGrant.m_tbSize;
639  dci.m_mcs = ulGrant.m_mcs;
640  dci.m_hopping = ulGrant.m_hopping;
641  dci.m_tpc = ulGrant.m_tpc;
642  dci.m_cqiRequest = ulGrant.m_cqiRequest;
643  dci.m_ndi = 1;
645  msg.SetDci (dci);
646  QueueUlDci (msg);
647  }
648  }
649  it++;
650 
651  }
652  }
653 
654  SendControlChannels (ctrlMsg);
655 
656  // send data frame
658  if (pb)
659  {
660  Simulator::Schedule (DL_CTRL_DELAY_FROM_SUBFRAME_START, // ctrl frame fixed to 3 symbols
662  this,pb);
663  }
664 
665  // trigger the MAC
667 
668  Simulator::Schedule (Seconds (GetTti ()),
670  this);
671 
672 }
673 
674 void
676 {
677  NS_LOG_FUNCTION (this << " eNB " << m_cellId << " start tx ctrl frame");
678  // set the current tx power spectral density (full bandwidth)
679  std::vector <int> dlRb;
680  for (uint8_t i = 0; i < m_dlBandwidth; i++)
681  {
682  dlRb.push_back (i);
683  }
684  SetDownlinkSubChannels (dlRb);
685  NS_LOG_LOGIC (this << " eNB start TX CTRL");
686  bool pss = false;
687  if ((m_nrSubFrames == 1) || (m_nrSubFrames == 6))
688  {
689  pss = true;
690  }
691  m_downlinkSpectrumPhy->StartTxDlCtrlFrame (ctrlMsgList, pss);
692 
693 }
694 
695 void
697 {
698  // set the current tx power spectral density
700  // send the current burts of packets
701  NS_LOG_LOGIC (this << " eNB start TX DATA");
702  std::list<Ptr<LteControlMessage> > ctrlMsgList;
703  ctrlMsgList.clear ();
704  m_downlinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsgList, DL_DATA_DURATION);
705 }
706 
707 
708 void
710 {
711  NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ());
712  if (m_nrSubFrames == 10)
713  {
715  }
716  else
717  {
719  }
720 }
721 
722 
723 void
725 {
726  NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ());
728 }
729 
730 
731 void
733 {
734  NS_LOG_FUNCTION (this << sinr << Simulator::Now () << m_srsStartTime);
735  // avoid processing SRSs sent with an old SRS configuration index
737  {
739  m_enbPhySapUser->UlCqiReport (ulcqi);
740  }
741 }
742 
743 void
745 {
746  NS_LOG_FUNCTION (this << sinr);
748  m_enbPhySapUser->UlCqiReport (ulcqi);
749 }
750 
751 void
753 {
754  NS_LOG_FUNCTION (this << interf);
755  Ptr<SpectrumValue> interfCopy = Create<SpectrumValue> (interf);
757  if (m_interferenceSampleCounter == m_interferenceSamplePeriod)
758  {
759  m_reportInterferenceTrace (m_cellId, interfCopy);
760  m_interferenceSampleCounter = 0;
761  }
762 }
763 
764 void
766 {
767  // not used by eNB
768 }
769 
770 
771 
774 {
775  NS_LOG_FUNCTION (this << sinr);
776  Values::const_iterator it;
778  ulcqi.m_ulCqi.m_type = UlCqi_s::PUSCH;
779  int i = 0;
780  for (it = sinr.ConstValuesBegin (); it != sinr.ConstValuesEnd (); it++)
781  {
782  double sinrdb = 10 * std::log10 ((*it));
783 // NS_LOG_DEBUG ("ULCQI RB " << i << " value " << sinrdb);
784  // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
785  int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
786  ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
787  i++;
788  }
789  return (ulcqi);
790 
791 }
792 
793 
794 void
795 LteEnbPhy::DoSetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
796 {
797  NS_LOG_FUNCTION (this << (uint32_t) ulBandwidth << (uint32_t) dlBandwidth);
798  m_ulBandwidth = ulBandwidth;
799  m_dlBandwidth = dlBandwidth;
800 
801  int Type0AllocationRbg[4] = {
802  10, // RGB size 1
803  26, // RGB size 2
804  63, // RGB size 3
805  110 // RGB size 4
806  }; // see table 7.1.6.1-1 of 36.213
807  for (int i = 0; i < 4; i++)
808  {
809  if (dlBandwidth < Type0AllocationRbg[i])
810  {
811  m_rbgSize = i + 1;
812  break;
813  }
814  }
815 }
816 
817 void
818 LteEnbPhy::DoSetEarfcn (uint16_t ulEarfcn, uint16_t dlEarfcn)
819 {
820  NS_LOG_FUNCTION (this << ulEarfcn << dlEarfcn);
821  m_ulEarfcn = ulEarfcn;
822  m_dlEarfcn = dlEarfcn;
823 }
824 
825 
826 void
827 LteEnbPhy::DoAddUe (uint16_t rnti)
828 {
829  NS_LOG_FUNCTION (this << rnti);
830 
831  bool success = AddUePhy (rnti);
832  NS_ASSERT_MSG (success, "AddUePhy() failed");
833 }
834 
835 void
836 LteEnbPhy::DoRemoveUe (uint16_t rnti)
837 {
838  NS_LOG_FUNCTION (this << rnti);
839 
840  bool success = DeleteUePhy (rnti);
841  NS_ASSERT_MSG (success, "DeleteUePhy() failed");
842 }
843 
844 
847 {
848  NS_LOG_FUNCTION (this << sinr);
849  Values::const_iterator it;
851  ulcqi.m_ulCqi.m_type = UlCqi_s::SRS;
852  int i = 0;
853  double srsSum = 0.0;
854  for (it = sinr.ConstValuesBegin (); it != sinr.ConstValuesEnd (); it++)
855  {
856  double sinrdb = 10 * log10 ((*it));
857  // NS_LOG_DEBUG ("ULCQI RB " << i << " value " << sinrdb);
858  // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
859  int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
860  srsSum += (*it);
861  ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
862  i++;
863  }
864  // Insert the user generated the srs as a vendor specific parameter
865  NS_LOG_DEBUG (this << " ENB RX UL-CQI of " << m_srsUeOffset.at (m_currentSrsOffset));
867  vsp.m_type = SRS_CQI_RNTI_VSP;
868  vsp.m_length = sizeof(SrsCqiRntiVsp);
869  Ptr<SrsCqiRntiVsp> rnti = Create <SrsCqiRntiVsp> (m_srsUeOffset.at (m_currentSrsOffset));
870  vsp.m_value = rnti;
871  ulcqi.m_vendorSpecificList.push_back (vsp);
872  // call SRS tracing method
874  (i > 0) ? (srsSum / i) : DBL_MAX);
875  return (ulcqi);
876 
877 }
878 
879 
880 void
881 LteEnbPhy::CreateSrsReport(uint16_t rnti, double srs)
882 {
883  NS_LOG_FUNCTION (this << rnti << srs);
884  std::map <uint16_t,uint16_t>::iterator it = m_srsSampleCounterMap.find (rnti);
885  if (it==m_srsSampleCounterMap.end ())
886  {
887  // create new entry
888  m_srsSampleCounterMap.insert (std::pair <uint16_t,uint16_t> (rnti, 0));
889  it = m_srsSampleCounterMap.find (rnti);
890  }
891  (*it).second++;
892  if ((*it).second == m_srsSamplePeriod)
893  {
894  m_reportUeSinr (m_cellId, rnti, srs);
895  (*it).second = 0;
896  }
897 }
898 
899 void
900 LteEnbPhy::DoSetTransmissionMode (uint16_t rnti, uint8_t txMode)
901 {
902  NS_LOG_FUNCTION (this << rnti << (uint16_t)txMode);
903  // UL supports only SISO MODE
904 }
905 
906 void
908 {
909  NS_LOG_FUNCTION (this);
910  m_ulDciQueue.at (UL_PUSCH_TTIS_DELAY - 1).push_back (m);
911 }
912 
913 std::list<UlDciLteControlMessage>
915 {
916  NS_LOG_FUNCTION (this);
917  if (m_ulDciQueue.at (0).size ()>0)
918  {
919  std::list<UlDciLteControlMessage> ret = m_ulDciQueue.at (0);
920  m_ulDciQueue.erase (m_ulDciQueue.begin ());
921  std::list<UlDciLteControlMessage> l;
922  m_ulDciQueue.push_back (l);
923  return (ret);
924  }
925  else
926  {
927  m_ulDciQueue.erase (m_ulDciQueue.begin ());
928  std::list<UlDciLteControlMessage> l;
929  m_ulDciQueue.push_back (l);
930  std::list<UlDciLteControlMessage> emptylist;
931  return (emptylist);
932  }
933 }
934 
935 void
936 LteEnbPhy::DoSetSrsConfigurationIndex (uint16_t rnti, uint16_t srcCi)
937 {
938  NS_LOG_FUNCTION (this);
939  uint16_t p = GetSrsPeriodicity (srcCi);
940  if (p!=m_srsPeriodicity)
941  {
942  // resize the array of offset -> re-initialize variables
943  m_srsUeOffset.clear ();
944  m_srsUeOffset.resize (p, 0);
945  m_srsPeriodicity = p;
946  // inhibit SRS until RRC Connection Reconfiguration propagates
947  // to UEs, otherwise we might be wrong in determining the UE who
948  // actually sent the SRS (if the UE was using a stale SRS config)
949  // if we use a static SRS configuration index, we can have a 0ms guard time
950  m_srsStartTime = Simulator::Now () + MilliSeconds (m_macChTtiDelay) + MilliSeconds (0);
951  }
952 
953  NS_LOG_DEBUG (this << " ENB SRS P " << m_srsPeriodicity << " RNTI " << rnti << " offset " << GetSrsSubframeOffset (srcCi) << " CI " << srcCi);
954  std::map <uint16_t,uint16_t>::iterator it = m_srsCounter.find (rnti);
955  if (it != m_srsCounter.end ())
956  {
957  (*it).second = GetSrsSubframeOffset (srcCi) + 1;
958  }
959  else
960  {
961  m_srsCounter.insert (std::pair<uint16_t, uint16_t> (rnti, GetSrsSubframeOffset (srcCi) + 1));
962  }
963  m_srsUeOffset.at (GetSrsSubframeOffset (srcCi)) = rnti;
964 
965 }
966 
967 
968 void
970 {
971  NS_LOG_FUNCTION (this);
972  m_mib = mib;
973 }
974 
975 
976 void
978 {
979  m_harqPhyModule = harq;
980 }
981 
982 
983 void
985 {
986  NS_LOG_FUNCTION (this);
987  // forward to scheduler
989 }
990 
991 };
Values::const_iterator ConstValuesEnd() const
virtual ~LteEnbPhy()
Definition: lte-enb-phy.cc:217
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
uint16_t m_interferenceSampleCounter
Definition: lte-enb-phy.h:322
void DoSetCellId(uint16_t cellId)
Definition: lte-phy.cc:245
double m_noiseFigure
Definition: lte-phy.h:228
uint32_t m_nrSubFrames
Definition: lte-enb-phy.h:295
static uint16_t double2fpS11dot3(double val)
Definition: lte-common.cc:97
double m_txPower
Definition: lte-phy.h:227
uint16_t m_dlEarfcn
Definition: lte-phy.h:235
virtual void SendMacPdu(Ptr< Packet > p)
Send the MAC PDU to the channel.
Definition: lte-enb-phy.cc:90
uint16_t m_srsSamplePeriod
Definition: lte-enb-phy.h:312
void SetDownlinkSubChannels(std::vector< int > mask)
set the resource blocks (a.k.a. sub channels) to be used in the downlink for transmission ...
Definition: lte-enb-phy.cc:395
void CalcChannelQualityForUe(std::vector< double > sinr, Ptr< LteSpectrumPhy > ue)
Calculate the channel quality for a given UE.
Definition: lte-enb-phy.cc:422
bool DeleteUePhy(uint16_t rnti)
Definition: lte-enb-phy.cc:354
std::list< UlDciLteControlMessage > DequeueUlDci(void)
Definition: lte-enb-phy.cc:914
std::vector< Ptr< PacketBurst > > m_packetBurstQueue
Definition: lte-phy.h:238
virtual uint8_t GetMacChTtiDelay()
Get the delay from MAC to Channel expressed in TTIs.
Definition: lte-enb-phy.cc:114
virtual void ReceiveLteControlMessageList(std::list< Ptr< LteControlMessage > >)
PhySpectrum received a new list of LteControlMessage.
Definition: lte-enb-phy.cc:447
enum ns3::UlCqi_s::Type_e m_type
void DoSendLteControlMessage(Ptr< LteControlMessage > msg)
Definition: lte-enb-phy.cc:429
uint16_t GetSrsPeriodicity(uint16_t srcCi) const
Definition: lte-phy.cc:147
double GetTti(void) const
Definition: lte-phy.cc:139
std::vector< uint16_t > m_sinr
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity()
Create the PSD for TX.
Definition: lte-enb-phy.cc:411
std::vector< std::list< UlDciLteControlMessage > > m_ulDciQueue
Definition: lte-enb-phy.h:286
virtual void SendLteControlMessage(Ptr< LteControlMessage > msg)
Send SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
Definition: lte-enb-phy.cc:108
Ptr< LteSpectrumPhy > m_downlinkSpectrumPhy
Definition: lte-phy.h:224
See section 4.3.2 ulDciListElement.
TracedCallback< uint16_t, uint16_t, double > m_reportUeSinr
Definition: lte-enb-phy.h:311
See section 4.3.24 cqiListElement.
#define NS_LOG_INFO(msg)
Definition: log.h:264
EnbMemberLteEnbPhySapProvider(LteEnbPhy *phy)
Definition: lte-enb-phy.cc:84
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:824
See section 4.3.12 ulInfoListElement.
NS_LOG_COMPONENT_DEFINE("LteEnbPhy")
std::vector< int > m_dlDataRbMap
Definition: lte-enb-phy.h:284
uint32_t m_nrFrames
Definition: lte-enb-phy.h:294
std::map< uint16_t, uint16_t > m_srsCounter
Definition: lte-enb-phy.h:299
void DoSetEarfcn(uint16_t dlEarfcn, uint16_t ulEarfcn)
Definition: lte-enb-phy.cc:818
LteEnbPhySapUser * m_enbPhySapUser
Definition: lte-enb-phy.h:289
uint8_t m_ulBandwidth
Definition: lte-phy.h:231
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
uint16_t m_tbSize
virtual void ReceiveRachPreamble(uint32_t prachId)=0
std::vector< int > m_listOfDownlinkSubchannel
Definition: lte-enb-phy.h:282
double GetNoiseFigure() const
Definition: lte-enb-phy.cc:290
void CreateSrsReport(uint16_t rnti, double srs)
Definition: lte-enb-phy.cc:881
void SetMacChDelay(uint8_t delay)
Definition: lte-enb-phy.cc:297
static TypeId GetTypeId(void)
Definition: lte-enb-phy.cc:152
virtual void GenerateCtrlCqiReport(const SpectrumValue &sinr)
Definition: lte-enb-phy.cc:732
LteEnbCphySapProvider * m_enbCphySapProvider
Definition: lte-enb-phy.h:291
uint16_t GetSrsSubframeOffset(uint16_t srcCi) const
Definition: lte-phy.cc:165
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
void DoDispose()
Definition: lte-phy.cc:75
void DoSetMasterInformationBlock(LteRrcSap::MasterInformationBlock mib)
Definition: lte-enb-phy.cc:969
virtual void DoInitialize(void)
Definition: lte-enb-phy.cc:233
virtual void GenerateDataCqiReport(const SpectrumValue &sinr)
Definition: lte-enb-phy.cc:744
uint8_t GetRbgSize(void) const
Definition: lte-phy.cc:183
Ptr< LteHarqPhy > m_harqPhyModule
Definition: lte-enb-phy.h:305
Ptr< LteSpectrumPhy > GetDlSpectrumPhy() const
Definition: lte-enb-phy.cc:324
std::map< uint16_t, uint16_t > m_srsSampleCounterMap
Definition: lte-enb-phy.h:313
virtual void ReceiveLteUlHarqFeedback(UlInfoListElement_s mes)
PhySpectrum generated a new UL HARQ feedback.
Definition: lte-enb-phy.cc:984
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual void SetBandwidth(uint8_t ulBandwidth, uint8_t dlBandwidth)
Definition: lte-enb-phy.cc:96
Ptr< SampleEmitter > s
void SetHarqPhyModule(Ptr< LteHarqPhy > harq)
Definition: lte-enb-phy.cc:977
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
Define the RNTI that has generated the.
uint16_t m_interferenceSamplePeriod
Definition: lte-enb-phy.h:321
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)
Receive the control message.
Definition: lte-enb-phy.cc:439
uint16_t m_ulEarfcn
Definition: lte-phy.h:236
void StartSubFrame(void)
Start a LTE sub frame.
Definition: lte-enb-phy.cc:523
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
See section 4.3.3 vendorSpecifiListElement.
bool AddUePhy(uint16_t rnti)
Definition: lte-enb-phy.cc:336
#define list
virtual void ReportInterference(const SpectrumValue &interf)
Definition: lte-enb-phy.cc:752
See section 4.3.23 dlInfoListElement.
See section 4.3.14 macCEListElement.
void DoSetBandwidth(uint8_t ulBandwidth, uint8_t dlBandwidth)
Definition: lte-enb-phy.cc:795
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.
Definition: lte-enb-phy.cc:675
double GetTxPower() const
Definition: lte-enb-phy.cc:276
uint8_t m_macChTtiDelay
Definition: lte-phy.h:240
virtual void UlInfoListElementHarqFeeback(UlInfoListElement_s params)=0
LteEnbPhySapProvider * GetLteEnbPhySapProvider()
Get the PHY SAP provider.
Definition: lte-enb-phy.cc:249
hold objects of type Ptr
Definition: pointer.h:33
LteRrcSap::MasterInformationBlock m_mib
Definition: lte-enb-phy.h:303
void DoRemoveUe(uint16_t rnti)
Definition: lte-enb-phy.cc:836
void SetControlMessages(Ptr< LteControlMessage > m)
Definition: lte-phy.cc:214
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
LteEnbPhySapProvider * m_enbPhySapProvider
Definition: lte-enb-phy.h:288
uint16_t m_currentSrsOffset
Definition: lte-enb-phy.h:301
void SetTxPower(double pow)
Definition: lte-enb-phy.cc:269
void SetDci(UlDciListElement_s dci)
add a DCI into the message
uint8_t m_dlBandwidth
Definition: lte-phy.h:232
void DoAddUe(uint16_t rnti)
Definition: lte-enb-phy.cc:827
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Definition: simulator.h:985
static Time Now(void)
Definition: simulator.cc:180
virtual void SetCellId(uint16_t cellId)
Definition: lte-enb-phy.cc:102
LteEnbCphySapProvider * GetLteEnbCphySapProvider()
Get the CPHY SAP provider.
Definition: lte-enb-phy.cc:262
uint16_t m_cellId
Definition: lte-phy.h:242
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters CreatePuschCqiReport(const SpectrumValue &sinr)
Create the UL CQI feedback from SINR values perceived at the physical layer with the PUSCH signal rec...
Definition: lte-enb-phy.cc:773
#define SRS_CQI_RNTI_VSP
LteEnbCphySapUser * m_enbCphySapUser
Definition: lte-enb-phy.h:292
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
static Ptr< SpectrumValue > CreateTxPowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double powerTx, std::vector< int > activeRbs)
uint8_t DoGetMacChTtiDelay()
Definition: lte-enb-phy.cc:381
friend class EnbMemberLteEnbPhySapProvider
Definition: lte-enb-phy.h:49
std::list< Ptr< LteControlMessage > > GetControlMessages(void)
Definition: lte-phy.cc:222
Ptr< PacketBurst > GetPacketBurst(void)
Definition: lte-phy.cc:195
void DoSetSrsConfigurationIndex(uint16_t rnti, uint16_t srcCi)
Definition: lte-enb-phy.cc:936
void SetNoiseFigure(double pow)
Definition: lte-enb-phy.cc:283
void SetLteEnbPhySapUser(LteEnbPhySapUser *s)
Set the PHY SAP User.
Definition: lte-enb-phy.cc:243
static const Time DL_DATA_DURATION
Definition: lte-enb-phy.cc:56
int Type0AllocationRbg[4]
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
void StartFrame(void)
Start a LTE frame.
Definition: lte-enb-phy.cc:504
std::vector< int > GetDownlinkSubChannels(void)
Definition: lte-enb-phy.cc:404
std::vector< uint16_t > m_srsUeOffset
Definition: lte-enb-phy.h:300
void DoSetTransmissionMode(uint16_t rnti, uint8_t txMode)
Definition: lte-enb-phy.cc:900
uint8_t m_rbgSize
Definition: lte-phy.h:233
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...
Definition: lte-enb-phy.cc:846
void QueueUlDci(UlDciLteControlMessage m)
Definition: lte-enb-phy.cc:907
#define NS_LOG_ERROR(msg)
Definition: log.h:237
Values::const_iterator ConstValuesBegin() const
std::vector< std::list< Ptr< LteControlMessage > > > m_controlMessagesQueue
Definition: lte-phy.h:239
Ptr< LteSpectrumPhy > m_uplinkSpectrumPhy
Definition: lte-phy.h:225
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
Definition: lte-enb-phy.h:320
void SendDataChannels(Ptr< PacketBurst > pb)
Send the PDSCH.
Definition: lte-enb-phy.cc:696
virtual void ReceivePhyPdu(Ptr< Packet > p)=0
Hold an floating point type.
Definition: double.h:41
virtual void ReportRsReceivedPower(const SpectrumValue &interf)
Definition: lte-enb-phy.cc:765
Set of values corresponding to a given SpectrumModel.
virtual void DoDispose(void)
Definition: lte-enb-phy.cc:222
void PhyPduReceived(Ptr< Packet > p)
PhySpectrum received a new PHY-PDU.
Definition: lte-enb-phy.cc:388
std::set< uint16_t > m_ueAttached
Definition: lte-enb-phy.h:280
Ptr< LteSpectrumPhy > GetUlSpectrumPhy() const
Definition: lte-enb-phy.cc:330
void SetMacPdu(Ptr< Packet > p)
Definition: lte-phy.cc:189
a unique identifier for an interface.
Definition: type-id.h:49
uint8_t GetMacChDelay(void) const
Definition: lte-enb-phy.cc:318
int64_t GetMilliSeconds(void) const
Definition: nstime.h:275
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void SetLteEnbCphySapUser(LteEnbCphySapUser *s)
Set the CPHY SAP User.
Definition: lte-enb-phy.cc:255
virtual void DoInitialize(void)
Definition: object.cc:342
TracedCallback< PhyTransmissionStatParameters > m_dlPhyTransmission
Definition: lte-enb-phy.h:328
static Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint16_t earfcn, uint8_t bandwidth, double noiseFigure)
#define UL_PUSCH_TTIS_DELAY
Definition: lte-common.h:28
uint16_t m_srsPeriodicity
Definition: lte-enb-phy.h:297
void EndFrame(void)
End a LTE frame.
Definition: lte-enb-phy.cc:724
void DoSendMacPdu(Ptr< Packet > p)
Queue the MAC PDU to be sent (according to m_macChTtiDelay)
Definition: lte-enb-phy.cc:374
void EndSubFrame(void)
End a LTE sub frame.
Definition: lte-enb-phy.cc:709
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)=0
Receive SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
static const Time DL_CTRL_DELAY_FROM_SUBFRAME_START
Definition: lte-enb-phy.cc:60