A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tta-ff-mac-scheduler.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: Marco Miozzo <marco.miozzo@cttc.es>
19  * Modification: Dizhi Zhou <dizhi.zhou@gmail.com> // modify codes related to downlink scheduler
20  */
21 
22 #include <ns3/log.h>
23 #include <ns3/pointer.h>
24 #include <ns3/math.h>
25 
26 #include <ns3/simulator.h>
27 #include <ns3/lte-amc.h>
28 #include <ns3/tta-ff-mac-scheduler.h>
29 #include <ns3/lte-vendor-specific-parameters.h>
30 #include <ns3/boolean.h>
31 #include <set>
32 #include <cfloat>
33 
34 NS_LOG_COMPONENT_DEFINE ("TtaFfMacScheduler");
35 
36 namespace ns3 {
37 
39  10, // RGB size 1
40  26, // RGB size 2
41  63, // RGB size 3
42  110 // RGB size 4
43 }; // see table 7.1.6.1-1 of 36.213
44 
45 
46 NS_OBJECT_ENSURE_REGISTERED (TtaFfMacScheduler);
47 
48 
49 
51 {
52 public:
54 
55  // inherited from FfMacCschedSapProvider
56  virtual void CschedCellConfigReq (const struct CschedCellConfigReqParameters& params);
57  virtual void CschedUeConfigReq (const struct CschedUeConfigReqParameters& params);
58  virtual void CschedLcConfigReq (const struct CschedLcConfigReqParameters& params);
59  virtual void CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params);
60  virtual void CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params);
61 
62 private:
65 };
66 
68 {
69 }
70 
72 {
73 }
74 
75 
76 void
78 {
80 }
81 
82 void
84 {
86 }
87 
88 
89 void
91 {
93 }
94 
95 void
97 {
99 }
100 
101 void
103 {
105 }
106 
107 
108 
109 
111 {
112 public:
114 
115  // inherited from FfMacSchedSapProvider
116  virtual void SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params);
117  virtual void SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params);
118  virtual void SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params);
119  virtual void SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params);
120  virtual void SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params);
121  virtual void SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params);
122  virtual void SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params);
123  virtual void SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params);
124  virtual void SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params);
125  virtual void SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params);
126  virtual void SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params);
127 
128 
129 private:
132 };
133 
134 
135 
137 {
138 }
139 
140 
142  : m_scheduler (scheduler)
143 {
144 }
145 
146 void
148 {
150 }
151 
152 void
154 {
156 }
157 
158 void
160 {
162 }
163 
164 void
166 {
168 }
169 
170 void
172 {
174 }
175 
176 void
178 {
180 }
181 
182 void
184 {
186 }
187 
188 void
190 {
192 }
193 
194 void
196 {
198 }
199 
200 void
202 {
204 }
205 
206 void
208 {
210 }
211 
212 
213 
214 
215 
217  : m_cschedSapUser (0),
218  m_schedSapUser (0),
219  m_nextRntiUl (0)
220 {
221  m_amc = CreateObject <LteAmc> ();
224 }
225 
227 {
228  NS_LOG_FUNCTION (this);
229 }
230 
231 void
233 {
234  NS_LOG_FUNCTION (this);
236  m_dlHarqProcessesTimer.clear ();
238  m_dlInfoListBuffered.clear ();
239  m_ulHarqCurrentProcessId.clear ();
240  m_ulHarqProcessesStatus.clear ();
242  delete m_cschedSapProvider;
243  delete m_schedSapProvider;
244 }
245 
246 TypeId
248 {
249  static TypeId tid = TypeId ("ns3::TtaFfMacScheduler")
251  .AddConstructor<TtaFfMacScheduler> ()
252  .AddAttribute ("CqiTimerThreshold",
253  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
254  UintegerValue (1000),
255  MakeUintegerAccessor (&TtaFfMacScheduler::m_cqiTimersThreshold),
256  MakeUintegerChecker<uint32_t> ())
257  .AddAttribute ("HarqEnabled",
258  "Activate/Deactivate the HARQ [by default is active].",
259  BooleanValue (true),
260  MakeBooleanAccessor (&TtaFfMacScheduler::m_harqOn),
261  MakeBooleanChecker ())
262  .AddAttribute ("UlGrantMcs",
263  "The MCS of the UL grant, must be [0..15] (default 0)",
264  UintegerValue (0),
265  MakeUintegerAccessor (&TtaFfMacScheduler::m_ulGrantMcs),
266  MakeUintegerChecker<uint8_t> ())
267  ;
268  return tid;
269 }
270 
271 
272 
273 void
275 {
276  m_cschedSapUser = s;
277 }
278 
279 void
281 {
282  m_schedSapUser = s;
283 }
284 
287 {
288  return m_cschedSapProvider;
289 }
290 
293 {
294  return m_schedSapProvider;
295 }
296 
297 void
299 {
300  NS_LOG_FUNCTION (this);
301  // Read the subset of parameters used
302  m_cschedCellConfig = params;
305  cnf.m_result = SUCCESS;
307  return;
308 }
309 
310 void
312 {
313  NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
314  std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
315  if (it == m_uesTxMode.end ())
316  {
317  m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
318  // generate HARQ buffers
319  m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
320  DlHarqProcessesStatus_t dlHarqPrcStatus;
321  dlHarqPrcStatus.resize (8,0);
322  m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
323  DlHarqProcessesTimer_t dlHarqProcessesTimer;
324  dlHarqProcessesTimer.resize (8,0);
325  m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
326  DlHarqProcessesDciBuffer_t dlHarqdci;
327  dlHarqdci.resize (8);
328  m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
329  DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
330  dlHarqRlcPdu.resize (2);
331  dlHarqRlcPdu.at (0).resize (8);
332  dlHarqRlcPdu.at (1).resize (8);
333  m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
334  m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
335  UlHarqProcessesStatus_t ulHarqPrcStatus;
336  ulHarqPrcStatus.resize (8,0);
337  m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
338  UlHarqProcessesDciBuffer_t ulHarqdci;
339  ulHarqdci.resize (8);
340  m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
341  }
342  else
343  {
344  (*it).second = params.m_transmissionMode;
345  }
346  return;
347 }
348 
349 void
351 {
352  NS_LOG_FUNCTION (this << " New LC, rnti: " << params.m_rnti);
353 
354  std::set <uint16_t>::iterator it;
355  for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
356  {
357  it = m_flowStatsDl.find (params.m_rnti);
358 
359  if (it == m_flowStatsDl.end ())
360  {
361  m_flowStatsDl.insert (params.m_rnti);
362  m_flowStatsUl.insert (params.m_rnti);
363  }
364  }
365 
366  return;
367 }
368 
369 void
371 {
372  NS_LOG_FUNCTION (this);
373  for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
374  {
375  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
376  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
377  while (it!=m_rlcBufferReq.end ())
378  {
379  if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
380  {
381  temp = it;
382  it++;
383  m_rlcBufferReq.erase (temp);
384  }
385  else
386  {
387  it++;
388  }
389  }
390  }
391  return;
392 }
393 
394 void
396 {
397  NS_LOG_FUNCTION (this);
398 
399  m_uesTxMode.erase (params.m_rnti);
400  m_dlHarqCurrentProcessId.erase (params.m_rnti);
401  m_dlHarqProcessesStatus.erase (params.m_rnti);
402  m_dlHarqProcessesTimer.erase (params.m_rnti);
403  m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
405  m_ulHarqCurrentProcessId.erase (params.m_rnti);
406  m_ulHarqProcessesStatus.erase (params.m_rnti);
407  m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
408  m_flowStatsDl.erase (params.m_rnti);
409  m_flowStatsUl.erase (params.m_rnti);
410  m_ceBsrRxed.erase (params.m_rnti);
411  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
412  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
413  while (it!=m_rlcBufferReq.end ())
414  {
415  if ((*it).first.m_rnti == params.m_rnti)
416  {
417  temp = it;
418  it++;
419  m_rlcBufferReq.erase (temp);
420  }
421  else
422  {
423  it++;
424  }
425  }
426  if (m_nextRntiUl == params.m_rnti)
427  {
428  m_nextRntiUl = 0;
429  }
430 
431  return;
432 }
433 
434 
435 void
437 {
438  NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
439  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
440 
441  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
442 
443  LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
444 
445  it = m_rlcBufferReq.find (flow);
446 
447  if (it == m_rlcBufferReq.end ())
448  {
449  m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
450  }
451  else
452  {
453  (*it).second = params;
454  }
455 
456  return;
457 }
458 
459 void
461 {
462  NS_LOG_FUNCTION (this);
463  NS_FATAL_ERROR ("method not implemented");
464  return;
465 }
466 
467 void
469 {
470  NS_LOG_FUNCTION (this);
471  NS_FATAL_ERROR ("method not implemented");
472  return;
473 }
474 
475 int
477 {
478  for (int i = 0; i < 4; i++)
479  {
480  if (dlbandwidth < TtaType0AllocationRbg[i])
481  {
482  return (i + 1);
483  }
484  }
485 
486  return (-1);
487 }
488 
489 
490 int
492 {
493  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
494  int lcActive = 0;
495  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
496  {
497  if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
498  || ((*it).second.m_rlcRetransmissionQueueSize > 0)
499  || ((*it).second.m_rlcStatusPduSize > 0) ))
500  {
501  lcActive++;
502  }
503  if ((*it).first.m_rnti > rnti)
504  {
505  break;
506  }
507  }
508  return (lcActive);
509 
510 }
511 
512 
513 uint8_t
515 {
516  NS_LOG_FUNCTION (this << rnti);
517 
518  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
519  if (it == m_dlHarqCurrentProcessId.end ())
520  {
521  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
522  }
523  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
524  if (itStat == m_dlHarqProcessesStatus.end ())
525  {
526  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
527  }
528  uint8_t i = (*it).second;
529  do
530  {
531  i = (i + 1) % HARQ_PROC_NUM;
532  }
533  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
534  if ((*itStat).second.at (i) == 0)
535  {
536  return (true);
537  }
538  else
539  {
540  return (false); // return a not valid harq proc id
541  }
542 }
543 
544 
545 
546 uint8_t
548 {
549  NS_LOG_FUNCTION (this << rnti);
550 
551  if (m_harqOn == false)
552  {
553  return (0);
554  }
555 
556 
557  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
558  if (it == m_dlHarqCurrentProcessId.end ())
559  {
560  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
561  }
562  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
563  if (itStat == m_dlHarqProcessesStatus.end ())
564  {
565  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
566  }
567  uint8_t i = (*it).second;
568  do
569  {
570  i = (i + 1) % HARQ_PROC_NUM;
571  }
572  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
573  if ((*itStat).second.at (i) == 0)
574  {
575  (*it).second = i;
576  (*itStat).second.at (i) = 1;
577  }
578  else
579  {
580  NS_FATAL_ERROR ("No HARQ process available for RNTI " << rnti << " check before update with HarqProcessAvailability");
581  }
582 
583  return ((*it).second);
584 }
585 
586 
587 void
589 {
590  NS_LOG_FUNCTION (this);
591 
592  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
593  for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
594  {
595  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
596  {
597  if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
598  {
599  // reset HARQ process
600 
601  NS_LOG_DEBUG (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
602  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
603  if (itStat == m_dlHarqProcessesStatus.end ())
604  {
605  NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
606  }
607  (*itStat).second.at (i) = 0;
608  (*itTimers).second.at (i) = 0;
609  }
610  else
611  {
612  (*itTimers).second.at (i)++;
613  }
614  }
615  }
616 
617 }
618 
619 
620 void
622 {
623  NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
624  // API generated by RLC for triggering the scheduling of a DL subframe
625 
626 
627  // evaluate the relative channel quality indicator for each UE per each RBG
628  // (since we are using allocation type 0 the small unit of allocation is RBG)
629  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
630 
631  RefreshDlCqiMaps ();
632 
634  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
635  std::map <uint16_t, std::vector <uint16_t> > allocationMap; // RBs map per RNTI
636  std::vector <bool> rbgMap; // global RBGs map
637  uint16_t rbgAllocatedNum = 0;
638  std::set <uint16_t> rntiAllocated;
639  rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
641 
642  // RACH Allocation
644  uint16_t rbStart = 0;
645  std::vector <struct RachListElement_s>::iterator itRach;
646  for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
647  {
648  NS_ASSERT_MSG (m_amc->GetTbSizeFromMcs (m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) > (*itRach).m_estimatedSize, " Default UL Grant MCS does not allow to send RACH messages");
649  BuildRarListElement_s newRar;
650  newRar.m_rnti = (*itRach).m_rnti;
651  // DL-RACH Allocation
652  // Ideal: no needs of configuring m_dci
653  // UL-RACH Allocation
654  newRar.m_grant.m_rnti = newRar.m_rnti;
655  newRar.m_grant.m_mcs = m_ulGrantMcs;
656  uint16_t rbLen = 1;
657  uint16_t tbSizeBits = 0;
658  // find lowest TB size that fits UL grant estimated size
659  while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
660  {
661  rbLen++;
662  tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
663  }
664  if (tbSizeBits < (*itRach).m_estimatedSize)
665  {
666  // no more allocation space: finish allocation
667  break;
668  }
669  newRar.m_grant.m_rbStart = rbStart;
670  newRar.m_grant.m_rbLen = rbLen;
671  newRar.m_grant.m_tbSize = tbSizeBits / 8;
672  newRar.m_grant.m_hopping = false;
673  newRar.m_grant.m_tpc = 0;
674  newRar.m_grant.m_cqiRequest = false;
675  newRar.m_grant.m_ulDelay = false;
676  NS_LOG_INFO (this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart " << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize " << newRar.m_grant.m_tbSize);
677  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
678  {
679  m_rachAllocationMap.at (i) = (*itRach).m_rnti;
680  }
681  rbStart = rbStart + rbLen;
682 
683  ret.m_buildRarList.push_back (newRar);
684  }
685  m_rachList.clear ();
686 
687 
688  // Process DL HARQ feedback
690  // retrieve past HARQ retx buffered
691  if (m_dlInfoListBuffered.size () > 0)
692  {
693  if (params.m_dlInfoList.size () > 0)
694  {
695  NS_LOG_INFO (this << " Received DL-HARQ feedback");
696  m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
697  }
698  }
699  else
700  {
701  if (params.m_dlInfoList.size () > 0)
702  {
704  }
705  }
706  if (m_harqOn == false)
707  {
708  // Ignore HARQ feedback
709  m_dlInfoListBuffered.clear ();
710  }
711  std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
712  for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
713  {
714  std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
715  if (itRnti != rntiAllocated.end ())
716  {
717  // RNTI already allocated for retx
718  continue;
719  }
720  uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
721  std::vector <bool> retx;
722  NS_LOG_INFO (this << " Processing DLHARQ feedback");
723  if (nLayers == 1)
724  {
725  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
726  retx.push_back (false);
727  }
728  else
729  {
730  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
731  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
732  }
733  if (retx.at (0) || retx.at (1))
734  {
735  // retrieve HARQ process information
736  uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
737  uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
738  NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
739  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
740  if (itHarq == m_dlHarqProcessesDciBuffer.end ())
741  {
742  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << rnti);
743  }
744 
745  DlDciListElement_s dci = (*itHarq).second.at (harqId);
746  int rv = 0;
747  if (dci.m_rv.size () == 1)
748  {
749  rv = dci.m_rv.at (0);
750  }
751  else
752  {
753  rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
754  }
755 
756  if (rv == 3)
757  {
758  // maximum number of retx reached -> drop process
759  NS_LOG_INFO ("Maximum number of retransmissions reached -> drop process");
760  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
761  if (it == m_dlHarqProcessesStatus.end ())
762  {
763  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
764  }
765  (*it).second.at (harqId) = 0;
766  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
767  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
768  {
769  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
770  }
771  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
772  {
773  (*itRlcPdu).second.at (k).at (harqId).clear ();
774  }
775  continue;
776  }
777  // check the feasibility of retransmitting on the same RBGs
778  // translate the DCI to Spectrum framework
779  std::vector <int> dciRbg;
780  uint32_t mask = 0x1;
781  NS_LOG_INFO ("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
782  for (int j = 0; j < 32; j++)
783  {
784  if (((dci.m_rbBitmap & mask) >> j) == 1)
785  {
786  dciRbg.push_back (j);
787  NS_LOG_INFO ("\t" << j);
788  }
789  mask = (mask << 1);
790  }
791  bool free = true;
792  for (uint8_t j = 0; j < dciRbg.size (); j++)
793  {
794  if (rbgMap.at (dciRbg.at (j)) == true)
795  {
796  free = false;
797  break;
798  }
799  }
800  if (free)
801  {
802  // use the same RBGs for the retx
803  // reserve RBGs
804  for (uint8_t j = 0; j < dciRbg.size (); j++)
805  {
806  rbgMap.at (dciRbg.at (j)) = true;
807  NS_LOG_INFO ("RBG " << dciRbg.at (j) << " assigned");
808  rbgAllocatedNum++;
809  }
810 
811  NS_LOG_INFO (this << " Send retx in the same RBGs");
812  }
813  else
814  {
815  // find RBGs for sending HARQ retx
816  uint8_t j = 0;
817  uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
818  uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
819  std::vector <bool> rbgMapCopy = rbgMap;
820  while ((j < dciRbg.size ())&&(startRbg != rbgId))
821  {
822  if (rbgMapCopy.at (rbgId) == false)
823  {
824  rbgMapCopy.at (rbgId) = true;
825  dciRbg.at (j) = rbgId;
826  j++;
827  }
828  rbgId++;
829  }
830  if (j == dciRbg.size ())
831  {
832  // find new RBGs -> update DCI map
833  uint32_t rbgMask = 0;
834  for (uint16_t k = 0; k < dciRbg.size (); k++)
835  {
836  rbgMask = rbgMask + (0x1 << dciRbg.at (k));
837  rbgAllocatedNum++;
838  }
839  dci.m_rbBitmap = rbgMask;
840  rbgMap = rbgMapCopy;
841  NS_LOG_INFO (this << " Move retx in RBGs " << dciRbg.size ());
842  }
843  else
844  {
845  // HARQ retx cannot be performed on this TTI -> store it
846  dlInfoListUntxed.push_back (params.m_dlInfoList.at (i));
847  NS_LOG_INFO (this << " No resource for this retx -> buffer it");
848  }
849  }
850  // retrieve RLC PDU list for retx TBsize and update DCI
852  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
853  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
854  {
855  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
856  }
857  for (uint8_t j = 0; j < nLayers; j++)
858  {
859  if (retx.at (j))
860  {
861  if (j >= dci.m_ndi.size ())
862  {
863  // for avoiding errors in MIMO transient phases
864  dci.m_ndi.push_back (0);
865  dci.m_rv.push_back (0);
866  dci.m_mcs.push_back (0);
867  dci.m_tbsSize.push_back (0);
868  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no txed (MIMO transition)");
869  }
870  else
871  {
872  dci.m_ndi.at (j) = 0;
873  dci.m_rv.at (j)++;
874  (*itHarq).second.at (harqId).m_rv.at (j)++;
875  NS_LOG_INFO (this << " layer " << (uint16_t)j << " RV " << (uint16_t)dci.m_rv.at (j));
876  }
877  }
878  else
879  {
880  // empty TB of layer j
881  dci.m_ndi.at (j) = 0;
882  dci.m_rv.at (j) = 0;
883  dci.m_mcs.at (j) = 0;
884  dci.m_tbsSize.at (j) = 0;
885  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no retx");
886  }
887  }
888  for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
889  {
890  std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
891  for (uint8_t j = 0; j < nLayers; j++)
892  {
893  if (retx.at (j))
894  {
895  if (j < dci.m_ndi.size ())
896  {
897  rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
898  }
899  }
900  }
901 
902  if (rlcPduListPerLc.size () > 0)
903  {
904  newEl.m_rlcPduList.push_back (rlcPduListPerLc);
905  }
906  }
907  newEl.m_rnti = rnti;
908  newEl.m_dci = dci;
909  (*itHarq).second.at (harqId).m_rv = dci.m_rv;
910  // refresh timer
911  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
912  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
913  {
914  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
915  }
916  (*itHarqTimer).second.at (harqId) = 0;
917  ret.m_buildDataList.push_back (newEl);
918  rntiAllocated.insert (rnti);
919  }
920  else
921  {
922  // update HARQ process status
923  NS_LOG_INFO (this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
924  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
925  if (it == m_dlHarqProcessesStatus.end ())
926  {
927  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
928  }
929  (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
930  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
931  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
932  {
933  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
934  }
935  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
936  {
937  (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
938  }
939  }
940  }
941  m_dlInfoListBuffered.clear ();
942  m_dlInfoListBuffered = dlInfoListUntxed;
943 
944 
945 
946  for (int i = 0; i < rbgNum; i++)
947  {
948  NS_LOG_INFO (this << " ALLOCATION for RBG " << i << " of " << rbgNum);
949  if (rbgMap.at (i) == false)
950  {
951  std::set <uint16_t>::iterator it;
952  std::set <uint16_t>::iterator itMax = m_flowStatsDl.end ();
953  double rcqiMax = 0.0;
954  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
955  {
956  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it));
957  if ((itRnti != rntiAllocated.end ())||(!HarqProcessAvailability ((*it))))
958  {
959  // UE already allocated for HARQ or without HARQ process available -> drop it
960  if (itRnti != rntiAllocated.end ())
961  {
962  NS_LOG_DEBUG (this << " RNTI discared for HARQ tx" << (uint16_t)(*it));
963  }
964  if (!HarqProcessAvailability ((*it)))
965  {
966  NS_LOG_DEBUG (this << " RNTI discared for HARQ id" << (uint16_t)(*it));
967  }
968  continue;
969  }
970 
971  std::map <uint16_t,SbMeasResult_s>::iterator itSbCqi;
972  itSbCqi = m_a30CqiRxed.find ((*it));
973  std::map <uint16_t,uint8_t>::iterator itWbCqi;
974  itWbCqi = m_p10CqiRxed.find ((*it));
975 
976  std::map <uint16_t,uint8_t>::iterator itTxMode;
977  itTxMode = m_uesTxMode.find ((*it));
978  if (itTxMode == m_uesTxMode.end ())
979  {
980  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it));
981  }
982  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
983 
984  std::vector <uint8_t> sbCqi;
985  if (itSbCqi == m_a30CqiRxed.end ())
986  {
987  for (uint8_t k = 0; k < nLayer; k++)
988  {
989  sbCqi.push_back (1); // start with lowest value
990  }
991  }
992  else
993  {
994  sbCqi = (*itSbCqi).second.m_higherLayerSelected.at (i).m_sbCqi;
995  }
996 
997  uint8_t wbCqi = 0;
998  if (itWbCqi != m_p10CqiRxed.end ())
999  {
1000  wbCqi = (*itWbCqi).second;
1001  }
1002  else
1003  {
1004  wbCqi = 1; // lowest value fro trying a transmission
1005  }
1006 
1007  uint8_t cqi1 = sbCqi.at (0);
1008  uint8_t cqi2 = 1;
1009  if (sbCqi.size () > 1)
1010  {
1011  cqi2 = sbCqi.at (1);
1012  }
1013  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1014  {
1015  if (LcActivePerFlow ((*it)) > 0)
1016  {
1017  // this UE has data to transmit
1018  double achievableSbRate = 0.0;
1019  double achievableWbRate = 0.0;
1020  uint8_t sbMcs = 0;
1021  uint8_t wbMcs = 0;
1022  for (uint8_t k = 0; k < nLayer; k++)
1023  {
1024  if (sbCqi.size () > k)
1025  {
1026  sbMcs = m_amc->GetMcsFromCqi (sbCqi.at (k));
1027  }
1028  else
1029  {
1030  // no info on this subband -> worst MCS
1031  sbMcs = 0;
1032  }
1033  achievableSbRate += ((m_amc->GetTbSizeFromMcs (sbMcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1034  wbMcs = m_amc->GetMcsFromCqi (wbCqi);
1035  achievableWbRate += ((m_amc->GetTbSizeFromMcs (wbMcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1036  }
1037 
1038  double metric = achievableSbRate / achievableWbRate;
1039 
1040  if (metric > rcqiMax)
1041  {
1042  rcqiMax = metric;
1043  itMax = it;
1044  }
1045  }
1046  } // end if cqi
1047 
1048  } // end for m_rlcBufferReq
1049 
1050  if (itMax == m_flowStatsDl.end ())
1051  {
1052  // no UE available for this RB
1053  NS_LOG_INFO (this << " any UE found");
1054  }
1055  else
1056  {
1057  rbgMap.at (i) = true;
1058  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1059  itMap = allocationMap.find ((*itMax));
1060  if (itMap == allocationMap.end ())
1061  {
1062  // insert new element
1063  std::vector <uint16_t> tempMap;
1064  tempMap.push_back (i);
1065  allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax), tempMap));
1066  }
1067  else
1068  {
1069  (*itMap).second.push_back (i);
1070  }
1071  NS_LOG_INFO (this << " UE assigned " << (*itMax));
1072  }
1073  } // end for RBG free
1074  } // end for RBGs
1075 
1076  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1077  // creating the correspondent DCIs
1078  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1079  while (itMap != allocationMap.end ())
1080  {
1081  // create new BuildDataListElement_s for this LC
1082  BuildDataListElement_s newEl;
1083  newEl.m_rnti = (*itMap).first;
1084  // create the DlDciListElement_s
1085  DlDciListElement_s newDci;
1086  newDci.m_rnti = (*itMap).first;
1087  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1088 
1089  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1090  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1091  if (lcActives == 0)
1092  {
1093  // Set to max value, to avoid divide by 0 below
1094  lcActives = (uint16_t)65535; // UINT16_MAX;
1095  }
1096  uint16_t RgbPerRnti = (*itMap).second.size ();
1097  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1098  itCqi = m_a30CqiRxed.find ((*itMap).first);
1099  std::map <uint16_t,uint8_t>::iterator itTxMode;
1100  itTxMode = m_uesTxMode.find ((*itMap).first);
1101  if (itTxMode == m_uesTxMode.end ())
1102  {
1103  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1104  }
1105  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1106  std::vector <uint8_t> worstCqi (2, 15);
1107  if (itCqi != m_a30CqiRxed.end ())
1108  {
1109  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1110  {
1111  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1112  {
1113  NS_LOG_INFO (this << " RBG " << (*itMap).second.at (k) << " CQI " << (uint16_t)((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (0)) );
1114  for (uint8_t j = 0; j < nLayer; j++)
1115  {
1116  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1117  {
1118  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1119  {
1120  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1121  }
1122  }
1123  else
1124  {
1125  // no CQI for this layer of this suband -> worst one
1126  worstCqi.at (j) = 1;
1127  }
1128  }
1129  }
1130  else
1131  {
1132  for (uint8_t j = 0; j < nLayer; j++)
1133  {
1134  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1135  }
1136  }
1137  }
1138  }
1139  else
1140  {
1141  for (uint8_t j = 0; j < nLayer; j++)
1142  {
1143  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1144  }
1145  }
1146  for (uint8_t j = 0; j < nLayer; j++)
1147  {
1148  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " CQI selected " << (uint16_t)worstCqi.at (j));
1149  }
1150  uint32_t bytesTxed = 0;
1151  for (uint8_t j = 0; j < nLayer; j++)
1152  {
1153  newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1154  int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (j), RgbPerRnti * rbgSize) / 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1155  newDci.m_tbsSize.push_back (tbSize);
1156  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " MCS selected" << m_amc->GetMcsFromCqi (worstCqi.at (j)));
1157 
1158  bytesTxed += tbSize;
1159  }
1160 
1161  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1162  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1163  uint32_t rbgMask = 0;
1164  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1165  {
1166  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1167  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1168  }
1169  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1170 
1171  // create the rlc PDUs -> equally divide resources among actives LCs
1172  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1173  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1174  {
1175  if (((*itBufReq).first.m_rnti == (*itMap).first)
1176  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1177  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1178  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1179  {
1180  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1181  for (uint8_t j = 0; j < nLayer; j++)
1182  {
1183  RlcPduListElement_s newRlcEl;
1184  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1185  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1186  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1187  newRlcPduLe.push_back (newRlcEl);
1188  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1189  if (m_harqOn == true)
1190  {
1191  // store RLC PDU list for HARQ
1192  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1193  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1194  {
1195  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1196  }
1197  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1198  }
1199  }
1200  newEl.m_rlcPduList.push_back (newRlcPduLe);
1201  }
1202  if ((*itBufReq).first.m_rnti > (*itMap).first)
1203  {
1204  break;
1205  }
1206  }
1207  for (uint8_t j = 0; j < nLayer; j++)
1208  {
1209  newDci.m_ndi.push_back (1);
1210  newDci.m_rv.push_back (0);
1211  }
1212 
1213  newEl.m_dci = newDci;
1214 
1215  if (m_harqOn == true)
1216  {
1217  // store DCI for HARQ
1218  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1219  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1220  {
1221  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1222  }
1223  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1224  // refresh timer
1225  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1226  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1227  {
1228  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1229  }
1230  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1231  }
1232 
1233  // ...more parameters -> ingored in this version
1234 
1235  ret.m_buildDataList.push_back (newEl);
1236 
1237  itMap++;
1238  } // end while allocation
1239  ret.m_nrOfPdcchOfdmSymbols = 1;
1240 
1242 
1243 
1244  return;
1245 }
1246 
1247 void
1249 {
1250  NS_LOG_FUNCTION (this);
1251 
1252  m_rachList = params.m_rachList;
1253 
1254  return;
1255 }
1256 
1257 void
1259 {
1260  NS_LOG_FUNCTION (this);
1261 
1262  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1263  {
1264  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1265  {
1266  // wideband CQI reporting
1267  std::map <uint16_t,uint8_t>::iterator it;
1268  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1269  it = m_p10CqiRxed.find (rnti);
1270  if (it == m_p10CqiRxed.end ())
1271  {
1272  // create the new entry
1273  m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.m_cqiList.at (i).m_wbCqi.at (0)) ); // only codeword 0 at this stage (SISO)
1274  // generate correspondent timer
1275  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1276  }
1277  else
1278  {
1279  // update the CQI value and refresh correspondent timer
1280  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1281  // update correspondent timer
1282  std::map <uint16_t,uint32_t>::iterator itTimers;
1283  itTimers = m_p10CqiTimers.find (rnti);
1284  (*itTimers).second = m_cqiTimersThreshold;
1285  }
1286  }
1287  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1288  {
1289  // subband CQI reporting high layer configured
1290  std::map <uint16_t,SbMeasResult_s>::iterator it;
1291  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1292  it = m_a30CqiRxed.find (rnti);
1293  if (it == m_a30CqiRxed.end ())
1294  {
1295  // create the new entry
1296  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1297  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1298  }
1299  else
1300  {
1301  // update the CQI value and refresh correspondent timer
1302  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1303  std::map <uint16_t,uint32_t>::iterator itTimers;
1304  itTimers = m_a30CqiTimers.find (rnti);
1305  (*itTimers).second = m_cqiTimersThreshold;
1306  }
1307  }
1308  else
1309  {
1310  NS_LOG_ERROR (this << " CQI type unknown");
1311  }
1312  }
1313 
1314  return;
1315 }
1316 
1317 
1318 double
1319 TtaFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1320 {
1321  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1322  if (itCqi == m_ueCqi.end ())
1323  {
1324  // no cqi info about this UE
1325  return (NO_SINR);
1326 
1327  }
1328  else
1329  {
1330  // take the average SINR value among the available
1331  double sinrSum = 0;
1332  int sinrNum = 0;
1333  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1334  {
1335  double sinr = (*itCqi).second.at (i);
1336  if (sinr != NO_SINR)
1337  {
1338  sinrSum += sinr;
1339  sinrNum++;
1340  }
1341  }
1342  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1343  // store the value
1344  (*itCqi).second.at (rb) = estimatedSinr;
1345  return (estimatedSinr);
1346  }
1347 }
1348 
1349 void
1351 {
1352  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1353 
1354  RefreshUlCqiMaps ();
1355 
1356  // Generate RBs map
1358  std::vector <bool> rbMap;
1359  uint16_t rbAllocatedNum = 0;
1360  std::set <uint16_t> rntiAllocated;
1361  std::vector <uint16_t> rbgAllocationMap;
1362  // update with RACH allocation map
1363  rbgAllocationMap = m_rachAllocationMap;
1364  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1365  m_rachAllocationMap.clear ();
1367 
1368  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1369  // remove RACH allocation
1370  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1371  {
1372  if (rbgAllocationMap.at (i) != 0)
1373  {
1374  rbMap.at (i) = true;
1375  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1376  }
1377  }
1378 
1379 
1380  if (m_harqOn == true)
1381  {
1382  // Process UL HARQ feedback
1383  // update UL HARQ proc id
1384  std::map <uint16_t, uint8_t>::iterator itProcId;
1385  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
1386  {
1387  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
1388  }
1389 
1390  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1391  {
1392  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1393  {
1394  // retx correspondent block: retrieve the UL-DCI
1395  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1396  itProcId = m_ulHarqCurrentProcessId.find (rnti);
1397  if (itProcId == m_ulHarqCurrentProcessId.end ())
1398  {
1399  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1400  }
1401  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1402  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1403  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1404  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1405  {
1406  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1407  continue;
1408  }
1409  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1410  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1411  if (itStat == m_ulHarqProcessesStatus.end ())
1412  {
1413  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1414  }
1415  if ((*itStat).second.at (harqId) >= 3)
1416  {
1417  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1418  continue;
1419  }
1420  bool free = true;
1421  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1422  {
1423  if (rbMap.at (j) == true)
1424  {
1425  free = false;
1426  NS_LOG_INFO (this << " BUSY " << j);
1427  }
1428  }
1429  if (free)
1430  {
1431  // retx on the same RBs
1432  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1433  {
1434  rbMap.at (j) = true;
1435  rbgAllocationMap.at (j) = dci.m_rnti;
1436  NS_LOG_INFO ("\tRB " << j);
1437  rbAllocatedNum++;
1438  }
1439  NS_LOG_INFO (this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart << " to " << dci.m_rbStart + dci.m_rbLen << " RV " << (*itStat).second.at (harqId) + 1);
1440  }
1441  else
1442  {
1443  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1444  continue;
1445  }
1446  dci.m_ndi = 0;
1447  // Update HARQ buffers with new HarqId
1448  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1449  (*itStat).second.at (harqId) = 0;
1450  (*itHarq).second.at ((*itProcId).second) = dci;
1451  ret.m_dciList.push_back (dci);
1452  rntiAllocated.insert (dci.m_rnti);
1453  }
1454  else
1455  {
1456  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1457  }
1458  }
1459  }
1460 
1461  std::map <uint16_t,uint32_t>::iterator it;
1462  int nflows = 0;
1463 
1464  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1465  {
1466  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1467  // select UEs with queues not empty and not yet allocated for HARQ
1468  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1469  {
1470  nflows++;
1471  }
1472  }
1473 
1474  if (nflows == 0)
1475  {
1476  if (ret.m_dciList.size () > 0)
1477  {
1479  }
1480 
1481  return; // no flows to be scheduled
1482  }
1483 
1484 
1485  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1486  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1487  if (rbPerFlow < 3)
1488  {
1489  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1490  }
1491  int rbAllocated = 0;
1492 
1493  if (m_nextRntiUl != 0)
1494  {
1495  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1496  {
1497  if ((*it).first == m_nextRntiUl)
1498  {
1499  break;
1500  }
1501  }
1502  if (it == m_ceBsrRxed.end ())
1503  {
1504  NS_LOG_ERROR (this << " no user found");
1505  }
1506  }
1507  else
1508  {
1509  it = m_ceBsrRxed.begin ();
1510  m_nextRntiUl = (*it).first;
1511  }
1512  do
1513  {
1514  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1515  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1516  {
1517  // UE already allocated for UL-HARQ -> skip it
1518  NS_LOG_DEBUG (this << " UE already allocated in HARQ -> discared, RNTI " << (*it).first);
1519  it++;
1520  if (it == m_ceBsrRxed.end ())
1521  {
1522  // restart from the first
1523  it = m_ceBsrRxed.begin ();
1524  }
1525  continue;
1526  }
1527  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1528  {
1529  // limit to physical resources last resource assignment
1530  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1531  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1532  if (rbPerFlow < 3)
1533  {
1534  // terminate allocation
1535  rbPerFlow = 0;
1536  }
1537  }
1538 
1539  UlDciListElement_s uldci;
1540  uldci.m_rnti = (*it).first;
1541  uldci.m_rbLen = rbPerFlow;
1542  bool allocated = false;
1543  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1544  while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0))
1545  {
1546  // check availability
1547  bool free = true;
1548  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1549  {
1550  if (rbMap.at (j) == true)
1551  {
1552  free = false;
1553  break;
1554  }
1555  }
1556  if (free)
1557  {
1558  uldci.m_rbStart = rbAllocated;
1559 
1560  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1561  {
1562  rbMap.at (j) = true;
1563  // store info on allocation for managing ul-cqi interpretation
1564  rbgAllocationMap.at (j) = (*it).first;
1565  }
1566  rbAllocated += rbPerFlow;
1567  allocated = true;
1568  break;
1569  }
1570  rbAllocated++;
1571  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1572  {
1573  // limit to physical resources last resource assignment
1574  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1575  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1576  if (rbPerFlow < 3)
1577  {
1578  // terminate allocation
1579  rbPerFlow = 0;
1580  }
1581  }
1582  }
1583  if (!allocated)
1584  {
1585  // unable to allocate new resource: finish scheduling
1586  m_nextRntiUl = (*it).first;
1587  if (ret.m_dciList.size () > 0)
1588  {
1590  }
1591  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1592  return;
1593  }
1594 
1595 
1596 
1597  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1598  int cqi = 0;
1599  if (itCqi == m_ueCqi.end ())
1600  {
1601  // no cqi info about this UE
1602  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1603  }
1604  else
1605  {
1606  // take the lowest CQI value (worst RB)
1607  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1608  if (minSinr == NO_SINR)
1609  {
1610  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1611  }
1612  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1613  {
1614  double sinr = (*itCqi).second.at (i);
1615  if (sinr == NO_SINR)
1616  {
1617  sinr = EstimateUlSinr ((*it).first, i);
1618  }
1619  if ((*itCqi).second.at (i) < minSinr)
1620  {
1621  minSinr = (*itCqi).second.at (i);
1622  }
1623  }
1624 
1625  // translate SINR -> cqi: WILD ACK: same as DL
1626  double s = log2 ( 1 + (
1627  std::pow (10, minSinr / 10 ) /
1628  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1629  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1630  if (cqi == 0)
1631  {
1632  it++;
1633  if (it == m_ceBsrRxed.end ())
1634  {
1635  // restart from the first
1636  it = m_ceBsrRxed.begin ();
1637  }
1638  NS_LOG_DEBUG (this << " UE discared for CQI=0, RNTI " << uldci.m_rnti);
1639  // remove UE from allocation map
1640  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1641  {
1642  rbgAllocationMap.at (i) = 0;
1643  }
1644  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1645  }
1646  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1647  }
1648 
1649  uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1650  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1651  uldci.m_ndi = 1;
1652  uldci.m_cceIndex = 0;
1653  uldci.m_aggrLevel = 1;
1654  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1655  uldci.m_hopping = false;
1656  uldci.m_n2Dmrs = 0;
1657  uldci.m_tpc = 0; // no power control
1658  uldci.m_cqiRequest = false; // only period CQI at this stage
1659  uldci.m_ulIndex = 0; // TDD parameter
1660  uldci.m_dai = 1; // TDD parameter
1661  uldci.m_freqHopping = 0;
1662  uldci.m_pdcchPowerOffset = 0; // not used
1663  ret.m_dciList.push_back (uldci);
1664  // store DCI for HARQ_PERIOD
1665  uint8_t harqId = 0;
1666  if (m_harqOn == true)
1667  {
1668  std::map <uint16_t, uint8_t>::iterator itProcId;
1669  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1670  if (itProcId == m_ulHarqCurrentProcessId.end ())
1671  {
1672  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1673  }
1674  harqId = (*itProcId).second;
1675  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1676  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1677  {
1678  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1679  }
1680  (*itDci).second.at (harqId) = uldci;
1681  }
1682 
1683  NS_LOG_INFO (this << " UE Allocation RNTI " << (*it).first << " startPRB " << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize " << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId " << (uint16_t)harqId);
1684 
1685 
1686  it++;
1687  if (it == m_ceBsrRxed.end ())
1688  {
1689  // restart from the first
1690  it = m_ceBsrRxed.begin ();
1691  }
1692  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1693  {
1694  // Stop allocation: no more PRBs
1695  m_nextRntiUl = (*it).first;
1696  break;
1697  }
1698  }
1699  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1700 
1701 
1702  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1704 
1705  return;
1706 }
1707 
1708 void
1710 {
1711  NS_LOG_FUNCTION (this);
1712  return;
1713 }
1714 
1715 void
1717 {
1718  NS_LOG_FUNCTION (this);
1719  return;
1720 }
1721 
1722 void
1724 {
1725  NS_LOG_FUNCTION (this);
1726 
1727  std::map <uint16_t,uint32_t>::iterator it;
1728 
1729  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1730  {
1731  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1732  {
1733  // buffer status report
1734  // note that this scheduler does not differentiate the
1735  // allocation according to which LCGs have more/less bytes
1736  // to send.
1737  // Hence the BSR of different LCGs are just summed up to get
1738  // a total queue size that is used for allocation purposes.
1739 
1740  uint32_t buffer = 0;
1741  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1742  {
1743  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1744  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1745  }
1746 
1747  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1748  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
1749  it = m_ceBsrRxed.find (rnti);
1750  if (it == m_ceBsrRxed.end ())
1751  {
1752  // create the new entry
1753  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1754  }
1755  else
1756  {
1757  // update the buffer size value
1758  (*it).second = buffer;
1759  }
1760  }
1761  }
1762 
1763  return;
1764 }
1765 
1766 void
1768 {
1769  NS_LOG_FUNCTION (this);
1770 // retrieve the allocation for this subframe
1771  switch (m_ulCqiFilter)
1772  {
1774  {
1775  // filter all the CQIs that are not SRS based
1776  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1777  {
1778  return;
1779  }
1780  }
1781  break;
1783  {
1784  // filter all the CQIs that are not SRS based
1785  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1786  {
1787  return;
1788  }
1789  }
1791  break;
1792 
1793  default:
1794  NS_FATAL_ERROR ("Unknown UL CQI type");
1795  }
1796 
1797  switch (params.m_ulCqi.m_type)
1798  {
1799  case UlCqi_s::PUSCH:
1800  {
1801  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1802  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1803  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
1804  itMap = m_allocationMaps.find (params.m_sfnSf);
1805  if (itMap == m_allocationMaps.end ())
1806  {
1807  return;
1808  }
1809  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1810  {
1811  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1812  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1813  itCqi = m_ueCqi.find ((*itMap).second.at (i));
1814  if (itCqi == m_ueCqi.end ())
1815  {
1816  // create a new entry
1817  std::vector <double> newCqi;
1818  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1819  {
1820  if (i == j)
1821  {
1822  newCqi.push_back (sinr);
1823  }
1824  else
1825  {
1826  // initialize with NO_SINR value.
1827  newCqi.push_back (NO_SINR);
1828  }
1829 
1830  }
1831  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1832  // generate correspondent timer
1833  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1834  }
1835  else
1836  {
1837  // update the value
1838  (*itCqi).second.at (i) = sinr;
1839  //NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
1840  // update correspondent timer
1841  std::map <uint16_t, uint32_t>::iterator itTimers;
1842  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1843  (*itTimers).second = m_cqiTimersThreshold;
1844 
1845  }
1846 
1847  }
1848  // remove obsolete info on allocation
1849  m_allocationMaps.erase (itMap);
1850  }
1851  break;
1852  case UlCqi_s::SRS:
1853  {
1854  // get the RNTI from vendor specific parameters
1855  uint16_t rnti = 0;
1856  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1857  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1858  {
1859  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1860  {
1861  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1862  rnti = vsp->GetRnti ();
1863  }
1864  }
1865  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1866  itCqi = m_ueCqi.find (rnti);
1867  if (itCqi == m_ueCqi.end ())
1868  {
1869  // create a new entry
1870  std::vector <double> newCqi;
1871  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1872  {
1873  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1874  newCqi.push_back (sinr);
1875  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
1876 
1877  }
1878  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1879  // generate correspondent timer
1880  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1881  }
1882  else
1883  {
1884  // update the values
1885  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1886  {
1887  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1888  (*itCqi).second.at (j) = sinr;
1889  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
1890  }
1891  // update correspondent timer
1892  std::map <uint16_t, uint32_t>::iterator itTimers;
1893  itTimers = m_ueCqiTimers.find (rnti);
1894  (*itTimers).second = m_cqiTimersThreshold;
1895 
1896  }
1897 
1898 
1899  }
1900  break;
1901  case UlCqi_s::PUCCH_1:
1902  case UlCqi_s::PUCCH_2:
1903  case UlCqi_s::PRACH:
1904  {
1905  NS_FATAL_ERROR ("TtaFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1906  }
1907  break;
1908  default:
1909  NS_FATAL_ERROR ("Unknown type of UL-CQI");
1910  }
1911  return;
1912 }
1913 
1914 void
1916 {
1917  // refresh DL CQI P01 Map
1918  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1919  while (itP10 != m_p10CqiTimers.end ())
1920  {
1921  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1922  if ((*itP10).second == 0)
1923  {
1924  // delete correspondent entries
1925  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1926  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
1927  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
1928  m_p10CqiRxed.erase (itMap);
1929  std::map <uint16_t,uint32_t>::iterator temp = itP10;
1930  itP10++;
1931  m_p10CqiTimers.erase (temp);
1932  }
1933  else
1934  {
1935  (*itP10).second--;
1936  itP10++;
1937  }
1938  }
1939 
1940  // refresh DL CQI A30 Map
1941  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
1942  while (itA30 != m_a30CqiTimers.end ())
1943  {
1944  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1945  if ((*itA30).second == 0)
1946  {
1947  // delete correspondent entries
1948  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
1949  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
1950  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
1951  m_a30CqiRxed.erase (itMap);
1952  std::map <uint16_t,uint32_t>::iterator temp = itA30;
1953  itA30++;
1954  m_a30CqiTimers.erase (temp);
1955  }
1956  else
1957  {
1958  (*itA30).second--;
1959  itA30++;
1960  }
1961  }
1962 
1963  return;
1964 }
1965 
1966 
1967 void
1969 {
1970  // refresh UL CQI Map
1971  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1972  while (itUl != m_ueCqiTimers.end ())
1973  {
1974  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1975  if ((*itUl).second == 0)
1976  {
1977  // delete correspondent entries
1978  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1979  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
1980  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
1981  (*itMap).second.clear ();
1982  m_ueCqi.erase (itMap);
1983  std::map <uint16_t,uint32_t>::iterator temp = itUl;
1984  itUl++;
1985  m_ueCqiTimers.erase (temp);
1986  }
1987  else
1988  {
1989  (*itUl).second--;
1990  itUl++;
1991  }
1992  }
1993 
1994  return;
1995 }
1996 
1997 void
1998 TtaFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1999 {
2000  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2001  LteFlowId_t flow (rnti, lcid);
2002  it = m_rlcBufferReq.find (flow);
2003  if (it != m_rlcBufferReq.end ())
2004  {
2005  NS_LOG_INFO (this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue " << (*it).second.m_rlcTransmissionQueueSize << " retxqueue " << (*it).second.m_rlcRetransmissionQueueSize << " status " << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2006  // Update queues: RLC tx order Status, ReTx, Tx
2007  // Update status queue
2008  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2009  {
2010  (*it).second.m_rlcStatusPduSize = 0;
2011  }
2012  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2013  {
2014  (*it).second.m_rlcRetransmissionQueueSize = 0;
2015  }
2016  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2017  {
2018  uint32_t rlcOverhead;
2019  if (lcid == 1)
2020  {
2021  // for SRB1 (using RLC AM) it's better to
2022  // overestimate RLC overhead rather than
2023  // underestimate it and risk unneeded
2024  // segmentation which increases delay
2025  rlcOverhead = 4;
2026  }
2027  else
2028  {
2029  // minimum RLC overhead due to header
2030  rlcOverhead = 2;
2031  }
2032  // update transmission queue
2033  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2034  {
2035  (*it).second.m_rlcTransmissionQueueSize = 0;
2036  }
2037  else
2038  {
2039  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2040  }
2041  }
2042  }
2043  else
2044  {
2045  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2046  }
2047 }
2048 
2049 void
2050 TtaFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2051 {
2052 
2053  size = size - 2; // remove the minimum RLC overhead
2054  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2055  if (it != m_ceBsrRxed.end ())
2056  {
2057  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2058  if ((*it).second >= size)
2059  {
2060  (*it).second -= size;
2061  }
2062  else
2063  {
2064  (*it).second = 0;
2065  }
2066  }
2067  else
2068  {
2069  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2070  }
2071 
2072 }
2073 
2074 void
2076 {
2077  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2079  params.m_rnti = rnti;
2080  params.m_transmissionMode = txMode;
2082 }
2083 
2084 
2085 }
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
FfMacCschedSapUser * m_cschedSapUser
int GetRbgSize(int dlbandwidth)
std::vector< struct UlInfoListElement_s > m_ulInfoList
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:88
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
std::vector< struct RachListElement_s > m_rachList
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual void SchedUlSrInfoReq(const struct SchedUlSrInfoReqParameters &params)
#define HARQ_PERIOD
Definition: lte-common.h:30
Hold a bool native type.
Definition: boolean.h:38
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
std::map< uint16_t, uint32_t > m_ceBsrRxed
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters &params)
CSCHED_CELL_CONFIG_REQ.
virtual void SchedDlPagingBufferReq(const struct SchedDlPagingBufferReqParameters &params)
virtual void SchedDlMacBufferReq(const struct SchedDlMacBufferReqParameters &params)
virtual void SchedDlCqiInfoReq(const struct SchedDlCqiInfoReqParameters &params)
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
enum ns3::UlCqi_s::Type_e m_type
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
std::vector< struct LogicalChannelConfigListElement_s > m_logicalChannelConfigList
std::vector< uint16_t > m_sinr
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
std::vector< uint8_t > DlHarqProcessesTimer_t
#define NO_SINR
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual void SchedDlTriggerReq(const struct SchedDlTriggerReqParameters &params)
std::vector< uint8_t > m_mcs
Definition: ff-mac-common.h:95
int TtaType0AllocationRbg[4]
See section 4.3.2 ulDciListElement.
Provides the CSCHED SAP.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
std::vector< struct UlDciListElement_s > m_dciList
#define NS_LOG_INFO(msg)
Definition: log.h:264
See section 4.3.10 buildRARListElement.
FfMacSchedSapUser * m_schedSapUser
std::map< uint16_t, uint32_t > m_a30CqiTimers
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
virtual void DoDispose(void)
std::map< uint16_t, uint32_t > m_p10CqiTimers
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
virtual void CschedLcReleaseReq(const struct CschedLcReleaseReqParameters &params)
std::map< uint16_t, uint8_t > m_p10CqiRxed
virtual void CschedUeConfigUpdateInd(const struct CschedUeConfigUpdateIndParameters &params)=0
virtual void CschedUeConfigReq(const struct CschedUeConfigReqParameters &params)
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Hold an unsigned integer type.
Definition: uinteger.h:46
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
static uint8_t TxMode2LayerNum(uint8_t txMode)
Definition: lte-common.cc:170
Ptr< SampleEmitter > s
virtual void SchedDlRachInfoReq(const struct SchedDlRachInfoReqParameters &params)
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual void CschedLcConfigReq(const struct CschedLcConfigReqParameters &params)
std::map< uint16_t, uint8_t > m_uesTxMode
std::vector< uint8_t > m_ndi
Definition: ff-mac-common.h:96
std::map< uint16_t, uint32_t > m_ueCqiTimers
int LcActivePerFlow(uint16_t rnti)
Provides the SCHED SAP.
friend class TtaSchedulerMemberCschedSapProvider
virtual void SchedUlNoiseInterferenceReq(const struct SchedUlNoiseInterferenceReqParameters &params)
virtual void CschedUeConfigCnf(const struct CschedUeConfigCnfParameters &params)=0
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
std::vector< struct CqiListElement_s > m_cqiList
std::vector< struct DlInfoListElement_s > m_dlInfoList
friend class TtaSchedulerMemberSchedSapProvider
virtual void SchedUlCqiInfoReq(const struct SchedUlCqiInfoReqParameters &params)
virtual void SchedDlConfigInd(const struct SchedDlConfigIndParameters &params)=0
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
virtual void SchedUlTriggerReq(const struct SchedUlTriggerReqParameters &params)
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
static TypeId GetTypeId(void)
std::vector< uint16_t > m_tbsSize
Definition: ff-mac-common.h:94
See section 4.3.9 rlcPDU_ListElement.
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
std::vector< uint8_t > m_rv
Definition: ff-mac-common.h:97
FfMacSchedSapProvider * m_schedSapProvider
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
std::set< uint16_t > m_flowStatsDl
virtual void SchedUlConfigInd(const struct SchedUlConfigIndParameters &params)=0
UlCqiFilter_t m_ulCqiFilter
#define SRS_CQI_RNTI_VSP
std::set< uint16_t > m_flowStatsUl
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
std::map< uint16_t, std::vector< double > > m_ueCqi
std::vector< struct MacCeListElement_s > m_macCeList
std::vector< struct RachListElement_s > m_rachList
static double fpS11dot3toDouble(uint16_t val)
Definition: lte-common.cc:114
#define HARQ_PROC_NUM
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
std::vector< uint8_t > UlHarqProcessesStatus_t
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
std::vector< uint8_t > DlHarqProcessesStatus_t
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
static uint32_t BsrId2BufferSize(uint8_t val)
Definition: lte-common.cc:142
virtual void SchedDlRlcBufferReq(const struct SchedDlRlcBufferReqParameters &params)
virtual void CschedUeReleaseReq(const struct CschedUeReleaseReqParameters &params)
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
virtual void SchedUlMacCtrlInfoReq(const struct SchedUlMacCtrlInfoReqParameters &params)
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
#define NS_LOG_ERROR(msg)
Definition: log.h:237
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
std::vector< uint16_t > m_rachAllocationMap
FfMacCschedSapProvider * m_cschedSapProvider
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
struct DlDciListElement_s m_dci
NS_LOG_COMPONENT_DEFINE("TtaFfMacScheduler")
#define HARQ_DL_TIMEOUT
std::vector< struct BuildRarListElement_s > m_buildRarList
a unique identifier for an interface.
Definition: type-id.h:49
Implements the SCHED SAP and CSCHED SAP for a Throughput to Average scheduler.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::vector< struct BuildDataListElement_s > m_buildDataList
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
See section 4.3.8 builDataListElement.