A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-ue-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 <marco.miozzo@cttc.es>
20  * Nicola Baldo <nbaldo@cttc.es>
21  */
22 
23 #include <ns3/object-factory.h>
24 #include <ns3/log.h>
25 #include <math.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"
34 #include "lte-amc.h"
35 #include "lte-ue-mac.h"
36 #include "ff-mac-common.h"
38 #include <ns3/lte-common.h>
39 
40 
41 NS_LOG_COMPONENT_DEFINE ("LteUePhy");
42 
43 namespace ns3 {
44 
46 // member SAP forwarders
48 
49 
51 {
52 public:
54 
55  // inherited from LtePhySapProvider
56  virtual void SendMacPdu (Ptr<Packet> p);
57  virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth);
59  virtual void SetTransmissionMode (uint8_t txMode);
60 
61 private:
63 };
64 
66 {
67 
68 }
69 
70 
71 void
73 {
74  m_phy->DoSendMacPdu (p);
75 }
76 
77 void
78 UeMemberLteUePhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
79 {
80  m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth);
81 }
82 
83 void
85 {
87 }
88 
89 void
91 {
92  m_phy->DoSetTransmissionMode (txMode);
93 }
94 
95 
96 
98 // generic LteUePhy methods
100 
101 
103 
104 
106 {
107  NS_LOG_FUNCTION (this);
108  NS_FATAL_ERROR ("This constructor should not be called");
109 }
110 
112  : LtePhy (dlPhy, ulPhy),
113  m_p10CqiPeriocity (MilliSeconds (1)),
114  // ideal behavior
115  m_p10CqiLast (MilliSeconds (0)),
116  m_a30CqiPeriocity (MilliSeconds (1)),
117  // ideal behavior
118  m_a30CqiLast (MilliSeconds (0))
119 {
120  m_amc = CreateObject <LteAmc> ();
122  m_macChTtiDelay = UL_PUSCH_TTIS_DELAY + 1; // +1 for avoiding UL/DL trigger synchronization remove 1 TTI of delay
123  for (int i = 0; i < m_macChTtiDelay; i++)
124  {
125  Ptr<PacketBurst> pb = CreateObject <PacketBurst> ();
126  m_packetBurstQueue.push_back (pb);
127  std::list<Ptr<IdealControlMessage> > l;
128  m_controlMessagesQueue.push_back (l);
129  }
130  std::vector <int> ulRb;
131  m_subChannelsForTransmissionQueue.resize (m_macChTtiDelay, ulRb);
132 }
133 
134 
136 {
137  m_txModeGain.clear ();
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION (this);
144  delete m_uePhySapProvider;
146 }
147 
148 
149 
150 TypeId
152 {
153  static TypeId tid = TypeId ("ns3::LteUePhy")
154  .SetParent<LtePhy> ()
155  .AddConstructor<LteUePhy> ()
156  .AddAttribute ("TxPower",
157  "Transmission power in dBm",
158  DoubleValue (10.0),
159  MakeDoubleAccessor (&LteUePhy::SetTxPower,
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.",
170  DoubleValue (9.0),
171  MakeDoubleAccessor (&LteUePhy::SetNoiseFigure,
173  MakeDoubleChecker<double> ())
174  .AddAttribute ("TxMode1Gain",
175  "Transmission mode 1 gain in dB",
176  DoubleValue (0.0),
177  MakeDoubleAccessor (&LteUePhy::SetTxMode1Gain ),
178  MakeDoubleChecker<double> ())
179  .AddAttribute ("TxMode2Gain",
180  "Transmission mode 2 gain in dB",
181  DoubleValue (4.2),
182  MakeDoubleAccessor (&LteUePhy::SetTxMode2Gain ),
183  MakeDoubleChecker<double> ())
184  .AddAttribute ("TxMode3Gain",
185  "Transmission mode 3 gain in dB",
186  DoubleValue (-2.8),
187  MakeDoubleAccessor (&LteUePhy::SetTxMode3Gain ),
188  MakeDoubleChecker<double> ())
189  .AddAttribute ("TxMode4Gain",
190  "Transmission mode 4 gain in dB",
191  DoubleValue (0.0),
192  MakeDoubleAccessor (&LteUePhy::SetTxMode4Gain ),
193  MakeDoubleChecker<double> ())
194  .AddAttribute ("TxMode5Gain",
195  "Transmission mode 5 gain in dB",
196  DoubleValue (0.0),
197  MakeDoubleAccessor (&LteUePhy::SetTxMode5Gain ),
198  MakeDoubleChecker<double> ())
199  .AddAttribute ("TxMode6Gain",
200  "Transmission mode 6 gain in dB",
201  DoubleValue (0.0),
202  MakeDoubleAccessor (&LteUePhy::SetTxMode6Gain ),
203  MakeDoubleChecker<double> ())
204  .AddAttribute ("TxMode7Gain",
205  "Transmission mode 7 gain in dB",
206  DoubleValue (0.0),
207  MakeDoubleAccessor (&LteUePhy::SetTxMode7Gain ),
208  MakeDoubleChecker<double> ())
209  ;
210  return tid;
211 }
212 
213 void
215 {
216  NS_LOG_FUNCTION (this);
219  LtePhy::DoStart ();
220 }
221 
222 void
224 {
225  NS_LOG_FUNCTION (this);
226  m_uePhySapUser = s;
227 }
228 
231 {
232  NS_LOG_FUNCTION (this);
233  return (m_uePhySapProvider);
234 }
235 
236 void
238 {
239  NS_LOG_FUNCTION (this << nf);
240  m_noiseFigure = nf;
241 }
242 
243 double
245 {
246  NS_LOG_FUNCTION (this);
247  return m_noiseFigure;
248 }
249 
250 void
252 {
253  NS_LOG_FUNCTION (this << pow);
254  m_txPower = pow;
255 }
256 
257 double
259 {
260  NS_LOG_FUNCTION (this);
261  return m_txPower;
262 }
263 
264 
265 uint8_t
267 {
268  return (m_macChTtiDelay);
269 }
270 
271 void
273 {
274  NS_LOG_FUNCTION (this);
275 
276  SetMacPdu (p);
277 }
278 
279 
280 void
282 {
284 }
285 
286 void
288 {
289  NS_LOG_FUNCTION (this);
290 
291  /*
292  * XXX: the uplink scheduler is not implemented yet!
293  * Now, all uplink sub channels can be used for uplink transmission
294  */
296 }
297 
298 
299 void
301 {
302  NS_LOG_FUNCTION (this);
303 
305 
308 }
309 
310 
311 void
312 LteUePhy::SetSubChannelsForReception (std::vector <int> mask)
313 {
314  NS_LOG_FUNCTION (this);
316 }
317 
318 
319 std::vector <int>
321 {
322  NS_LOG_FUNCTION (this);
324 }
325 
326 
327 std::vector <int>
329 {
330  NS_LOG_FUNCTION (this);
332 }
333 
334 
337 {
338  NS_LOG_FUNCTION (this);
339  LteSpectrumValueHelper psdHelper;
341 
342  return psd;
343 }
344 
345 void
347 {
348  NS_LOG_FUNCTION (this);
349  // check periodic wideband CQI
351  {
356  }
357  // check aperiodic high-layer configured subband CQI
359  {
364  }
365 }
366 
367 
368 
371 {
372  NS_LOG_FUNCTION (this);
373 
374  // apply transmission mode gain
376  SpectrumValue newSinr = sinr;
377  newSinr *= m_txModeGain.at (m_transmissionMode);
378 // std::vector<int> cqi = m_amc->CreateCqiFeedbacks (newSinr);
379 
380 
381 
382  // CREATE DlCqiIdealControlMessage
383  Ptr<DlCqiIdealControlMessage> msg = Create<DlCqiIdealControlMessage> ();
384  CqiListElement_s dlcqi;
385  std::vector<int> cqi;
387  {
388  cqi = m_amc->CreateCqiFeedbacks (newSinr, m_dlBandwidth);
389 
391  int nbSubChannels = cqi.size ();
392  double cqiSum = 0.0;
393  int activeSubChannels = 0;
394  // average the CQIs of the different RBs
395  for (int i = 0; i < nbSubChannels; i++)
396  {
397  if (cqi.at (i) != -1)
398  {
399  cqiSum += cqi.at (i);
400  activeSubChannels++;
401  }
402  NS_LOG_DEBUG (this << " subch " << i << " cqi " << cqi.at (i));
403  }
404  dlcqi.m_rnti = m_rnti;
405  dlcqi.m_ri = 1; // not yet used
406  dlcqi.m_cqiType = CqiListElement_s::P10; // Peridic CQI using PUCCH wideband
407  NS_ASSERT_MSG (nLayer > 0, " nLayer negative");
408  NS_ASSERT_MSG (nLayer < 3, " nLayer limit is 2s");
409  for (int i = 0; i < nLayer; i++)
410  {
411  if (activeSubChannels > 0)
412  {
413  dlcqi.m_wbCqi.push_back ((uint16_t) cqiSum / activeSubChannels);
414  }
415  else
416  {
417  // approximate with the worst case -> CQI = 1
418  dlcqi.m_wbCqi.push_back (1);
419  }
420  }
421  //NS_LOG_DEBUG (this << " Generate P10 CQI feedback " << (uint16_t) cqiSum / activeSubChannels);
422  dlcqi.m_wbPmi = 0; // not yet used
423  // dl.cqi.m_sbMeasResult others CQI report modes: not yet implemented
424  }
426  {
427  cqi = m_amc->CreateCqiFeedbacks (newSinr, GetRbgSize ());
429  int nbSubChannels = cqi.size ();
430  int rbgSize = GetRbgSize ();
431  double cqiSum = 0.0;
432  int cqiNum = 0;
433  SbMeasResult_s rbgMeas;
434  //NS_LOG_DEBUG (this << " Create A30 CQI feedback, RBG " << rbgSize << " cqiNum " << nbSubChannels << " band " << (uint16_t)m_dlBandwidth);
435  for (int i = 0; i < nbSubChannels; i++)
436  {
437  if (cqi.at (i) != -1)
438  {
439  cqiSum += cqi.at (i);
440  }
441  // else "nothing" no CQI is treated as CQI = 0 (worst case scenario)
442  cqiNum++;
443  if (cqiNum == rbgSize)
444  {
445  // average the CQIs of the different RBGs
446  //NS_LOG_DEBUG (this << " RBG CQI " << (uint16_t) cqiSum / rbgSize);
447  HigherLayerSelected_s hlCqi;
448  hlCqi.m_sbPmi = 0; // not yet used
449  for (int i = 0; i < nLayer; i++)
450  {
451  hlCqi.m_sbCqi.push_back ((uint16_t) cqiSum / rbgSize);
452  }
453  rbgMeas.m_higherLayerSelected.push_back (hlCqi);
454  cqiSum = 0.0;
455  cqiNum = 0;
456  }
457  }
458  dlcqi.m_rnti = m_rnti;
459  dlcqi.m_ri = 1; // not yet used
460  dlcqi.m_cqiType = CqiListElement_s::A30; // Aperidic CQI using PUSCH
461  //dlcqi.m_wbCqi.push_back ((uint16_t) cqiSum / nbSubChannels);
462  dlcqi.m_wbPmi = 0; // not yet used
463  dlcqi.m_sbMeasResult = rbgMeas;
464  }
465 
466  msg->SetDlCqi (dlcqi);
467  return msg;
468 }
469 
470 
471 
472 void
474 {
475  NS_LOG_FUNCTION (this << msg);
477  Ptr<LteEnbNetDevice> remoteDevice = thisDevice->GetTargetEnb ();
478  msg->SetSourceDevice (thisDevice);
479  msg->SetDestinationDevice (remoteDevice);
480  SetControlMessages (msg);
481 }
482 
483 
484 void
486 {
487  NS_LOG_FUNCTION (this << msg);
488 
490  {
491  Ptr<DlDciIdealControlMessage> msg2 = DynamicCast<DlDciIdealControlMessage> (msg);
492 
493  DlDciListElement_s dci = msg2->GetDci ();
494 
495  if (dci.m_resAlloc != 0)
496  {
497  NS_FATAL_ERROR ("Resource Allocation type not implemented");
498  }
499 
500  std::vector <int> dlRb;
501 
502  // translate the DCI to Spectrum framework
503  uint32_t mask = 0x1;
504  for (int i = 0; i < 32; i++)
505  {
506  if (((dci.m_rbBitmap & mask) >> i) == 1)
507  {
508  for (int k = 0; k < GetRbgSize (); k++)
509  {
510  dlRb.push_back ((i * GetRbgSize ()) + k);
511  //NS_LOG_DEBUG(this << "DL-DCI allocated PRB " << (i*GetRbgSize()) + k);
512  }
513  }
514  mask = (mask << 1);
515  }
516 
517  // send TB info to LteSpectrumPhy
518  NS_LOG_DEBUG (this << " UE " << m_rnti << " DCI " << dci.m_rnti << " bitmap " << dci.m_rbBitmap);
519  for (uint8_t i = 0; i < dci.m_tbsSize.size (); i++)
520  {
521  m_downlinkSpectrumPhy->AddExpectedTb (dci.m_rnti, dci.m_tbsSize.at (i), dci.m_mcs.at (i), dlRb, i);
522  }
523 
525 
526 
527  }
528  else if (msg->GetMessageType () == IdealControlMessage::UL_DCI)
529  {
530  // set the uplink bandwidht according to the UL-CQI
531  NS_LOG_DEBUG (this << " UL DCI");
532  Ptr<UlDciIdealControlMessage> msg2 = DynamicCast<UlDciIdealControlMessage> (msg);
533  UlDciListElement_s dci = msg2->GetDci ();
534  std::vector <int> ulRb;
535  for (int i = 0; i < dci.m_rbLen; i++)
536  {
537  ulRb.push_back (i + dci.m_rbStart);
538  //NS_LOG_DEBUG (this << " UE RB " << i + dci.m_rbStart);
539  }
540 
542  // pass the info to the MAC
544  }
545  else
546  {
547  // pass the message to UE-MAC
549  }
550 
551 
552 }
553 
554 void
556 {
558 }
559 
560 
561 void
562 LteUePhy::SubframeIndication (uint32_t frameNo, uint32_t subframeNo)
563 {
564  // trigger from eNB
565 
566  // update uplink transmission mask according to previous UL-CQIs
568  // shift the queue
569  for (uint8_t i = 1; i < m_macChTtiDelay; i++)
570  {
572  }
573  m_subChannelsForTransmissionQueue.at (m_macChTtiDelay-1).clear ();
574 
575 
576  // send control messages
577  std::list<Ptr<IdealControlMessage> > ctrlMsg = GetControlMessages ();
578  if (ctrlMsg.size () > 0)
579  {
580  Ptr<LtePhy> phy = GetDevice ()->GetObject<LteUeNetDevice> ()->GetTargetEnb ()->GetPhy ();
581  std::list<Ptr<IdealControlMessage> >::iterator it;
582  it = ctrlMsg.begin ();
583  while (it != ctrlMsg.end ())
584  {
585  Ptr<IdealControlMessage> msg = (*it);
586  phy->ReceiveIdealControlMessage (msg);
587  ctrlMsg.pop_front ();
588  it = ctrlMsg.begin ();
589  }
590  }
591 
592  // send packets in queue
593  // send the current burts of packets
595  if (pb)
596  {
597  NS_LOG_LOGIC (this << " UE - start TX");
599  }
600 
601  // trigger the MAC
602  m_uePhySapUser->SubframeIndication (frameNo, subframeNo);
603 
604 }
605 
606 
607 void
608 LteUePhy::SetEnbCellId (uint16_t cellId)
609 {
610  m_enbCellId = cellId;
612  m_uplinkSpectrumPhy->SetCellId (cellId);
613 }
614 
615 
616 
617 void
618 LteUePhy::SetRnti (uint16_t rnti)
619 {
620  NS_LOG_FUNCTION (this << rnti);
621  m_rnti = rnti;
622 }
623 
624 
625 void
627 {
628  NS_LOG_FUNCTION (this << (uint16_t)txMode);
629  m_transmissionMode = txMode;
631 }
632 
633 
634 void
636 {
637  SetTxModeGain (1, gain);
638 }
639 
640 void
642 {
643  SetTxModeGain (2, gain);
644 }
645 
646 void
648 {
649  SetTxModeGain (3, gain);
650 }
651 
652 void
654 {
655  SetTxModeGain (4, gain);
656 }
657 
658 void
660 {
661  SetTxModeGain (5, gain);
662 }
663 
664 void
666 {
667  SetTxModeGain (6, gain);
668 }
669 
670 void
672 {
673  SetTxModeGain (7, gain);
674 }
675 
676 
677 void
678 LteUePhy::SetTxModeGain (uint8_t txMode, double gain)
679 {
680  NS_LOG_FUNCTION (this << gain);
681  // convert to linear
682  double gainLin = pow (10.0, (gain / 10.0));
683  if (m_txModeGain.size () < txMode)
684  {
685  m_txModeGain.resize (txMode);
686  }
687  std::vector <double> temp;
688  temp = m_txModeGain;
689  m_txModeGain.clear ();
690  for (uint8_t i = 0; i < temp.size (); i++)
691  {
692  if (i==txMode-1)
693  {
694  m_txModeGain.push_back (gainLin);
695  }
696  else
697  {
698  m_txModeGain.push_back (temp.at (i));
699  }
700  }
701  // forward the info to DL LteSpectrumPhy
702  m_downlinkSpectrumPhy->SetTxModeGain (txMode, gain);
703 }
704 
705 
706 
707 
708 } // namespace ns3