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  for (uint8_t j = 0; j < nLayer; j++)
1418  {
1419  newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1420  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)
1421  newDci.m_tbsSize.push_back (tbSize);
1422  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " MCS selected" << (uint16_t) m_amc->GetMcsFromCqi (worstCqi.at (j)));
1423  }
1424 
1425  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1426  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1427  uint32_t rbgMask = 0;
1428  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1429  {
1430  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1431  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1432  }
1433  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1434 
1435  // create the rlc PDUs -> equally divide resources among actives LCs
1436  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1437  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1438  {
1439  if (((*itBufReq).first.m_rnti == (*itMap).first)
1440  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1441  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1442  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1443  {
1444  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1445  for (uint8_t j = 0; j < nLayer; j++)
1446  {
1447  RlcPduListElement_s newRlcEl;
1448  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1449  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1450  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1451  newRlcPduLe.push_back (newRlcEl);
1452  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1453  if (m_harqOn == true)
1454  {
1455  // store RLC PDU list for HARQ
1456  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1457  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1458  {
1459  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1460  }
1461  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1462  }
1463  }
1464  newEl.m_rlcPduList.push_back (newRlcPduLe);
1465  }
1466  if ((*itBufReq).first.m_rnti > (*itMap).first)
1467  {
1468  break;
1469  }
1470  }
1471  for (uint8_t j = 0; j < nLayer; j++)
1472  {
1473  newDci.m_ndi.push_back (1);
1474  newDci.m_rv.push_back (0);
1475  }
1476 
1477  newDci.m_tpc = m_ffrSapProvider->GetTpc ((*itMap).first);
1478 
1479  newEl.m_dci = newDci;
1480 
1481  if (m_harqOn == true)
1482  {
1483  // store DCI for HARQ
1484  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1485  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1486  {
1487  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1488  }
1489  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1490  // refresh timer
1491  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1492  if (itHarqTimer == m_dlHarqProcessesTimer.end ())
1493  {
1494  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1495  }
1496  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1497  }
1498 
1499  // ...more parameters -> ignored in this version
1500 
1501  ret.m_buildDataList.push_back (newEl);
1502 
1503  itMap++;
1504  } // end while allocation
1505  ret.m_nrOfPdcchOfdmSymbols = 1;
1506 
1508 
1509 
1510  return;
1511 }
1512 
1513 void
1515 {
1516  NS_LOG_FUNCTION (this);
1517 
1518  m_rachList = params.m_rachList;
1519 
1520  return;
1521 }
1522 
1523 void
1525 {
1526  NS_LOG_FUNCTION (this);
1528 
1529  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1530  {
1531  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1532  {
1533  NS_LOG_LOGIC ("wideband CQI " << (uint32_t) params.m_cqiList.at (i).m_wbCqi.at (0) << " reported");
1534  std::map <uint16_t,uint8_t>::iterator it;
1535  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1536  it = m_p10CqiRxed.find (rnti);
1537  if (it == m_p10CqiRxed.end ())
1538  {
1539  // create the new entry
1540  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)
1541  // generate correspondent timer
1542  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1543  }
1544  else
1545  {
1546  // update the CQI value and refresh correspondent timer
1547  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1548  // update correspondent timer
1549  std::map <uint16_t,uint32_t>::iterator itTimers;
1550  itTimers = m_p10CqiTimers.find (rnti);
1551  (*itTimers).second = m_cqiTimersThreshold;
1552  }
1553  }
1554  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1555  {
1556  // subband CQI reporting high layer configured
1557  std::map <uint16_t,SbMeasResult_s>::iterator it;
1558  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1559  it = m_a30CqiRxed.find (rnti);
1560  if (it == m_a30CqiRxed.end ())
1561  {
1562  // create the new entry
1563  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1564  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1565  }
1566  else
1567  {
1568  // update the CQI value and refresh correspondent timer
1569  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1570  std::map <uint16_t,uint32_t>::iterator itTimers;
1571  itTimers = m_a30CqiTimers.find (rnti);
1572  (*itTimers).second = m_cqiTimersThreshold;
1573  }
1574  }
1575  else
1576  {
1577  NS_LOG_ERROR (this << " CQI type unknown");
1578  }
1579  }
1580 
1581  return;
1582 }
1583 
1584 
1585 double
1586 FdTbfqFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1587 {
1588  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1589  if (itCqi == m_ueCqi.end ())
1590  {
1591  // no cqi info about this UE
1592  return (NO_SINR);
1593 
1594  }
1595  else
1596  {
1597  // take the average SINR value among the available
1598  double sinrSum = 0;
1599  unsigned int sinrNum = 0;
1600  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1601  {
1602  double sinr = (*itCqi).second.at (i);
1603  if (sinr != NO_SINR)
1604  {
1605  sinrSum += sinr;
1606  sinrNum++;
1607  }
1608  }
1609  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1610  // store the value
1611  (*itCqi).second.at (rb) = estimatedSinr;
1612  return (estimatedSinr);
1613  }
1614 }
1615 
1616 void
1618 {
1619  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1620 
1621  RefreshUlCqiMaps ();
1623 
1624  // Generate RBs map
1626  std::vector <bool> rbMap;
1627  uint16_t rbAllocatedNum = 0;
1628  std::set <uint16_t> rntiAllocated;
1629  std::vector <uint16_t> rbgAllocationMap;
1630  // update with RACH allocation map
1631  rbgAllocationMap = m_rachAllocationMap;
1632  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1633  m_rachAllocationMap.clear ();
1635 
1636  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1637 
1638  rbMap = m_ffrSapProvider->GetAvailableUlRbg ();
1639 
1640  for (std::vector<bool>::iterator it = rbMap.begin (); it != rbMap.end (); it++)
1641  {
1642  if ((*it) == true )
1643  {
1644  rbAllocatedNum++;
1645  }
1646  }
1647 
1648  uint8_t minContinuousUlBandwidth = m_ffrSapProvider->GetMinContinuousUlBandwidth ();
1649  uint8_t ffrUlBandwidth = m_cschedCellConfig.m_ulBandwidth - rbAllocatedNum;
1650 
1651  // remove RACH allocation
1652  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1653  {
1654  if (rbgAllocationMap.at (i) != 0)
1655  {
1656  rbMap.at (i) = true;
1657  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1658  }
1659  }
1660 
1661 
1662  if (m_harqOn == true)
1663  {
1664  // Process UL HARQ feedback
1665  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1666  {
1667  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1668  {
1669  // retx correspondent block: retrieve the UL-DCI
1670  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1671  std::map <uint16_t, uint8_t>::iterator itProcId = m_ulHarqCurrentProcessId.find (rnti);
1672  if (itProcId == m_ulHarqCurrentProcessId.end ())
1673  {
1674  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1675  }
1676  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1677  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1678  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1679  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1680  {
1681  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1682  continue;
1683  }
1684  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1685  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1686  if (itStat == m_ulHarqProcessesStatus.end ())
1687  {
1688  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1689  }
1690  if ((*itStat).second.at (harqId) >= 3)
1691  {
1692  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1693  continue;
1694  }
1695  bool free = true;
1696  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1697  {
1698  if (rbMap.at (j) == true)
1699  {
1700  free = false;
1701  NS_LOG_INFO (this << " BUSY " << j);
1702  }
1703  }
1704  if (free)
1705  {
1706  // retx on the same RBs
1707  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1708  {
1709  rbMap.at (j) = true;
1710  rbgAllocationMap.at (j) = dci.m_rnti;
1711  NS_LOG_INFO ("\tRB " << j);
1712  rbAllocatedNum++;
1713  }
1714  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);
1715  }
1716  else
1717  {
1718  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1719  continue;
1720  }
1721  dci.m_ndi = 0;
1722  // Update HARQ buffers with new HarqId
1723  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1724  (*itStat).second.at (harqId) = 0;
1725  (*itHarq).second.at ((*itProcId).second) = dci;
1726  ret.m_dciList.push_back (dci);
1727  rntiAllocated.insert (dci.m_rnti);
1728  }
1729  else
1730  {
1731  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1732  }
1733  }
1734  }
1735 
1736  std::map <uint16_t,uint32_t>::iterator it;
1737  int nflows = 0;
1738 
1739  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1740  {
1741  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1742  // select UEs with queues not empty and not yet allocated for HARQ
1743  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1744  {
1745  nflows++;
1746  }
1747  }
1748 
1749  if (nflows == 0)
1750  {
1751  if (ret.m_dciList.size () > 0)
1752  {
1753  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1755  }
1756 
1757  return; // no flows to be scheduled
1758  }
1759 
1760 
1761  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1762  uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size ());
1763  uint16_t rbPerFlow = (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1764 
1765  if (rbPerFlow < 3)
1766  {
1767  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1768  }
1769  int rbAllocated = 0;
1770 
1771  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator itStats;
1772  if (m_nextRntiUl != 0)
1773  {
1774  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1775  {
1776  if ((*it).first == m_nextRntiUl)
1777  {
1778  break;
1779  }
1780  }
1781  if (it == m_ceBsrRxed.end ())
1782  {
1783  NS_LOG_ERROR (this << " no user found");
1784  }
1785  }
1786  else
1787  {
1788  it = m_ceBsrRxed.begin ();
1789  m_nextRntiUl = (*it).first;
1790  }
1791  do
1792  {
1793  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1794  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1795  {
1796  // UE already allocated for UL-HARQ -> skip it
1797  NS_LOG_DEBUG (this << " UE already allocated in HARQ -> discared, RNTI " << (*it).first);
1798  it++;
1799  if (it == m_ceBsrRxed.end ())
1800  {
1801  // restart from the first
1802  it = m_ceBsrRxed.begin ();
1803  }
1804  continue;
1805  }
1806  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1807  {
1808  // limit to physical resources last resource assignment
1809  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1810  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1811  if (rbPerFlow < 3)
1812  {
1813  // terminate allocation
1814  rbPerFlow = 0;
1815  }
1816  }
1817 
1818  rbAllocated = 0;
1819  UlDciListElement_s uldci;
1820  uldci.m_rnti = (*it).first;
1821  uldci.m_rbLen = rbPerFlow;
1822  bool allocated = false;
1823  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1824  while ((!allocated)&&((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) && (rbPerFlow != 0))
1825  {
1826  // check availability
1827  bool free = true;
1828  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1829  {
1830  if (rbMap.at (j) == true)
1831  {
1832  free = false;
1833  break;
1834  }
1835  if ((m_ffrSapProvider->IsUlRbgAvailableForUe (j, (*it).first)) == false)
1836  {
1837  free = false;
1838  break;
1839  }
1840  }
1841  if (free)
1842  {
1843  NS_LOG_INFO (this << "RNTI: " << (*it).first << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1844  uldci.m_rbStart = rbAllocated;
1845 
1846  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1847  {
1848  rbMap.at (j) = true;
1849  // store info on allocation for managing ul-cqi interpretation
1850  rbgAllocationMap.at (j) = (*it).first;
1851  }
1852  rbAllocated += rbPerFlow;
1853  allocated = true;
1854  break;
1855  }
1856  rbAllocated++;
1857  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1858  {
1859  // limit to physical resources last resource assignment
1860  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1861  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1862  if (rbPerFlow < 3)
1863  {
1864  // terminate allocation
1865  rbPerFlow = 0;
1866  }
1867  }
1868  }
1869  if (!allocated)
1870  {
1871  // unable to allocate new resource: finish scheduling
1872 // m_nextRntiUl = (*it).first;
1873 // if (ret.m_dciList.size () > 0)
1874 // {
1875 // m_schedSapUser->SchedUlConfigInd (ret);
1876 // }
1877 // m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1878 // return;
1879  break;
1880  }
1881 
1882 
1883 
1884  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1885  int cqi = 0;
1886  if (itCqi == m_ueCqi.end ())
1887  {
1888  // no cqi info about this UE
1889  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1890  }
1891  else
1892  {
1893  // take the lowest CQI value (worst RB)
1894  NS_ABORT_MSG_IF ((*itCqi).second.size () == 0, "CQI of RNTI = " << (*it).first << " has expired");
1895  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1896  if (minSinr == NO_SINR)
1897  {
1898  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1899  }
1900  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1901  {
1902  double sinr = (*itCqi).second.at (i);
1903  if (sinr == NO_SINR)
1904  {
1905  sinr = EstimateUlSinr ((*it).first, i);
1906  }
1907  if (sinr < minSinr)
1908  {
1909  minSinr = sinr;
1910  }
1911  }
1912 
1913  // translate SINR -> cqi: WILD ACK: same as DL
1914  double s = log2 ( 1 + (
1915  std::pow (10, minSinr / 10 ) /
1916  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1917  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1918  if (cqi == 0)
1919  {
1920  it++;
1921  if (it == m_ceBsrRxed.end ())
1922  {
1923  // restart from the first
1924  it = m_ceBsrRxed.begin ();
1925  }
1926  NS_LOG_DEBUG (this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1927  // remove UE from allocation map
1928  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1929  {
1930  rbgAllocationMap.at (i) = 0;
1931  }
1932  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1933  }
1934  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1935  }
1936 
1937  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1938  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1939  uldci.m_ndi = 1;
1940  uldci.m_cceIndex = 0;
1941  uldci.m_aggrLevel = 1;
1942  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1943  uldci.m_hopping = false;
1944  uldci.m_n2Dmrs = 0;
1945  uldci.m_tpc = 0; // no power control
1946  uldci.m_cqiRequest = false; // only period CQI at this stage
1947  uldci.m_ulIndex = 0; // TDD parameter
1948  uldci.m_dai = 1; // TDD parameter
1949  uldci.m_freqHopping = 0;
1950  uldci.m_pdcchPowerOffset = 0; // not used
1951  ret.m_dciList.push_back (uldci);
1952  // store DCI for HARQ_PERIOD
1953  uint8_t harqId = 0;
1954  if (m_harqOn == true)
1955  {
1956  std::map <uint16_t, uint8_t>::iterator itProcId;
1957  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1958  if (itProcId == m_ulHarqCurrentProcessId.end ())
1959  {
1960  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1961  }
1962  harqId = (*itProcId).second;
1963  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1964  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1965  {
1966  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1967  }
1968  (*itDci).second.at (harqId) = uldci;
1969  // Update HARQ process status (RV 0)
1970  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (uldci.m_rnti);
1971  if (itStat == m_ulHarqProcessesStatus.end ())
1972  {
1973  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << uldci.m_rnti);
1974  }
1975  (*itStat).second.at (harqId) = 0;
1976  }
1977 
1978  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);
1979 
1980  it++;
1981  if (it == m_ceBsrRxed.end ())
1982  {
1983  // restart from the first
1984  it = m_ceBsrRxed.begin ();
1985  }
1986  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1987  {
1988  // Stop allocation: no more PRBs
1989  m_nextRntiUl = (*it).first;
1990  break;
1991  }
1992  }
1993  while (((*it).first != m_nextRntiUl)&&(rbPerFlow != 0));
1994 
1995 
1996  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1998 
1999  return;
2000 }
2001 
2002 void
2004 {
2005  NS_LOG_FUNCTION (this);
2006  return;
2007 }
2008 
2009 void
2011 {
2012  NS_LOG_FUNCTION (this);
2013  return;
2014 }
2015 
2016 void
2018 {
2019  NS_LOG_FUNCTION (this);
2020 
2021  std::map <uint16_t,uint32_t>::iterator it;
2022 
2023  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
2024  {
2025  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
2026  {
2027  // buffer status report
2028  // note that this scheduler does not differentiate the
2029  // allocation according to which LCGs have more/less bytes
2030  // to send.
2031  // Hence the BSR of different LCGs are just summed up to get
2032  // a total queue size that is used for allocation purposes.
2033 
2034  uint32_t buffer = 0;
2035  for (uint8_t lcg = 0; lcg < 4; ++lcg)
2036  {
2037  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
2038  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
2039  }
2040 
2041  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
2042  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
2043  it = m_ceBsrRxed.find (rnti);
2044  if (it == m_ceBsrRxed.end ())
2045  {
2046  // create the new entry
2047  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
2048  }
2049  else
2050  {
2051  // update the buffer size value
2052  (*it).second = buffer;
2053  }
2054  }
2055  }
2056 
2057  return;
2058 }
2059 
2060 void
2062 {
2063  NS_LOG_FUNCTION (this);
2064 // retrieve the allocation for this subframe
2065  switch (m_ulCqiFilter)
2066  {
2068  {
2069  // filter all the CQIs that are not SRS based
2070  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
2071  {
2072  return;
2073  }
2074  }
2075  break;
2077  {
2078  // filter all the CQIs that are not SRS based
2079  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2080  {
2081  return;
2082  }
2083  }
2084  break;
2085  default:
2086  NS_FATAL_ERROR ("Unknown UL CQI type");
2087  }
2088 
2089  switch (params.m_ulCqi.m_type)
2090  {
2091  case UlCqi_s::PUSCH:
2092  {
2093  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
2094  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2095  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
2096  itMap = m_allocationMaps.find (params.m_sfnSf);
2097  if (itMap == m_allocationMaps.end ())
2098  {
2099  return;
2100  }
2101  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
2102  {
2103  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2104  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
2105  itCqi = m_ueCqi.find ((*itMap).second.at (i));
2106  if (itCqi == m_ueCqi.end ())
2107  {
2108  // create a new entry
2109  std::vector <double> newCqi;
2110  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2111  {
2112  if (i == j)
2113  {
2114  newCqi.push_back (sinr);
2115  }
2116  else
2117  {
2118  // initialize with NO_SINR value.
2119  newCqi.push_back (NO_SINR);
2120  }
2121 
2122  }
2123  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
2124  // generate correspondent timer
2125  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
2126  }
2127  else
2128  {
2129  // update the value
2130  (*itCqi).second.at (i) = sinr;
2131  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
2132  // update correspondent timer
2133  std::map <uint16_t, uint32_t>::iterator itTimers;
2134  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
2135  (*itTimers).second = m_cqiTimersThreshold;
2136 
2137  }
2138 
2139  }
2140  // remove obsolete info on allocation
2141  m_allocationMaps.erase (itMap);
2142  }
2143  break;
2144  case UlCqi_s::SRS:
2145  {
2146  // get the RNTI from vendor specific parameters
2147  uint16_t rnti = 0;
2148  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
2149  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
2150  {
2151  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
2152  {
2153  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
2154  rnti = vsp->GetRnti ();
2155  }
2156  }
2157  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2158  itCqi = m_ueCqi.find (rnti);
2159  if (itCqi == m_ueCqi.end ())
2160  {
2161  // create a new entry
2162  std::vector <double> newCqi;
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  newCqi.push_back (sinr);
2167  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
2168 
2169  }
2170  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
2171  // generate correspondent timer
2172  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
2173  }
2174  else
2175  {
2176  // update the values
2177  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2178  {
2179  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2180  (*itCqi).second.at (j) = sinr;
2181  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
2182  }
2183  // update correspondent timer
2184  std::map <uint16_t, uint32_t>::iterator itTimers;
2185  itTimers = m_ueCqiTimers.find (rnti);
2186  (*itTimers).second = m_cqiTimersThreshold;
2187 
2188  }
2189 
2190 
2191  }
2192  break;
2193  case UlCqi_s::PUCCH_1:
2194  case UlCqi_s::PUCCH_2:
2195  case UlCqi_s::PRACH:
2196  {
2197  NS_FATAL_ERROR ("FdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2198  }
2199  break;
2200  default:
2201  NS_FATAL_ERROR ("Unknown type of UL-CQI");
2202  }
2203  return;
2204 }
2205 
2206 void
2208 {
2209  // refresh DL CQI P01 Map
2210  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
2211  while (itP10 != m_p10CqiTimers.end ())
2212  {
2213  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2214  if ((*itP10).second == 0)
2215  {
2216  // delete correspondent entries
2217  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
2218  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
2219  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
2220  m_p10CqiRxed.erase (itMap);
2221  std::map <uint16_t,uint32_t>::iterator temp = itP10;
2222  itP10++;
2223  m_p10CqiTimers.erase (temp);
2224  }
2225  else
2226  {
2227  (*itP10).second--;
2228  itP10++;
2229  }
2230  }
2231 
2232  // refresh DL CQI A30 Map
2233  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
2234  while (itA30 != m_a30CqiTimers.end ())
2235  {
2236  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2237  if ((*itA30).second == 0)
2238  {
2239  // delete correspondent entries
2240  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
2241  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
2242  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
2243  m_a30CqiRxed.erase (itMap);
2244  std::map <uint16_t,uint32_t>::iterator temp = itA30;
2245  itA30++;
2246  m_a30CqiTimers.erase (temp);
2247  }
2248  else
2249  {
2250  (*itA30).second--;
2251  itA30++;
2252  }
2253  }
2254 
2255  return;
2256 }
2257 
2258 
2259 void
2261 {
2262  // refresh UL CQI Map
2263  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
2264  while (itUl != m_ueCqiTimers.end ())
2265  {
2266  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2267  if ((*itUl).second == 0)
2268  {
2269  // delete correspondent entries
2270  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
2271  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
2272  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
2273  (*itMap).second.clear ();
2274  m_ueCqi.erase (itMap);
2275  std::map <uint16_t,uint32_t>::iterator temp = itUl;
2276  itUl++;
2277  m_ueCqiTimers.erase (temp);
2278  }
2279  else
2280  {
2281  (*itUl).second--;
2282  itUl++;
2283  }
2284  }
2285 
2286  return;
2287 }
2288 
2289 void
2290 FdTbfqFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
2291 {
2292  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2293  LteFlowId_t flow (rnti, lcid);
2294  it = m_rlcBufferReq.find (flow);
2295  if (it != m_rlcBufferReq.end ())
2296  {
2297  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);
2298  // Update queues: RLC tx order Status, ReTx, Tx
2299  // Update status queue
2300  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2301  {
2302  (*it).second.m_rlcStatusPduSize = 0;
2303  }
2304  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2305  {
2306  (*it).second.m_rlcRetransmissionQueueSize = 0;
2307  }
2308  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2309  {
2310  uint32_t rlcOverhead;
2311  if (lcid == 1)
2312  {
2313  // for SRB1 (using RLC AM) it's better to
2314  // overestimate RLC overhead rather than
2315  // underestimate it and risk unneeded
2316  // segmentation which increases delay
2317  rlcOverhead = 4;
2318  }
2319  else
2320  {
2321  // minimum RLC overhead due to header
2322  rlcOverhead = 2;
2323  }
2324  // update transmission queue
2325  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2326  {
2327  (*it).second.m_rlcTransmissionQueueSize = 0;
2328  }
2329  else
2330  {
2331  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2332  }
2333  }
2334  }
2335  else
2336  {
2337  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2338  }
2339 }
2340 
2341 void
2342 FdTbfqFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2343 {
2344 
2345  size = size - 2; // remove the minimum RLC overhead
2346  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2347  if (it != m_ceBsrRxed.end ())
2348  {
2349  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2350  if ((*it).second >= size)
2351  {
2352  (*it).second -= size;
2353  }
2354  else
2355  {
2356  (*it).second = 0;
2357  }
2358  }
2359  else
2360  {
2361  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2362  }
2363 
2364 }
2365 
2366 void
2368 {
2369  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2371  params.m_rnti = rnti;
2372  params.m_transmissionMode = txMode;
2374 }
2375 
2376 
2377 }
AttributeValue implementation for Boolean.
Definition: boolean.h:37
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Definition: lte-common.cc:184
Implements the SCHED SAP and CSCHED SAP for a Frequency Domain Token Bank Fair Queue scheduler.
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
Set FF MAC sched SAP user function.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request function.
std::vector< struct RachListElement_s > m_rachList
RACH list.
uint32_t m_tokenPoolSize
maximum size of token pool (byte)
std::map< uint16_t, fdtbfqsFlowPerf_t > m_flowStatsUl
Map of UE statistics (per RNTI basis)
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request function.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
virtual ~FdTbfqFfMacScheduler()
Destructor.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
uint64_t bankSize
the number of bytes in token bank
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request function.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request function.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
friend class MemberSchedSapProvider< FdTbfqFfMacScheduler >
allow MemberSchedSapProvider<FdTbfqFfMacScheduler> claass friend access
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
virtual void DoDispose(void)
Destructor implementation.
void RefreshDlCqiMaps(void)
Refresh DL CQI maps function.
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request function.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request function.
virtual void SetLteFfrSapProvider(LteFfrSapProvider *s)
Set FFR SAP provider function.
uint32_t m_creditableThreshold
threshold of flow credit
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
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, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
static TypeId GetTypeId(void)
Get the type ID.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request function.
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request function.
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request function.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
Csched cell config.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL SNR function.
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
Set FF MAC Csched SAP user function.
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request function.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
Get FF MAC sched SAP provider function.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmisson mode config update function.
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request function.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
uint32_t m_creditLimit
flow credit limit (byte)
int m_debtLimit
flow debt limit (byte)
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request function.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
Get FF MAC CSched SAP provider function.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
Csched cell config request function.
FfMacSchedSapProvider * m_schedSapProvider
sched SAP provider
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request function.
void RefreshUlCqiMaps(void)
Refresh UL CQI maps function.
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request function.
std::map< uint16_t, fdtbfqsFlowPerf_t > m_flowStatsDl
Map of UE statistics (per RNTI basis) in downlink.
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
FfMacSchedSapUser * m_schedSapUser
sched SAP user
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
unsigned int LcActivePerFlow(uint16_t rnti)
LC Active per flow function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
FfMacCschedSapUser * m_cschedSapUser
Csched SAP user.
friend class MemberCschedSapProvider< FdTbfqFfMacScheduler >
allow MemberCschedSapProvider<FdTbfqFfMacScheduler> class friend access
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
virtual LteFfrSapUser * GetLteFfrSapUser()
Get FFR SAP user function.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request function.
Provides the CSCHED SAP.
FfMacCschedSapUser class.
virtual void CschedUeConfigUpdateInd(const struct CschedUeConfigUpdateIndParameters &params)=0
CSCHED_UE_UPDATE_IND.
virtual void CschedUeConfigCnf(const struct CschedUeConfigCnfParameters &params)=0
CSCHED_UE_CONFIG_CNF.
Provides the SCHED SAP.
FfMacSchedSapUser class.
virtual void SchedUlConfigInd(const struct SchedUlConfigIndParameters &params)=0
SCHED_UL_CONFIG_IND.
virtual void SchedDlConfigInd(const struct SchedDlConfigIndParameters &params)=0
SCHED_DL_CONFIG_IND.
This abstract base class identifies the interface by means of which the helper object can plug on the...
UlCqiFilter_t m_ulCqiFilter
UL CQI filter.
Hold a signed integer type.
Definition: integer.h:44
static double fpS11dot3toDouble(uint16_t val)
Convert from fixed point S11.3 notation to double.
Definition: lte-common.cc:155
Service Access Point (SAP) offered by the Frequency Reuse algorithm instance to the MAC Scheduler ins...
Definition: lte-ffr-sap.h:40
virtual uint8_t GetTpc(uint16_t rnti)=0
GetTpc.
virtual void ReportUlCqiInfo(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)=0
ReportUlCqiInfo.
virtual bool IsUlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in UL.
virtual uint16_t GetMinContinuousUlBandwidth()=0
Get the minimum continuous Ul bandwidth.
virtual bool IsDlRbgAvailableForUe(int i, uint16_t rnti)=0
Check if UE can be served on i-th RB in DL.
virtual void ReportDlCqiInfo(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)=0
ReportDlCqiInfo.
virtual std::vector< bool > GetAvailableUlRbg()=0
Get vector of available RB in UL for this Cell.
virtual std::vector< bool > GetAvailableDlRbg()=0
Get vector of available RBG in DL for this Cell.
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Definition: lte-ffr-sap.h:139
Template for the implementation of the LteFfrSapUser as a member of an owner class of type C to which...
Definition: lte-ffr-sap.h:256
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
@ MS
millisecond
Definition: nstime.h:115
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
Definition: lte-common.cc:212
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NO_SINR
#define HARQ_PROC_NUM
#define HARQ_DL_TIMEOUT
#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
#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
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
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
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
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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define HARQ_PERIOD
Definition: lte-common.h:30
#define SRS_CQI_RNTI_VSP
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector typedef.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector typedef.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
vector of the 8 HARQ processes per UE
@ SUCCESS
Definition: ff-mac-common.h:62
static const int FdTbfqType0AllocationRbg[4]
FdTbfqType0AllocationRbg value array.
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector typedef.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
See section 4.3.8 builDataListElement.
struct DlDciListElement_s m_dci
DCI.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
RLC PDU list.
See section 4.3.10 buildRARListElement.
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:94
std::vector< uint8_t > m_ndi
New data indicator.
uint8_t m_harqProcess
HARQ process.
uint32_t m_rbBitmap
RB bitmap.
Definition: ff-mac-common.h:96
std::vector< uint8_t > m_mcs
MCS.
uint8_t m_resAlloc
The type of resource allocation.
Definition: ff-mac-common.h:98
std::vector< uint16_t > m_tbsSize
The TBs size.
Definition: ff-mac-common.h:99
std::vector< uint8_t > m_rv
Redundancy version.
uint8_t m_tpc
Tx power control command.
Parameters of the CSCHED_LC_CONFIG_REQ primitive.
std::vector< struct LogicalChannelConfigListElement_s > m_logicalChannelConfigList
logicalChannelConfigList
Parameters of the CSCHED_LC_RELEASE_REQ primitive.
std::vector< uint8_t > m_logicalChannelIdentity
logical channel identity
Parameters of the CSCHED_UE_CONFIG_REQ primitive.
Parameters of the CSCHED_UE_RELEASE_REQ primitive.
Parameters of the CSCHED_UE_CONFIG_CNF primitive.
Parameters of the CSCHED_UE_CONFIG_UPDATE_IND primitive.
Parameters of the SCHED_DL_CQI_INFO_REQ primitive.
std::vector< struct CqiListElement_s > m_cqiList
CQI list.
Parameters of the SCHED_DL_MAC_BUFFER_REQ primitive.
Parameters of the SCHED_DL_PAGING_BUFFER_REQ primitive.
Parameters of the SCHED_DL_RACH_INFO_REQ primitive.
std::vector< struct RachListElement_s > m_rachList
RACH list.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
std::vector< struct DlInfoListElement_s > m_dlInfoList
DL info list.
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
std::vector< struct VendorSpecificListElement_s > m_vendorSpecificList
vendor specific list
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
std::vector< struct MacCeListElement_s > m_macCeList
MAC CE list.
Parameters of the SCHED_UL_NOISE_INTERFERENCE_REQ primitive.
Parameters of the SCHED_UL_SR_INFO_REQ primitive.
Parameters of the SCHED_UL_TRIGGER_REQ primitive.
std::vector< struct UlInfoListElement_s > m_ulInfoList
UL info list.
uint8_t m_nrOfPdcchOfdmSymbols
number of PDCCH OFDM symbols
std::vector< struct BuildDataListElement_s > m_buildDataList
build data list
std::vector< struct BuildRarListElement_s > m_buildRarList
build rar list
Parameters of the SCHED_UL_CONFIG_IND primitive.
std::vector< struct UlDciListElement_s > m_dciList
DCI list.
LteFlowId structure.
Definition: lte-common.h:37
See section 4.3.9 rlcPDU_ListElement.
uint8_t m_logicalChannelIdentity
logical channel identity
std::vector< uint16_t > m_sinr
SINR.
See section 4.3.2 ulDciListElement.
int8_t m_pdcchPowerOffset
CCH power offset.
int8_t m_tpc
Tx power control command.
uint8_t m_dai
DL assignment index.
uint8_t m_cceIndex
Control Channel Element index.
uint8_t m_ulIndex
UL index.
uint8_t m_ueTxAntennaSelection
UE antenna selection.
bool m_cqiRequest
CQI request.
uint8_t m_n2Dmrs
n2 DMRS
uint8_t m_freqHopping
freq hopping
uint8_t m_aggrLevel
The aggregation level.
bool m_ulDelay
UL delay?
int8_t m_tpc
Tx power control command.
bool m_cqiRequest
CQI request?
bool m_hopping
hopping?
uint16_t m_tbSize
size
uint8_t m_rbLen
length
uint8_t m_mcs
MCS.
uint8_t m_rbStart
start
uint16_t m_rnti
RNTI.
Time flowStart
flow start time
int counter
the number of token borrow or given to token bank
uint32_t burstCredit
the maximum number of tokens connection i can borrow from the bank each time
int debtLimit
counter threshold that the flow cannot further borrow tokens from bank
uint32_t creditableThreshold
the flow cannot borrow token from bank until the number of token it has deposited to bank reaches thi...
uint64_t packetArrivalRate
packet arrival rate( byte/s)
uint32_t tokenPoolSize
current size of token pool (byte)
uint32_t maxTokenPoolSize
maximum size of token pool (byte)
uint64_t tokenGenerationRate
token generation rate ( byte/s )