A Discrete-Event Network Simulator
API
tdbet-ff-mac-scheduler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Marco Miozzo <marco.miozzo@cttc.es>
18  * Modification: Dizhi Zhou <dizhi.zhou@gmail.com> // modify codes related to downlink scheduler
19  */
20 
21 #include "tdbet-ff-mac-scheduler.h"
22 
23 #include "lte-amc.h"
25 
26 #include <ns3/boolean.h>
27 #include <ns3/log.h>
28 #include <ns3/math.h>
29 #include <ns3/pointer.h>
30 #include <ns3/simulator.h>
31 
32 #include <cfloat>
33 #include <set>
34 
35 namespace ns3
36 {
37 
38 NS_LOG_COMPONENT_DEFINE("TdBetFfMacScheduler");
39 
41 static const int TdBetType0AllocationRbg[4] = {
42  10, // RGB size 1
43  26, // RGB size 2
44  63, // RGB size 3
45  110, // RGB size 4
46 }; // see table 7.1.6.1-1 of 36.213
47 
48 NS_OBJECT_ENSURE_REGISTERED(TdBetFfMacScheduler);
49 
51  : m_cschedSapUser(nullptr),
52  m_schedSapUser(nullptr),
53  m_timeWindow(99.0),
54  m_nextRntiUl(0)
55 {
56  m_amc = CreateObject<LteAmc>();
59 }
60 
62 {
63  NS_LOG_FUNCTION(this);
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION(this);
71  m_dlHarqProcessesTimer.clear();
73  m_dlInfoListBuffered.clear();
77  delete m_cschedSapProvider;
78  delete m_schedSapProvider;
79 }
80 
81 TypeId
83 {
84  static TypeId tid =
85  TypeId("ns3::TdBetFfMacScheduler")
87  .SetGroupName("Lte")
88  .AddConstructor<TdBetFfMacScheduler>()
89  .AddAttribute("CqiTimerThreshold",
90  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
91  UintegerValue(1000),
93  MakeUintegerChecker<uint32_t>())
94  .AddAttribute("HarqEnabled",
95  "Activate/Deactivate the HARQ [by default is active].",
96  BooleanValue(true),
99  .AddAttribute("UlGrantMcs",
100  "The MCS of the UL grant, must be [0..15] (default 0)",
101  UintegerValue(0),
103  MakeUintegerChecker<uint8_t>());
104  return tid;
105 }
106 
107 void
109 {
110  m_cschedSapUser = s;
111 }
112 
113 void
115 {
116  m_schedSapUser = s;
117 }
118 
121 {
122  return m_cschedSapProvider;
123 }
124 
127 {
128  return m_schedSapProvider;
129 }
130 
131 void
133 {
134  m_ffrSapProvider = s;
135 }
136 
139 {
140  return m_ffrSapUser;
141 }
142 
143 void
146 {
147  NS_LOG_FUNCTION(this);
148  // Read the subset of parameters used
152  cnf.m_result = SUCCESS;
154 }
155 
156 void
159 {
160  NS_LOG_FUNCTION(this << " RNTI " << params.m_rnti << " txMode "
161  << (uint16_t)params.m_transmissionMode);
162  auto it = m_uesTxMode.find(params.m_rnti);
163  if (it == m_uesTxMode.end())
164  {
165  m_uesTxMode[params.m_rnti] = params.m_transmissionMode;
166  // generate HARQ buffers
167  m_dlHarqCurrentProcessId[params.m_rnti] = 0;
168  DlHarqProcessesStatus_t dlHarqPrcStatus;
169  dlHarqPrcStatus.resize(8, 0);
170  m_dlHarqProcessesStatus[params.m_rnti] = dlHarqPrcStatus;
171  DlHarqProcessesTimer_t dlHarqProcessesTimer;
172  dlHarqProcessesTimer.resize(8, 0);
173  m_dlHarqProcessesTimer[params.m_rnti] = dlHarqProcessesTimer;
174  DlHarqProcessesDciBuffer_t dlHarqdci;
175  dlHarqdci.resize(8);
176  m_dlHarqProcessesDciBuffer[params.m_rnti] = dlHarqdci;
177  DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
178  dlHarqRlcPdu.resize(2);
179  dlHarqRlcPdu.at(0).resize(8);
180  dlHarqRlcPdu.at(1).resize(8);
181  m_dlHarqProcessesRlcPduListBuffer[params.m_rnti] = dlHarqRlcPdu;
182  m_ulHarqCurrentProcessId[params.m_rnti] = 0;
183  UlHarqProcessesStatus_t ulHarqPrcStatus;
184  ulHarqPrcStatus.resize(8, 0);
185  m_ulHarqProcessesStatus[params.m_rnti] = ulHarqPrcStatus;
186  UlHarqProcessesDciBuffer_t ulHarqdci;
187  ulHarqdci.resize(8);
188  m_ulHarqProcessesDciBuffer[params.m_rnti] = ulHarqdci;
189  }
190  else
191  {
192  (*it).second = params.m_transmissionMode;
193  }
194 }
195 
196 void
199 {
200  NS_LOG_FUNCTION(this << " New LC, rnti: " << params.m_rnti);
201 
202  for (std::size_t i = 0; i < params.m_logicalChannelConfigList.size(); i++)
203  {
204  auto it = m_flowStatsDl.find(params.m_rnti);
205 
206  if (it == m_flowStatsDl.end())
207  {
208  tdbetsFlowPerf_t flowStatsDl;
209  flowStatsDl.flowStart = Simulator::Now();
210  flowStatsDl.totalBytesTransmitted = 0;
211  flowStatsDl.lastTtiBytesTransmitted = 0;
212  flowStatsDl.lastAveragedThroughput = 1;
213  m_flowStatsDl[params.m_rnti] = flowStatsDl;
214  tdbetsFlowPerf_t flowStatsUl;
215  flowStatsUl.flowStart = Simulator::Now();
216  flowStatsUl.totalBytesTransmitted = 0;
217  flowStatsUl.lastTtiBytesTransmitted = 0;
218  flowStatsUl.lastAveragedThroughput = 1;
219  m_flowStatsUl[params.m_rnti] = flowStatsUl;
220  }
221  }
222 }
223 
224 void
227 {
228  NS_LOG_FUNCTION(this);
229  for (std::size_t i = 0; i < params.m_logicalChannelIdentity.size(); i++)
230  {
231  auto it = m_rlcBufferReq.begin();
232  while (it != m_rlcBufferReq.end())
233  {
234  if (((*it).first.m_rnti == params.m_rnti) &&
235  ((*it).first.m_lcId == params.m_logicalChannelIdentity.at(i)))
236  {
237  auto temp = it;
238  it++;
239  m_rlcBufferReq.erase(temp);
240  }
241  else
242  {
243  it++;
244  }
245  }
246  }
247 }
248 
249 void
252 {
253  NS_LOG_FUNCTION(this);
254 
255  m_uesTxMode.erase(params.m_rnti);
256  m_dlHarqCurrentProcessId.erase(params.m_rnti);
257  m_dlHarqProcessesStatus.erase(params.m_rnti);
258  m_dlHarqProcessesTimer.erase(params.m_rnti);
259  m_dlHarqProcessesDciBuffer.erase(params.m_rnti);
261  m_ulHarqCurrentProcessId.erase(params.m_rnti);
262  m_ulHarqProcessesStatus.erase(params.m_rnti);
263  m_ulHarqProcessesDciBuffer.erase(params.m_rnti);
264  m_flowStatsDl.erase(params.m_rnti);
265  m_flowStatsUl.erase(params.m_rnti);
266  m_ceBsrRxed.erase(params.m_rnti);
267  auto it = m_rlcBufferReq.begin();
268  while (it != m_rlcBufferReq.end())
269  {
270  if ((*it).first.m_rnti == params.m_rnti)
271  {
272  auto temp = it;
273  it++;
274  m_rlcBufferReq.erase(temp);
275  }
276  else
277  {
278  it++;
279  }
280  }
281  if (m_nextRntiUl == params.m_rnti)
282  {
283  m_nextRntiUl = 0;
284  }
285 }
286 
287 void
290 {
291  NS_LOG_FUNCTION(this << params.m_rnti << (uint32_t)params.m_logicalChannelIdentity);
292  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
293 
294  LteFlowId_t flow(params.m_rnti, params.m_logicalChannelIdentity);
295 
296  auto it = m_rlcBufferReq.find(flow);
297 
298  if (it == m_rlcBufferReq.end())
299  {
300  m_rlcBufferReq[flow] = params;
301  }
302  else
303  {
304  (*it).second = params;
305  }
306 }
307 
308 void
311 {
312  NS_LOG_FUNCTION(this);
313  NS_FATAL_ERROR("method not implemented");
314 }
315 
316 void
319 {
320  NS_LOG_FUNCTION(this);
321  NS_FATAL_ERROR("method not implemented");
322 }
323 
324 int
326 {
327  for (int i = 0; i < 4; i++)
328  {
329  if (dlbandwidth < TdBetType0AllocationRbg[i])
330  {
331  return i + 1;
332  }
333  }
334 
335  return -1;
336 }
337 
338 unsigned int
340 {
341  unsigned int lcActive = 0;
342  for (auto it = m_rlcBufferReq.begin(); it != m_rlcBufferReq.end(); it++)
343  {
344  if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0) ||
345  ((*it).second.m_rlcRetransmissionQueueSize > 0) ||
346  ((*it).second.m_rlcStatusPduSize > 0)))
347  {
348  lcActive++;
349  }
350  if ((*it).first.m_rnti > rnti)
351  {
352  break;
353  }
354  }
355  return lcActive;
356 }
357 
358 bool
360 {
361  NS_LOG_FUNCTION(this << rnti);
362 
363  auto it = m_dlHarqCurrentProcessId.find(rnti);
364  if (it == m_dlHarqCurrentProcessId.end())
365  {
366  NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
367  }
368  auto itStat = m_dlHarqProcessesStatus.find(rnti);
369  if (itStat == m_dlHarqProcessesStatus.end())
370  {
371  NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
372  }
373  uint8_t i = (*it).second;
374  do
375  {
376  i = (i + 1) % HARQ_PROC_NUM;
377  } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
378 
379  return (*itStat).second.at(i) == 0;
380 }
381 
382 uint8_t
384 {
385  NS_LOG_FUNCTION(this << rnti);
386 
387  if (!m_harqOn)
388  {
389  return 0;
390  }
391 
392  auto it = m_dlHarqCurrentProcessId.find(rnti);
393  if (it == m_dlHarqCurrentProcessId.end())
394  {
395  NS_FATAL_ERROR("No Process Id found for this RNTI " << rnti);
396  }
397  auto itStat = m_dlHarqProcessesStatus.find(rnti);
398  if (itStat == m_dlHarqProcessesStatus.end())
399  {
400  NS_FATAL_ERROR("No Process Id Statusfound for this RNTI " << rnti);
401  }
402  uint8_t i = (*it).second;
403  do
404  {
405  i = (i + 1) % HARQ_PROC_NUM;
406  } while (((*itStat).second.at(i) != 0) && (i != (*it).second));
407  if ((*itStat).second.at(i) == 0)
408  {
409  (*it).second = i;
410  (*itStat).second.at(i) = 1;
411  }
412  else
413  {
414  NS_FATAL_ERROR("No HARQ process available for RNTI "
415  << rnti << " check before update with HarqProcessAvailability");
416  }
417 
418  return (*it).second;
419 }
420 
421 void
423 {
424  NS_LOG_FUNCTION(this);
425 
426  for (auto itTimers = m_dlHarqProcessesTimer.begin(); itTimers != m_dlHarqProcessesTimer.end();
427  itTimers++)
428  {
429  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
430  {
431  if ((*itTimers).second.at(i) == HARQ_DL_TIMEOUT)
432  {
433  // reset HARQ process
434 
435  NS_LOG_DEBUG(this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
436  auto itStat = m_dlHarqProcessesStatus.find((*itTimers).first);
437  if (itStat == m_dlHarqProcessesStatus.end())
438  {
439  NS_FATAL_ERROR("No Process Id Status found for this RNTI "
440  << (*itTimers).first);
441  }
442  (*itStat).second.at(i) = 0;
443  (*itTimers).second.at(i) = 0;
444  }
445  else
446  {
447  (*itTimers).second.at(i)++;
448  }
449  }
450  }
451 }
452 
453 void
456 {
457  NS_LOG_FUNCTION(this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
458  << (0xF & params.m_sfnSf));
459  // API generated by RLC for triggering the scheduling of a DL subframe
460 
461  // evaluate the relative channel quality indicator for each UE per each RBG
462  // (since we are using allocation type 0 the small unit of allocation is RBG)
463  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
464 
466 
468  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
469  std::map<uint16_t, std::vector<uint16_t>> allocationMap; // RBs map per RNTI
470  std::vector<bool> rbgMap; // global RBGs map
471  uint16_t rbgAllocatedNum = 0;
472  std::set<uint16_t> rntiAllocated;
473  rbgMap.resize(m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
475 
476  // update UL HARQ proc id
477  for (auto itProcId = m_ulHarqCurrentProcessId.begin();
478  itProcId != m_ulHarqCurrentProcessId.end();
479  itProcId++)
480  {
481  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
482  }
483 
484  // RACH Allocation
486  uint16_t rbStart = 0;
487  for (auto itRach = m_rachList.begin(); itRach != m_rachList.end(); itRach++)
488  {
490  (*itRach).m_estimatedSize,
491  " Default UL Grant MCS does not allow to send RACH messages");
492  BuildRarListElement_s newRar;
493  newRar.m_rnti = (*itRach).m_rnti;
494  // DL-RACH Allocation
495  // Ideal: no needs of configuring m_dci
496  // UL-RACH Allocation
497  newRar.m_grant.m_rnti = newRar.m_rnti;
498  newRar.m_grant.m_mcs = m_ulGrantMcs;
499  uint16_t rbLen = 1;
500  uint16_t tbSizeBits = 0;
501  // find lowest TB size that fits UL grant estimated size
502  while ((tbSizeBits < (*itRach).m_estimatedSize) &&
503  (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
504  {
505  rbLen++;
506  tbSizeBits = m_amc->GetUlTbSizeFromMcs(m_ulGrantMcs, rbLen);
507  }
508  if (tbSizeBits < (*itRach).m_estimatedSize)
509  {
510  // no more allocation space: finish allocation
511  break;
512  }
513  newRar.m_grant.m_rbStart = rbStart;
514  newRar.m_grant.m_rbLen = rbLen;
515  newRar.m_grant.m_tbSize = tbSizeBits / 8;
516  newRar.m_grant.m_hopping = false;
517  newRar.m_grant.m_tpc = 0;
518  newRar.m_grant.m_cqiRequest = false;
519  newRar.m_grant.m_ulDelay = false;
520  NS_LOG_INFO(this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart "
521  << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize "
522  << newRar.m_grant.m_tbSize);
523  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
524  {
525  m_rachAllocationMap.at(i) = (*itRach).m_rnti;
526  }
527 
528  if (m_harqOn)
529  {
530  // generate UL-DCI for HARQ retransmissions
531  UlDciListElement_s uldci;
532  uldci.m_rnti = newRar.m_rnti;
533  uldci.m_rbLen = rbLen;
534  uldci.m_rbStart = rbStart;
535  uldci.m_mcs = m_ulGrantMcs;
536  uldci.m_tbSize = tbSizeBits / 8;
537  uldci.m_ndi = 1;
538  uldci.m_cceIndex = 0;
539  uldci.m_aggrLevel = 1;
540  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
541  uldci.m_hopping = false;
542  uldci.m_n2Dmrs = 0;
543  uldci.m_tpc = 0; // no power control
544  uldci.m_cqiRequest = false; // only period CQI at this stage
545  uldci.m_ulIndex = 0; // TDD parameter
546  uldci.m_dai = 1; // TDD parameter
547  uldci.m_freqHopping = 0;
548  uldci.m_pdcchPowerOffset = 0; // not used
549 
550  uint8_t harqId = 0;
551  auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
552  if (itProcId == m_ulHarqCurrentProcessId.end())
553  {
554  NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
555  }
556  harqId = (*itProcId).second;
557  auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
558  if (itDci == m_ulHarqProcessesDciBuffer.end())
559  {
560  NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
561  << uldci.m_rnti);
562  }
563  (*itDci).second.at(harqId) = uldci;
564  }
565 
566  rbStart = rbStart + rbLen;
567  ret.m_buildRarList.push_back(newRar);
568  }
569  m_rachList.clear();
570 
571  // Process DL HARQ feedback
573  // retrieve past HARQ retx buffered
574  if (!m_dlInfoListBuffered.empty())
575  {
576  if (!params.m_dlInfoList.empty())
577  {
578  NS_LOG_INFO(this << " Received DL-HARQ feedback");
580  params.m_dlInfoList.begin(),
581  params.m_dlInfoList.end());
582  }
583  }
584  else
585  {
586  if (!params.m_dlInfoList.empty())
587  {
588  m_dlInfoListBuffered = params.m_dlInfoList;
589  }
590  }
591  if (!m_harqOn)
592  {
593  // Ignore HARQ feedback
594  m_dlInfoListBuffered.clear();
595  }
596  std::vector<DlInfoListElement_s> dlInfoListUntxed;
597  for (std::size_t i = 0; i < m_dlInfoListBuffered.size(); i++)
598  {
599  auto itRnti = rntiAllocated.find(m_dlInfoListBuffered.at(i).m_rnti);
600  if (itRnti != rntiAllocated.end())
601  {
602  // RNTI already allocated for retx
603  continue;
604  }
605  auto nLayers = m_dlInfoListBuffered.at(i).m_harqStatus.size();
606  std::vector<bool> retx;
607  NS_LOG_INFO(this << " Processing DLHARQ feedback");
608  if (nLayers == 1)
609  {
610  retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
612  retx.push_back(false);
613  }
614  else
615  {
616  retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(0) ==
618  retx.push_back(m_dlInfoListBuffered.at(i).m_harqStatus.at(1) ==
620  }
621  if (retx.at(0) || retx.at(1))
622  {
623  // retrieve HARQ process information
624  uint16_t rnti = m_dlInfoListBuffered.at(i).m_rnti;
625  uint8_t harqId = m_dlInfoListBuffered.at(i).m_harqProcessId;
626  NS_LOG_INFO(this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
627  auto itHarq = m_dlHarqProcessesDciBuffer.find(rnti);
628  if (itHarq == m_dlHarqProcessesDciBuffer.end())
629  {
630  NS_FATAL_ERROR("No info find in HARQ buffer for UE " << rnti);
631  }
632 
633  DlDciListElement_s dci = (*itHarq).second.at(harqId);
634  int rv = 0;
635  if (dci.m_rv.size() == 1)
636  {
637  rv = dci.m_rv.at(0);
638  }
639  else
640  {
641  rv = (dci.m_rv.at(0) > dci.m_rv.at(1) ? dci.m_rv.at(0) : dci.m_rv.at(1));
642  }
643 
644  if (rv == 3)
645  {
646  // maximum number of retx reached -> drop process
647  NS_LOG_INFO("Maximum number of retransmissions reached -> drop process");
648  auto it = m_dlHarqProcessesStatus.find(rnti);
649  if (it == m_dlHarqProcessesStatus.end())
650  {
651  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
652  << m_dlInfoListBuffered.at(i).m_rnti);
653  }
654  (*it).second.at(harqId) = 0;
655  auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
656  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
657  {
658  NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
659  << m_dlInfoListBuffered.at(i).m_rnti);
660  }
661  for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
662  {
663  (*itRlcPdu).second.at(k).at(harqId).clear();
664  }
665  continue;
666  }
667  // check the feasibility of retransmitting on the same RBGs
668  // translate the DCI to Spectrum framework
669  std::vector<int> dciRbg;
670  uint32_t mask = 0x1;
671  NS_LOG_INFO("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
672  for (int j = 0; j < 32; j++)
673  {
674  if (((dci.m_rbBitmap & mask) >> j) == 1)
675  {
676  dciRbg.push_back(j);
677  NS_LOG_INFO("\t" << j);
678  }
679  mask = (mask << 1);
680  }
681  bool free = true;
682  for (std::size_t j = 0; j < dciRbg.size(); j++)
683  {
684  if (rbgMap.at(dciRbg.at(j)))
685  {
686  free = false;
687  break;
688  }
689  }
690  if (free)
691  {
692  // use the same RBGs for the retx
693  // reserve RBGs
694  for (std::size_t j = 0; j < dciRbg.size(); j++)
695  {
696  rbgMap.at(dciRbg.at(j)) = true;
697  NS_LOG_INFO("RBG " << dciRbg.at(j) << " assigned");
698  rbgAllocatedNum++;
699  }
700 
701  NS_LOG_INFO(this << " Send retx in the same RBGs");
702  }
703  else
704  {
705  // find RBGs for sending HARQ retx
706  uint8_t j = 0;
707  uint8_t rbgId = (dciRbg.at(dciRbg.size() - 1) + 1) % rbgNum;
708  uint8_t startRbg = dciRbg.at(dciRbg.size() - 1);
709  std::vector<bool> rbgMapCopy = rbgMap;
710  while ((j < dciRbg.size()) && (startRbg != rbgId))
711  {
712  if (!rbgMapCopy.at(rbgId))
713  {
714  rbgMapCopy.at(rbgId) = true;
715  dciRbg.at(j) = rbgId;
716  j++;
717  }
718  rbgId = (rbgId + 1) % rbgNum;
719  }
720  if (j == dciRbg.size())
721  {
722  // find new RBGs -> update DCI map
723  uint32_t rbgMask = 0;
724  for (std::size_t k = 0; k < dciRbg.size(); k++)
725  {
726  rbgMask = rbgMask + (0x1 << dciRbg.at(k));
727  rbgAllocatedNum++;
728  }
729  dci.m_rbBitmap = rbgMask;
730  rbgMap = rbgMapCopy;
731  NS_LOG_INFO(this << " Move retx in RBGs " << dciRbg.size());
732  }
733  else
734  {
735  // HARQ retx cannot be performed on this TTI -> store it
736  dlInfoListUntxed.push_back(m_dlInfoListBuffered.at(i));
737  NS_LOG_INFO(this << " No resource for this retx -> buffer it");
738  }
739  }
740  // retrieve RLC PDU list for retx TBsize and update DCI
742  auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find(rnti);
743  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
744  {
745  NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
746  }
747  for (std::size_t j = 0; j < nLayers; j++)
748  {
749  if (retx.at(j))
750  {
751  if (j >= dci.m_ndi.size())
752  {
753  // for avoiding errors in MIMO transient phases
754  dci.m_ndi.push_back(0);
755  dci.m_rv.push_back(0);
756  dci.m_mcs.push_back(0);
757  dci.m_tbsSize.push_back(0);
758  NS_LOG_INFO(this << " layer " << (uint16_t)j
759  << " no txed (MIMO transition)");
760  }
761  else
762  {
763  dci.m_ndi.at(j) = 0;
764  dci.m_rv.at(j)++;
765  (*itHarq).second.at(harqId).m_rv.at(j)++;
766  NS_LOG_INFO(this << " layer " << (uint16_t)j << " RV "
767  << (uint16_t)dci.m_rv.at(j));
768  }
769  }
770  else
771  {
772  // empty TB of layer j
773  dci.m_ndi.at(j) = 0;
774  dci.m_rv.at(j) = 0;
775  dci.m_mcs.at(j) = 0;
776  dci.m_tbsSize.at(j) = 0;
777  NS_LOG_INFO(this << " layer " << (uint16_t)j << " no retx");
778  }
779  }
780  for (std::size_t k = 0; k < (*itRlcPdu).second.at(0).at(dci.m_harqProcess).size(); k++)
781  {
782  std::vector<RlcPduListElement_s> rlcPduListPerLc;
783  for (std::size_t j = 0; j < nLayers; j++)
784  {
785  if (retx.at(j))
786  {
787  if (j < dci.m_ndi.size())
788  {
789  NS_LOG_INFO(" layer " << (uint16_t)j << " tb size "
790  << dci.m_tbsSize.at(j));
791  rlcPduListPerLc.push_back(
792  (*itRlcPdu).second.at(j).at(dci.m_harqProcess).at(k));
793  }
794  }
795  else
796  { // if no retx needed on layer j, push an RlcPduListElement_s object with
797  // m_size=0 to keep the size of rlcPduListPerLc vector = 2 in case of MIMO
798  NS_LOG_INFO(" layer " << (uint16_t)j << " tb size " << dci.m_tbsSize.at(j));
799  RlcPduListElement_s emptyElement;
800  emptyElement.m_logicalChannelIdentity = (*itRlcPdu)
801  .second.at(j)
802  .at(dci.m_harqProcess)
803  .at(k)
804  .m_logicalChannelIdentity;
805  emptyElement.m_size = 0;
806  rlcPduListPerLc.push_back(emptyElement);
807  }
808  }
809 
810  if (!rlcPduListPerLc.empty())
811  {
812  newEl.m_rlcPduList.push_back(rlcPduListPerLc);
813  }
814  }
815  newEl.m_rnti = rnti;
816  newEl.m_dci = dci;
817  (*itHarq).second.at(harqId).m_rv = dci.m_rv;
818  // refresh timer
819  auto itHarqTimer = m_dlHarqProcessesTimer.find(rnti);
820  if (itHarqTimer == m_dlHarqProcessesTimer.end())
821  {
822  NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
823  }
824  (*itHarqTimer).second.at(harqId) = 0;
825  ret.m_buildDataList.push_back(newEl);
826  rntiAllocated.insert(rnti);
827  }
828  else
829  {
830  // update HARQ process status
831  NS_LOG_INFO(this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at(i).m_rnti);
832  auto it = m_dlHarqProcessesStatus.find(m_dlInfoListBuffered.at(i).m_rnti);
833  if (it == m_dlHarqProcessesStatus.end())
834  {
835  NS_FATAL_ERROR("No info find in HARQ buffer for UE "
836  << m_dlInfoListBuffered.at(i).m_rnti);
837  }
838  (*it).second.at(m_dlInfoListBuffered.at(i).m_harqProcessId) = 0;
839  auto itRlcPdu =
841  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
842  {
843  NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
844  << m_dlInfoListBuffered.at(i).m_rnti);
845  }
846  for (std::size_t k = 0; k < (*itRlcPdu).second.size(); k++)
847  {
848  (*itRlcPdu).second.at(k).at(m_dlInfoListBuffered.at(i).m_harqProcessId).clear();
849  }
850  }
851  }
852  m_dlInfoListBuffered.clear();
853  m_dlInfoListBuffered = dlInfoListUntxed;
854 
855  if (rbgAllocatedNum == rbgNum)
856  {
857  // all the RBGs are already allocated -> exit
858  if (!ret.m_buildDataList.empty() || !ret.m_buildRarList.empty())
859  {
861  }
862  return;
863  }
864 
865  auto itMax = m_flowStatsDl.end();
866  double metricMax = 0.0;
867  for (auto it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
868  {
869  // check first what are channel conditions for this UE, if CQI!=0
870  auto itCqi = m_p10CqiRxed.find((*it).first);
871  auto itTxMode = m_uesTxMode.find((*it).first);
872  if (itTxMode == m_uesTxMode.end())
873  {
874  NS_FATAL_ERROR("No Transmission Mode info on user " << (*it).first);
875  }
876  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
877 
878  uint8_t cqiSum = 0;
879  for (uint8_t j = 0; j < nLayer; j++)
880  {
881  if (itCqi == m_p10CqiRxed.end())
882  {
883  cqiSum += 1; // no info on this user -> lowest MCS
884  }
885  else
886  {
887  cqiSum = (*itCqi).second;
888  }
889  }
890  if (cqiSum == 0)
891  {
892  NS_LOG_INFO("Skip this flow, CQI==0, rnti:" << (*it).first);
893  continue;
894  }
895 
896  auto itRnti = rntiAllocated.find((*it).first);
897  if ((itRnti != rntiAllocated.end()) || (!HarqProcessAvailability((*it).first)))
898  {
899  // UE already allocated for HARQ or without HARQ process available -> drop it
900  if (itRnti != rntiAllocated.end())
901  {
902  NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx" << (uint16_t)(*it).first);
903  }
904  if (!HarqProcessAvailability((*it).first))
905  {
906  NS_LOG_DEBUG(this << " RNTI discarded for HARQ id" << (uint16_t)(*it).first);
907  }
908  continue;
909  }
910 
911  double metric = 1 / (*it).second.lastAveragedThroughput;
912 
913  if (metric > metricMax)
914  {
915  metricMax = metric;
916  itMax = it;
917  }
918  } // end for m_flowStatsDl
919 
920  if (itMax == m_flowStatsDl.end())
921  {
922  // no UE available for downlink
923  return;
924  }
925  else
926  {
927  // assign all RBGs to this UE
928  std::vector<uint16_t> tempMap;
929  tempMap.reserve(rbgNum);
930  for (int i = 0; i < rbgNum; i++)
931  {
932  tempMap.push_back(i);
933  }
934  allocationMap[(*itMax).first] = tempMap;
935  }
936 
937  // reset TTI stats of users
938  for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
939  {
940  (*itStats).second.lastTtiBytesTransmitted = 0;
941  }
942 
943  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
944  // creating the correspondent DCIs
945  auto itMap = allocationMap.begin();
946  while (itMap != allocationMap.end())
947  {
948  // create new BuildDataListElement_s for this LC
950  newEl.m_rnti = (*itMap).first;
951  // create the DlDciListElement_s
952  DlDciListElement_s newDci;
953  newDci.m_rnti = (*itMap).first;
954  newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
955 
956  uint16_t lcActives = LcActivePerFlow((*itMap).first);
957  NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
958  if (lcActives == 0)
959  {
960  // Set to max value, to avoid divide by 0 below
961  lcActives = (uint16_t)65535; // UINT16_MAX;
962  }
963  uint16_t RgbPerRnti = (*itMap).second.size();
964  auto itCqi = m_p10CqiRxed.find((*itMap).first);
965  auto itTxMode = m_uesTxMode.find((*itMap).first);
966  if (itTxMode == m_uesTxMode.end())
967  {
968  NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
969  }
970  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
971 
972  uint32_t bytesTxed = 0;
973  for (uint8_t j = 0; j < nLayer; j++)
974  {
975  if (itCqi == m_p10CqiRxed.end())
976  {
977  newDci.m_mcs.push_back(0); // no info on this user -> lowest MCS
978  }
979  else
980  {
981  newDci.m_mcs.push_back(m_amc->GetMcsFromCqi((*itCqi).second));
982  }
983 
984  int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
985  8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
986  newDci.m_tbsSize.push_back(tbSize);
987  bytesTxed += tbSize;
988  }
989 
990  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
991  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
992  uint32_t rbgMask = 0;
993  for (std::size_t k = 0; k < (*itMap).second.size(); k++)
994  {
995  rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
996  NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
997  }
998  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
999 
1000  // create the rlc PDUs -> equally divide resources among actives LCs
1001  for (auto itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1002  {
1003  if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1004  (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1005  ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1006  ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1007  {
1008  std::vector<RlcPduListElement_s> newRlcPduLe;
1009  for (uint8_t j = 0; j < nLayer; j++)
1010  {
1011  RlcPduListElement_s newRlcEl;
1012  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1013  newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1014  NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1015  << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1016  newRlcPduLe.push_back(newRlcEl);
1018  newRlcEl.m_logicalChannelIdentity,
1019  newRlcEl.m_size);
1020  if (m_harqOn)
1021  {
1022  // store RLC PDU list for HARQ
1023  auto itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1024  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1025  {
1026  NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1027  << (*itMap).first);
1028  }
1029  (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1030  }
1031  }
1032  newEl.m_rlcPduList.push_back(newRlcPduLe);
1033  }
1034  if ((*itBufReq).first.m_rnti > (*itMap).first)
1035  {
1036  break;
1037  }
1038  }
1039  for (uint8_t j = 0; j < nLayer; j++)
1040  {
1041  newDci.m_ndi.push_back(1);
1042  newDci.m_rv.push_back(0);
1043  }
1044 
1045  newDci.m_tpc = 1; // 1 is mapped to 0 in Accumulated Mode and to -1 in Absolute Mode
1046 
1047  newEl.m_dci = newDci;
1048 
1049  if (m_harqOn)
1050  {
1051  // store DCI for HARQ
1052  auto itDci = m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1053  if (itDci == m_dlHarqProcessesDciBuffer.end())
1054  {
1055  NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1056  << newEl.m_rnti);
1057  }
1058  (*itDci).second.at(newDci.m_harqProcess) = newDci;
1059  // refresh timer
1060  auto itHarqTimer = m_dlHarqProcessesTimer.find(newEl.m_rnti);
1061  if (itHarqTimer == m_dlHarqProcessesTimer.end())
1062  {
1063  NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1064  }
1065  (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1066  }
1067 
1068  // ...more parameters -> ignored in this version
1069 
1070  ret.m_buildDataList.push_back(newEl);
1071  // update UE stats
1072  auto it = m_flowStatsDl.find((*itMap).first);
1073  if (it != m_flowStatsDl.end())
1074  {
1075  (*it).second.lastTtiBytesTransmitted = bytesTxed;
1076  NS_LOG_INFO(this << " UE total bytes txed " << (*it).second.lastTtiBytesTransmitted);
1077  }
1078  else
1079  {
1080  NS_FATAL_ERROR(this << " No Stats for this allocated UE");
1081  }
1082 
1083  itMap++;
1084  } // end while allocation
1085  ret.m_nrOfPdcchOfdmSymbols = 1;
1086 
1087  // update UEs stats
1088  NS_LOG_INFO(this << " Update UEs statistics");
1089  for (auto itStats = m_flowStatsDl.begin(); itStats != m_flowStatsDl.end(); itStats++)
1090  {
1091  (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1092  // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1093  // Evolution, Ed Wiley)
1094  (*itStats).second.lastAveragedThroughput =
1095  ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1096  ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1097  NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1098  NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1099  (*itStats).second.lastTtiBytesTransmitted = 0;
1100  }
1101 
1103 }
1104 
1105 void
1108 {
1109  NS_LOG_FUNCTION(this);
1110 
1111  m_rachList = params.m_rachList;
1112 }
1113 
1114 void
1117 {
1118  NS_LOG_FUNCTION(this);
1119 
1120  for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1121  {
1122  if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1123  {
1124  NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1125  << " reported");
1126  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1127  auto it = m_p10CqiRxed.find(rnti);
1128  if (it == m_p10CqiRxed.end())
1129  {
1130  // create the new entry
1131  m_p10CqiRxed[rnti] =
1132  params.m_cqiList.at(i).m_wbCqi.at(0); // only codeword 0 at this stage (SISO)
1133  // generate correspondent timer
1135  }
1136  else
1137  {
1138  // update the CQI value and refresh correspondent timer
1139  (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1140  // update correspondent timer
1141  auto itTimers = m_p10CqiTimers.find(rnti);
1142  (*itTimers).second = m_cqiTimersThreshold;
1143  }
1144  }
1145  else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1146  {
1147  // subband CQI reporting high layer configured
1148  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1149  auto it = m_a30CqiRxed.find(rnti);
1150  if (it == m_a30CqiRxed.end())
1151  {
1152  // create the new entry
1153  m_a30CqiRxed[rnti] = params.m_cqiList.at(i).m_sbMeasResult;
1155  }
1156  else
1157  {
1158  // update the CQI value and refresh correspondent timer
1159  (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1160  auto itTimers = m_a30CqiTimers.find(rnti);
1161  (*itTimers).second = m_cqiTimersThreshold;
1162  }
1163  }
1164  else
1165  {
1166  NS_LOG_ERROR(this << " CQI type unknown");
1167  }
1168  }
1169 }
1170 
1171 double
1172 TdBetFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1173 {
1174  auto itCqi = m_ueCqi.find(rnti);
1175  if (itCqi == m_ueCqi.end())
1176  {
1177  // no cqi info about this UE
1178  return NO_SINR;
1179  }
1180  else
1181  {
1182  // take the average SINR value among the available
1183  double sinrSum = 0;
1184  unsigned int sinrNum = 0;
1185  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1186  {
1187  double sinr = (*itCqi).second.at(i);
1188  if (sinr != NO_SINR)
1189  {
1190  sinrSum += sinr;
1191  sinrNum++;
1192  }
1193  }
1194  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1195  // store the value
1196  (*itCqi).second.at(rb) = estimatedSinr;
1197  return estimatedSinr;
1198  }
1199 }
1200 
1201 void
1204 {
1205  NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1206  << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1207 
1208  RefreshUlCqiMaps();
1209 
1210  // Generate RBs map
1212  std::vector<bool> rbMap;
1213  std::set<uint16_t> rntiAllocated;
1214  std::vector<uint16_t> rbgAllocationMap;
1215  // update with RACH allocation map
1216  rbgAllocationMap = m_rachAllocationMap;
1217  // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1218  m_rachAllocationMap.clear();
1220 
1221  rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1222  // remove RACH allocation
1223  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1224  {
1225  if (rbgAllocationMap.at(i) != 0)
1226  {
1227  rbMap.at(i) = true;
1228  NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1229  }
1230  }
1231 
1232  if (m_harqOn)
1233  {
1234  // Process UL HARQ feedback
1235  for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1236  {
1237  if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1238  {
1239  // retx correspondent block: retrieve the UL-DCI
1240  uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1241  auto itProcId = m_ulHarqCurrentProcessId.find(rnti);
1242  if (itProcId == m_ulHarqCurrentProcessId.end())
1243  {
1244  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1245  }
1246  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1247  NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1248  << " i " << i << " size " << params.m_ulInfoList.size());
1249  auto itHarq = m_ulHarqProcessesDciBuffer.find(rnti);
1250  if (itHarq == m_ulHarqProcessesDciBuffer.end())
1251  {
1252  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1253  continue;
1254  }
1255  UlDciListElement_s dci = (*itHarq).second.at(harqId);
1256  auto itStat = m_ulHarqProcessesStatus.find(rnti);
1257  if (itStat == m_ulHarqProcessesStatus.end())
1258  {
1259  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1260  }
1261  if ((*itStat).second.at(harqId) >= 3)
1262  {
1263  NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1264  continue;
1265  }
1266  bool free = true;
1267  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1268  {
1269  if (rbMap.at(j))
1270  {
1271  free = false;
1272  NS_LOG_INFO(this << " BUSY " << j);
1273  }
1274  }
1275  if (free)
1276  {
1277  // retx on the same RBs
1278  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1279  {
1280  rbMap.at(j) = true;
1281  rbgAllocationMap.at(j) = dci.m_rnti;
1282  NS_LOG_INFO("\tRB " << j);
1283  }
1284  NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1285  << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1286  << (*itStat).second.at(harqId) + 1);
1287  }
1288  else
1289  {
1290  NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1291  continue;
1292  }
1293  dci.m_ndi = 0;
1294  // Update HARQ buffers with new HarqId
1295  (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1296  (*itStat).second.at(harqId) = 0;
1297  (*itHarq).second.at((*itProcId).second) = dci;
1298  ret.m_dciList.push_back(dci);
1299  rntiAllocated.insert(dci.m_rnti);
1300  }
1301  else
1302  {
1303  NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1304  << params.m_ulInfoList.at(i).m_rnti);
1305  }
1306  }
1307  }
1308 
1309  std::map<uint16_t, uint32_t>::iterator it;
1310  int nflows = 0;
1311 
1312  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1313  {
1314  auto itRnti = rntiAllocated.find((*it).first);
1315  // select UEs with queues not empty and not yet allocated for HARQ
1316  if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1317  {
1318  nflows++;
1319  }
1320  }
1321 
1322  if (nflows == 0)
1323  {
1324  if (!ret.m_dciList.empty())
1325  {
1326  m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1328  }
1329 
1330  return; // no flows to be scheduled
1331  }
1332 
1333  // Divide the remaining resources equally among the active users starting from the subsequent
1334  // one served last scheduling trigger
1335  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1336  if (rbPerFlow < 3)
1337  {
1338  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1339  // >= 7 bytes
1340  }
1341  int rbAllocated = 0;
1342 
1343  if (m_nextRntiUl != 0)
1344  {
1345  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1346  {
1347  if ((*it).first == m_nextRntiUl)
1348  {
1349  break;
1350  }
1351  }
1352  if (it == m_ceBsrRxed.end())
1353  {
1354  NS_LOG_ERROR(this << " no user found");
1355  }
1356  }
1357  else
1358  {
1359  it = m_ceBsrRxed.begin();
1360  m_nextRntiUl = (*it).first;
1361  }
1362  do
1363  {
1364  auto itRnti = rntiAllocated.find((*it).first);
1365  if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1366  {
1367  // UE already allocated for UL-HARQ -> skip it
1368  NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1369  << (*it).first);
1370  it++;
1371  if (it == m_ceBsrRxed.end())
1372  {
1373  // restart from the first
1374  it = m_ceBsrRxed.begin();
1375  }
1376  continue;
1377  }
1378  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1379  {
1380  // limit to physical resources last resource assignment
1381  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1382  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1383  if (rbPerFlow < 3)
1384  {
1385  // terminate allocation
1386  rbPerFlow = 0;
1387  }
1388  }
1389 
1390  UlDciListElement_s uldci;
1391  uldci.m_rnti = (*it).first;
1392  uldci.m_rbLen = rbPerFlow;
1393  bool allocated = false;
1394  NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1395  << " flows " << nflows);
1396  while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1397  (rbPerFlow != 0))
1398  {
1399  // check availability
1400  bool free = true;
1401  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1402  {
1403  if (rbMap.at(j))
1404  {
1405  free = false;
1406  break;
1407  }
1408  }
1409  if (free)
1410  {
1411  uldci.m_rbStart = rbAllocated;
1412 
1413  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1414  {
1415  rbMap.at(j) = true;
1416  // store info on allocation for managing ul-cqi interpretation
1417  rbgAllocationMap.at(j) = (*it).first;
1418  }
1419  rbAllocated += rbPerFlow;
1420  allocated = true;
1421  break;
1422  }
1423  rbAllocated++;
1424  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1425  {
1426  // limit to physical resources last resource assignment
1427  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1428  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1429  if (rbPerFlow < 3)
1430  {
1431  // terminate allocation
1432  rbPerFlow = 0;
1433  }
1434  }
1435  }
1436  if (!allocated)
1437  {
1438  // unable to allocate new resource: finish scheduling
1439  m_nextRntiUl = (*it).first;
1440  if (!ret.m_dciList.empty())
1441  {
1443  }
1444  m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1445  return;
1446  }
1447 
1448  auto itCqi = m_ueCqi.find((*it).first);
1449  int cqi = 0;
1450  if (itCqi == m_ueCqi.end())
1451  {
1452  // no cqi info about this UE
1453  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1454  }
1455  else
1456  {
1457  // take the lowest CQI value (worst RB)
1458  NS_ABORT_MSG_IF((*itCqi).second.empty(),
1459  "CQI of RNTI = " << (*it).first << " has expired");
1460  double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1461  if (minSinr == NO_SINR)
1462  {
1463  minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1464  }
1465  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1466  {
1467  double sinr = (*itCqi).second.at(i);
1468  if (sinr == NO_SINR)
1469  {
1470  sinr = EstimateUlSinr((*it).first, i);
1471  }
1472  if (sinr < minSinr)
1473  {
1474  minSinr = sinr;
1475  }
1476  }
1477 
1478  // translate SINR -> cqi: WILD ACK: same as DL
1479  double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1480  cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1481  if (cqi == 0)
1482  {
1483  it++;
1484  if (it == m_ceBsrRxed.end())
1485  {
1486  // restart from the first
1487  it = m_ceBsrRxed.begin();
1488  }
1489  NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1490  // remove UE from allocation map
1491  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1492  {
1493  rbgAllocationMap.at(i) = 0;
1494  }
1495  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1496  }
1497  uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1498  }
1499 
1500  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1501  UpdateUlRlcBufferInfo(uldci.m_rnti, uldci.m_tbSize);
1502  uldci.m_ndi = 1;
1503  uldci.m_cceIndex = 0;
1504  uldci.m_aggrLevel = 1;
1505  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1506  uldci.m_hopping = false;
1507  uldci.m_n2Dmrs = 0;
1508  uldci.m_tpc = 0; // no power control
1509  uldci.m_cqiRequest = false; // only period CQI at this stage
1510  uldci.m_ulIndex = 0; // TDD parameter
1511  uldci.m_dai = 1; // TDD parameter
1512  uldci.m_freqHopping = 0;
1513  uldci.m_pdcchPowerOffset = 0; // not used
1514  ret.m_dciList.push_back(uldci);
1515  // store DCI for HARQ_PERIOD
1516  uint8_t harqId = 0;
1517  if (m_harqOn)
1518  {
1519  auto itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1520  if (itProcId == m_ulHarqCurrentProcessId.end())
1521  {
1522  NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1523  }
1524  harqId = (*itProcId).second;
1525  auto itDci = m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1526  if (itDci == m_ulHarqProcessesDciBuffer.end())
1527  {
1528  NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1529  << uldci.m_rnti);
1530  }
1531  (*itDci).second.at(harqId) = uldci;
1532  // Update HARQ process status (RV 0)
1533  auto itStat = m_ulHarqProcessesStatus.find(uldci.m_rnti);
1534  if (itStat == m_ulHarqProcessesStatus.end())
1535  {
1536  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1537  << uldci.m_rnti);
1538  }
1539  (*itStat).second.at(harqId) = 0;
1540  }
1541 
1542  NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1543  << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1544  << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1545  << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1546  << (uint16_t)harqId);
1547 
1548  // update TTI UE stats
1549  auto itStats = m_flowStatsUl.find((*it).first);
1550  if (itStats != m_flowStatsUl.end())
1551  {
1552  (*itStats).second.lastTtiBytesTransmitted = uldci.m_tbSize;
1553  }
1554  else
1555  {
1556  NS_LOG_DEBUG(this << " No Stats for this allocated UE");
1557  }
1558 
1559  it++;
1560  if (it == m_ceBsrRxed.end())
1561  {
1562  // restart from the first
1563  it = m_ceBsrRxed.begin();
1564  }
1565  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1566  {
1567  // Stop allocation: no more PRBs
1568  m_nextRntiUl = (*it).first;
1569  break;
1570  }
1571  } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1572 
1573  // Update global UE stats
1574  // update UEs stats
1575  for (auto itStats = m_flowStatsUl.begin(); itStats != m_flowStatsUl.end(); itStats++)
1576  {
1577  (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1578  // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term
1579  // Evolution, Ed Wiley)
1580  (*itStats).second.lastAveragedThroughput =
1581  ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) +
1582  ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1583  NS_LOG_INFO(this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1584  NS_LOG_INFO(this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1585  (*itStats).second.lastTtiBytesTransmitted = 0;
1586  }
1587  m_allocationMaps[params.m_sfnSf] = rbgAllocationMap;
1589 }
1590 
1591 void
1594 {
1595  NS_LOG_FUNCTION(this);
1596 }
1597 
1598 void
1601 {
1602  NS_LOG_FUNCTION(this);
1603 }
1604 
1605 void
1608 {
1609  NS_LOG_FUNCTION(this);
1610 
1611  for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1612  {
1613  if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1614  {
1615  // buffer status report
1616  // note that this scheduler does not differentiate the
1617  // allocation according to which LCGs have more/less bytes
1618  // to send.
1619  // Hence the BSR of different LCGs are just summed up to get
1620  // a total queue size that is used for allocation purposes.
1621 
1622  uint32_t buffer = 0;
1623  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1624  {
1625  uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1626  buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1627  }
1628 
1629  uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1630  NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1631  auto it = m_ceBsrRxed.find(rnti);
1632  if (it == m_ceBsrRxed.end())
1633  {
1634  // create the new entry
1635  m_ceBsrRxed[rnti] = buffer;
1636  }
1637  else
1638  {
1639  // update the buffer size value
1640  (*it).second = buffer;
1641  }
1642  }
1643  }
1644 }
1645 
1646 void
1649 {
1650  NS_LOG_FUNCTION(this);
1651  // retrieve the allocation for this subframe
1652  switch (m_ulCqiFilter)
1653  {
1655  // filter all the CQIs that are not SRS based
1656  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1657  {
1658  return;
1659  }
1660  }
1661  break;
1663  // filter all the CQIs that are not SRS based
1664  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1665  {
1666  return;
1667  }
1668  }
1669  break;
1670  default:
1671  NS_FATAL_ERROR("Unknown UL CQI type");
1672  }
1673 
1674  switch (params.m_ulCqi.m_type)
1675  {
1676  case UlCqi_s::PUSCH: {
1677  NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1678  << " subframe no. " << (0xF & params.m_sfnSf));
1679  auto itMap = m_allocationMaps.find(params.m_sfnSf);
1680  if (itMap == m_allocationMaps.end())
1681  {
1682  return;
1683  }
1684  for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1685  {
1686  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1687  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1688  auto itCqi = m_ueCqi.find((*itMap).second.at(i));
1689  if (itCqi == m_ueCqi.end())
1690  {
1691  // create a new entry
1692  std::vector<double> newCqi;
1693  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1694  {
1695  if (i == j)
1696  {
1697  newCqi.push_back(sinr);
1698  }
1699  else
1700  {
1701  // initialize with NO_SINR value.
1702  newCqi.push_back(NO_SINR);
1703  }
1704  }
1705  m_ueCqi[(*itMap).second.at(i)] = newCqi;
1706  // generate correspondent timer
1707  m_ueCqiTimers[(*itMap).second.at(i)] = m_cqiTimersThreshold;
1708  }
1709  else
1710  {
1711  // update the value
1712  (*itCqi).second.at(i) = sinr;
1713  NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
1714  << sinr);
1715  // update correspondent timer
1716  auto itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1717  (*itTimers).second = m_cqiTimersThreshold;
1718  }
1719  }
1720  // remove obsolete info on allocation
1721  m_allocationMaps.erase(itMap);
1722  }
1723  break;
1724  case UlCqi_s::SRS: {
1725  // get the RNTI from vendor specific parameters
1726  uint16_t rnti = 0;
1727  NS_ASSERT(!params.m_vendorSpecificList.empty());
1728  for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1729  {
1730  if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1731  {
1732  Ptr<SrsCqiRntiVsp> vsp =
1733  DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1734  rnti = vsp->GetRnti();
1735  }
1736  }
1737  auto itCqi = m_ueCqi.find(rnti);
1738  if (itCqi == m_ueCqi.end())
1739  {
1740  // create a new entry
1741  std::vector<double> newCqi;
1742  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1743  {
1744  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1745  newCqi.push_back(sinr);
1746  NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1747  << sinr);
1748  }
1749  m_ueCqi[rnti] = newCqi;
1750  // generate correspondent timer
1752  }
1753  else
1754  {
1755  // update the values
1756  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1757  {
1758  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1759  (*itCqi).second.at(j) = sinr;
1760  NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1761  << sinr);
1762  }
1763  // update correspondent timer
1764  auto itTimers = m_ueCqiTimers.find(rnti);
1765  (*itTimers).second = m_cqiTimersThreshold;
1766  }
1767  }
1768  break;
1769  case UlCqi_s::PUCCH_1:
1770  case UlCqi_s::PUCCH_2:
1771  case UlCqi_s::PRACH: {
1772  NS_FATAL_ERROR("TdBetFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1773  }
1774  break;
1775  default:
1776  NS_FATAL_ERROR("Unknown type of UL-CQI");
1777  }
1778 }
1779 
1780 void
1782 {
1783  // refresh DL CQI P01 Map
1784  auto itP10 = m_p10CqiTimers.begin();
1785  while (itP10 != m_p10CqiTimers.end())
1786  {
1787  NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1788  << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1789  if ((*itP10).second == 0)
1790  {
1791  // delete correspondent entries
1792  auto itMap = m_p10CqiRxed.find((*itP10).first);
1793  NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1794  " Does not find CQI report for user " << (*itP10).first);
1795  NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1796  m_p10CqiRxed.erase(itMap);
1797  auto temp = itP10;
1798  itP10++;
1799  m_p10CqiTimers.erase(temp);
1800  }
1801  else
1802  {
1803  (*itP10).second--;
1804  itP10++;
1805  }
1806  }
1807 
1808  // refresh DL CQI A30 Map
1809  auto itA30 = m_a30CqiTimers.begin();
1810  while (itA30 != m_a30CqiTimers.end())
1811  {
1812  NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1813  << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1814  if ((*itA30).second == 0)
1815  {
1816  // delete correspondent entries
1817  auto itMap = m_a30CqiRxed.find((*itA30).first);
1818  NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1819  " Does not find CQI report for user " << (*itA30).first);
1820  NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1821  m_a30CqiRxed.erase(itMap);
1822  auto temp = itA30;
1823  itA30++;
1824  m_a30CqiTimers.erase(temp);
1825  }
1826  else
1827  {
1828  (*itA30).second--;
1829  itA30++;
1830  }
1831  }
1832 }
1833 
1834 void
1836 {
1837  // refresh UL CQI Map
1838  auto itUl = m_ueCqiTimers.begin();
1839  while (itUl != m_ueCqiTimers.end())
1840  {
1841  NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1842  << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1843  if ((*itUl).second == 0)
1844  {
1845  // delete correspondent entries
1846  auto itMap = m_ueCqi.find((*itUl).first);
1847  NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1848  " Does not find CQI report for user " << (*itUl).first);
1849  NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1850  (*itMap).second.clear();
1851  m_ueCqi.erase(itMap);
1852  auto temp = itUl;
1853  itUl++;
1854  m_ueCqiTimers.erase(temp);
1855  }
1856  else
1857  {
1858  (*itUl).second--;
1859  itUl++;
1860  }
1861  }
1862 }
1863 
1864 void
1865 TdBetFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1866 {
1867  LteFlowId_t flow(rnti, lcid);
1868  auto it = m_rlcBufferReq.find(flow);
1869  if (it != m_rlcBufferReq.end())
1870  {
1871  NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1872  << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1873  << (*it).second.m_rlcRetransmissionQueueSize << " status "
1874  << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1875  // Update queues: RLC tx order Status, ReTx, Tx
1876  // Update status queue
1877  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1878  {
1879  (*it).second.m_rlcStatusPduSize = 0;
1880  }
1881  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1882  (size >= (*it).second.m_rlcRetransmissionQueueSize))
1883  {
1884  (*it).second.m_rlcRetransmissionQueueSize = 0;
1885  }
1886  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1887  {
1888  uint32_t rlcOverhead;
1889  if (lcid == 1)
1890  {
1891  // for SRB1 (using RLC AM) it's better to
1892  // overestimate RLC overhead rather than
1893  // underestimate it and risk unneeded
1894  // segmentation which increases delay
1895  rlcOverhead = 4;
1896  }
1897  else
1898  {
1899  // minimum RLC overhead due to header
1900  rlcOverhead = 2;
1901  }
1902  // update transmission queue
1903  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
1904  {
1905  (*it).second.m_rlcTransmissionQueueSize = 0;
1906  }
1907  else
1908  {
1909  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
1910  }
1911  }
1912  }
1913  else
1914  {
1915  NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
1916  }
1917 }
1918 
1919 void
1920 TdBetFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
1921 {
1922  size = size - 2; // remove the minimum RLC overhead
1923  auto it = m_ceBsrRxed.find(rnti);
1924  if (it != m_ceBsrRxed.end())
1925  {
1926  NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
1927  if ((*it).second >= size)
1928  {
1929  (*it).second -= size;
1930  }
1931  else
1932  {
1933  (*it).second = 0;
1934  }
1935  }
1936  else
1937  {
1938  NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
1939  }
1940 }
1941 
1942 void
1944 {
1945  NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1947  params.m_rnti = rnti;
1948  params.m_transmissionMode = txMode;
1950 }
1951 
1952 } // namespace ns3
static uint32_t BsrId2BufferSize(uint8_t val)
Convert BSR ID to buffer size.
Definition: lte-common.cc:176
Provides the CSCHED SAP.
FfMacCschedSapUser class.
virtual void CschedUeConfigCnf(const CschedUeConfigCnfParameters &params)=0
CSCHED_UE_CONFIG_CNF.
virtual void CschedUeConfigUpdateInd(const CschedUeConfigUpdateIndParameters &params)=0
CSCHED_UE_UPDATE_IND.
Provides the SCHED SAP.
FfMacSchedSapUser class.
virtual void SchedUlConfigInd(const SchedUlConfigIndParameters &params)=0
SCHED_UL_CONFIG_IND.
virtual void SchedDlConfigInd(const 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.
static double fpS11dot3toDouble(uint16_t val)
Convert from fixed point S11.3 notation to double.
Definition: lte-common.cc:151
Service Access Point (SAP) offered by the Frequency Reuse algorithm instance to the MAC Scheduler ins...
Definition: lte-ffr-sap.h:40
Service Access Point (SAP) offered by the eNodeB RRC instance to the Frequency Reuse algorithm instan...
Definition: lte-ffr-sap.h:140
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Implements the SCHED SAP and CSCHED SAP for a Time Domain Blind Equal Throughput scheduler.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL SINR function.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
void DoSchedUlNoiseInterferenceReq(const FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
void DoSchedDlPagingBufferReq(const FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request.
void DoCschedUeReleaseReq(const FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request.
std::map< uint16_t, tdbetsFlowPerf_t > m_flowStatsDl
Map of UE statistics (per RNTI basis) in downlink.
int GetRbgSize(int dlbandwidth)
Get RBG size function.
void DoCschedUeConfigReq(const FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request.
void DoCschedLcConfigReq(const FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request.
void RefreshDlCqiMaps()
Refresh DL CQI maps function.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ process ID.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
std::map< uint16_t, tdbetsFlowPerf_t > m_flowStatsUl
Map of UE statistics (per RNTI basis)
std::vector< RachListElement_s > m_rachList
RACH list.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
void DoSchedUlMacCtrlInfoReq(const FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
void DoSchedUlSrInfoReq(const FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request.
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
void DoDispose() override
Destructor implementation.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
LteFfrSapUser * GetLteFfrSapUser() override
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
static TypeId GetTypeId()
Get the type ID.
void DoSchedUlTriggerReq(const FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request.
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
void DoSchedDlMacBufferReq(const FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request.
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void DoSchedUlCqiInfoReq(const FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
friend class MemberSchedSapProvider< TdBetFfMacScheduler >
allow MemberSchedSapProvider<TdBetFfMacScheduler> class friend access
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update function.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
friend class MemberCschedSapProvider< TdBetFfMacScheduler >
allow MemberCschedSapProvider<TdBetFfMacScheduler> class friend access
void DoSchedDlRlcBufferReq(const FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
void DoSchedDlRachInfoReq(const FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request.
std::map< uint16_t, std::vector< uint16_t > > m_allocationMaps
Map of previous allocated UE per RBG (used to retrieve info from UL-CQI)
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
void RefreshUlCqiMaps()
Refresh UL CQI maps function.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
void DoSchedDlTriggerReq(const FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request.
void DoCschedLcReleaseReq(const FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
~TdBetFfMacScheduler() override
Destructor.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
unsigned int LcActivePerFlow(uint16_t rnti)
LC active flow function.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
void DoSchedDlCqiInfoReq(const FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request.
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
void DoCschedCellConfigReq(const FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
Definition: lte-common.cc:203
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#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:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
#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.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
constexpr double NO_SINR
Value for SINR outside the range defined by FF-API, used to indicate that there is no CQI for this el...
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
static const int TdBetType0AllocationRbg[4]
TDBET type 0 allocation RBG.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
Vector of the 8 HARQ processes per UE.
@ SUCCESS
Definition: ff-mac-common.h:62
constexpr uint32_t HARQ_DL_TIMEOUT
HARQ DL timeout.
constexpr uint32_t HARQ_PROC_NUM
Number of HARQ processes.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
std::vector< DlDciListElement_s > DlHarqProcessesDciBuffer_t
DL HARQ process DCI buffer vector.
std::vector< uint8_t > UlHarqProcessesStatus_t
UL HARQ process status vector.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector.
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
See section 4.3.8 buildDataListElement.
std::vector< std::vector< struct RlcPduListElement_s > > m_rlcPduList
RLC PDU list.
struct DlDciListElement_s m_dci
DCI.
See section 4.3.10 buildRARListElement.
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:93
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:95
std::vector< uint8_t > m_mcs
MCS.
Definition: ff-mac-common.h:99
uint8_t m_resAlloc
The type of resource allocation.
Definition: ff-mac-common.h:97
std::vector< uint16_t > m_tbsSize
The TBs size.
Definition: ff-mac-common.h:98
std::vector< uint8_t > m_rv
Redundancy version.
uint8_t m_tpc
Tx power control command.
Parameters of the CSCHED_LC_CONFIG_REQ primitive.
Parameters of the CSCHED_LC_RELEASE_REQ primitive.
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.
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.
Parameters of the SCHED_DL_TRIGGER_REQ primitive.
Parameters of the SCHED_UL_CQI_INFO_REQ primitive.
Parameters of the SCHED_UL_MAC_CTRL_INFO_REQ primitive.
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< BuildDataListElement_s > m_buildDataList
build data list
std::vector< BuildRarListElement_s > m_buildRarList
build rar list
uint8_t m_nrOfPdcchOfdmSymbols
number of PDCCH OFDM symbols
Parameters of the SCHED_UL_CONFIG_IND primitive.
std::vector< UlDciListElement_s > m_dciList
DCI list.
LteFlowId structure.
Definition: lte-common.h:43
See section 4.3.9 rlcPDU_ListElement.
uint8_t m_logicalChannelIdentity
logical channel identity
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.
tdbetsFlowPerf_t structure
double lastAveragedThroughput
last average throughput
Time flowStart
flow start time
unsigned long totalBytesTransmitted
total bytes transmitted
unsigned int lastTtiBytesTransmitted
last total bytes transmitted