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