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 <ns3/boolean.h>
22 #include <ns3/log.h>
23 #include <ns3/lte-amc.h>
24 #include <ns3/lte-vendor-specific-parameters.h>
25 #include <ns3/math.h>
26 #include <ns3/pointer.h>
27 #include <ns3/simulator.h>
28 #include <ns3/tta-ff-mac-scheduler.h>
29 
30 #include <cfloat>
31 #include <set>
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("TtaFfMacScheduler");
37 
39 static const int TtaType0AllocationRbg[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(TtaFfMacScheduler);
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::TtaFfMacScheduler")
84  .SetGroupName("Lte")
85  .AddConstructor<TtaFfMacScheduler>()
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 < TtaType0AllocationRbg[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 itSbCqi;
913  itSbCqi = m_a30CqiRxed.find((*it));
914  std::map<uint16_t, uint8_t>::iterator itWbCqi;
915  itWbCqi = m_p10CqiRxed.find((*it));
916 
917  std::map<uint16_t, uint8_t>::iterator itTxMode;
918  itTxMode = m_uesTxMode.find((*it));
919  if (itTxMode == m_uesTxMode.end())
920  {
921  NS_FATAL_ERROR("No Transmission Mode info on user " << (*it));
922  }
923  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
924 
925  std::vector<uint8_t> sbCqi;
926  if (itSbCqi == m_a30CqiRxed.end())
927  {
928  for (uint8_t k = 0; k < nLayer; k++)
929  {
930  sbCqi.push_back(1); // start with lowest value
931  }
932  }
933  else
934  {
935  sbCqi = (*itSbCqi).second.m_higherLayerSelected.at(i).m_sbCqi;
936  }
937 
938  uint8_t wbCqi = 0;
939  if (itWbCqi != m_p10CqiRxed.end())
940  {
941  wbCqi = (*itWbCqi).second;
942  }
943  else
944  {
945  wbCqi = 1; // lowest value for trying a transmission
946  }
947 
948  uint8_t cqi1 = sbCqi.at(0);
949  uint8_t cqi2 = 0;
950  if (sbCqi.size() > 1)
951  {
952  cqi2 = sbCqi.at(1);
953  }
954  if ((cqi1 > 0) ||
955  (cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
956  {
957  if (LcActivePerFlow((*it)) > 0)
958  {
959  // this UE has data to transmit
960  double achievableSbRate = 0.0;
961  double achievableWbRate = 0.0;
962  uint8_t sbMcs = 0;
963  uint8_t wbMcs = 0;
964  for (uint8_t k = 0; k < nLayer; k++)
965  {
966  if (sbCqi.size() > k)
967  {
968  sbMcs = m_amc->GetMcsFromCqi(sbCqi.at(k));
969  }
970  else
971  {
972  // no info on this subband -> worst MCS
973  sbMcs = 0;
974  }
975  achievableSbRate += ((m_amc->GetDlTbSizeFromMcs(sbMcs, rbgSize) / 8) /
976  0.001); // = TB size / TTI
977  wbMcs = m_amc->GetMcsFromCqi(wbCqi);
978  achievableWbRate += ((m_amc->GetDlTbSizeFromMcs(wbMcs, rbgSize) / 8) /
979  0.001); // = TB size / TTI
980  }
981 
982  double metric = achievableSbRate / achievableWbRate;
983 
984  if (metric > rcqiMax)
985  {
986  rcqiMax = metric;
987  itMax = it;
988  }
989  }
990  } // end if cqi
991 
992  } // end for m_rlcBufferReq
993 
994  if (itMax == m_flowStatsDl.end())
995  {
996  // no UE available for this RB
997  NS_LOG_INFO(this << " any UE found");
998  }
999  else
1000  {
1001  rbgMap.at(i) = true;
1002  std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1003  itMap = allocationMap.find((*itMax));
1004  if (itMap == allocationMap.end())
1005  {
1006  // insert new element
1007  std::vector<uint16_t> tempMap;
1008  tempMap.push_back(i);
1009  allocationMap.insert(
1010  std::pair<uint16_t, std::vector<uint16_t>>((*itMax), tempMap));
1011  }
1012  else
1013  {
1014  (*itMap).second.push_back(i);
1015  }
1016  NS_LOG_INFO(this << " UE assigned " << (*itMax));
1017  }
1018  } // end for RBG free
1019  } // end for RBGs
1020 
1021  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1022  // creating the correspondent DCIs
1023  std::map<uint16_t, std::vector<uint16_t>>::iterator itMap = allocationMap.begin();
1024  while (itMap != allocationMap.end())
1025  {
1026  // create new BuildDataListElement_s for this LC
1027  BuildDataListElement_s newEl;
1028  newEl.m_rnti = (*itMap).first;
1029  // create the DlDciListElement_s
1030  DlDciListElement_s newDci;
1031  newDci.m_rnti = (*itMap).first;
1032  newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
1033 
1034  uint16_t lcActives = LcActivePerFlow((*itMap).first);
1035  NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1036  if (lcActives == 0)
1037  {
1038  // Set to max value, to avoid divide by 0 below
1039  lcActives = (uint16_t)65535; // UINT16_MAX;
1040  }
1041  uint16_t RgbPerRnti = (*itMap).second.size();
1042  std::map<uint16_t, SbMeasResult_s>::iterator itCqi;
1043  itCqi = m_a30CqiRxed.find((*itMap).first);
1044  std::map<uint16_t, uint8_t>::iterator itTxMode;
1045  itTxMode = m_uesTxMode.find((*itMap).first);
1046  if (itTxMode == m_uesTxMode.end())
1047  {
1048  NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1049  }
1050  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1051  std::vector<uint8_t> worstCqi(2, 15);
1052  if (itCqi != m_a30CqiRxed.end())
1053  {
1054  for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1055  {
1056  if ((*itCqi).second.m_higherLayerSelected.size() > (*itMap).second.at(k))
1057  {
1058  NS_LOG_INFO(this << " RBG " << (*itMap).second.at(k) << " CQI "
1059  << (uint16_t)((*itCqi)
1060  .second.m_higherLayerSelected
1061  .at((*itMap).second.at(k))
1062  .m_sbCqi.at(0)));
1063  for (uint8_t j = 0; j < nLayer; j++)
1064  {
1065  if ((*itCqi)
1066  .second.m_higherLayerSelected.at((*itMap).second.at(k))
1067  .m_sbCqi.size() > j)
1068  {
1069  if (((*itCqi)
1070  .second.m_higherLayerSelected.at((*itMap).second.at(k))
1071  .m_sbCqi.at(j)) < worstCqi.at(j))
1072  {
1073  worstCqi.at(j) =
1074  ((*itCqi)
1075  .second.m_higherLayerSelected.at((*itMap).second.at(k))
1076  .m_sbCqi.at(j));
1077  }
1078  }
1079  else
1080  {
1081  // no CQI for this layer of this suband -> worst one
1082  worstCqi.at(j) = 1;
1083  }
1084  }
1085  }
1086  else
1087  {
1088  for (uint8_t j = 0; j < nLayer; j++)
1089  {
1090  worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1091  }
1092  }
1093  }
1094  }
1095  else
1096  {
1097  for (uint8_t j = 0; j < nLayer; j++)
1098  {
1099  worstCqi.at(j) = 1; // try with lowest MCS in RBG with no info on channel
1100  }
1101  }
1102  for (uint8_t j = 0; j < nLayer; j++)
1103  {
1104  NS_LOG_INFO(this << " Layer " << (uint16_t)j << " CQI selected "
1105  << (uint16_t)worstCqi.at(j));
1106  }
1107  for (uint8_t j = 0; j < nLayer; j++)
1108  {
1109  newDci.m_mcs.push_back(m_amc->GetMcsFromCqi(worstCqi.at(j)));
1110  int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1111  8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1112  newDci.m_tbsSize.push_back(tbSize);
1113  NS_LOG_INFO(this << " Layer " << (uint16_t)j << " MCS selected"
1114  << m_amc->GetMcsFromCqi(worstCqi.at(j)));
1115  }
1116 
1117  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1118  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1119  uint32_t rbgMask = 0;
1120  for (std::size_t k = 0; k < (*itMap).second.size(); k++)
1121  {
1122  rbgMask = rbgMask + (0x1 << (*itMap).second.at(k));
1123  NS_LOG_INFO(this << " Allocated RBG " << (*itMap).second.at(k));
1124  }
1125  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1126 
1127  // create the rlc PDUs -> equally divide resources among actives LCs
1128  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator
1129  itBufReq;
1130  for (itBufReq = m_rlcBufferReq.begin(); itBufReq != m_rlcBufferReq.end(); itBufReq++)
1131  {
1132  if (((*itBufReq).first.m_rnti == (*itMap).first) &&
1133  (((*itBufReq).second.m_rlcTransmissionQueueSize > 0) ||
1134  ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0) ||
1135  ((*itBufReq).second.m_rlcStatusPduSize > 0)))
1136  {
1137  std::vector<struct RlcPduListElement_s> newRlcPduLe;
1138  for (uint8_t j = 0; j < nLayer; j++)
1139  {
1140  RlcPduListElement_s newRlcEl;
1141  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1142  newRlcEl.m_size = newDci.m_tbsSize.at(j) / lcActives;
1143  NS_LOG_INFO(this << " LCID " << (uint32_t)newRlcEl.m_logicalChannelIdentity
1144  << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1145  newRlcPduLe.push_back(newRlcEl);
1147  newRlcEl.m_logicalChannelIdentity,
1148  newRlcEl.m_size);
1149  if (m_harqOn == true)
1150  {
1151  // store RLC PDU list for HARQ
1152  std::map<uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu =
1153  m_dlHarqProcessesRlcPduListBuffer.find((*itMap).first);
1154  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end())
1155  {
1156  NS_FATAL_ERROR("Unable to find RlcPdcList in HARQ buffer for RNTI "
1157  << (*itMap).first);
1158  }
1159  (*itRlcPdu).second.at(j).at(newDci.m_harqProcess).push_back(newRlcEl);
1160  }
1161  }
1162  newEl.m_rlcPduList.push_back(newRlcPduLe);
1163  }
1164  if ((*itBufReq).first.m_rnti > (*itMap).first)
1165  {
1166  break;
1167  }
1168  }
1169  for (uint8_t j = 0; j < nLayer; j++)
1170  {
1171  newDci.m_ndi.push_back(1);
1172  newDci.m_rv.push_back(0);
1173  }
1174 
1175  newDci.m_tpc = 1; // 1 is mapped to 0 in Accumulated Mode and to -1 in Absolute Mode
1176 
1177  newEl.m_dci = newDci;
1178 
1179  if (m_harqOn == true)
1180  {
1181  // store DCI for HARQ
1182  std::map<uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci =
1183  m_dlHarqProcessesDciBuffer.find(newEl.m_rnti);
1184  if (itDci == m_dlHarqProcessesDciBuffer.end())
1185  {
1186  NS_FATAL_ERROR("Unable to find RNTI entry in DCI HARQ buffer for RNTI "
1187  << newEl.m_rnti);
1188  }
1189  (*itDci).second.at(newDci.m_harqProcess) = newDci;
1190  // refresh timer
1191  std::map<uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer =
1192  m_dlHarqProcessesTimer.find(newEl.m_rnti);
1193  if (itHarqTimer == m_dlHarqProcessesTimer.end())
1194  {
1195  NS_FATAL_ERROR("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1196  }
1197  (*itHarqTimer).second.at(newDci.m_harqProcess) = 0;
1198  }
1199 
1200  // ...more parameters -> ignored in this version
1201 
1202  ret.m_buildDataList.push_back(newEl);
1203 
1204  itMap++;
1205  } // end while allocation
1206  ret.m_nrOfPdcchOfdmSymbols = 1;
1207 
1209 }
1210 
1211 void
1214 {
1215  NS_LOG_FUNCTION(this);
1216 
1217  m_rachList = params.m_rachList;
1218 }
1219 
1220 void
1223 {
1224  NS_LOG_FUNCTION(this);
1225 
1226  for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1227  {
1228  if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1229  {
1230  NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1231  << " reported");
1232  std::map<uint16_t, uint8_t>::iterator it;
1233  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1234  it = m_p10CqiRxed.find(rnti);
1235  if (it == m_p10CqiRxed.end())
1236  {
1237  // create the new entry
1238  m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1239  rnti,
1240  params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1241  // generate correspondent timer
1242  m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1243  }
1244  else
1245  {
1246  // update the CQI value and refresh correspondent timer
1247  (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1248  // update correspondent timer
1249  std::map<uint16_t, uint32_t>::iterator itTimers;
1250  itTimers = m_p10CqiTimers.find(rnti);
1251  (*itTimers).second = m_cqiTimersThreshold;
1252  }
1253  }
1254  else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1255  {
1256  // subband CQI reporting high layer configured
1257  std::map<uint16_t, SbMeasResult_s>::iterator it;
1258  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1259  it = m_a30CqiRxed.find(rnti);
1260  if (it == m_a30CqiRxed.end())
1261  {
1262  // create the new entry
1263  m_a30CqiRxed.insert(
1264  std::pair<uint16_t, SbMeasResult_s>(rnti,
1265  params.m_cqiList.at(i).m_sbMeasResult));
1266  m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1267  }
1268  else
1269  {
1270  // update the CQI value and refresh correspondent timer
1271  (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1272  std::map<uint16_t, uint32_t>::iterator itTimers;
1273  itTimers = m_a30CqiTimers.find(rnti);
1274  (*itTimers).second = m_cqiTimersThreshold;
1275  }
1276  }
1277  else
1278  {
1279  NS_LOG_ERROR(this << " CQI type unknown");
1280  }
1281  }
1282 }
1283 
1284 double
1285 TtaFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1286 {
1287  std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find(rnti);
1288  if (itCqi == m_ueCqi.end())
1289  {
1290  // no cqi info about this UE
1291  return (NO_SINR);
1292  }
1293  else
1294  {
1295  // take the average SINR value among the available
1296  double sinrSum = 0;
1297  unsigned int sinrNum = 0;
1298  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1299  {
1300  double sinr = (*itCqi).second.at(i);
1301  if (sinr != NO_SINR)
1302  {
1303  sinrSum += sinr;
1304  sinrNum++;
1305  }
1306  }
1307  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1308  // store the value
1309  (*itCqi).second.at(rb) = estimatedSinr;
1310  return (estimatedSinr);
1311  }
1312 }
1313 
1314 void
1317 {
1318  NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1319  << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1320 
1321  RefreshUlCqiMaps();
1322 
1323  // Generate RBs map
1325  std::vector<bool> rbMap;
1326  std::set<uint16_t> rntiAllocated;
1327  std::vector<uint16_t> rbgAllocationMap;
1328  // update with RACH allocation map
1329  rbgAllocationMap = m_rachAllocationMap;
1330  // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1331  m_rachAllocationMap.clear();
1333 
1334  rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1335  // remove RACH allocation
1336  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1337  {
1338  if (rbgAllocationMap.at(i) != 0)
1339  {
1340  rbMap.at(i) = true;
1341  NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1342  }
1343  }
1344 
1345  if (m_harqOn == true)
1346  {
1347  // Process UL HARQ feedback
1348  for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1349  {
1350  if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1351  {
1352  // retx correspondent block: retrieve the UL-DCI
1353  uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1354  std::map<uint16_t, uint8_t>::iterator itProcId =
1355  m_ulHarqCurrentProcessId.find(rnti);
1356  if (itProcId == m_ulHarqCurrentProcessId.end())
1357  {
1358  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1359  }
1360  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1361  NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1362  << " i " << i << " size " << params.m_ulInfoList.size());
1363  std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq =
1364  m_ulHarqProcessesDciBuffer.find(rnti);
1365  if (itHarq == m_ulHarqProcessesDciBuffer.end())
1366  {
1367  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1368  continue;
1369  }
1370  UlDciListElement_s dci = (*itHarq).second.at(harqId);
1371  std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1372  m_ulHarqProcessesStatus.find(rnti);
1373  if (itStat == m_ulHarqProcessesStatus.end())
1374  {
1375  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1376  }
1377  if ((*itStat).second.at(harqId) >= 3)
1378  {
1379  NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1380  continue;
1381  }
1382  bool free = true;
1383  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1384  {
1385  if (rbMap.at(j) == true)
1386  {
1387  free = false;
1388  NS_LOG_INFO(this << " BUSY " << j);
1389  }
1390  }
1391  if (free)
1392  {
1393  // retx on the same RBs
1394  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1395  {
1396  rbMap.at(j) = true;
1397  rbgAllocationMap.at(j) = dci.m_rnti;
1398  NS_LOG_INFO("\tRB " << j);
1399  }
1400  NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1401  << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1402  << (*itStat).second.at(harqId) + 1);
1403  }
1404  else
1405  {
1406  NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1407  continue;
1408  }
1409  dci.m_ndi = 0;
1410  // Update HARQ buffers with new HarqId
1411  (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1412  (*itStat).second.at(harqId) = 0;
1413  (*itHarq).second.at((*itProcId).second) = dci;
1414  ret.m_dciList.push_back(dci);
1415  rntiAllocated.insert(dci.m_rnti);
1416  }
1417  else
1418  {
1419  NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1420  << params.m_ulInfoList.at(i).m_rnti);
1421  }
1422  }
1423  }
1424 
1425  std::map<uint16_t, uint32_t>::iterator it;
1426  int nflows = 0;
1427 
1428  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1429  {
1430  std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1431  // select UEs with queues not empty and not yet allocated for HARQ
1432  if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1433  {
1434  nflows++;
1435  }
1436  }
1437 
1438  if (nflows == 0)
1439  {
1440  if (!ret.m_dciList.empty())
1441  {
1442  m_allocationMaps.insert(
1443  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1445  }
1446 
1447  return; // no flows to be scheduled
1448  }
1449 
1450  // Divide the remaining resources equally among the active users starting from the subsequent
1451  // one served last scheduling trigger
1452  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1453  if (rbPerFlow < 3)
1454  {
1455  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1456  // >= 7 bytes
1457  }
1458  int rbAllocated = 0;
1459 
1460  if (m_nextRntiUl != 0)
1461  {
1462  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1463  {
1464  if ((*it).first == m_nextRntiUl)
1465  {
1466  break;
1467  }
1468  }
1469  if (it == m_ceBsrRxed.end())
1470  {
1471  NS_LOG_ERROR(this << " no user found");
1472  }
1473  }
1474  else
1475  {
1476  it = m_ceBsrRxed.begin();
1477  m_nextRntiUl = (*it).first;
1478  }
1479  do
1480  {
1481  std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1482  if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1483  {
1484  // UE already allocated for UL-HARQ -> skip it
1485  NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1486  << (*it).first);
1487  it++;
1488  if (it == m_ceBsrRxed.end())
1489  {
1490  // restart from the first
1491  it = m_ceBsrRxed.begin();
1492  }
1493  continue;
1494  }
1495  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1496  {
1497  // limit to physical resources last resource assignment
1498  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1499  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1500  if (rbPerFlow < 3)
1501  {
1502  // terminate allocation
1503  rbPerFlow = 0;
1504  }
1505  }
1506 
1507  UlDciListElement_s uldci;
1508  uldci.m_rnti = (*it).first;
1509  uldci.m_rbLen = rbPerFlow;
1510  bool allocated = false;
1511  NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1512  << " flows " << nflows);
1513  while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1514  (rbPerFlow != 0))
1515  {
1516  // check availability
1517  bool free = true;
1518  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1519  {
1520  if (rbMap.at(j) == true)
1521  {
1522  free = false;
1523  break;
1524  }
1525  }
1526  if (free)
1527  {
1528  uldci.m_rbStart = rbAllocated;
1529 
1530  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1531  {
1532  rbMap.at(j) = true;
1533  // store info on allocation for managing ul-cqi interpretation
1534  rbgAllocationMap.at(j) = (*it).first;
1535  }
1536  rbAllocated += rbPerFlow;
1537  allocated = true;
1538  break;
1539  }
1540  rbAllocated++;
1541  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1542  {
1543  // limit to physical resources last resource assignment
1544  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1545  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1546  if (rbPerFlow < 3)
1547  {
1548  // terminate allocation
1549  rbPerFlow = 0;
1550  }
1551  }
1552  }
1553  if (!allocated)
1554  {
1555  // unable to allocate new resource: finish scheduling
1556  m_nextRntiUl = (*it).first;
1557  if (!ret.m_dciList.empty())
1558  {
1560  }
1561  m_allocationMaps.insert(
1562  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1563  return;
1564  }
1565 
1566  std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find((*it).first);
1567  int cqi = 0;
1568  if (itCqi == m_ueCqi.end())
1569  {
1570  // no cqi info about this UE
1571  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1572  }
1573  else
1574  {
1575  // take the lowest CQI value (worst RB)
1576  NS_ABORT_MSG_IF((*itCqi).second.empty(),
1577  "CQI of RNTI = " << (*it).first << " has expired");
1578  double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1579  if (minSinr == NO_SINR)
1580  {
1581  minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1582  }
1583  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1584  {
1585  double sinr = (*itCqi).second.at(i);
1586  if (sinr == NO_SINR)
1587  {
1588  sinr = EstimateUlSinr((*it).first, i);
1589  }
1590  if (sinr < minSinr)
1591  {
1592  minSinr = sinr;
1593  }
1594  }
1595 
1596  // translate SINR -> cqi: WILD ACK: same as DL
1597  double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1598  cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1599  if (cqi == 0)
1600  {
1601  it++;
1602  if (it == m_ceBsrRxed.end())
1603  {
1604  // restart from the first
1605  it = m_ceBsrRxed.begin();
1606  }
1607  NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1608  // remove UE from allocation map
1609  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1610  {
1611  rbgAllocationMap.at(i) = 0;
1612  }
1613  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1614  }
1615  uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1616  }
1617 
1618  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1619  UpdateUlRlcBufferInfo(uldci.m_rnti, uldci.m_tbSize);
1620  uldci.m_ndi = 1;
1621  uldci.m_cceIndex = 0;
1622  uldci.m_aggrLevel = 1;
1623  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1624  uldci.m_hopping = false;
1625  uldci.m_n2Dmrs = 0;
1626  uldci.m_tpc = 0; // no power control
1627  uldci.m_cqiRequest = false; // only period CQI at this stage
1628  uldci.m_ulIndex = 0; // TDD parameter
1629  uldci.m_dai = 1; // TDD parameter
1630  uldci.m_freqHopping = 0;
1631  uldci.m_pdcchPowerOffset = 0; // not used
1632  ret.m_dciList.push_back(uldci);
1633  // store DCI for HARQ_PERIOD
1634  uint8_t harqId = 0;
1635  if (m_harqOn == true)
1636  {
1637  std::map<uint16_t, uint8_t>::iterator itProcId;
1638  itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1639  if (itProcId == m_ulHarqCurrentProcessId.end())
1640  {
1641  NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1642  }
1643  harqId = (*itProcId).second;
1644  std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
1645  m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1646  if (itDci == m_ulHarqProcessesDciBuffer.end())
1647  {
1648  NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1649  << uldci.m_rnti);
1650  }
1651  (*itDci).second.at(harqId) = uldci;
1652  // Update HARQ process status (RV 0)
1653  std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1654  m_ulHarqProcessesStatus.find(uldci.m_rnti);
1655  if (itStat == m_ulHarqProcessesStatus.end())
1656  {
1657  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1658  << uldci.m_rnti);
1659  }
1660  (*itStat).second.at(harqId) = 0;
1661  }
1662 
1663  NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1664  << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1665  << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1666  << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1667  << (uint16_t)harqId);
1668 
1669  it++;
1670  if (it == m_ceBsrRxed.end())
1671  {
1672  // restart from the first
1673  it = m_ceBsrRxed.begin();
1674  }
1675  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1676  {
1677  // Stop allocation: no more PRBs
1678  m_nextRntiUl = (*it).first;
1679  break;
1680  }
1681  } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1682 
1683  m_allocationMaps.insert(
1684  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1686 }
1687 
1688 void
1691 {
1692  NS_LOG_FUNCTION(this);
1693 }
1694 
1695 void
1698 {
1699  NS_LOG_FUNCTION(this);
1700 }
1701 
1702 void
1705 {
1706  NS_LOG_FUNCTION(this);
1707 
1708  std::map<uint16_t, uint32_t>::iterator it;
1709 
1710  for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1711  {
1712  if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1713  {
1714  // buffer status report
1715  // note that this scheduler does not differentiate the
1716  // allocation according to which LCGs have more/less bytes
1717  // to send.
1718  // Hence the BSR of different LCGs are just summed up to get
1719  // a total queue size that is used for allocation purposes.
1720 
1721  uint32_t buffer = 0;
1722  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1723  {
1724  uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1725  buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1726  }
1727 
1728  uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1729  NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1730  it = m_ceBsrRxed.find(rnti);
1731  if (it == m_ceBsrRxed.end())
1732  {
1733  // create the new entry
1734  m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
1735  }
1736  else
1737  {
1738  // update the buffer size value
1739  (*it).second = buffer;
1740  }
1741  }
1742  }
1743 }
1744 
1745 void
1748 {
1749  NS_LOG_FUNCTION(this);
1750  // retrieve the allocation for this subframe
1751  switch (m_ulCqiFilter)
1752  {
1754  // filter all the CQIs that are not SRS based
1755  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1756  {
1757  return;
1758  }
1759  }
1760  break;
1762  // filter all the CQIs that are not SRS based
1763  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1764  {
1765  return;
1766  }
1767  }
1768  break;
1769  default:
1770  NS_FATAL_ERROR("Unknown UL CQI type");
1771  }
1772 
1773  switch (params.m_ulCqi.m_type)
1774  {
1775  case UlCqi_s::PUSCH: {
1776  std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1777  std::map<uint16_t, std::vector<double>>::iterator itCqi;
1778  NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1779  << " subframe no. " << (0xF & params.m_sfnSf));
1780  itMap = m_allocationMaps.find(params.m_sfnSf);
1781  if (itMap == m_allocationMaps.end())
1782  {
1783  return;
1784  }
1785  for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1786  {
1787  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1788  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1789  itCqi = m_ueCqi.find((*itMap).second.at(i));
1790  if (itCqi == m_ueCqi.end())
1791  {
1792  // create a new entry
1793  std::vector<double> newCqi;
1794  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1795  {
1796  if (i == j)
1797  {
1798  newCqi.push_back(sinr);
1799  }
1800  else
1801  {
1802  // initialize with NO_SINR value.
1803  newCqi.push_back(NO_SINR);
1804  }
1805  }
1806  m_ueCqi.insert(
1807  std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
1808  // generate correspondent timer
1809  m_ueCqiTimers.insert(
1810  std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
1811  }
1812  else
1813  {
1814  // update the value
1815  (*itCqi).second.at(i) = sinr;
1816  // NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR
1817  // " << sinr);
1818  // update correspondent timer
1819  std::map<uint16_t, uint32_t>::iterator itTimers;
1820  itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1821  (*itTimers).second = m_cqiTimersThreshold;
1822  }
1823  }
1824  // remove obsolete info on allocation
1825  m_allocationMaps.erase(itMap);
1826  }
1827  break;
1828  case UlCqi_s::SRS: {
1829  // get the RNTI from vendor specific parameters
1830  uint16_t rnti = 0;
1831  NS_ASSERT(!params.m_vendorSpecificList.empty());
1832  for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1833  {
1834  if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1835  {
1836  Ptr<SrsCqiRntiVsp> vsp =
1837  DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1838  rnti = vsp->GetRnti();
1839  }
1840  }
1841  std::map<uint16_t, std::vector<double>>::iterator itCqi;
1842  itCqi = m_ueCqi.find(rnti);
1843  if (itCqi == m_ueCqi.end())
1844  {
1845  // create a new entry
1846  std::vector<double> newCqi;
1847  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1848  {
1849  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1850  newCqi.push_back(sinr);
1851  NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1852  << sinr);
1853  }
1854  m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
1855  // generate correspondent timer
1856  m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1857  }
1858  else
1859  {
1860  // update the values
1861  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1862  {
1863  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1864  (*itCqi).second.at(j) = sinr;
1865  NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1866  << sinr);
1867  }
1868  // update correspondent timer
1869  std::map<uint16_t, uint32_t>::iterator itTimers;
1870  itTimers = m_ueCqiTimers.find(rnti);
1871  (*itTimers).second = m_cqiTimersThreshold;
1872  }
1873  }
1874  break;
1875  case UlCqi_s::PUCCH_1:
1876  case UlCqi_s::PUCCH_2:
1877  case UlCqi_s::PRACH: {
1878  NS_FATAL_ERROR("TtaFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1879  }
1880  break;
1881  default:
1882  NS_FATAL_ERROR("Unknown type of UL-CQI");
1883  }
1884 }
1885 
1886 void
1888 {
1889  // refresh DL CQI P01 Map
1890  std::map<uint16_t, uint32_t>::iterator itP10 = m_p10CqiTimers.begin();
1891  while (itP10 != m_p10CqiTimers.end())
1892  {
1893  NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1894  << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1895  if ((*itP10).second == 0)
1896  {
1897  // delete correspondent entries
1898  std::map<uint16_t, uint8_t>::iterator itMap = m_p10CqiRxed.find((*itP10).first);
1899  NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1900  " Does not find CQI report for user " << (*itP10).first);
1901  NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1902  m_p10CqiRxed.erase(itMap);
1903  std::map<uint16_t, uint32_t>::iterator temp = itP10;
1904  itP10++;
1905  m_p10CqiTimers.erase(temp);
1906  }
1907  else
1908  {
1909  (*itP10).second--;
1910  itP10++;
1911  }
1912  }
1913 
1914  // refresh DL CQI A30 Map
1915  std::map<uint16_t, uint32_t>::iterator itA30 = m_a30CqiTimers.begin();
1916  while (itA30 != m_a30CqiTimers.end())
1917  {
1918  NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1919  << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1920  if ((*itA30).second == 0)
1921  {
1922  // delete correspondent entries
1923  std::map<uint16_t, SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find((*itA30).first);
1924  NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1925  " Does not find CQI report for user " << (*itA30).first);
1926  NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1927  m_a30CqiRxed.erase(itMap);
1928  std::map<uint16_t, uint32_t>::iterator temp = itA30;
1929  itA30++;
1930  m_a30CqiTimers.erase(temp);
1931  }
1932  else
1933  {
1934  (*itA30).second--;
1935  itA30++;
1936  }
1937  }
1938 }
1939 
1940 void
1942 {
1943  // refresh UL CQI Map
1944  std::map<uint16_t, uint32_t>::iterator itUl = m_ueCqiTimers.begin();
1945  while (itUl != m_ueCqiTimers.end())
1946  {
1947  NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1948  << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1949  if ((*itUl).second == 0)
1950  {
1951  // delete correspondent entries
1952  std::map<uint16_t, std::vector<double>>::iterator itMap = m_ueCqi.find((*itUl).first);
1953  NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1954  " Does not find CQI report for user " << (*itUl).first);
1955  NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1956  (*itMap).second.clear();
1957  m_ueCqi.erase(itMap);
1958  std::map<uint16_t, uint32_t>::iterator temp = itUl;
1959  itUl++;
1960  m_ueCqiTimers.erase(temp);
1961  }
1962  else
1963  {
1964  (*itUl).second--;
1965  itUl++;
1966  }
1967  }
1968 }
1969 
1970 void
1971 TtaFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1972 {
1973  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1974  LteFlowId_t flow(rnti, lcid);
1975  it = m_rlcBufferReq.find(flow);
1976  if (it != m_rlcBufferReq.end())
1977  {
1978  NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1979  << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1980  << (*it).second.m_rlcRetransmissionQueueSize << " status "
1981  << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1982  // Update queues: RLC tx order Status, ReTx, Tx
1983  // Update status queue
1984  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1985  {
1986  (*it).second.m_rlcStatusPduSize = 0;
1987  }
1988  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1989  (size >= (*it).second.m_rlcRetransmissionQueueSize))
1990  {
1991  (*it).second.m_rlcRetransmissionQueueSize = 0;
1992  }
1993  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1994  {
1995  uint32_t rlcOverhead;
1996  if (lcid == 1)
1997  {
1998  // for SRB1 (using RLC AM) it's better to
1999  // overestimate RLC overhead rather than
2000  // underestimate it and risk unneeded
2001  // segmentation which increases delay
2002  rlcOverhead = 4;
2003  }
2004  else
2005  {
2006  // minimum RLC overhead due to header
2007  rlcOverhead = 2;
2008  }
2009  // update transmission queue
2010  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2011  {
2012  (*it).second.m_rlcTransmissionQueueSize = 0;
2013  }
2014  else
2015  {
2016  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2017  }
2018  }
2019  }
2020  else
2021  {
2022  NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
2023  }
2024 }
2025 
2026 void
2027 TtaFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
2028 {
2029  size = size - 2; // remove the minimum RLC overhead
2030  std::map<uint16_t, uint32_t>::iterator it = m_ceBsrRxed.find(rnti);
2031  if (it != m_ceBsrRxed.end())
2032  {
2033  NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2034  if ((*it).second >= size)
2035  {
2036  (*it).second -= size;
2037  }
2038  else
2039  {
2040  (*it).second = 0;
2041  }
2042  }
2043  else
2044  {
2045  NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
2046  }
2047 }
2048 
2049 void
2051 {
2052  NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2054  params.m_rnti = rnti;
2055  params.m_transmissionMode = txMode;
2057 }
2058 
2059 } // 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
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
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.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release 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.
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request function.
std::set< uint16_t > m_flowStatsDl
Set of UE statistics (per RNTI basis) in downlink.
void DoDispose() override
Destructor implementation.
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request function.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release 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.
std::vector< struct RachListElement_s > m_rachList
RACH list.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request function.
friend class MemberSchedSapProvider< TtaFfMacScheduler >
allow MemberSchedSapProvider<TtaFfMacScheduler> class friend access
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request function.
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
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.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
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 DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request function.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request function.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request function.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request function.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update.
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request function.
void UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update DL RLC buffer info 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.
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 DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request function.
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger 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)
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request function.
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request function.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request function.
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 TtaType0AllocationRbg[4]
TTA type 0 allocation RBG.
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.