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