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