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