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