A Discrete-Event Network Simulator
API
lte-ue-mac.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Nicola Baldo <nbaldo@cttc.es>
19  * Author: Marco Miozzo <mmiozzo@cttc.es>
20  */
21 
22 
23 
24 #include <ns3/log.h>
25 #include <ns3/pointer.h>
26 #include <ns3/packet.h>
27 #include <ns3/packet-burst.h>
28 #include <ns3/random-variable-stream.h>
29 
30 #include "lte-ue-mac.h"
31 #include "lte-ue-net-device.h"
32 #include "lte-radio-bearer-tag.h"
33 #include <ns3/ff-mac-common.h>
34 #include <ns3/lte-control-messages.h>
35 #include <ns3/simulator.h>
36 #include <ns3/lte-common.h>
37 
38 
39 
40 namespace ns3 {
41 
42 NS_LOG_COMPONENT_DEFINE ("LteUeMac");
43 
45 
46 
48 // SAP forwarders
50 
53 {
54 public:
61 
62  // inherited from LteUeCmacSapProvider
63  virtual void ConfigureRach (RachConfig rc);
65  virtual void StartNonContentionBasedRandomAccessProcedure (uint16_t rnti, uint8_t preambleId, uint8_t prachMask);
66  virtual void SetRnti (uint16_t rnti);
67  virtual void AddLc (uint8_t lcId, LteUeCmacSapProvider::LogicalChannelConfig lcConfig, LteMacSapUser* msu);
68  virtual void RemoveLc (uint8_t lcId);
69  virtual void Reset ();
70  virtual void NotifyConnectionSuccessful ();
71  virtual void SetImsi (uint64_t imsi);
72 
73 private:
75 };
76 
77 
79  : m_mac (mac)
80 {
81 }
82 
83 void
85 {
86  m_mac->DoConfigureRach (rc);
87 }
88 
89  void
91 {
93 }
94 
95  void
96 UeMemberLteUeCmacSapProvider::StartNonContentionBasedRandomAccessProcedure (uint16_t rnti, uint8_t preambleId, uint8_t prachMask)
97 {
98  m_mac->DoStartNonContentionBasedRandomAccessProcedure (rnti, preambleId, prachMask);
99 }
100 
101  void
103  {
104  m_mac->DoSetRnti (rnti);
105  }
106 
107 void
109 {
110  m_mac->DoAddLc (lcId, lcConfig, msu);
111 }
112 
113 void
115 {
116  m_mac->DoRemoveLc (lcid);
117 }
118 
119 void
121 {
122  m_mac->DoReset ();
123 }
124 
125 void
127 {
129 }
130 
131 void
133  {
134  m_mac->DoSetImsi (imsi);
135  }
136 
137 
140 {
141 public:
148 
149  // inherited from LteMacSapProvider
150  virtual void TransmitPdu (TransmitPduParameters params);
151  virtual void ReportBufferStatus (ReportBufferStatusParameters params);
152 
153 private:
155 };
156 
157 
159  : m_mac (mac)
160 {
161 }
162 
163 void
165 {
166  m_mac->DoTransmitPdu (params);
167 }
168 
169 
170 void
172 {
173  m_mac->DoReportBufferStatus (params);
174 }
175 
176 
177 
182 {
183 public:
190 
191  // inherited from LtePhySapUser
192  virtual void ReceivePhyPdu (Ptr<Packet> p);
193  virtual void SubframeIndication (uint32_t frameNo, uint32_t subframeNo);
195 
196 private:
198 };
199 
201 {
202 
203 }
204 
205 void
207 {
208  m_mac->DoReceivePhyPdu (p);
209 }
210 
211 
212 void
213 UeMemberLteUePhySapUser::SubframeIndication (uint32_t frameNo, uint32_t subframeNo)
214 {
215  m_mac->DoSubframeIndication (frameNo, subframeNo);
216 }
217 
218 void
220 {
222 }
223 
224 
225 
226 
228 // LteUeMac methods
230 
231 
232 TypeId
234 {
235  static TypeId tid = TypeId ("ns3::LteUeMac")
236  .SetParent<Object> ()
237  .SetGroupName("Lte")
238  .AddConstructor<LteUeMac> ()
239  .AddTraceSource ("RaResponseTimeout",
240  "trace fired upon RA response timeout",
242  "ns3::LteUeMac::RaResponseTimeoutTracedCallback")
243 
244  ;
245  return tid;
246 }
247 
248 
250  : m_bsrPeriodicity (MilliSeconds (1)), // ideal behavior
251  m_bsrLast (MilliSeconds (0)),
252  m_freshUlBsr (false),
253  m_harqProcessId (0),
254  m_rnti (0),
255  m_imsi (0),
256  m_rachConfigured (false),
257  m_waitingForRaResponse (false)
258 
259 {
260  NS_LOG_FUNCTION (this);
262  for (uint8_t i = 0; i < m_miUlHarqProcessesPacket.size (); i++)
263  {
264  Ptr<PacketBurst> pb = CreateObject <PacketBurst> ();
265  m_miUlHarqProcessesPacket.at (i) = pb;
266  }
268 
272  m_raPreambleUniformVariable = CreateObject<UniformRandomVariable> ();
274 }
275 
276 
278 {
279  NS_LOG_FUNCTION (this);
280 }
281 
282 void
284 {
285  NS_LOG_FUNCTION (this);
286  m_miUlHarqProcessesPacket.clear ();
287  delete m_macSapProvider;
288  delete m_cmacSapProvider;
289  delete m_uePhySapUser;
291 }
292 
293 
296 {
297  return m_uePhySapUser;
298 }
299 
300 void
302 {
303  m_uePhySapProvider = s;
304 }
305 
306 
309 {
310  return m_macSapProvider;
311 }
312 
313 void
315 {
316  m_cmacSapUser = s;
317 }
318 
321 {
322  return m_cmacSapProvider;
323 }
324 
325 void
327 {
328  m_componentCarrierId = index;
329 }
330 
331 void
333 {
334  NS_LOG_FUNCTION (this);
335  NS_ASSERT_MSG (m_rnti == params.rnti, "RNTI mismatch between RLC and MAC");
336  LteRadioBearerTag tag (params.rnti, params.lcid, 0 /* UE works in SISO mode*/);
337  params.pdu->AddPacketTag (tag);
338  // store pdu in HARQ buffer
339  m_miUlHarqProcessesPacket.at (m_harqProcessId)->AddPacket (params.pdu);
342 }
343 
344 void
346 {
347  NS_LOG_FUNCTION (this << (uint32_t) params.lcid);
348 
349  std::map <uint8_t, LteMacSapProvider::ReportBufferStatusParameters>::iterator it;
350 
351 
352  it = m_ulBsrReceived.find (params.lcid);
353  if (it != m_ulBsrReceived.end ())
354  {
355  // update entry
356  (*it).second = params;
357  }
358  else
359  {
360  m_ulBsrReceived.insert (std::pair<uint8_t, LteMacSapProvider::ReportBufferStatusParameters> (params.lcid, params));
361  }
362  m_freshUlBsr = true;
363 }
364 
365 
366 void
368 {
369  NS_LOG_FUNCTION (this);
370 
371  if (m_rnti == 0)
372  {
373  NS_LOG_INFO ("MAC not initialized, BSR deferred");
374  return;
375  }
376 
377  if (m_ulBsrReceived.size () == 0)
378  {
379  NS_LOG_INFO ("No BSR report to transmit");
380  return;
381  }
382  MacCeListElement_s bsr;
383  bsr.m_rnti = m_rnti;
385 
386  // BSR is reported for each LCG
387  std::map <uint8_t, LteMacSapProvider::ReportBufferStatusParameters>::iterator it;
388  std::vector<uint32_t> queue (4, 0); // one value per each of the 4 LCGs, initialized to 0
389  for (it = m_ulBsrReceived.begin (); it != m_ulBsrReceived.end (); it++)
390  {
391  uint8_t lcid = it->first;
392  std::map <uint8_t, LcInfo>::iterator lcInfoMapIt;
393  lcInfoMapIt = m_lcInfoMap.find (lcid);
394  NS_ASSERT (lcInfoMapIt != m_lcInfoMap.end ());
395  NS_ASSERT_MSG ((lcid != 0) || (((*it).second.txQueueSize == 0)
396  && ((*it).second.retxQueueSize == 0)
397  && ((*it).second.statusPduSize == 0)),
398  "BSR should not be used for LCID 0");
399  uint8_t lcg = lcInfoMapIt->second.lcConfig.logicalChannelGroup;
400  queue.at (lcg) += ((*it).second.txQueueSize + (*it).second.retxQueueSize + (*it).second.statusPduSize);
401  }
402 
403  // FF API says that all 4 LCGs are always present
408 
409  // create the feedback to eNB
410  Ptr<BsrLteControlMessage> msg = Create<BsrLteControlMessage> ();
411  msg->SetBsr (bsr);
413 
414 }
415 
416 void
418 {
419  NS_LOG_FUNCTION (this);
420  // 3GPP 36.321 5.1.1
421  NS_ASSERT_MSG (m_rachConfigured, "RACH not configured");
422  // assume that there is no Random Access Preambles group B
424  bool contention = true;
425  SendRaPreamble (contention);
426 }
427 
428 void
429 LteUeMac::SendRaPreamble (bool contention)
430 {
431  NS_LOG_FUNCTION (this << (uint32_t) m_raPreambleId << contention);
432  // Since regular UL LteControlMessages need m_ulConfigured = true in
433  // order to be sent by the UE, the rach preamble needs to be sent
434  // with a dedicated primitive (not
435  // m_uePhySapProvider->SendLteControlMessage (msg)) so that it can
436  // bypass the m_ulConfigured flag. This is reasonable, since In fact
437  // the RACH preamble is sent on 6RB bandwidth so the uplink
438  // bandwidth does not need to be configured.
439  NS_ASSERT (m_subframeNo > 0); // sanity check for subframe starting at 1
440  m_raRnti = m_subframeNo - 1;
442  NS_LOG_INFO (this << " sent preamble id " << (uint32_t) m_raPreambleId << ", RA-RNTI " << (uint32_t) m_raRnti);
443  // 3GPP 36.321 5.1.4
444  Time raWindowBegin = MilliSeconds (3);
448 }
449 
450 void
452 {
453  NS_LOG_FUNCTION (this);
454  m_waitingForRaResponse = true;
455 }
456 
457 void
459 {
460  NS_LOG_FUNCTION (this);
461  m_waitingForRaResponse = false;
463  NS_LOG_INFO ("got RAR for RAPID " << (uint32_t) m_raPreambleId << ", setting T-C-RNTI = " << raResponse.m_rnti);
464  m_rnti = raResponse.m_rnti;
466  // in principle we should wait for contention resolution,
467  // but in the current LTE model when two or more identical
468  // preambles are sent no one is received, so there is no need
469  // for contention resolution
471  // trigger tx opportunity for Message 3 over LC 0
472  // this is needed since Message 3's UL GRANT is in the RAR, not in UL-DCIs
473  const uint8_t lc0Lcid = 0;
474  std::map <uint8_t, LcInfo>::iterator lc0InfoIt = m_lcInfoMap.find (lc0Lcid);
475  NS_ASSERT (lc0InfoIt != m_lcInfoMap.end ());
476  std::map <uint8_t, LteMacSapProvider::ReportBufferStatusParameters>::iterator lc0BsrIt
477  = m_ulBsrReceived.find (lc0Lcid);
478  if ((lc0BsrIt != m_ulBsrReceived.end ())
479  && (lc0BsrIt->second.txQueueSize > 0))
480  {
481  NS_ASSERT_MSG (raResponse.m_grant.m_tbSize > lc0BsrIt->second.txQueueSize,
482  "segmentation of Message 3 is not allowed");
483  // this function can be called only from primary carrier
484  if (m_componentCarrierId > 0)
485  {
486  NS_FATAL_ERROR ("Function called on wrong componentCarrier");
487  }
489  txOpParams.bytes = raResponse.m_grant.m_tbSize;
490  txOpParams.layer = 0;
491  txOpParams.harqId = 0;
493  txOpParams.rnti = m_rnti;
494  txOpParams.lcid = lc0Lcid;
495  lc0InfoIt->second.macSapUser->NotifyTxOpportunity (txOpParams);
496  lc0BsrIt->second.txQueueSize = 0;
497  }
498 }
499 
500 void
502 {
503  NS_LOG_FUNCTION (this << contention);
504  m_waitingForRaResponse = false;
505  // 3GPP 36.321 5.1.4
507  //fire RA response timeout trace
511  {
512  NS_LOG_INFO ("RAR timeout, preambleTransMax reached => giving up");
514  }
515  else
516  {
517  NS_LOG_INFO ("RAR timeout, re-send preamble");
518  if (contention)
519  {
521  }
522  else
523  {
524  SendRaPreamble (contention);
525  }
526  }
527 }
528 
529 void
531 {
532  NS_LOG_FUNCTION (this);
533  m_rachConfig = rc;
534  m_rachConfigured = true;
535 }
536 
537 void
539 {
540  NS_LOG_FUNCTION (this);
541 
542  // 3GPP 36.321 5.1.1
543  NS_ASSERT_MSG (m_rachConfigured, "RACH not configured");
545  m_backoffParameter = 0;
547 }
548 
549 void
550 LteUeMac::DoSetRnti (uint16_t rnti)
551 {
552  NS_LOG_FUNCTION (this);
553  m_rnti = rnti;
554 }
555 
556 void
557 LteUeMac::DoSetImsi (uint64_t imsi)
558 {
559  NS_LOG_FUNCTION (this);
560  m_imsi = imsi;
561 }
562 
563 
564 void
565 LteUeMac::DoStartNonContentionBasedRandomAccessProcedure (uint16_t rnti, uint8_t preambleId, uint8_t prachMask)
566 {
567  NS_LOG_FUNCTION (this << rnti << (uint16_t) preambleId << (uint16_t) prachMask);
568  NS_ASSERT_MSG (prachMask == 0, "requested PRACH MASK = " << (uint32_t) prachMask << ", but only PRACH MASK = 0 is supported");
569  m_rnti = rnti;
570  m_raPreambleId = preambleId;
572  bool contention = false;
573  SendRaPreamble (contention);
574 }
575 
576 void
578 {
579  NS_LOG_FUNCTION (this << " lcId" << (uint32_t) lcId);
580  NS_ASSERT_MSG (m_lcInfoMap.find (lcId) == m_lcInfoMap.end (), "cannot add channel because LCID " << (uint16_t)lcId << " is already present");
581 
582  LcInfo lcInfo;
583  lcInfo.lcConfig = lcConfig;
584  lcInfo.macSapUser = msu;
585  m_lcInfoMap[lcId] = lcInfo;
586 }
587 
588 void
589 LteUeMac::DoRemoveLc (uint8_t lcId)
590 {
591  NS_LOG_FUNCTION (this << " lcId" << lcId);
592  NS_ASSERT_MSG (m_lcInfoMap.find (lcId) != m_lcInfoMap.end (), "could not find LCID " << lcId);
593  m_lcInfoMap.erase (lcId);
594 }
595 
596 void
598 {
599  NS_LOG_FUNCTION (this);
600  std::map <uint8_t, LcInfo>::iterator it = m_lcInfoMap.begin ();
601  while (it != m_lcInfoMap.end ())
602  {
603  // don't delete CCCH)
604  if (it->first == 0)
605  {
606  ++it;
607  }
608  else
609  {
610  // note: use of postfix operator preserves validity of iterator
611  m_lcInfoMap.erase (it++);
612  }
613  }
614  // note: rnti will be assigned by the eNB using RA response message
615  m_rnti = 0;
617  m_rachConfigured = false;
618  m_freshUlBsr = false;
619  m_ulBsrReceived.clear ();
620 }
621 
622 void
624 {
625  NS_LOG_FUNCTION (this);
627 }
628 
629 void
631 {
632  LteRadioBearerTag tag;
633  p->RemovePacketTag (tag);
634  if (tag.GetRnti () == m_rnti)
635  {
636  // packet is for the current user
637  std::map <uint8_t, LcInfo>::const_iterator it = m_lcInfoMap.find (tag.GetLcid ());
638  if (it != m_lcInfoMap.end ())
639  {
641  rxPduParams.p = p;
642  rxPduParams.rnti = m_rnti;
643  rxPduParams.lcid = tag.GetLcid ();
644  it->second.macSapUser->ReceivePdu (rxPduParams);
645  }
646  else
647  {
648  NS_LOG_WARN ("received packet with unknown lcid " << (uint32_t) tag.GetLcid ());
649  }
650  }
651 }
652 
653 
654 void
656 {
657  NS_LOG_FUNCTION (this);
658  if (msg->GetMessageType () == LteControlMessage::UL_DCI)
659  {
660  Ptr<UlDciLteControlMessage> msg2 = DynamicCast<UlDciLteControlMessage> (msg);
661  UlDciListElement_s dci = msg2->GetDci ();
662  if (dci.m_ndi == 1)
663  {
664  // New transmission -> empty pkt buffer queue (for deleting eventual pkts not acked )
665  Ptr<PacketBurst> pb = CreateObject <PacketBurst> ();
667  // Retrieve data from RLC
668  std::map <uint8_t, LteMacSapProvider::ReportBufferStatusParameters>::iterator itBsr;
669  uint16_t activeLcs = 0;
670  uint32_t statusPduMinSize = 0;
671  for (itBsr = m_ulBsrReceived.begin (); itBsr != m_ulBsrReceived.end (); itBsr++)
672  {
673  if (((*itBsr).second.statusPduSize > 0) || ((*itBsr).second.retxQueueSize > 0) || ((*itBsr).second.txQueueSize > 0))
674  {
675  activeLcs++;
676  if (((*itBsr).second.statusPduSize != 0)&&((*itBsr).second.statusPduSize < statusPduMinSize))
677  {
678  statusPduMinSize = (*itBsr).second.statusPduSize;
679  }
680  if (((*itBsr).second.statusPduSize != 0)&&(statusPduMinSize == 0))
681  {
682  statusPduMinSize = (*itBsr).second.statusPduSize;
683  }
684  }
685  }
686  if (activeLcs == 0)
687  {
688  NS_LOG_ERROR (this << " No active flows for this UL-DCI");
689  return;
690  }
691  std::map <uint8_t, LcInfo>::iterator it;
692  uint32_t bytesPerActiveLc = dci.m_tbSize / activeLcs;
693  bool statusPduPriority = false;
694  if ((statusPduMinSize != 0)&&(bytesPerActiveLc < statusPduMinSize))
695  {
696  // send only the status PDU which has highest priority
697  statusPduPriority = true;
698  NS_LOG_DEBUG (this << " Reduced resource -> send only Status, b ytes " << statusPduMinSize);
699  if (dci.m_tbSize < statusPduMinSize)
700  {
701  NS_FATAL_ERROR ("Insufficient Tx Opportunity for sending a status message");
702  }
703  }
704  NS_LOG_LOGIC (this << " UE " << m_rnti << ": UL-CQI notified TxOpportunity of " << dci.m_tbSize << " => " << bytesPerActiveLc << " bytes per active LC" << " statusPduMinSize " << statusPduMinSize);
705 
707 
708  for (it = m_lcInfoMap.begin (); it != m_lcInfoMap.end (); it++)
709  {
710  itBsr = m_ulBsrReceived.find ((*it).first);
711  NS_LOG_DEBUG (this << " Processing LC " << (uint32_t)(*it).first << " bytesPerActiveLc " << bytesPerActiveLc);
712  if ( (itBsr != m_ulBsrReceived.end ())
713  && ( ((*itBsr).second.statusPduSize > 0)
714  || ((*itBsr).second.retxQueueSize > 0)
715  || ((*itBsr).second.txQueueSize > 0)) )
716  {
717  if ((statusPduPriority) && ((*itBsr).second.statusPduSize == statusPduMinSize))
718  {
719  txOpParams.bytes = (*itBsr).second.statusPduSize;
720  txOpParams.layer = 0;
721  txOpParams.harqId = 0;
723  txOpParams.rnti = m_rnti;
724  txOpParams.lcid = (*it).first;
725  (*it).second.macSapUser->NotifyTxOpportunity (txOpParams);
726  NS_LOG_LOGIC (this << "\t" << bytesPerActiveLc << " send " << (*itBsr).second.statusPduSize << " status bytes to LC " << (uint32_t)(*it).first << " statusQueue " << (*itBsr).second.statusPduSize << " retxQueue" << (*itBsr).second.retxQueueSize << " txQueue" << (*itBsr).second.txQueueSize);
727  (*itBsr).second.statusPduSize = 0;
728  break;
729  }
730  else
731  {
732  uint32_t bytesForThisLc = bytesPerActiveLc;
733  NS_LOG_LOGIC (this << "\t" << bytesPerActiveLc << " bytes to LC " << (uint32_t)(*it).first << " statusQueue " << (*itBsr).second.statusPduSize << " retxQueue" << (*itBsr).second.retxQueueSize << " txQueue" << (*itBsr).second.txQueueSize);
734  if (((*itBsr).second.statusPduSize > 0) && (bytesForThisLc > (*itBsr).second.statusPduSize))
735  {
736  txOpParams.bytes = (*itBsr).second.statusPduSize;
737  txOpParams.layer = 0;
738  txOpParams.harqId = 0;
740  txOpParams.rnti = m_rnti;
741  txOpParams.lcid = (*it).first;
742  (*it).second.macSapUser->NotifyTxOpportunity (txOpParams);
743  bytesForThisLc -= (*itBsr).second.statusPduSize;
744  NS_LOG_DEBUG (this << " serve STATUS " << (*itBsr).second.statusPduSize);
745  (*itBsr).second.statusPduSize = 0;
746  }
747  else
748  {
749  if ((*itBsr).second.statusPduSize > bytesForThisLc)
750  {
751  NS_FATAL_ERROR ("Insufficient Tx Opportunity for sending a status message");
752  }
753  }
754 
755  if ((bytesForThisLc > 7) // 7 is the min TxOpportunity useful for Rlc
756  && (((*itBsr).second.retxQueueSize > 0)
757  || ((*itBsr).second.txQueueSize > 0)))
758  {
759  if ((*itBsr).second.retxQueueSize > 0)
760  {
761  NS_LOG_DEBUG (this << " serve retx DATA, bytes " << bytesForThisLc);
762  txOpParams.bytes = bytesForThisLc;
763  txOpParams.layer = 0;
764  txOpParams.harqId = 0;
766  txOpParams.rnti = m_rnti;
767  txOpParams.lcid = (*it).first;
768  (*it).second.macSapUser->NotifyTxOpportunity (txOpParams);
769  if ((*itBsr).second.retxQueueSize >= bytesForThisLc)
770  {
771  (*itBsr).second.retxQueueSize -= bytesForThisLc;
772  }
773  else
774  {
775  (*itBsr).second.retxQueueSize = 0;
776  }
777  }
778  else if ((*itBsr).second.txQueueSize > 0)
779  {
780  uint16_t lcid = (*it).first;
781  uint32_t rlcOverhead;
782  if (lcid == 1)
783  {
784  // for SRB1 (using RLC AM) it's better to
785  // overestimate RLC overhead rather than
786  // underestimate it and risk unneeded
787  // segmentation which increases delay
788  rlcOverhead = 4;
789  }
790  else
791  {
792  // minimum RLC overhead due to header
793  rlcOverhead = 2;
794  }
795  NS_LOG_DEBUG (this << " serve tx DATA, bytes " << bytesForThisLc << ", RLC overhead " << rlcOverhead);
796  txOpParams.bytes = bytesForThisLc;
797  txOpParams.layer = 0;
798  txOpParams.harqId = 0;
800  txOpParams.rnti = m_rnti;
801  txOpParams.lcid = (*it).first;
802  (*it).second.macSapUser->NotifyTxOpportunity (txOpParams);
803  if ((*itBsr).second.txQueueSize >= bytesForThisLc - rlcOverhead)
804  {
805  (*itBsr).second.txQueueSize -= bytesForThisLc - rlcOverhead;
806  }
807  else
808  {
809  (*itBsr).second.txQueueSize = 0;
810  }
811  }
812  }
813  else
814  {
815  if ( ((*itBsr).second.retxQueueSize > 0) || ((*itBsr).second.txQueueSize > 0))
816  {
817  // resend BSR info for updating eNB peer MAC
818  m_freshUlBsr = true;
819  }
820  }
821  NS_LOG_LOGIC (this << "\t" << bytesPerActiveLc << "\t new queues " << (uint32_t)(*it).first << " statusQueue " << (*itBsr).second.statusPduSize << " retxQueue" << (*itBsr).second.retxQueueSize << " txQueue" << (*itBsr).second.txQueueSize);
822  }
823 
824  }
825  }
826  }
827  else
828  {
829  // HARQ retransmission -> retrieve data from HARQ buffer
830  NS_LOG_DEBUG (this << " UE MAC RETX HARQ " << (uint16_t)m_harqProcessId);
832  for (std::list<Ptr<Packet> >::const_iterator j = pb->Begin (); j != pb->End (); ++j)
833  {
834  Ptr<Packet> pkt = (*j)->Copy ();
836  }
838  }
839 
840  }
841  else if (msg->GetMessageType () == LteControlMessage::RAR)
842  {
844  {
845  Ptr<RarLteControlMessage> rarMsg = DynamicCast<RarLteControlMessage> (msg);
846  uint16_t raRnti = rarMsg->GetRaRnti ();
847  NS_LOG_LOGIC (this << "got RAR with RA-RNTI " << (uint32_t) raRnti << ", expecting " << (uint32_t) m_raRnti);
848  if (raRnti == m_raRnti) // RAR corresponds to TX subframe of preamble
849  {
850  for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin ();
851  it != rarMsg->RarListEnd ();
852  ++it)
853  {
854  if (it->rapId == m_raPreambleId) // RAR is for me
855  {
856  RecvRaResponse (it->rarPayload);
860  }
861  }
862  }
863  }
864  }
865  else
866  {
867  NS_LOG_WARN (this << " LteControlMessage not recognized");
868  }
869 }
870 
871 void
873 {
874  NS_LOG_FUNCTION (this);
875 
876  for (uint16_t i = 0; i < m_miUlHarqProcessesPacketTimer.size (); i++)
877  {
878  if (m_miUlHarqProcessesPacketTimer.at (i) == 0)
879  {
880  if (m_miUlHarqProcessesPacket.at (i)->GetSize () > 0)
881  {
882  // timer expired: drop packets in buffer for this process
883  NS_LOG_INFO (this << " HARQ Proc Id " << i << " packets buffer expired");
884  Ptr<PacketBurst> emptyPb = CreateObject <PacketBurst> ();
885  m_miUlHarqProcessesPacket.at (i) = emptyPb;
886  }
887  }
888  else
889  {
891  }
892  }
893 }
894 
895 
896 void
897 LteUeMac::DoSubframeIndication (uint32_t frameNo, uint32_t subframeNo)
898 {
899  NS_LOG_FUNCTION (this);
900  m_frameNo = frameNo;
901  m_subframeNo = subframeNo;
903  if ((Simulator::Now () >= m_bsrLast + m_bsrPeriodicity) && (m_freshUlBsr == true))
904  {
905  if (m_componentCarrierId == 0)
906  {
907  //Send BSR through primary carrier
909  }
911  m_freshUlBsr = false;
912  }
914 
915 }
916 
917 int64_t
918 LteUeMac::AssignStreams (int64_t stream)
919 {
920  NS_LOG_FUNCTION (this << stream);
922  return 1;
923 }
924 
925 } // namespace ns3
uint8_t numberOfRaPreambles
number of RA preambles
virtual void AddLc(uint8_t lcId, LteUeCmacSapProvider::LogicalChannelConfig lcConfig, LteMacSapUser *msu)
add a new Logical Channel (LC)
Definition: lte-ue-mac.cc:108
void DoStartNonContentionBasedRandomAccessProcedure(uint16_t rnti, uint8_t rapId, uint8_t prachMask)
Start non contention based random access procedure function.
Definition: lte-ue-mac.cc:565
LteUeCmacSapProvider::LogicalChannelConfig lcConfig
logical channel config
Definition: lte-ue-mac.h:249
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void DoReset()
Reset function.
Definition: lte-ue-mac.cc:597
uint8_t m_raPreambleId
RA preamble ID.
Definition: lte-ue-mac.h:280
uint8_t raResponseWindowSize
RA response window size.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
virtual void TransmitPdu(TransmitPduParameters params)
send an RLC PDU to the MAC for transmission.
Definition: lte-ue-mac.cc:164
Parameters for LteMacSapUser::NotifyTxOpportunity.
Definition: lte-mac-sap.h:103
#define HARQ_PERIOD
Definition: lte-common.h:30
void SendRaPreamble(bool contention)
Send RA preamble function.
Definition: lte-ue-mac.cc:429
void StartWaitingForRaResponse()
Start waiting for RA response function.
Definition: lte-ue-mac.cc:451
uint32_t GetInteger(uint32_t min, uint32_t max)
Get the next random value, as an unsigned integer in the specified range .
void DoReceivePhyPdu(Ptr< Packet > p)
Receive Phy PDU function.
Definition: lte-ue-mac.cc:630
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Ptr< UniformRandomVariable > m_raPreambleUniformVariable
RA preamble random variable.
Definition: lte-ue-mac.h:284
LteUePhySapUser * m_uePhySapUser
UE Phy SAP user.
Definition: lte-ue-mac.h:261
void DoSetRnti(uint16_t rnti)
Set RNTI.
Definition: lte-ue-mac.cc:550
UeMemberLteMacSapProvider class.
Definition: lte-ue-mac.cc:139
uint16_t m_imsi
IMSI.
Definition: lte-ue-mac.h:276
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
void RaResponseTimeout(bool contention)
RA response timeout function.
Definition: lte-ue-mac.cc:501
See section 4.3.2 ulDciListElement.
virtual void ReportBufferStatus(ReportBufferStatusParameters params)
Report the RLC buffer status to the MAC.
Definition: lte-ue-mac.cc:171
struct MacCeValue_u m_macCeValue
MAC CE value.
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-mac-sap.h:133
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
See section 4.3.10 buildRARListElement.
void DoAddLc(uint8_t lcId, LteUeCmacSapProvider::LogicalChannelConfig lcConfig, LteMacSapUser *msu)
Add LC function.
Definition: lte-ue-mac.cc:577
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
void SetLteUePhySapProvider(LteUePhySapProvider *s)
Set the PHY SAP Provider.
Definition: lte-ue-mac.cc:301
virtual void SendRachPreamble(uint32_t prachId, uint32_t raRnti)=0
Send a preamble on the PRACH.
LteMacSapUser * macSapUser
MAC SAP user.
Definition: lte-ue-mac.h:250
Service Access Point (SAP) offered by the PHY to the MAC.
UeMemberLteUeCmacSapProvider class.
Definition: lte-ue-mac.cc:52
uint8_t lcid
the logical channel id corresponding to the sending RLC instance
Definition: lte-mac-sap.h:49
void DoStartContentionBasedRandomAccessProcedure()
Start contention based random access procedure function.
Definition: lte-ue-mac.cc:538
void SendReportBufferStatus(void)
Send report buffer status.
Definition: lte-ue-mac.cc:367
virtual void NotifyConnectionSuccessful()=0
Notify PHY about the successful RRC connection establishment.
virtual void SubframeIndication(uint32_t frameNo, uint32_t subframeNo)
Trigger the start from a new frame (input from Phy layer)
Definition: lte-ue-mac.cc:213
virtual ~LteUeMac()
Definition: lte-ue-mac.cc:277
uint16_t m_tbSize
size
virtual void StartContentionBasedRandomAccessProcedure()
tell the MAC to start a contention-based random access procedure, e.g., to perform RRC connection est...
Definition: lte-ue-mac.cc:90
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void DoRemoveLc(uint8_t lcId)
Remove LC function.
Definition: lte-ue-mac.cc:589
Parameters for LteMacSapProvider::ReportBufferStatus.
Definition: lte-mac-sap.h:67
uint8_t lcid
the logical channel id
Definition: lte-mac-sap.h:177
std::vector< uint8_t > m_miUlHarqProcessesPacketTimer
timer for packet life in the buffer
Definition: lte-ue-mac.h:273
friend class UeMemberLteUePhySapUser
allow UeMemberLteUePhySapUser class friend access
Definition: lte-ue-mac.h:51
uint8_t lcid
the logical channel id
Definition: lte-mac-sap.h:134
void SetLteUeCmacSapUser(LteUeCmacSapUser *s)
Set the LTE UE CMAC SAP user.
Definition: lte-ue-mac.cc:314
void DoTransmitPdu(LteMacSapProvider::TransmitPduParameters params)
Transmit PDU function.
Definition: lte-ue-mac.cc:332
virtual void ConfigureRach(RachConfig rc)
Configure RACH function.
Definition: lte-ue-mac.cc:84
virtual void SetTemporaryCellRnti(uint16_t rnti)=0
friend class UeMemberLteMacSapProvider
allow UeMemberLteMacSapProvider class friend access
Definition: lte-ue-mac.h:49
uint8_t preambleTransMax
preamble transmit maximum
uint16_t GetRnti(void) const
Get RNTI function.
uint8_t m_harqProcessId
HARQ process ID.
Definition: lte-ue-mac.h:271
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1390
static uint8_t BufferSize2BsrId(uint32_t val)
Convert Buffer size to BSR ID.
Definition: lte-common.cc:191
virtual void Reset()
reset the MAC
Definition: lte-ue-mac.cc:120
LteUeMac * m_mac
the UE MAC
Definition: lte-ue-mac.cc:154
uint32_t m_frameNo
frame number
Definition: lte-ue-mac.h:286
bool m_waitingForRaResponse
waiting for RA response
Definition: lte-ue-mac.h:289
void DoReportBufferStatus(LteMacSapProvider::ReportBufferStatusParameters params)
Report buffers status function.
Definition: lte-ue-mac.cc:345
virtual void StartNonContentionBasedRandomAccessProcedure(uint16_t rnti, uint8_t preambleId, uint8_t prachMask)
tell the MAC to start a non-contention-based random access procedure, e.g., as a consequence of hando...
Definition: lte-ue-mac.cc:96
virtual void SendMacPdu(Ptr< Packet > p)=0
Send the MAC PDU to the channel.
uint16_t m_rnti
RNTI.
Definition: lte-ue-mac.h:275
LteUeCmacSapProvider * m_cmacSapProvider
CMAC SAP provider.
Definition: lte-ue-mac.h:258
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-mac-sap.h:48
mac
Definition: third.py:99
virtual void NotifyConnectionSuccessful()
Notify MAC about the successful RRC connection establishment.
Definition: lte-ue-mac.cc:126
uint8_t componentCarrierId
the component carrier id
Definition: lte-mac-sap.h:132
uint8_t m_raRnti
RA RNTI.
Definition: lte-ue-mac.h:288
std::vector< Ptr< PacketBurst > > m_miUlHarqProcessesPacket
Packets under transmission of the UL HARQ processes.
Definition: lte-ue-mac.h:272
LteUeCmacSapProvider * GetLteUeCmacSapProvider(void)
Get the LTE CMAC SAP provider.
Definition: lte-ue-mac.cc:320
void DoSetImsi(uint64_t imsi)
Set IMSI.
Definition: lte-ue-mac.cc:557
Service Access Point (SAP) offered by the UE MAC to the UE RRC.
void SetComponentCarrierId(uint8_t index)
Set the component carried ID.
Definition: lte-ue-mac.cc:326
void DoConfigureRach(LteUeCmacSapProvider::RachConfig rc)
Configure RACH function.
Definition: lte-ue-mac.cc:530
#define list
virtual void NotifyRandomAccessSuccessful()=0
Notify the RRC that the MAC Random Access procedure completed successfully.
See section 4.3.14 macCEListElement.
void DoSubframeIndication(uint32_t frameNo, uint32_t subframeNo)
Forwarded from LteUePhySapUser: trigger the start from a new frame.
Definition: lte-ue-mac.cc:897
UeMemberLteUeCmacSapProvider(LteUeMac *mac)
Constructor.
Definition: lte-ue-mac.cc:78
void DoReceiveLteControlMessage(Ptr< LteControlMessage > msg)
Receive LTE control message function.
Definition: lte-ue-mac.cc:655
std::map< uint8_t, LcInfo > m_lcInfoMap
logical channel info map
Definition: lte-ue-mac.h:253
virtual void SendLteControlMessage(Ptr< LteControlMessage > msg)=0
Send SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
LteUePhySapUser * GetLteUePhySapUser()
Get the PHY SAP user.
Definition: lte-ue-mac.cc:295
Every class exported by the ns3 library is enclosed in the ns3 namespace.
LteMacSapProvider * GetLteMacSapProvider(void)
Get the LTE MAC SAP provider.
Definition: lte-ue-mac.cc:308
uint16_t m_backoffParameter
backoff parameter
Definition: lte-ue-mac.h:282
static TypeId GetTypeId(void)
Get the type ID.
Definition: lte-ue-mac.cc:233
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
UeMemberLteUePhySapUser(LteUeMac *mac)
Constructor.
Definition: lte-ue-mac.cc:200
LteMacSapProvider * m_macSapProvider
MAC SAP provider.
Definition: lte-ue-mac.h:255
Service Access Point (SAP) offered by the UE MAC to the UE RRC.
uint8_t lcid
the logical channel id corresponding to the sending RLC instance
Definition: lte-mac-sap.h:70
virtual void ReceivePhyPdu(Ptr< Packet > p)
Receive Phy Pdu funtion.
Definition: lte-ue-mac.cc:206
LteUePhySapProvider * m_uePhySapProvider
UE Phy SAP provider.
Definition: lte-ue-mac.h:260
uint8_t m_componentCarrierId
component carrier Id –> used to address sap
Definition: lte-ue-mac.h:242
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
Time m_bsrLast
BSR last.
Definition: lte-ue-mac.h:267
bool m_freshUlBsr
true when a BSR has been received in the last TTI
Definition: lte-ue-mac.h:269
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
virtual void RemoveLc(uint8_t lcId)
remove an existing LC
Definition: lte-ue-mac.cc:114
virtual void SetRnti(uint16_t rnti)
Definition: lte-ue-mac.cc:102
std::vector< uint8_t > m_bufferStatus
buffer status
virtual void NotifyRandomAccessFailed()=0
Notify the RRC that the MAC Random Access procedure failed.
void RandomlySelectAndSendRaPreamble()
Randomly select and send RA preamble function.
Definition: lte-ue-mac.cc:417
void RecvRaResponse(BuildRarListElement_s raResponse)
Receive the RA response function.
Definition: lte-ue-mac.cc:458
uint32_t bytes
the number of bytes to transmit
Definition: lte-mac-sap.h:129
uint8_t m_preambleTransmissionCounter
preamble tranamission counter
Definition: lte-ue-mac.h:281
uint8_t GetLcid(void) const
Get LCID function.
uint8_t layer
the layer of transmission (MIMO)
Definition: lte-mac-sap.h:130
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:863
Service Access Point (SAP) offered by the MAC to the RLC See Femto Forum MAC Scheduler Interface Spec...
Definition: lte-mac-sap.h:95
EventId m_noRaResponseReceivedEvent
no RA response received event ID
Definition: lte-ue-mac.h:283
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
bool m_rachConfigured
is RACH configured?
Definition: lte-ue-mac.h:278
virtual void DoDispose(void)
Destructor implementation.
Definition: lte-ue-mac.cc:283
LteUeCmacSapProvider::RachConfig m_rachConfig
RACH configuration.
Definition: lte-ue-mac.h:279
Service Access Point (SAP) offered by the UE-PHY to the UE-MAC.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:870
void DoNotifyConnectionSuccessful()
Notify MAC about the successful RRC connection establishment.
Definition: lte-ue-mac.cc:623
LteUeMac * m_mac
the UE MAC
Definition: lte-ue-mac.cc:197
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
LteUeMac * m_mac
the UE MAC
Definition: lte-ue-mac.cc:74
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
Service Access Point (SAP) offered by the MAC to the RLC See Femto Forum MAC Scheduler Interface Spec...
Definition: lte-mac-sap.h:36
LcInfo structure.
Definition: lte-ue-mac.h:247
Tag used to define the RNTI and LC id for each MAC packet trasmitted.
enum ns3::MacCeListElement_s::MacCeType_e m_macCeType
MAC CE type.
Parameters for LteMacSapUser::ReceivePdu.
Definition: lte-mac-sap.h:156
uint16_t rnti
the C-RNTI identifying the UE
Definition: lte-mac-sap.h:176
Time m_bsrPeriodicity
BSR periodicity.
Definition: lte-ue-mac.h:266
virtual void ReceiveLteControlMessage(Ptr< LteControlMessage > msg)
Receive SendLteControlMessage (PDCCH map, CQI feedbacks) using the ideal control channel.
Definition: lte-ue-mac.cc:219
UeMemberLteUePhySapUser.
Definition: lte-ue-mac.cc:181
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
uint32_t m_subframeNo
subframe number
Definition: lte-ue-mac.h:287
std::map< uint8_t, LteMacSapProvider::ReportBufferStatusParameters > m_ulBsrReceived
BSR received from RLC (the last one)
Definition: lte-ue-mac.h:263
A base class which provides memory management and object aggregation.
Definition: object.h:87
friend class UeMemberLteUeCmacSapProvider
allow UeMemberLteUeCmacSapProvider class friend access
Definition: lte-ue-mac.h:47
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: lte-ue-mac.cc:918
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
void RefreshHarqProcessesPacketBuffer(void)
Refresh HARQ processes packet buffer function.
Definition: lte-ue-mac.cc:872
TracedCallback< uint64_t, bool, uint8_t, uint8_t > m_raResponseTimeoutTrace
The RaResponseTimeout trace source.
Definition: lte-ue-mac.h:296
virtual void SetImsi(uint64_t imsi)
A method call by UE RRC to communicate the IMSI to the UE MAC.
Definition: lte-ue-mac.cc:132
UeMemberLteMacSapProvider(LteUeMac *mac)
Constructor.
Definition: lte-ue-mac.cc:158
LteUeCmacSapUser * m_cmacSapUser
CMAC SAP user.
Definition: lte-ue-mac.h:257
Ptr< Packet > p
the RLC PDU to be received
Definition: lte-mac-sap.h:175
Parameters for LteMacSapProvider::TransmitPdu.
Definition: lte-mac-sap.h:45