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