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