A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pss-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/pss-ff-mac-scheduler.h>
29 #include <ns3/lte-vendor-specific-parameters.h>
30 #include <ns3/boolean.h>
31 #include <cfloat>
32 #include <set>
33 #include <ns3/string.h>
34 #include <algorithm>
35 
36 
37 NS_LOG_COMPONENT_DEFINE ("PssFfMacScheduler");
38 
39 namespace ns3 {
40 
41 static const int PssType0AllocationRbg[4] = {
42  10, // RGB size 1
43  26, // RGB size 2
44  63, // RGB size 3
45  110 // RGB size 4
46 }; // see table 7.1.6.1-1 of 36.213
47 
48 
49 NS_OBJECT_ENSURE_REGISTERED (PssFfMacScheduler);
50 
51 
52 
54 {
55 public:
57 
58  // inherited from FfMacCschedSapProvider
59  virtual void CschedCellConfigReq (const struct CschedCellConfigReqParameters& params);
60  virtual void CschedUeConfigReq (const struct CschedUeConfigReqParameters& params);
61  virtual void CschedLcConfigReq (const struct CschedLcConfigReqParameters& params);
62  virtual void CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params);
63  virtual void CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params);
64 
65 private:
68 };
69 
71 {
72 }
73 
75 {
76 }
77 
78 
79 void
81 {
83 }
84 
85 void
87 {
89 }
90 
91 
92 void
94 {
96 }
97 
98 void
100 {
102 }
103 
104 void
106 {
108 }
109 
110 
111 
112 
114 {
115 public:
117 
118  // inherited from FfMacSchedSapProvider
119  virtual void SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params);
120  virtual void SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params);
121  virtual void SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params);
122  virtual void SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params);
123  virtual void SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params);
124  virtual void SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params);
125  virtual void SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params);
126  virtual void SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params);
127  virtual void SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params);
128  virtual void SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params);
129  virtual void SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params);
130 
131 
132 private:
135 };
136 
137 
138 
140 {
141 }
142 
143 
145  : m_scheduler (scheduler)
146 {
147 }
148 
149 void
151 {
153 }
154 
155 void
157 {
159 }
160 
161 void
163 {
165 }
166 
167 void
169 {
171 }
172 
173 void
175 {
177 }
178 
179 void
181 {
183 }
184 
185 void
187 {
189 }
190 
191 void
193 {
195 }
196 
197 void
199 {
201 }
202 
203 void
205 {
207 }
208 
209 void
211 {
213 }
214 
215 
216 
217 
218 
220  : m_cschedSapUser (0),
221  m_schedSapUser (0),
222  m_timeWindow (99.0),
223  m_nextRntiUl (0)
224 {
225  m_amc = CreateObject <LteAmc> ();
228  m_ffrSapProvider = 0;
230 }
231 
233 {
234  NS_LOG_FUNCTION (this);
235 }
236 
237 void
239 {
240  NS_LOG_FUNCTION (this);
242  m_dlHarqProcessesTimer.clear ();
244  m_dlInfoListBuffered.clear ();
245  m_ulHarqCurrentProcessId.clear ();
246  m_ulHarqProcessesStatus.clear ();
248  delete m_cschedSapProvider;
249  delete m_schedSapProvider;
250  delete m_ffrSapUser;
251 }
252 
253 TypeId
255 {
256  static TypeId tid = TypeId ("ns3::PssFfMacScheduler")
258  .AddConstructor<PssFfMacScheduler> ()
259  .AddAttribute ("CqiTimerThreshold",
260  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
261  UintegerValue (1000),
262  MakeUintegerAccessor (&PssFfMacScheduler::m_cqiTimersThreshold),
263  MakeUintegerChecker<uint32_t> ())
264  .AddAttribute ("PssFdSchedulerType",
265  "FD scheduler in PSS (default value is PFsch)",
266  StringValue ("PFsch"),
267  MakeStringAccessor (&PssFfMacScheduler::m_fdSchedulerType),
268  MakeStringChecker ())
269  .AddAttribute ("nMux",
270  "The number of UE selected by TD scheduler (default value is 0)",
271  UintegerValue (0),
272  MakeUintegerAccessor (&PssFfMacScheduler::m_nMux),
273  MakeUintegerChecker<uint32_t> ())
274  .AddAttribute ("HarqEnabled",
275  "Activate/Deactivate the HARQ [by default is active].",
276  BooleanValue (true),
277  MakeBooleanAccessor (&PssFfMacScheduler::m_harqOn),
278  MakeBooleanChecker ())
279  .AddAttribute ("UlGrantMcs",
280  "The MCS of the UL grant, must be [0..15] (default 0)",
281  UintegerValue (0),
282  MakeUintegerAccessor (&PssFfMacScheduler::m_ulGrantMcs),
283  MakeUintegerChecker<uint8_t> ())
284  ;
285  return tid;
286 }
287 
288 
289 
290 void
292 {
293  m_cschedSapUser = s;
294 }
295 
296 void
298 {
299  m_schedSapUser = s;
300 }
301 
304 {
305  return m_cschedSapProvider;
306 }
307 
310 {
311  return m_schedSapProvider;
312 }
313 
314 void
316 {
318 }
319 
322 {
323  return m_ffrSapUser;
324 }
325 
326 void
328 {
329  NS_LOG_FUNCTION (this);
330  // Read the subset of parameters used
331  m_cschedCellConfig = params;
334  cnf.m_result = SUCCESS;
336  return;
337 }
338 
339 void
341 {
342  NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
343  std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
344  if (it == m_uesTxMode.end ())
345  {
346  m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
347  // generate HARQ buffers
348  m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
349  DlHarqProcessesStatus_t dlHarqPrcStatus;
350  dlHarqPrcStatus.resize (8,0);
351  m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
352  DlHarqProcessesTimer_t dlHarqProcessesTimer;
353  dlHarqProcessesTimer.resize (8,0);
354  m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
355  DlHarqProcessesDciBuffer_t dlHarqdci;
356  dlHarqdci.resize (8);
357  m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
358  DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
359  dlHarqRlcPdu.resize (2);
360  dlHarqRlcPdu.at (0).resize (8);
361  dlHarqRlcPdu.at (1).resize (8);
362  m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
363  m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
364  UlHarqProcessesStatus_t ulHarqPrcStatus;
365  ulHarqPrcStatus.resize (8,0);
366  m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
367  UlHarqProcessesDciBuffer_t ulHarqdci;
368  ulHarqdci.resize (8);
369  m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
370  }
371  else
372  {
373  (*it).second = params.m_transmissionMode;
374  }
375  return;
376 }
377 
378 void
380 {
381  NS_LOG_FUNCTION (this << " New LC, rnti: " << params.m_rnti);
382 
383  std::map <uint16_t, pssFlowPerf_t>::iterator it;
384  for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
385  {
386  it = m_flowStatsDl.find (params.m_rnti);
387 
388  if (it == m_flowStatsDl.end ())
389  {
390  double tbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateDl / 8; // byte/s
391  double tbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateUl / 8; // byte/s
392 
393  pssFlowPerf_t flowStatsDl;
394  flowStatsDl.flowStart = Simulator::Now ();
395  flowStatsDl.totalBytesTransmitted = 0;
396  flowStatsDl.lastTtiBytesTransmitted = 0;
397  flowStatsDl.lastAveragedThroughput = 1;
398  flowStatsDl.secondLastAveragedThroughput = 1;
399  flowStatsDl.targetThroughput = tbrDlInBytes;
400  m_flowStatsDl.insert (std::pair<uint16_t, pssFlowPerf_t> (params.m_rnti, flowStatsDl));
401  pssFlowPerf_t flowStatsUl;
402  flowStatsUl.flowStart = Simulator::Now ();
403  flowStatsUl.totalBytesTransmitted = 0;
404  flowStatsUl.lastTtiBytesTransmitted = 0;
405  flowStatsUl.lastAveragedThroughput = 1;
406  flowStatsUl.secondLastAveragedThroughput = 1;
407  flowStatsUl.targetThroughput = tbrUlInBytes;
408  m_flowStatsUl.insert (std::pair<uint16_t, pssFlowPerf_t> (params.m_rnti, flowStatsUl));
409  }
410  else
411  {
412  // update GBR from UeManager::SetupDataRadioBearer ()
413  double tbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateDl / 8; // byte/s
414  double tbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabGuaranteedBitrateUl / 8; // byte/s
415  m_flowStatsDl[(*it).first].targetThroughput = tbrDlInBytes;
416  m_flowStatsUl[(*it).first].targetThroughput = tbrUlInBytes;
417  }
418  }
419 
420  return;
421 }
422 
423 void
425 {
426  NS_LOG_FUNCTION (this);
427  for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
428  {
429  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
430  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
431  while (it!=m_rlcBufferReq.end ())
432  {
433  if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
434  {
435  temp = it;
436  it++;
437  m_rlcBufferReq.erase (temp);
438  }
439  else
440  {
441  it++;
442  }
443  }
444  }
445  return;
446 }
447 
448 void
450 {
451  NS_LOG_FUNCTION (this);
452 
453  m_uesTxMode.erase (params.m_rnti);
454  m_dlHarqCurrentProcessId.erase (params.m_rnti);
455  m_dlHarqProcessesStatus.erase (params.m_rnti);
456  m_dlHarqProcessesTimer.erase (params.m_rnti);
457  m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
459  m_ulHarqCurrentProcessId.erase (params.m_rnti);
460  m_ulHarqProcessesStatus.erase (params.m_rnti);
461  m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
462  m_flowStatsDl.erase (params.m_rnti);
463  m_flowStatsUl.erase (params.m_rnti);
464  m_ceBsrRxed.erase (params.m_rnti);
465  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
466  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
467  while (it!=m_rlcBufferReq.end ())
468  {
469  if ((*it).first.m_rnti == params.m_rnti)
470  {
471  temp = it;
472  it++;
473  m_rlcBufferReq.erase (temp);
474  }
475  else
476  {
477  it++;
478  }
479  }
480  if (m_nextRntiUl == params.m_rnti)
481  {
482  m_nextRntiUl = 0;
483  }
484 
485  return;
486 }
487 
488 
489 void
491 {
492  NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
493  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
494 
495  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
496 
497  LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
498 
499  it = m_rlcBufferReq.find (flow);
500 
501  if (it == m_rlcBufferReq.end ())
502  {
503  m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
504  }
505  else
506  {
507  (*it).second = params;
508  }
509 
510  return;
511 }
512 
513 void
515 {
516  NS_LOG_FUNCTION (this);
517  NS_FATAL_ERROR ("method not implemented");
518  return;
519 }
520 
521 void
523 {
524  NS_LOG_FUNCTION (this);
525  NS_FATAL_ERROR ("method not implemented");
526  return;
527 }
528 
529 int
531 {
532  for (int i = 0; i < 4; i++)
533  {
534  if (dlbandwidth < PssType0AllocationRbg[i])
535  {
536  return (i + 1);
537  }
538  }
539 
540  return (-1);
541 }
542 
543 
544 int
546 {
547  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
548  int lcActive = 0;
549  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
550  {
551  if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
552  || ((*it).second.m_rlcRetransmissionQueueSize > 0)
553  || ((*it).second.m_rlcStatusPduSize > 0) ))
554  {
555  lcActive++;
556  }
557  if ((*it).first.m_rnti > rnti)
558  {
559  break;
560  }
561  }
562  return (lcActive);
563 
564 }
565 
566 
567 uint8_t
569 {
570  NS_LOG_FUNCTION (this << rnti);
571 
572  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
573  if (it == m_dlHarqCurrentProcessId.end ())
574  {
575  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
576  }
577  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
578  if (itStat == m_dlHarqProcessesStatus.end ())
579  {
580  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
581  }
582  uint8_t i = (*it).second;
583  do
584  {
585  i = (i + 1) % HARQ_PROC_NUM;
586  }
587  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
588  if ((*itStat).second.at (i) == 0)
589  {
590  return (true);
591  }
592  else
593  {
594  return (false); // return a not valid harq proc id
595  }
596 }
597 
598 
599 
600 uint8_t
602 {
603  NS_LOG_FUNCTION (this << rnti);
604 
605  if (m_harqOn == false)
606  {
607  return (0);
608  }
609 
610 
611  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
612  if (it == m_dlHarqCurrentProcessId.end ())
613  {
614  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
615  }
616  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
617  if (itStat == m_dlHarqProcessesStatus.end ())
618  {
619  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
620  }
621  uint8_t i = (*it).second;
622  do
623  {
624  i = (i + 1) % HARQ_PROC_NUM;
625  }
626  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
627  if ((*itStat).second.at (i) == 0)
628  {
629  (*it).second = i;
630  (*itStat).second.at (i) = 1;
631  }
632  else
633  {
634  NS_FATAL_ERROR ("No HARQ process available for RNTI " << rnti << " check before update with HarqProcessAvailability");
635  }
636 
637  return ((*it).second);
638 }
639 
640 
641 void
643 {
644  NS_LOG_FUNCTION (this);
645 
646  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
647  for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
648  {
649  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
650  {
651  if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
652  {
653  // reset HARQ process
654 
655  NS_LOG_DEBUG (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
656  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
657  if (itStat == m_dlHarqProcessesStatus.end ())
658  {
659  NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
660  }
661  (*itStat).second.at (i) = 0;
662  (*itTimers).second.at (i) = 0;
663  }
664  else
665  {
666  (*itTimers).second.at (i)++;
667  }
668  }
669  }
670 
671 }
672 
673 
674 void
676 {
677  NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
678  // API generated by RLC for triggering the scheduling of a DL subframe
679 
680 
681  // evaluate the relative channel quality indicator for each UE per each RBG
682  // (since we are using allocation type 0 the small unit of allocation is RBG)
683  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
684 
685  RefreshDlCqiMaps ();
686 
688  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
689  std::map <uint16_t, std::vector <uint16_t> > allocationMap; // RBs map per RNTI
690  std::vector <bool> rbgMap; // global RBGs map
691  uint16_t rbgAllocatedNum = 0;
692  std::set <uint16_t> rntiAllocated;
693  rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
694 
695  rbgMap = m_ffrSapProvider->GetAvailableDlRbg ();
696  for (std::vector<bool>::iterator it = rbgMap.begin (); it != rbgMap.end (); it++)
697  {
698  if ((*it) == true )
699  {
700  rbgAllocatedNum++;
701  }
702  }
703 
705 
706  // update UL HARQ proc id
707  std::map <uint16_t, uint8_t>::iterator itProcId;
708  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
709  {
710  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
711  }
712 
713  // RACH Allocation
714  uint16_t rbAllocatedNum = 0;
715  std::vector <bool> ulRbMap;
716  ulRbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
717  ulRbMap = m_ffrSapProvider->GetAvailableUlRbg ();
718  uint8_t maxContinuousUlBandwidth = 0;
719  uint8_t tmpMinBandwidth = 0;
720  uint16_t ffrRbStartOffset = 0;
721  uint16_t tmpFfrRbStartOffset = 0;
722  uint16_t index = 0;
723 
724  for (std::vector<bool>::iterator it = ulRbMap.begin (); it != ulRbMap.end (); it++)
725  {
726  if ((*it) == true )
727  {
728  rbAllocatedNum++;
729  if (tmpMinBandwidth > maxContinuousUlBandwidth)
730  {
731  maxContinuousUlBandwidth = tmpMinBandwidth;
732  ffrRbStartOffset = tmpFfrRbStartOffset;
733  }
734  tmpMinBandwidth = 0;
735  }
736  else
737  {
738  if (tmpMinBandwidth == 0)
739  {
740  tmpFfrRbStartOffset = index;
741  }
742  tmpMinBandwidth++;
743  }
744  index++;
745  }
746 
747  if (tmpMinBandwidth > maxContinuousUlBandwidth)
748  {
749  maxContinuousUlBandwidth = tmpMinBandwidth;
750  ffrRbStartOffset = tmpFfrRbStartOffset;
751  }
752 
754  uint16_t rbStart = 0;
755  rbStart = ffrRbStartOffset;
756  std::vector <struct RachListElement_s>::iterator itRach;
757  for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
758  {
759  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");
760  BuildRarListElement_s newRar;
761  newRar.m_rnti = (*itRach).m_rnti;
762  // DL-RACH Allocation
763  // Ideal: no needs of configuring m_dci
764  // UL-RACH Allocation
765  newRar.m_grant.m_rnti = newRar.m_rnti;
766  newRar.m_grant.m_mcs = m_ulGrantMcs;
767  uint16_t rbLen = 1;
768  uint16_t tbSizeBits = 0;
769  // find lowest TB size that fits UL grant estimated size
770  while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
771  {
772  rbLen++;
773  tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
774  }
775  if (tbSizeBits < (*itRach).m_estimatedSize)
776  {
777  // no more allocation space: finish allocation
778  break;
779  }
780  newRar.m_grant.m_rbStart = rbStart;
781  newRar.m_grant.m_rbLen = rbLen;
782  newRar.m_grant.m_tbSize = tbSizeBits / 8;
783  newRar.m_grant.m_hopping = false;
784  newRar.m_grant.m_tpc = 0;
785  newRar.m_grant.m_cqiRequest = false;
786  newRar.m_grant.m_ulDelay = false;
787  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);
788  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
789  {
790  m_rachAllocationMap.at (i) = (*itRach).m_rnti;
791  }
792 
793  if (m_harqOn == true)
794  {
795  // generate UL-DCI for HARQ retransmissions
796  UlDciListElement_s uldci;
797  uldci.m_rnti = newRar.m_rnti;
798  uldci.m_rbLen = rbLen;
799  uldci.m_rbStart = rbStart;
800  uldci.m_mcs = m_ulGrantMcs;
801  uldci.m_tbSize = tbSizeBits / 8;
802  uldci.m_ndi = 1;
803  uldci.m_cceIndex = 0;
804  uldci.m_aggrLevel = 1;
805  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
806  uldci.m_hopping = false;
807  uldci.m_n2Dmrs = 0;
808  uldci.m_tpc = 0; // no power control
809  uldci.m_cqiRequest = false; // only period CQI at this stage
810  uldci.m_ulIndex = 0; // TDD parameter
811  uldci.m_dai = 1; // TDD parameter
812  uldci.m_freqHopping = 0;
813  uldci.m_pdcchPowerOffset = 0; // not used
814 
815  uint8_t harqId = 0;
816  std::map <uint16_t, uint8_t>::iterator itProcId;
817  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
818  if (itProcId == m_ulHarqCurrentProcessId.end ())
819  {
820  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
821  }
822  harqId = (*itProcId).second;
823  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
824  if (itDci == m_ulHarqProcessesDciBuffer.end ())
825  {
826  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
827  }
828  (*itDci).second.at (harqId) = uldci;
829  }
830 
831  rbStart = rbStart + rbLen;
832  ret.m_buildRarList.push_back (newRar);
833  }
834  m_rachList.clear ();
835 
836 
837  // Process DL HARQ feedback
839  // retrieve past HARQ retx buffered
840  if (m_dlInfoListBuffered.size () > 0)
841  {
842  if (params.m_dlInfoList.size () > 0)
843  {
844  NS_LOG_INFO (this << " Received DL-HARQ feedback");
845  m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
846  }
847  }
848  else
849  {
850  if (params.m_dlInfoList.size () > 0)
851  {
853  }
854  }
855  if (m_harqOn == false)
856  {
857  // Ignore HARQ feedback
858  m_dlInfoListBuffered.clear ();
859  }
860  std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
861  for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
862  {
863  std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
864  if (itRnti != rntiAllocated.end ())
865  {
866  // RNTI already allocated for retx
867  continue;
868  }
869  uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
870  std::vector <bool> retx;
871  NS_LOG_INFO (this << " Processing DLHARQ feedback");
872  if (nLayers == 1)
873  {
874  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
875  retx.push_back (false);
876  }
877  else
878  {
879  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
880  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
881  }
882  if (retx.at (0) || retx.at (1))
883  {
884  // retrieve HARQ process information
885  uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
886  uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
887  NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
888  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
889  if (itHarq == m_dlHarqProcessesDciBuffer.end ())
890  {
891  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << rnti);
892  }
893 
894  DlDciListElement_s dci = (*itHarq).second.at (harqId);
895  int rv = 0;
896  if (dci.m_rv.size () == 1)
897  {
898  rv = dci.m_rv.at (0);
899  }
900  else
901  {
902  rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
903  }
904 
905  if (rv == 3)
906  {
907  // maximum number of retx reached -> drop process
908  NS_LOG_INFO ("Maximum number of retransmissions reached -> drop process");
909  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
910  if (it == m_dlHarqProcessesStatus.end ())
911  {
912  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
913  }
914  (*it).second.at (harqId) = 0;
915  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
916  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
917  {
918  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
919  }
920  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
921  {
922  (*itRlcPdu).second.at (k).at (harqId).clear ();
923  }
924  continue;
925  }
926  // check the feasibility of retransmitting on the same RBGs
927  // translate the DCI to Spectrum framework
928  std::vector <int> dciRbg;
929  uint32_t mask = 0x1;
930  NS_LOG_INFO ("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
931  for (int j = 0; j < 32; j++)
932  {
933  if (((dci.m_rbBitmap & mask) >> j) == 1)
934  {
935  dciRbg.push_back (j);
936  NS_LOG_INFO ("\t" << j);
937  }
938  mask = (mask << 1);
939  }
940  bool free = true;
941  for (uint8_t j = 0; j < dciRbg.size (); j++)
942  {
943  if (rbgMap.at (dciRbg.at (j)) == true)
944  {
945  free = false;
946  break;
947  }
948  }
949  if (free)
950  {
951  // use the same RBGs for the retx
952  // reserve RBGs
953  for (uint8_t j = 0; j < dciRbg.size (); j++)
954  {
955  rbgMap.at (dciRbg.at (j)) = true;
956  NS_LOG_INFO ("RBG " << dciRbg.at (j) << " assigned");
957  rbgAllocatedNum++;
958  }
959 
960  NS_LOG_INFO (this << " Send retx in the same RBGs");
961  }
962  else
963  {
964  // find RBGs for sending HARQ retx
965  uint8_t j = 0;
966  uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
967  uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
968  std::vector <bool> rbgMapCopy = rbgMap;
969  while ((j < dciRbg.size ())&&(startRbg != rbgId))
970  {
971  if (rbgMapCopy.at (rbgId) == false)
972  {
973  rbgMapCopy.at (rbgId) = true;
974  dciRbg.at (j) = rbgId;
975  j++;
976  }
977  rbgId = (rbgId + 1) % rbgNum;
978  }
979  if (j == dciRbg.size ())
980  {
981  // find new RBGs -> update DCI map
982  uint32_t rbgMask = 0;
983  for (uint16_t k = 0; k < dciRbg.size (); k++)
984  {
985  rbgMask = rbgMask + (0x1 << dciRbg.at (k));
986  rbgAllocatedNum++;
987  }
988  dci.m_rbBitmap = rbgMask;
989  rbgMap = rbgMapCopy;
990  NS_LOG_INFO (this << " Move retx in RBGs " << dciRbg.size ());
991  }
992  else
993  {
994  // HARQ retx cannot be performed on this TTI -> store it
995  dlInfoListUntxed.push_back (m_dlInfoListBuffered.at (i));
996  NS_LOG_INFO (this << " No resource for this retx -> buffer it");
997  }
998  }
999  // retrieve RLC PDU list for retx TBsize and update DCI
1000  BuildDataListElement_s newEl;
1001  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
1002  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1003  {
1004  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
1005  }
1006  for (uint8_t j = 0; j < nLayers; j++)
1007  {
1008  if (retx.at (j))
1009  {
1010  if (j >= dci.m_ndi.size ())
1011  {
1012  // for avoiding errors in MIMO transient phases
1013  dci.m_ndi.push_back (0);
1014  dci.m_rv.push_back (0);
1015  dci.m_mcs.push_back (0);
1016  dci.m_tbsSize.push_back (0);
1017  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no txed (MIMO transition)");
1018  }
1019  else
1020  {
1021  dci.m_ndi.at (j) = 0;
1022  dci.m_rv.at (j)++;
1023  (*itHarq).second.at (harqId).m_rv.at (j)++;
1024  NS_LOG_INFO (this << " layer " << (uint16_t)j << " RV " << (uint16_t)dci.m_rv.at (j));
1025  }
1026  }
1027  else
1028  {
1029  // empty TB of layer j
1030  dci.m_ndi.at (j) = 0;
1031  dci.m_rv.at (j) = 0;
1032  dci.m_mcs.at (j) = 0;
1033  dci.m_tbsSize.at (j) = 0;
1034  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no retx");
1035  }
1036  }
1037  for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
1038  {
1039  std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
1040  for (uint8_t j = 0; j < nLayers; j++)
1041  {
1042  if (retx.at (j))
1043  {
1044  if (j < dci.m_ndi.size ())
1045  {
1046  rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
1047  }
1048  }
1049  }
1050 
1051  if (rlcPduListPerLc.size () > 0)
1052  {
1053  newEl.m_rlcPduList.push_back (rlcPduListPerLc);
1054  }
1055  }
1056  newEl.m_rnti = rnti;
1057  newEl.m_dci = dci;
1058  (*itHarq).second.at (harqId).m_rv = dci.m_rv;
1059  // refresh timer
1060  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
1061  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1062  {
1063  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
1064  }
1065  (*itHarqTimer).second.at (harqId) = 0;
1066  ret.m_buildDataList.push_back (newEl);
1067  rntiAllocated.insert (rnti);
1068  }
1069  else
1070  {
1071  // update HARQ process status
1072  NS_LOG_INFO (this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
1073  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
1074  if (it == m_dlHarqProcessesStatus.end ())
1075  {
1076  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
1077  }
1078  (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
1079  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
1080  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1081  {
1082  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
1083  }
1084  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
1085  {
1086  (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
1087  }
1088  }
1089  }
1090  m_dlInfoListBuffered.clear ();
1091  m_dlInfoListBuffered = dlInfoListUntxed;
1092 
1093  if (rbgAllocatedNum == rbgNum)
1094  {
1095  // all the RBGs are already allocated -> exit
1096  if ((ret.m_buildDataList.size () > 0) || (ret.m_buildRarList.size () > 0))
1097  {
1099  }
1100  return;
1101  }
1102 
1103 
1104  std::map <uint16_t, pssFlowPerf_t>::iterator it;
1105  std::map <uint16_t, pssFlowPerf_t> tdUeSet; // the result of TD scheduler
1106 
1107  // schedulability check
1108  std::map <uint16_t, pssFlowPerf_t> ueSet;
1109  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
1110  {
1111  if( LcActivePerFlow ((*it).first) > 0 )
1112  {
1113  ueSet.insert(std::pair <uint16_t, pssFlowPerf_t> ((*it).first, (*it).second));
1114  }
1115  }
1116 
1117  if (ueSet.size() != 0)
1118  { // has data in RLC buffer
1119 
1120  // Time Domain scheduler
1121  std::vector <std::pair<double, uint16_t> > ueSet1;
1122  std::vector <std::pair<double,uint16_t> > ueSet2;
1123  for (it = ueSet.begin (); it != ueSet.end (); it++)
1124  {
1125  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1126  if ((itRnti != rntiAllocated.end ())||(!HarqProcessAvailability ((*it).first)))
1127  {
1128  // UE already allocated for HARQ or without HARQ process available -> drop it
1129  if (itRnti != rntiAllocated.end ())
1130  {
1131  NS_LOG_DEBUG (this << " RNTI discared for HARQ tx" << (uint16_t)(*it).first);
1132  }
1133  if (!HarqProcessAvailability ((*it).first))
1134  {
1135  NS_LOG_DEBUG (this << " RNTI discared for HARQ id" << (uint16_t)(*it).first);
1136  }
1137  continue;
1138  }
1139 
1140  double metric = 0.0;
1141  if ((*it).second.lastAveragedThroughput < (*it).second.targetThroughput )
1142  {
1143  // calculate TD BET metric
1144  metric = 1 / (*it).second.lastAveragedThroughput;
1145  ueSet1.push_back(std::pair<double, uint16_t> (metric, (*it).first));
1146  }
1147  else
1148  {
1149  // calculate TD PF metric
1150  std::map <uint16_t,uint8_t>::iterator itCqi;
1151  itCqi = m_p10CqiRxed.find ((*it).first);
1152  std::map <uint16_t,uint8_t>::iterator itTxMode;
1153  itTxMode = m_uesTxMode.find ((*it).first);
1154  if (itTxMode == m_uesTxMode.end())
1155  {
1156  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1157  }
1158  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1159  uint8_t wbCqi = 0;
1160  if (itCqi == m_p10CqiRxed.end())
1161  {
1162  wbCqi = 1; // start with lowest value
1163  }
1164  else
1165  {
1166  wbCqi = (*itCqi).second;
1167  }
1168 
1169  if (wbCqi > 0)
1170  {
1171  if (LcActivePerFlow ((*it).first) > 0)
1172  {
1173  // this UE has data to transmit
1174  double achievableRate = 0.0;
1175  for (uint8_t k = 0; k < nLayer; k++)
1176  {
1177  uint8_t mcs = 0;
1178  mcs = m_amc->GetMcsFromCqi (wbCqi);
1179  achievableRate += ((m_amc->GetTbSizeFromMcs (mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1180  }
1181 
1182  metric = achievableRate / (*it).second.lastAveragedThroughput;
1183  }
1184  } // end of wbCqi
1185 
1186  ueSet2.push_back(std::pair<double, uint16_t> (metric, (*it).first));
1187  }
1188  }// end of ueSet
1189 
1190 
1191  if (ueSet1.size () != 0 || ueSet2.size () != 0)
1192  {
1193  // sorting UE in ueSet1 and ueSet1 in descending order based on their metric value
1194  std::sort (ueSet1.rbegin (), ueSet1.rend ());
1195  std::sort (ueSet2.rbegin (), ueSet2.rend ());
1196 
1197  // select UE set for frequency domain scheduler
1198  uint32_t nMux;
1199  if ( m_nMux > 0)
1200  nMux = m_nMux;
1201  else
1202  {
1203  // select half number of UE
1204  if (ueSet1.size() + ueSet2.size() <=2 )
1205  nMux = 1;
1206  else
1207  nMux = (int)((ueSet1.size() + ueSet2.size()) / 2) ; // TD scheduler only transfers half selected UE per RTT to TD scheduler
1208  }
1209  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it--)
1210  {
1211  std::vector <std::pair<double, uint16_t> >::iterator itSet;
1212  for (itSet = ueSet1.begin (); itSet != ueSet1.end () && nMux != 0; itSet++)
1213  {
1214  std::map <uint16_t, pssFlowPerf_t>::iterator itUe;
1215  itUe = m_flowStatsDl.find((*itSet).second);
1216  tdUeSet.insert(std::pair<uint16_t, pssFlowPerf_t> ( (*itUe).first, (*itUe).second ) );
1217  nMux--;
1218  }
1219 
1220  if (nMux == 0)
1221  break;
1222 
1223  for (itSet = ueSet2.begin (); itSet != ueSet2.end () && nMux != 0; itSet++)
1224  {
1225  std::map <uint16_t, pssFlowPerf_t>::iterator itUe;
1226  itUe = m_flowStatsDl.find((*itSet).second);
1227  tdUeSet.insert(std::pair<uint16_t, pssFlowPerf_t> ( (*itUe).first, (*itUe).second ) );
1228  nMux--;
1229  }
1230 
1231  if (nMux == 0)
1232  break;
1233 
1234  } // end of m_flowStatsDl
1235 
1236 
1237  if ( m_fdSchedulerType.compare("CoItA") == 0)
1238  {
1239  // FD scheduler: Carrier over Interference to Average (CoItA)
1240  std::map < uint16_t, uint8_t > sbCqiSum;
1241  for (it = tdUeSet.begin (); it != tdUeSet.end (); it++)
1242  {
1243  uint8_t sum = 0;
1244  for (int i = 0; i < rbgNum; i++)
1245  {
1246  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1247  itCqi = m_a30CqiRxed.find ((*it).first);
1248  std::map <uint16_t,uint8_t>::iterator itTxMode;
1249  itTxMode = m_uesTxMode.find ((*it).first);
1250  if (itTxMode == m_uesTxMode.end ())
1251  {
1252  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1253  }
1254  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1255  std::vector <uint8_t> sbCqis;
1256  if (itCqi == m_a30CqiRxed.end ())
1257  {
1258  for (uint8_t k = 0; k < nLayer; k++)
1259  {
1260  sbCqis.push_back (1); // start with lowest value
1261  }
1262  }
1263  else
1264  {
1265  sbCqis = (*itCqi).second.m_higherLayerSelected.at (i).m_sbCqi;
1266  }
1267 
1268  uint8_t cqi1 = sbCqis.at (0);
1269  uint8_t cqi2 = 1;
1270  if (sbCqis.size () > 1)
1271  {
1272  cqi2 = sbCqis.at (1);
1273  }
1274 
1275  uint8_t sbCqi;
1276  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1277  {
1278  for (uint8_t k = 0; k < nLayer; k++)
1279  {
1280  if (sbCqis.size () > k)
1281  {
1282  sbCqi = sbCqis.at(k);
1283  }
1284  else
1285  {
1286  // no info on this subband
1287  sbCqi = 0;
1288  }
1289  sum += sbCqi;
1290  }
1291  } // end if cqi
1292  }// end of rbgNum
1293 
1294  sbCqiSum.insert (std::pair<uint16_t, uint8_t> ((*it).first, sum));
1295  }// end tdUeSet
1296 
1297  for (int i = 0; i < rbgNum; i++)
1298  {
1299  if (rbgMap.at (i) == true)
1300  continue;
1301  if ((m_ffrSapProvider->IsDlRbgAvailableForUe (i, (*it).first)) == false)
1302  continue;
1303 
1304  std::map <uint16_t, pssFlowPerf_t>::iterator itMax = tdUeSet.end ();
1305  double metricMax = 0.0;
1306  for (it = tdUeSet.begin (); it != tdUeSet.end (); it++)
1307  {
1308  // calculate PF weigth
1309  double weight = (*it).second.targetThroughput / (*it).second.lastAveragedThroughput;
1310  if (weight < 1.0)
1311  weight = 1.0;
1312 
1313  std::map < uint16_t, uint8_t>::iterator itSbCqiSum;
1314  itSbCqiSum = sbCqiSum.find((*it).first);
1315 
1316  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1317  itCqi = m_a30CqiRxed.find ((*it).first);
1318  std::map <uint16_t,uint8_t>::iterator itTxMode;
1319  itTxMode = m_uesTxMode.find ((*it).first);
1320  if (itTxMode == m_uesTxMode.end())
1321  {
1322  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1323  }
1324  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1325  std::vector <uint8_t> sbCqis;
1326  if (itCqi == m_a30CqiRxed.end ())
1327  {
1328  for (uint8_t k = 0; k < nLayer; k++)
1329  {
1330  sbCqis.push_back (1); // start with lowest value
1331  }
1332  }
1333  else
1334  {
1335  sbCqis = (*itCqi).second.m_higherLayerSelected.at (i).m_sbCqi;
1336  }
1337 
1338  uint8_t cqi1 = sbCqis.at( 0);
1339  uint8_t cqi2 = 1;
1340  if (sbCqis.size () > 1)
1341  {
1342  cqi2 = sbCqis.at(1);
1343  }
1344 
1345  uint8_t sbCqi;
1346  double colMetric = 0.0;
1347  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1348  {
1349  for (uint8_t k = 0; k < nLayer; k++)
1350  {
1351  if (sbCqis.size () > k)
1352  {
1353  sbCqi = sbCqis.at(k);
1354  }
1355  else
1356  {
1357  // no info on this subband
1358  sbCqi = 0;
1359  }
1360  colMetric += (double)sbCqi / (double)(*itSbCqiSum).second;
1361  }
1362  } // end if cqi
1363 
1364  double metric = 0.0;
1365  if (colMetric != 0)
1366  metric= weight * colMetric;
1367  else
1368  metric = 1;
1369 
1370  if (metric > metricMax )
1371  {
1372  metricMax = metric;
1373  itMax = it;
1374  }
1375  } // end of tdUeSet
1376 
1377  if (itMax == m_flowStatsDl.end ())
1378  {
1379  // no UE available for downlink
1380  return;
1381  }
1382  else
1383  {
1384  allocationMap[(*itMax).first].push_back (i);
1385  rbgMap.at (i) = true;
1386  }
1387  }// end of rbgNum
1388 
1389  }// end of CoIta
1390 
1391 
1392  if ( m_fdSchedulerType.compare("PFsch") == 0)
1393  {
1394  // FD scheduler: Proportional Fair scheduled (PFsch)
1395  for (int i = 0; i < rbgNum; i++)
1396  {
1397  if (rbgMap.at (i) == true)
1398  continue;
1399 
1400  if ((m_ffrSapProvider->IsDlRbgAvailableForUe (i, (*it).first)) == false)
1401  continue;
1402 
1403  std::map <uint16_t, pssFlowPerf_t>::iterator itMax = tdUeSet.end ();
1404  double metricMax = 0.0;
1405  for (it = tdUeSet.begin (); it != tdUeSet.end (); it++)
1406  {
1407  // calculate PF weigth
1408  double weight = (*it).second.targetThroughput / (*it).second.lastAveragedThroughput;
1409  if (weight < 1.0)
1410  weight = 1.0;
1411 
1412  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1413  itCqi = m_a30CqiRxed.find ((*it).first);
1414  std::map <uint16_t,uint8_t>::iterator itTxMode;
1415  itTxMode = m_uesTxMode.find ((*it).first);
1416  if (itTxMode == m_uesTxMode.end())
1417  {
1418  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1419  }
1420  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1421  std::vector <uint8_t> sbCqis;
1422  if (itCqi == m_a30CqiRxed.end ())
1423  {
1424  for (uint8_t k = 0; k < nLayer; k++)
1425  {
1426  sbCqis.push_back (1); // start with lowest value
1427  }
1428  }
1429  else
1430  {
1431  sbCqis = (*itCqi).second.m_higherLayerSelected.at (i).m_sbCqi;
1432  }
1433 
1434  uint8_t cqi1 = sbCqis.at(0);
1435  uint8_t cqi2 = 1;
1436  if (sbCqis.size () > 1)
1437  {
1438  cqi2 = sbCqis.at(1);
1439  }
1440 
1441  double schMetric = 0.0;
1442  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1443  {
1444  double achievableRate = 0.0;
1445  for (uint8_t k = 0; k < nLayer; k++)
1446  {
1447  uint8_t mcs = 0;
1448  if (sbCqis.size () > k)
1449  {
1450  mcs = m_amc->GetMcsFromCqi (sbCqis.at (k));
1451  }
1452  else
1453  {
1454  // no info on this subband -> worst MCS
1455  mcs = 0;
1456  }
1457  achievableRate += ((m_amc->GetTbSizeFromMcs (mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1458  }
1459  schMetric = achievableRate / (*it).second.secondLastAveragedThroughput;
1460  } // end if cqi
1461 
1462  double metric = 0.0;
1463  metric= weight * schMetric;
1464 
1465  if (metric > metricMax )
1466  {
1467  metricMax = metric;
1468  itMax = it;
1469  }
1470  } // end of tdUeSet
1471 
1472  if (itMax == m_flowStatsDl.end ())
1473  {
1474  // no UE available for downlink
1475  return;
1476  }
1477  else
1478  {
1479  allocationMap[(*itMax).first].push_back (i);
1480  rbgMap.at (i) = true;
1481  }
1482 
1483  }// end of rbgNum
1484 
1485  } // end of PFsch
1486 
1487  } // end if ueSet1 || ueSet2
1488 
1489  } // end if ueSet
1490 
1491 
1492 
1493  // reset TTI stats of users
1494  std::map <uint16_t, pssFlowPerf_t>::iterator itStats;
1495  for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1496  {
1497  (*itStats).second.lastTtiBytesTransmitted = 0;
1498  }
1499 
1500  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1501  // creating the correspondent DCIs
1502  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1503  while (itMap != allocationMap.end ())
1504  {
1505  // create new BuildDataListElement_s for this LC
1506  BuildDataListElement_s newEl;
1507  newEl.m_rnti = (*itMap).first;
1508  // create the DlDciListElement_s
1509  DlDciListElement_s newDci;
1510  newDci.m_rnti = (*itMap).first;
1511  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1512 
1513  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1514  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1515  if (lcActives == 0)
1516  {
1517  // Set to max value, to avoid divide by 0 below
1518  lcActives = (uint16_t)65535; // UINT16_MAX;
1519  }
1520  uint16_t RgbPerRnti = (*itMap).second.size ();
1521  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1522  itCqi = m_a30CqiRxed.find ((*itMap).first);
1523  std::map <uint16_t,uint8_t>::iterator itTxMode;
1524  itTxMode = m_uesTxMode.find ((*itMap).first);
1525  if (itTxMode == m_uesTxMode.end ())
1526  {
1527  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1528  }
1529  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1530  std::vector <uint8_t> worstCqi (2, 15);
1531  if (itCqi != m_a30CqiRxed.end ())
1532  {
1533  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1534  {
1535  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1536  {
1537  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)) );
1538  for (uint8_t j = 0; j < nLayer; j++)
1539  {
1540  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1541  {
1542  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1543  {
1544  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1545  }
1546  }
1547  else
1548  {
1549  // no CQI for this layer of this suband -> worst one
1550  worstCqi.at (j) = 1;
1551  }
1552  }
1553  }
1554  else
1555  {
1556  for (uint8_t j = 0; j < nLayer; j++)
1557  {
1558  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1559  }
1560  }
1561  }
1562  }
1563  else
1564  {
1565  for (uint8_t j = 0; j < nLayer; j++)
1566  {
1567  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1568  }
1569  }
1570  for (uint8_t j = 0; j < nLayer; j++)
1571  {
1572  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " CQI selected " << (uint16_t)worstCqi.at (j));
1573  }
1574  uint32_t bytesTxed = 0;
1575  for (uint8_t j = 0; j < nLayer; j++)
1576  {
1577  newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1578  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)
1579  newDci.m_tbsSize.push_back (tbSize);
1580  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " MCS selected" << m_amc->GetMcsFromCqi (worstCqi.at (j)));
1581  bytesTxed += tbSize;
1582  }
1583 
1584  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1585  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1586  uint32_t rbgMask = 0;
1587  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1588  {
1589  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1590  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1591  }
1592  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1593 
1594  // create the rlc PDUs -> equally divide resources among actives LCs
1595  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1596  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1597  {
1598  if (((*itBufReq).first.m_rnti == (*itMap).first)
1599  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1600  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1601  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1602  {
1603  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1604  for (uint8_t j = 0; j < nLayer; j++)
1605  {
1606  RlcPduListElement_s newRlcEl;
1607  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1608  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1609  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1610  newRlcPduLe.push_back (newRlcEl);
1611  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1612  if (m_harqOn == true)
1613  {
1614  // store RLC PDU list for HARQ
1615  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1616  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1617  {
1618  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1619  }
1620  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1621  }
1622  }
1623  newEl.m_rlcPduList.push_back (newRlcPduLe);
1624  }
1625  if ((*itBufReq).first.m_rnti > (*itMap).first)
1626  {
1627  break;
1628  }
1629  }
1630  for (uint8_t j = 0; j < nLayer; j++)
1631  {
1632  newDci.m_ndi.push_back (1);
1633  newDci.m_rv.push_back (0);
1634  }
1635 
1636  newDci.m_tpc = m_ffrSapProvider->GetTpc ((*itMap).first);
1637 
1638  newEl.m_dci = newDci;
1639 
1640  if (m_harqOn == true)
1641  {
1642  // store DCI for HARQ
1643  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1644  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1645  {
1646  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1647  }
1648  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1649  // refresh timer
1650  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1651  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1652  {
1653  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1654  }
1655  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1656  }
1657 
1658  // ...more parameters -> ingored in this version
1659 
1660  ret.m_buildDataList.push_back (newEl);
1661  // update UE stats
1662  std::map <uint16_t, pssFlowPerf_t>::iterator it;
1663  it = m_flowStatsDl.find ((*itMap).first);
1664  if (it != m_flowStatsDl.end ())
1665  {
1666  (*it).second.lastTtiBytesTransmitted = bytesTxed;
1667  NS_LOG_INFO (this << " UE total bytes txed " << (*it).second.lastTtiBytesTransmitted);
1668 
1669 
1670  }
1671  else
1672  {
1673  NS_FATAL_ERROR (this << " No Stats for this allocated UE");
1674  }
1675 
1676  itMap++;
1677  } // end while allocation
1678  ret.m_nrOfPdcchOfdmSymbols = 1;
1679 
1680 
1681  // update UEs stats
1682  NS_LOG_INFO (this << " Update UEs statistics");
1683  for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1684  {
1685  std::map <uint16_t, pssFlowPerf_t>::iterator itUeScheduleted = tdUeSet.end();
1686  itUeScheduleted = tdUeSet.find((*itStats).first);
1687  if (itUeScheduleted != tdUeSet.end())
1688  {
1689  (*itStats).second.secondLastAveragedThroughput = ((1.0 - (1 / m_timeWindow)) * (*itStats).second.secondLastAveragedThroughput) + ((1 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1690  }
1691 
1692  (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1693  // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term Evolution, Ed Wiley)
1694  (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1695  (*itStats).second.lastTtiBytesTransmitted = 0;
1696  }
1697 
1698 
1700 
1701 
1702  return;
1703 }
1704 
1705 void
1707 {
1708  NS_LOG_FUNCTION (this);
1709 
1710  m_rachList = params.m_rachList;
1711 
1712  return;
1713 }
1714 
1715 void
1717 {
1718  NS_LOG_FUNCTION (this);
1720 
1721  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1722  {
1723  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1724  {
1725  // wideband CQI reporting
1726  std::map <uint16_t,uint8_t>::iterator it;
1727  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1728  it = m_p10CqiRxed.find (rnti);
1729  if (it == m_p10CqiRxed.end ())
1730  {
1731  // create the new entry
1732  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)
1733  // generate correspondent timer
1734  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1735  }
1736  else
1737  {
1738  // update the CQI value and refresh correspondent timer
1739  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1740  // update correspondent timer
1741  std::map <uint16_t,uint32_t>::iterator itTimers;
1742  itTimers = m_p10CqiTimers.find (rnti);
1743  (*itTimers).second = m_cqiTimersThreshold;
1744  }
1745  }
1746  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1747  {
1748  // subband CQI reporting high layer configured
1749  std::map <uint16_t,SbMeasResult_s>::iterator it;
1750  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1751  it = m_a30CqiRxed.find (rnti);
1752  if (it == m_a30CqiRxed.end ())
1753  {
1754  // create the new entry
1755  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1756  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1757  }
1758  else
1759  {
1760  // update the CQI value and refresh correspondent timer
1761  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1762  std::map <uint16_t,uint32_t>::iterator itTimers;
1763  itTimers = m_a30CqiTimers.find (rnti);
1764  (*itTimers).second = m_cqiTimersThreshold;
1765  }
1766  }
1767  else
1768  {
1769  NS_LOG_ERROR (this << " CQI type unknown");
1770  }
1771  }
1772 
1773  return;
1774 }
1775 
1776 
1777 double
1778 PssFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1779 {
1780  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1781  if (itCqi == m_ueCqi.end ())
1782  {
1783  // no cqi info about this UE
1784  return (NO_SINR);
1785 
1786  }
1787  else
1788  {
1789  // take the average SINR value among the available
1790  double sinrSum = 0;
1791  int sinrNum = 0;
1792  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1793  {
1794  double sinr = (*itCqi).second.at (i);
1795  if (sinr != NO_SINR)
1796  {
1797  sinrSum += sinr;
1798  sinrNum++;
1799  }
1800  }
1801  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1802  // store the value
1803  (*itCqi).second.at (rb) = estimatedSinr;
1804  return (estimatedSinr);
1805  }
1806 }
1807 
1808 void
1810 {
1811  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1812 
1813  RefreshUlCqiMaps ();
1815 
1816  // Generate RBs map
1818  std::vector <bool> rbMap;
1819  uint16_t rbAllocatedNum = 0;
1820  std::set <uint16_t> rntiAllocated;
1821  std::vector <uint16_t> rbgAllocationMap;
1822  // update with RACH allocation map
1823  rbgAllocationMap = m_rachAllocationMap;
1824  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1825  m_rachAllocationMap.clear ();
1827 
1828  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1829 
1830  rbMap = m_ffrSapProvider->GetAvailableUlRbg ();
1831 
1832  for (std::vector<bool>::iterator it = rbMap.begin (); it != rbMap.end (); it++)
1833  {
1834  if ((*it) == true )
1835  {
1836  rbAllocatedNum++;
1837  }
1838  }
1839 
1840  uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth ();
1841  uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1842 
1843 
1844  // remove RACH allocation
1845  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1846  {
1847  if (rbgAllocationMap.at (i) != 0)
1848  {
1849  rbMap.at (i) = true;
1850  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1851  }
1852  }
1853 
1854 
1855  if (m_harqOn == true)
1856  {
1857  // Process UL HARQ feedback
1858  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1859  {
1860  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1861  {
1862  // retx correspondent block: retrieve the UL-DCI
1863  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1864  std::map <uint16_t, uint8_t>::iterator itProcId = m_ulHarqCurrentProcessId.find (rnti);
1865  if (itProcId == m_ulHarqCurrentProcessId.end ())
1866  {
1867  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1868  }
1869  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1870  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1871  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1872  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1873  {
1874  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1875  continue;
1876  }
1877  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1878  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1879  if (itStat == m_ulHarqProcessesStatus.end ())
1880  {
1881  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1882  }
1883  if ((*itStat).second.at (harqId) >= 3)
1884  {
1885  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1886  continue;
1887  }
1888  bool free = true;
1889  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1890  {
1891  if (rbMap.at (j) == true)
1892  {
1893  free = false;
1894  NS_LOG_INFO (this << " BUSY " << j);
1895  }
1896  }
1897  if (free)
1898  {
1899  // retx on the same RBs
1900  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1901  {
1902  rbMap.at (j) = true;
1903  rbgAllocationMap.at (j) = dci.m_rnti;
1904  NS_LOG_INFO ("\tRB " << j);
1905  rbAllocatedNum++;
1906  }
1907  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);
1908  }
1909  else
1910  {
1911  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1912  continue;
1913  }
1914  dci.m_ndi = 0;
1915  // Update HARQ buffers with new HarqId
1916  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1917  (*itStat).second.at (harqId) = 0;
1918  (*itHarq).second.at ((*itProcId).second) = dci;
1919  ret.m_dciList.push_back (dci);
1920  rntiAllocated.insert (dci.m_rnti);
1921  }
1922  else
1923  {
1924  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1925  }
1926  }
1927  }
1928 
1929  std::map <uint16_t,uint32_t>::iterator it;
1930  int nflows = 0;
1931 
1932  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1933  {
1934  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1935  // select UEs with queues not empty and not yet allocated for HARQ
1936  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1937  {
1938  nflows++;
1939  }
1940  }
1941 
1942  if (nflows == 0)
1943  {
1944  if (ret.m_dciList.size () > 0)
1945  {
1946  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1948  }
1949 
1950  return; // no flows to be scheduled
1951  }
1952 
1953 
1954  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1955  uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size ());
1956  uint16_t rbPerFlow = (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1957 
1958  if (rbPerFlow < 3)
1959  {
1960  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1961  }
1962  int rbAllocated = 0;
1963 
1964  std::map <uint16_t, pssFlowPerf_t>::iterator itStats;
1965  if (m_nextRntiUl != 0)
1966  {
1967  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1968  {
1969  if ((*it).first == m_nextRntiUl)
1970  {
1971  break;
1972  }
1973  }
1974  if (it == m_ceBsrRxed.end ())
1975  {
1976  NS_LOG_ERROR (this << " no user found");
1977  }
1978  }
1979  else
1980  {
1981  it = m_ceBsrRxed.begin ();
1982  m_nextRntiUl = (*it).first;
1983  }
1984  do
1985  {
1986  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1987  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1988  {
1989  // UE already allocated for UL-HARQ -> skip it
1990  NS_LOG_DEBUG (this << " UE already allocated in HARQ -> discared, RNTI " << (*it).first);
1991  it++;
1992  if (it == m_ceBsrRxed.end ())
1993  {
1994  // restart from the first
1995  it = m_ceBsrRxed.begin ();
1996  }
1997  continue;
1998  }
1999  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
2000  {
2001  // limit to physical resources last resource assignment
2002  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
2003  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
2004  if (rbPerFlow < 3)
2005  {
2006  // terminate allocation
2007  rbPerFlow = 0;
2008  }
2009  }
2010 
2011  rbAllocated = 0;
2012  UlDciListElement_s uldci;
2013  uldci.m_rnti = (*it).first;
2014  uldci.m_rbLen = rbPerFlow;
2015  bool allocated = false;
2016  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
2017  while ((!allocated)&&((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) && (rbPerFlow != 0))
2018  {
2019  // check availability
2020  bool free = true;
2021  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
2022  {
2023  if (rbMap.at (j) == true)
2024  {
2025  free = false;
2026  break;
2027  }
2028  if ((m_ffrSapProvider->IsUlRbgAvailableForUe (j, (*it).first)) == false)
2029  {
2030  free = false;
2031  break;
2032  }
2033  }
2034  if (free)
2035  {
2036  NS_LOG_INFO (this << "RNTI: "<< (*it).first<< " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
2037  uldci.m_rbStart = rbAllocated;
2038 
2039  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
2040  {
2041  rbMap.at (j) = true;
2042  // store info on allocation for managing ul-cqi interpretation
2043  rbgAllocationMap.at (j) = (*it).first;
2044  }
2045  rbAllocated += rbPerFlow;
2046  allocated = true;
2047  break;
2048  }
2049  rbAllocated++;
2050  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
2051  {
2052  // limit to physical resources last resource assignment
2053  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
2054  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
2055  if (rbPerFlow < 3)
2056  {
2057  // terminate allocation
2058  rbPerFlow = 0;
2059  }
2060  }
2061  }
2062  if (!allocated)
2063  {
2064  // unable to allocate new resource: finish scheduling
2065 // m_nextRntiUl = (*it).first;
2066 // if (ret.m_dciList.size () > 0)
2067 // {
2068 // m_schedSapUser->SchedUlConfigInd (ret);
2069 // }
2070 // m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
2071 // return;
2072  break;
2073  }
2074 
2075 
2076 
2077  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
2078  int cqi = 0;
2079  if (itCqi == m_ueCqi.end ())
2080  {
2081  // no cqi info about this UE
2082  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
2083  }
2084  else
2085  {
2086  // take the lowest CQI value (worst RB)
2087  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
2088  if (minSinr == NO_SINR)
2089  {
2090  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
2091  }
2092  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
2093  {
2094  double sinr = (*itCqi).second.at (i);
2095  if (sinr == NO_SINR)
2096  {
2097  sinr = EstimateUlSinr ((*it).first, i);
2098  }
2099  if ((*itCqi).second.at (i) < minSinr)
2100  {
2101  minSinr = (*itCqi).second.at (i);
2102  }
2103  }
2104 
2105  // translate SINR -> cqi: WILD ACK: same as DL
2106  double s = log2 ( 1 + (
2107  std::pow (10, minSinr / 10 ) /
2108  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
2109  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
2110  if (cqi == 0)
2111  {
2112  it++;
2113  if (it == m_ceBsrRxed.end ())
2114  {
2115  // restart from the first
2116  it = m_ceBsrRxed.begin ();
2117  }
2118  NS_LOG_DEBUG (this << " UE discared for CQI=0, RNTI " << uldci.m_rnti);
2119  // remove UE from allocation map
2120  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
2121  {
2122  rbgAllocationMap.at (i) = 0;
2123  }
2124  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
2125  }
2126  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
2127  }
2128 
2129  uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
2130  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
2131  uldci.m_ndi = 1;
2132  uldci.m_cceIndex = 0;
2133  uldci.m_aggrLevel = 1;
2134  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
2135  uldci.m_hopping = false;
2136  uldci.m_n2Dmrs = 0;
2137  uldci.m_tpc = 0; // no power control
2138  uldci.m_cqiRequest = false; // only period CQI at this stage
2139  uldci.m_ulIndex = 0; // TDD parameter
2140  uldci.m_dai = 1; // TDD parameter
2141  uldci.m_freqHopping = 0;
2142  uldci.m_pdcchPowerOffset = 0; // not used
2143  ret.m_dciList.push_back (uldci);
2144  // store DCI for HARQ_PERIOD
2145  uint8_t harqId = 0;
2146  if (m_harqOn == true)
2147  {
2148  std::map <uint16_t, uint8_t>::iterator itProcId;
2149  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
2150  if (itProcId == m_ulHarqCurrentProcessId.end ())
2151  {
2152  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
2153  }
2154  harqId = (*itProcId).second;
2155  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
2156  if (itDci == m_ulHarqProcessesDciBuffer.end ())
2157  {
2158  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
2159  }
2160  (*itDci).second.at (harqId) = uldci;
2161  // Update HARQ process status (RV 0)
2162  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (uldci.m_rnti);
2163  if (itStat == m_ulHarqProcessesStatus.end ())
2164  {
2165  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << uldci.m_rnti);
2166  }
2167  (*itStat).second.at (harqId) = 0;
2168  }
2169 
2170  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);
2171 
2172  it++;
2173  if (it == m_ceBsrRxed.end ())
2174  {
2175  // restart from the first
2176  it = m_ceBsrRxed.begin ();
2177  }
2178  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
2179  {
2180  // Stop allocation: no more PRBs
2181  m_nextRntiUl = (*it).first;
2182  break;
2183  }
2184  }
2185  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
2186 
2187  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
2189 
2190  return;
2191 }
2192 
2193 void
2195 {
2196  NS_LOG_FUNCTION (this);
2197  return;
2198 }
2199 
2200 void
2202 {
2203  NS_LOG_FUNCTION (this);
2204  return;
2205 }
2206 
2207 void
2209 {
2210  NS_LOG_FUNCTION (this);
2211 
2212  std::map <uint16_t,uint32_t>::iterator it;
2213 
2214  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
2215  {
2216  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
2217  {
2218  // buffer status report
2219  // note that this scheduler does not differentiate the
2220  // allocation according to which LCGs have more/less bytes
2221  // to send.
2222  // Hence the BSR of different LCGs are just summed up to get
2223  // a total queue size that is used for allocation purposes.
2224 
2225  uint32_t buffer = 0;
2226  for (uint8_t lcg = 0; lcg < 4; ++lcg)
2227  {
2228  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
2229  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
2230  }
2231 
2232  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
2233  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
2234  it = m_ceBsrRxed.find (rnti);
2235  if (it == m_ceBsrRxed.end ())
2236  {
2237  // create the new entry
2238  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
2239  }
2240  else
2241  {
2242  // update the buffer size value
2243  (*it).second = buffer;
2244  }
2245  }
2246  }
2247 
2248  return;
2249 }
2250 
2251 void
2253 {
2254  NS_LOG_FUNCTION (this);
2255 // retrieve the allocation for this subframe
2256  switch (m_ulCqiFilter)
2257  {
2259  {
2260  // filter all the CQIs that are not SRS based
2261  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
2262  {
2263  return;
2264  }
2265  }
2266  break;
2268  {
2269  // filter all the CQIs that are not SRS based
2270  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2271  {
2272  return;
2273  }
2274  }
2276  break;
2277 
2278  default:
2279  NS_FATAL_ERROR ("Unknown UL CQI type");
2280  }
2281 
2282  switch (params.m_ulCqi.m_type)
2283  {
2284  case UlCqi_s::PUSCH:
2285  {
2286  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
2287  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2288  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
2289  itMap = m_allocationMaps.find (params.m_sfnSf);
2290  if (itMap == m_allocationMaps.end ())
2291  {
2292  return;
2293  }
2294  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
2295  {
2296  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2297  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
2298  itCqi = m_ueCqi.find ((*itMap).second.at (i));
2299  if (itCqi == m_ueCqi.end ())
2300  {
2301  // create a new entry
2302  std::vector <double> newCqi;
2303  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2304  {
2305  if (i == j)
2306  {
2307  newCqi.push_back (sinr);
2308  }
2309  else
2310  {
2311  // initialize with NO_SINR value.
2312  newCqi.push_back (NO_SINR);
2313  }
2314 
2315  }
2316  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
2317  // generate correspondent timer
2318  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
2319  }
2320  else
2321  {
2322  // update the value
2323  (*itCqi).second.at (i) = sinr;
2324  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
2325  // update correspondent timer
2326  std::map <uint16_t, uint32_t>::iterator itTimers;
2327  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
2328  (*itTimers).second = m_cqiTimersThreshold;
2329 
2330  }
2331 
2332  }
2333  // remove obsolete info on allocation
2334  m_allocationMaps.erase (itMap);
2335  }
2336  break;
2337  case UlCqi_s::SRS:
2338  {
2339  // get the RNTI from vendor specific parameters
2340  uint16_t rnti = 0;
2341  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
2342  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
2343  {
2344  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
2345  {
2346  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
2347  rnti = vsp->GetRnti ();
2348  }
2349  }
2350  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2351  itCqi = m_ueCqi.find (rnti);
2352  if (itCqi == m_ueCqi.end ())
2353  {
2354  // create a new entry
2355  std::vector <double> newCqi;
2356  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2357  {
2358  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2359  newCqi.push_back (sinr);
2360  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
2361 
2362  }
2363  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
2364  // generate correspondent timer
2365  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
2366  }
2367  else
2368  {
2369  // update the values
2370  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2371  {
2372  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2373  (*itCqi).second.at (j) = sinr;
2374  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
2375  }
2376  // update correspondent timer
2377  std::map <uint16_t, uint32_t>::iterator itTimers;
2378  itTimers = m_ueCqiTimers.find (rnti);
2379  (*itTimers).second = m_cqiTimersThreshold;
2380 
2381  }
2382 
2383 
2384  }
2385  break;
2386  case UlCqi_s::PUCCH_1:
2387  case UlCqi_s::PUCCH_2:
2388  case UlCqi_s::PRACH:
2389  {
2390  NS_FATAL_ERROR ("PssFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2391  }
2392  break;
2393  default:
2394  NS_FATAL_ERROR ("Unknown type of UL-CQI");
2395  }
2396  return;
2397 }
2398 
2399 void
2401 {
2402  // refresh DL CQI P01 Map
2403  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
2404  while (itP10 != m_p10CqiTimers.end ())
2405  {
2406  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2407  if ((*itP10).second == 0)
2408  {
2409  // delete correspondent entries
2410  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
2411  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
2412  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
2413  m_p10CqiRxed.erase (itMap);
2414  std::map <uint16_t,uint32_t>::iterator temp = itP10;
2415  itP10++;
2416  m_p10CqiTimers.erase (temp);
2417  }
2418  else
2419  {
2420  (*itP10).second--;
2421  itP10++;
2422  }
2423  }
2424 
2425  // refresh DL CQI A30 Map
2426  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
2427  while (itA30 != m_a30CqiTimers.end ())
2428  {
2429  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2430  if ((*itA30).second == 0)
2431  {
2432  // delete correspondent entries
2433  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
2434  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
2435  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
2436  m_a30CqiRxed.erase (itMap);
2437  std::map <uint16_t,uint32_t>::iterator temp = itA30;
2438  itA30++;
2439  m_a30CqiTimers.erase (temp);
2440  }
2441  else
2442  {
2443  (*itA30).second--;
2444  itA30++;
2445  }
2446  }
2447 
2448  return;
2449 }
2450 
2451 
2452 void
2454 {
2455  // refresh UL CQI Map
2456  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
2457  while (itUl != m_ueCqiTimers.end ())
2458  {
2459  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2460  if ((*itUl).second == 0)
2461  {
2462  // delete correspondent entries
2463  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
2464  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
2465  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
2466  (*itMap).second.clear ();
2467  m_ueCqi.erase (itMap);
2468  std::map <uint16_t,uint32_t>::iterator temp = itUl;
2469  itUl++;
2470  m_ueCqiTimers.erase (temp);
2471  }
2472  else
2473  {
2474  (*itUl).second--;
2475  itUl++;
2476  }
2477  }
2478 
2479  return;
2480 }
2481 
2482 void
2483 PssFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
2484 {
2485  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2486  LteFlowId_t flow (rnti, lcid);
2487  it = m_rlcBufferReq.find (flow);
2488  if (it != m_rlcBufferReq.end ())
2489  {
2490  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);
2491  // Update queues: RLC tx order Status, ReTx, Tx
2492  // Update status queue
2493  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2494  {
2495  (*it).second.m_rlcStatusPduSize = 0;
2496  }
2497  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2498  {
2499  (*it).second.m_rlcRetransmissionQueueSize = 0;
2500  }
2501  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2502  {
2503  uint32_t rlcOverhead;
2504  if (lcid == 1)
2505  {
2506  // for SRB1 (using RLC AM) it's better to
2507  // overestimate RLC overhead rather than
2508  // underestimate it and risk unneeded
2509  // segmentation which increases delay
2510  rlcOverhead = 4;
2511  }
2512  else
2513  {
2514  // minimum RLC overhead due to header
2515  rlcOverhead = 2;
2516  }
2517  // update transmission queue
2518  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2519  {
2520  (*it).second.m_rlcTransmissionQueueSize = 0;
2521  }
2522  else
2523  {
2524  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2525  }
2526  }
2527  }
2528  else
2529  {
2530  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2531  }
2532 }
2533 
2534 void
2535 PssFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2536 {
2537 
2538  size = size - 2; // remove the minimum RLC overhead
2539  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2540  if (it != m_ceBsrRxed.end ())
2541  {
2542  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2543  if ((*it).second >= size)
2544  {
2545  (*it).second -= size;
2546  }
2547  else
2548  {
2549  (*it).second = 0;
2550  }
2551  }
2552  else
2553  {
2554  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2555  }
2556 
2557 }
2558 
2559 void
2561 {
2562  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2564  params.m_rnti = rnti;
2565  params.m_transmissionMode = txMode;
2567 }
2568 
2569 
2570 }
virtual void SchedDlCqiInfoReq(const struct SchedDlCqiInfoReqParameters &params)
std::vector< struct UlInfoListElement_s > m_ulInfoList
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:88
std::map< uint16_t, uint32_t > m_p10CqiTimers
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Definition: lte-ffr-sap.h:132
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
#define HARQ_PERIOD
Definition: lte-common.h:30
Hold a bool native type.
Definition: boolean.h:38
virtual LteFfrSapUser * GetLteFfrSapUser()
std::map< uint16_t, uint8_t > m_uesTxMode
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void ReportUlCqiInfo(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)=0
ReportUlCqiInfo.
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Parameters of the CSCHED_UE_CONFIG_CNF primitive.
hold variables of type string
Definition: string.h:18
int LcActivePerFlow(uint16_t rnti)
Parameters of the CSCHED_UE_RELEASE_REQ primitive.
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
virtual bool IsDlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in DL.
virtual bool IsUlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in UL.
std::map< uint16_t, uint8_t > m_p10CqiRxed
enum ns3::UlCqi_s::Type_e m_type
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
std::vector< struct LogicalChannelConfigListElement_s > m_logicalChannelConfigList
std::vector< uint16_t > m_sinr
std::map< uint16_t, pssFlowPerf_t > m_flowStatsUl
std::vector< uint8_t > DlHarqProcessesTimer_t
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
virtual void SchedUlCqiInfoReq(const struct SchedUlCqiInfoReqParameters &params)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
std::vector< uint8_t > m_mcs
Definition: ff-mac-common.h:95
See section 4.3.2 ulDciListElement.
Provides the CSCHED SAP.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
virtual void SchedDlRachInfoReq(const struct SchedDlRachInfoReqParameters &params)
std::vector< struct UlDciListElement_s > m_dciList
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
See section 4.3.10 buildRARListElement.
virtual void CschedUeConfigReq(const struct CschedUeConfigReqParameters &params)
Parameters of the CSCHED_UE_CONFIG_UPDATE_IND primitive.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
Parameters of the CSCHED_LC_RELEASE_REQ primitive.
virtual uint8_t GetTpc(uint16_t rnti)=0
GetTpc.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
Flow information.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
static TypeId GetTypeId(void)
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
FfMacCschedSapUser * m_cschedSapUser
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
int GetRbgSize(int dlbandwidth)
Parameters of the SCHED_DL_MAC_BUFFER_REQ primitive.
Parameters of the SCHED_DL_PAGING_BUFFER_REQ primitive.
virtual void CschedUeConfigUpdateInd(const struct CschedUeConfigUpdateIndParameters &params)=0
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
double secondLastAveragedThroughput
Past average throughput.
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
Service Access Point (SAP) offered by the Frequency Reuse algorithm instance to the MAC Scheduler ins...
Definition: lte-ffr-sap.h:39
Parameters of the SCHED_UL_TRIGGER_REQ primitive.
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Hold an unsigned integer type.
Definition: uinteger.h:46
static uint8_t TxMode2LayerNum(uint8_t txMode)
Definition: lte-common.cc:170
Ptr< SampleEmitter > s
bool m_harqOn
m_harqOn when false inhibit te HARQ mechanisms (by default active)
std::vector< uint8_t > m_ndi
Definition: ff-mac-common.h:96
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Provides the SCHED SAP.
virtual void CschedLcReleaseReq(const struct CschedLcReleaseReqParameters &params)
virtual void CschedUeConfigCnf(const struct CschedUeConfigCnfParameters &params)=0
LteFfrSapProvider * m_ffrSapProvider
unsigned int lastTtiBytesTransmitted
Total bytes send by eNb for this UE.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
Parameters of the SCHED_UL_NOISE_INTERFERENCE_REQ primitive.
friend class PssSchedulerMemberSchedSapProvider
std::vector< struct CqiListElement_s > m_cqiList
std::vector< struct DlInfoListElement_s > m_dlInfoList
virtual void ReportDlCqiInfo(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)=0
ReportDlCqiInfo.
virtual void SchedDlRlcBufferReq(const struct SchedDlRlcBufferReqParameters &params)
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
double lastAveragedThroughput
Total bytes send by eNB in last tti for this UE.
virtual void SchedDlConfigInd(const struct SchedDlConfigIndParameters &params)=0
virtual void CschedLcConfigReq(const struct CschedLcConfigReqParameters &params)
std::vector< uint16_t > m_tbsSize
Definition: ff-mac-common.h:94
See section 4.3.9 rlcPDU_ListElement.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
unsigned long totalBytesTransmitted
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
Parameters of the CSCHED_LC_CONFIG_REQ primitive.
std::vector< uint8_t > m_rv
Definition: ff-mac-common.h:97
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
set the user part of the FfMacSchedSap that this Scheduler will interact with.
std::map< uint16_t, pssFlowPerf_t > m_flowStatsDl
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
virtual void CschedUeReleaseReq(const struct CschedUeReleaseReqParameters &params)
static const int PssType0AllocationRbg[4]
virtual std::vector< bool > GetAvailableUlRbg()=0
Get vector of available RB in UL for this Cell.
virtual uint8_t GetMinContinuousUlBandwidth()=0
GetMinContinuousUlBandwidth.
virtual void SchedUlConfigInd(const struct SchedUlConfigIndParameters &params)=0
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
UlCqiFilter_t m_ulCqiFilter
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
#define SRS_CQI_RNTI_VSP
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
This abstract base class identifies the interface by means of which the helper object can plug on the...
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:84
std::vector< struct RachListElement_s > m_rachList
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Parameters of the SCHED_DL_CQI_INFO_REQ primitive.
std::vector< struct MacCeListElement_s > m_macCeList
std::vector< struct RachListElement_s > m_rachList
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
static double fpS11dot3toDouble(uint16_t val)
Definition: lte-common.cc:114
virtual ~PssFfMacScheduler()
Destructor.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
std::map< uint16_t, uint32_t > m_ceBsrRxed
std::vector< uint8_t > UlHarqProcessesStatus_t
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
std::vector< uint8_t > DlHarqProcessesStatus_t
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
virtual void SchedDlTriggerReq(const struct SchedDlTriggerReqParameters &params)
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
static uint32_t BsrId2BufferSize(uint8_t val)
Definition: lte-common.cc:142
Template for the implementation of the LteFfrSapUser as a member of an owner class of type C to which...
Definition: lte-ffr-sap.h:244
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
virtual void SetLteFfrSapProvider(LteFfrSapProvider *s)
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
set the user part of the FfMacCschedSap that this Scheduler will interact with.
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
virtual std::vector< bool > GetAvailableDlRbg()=0
Get vector of available RBG in DL for this Cell.
virtual void SchedUlTriggerReq(const struct SchedUlTriggerReqParameters &params)
std::vector< uint16_t > m_rachAllocationMap
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
virtual void SchedDlMacBufferReq(const struct SchedDlMacBufferReqParameters &params)
FfMacCschedSapProvider * m_cschedSapProvider
std::map< uint16_t, uint32_t > m_a30CqiTimers
Parameters of the SCHED_UL_SR_INFO_REQ primitive.
virtual void SchedDlPagingBufferReq(const struct SchedDlPagingBufferReqParameters &params)
virtual void SchedUlMacCtrlInfoReq(const struct SchedUlMacCtrlInfoReqParameters &params)
std::map< uint16_t, std::vector< double > > m_ueCqi
std::map< uint16_t, uint32_t > m_ueCqiTimers
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:193
Parameters of the SCHED_DL_RACH_INFO_REQ primitive.
Parameters of the SCHED_UL_CONFIG_IND primitive.
Parameters of the CSCHED_UE_CONFIG_REQ primitive.
#define HARQ_DL_TIMEOUT
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
#define NO_SINR
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
struct DlDciListElement_s m_dci
std::vector< struct BuildRarListElement_s > m_buildRarList
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
FfMacSchedSapUser * m_schedSapUser
a unique identifier for an interface.
Definition: type-id.h:49
FfMacSchedSapProvider * m_schedSapProvider
virtual void SchedUlSrInfoReq(const struct SchedUlSrInfoReqParameters &params)
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters &params)
CSCHED_CELL_CONFIG_REQ.
#define HARQ_PROC_NUM
std::vector< struct BuildDataListElement_s > m_buildDataList
virtual void SchedUlNoiseInterferenceReq(const struct SchedUlNoiseInterferenceReqParameters &params)
friend class PssSchedulerMemberCschedSapProvider
See section 4.3.8 builDataListElement.
Implements the SCHED SAP and CSCHED SAP for a Priority Set scheduler.