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  {
1086  budget = (*itMax).second.burstCredit;
1087  }
1088  if ( budget > bankSize )
1089  {
1090  budget = bankSize;
1091  }
1092  }
1093  budget = budget + (*itMax).second.tokenPoolSize;
1094 
1095  // calculate how much bytes this UE actally need
1096  if (budget == 0)
1097  {
1098  // there are no tokens for this UE
1099  continue;
1100  }
1101  else
1102  {
1103  // calculate rlc buffer size
1104  uint32_t rlcBufSize = 0;
1105  uint8_t lcid = 0;
1106  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itRlcBuf;
1107  for (itRlcBuf = m_rlcBufferReq.begin (); itRlcBuf != m_rlcBufferReq.end (); itRlcBuf++)
1108  {
1109  if ( (*itRlcBuf).first.m_rnti == (*itMax).first )
1110  {
1111  lcid = (*itRlcBuf).first.m_lcId;
1112  }
1113  }
1114  LteFlowId_t flow ((*itMax).first, lcid);
1115  itRlcBuf = m_rlcBufferReq.find (flow);
1116  if (itRlcBuf != m_rlcBufferReq.end ())
1117  {
1118  rlcBufSize = (*itRlcBuf).second.m_rlcTransmissionQueueSize + (*itRlcBuf).second.m_rlcRetransmissionQueueSize + (*itRlcBuf).second.m_rlcStatusPduSize;
1119  }
1120  if (budget > rlcBufSize)
1121  {
1122  budget = rlcBufSize;
1123  NS_LOG_DEBUG ("budget > rlcBufSize. budget: " << budget << " RLC buffer size: " << rlcBufSize);
1124  }
1125  }
1126 
1127  // assign RBGs to this UE
1128  uint32_t bytesTxed = 0;
1129  uint32_t bytesTxedTmp = 0;
1130  int rbgIndex = 0;
1131  while ( bytesTxed <= budget )
1132  {
1133  totalRbg++;
1134 
1135  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1136  itCqi = m_a30CqiRxed.find ((*itMax).first);
1137  std::map <uint16_t,uint8_t>::iterator itTxMode;
1138  itTxMode = m_uesTxMode.find ((*itMax).first);
1139  if (itTxMode == m_uesTxMode.end ())
1140  {
1141  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1142  }
1143  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1144 
1145  // find RBG with largest achievableRate
1146  double achievableRateMax = 0.0;
1147  rbgIndex = rbgNum;
1148  for (int k = 0; k < rbgNum; k++)
1149  {
1150  std::set <uint8_t>::iterator rbg;
1151  rbg = allocatedRbg.find (k);
1152  if (rbg != allocatedRbg.end ()) // RBGs are already allocated to this UE
1153  {
1154  continue;
1155  }
1156 
1157  if ( rbgMap.at (k) == true) // this RBG is allocated in RACH procedure
1158  {
1159  continue;
1160  }
1161 
1162  if ((m_ffrSapProvider->IsDlRbgAvailableForUe (k, (*itMax).first)) == false)
1163  {
1164  continue;
1165  }
1166 
1167  std::vector <uint8_t> sbCqi;
1168  if (itCqi == m_a30CqiRxed.end ())
1169  {
1170  for (uint8_t k = 0; k < nLayer; k++)
1171  {
1172  sbCqi.push_back (1); // start with lowest value
1173  }
1174  }
1175  else
1176  {
1177  sbCqi = (*itCqi).second.m_higherLayerSelected.at (k).m_sbCqi;
1178  }
1179  uint8_t cqi1 = sbCqi.at (0);
1180  uint8_t cqi2 = 0;
1181  if (sbCqi.size () > 1)
1182  {
1183  cqi2 = sbCqi.at (1);
1184  }
1185 
1186  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1187  {
1188  if (LcActivePerFlow ((*itMax).first) > 0)
1189  {
1190  // this UE has data to transmit
1191  double achievableRate = 0.0;
1192  for (uint8_t j = 0; j < nLayer; j++)
1193  {
1194  uint8_t mcs = 0;
1195  if (sbCqi.size () > j)
1196  {
1197  mcs = m_amc->GetMcsFromCqi (sbCqi.at (j));
1198  }
1199  else
1200  {
1201  // no info on this subband -> worst MCS
1202  mcs = 0;
1203  }
1204  achievableRate += ((m_amc->GetDlTbSizeFromMcs (mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1205  }
1206 
1207  if ( achievableRate > achievableRateMax )
1208  {
1209  achievableRateMax = achievableRate;
1210  rbgIndex = k;
1211  }
1212  } // end of LcActivePerFlow
1213  } // end of cqi
1214  } // end of for rbgNum
1215 
1216  if ( rbgIndex == rbgNum) // impossible
1217  {
1218  // all RBGs are already assigned
1219  totalRbg = rbgNum;
1220  break;
1221  }
1222  else
1223  {
1224  // mark this UE as "allocated"
1225  allocatedRbg.insert (rbgIndex);
1226  }
1227 
1228  // assign this RBG to UE
1229  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1230  itMap = allocationMap.find ((*itMax).first);
1231  uint16_t RbgPerRnti;
1232  if (itMap == allocationMap.end ())
1233  {
1234  // insert new element
1235  std::vector <uint16_t> tempMap;
1236  tempMap.push_back (rbgIndex);
1237  allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax).first, tempMap));
1238  itMap = allocationMap.find ((*itMax).first); // point itMap to the first RBGs assigned to this UE
1239  }
1240  else
1241  {
1242  (*itMap).second.push_back (rbgIndex);
1243  }
1244  rbgMap.at (rbgIndex) = true; // Mark this RBG as allocated
1245 
1246  RbgPerRnti = (*itMap).second.size ();
1247 
1248  // calculate tb size
1249  std::vector <uint8_t> worstCqi (2, 15);
1250  if (itCqi != m_a30CqiRxed.end ())
1251  {
1252  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1253  {
1254  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1255  {
1256  for (uint8_t j = 0; j < nLayer; j++)
1257  {
1258  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1259  {
1260  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1261  {
1262  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1263  }
1264  }
1265  else
1266  {
1267  // no CQI for this layer of this suband -> worst one
1268  worstCqi.at (j) = 1;
1269  }
1270  }
1271  }
1272  else
1273  {
1274  for (uint8_t j = 0; j < nLayer; j++)
1275  {
1276  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1277  }
1278  }
1279  }
1280  }
1281  else
1282  {
1283  for (uint8_t j = 0; j < nLayer; j++)
1284  {
1285  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1286  }
1287  }
1288 
1289  bytesTxedTmp = bytesTxed;
1290  bytesTxed = 0;
1291  for (uint8_t j = 0; j < nLayer; j++)
1292  {
1293  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)
1294  bytesTxed += tbSize;
1295  }
1296 
1297  } // end of while()
1298 
1299  // remove and unmark last RBG assigned to UE
1300  if ( bytesTxed > budget )
1301  {
1302  NS_LOG_DEBUG ("budget: " << budget << " bytesTxed: " << bytesTxed << " at " << Simulator::Now ().As (Time::MS));
1303  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1304  itMap = allocationMap.find ((*itMax).first);
1305  (*itMap).second.pop_back ();
1306  allocatedRbg.erase (rbgIndex);
1307  bytesTxed = bytesTxedTmp; // recovery bytesTxed
1308  totalRbg--;
1309  rbgMap.at (rbgIndex) = false; // unmark this RBG
1310  //If all the RBGs are removed from the allocation
1311  //of this RNTI, we remove the UE from the allocation map
1312  if ((*itMap).second.size () == 0)
1313  {
1314  itMap = allocationMap.erase (itMap);
1315  }
1316  }
1317 
1318  //only update the UE stats if it exists in the allocation map
1319  if (allocationMap.find ((*itMax).first) != allocationMap.end ())
1320  {
1321  // update UE stats
1322  if ( bytesTxed <= (*itMax).second.tokenPoolSize )
1323  {
1324  (*itMax).second.tokenPoolSize -= bytesTxed;
1325  }
1326  else
1327  {
1328  (*itMax).second.counter = (*itMax).second.counter - ( bytesTxed - (*itMax).second.tokenPoolSize );
1329  (*itMax).second.tokenPoolSize = 0;
1330  if (bankSize <= ( bytesTxed - (*itMax).second.tokenPoolSize ))
1331  {
1332  bankSize = 0;
1333  }
1334  else
1335  {
1336  bankSize = bankSize - ( bytesTxed - (*itMax).second.tokenPoolSize );
1337  }
1338  }
1339  }
1340  } // end of RBGs
1341 
1342  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1343  // creating the correspondent DCIs
1344  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1345  while (itMap != allocationMap.end ())
1346  {
1347  NS_LOG_DEBUG ("Preparing DCI for RNTI " << (*itMap).first);
1348  // create new BuildDataListElement_s for this LC
1349  BuildDataListElement_s newEl;
1350  newEl.m_rnti = (*itMap).first;
1351  // create the DlDciListElement_s
1352  DlDciListElement_s newDci;
1353  newDci.m_rnti = (*itMap).first;
1354  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1355 
1356  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1357  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1358  if (lcActives == 0)
1359  {
1360  // Set to max value, to avoid divide by 0 below
1361  lcActives = (uint16_t)65535; // UINT16_MAX;
1362  }
1363  uint16_t RgbPerRnti = (*itMap).second.size ();
1364  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1365  itCqi = m_a30CqiRxed.find ((*itMap).first);
1366  std::map <uint16_t,uint8_t>::iterator itTxMode;
1367  itTxMode = m_uesTxMode.find ((*itMap).first);
1368  if (itTxMode == m_uesTxMode.end ())
1369  {
1370  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1371  }
1372  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1373  std::vector <uint8_t> worstCqi (2, 15);
1374  if (itCqi != m_a30CqiRxed.end ())
1375  {
1376  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1377  {
1378  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1379  {
1380  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)) );
1381  for (uint8_t j = 0; j < nLayer; j++)
1382  {
1383  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1384  {
1385  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1386  {
1387  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1388  }
1389  }
1390  else
1391  {
1392  // no CQI for this layer of this suband -> worst one
1393  worstCqi.at (j) = 1;
1394  }
1395  }
1396  }
1397  else
1398  {
1399  for (uint8_t j = 0; j < nLayer; j++)
1400  {
1401  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1402  }
1403  }
1404  }
1405  }
1406  else
1407  {
1408  for (uint8_t j = 0; j < nLayer; j++)
1409  {
1410  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1411  }
1412  }
1413  for (uint8_t j = 0; j < nLayer; j++)
1414  {
1415  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " CQI selected " << (uint16_t)worstCqi.at (j));
1416  }
1417  uint32_t bytesTxed = 0;
1418  for (uint8_t j = 0; j < nLayer; j++)
1419  {
1420  newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1421  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)
1422  newDci.m_tbsSize.push_back (tbSize);
1423  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " MCS selected" << (uint16_t) m_amc->GetMcsFromCqi (worstCqi.at (j)));
1424  bytesTxed += tbSize;
1425  }
1426 
1427  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1428  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1429  uint32_t rbgMask = 0;
1430  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1431  {
1432  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1433  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1434  }
1435  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1436 
1437  // create the rlc PDUs -> equally divide resources among actives LCs
1438  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1439  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1440  {
1441  if (((*itBufReq).first.m_rnti == (*itMap).first)
1442  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1443  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1444  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1445  {
1446  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1447  for (uint8_t j = 0; j < nLayer; j++)
1448  {
1449  RlcPduListElement_s newRlcEl;
1450  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1451  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1452  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1453  newRlcPduLe.push_back (newRlcEl);
1454  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1455  if (m_harqOn == true)
1456  {
1457  // store RLC PDU list for HARQ
1458  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1459  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1460  {
1461  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1462  }
1463  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1464  }
1465  }
1466  newEl.m_rlcPduList.push_back (newRlcPduLe);
1467  }
1468  if ((*itBufReq).first.m_rnti > (*itMap).first)
1469  {
1470  break;
1471  }
1472  }
1473  for (uint8_t j = 0; j < nLayer; j++)
1474  {
1475  newDci.m_ndi.push_back (1);
1476  newDci.m_rv.push_back (0);
1477  }
1478 
1479  newDci.m_tpc = m_ffrSapProvider->GetTpc ((*itMap).first);
1480 
1481  newEl.m_dci = newDci;
1482 
1483  if (m_harqOn == true)
1484  {
1485  // store DCI for HARQ
1486  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1487  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1488  {
1489  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1490  }
1491  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1492  // refresh timer
1493  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1494  if (itHarqTimer == m_dlHarqProcessesTimer.end ())
1495  {
1496  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1497  }
1498  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1499  }
1500 
1501  // ...more parameters -> ignored in this version
1502 
1503  ret.m_buildDataList.push_back (newEl);
1504 
1505  itMap++;
1506  } // end while allocation
1507  ret.m_nrOfPdcchOfdmSymbols = 1;
1508 
1510 
1511 
1512  return;
1513 }
1514 
1515 void
1517 {
1518  NS_LOG_FUNCTION (this);
1519 
1520  m_rachList = params.m_rachList;
1521 
1522  return;
1523 }
1524 
1525 void
1527 {
1528  NS_LOG_FUNCTION (this);
1530 
1531  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1532  {
1533  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1534  {
1535  NS_LOG_LOGIC ("wideband CQI " << (uint32_t) params.m_cqiList.at (i).m_wbCqi.at (0) << " reported");
1536  std::map <uint16_t,uint8_t>::iterator it;
1537  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1538  it = m_p10CqiRxed.find (rnti);
1539  if (it == m_p10CqiRxed.end ())
1540  {
1541  // create the new entry
1542  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)
1543  // generate correspondent timer
1544  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1545  }
1546  else
1547  {
1548  // update the CQI value and refresh correspondent timer
1549  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1550  // update correspondent timer
1551  std::map <uint16_t,uint32_t>::iterator itTimers;
1552  itTimers = m_p10CqiTimers.find (rnti);
1553  (*itTimers).second = m_cqiTimersThreshold;
1554  }
1555  }
1556  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1557  {
1558  // subband CQI reporting high layer configured
1559  std::map <uint16_t,SbMeasResult_s>::iterator it;
1560  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1561  it = m_a30CqiRxed.find (rnti);
1562  if (it == m_a30CqiRxed.end ())
1563  {
1564  // create the new entry
1565  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1566  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1567  }
1568  else
1569  {
1570  // update the CQI value and refresh correspondent timer
1571  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1572  std::map <uint16_t,uint32_t>::iterator itTimers;
1573  itTimers = m_a30CqiTimers.find (rnti);
1574  (*itTimers).second = m_cqiTimersThreshold;
1575  }
1576  }
1577  else
1578  {
1579  NS_LOG_ERROR (this << " CQI type unknown");
1580  }
1581  }
1582 
1583  return;
1584 }
1585 
1586 
1587 double
1588 FdTbfqFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1589 {
1590  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1591  if (itCqi == m_ueCqi.end ())
1592  {
1593  // no cqi info about this UE
1594  return (NO_SINR);
1595 
1596  }
1597  else
1598  {
1599  // take the average SINR value among the available
1600  double sinrSum = 0;
1601  unsigned int sinrNum = 0;
1602  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1603  {
1604  double sinr = (*itCqi).second.at (i);
1605  if (sinr != NO_SINR)
1606  {
1607  sinrSum += sinr;
1608  sinrNum++;
1609  }
1610  }
1611  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1612  // store the value
1613  (*itCqi).second.at (rb) = estimatedSinr;
1614  return (estimatedSinr);
1615  }
1616 }
1617 
1618 void
1620 {
1621  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1622 
1623  RefreshUlCqiMaps ();
1625 
1626  // Generate RBs map
1628  std::vector <bool> rbMap;
1629  uint16_t rbAllocatedNum = 0;
1630  std::set <uint16_t> rntiAllocated;
1631  std::vector <uint16_t> rbgAllocationMap;
1632  // update with RACH allocation map
1633  rbgAllocationMap = m_rachAllocationMap;
1634  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1635  m_rachAllocationMap.clear ();
1637 
1638  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1639 
1640  rbMap = m_ffrSapProvider->GetAvailableUlRbg ();
1641 
1642  for (std::vector<bool>::iterator it = rbMap.begin (); it != rbMap.end (); it++)
1643  {
1644  if ((*it) == true )
1645  {
1646  rbAllocatedNum++;
1647  }
1648  }
1649 
1650  uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth ();
1651  uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1652 
1653  // remove RACH allocation
1654  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1655  {
1656  if (rbgAllocationMap.at (i) != 0)
1657  {
1658  rbMap.at (i) = true;
1659  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1660  }
1661  }
1662 
1663 
1664  if (m_harqOn == true)
1665  {
1666  // Process UL HARQ feedback
1667  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1668  {
1669  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1670  {
1671  // retx correspondent block: retrieve the UL-DCI
1672  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1673  std::map <uint16_t, uint8_t>::iterator itProcId = m_ulHarqCurrentProcessId.find (rnti);
1674  if (itProcId == m_ulHarqCurrentProcessId.end ())
1675  {
1676  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1677  }
1678  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1679  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1680  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1681  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1682  {
1683  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1684  continue;
1685  }
1686  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1687  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1688  if (itStat == m_ulHarqProcessesStatus.end ())
1689  {
1690  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1691  }
1692  if ((*itStat).second.at (harqId) >= 3)
1693  {
1694  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1695  continue;
1696  }
1697  bool free = true;
1698  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1699  {
1700  if (rbMap.at (j) == true)
1701  {
1702  free = false;
1703  NS_LOG_INFO (this << " BUSY " << j);
1704  }
1705  }
1706  if (free)
1707  {
1708  // retx on the same RBs
1709  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1710  {
1711  rbMap.at (j) = true;
1712  rbgAllocationMap.at (j) = dci.m_rnti;
1713  NS_LOG_INFO ("\tRB " << j);
1714  rbAllocatedNum++;
1715  }
1716  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);
1717  }
1718  else
1719  {
1720  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1721  continue;
1722  }
1723  dci.m_ndi = 0;
1724  // Update HARQ buffers with new HarqId
1725  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1726  (*itStat).second.at (harqId) = 0;
1727  (*itHarq).second.at ((*itProcId).second) = dci;
1728  ret.m_dciList.push_back (dci);
1729  rntiAllocated.insert (dci.m_rnti);
1730  }
1731  else
1732  {
1733  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1734  }
1735  }
1736  }
1737 
1738  std::map <uint16_t,uint32_t>::iterator it;
1739  int nflows = 0;
1740 
1741  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1742  {
1743  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1744  // select UEs with queues not empty and not yet allocated for HARQ
1745  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1746  {
1747  nflows++;
1748  }
1749  }
1750 
1751  if (nflows == 0)
1752  {
1753  if (ret.m_dciList.size () > 0)
1754  {
1755  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1757  }
1758 
1759  return; // no flows to be scheduled
1760  }
1761 
1762 
1763  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1764  uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size ());
1765  uint16_t rbPerFlow = (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1766 
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  rbAllocated = 0;
1821  UlDciListElement_s uldci;
1822  uldci.m_rnti = (*it).first;
1823  uldci.m_rbLen = rbPerFlow;
1824  bool allocated = false;
1825  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1826  while ((!allocated)&&((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) && (rbPerFlow != 0))
1827  {
1828  // check availability
1829  bool free = true;
1830  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1831  {
1832  if (rbMap.at (j) == true)
1833  {
1834  free = false;
1835  break;
1836  }
1837  if ((m_ffrSapProvider->IsUlRbgAvailableForUe (j, (*it).first)) == false)
1838  {
1839  free = false;
1840  break;
1841  }
1842  }
1843  if (free)
1844  {
1845  NS_LOG_INFO (this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1846  uldci.m_rbStart = rbAllocated;
1847 
1848  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1849  {
1850  rbMap.at (j) = true;
1851  // store info on allocation for managing ul-cqi interpretation
1852  rbgAllocationMap.at (j) = (*it).first;
1853  }
1854  rbAllocated += rbPerFlow;
1855  allocated = true;
1856  break;
1857  }
1858  rbAllocated++;
1859  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1860  {
1861  // limit to physical resources last resource assignment
1862  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1863  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1864  if (rbPerFlow < 3)
1865  {
1866  // terminate allocation
1867  rbPerFlow = 0;
1868  }
1869  }
1870  }
1871  if (!allocated)
1872  {
1873  // unable to allocate new resource: finish scheduling
1874 // m_nextRntiUl = (*it).first;
1875 // if (ret.m_dciList.size () > 0)
1876 // {
1877 // m_schedSapUser->SchedUlConfigInd (ret);
1878 // }
1879 // m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1880 // return;
1881  break;
1882  }
1883 
1884 
1885 
1886  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1887  int cqi = 0;
1888  if (itCqi == m_ueCqi.end ())
1889  {
1890  // no cqi info about this UE
1891  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1892  }
1893  else
1894  {
1895  // take the lowest CQI value (worst RB)
1896  NS_ABORT_MSG_IF ((*itCqi).second.size () == 0, "CQI of RNTI = " << (*it).first << " has expired");
1897  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1898  if (minSinr == NO_SINR)
1899  {
1900  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1901  }
1902  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1903  {
1904  double sinr = (*itCqi).second.at (i);
1905  if (sinr == NO_SINR)
1906  {
1907  sinr = EstimateUlSinr ((*it).first, i);
1908  }
1909  if (sinr < minSinr)
1910  {
1911  minSinr = sinr;
1912  }
1913  }
1914 
1915  // translate SINR -> cqi: WILD ACK: same as DL
1916  double s = log2 ( 1 + (
1917  std::pow (10, minSinr / 10 ) /
1918  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1919  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1920  if (cqi == 0)
1921  {
1922  it++;
1923  if (it == m_ceBsrRxed.end ())
1924  {
1925  // restart from the first
1926  it = m_ceBsrRxed.begin ();
1927  }
1928  NS_LOG_DEBUG (this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1929  // remove UE from allocation map
1930  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1931  {
1932  rbgAllocationMap.at (i) = 0;
1933  }
1934  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1935  }
1936  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1937  }
1938 
1939  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1940  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1941  uldci.m_ndi = 1;
1942  uldci.m_cceIndex = 0;
1943  uldci.m_aggrLevel = 1;
1944  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1945  uldci.m_hopping = false;
1946  uldci.m_n2Dmrs = 0;
1947  uldci.m_tpc = 0; // no power control
1948  uldci.m_cqiRequest = false; // only period CQI at this stage
1949  uldci.m_ulIndex = 0; // TDD parameter
1950  uldci.m_dai = 1; // TDD parameter
1951  uldci.m_freqHopping = 0;
1952  uldci.m_pdcchPowerOffset = 0; // not used
1953  ret.m_dciList.push_back (uldci);
1954  // store DCI for HARQ_PERIOD
1955  uint8_t harqId = 0;
1956  if (m_harqOn == true)
1957  {
1958  std::map <uint16_t, uint8_t>::iterator itProcId;
1959  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1960  if (itProcId == m_ulHarqCurrentProcessId.end ())
1961  {
1962  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1963  }
1964  harqId = (*itProcId).second;
1965  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1966  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1967  {
1968  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1969  }
1970  (*itDci).second.at (harqId) = uldci;
1971  // Update HARQ process status (RV 0)
1972  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (uldci.m_rnti);
1973  if (itStat == m_ulHarqProcessesStatus.end ())
1974  {
1975  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << uldci.m_rnti);
1976  }
1977  (*itStat).second.at (harqId) = 0;
1978  }
1979 
1980  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);
1981 
1982  it++;
1983  if (it == m_ceBsrRxed.end ())
1984  {
1985  // restart from the first
1986  it = m_ceBsrRxed.begin ();
1987  }
1988  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1989  {
1990  // Stop allocation: no more PRBs
1991  m_nextRntiUl = (*it).first;
1992  break;
1993  }
1994  }
1995  while (((*it).first != m_nextRntiUl)&&(rbPerFlow != 0));
1996 
1997 
1998  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
2000 
2001  return;
2002 }
2003 
2004 void
2006 {
2007  NS_LOG_FUNCTION (this);
2008  return;
2009 }
2010 
2011 void
2013 {
2014  NS_LOG_FUNCTION (this);
2015  return;
2016 }
2017 
2018 void
2020 {
2021  NS_LOG_FUNCTION (this);
2022 
2023  std::map <uint16_t,uint32_t>::iterator it;
2024 
2025  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
2026  {
2027  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
2028  {
2029  // buffer status report
2030  // note that this scheduler does not differentiate the
2031  // allocation according to which LCGs have more/less bytes
2032  // to send.
2033  // Hence the BSR of different LCGs are just summed up to get
2034  // a total queue size that is used for allocation purposes.
2035 
2036  uint32_t buffer = 0;
2037  for (uint8_t lcg = 0; lcg < 4; ++lcg)
2038  {
2039  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
2040  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
2041  }
2042 
2043  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
2044  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
2045  it = m_ceBsrRxed.find (rnti);
2046  if (it == m_ceBsrRxed.end ())
2047  {
2048  // create the new entry
2049  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
2050  }
2051  else
2052  {
2053  // update the buffer size value
2054  (*it).second = buffer;
2055  }
2056  }
2057  }
2058 
2059  return;
2060 }
2061 
2062 void
2064 {
2065  NS_LOG_FUNCTION (this);
2066 // retrieve the allocation for this subframe
2067  switch (m_ulCqiFilter)
2068  {
2070  {
2071  // filter all the CQIs that are not SRS based
2072  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
2073  {
2074  return;
2075  }
2076  }
2077  break;
2079  {
2080  // filter all the CQIs that are not SRS based
2081  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2082  {
2083  return;
2084  }
2085  }
2086  break;
2087  default:
2088  NS_FATAL_ERROR ("Unknown UL CQI type");
2089  }
2090 
2091  switch (params.m_ulCqi.m_type)
2092  {
2093  case UlCqi_s::PUSCH:
2094  {
2095  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
2096  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2097  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
2098  itMap = m_allocationMaps.find (params.m_sfnSf);
2099  if (itMap == m_allocationMaps.end ())
2100  {
2101  return;
2102  }
2103  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
2104  {
2105  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2106  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
2107  itCqi = m_ueCqi.find ((*itMap).second.at (i));
2108  if (itCqi == m_ueCqi.end ())
2109  {
2110  // create a new entry
2111  std::vector <double> newCqi;
2112  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2113  {
2114  if (i == j)
2115  {
2116  newCqi.push_back (sinr);
2117  }
2118  else
2119  {
2120  // initialize with NO_SINR value.
2121  newCqi.push_back (NO_SINR);
2122  }
2123 
2124  }
2125  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
2126  // generate correspondent timer
2127  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
2128  }
2129  else
2130  {
2131  // update the value
2132  (*itCqi).second.at (i) = sinr;
2133  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
2134  // update correspondent timer
2135  std::map <uint16_t, uint32_t>::iterator itTimers;
2136  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
2137  (*itTimers).second = m_cqiTimersThreshold;
2138 
2139  }
2140 
2141  }
2142  // remove obsolete info on allocation
2143  m_allocationMaps.erase (itMap);
2144  }
2145  break;
2146  case UlCqi_s::SRS:
2147  {
2148  // get the RNTI from vendor specific parameters
2149  uint16_t rnti = 0;
2150  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
2151  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
2152  {
2153  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
2154  {
2155  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
2156  rnti = vsp->GetRnti ();
2157  }
2158  }
2159  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2160  itCqi = m_ueCqi.find (rnti);
2161  if (itCqi == m_ueCqi.end ())
2162  {
2163  // create a new entry
2164  std::vector <double> newCqi;
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  newCqi.push_back (sinr);
2169  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
2170 
2171  }
2172  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
2173  // generate correspondent timer
2174  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
2175  }
2176  else
2177  {
2178  // update the values
2179  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2180  {
2181  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2182  (*itCqi).second.at (j) = sinr;
2183  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
2184  }
2185  // update correspondent timer
2186  std::map <uint16_t, uint32_t>::iterator itTimers;
2187  itTimers = m_ueCqiTimers.find (rnti);
2188  (*itTimers).second = m_cqiTimersThreshold;
2189 
2190  }
2191 
2192 
2193  }
2194  break;
2195  case UlCqi_s::PUCCH_1:
2196  case UlCqi_s::PUCCH_2:
2197  case UlCqi_s::PRACH:
2198  {
2199  NS_FATAL_ERROR ("FdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2200  }
2201  break;
2202  default:
2203  NS_FATAL_ERROR ("Unknown type of UL-CQI");
2204  }
2205  return;
2206 }
2207 
2208 void
2210 {
2211  // refresh DL CQI P01 Map
2212  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
2213  while (itP10 != m_p10CqiTimers.end ())
2214  {
2215  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2216  if ((*itP10).second == 0)
2217  {
2218  // delete correspondent entries
2219  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
2220  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
2221  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
2222  m_p10CqiRxed.erase (itMap);
2223  std::map <uint16_t,uint32_t>::iterator temp = itP10;
2224  itP10++;
2225  m_p10CqiTimers.erase (temp);
2226  }
2227  else
2228  {
2229  (*itP10).second--;
2230  itP10++;
2231  }
2232  }
2233 
2234  // refresh DL CQI A30 Map
2235  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
2236  while (itA30 != m_a30CqiTimers.end ())
2237  {
2238  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2239  if ((*itA30).second == 0)
2240  {
2241  // delete correspondent entries
2242  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
2243  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
2244  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
2245  m_a30CqiRxed.erase (itMap);
2246  std::map <uint16_t,uint32_t>::iterator temp = itA30;
2247  itA30++;
2248  m_a30CqiTimers.erase (temp);
2249  }
2250  else
2251  {
2252  (*itA30).second--;
2253  itA30++;
2254  }
2255  }
2256 
2257  return;
2258 }
2259 
2260 
2261 void
2263 {
2264  // refresh UL CQI Map
2265  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
2266  while (itUl != m_ueCqiTimers.end ())
2267  {
2268  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2269  if ((*itUl).second == 0)
2270  {
2271  // delete correspondent entries
2272  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
2273  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
2274  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
2275  (*itMap).second.clear ();
2276  m_ueCqi.erase (itMap);
2277  std::map <uint16_t,uint32_t>::iterator temp = itUl;
2278  itUl++;
2279  m_ueCqiTimers.erase (temp);
2280  }
2281  else
2282  {
2283  (*itUl).second--;
2284  itUl++;
2285  }
2286  }
2287 
2288  return;
2289 }
2290 
2291 void
2292 FdTbfqFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
2293 {
2294  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2295  LteFlowId_t flow (rnti, lcid);
2296  it = m_rlcBufferReq.find (flow);
2297  if (it != m_rlcBufferReq.end ())
2298  {
2299  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);
2300  // Update queues: RLC tx order Status, ReTx, Tx
2301  // Update status queue
2302  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2303  {
2304  (*it).second.m_rlcStatusPduSize = 0;
2305  }
2306  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2307  {
2308  (*it).second.m_rlcRetransmissionQueueSize = 0;
2309  }
2310  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2311  {
2312  uint32_t rlcOverhead;
2313  if (lcid == 1)
2314  {
2315  // for SRB1 (using RLC AM) it's better to
2316  // overestimate RLC overhead rather than
2317  // underestimate it and risk unneeded
2318  // segmentation which increases delay
2319  rlcOverhead = 4;
2320  }
2321  else
2322  {
2323  // minimum RLC overhead due to header
2324  rlcOverhead = 2;
2325  }
2326  // update transmission queue
2327  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2328  {
2329  (*it).second.m_rlcTransmissionQueueSize = 0;
2330  }
2331  else
2332  {
2333  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2334  }
2335  }
2336  }
2337  else
2338  {
2339  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2340  }
2341 }
2342 
2343 void
2344 FdTbfqFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2345 {
2346 
2347  size = size - 2; // remove the minimum RLC overhead
2348  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2349  if (it != m_ceBsrRxed.end ())
2350  {
2351  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2352  if ((*it).second >= size)
2353  {
2354  (*it).second -= size;
2355  }
2356  else
2357  {
2358  (*it).second = 0;
2359  }
2360  }
2361  else
2362  {
2363  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2364  }
2365 
2366 }
2367 
2368 void
2370 {
2371  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2373  params.m_rnti = rnti;
2374  params.m_transmissionMode = txMode;
2376 }
2377 
2378 
2379 }
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.
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
millisecond
Definition: nstime.h:116
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.