A Discrete-Event Network Simulator
API
tdmt-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/tdmt-ff-mac-scheduler.h>
29 
30 #include <cfloat>
31 #include <set>
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("TdMtFfMacScheduler");
37 
39 static const int TdMtType0AllocationRbg[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(TdMtFfMacScheduler);
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::TdMtFfMacScheduler")
84  .SetGroupName("Lte")
85  .AddConstructor<TdMtFfMacScheduler>()
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 < TdMtType0AllocationRbg[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  std::set<uint16_t>::iterator it;
888  std::set<uint16_t>::iterator itMax = m_flowStatsDl.end();
889  double metricMax = 0.0;
890  for (it = m_flowStatsDl.begin(); it != m_flowStatsDl.end(); it++)
891  {
892  std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it));
893  if ((itRnti != rntiAllocated.end()) || (!HarqProcessAvailability((*it))))
894  {
895  // UE already allocated for HARQ or without HARQ process available -> drop it
896  if (itRnti != rntiAllocated.end())
897  {
898  NS_LOG_DEBUG(this << " RNTI discarded for HARQ tx" << (uint16_t)(*it));
899  }
900  if (!HarqProcessAvailability((*it)))
901  {
902  NS_LOG_DEBUG(this << " RNTI discarded for HARQ id" << (uint16_t)(*it));
903  }
904 
905  continue;
906  }
907 
908  std::map<uint16_t, uint8_t>::iterator itTxMode;
909  itTxMode = m_uesTxMode.find((*it));
910  if (itTxMode == m_uesTxMode.end())
911  {
912  NS_FATAL_ERROR("No Transmission Mode info on user " << (*it));
913  }
914  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
915  std::map<uint16_t, uint8_t>::iterator itCqi = m_p10CqiRxed.find((*it));
916  uint8_t wbCqi = 0;
917  if (itCqi != m_p10CqiRxed.end())
918  {
919  wbCqi = (*itCqi).second;
920  }
921  else
922  {
923  wbCqi = 1; // lowest value for trying a transmission
924  }
925 
926  if (wbCqi != 0)
927  {
928  // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
929  if (LcActivePerFlow(*it) > 0)
930  {
931  // this UE has data to transmit
932  double achievableRate = 0.0;
933  for (uint8_t k = 0; k < nLayer; k++)
934  {
935  uint8_t mcs = 0;
936  mcs = m_amc->GetMcsFromCqi(wbCqi);
937  achievableRate +=
938  ((m_amc->GetDlTbSizeFromMcs(mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
939 
940  NS_LOG_DEBUG(this << " RNTI " << (*it) << " MCS " << (uint32_t)mcs
941  << " achievableRate " << achievableRate);
942  }
943 
944  double metric = achievableRate;
945 
946  if (metric > metricMax)
947  {
948  metricMax = metric;
949  itMax = it;
950  }
951  } // LcActivePerFlow
952 
953  } // cqi
954 
955  } // end for m_flowStatsDl
956 
957  if (itMax == m_flowStatsDl.end())
958  {
959  // no UE available for downlink
960  NS_LOG_INFO(this << " any UE found");
961  }
962  else
963  {
964  // assign all free RBGs to this UE
965  std::vector<uint16_t> tempMap;
966  for (int i = 0; i < rbgNum; i++)
967  {
968  NS_LOG_INFO(this << " ALLOCATION for RBG " << i << " of " << rbgNum);
969  NS_LOG_DEBUG(this << " ALLOCATION for RBG " << i << " of " << rbgNum);
970  if (rbgMap.at(i) == false)
971  {
972  rbgMap.at(i) = true;
973  tempMap.push_back(i);
974  } // end for RBG free
975 
976  } // end for RBGs
977  if (!tempMap.empty())
978  {
979  allocationMap.insert(std::pair<uint16_t, std::vector<uint16_t>>((*itMax), tempMap));
980  }
981  }
982 
983  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
984  // creating the correspondent DCIs
985  std::map<uint16_t, std::vector<uint16_t>>::iterator itMap = allocationMap.begin();
986  while (itMap != allocationMap.end())
987  {
988  // create new BuildDataListElement_s for this LC
990  newEl.m_rnti = (*itMap).first;
991  // create the DlDciListElement_s
992  DlDciListElement_s newDci;
993  newDci.m_rnti = (*itMap).first;
994  newDci.m_harqProcess = UpdateHarqProcessId((*itMap).first);
995 
996  uint16_t lcActives = LcActivePerFlow((*itMap).first);
997  NS_LOG_INFO(this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
998  if (lcActives == 0)
999  {
1000  // Set to max value, to avoid divide by 0 below
1001  lcActives = (uint16_t)65535; // UINT16_MAX;
1002  }
1003  uint16_t RgbPerRnti = (*itMap).second.size();
1004  std::map<uint16_t, uint8_t>::iterator itCqi;
1005  itCqi = m_p10CqiRxed.find((*itMap).first);
1006  std::map<uint16_t, uint8_t>::iterator itTxMode;
1007  itTxMode = m_uesTxMode.find((*itMap).first);
1008  if (itTxMode == m_uesTxMode.end())
1009  {
1010  NS_FATAL_ERROR("No Transmission Mode info on user " << (*itMap).first);
1011  }
1012  auto nLayer = TransmissionModesLayers::TxMode2LayerNum((*itTxMode).second);
1013  for (uint8_t j = 0; j < nLayer; j++)
1014  {
1015  if (itCqi == m_p10CqiRxed.end())
1016  {
1017  newDci.m_mcs.push_back(0); // no info on this user -> lowest MCS
1018  }
1019  else
1020  {
1021  newDci.m_mcs.push_back(m_amc->GetMcsFromCqi((*itCqi).second));
1022  }
1023 
1024  int tbSize = (m_amc->GetDlTbSizeFromMcs(newDci.m_mcs.at(j), RgbPerRnti * rbgSize) /
1025  8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1026  newDci.m_tbsSize.push_back(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 
1116  itMap++;
1117  } // end while allocation
1118  ret.m_nrOfPdcchOfdmSymbols = 1;
1119 
1121 }
1122 
1123 void
1126 {
1127  NS_LOG_FUNCTION(this);
1128 
1129  m_rachList = params.m_rachList;
1130 }
1131 
1132 void
1135 {
1136  NS_LOG_FUNCTION(this);
1137 
1138  for (unsigned int i = 0; i < params.m_cqiList.size(); i++)
1139  {
1140  if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::P10)
1141  {
1142  NS_LOG_LOGIC("wideband CQI " << (uint32_t)params.m_cqiList.at(i).m_wbCqi.at(0)
1143  << " reported");
1144  std::map<uint16_t, uint8_t>::iterator it;
1145  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1146  it = m_p10CqiRxed.find(rnti);
1147  if (it == m_p10CqiRxed.end())
1148  {
1149  // create the new entry
1150  m_p10CqiRxed.insert(std::pair<uint16_t, uint8_t>(
1151  rnti,
1152  params.m_cqiList.at(i).m_wbCqi.at(0))); // only codeword 0 at this stage (SISO)
1153  // generate correspondent timer
1154  m_p10CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1155  }
1156  else
1157  {
1158  // update the CQI value and refresh correspondent timer
1159  (*it).second = params.m_cqiList.at(i).m_wbCqi.at(0);
1160  // update correspondent timer
1161  std::map<uint16_t, uint32_t>::iterator itTimers;
1162  itTimers = m_p10CqiTimers.find(rnti);
1163  (*itTimers).second = m_cqiTimersThreshold;
1164  }
1165  }
1166  else if (params.m_cqiList.at(i).m_cqiType == CqiListElement_s::A30)
1167  {
1168  // subband CQI reporting high layer configured
1169  std::map<uint16_t, SbMeasResult_s>::iterator it;
1170  uint16_t rnti = params.m_cqiList.at(i).m_rnti;
1171  it = m_a30CqiRxed.find(rnti);
1172  if (it == m_a30CqiRxed.end())
1173  {
1174  // create the new entry
1175  m_a30CqiRxed.insert(
1176  std::pair<uint16_t, SbMeasResult_s>(rnti,
1177  params.m_cqiList.at(i).m_sbMeasResult));
1178  m_a30CqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1179  }
1180  else
1181  {
1182  // update the CQI value and refresh correspondent timer
1183  (*it).second = params.m_cqiList.at(i).m_sbMeasResult;
1184  std::map<uint16_t, uint32_t>::iterator itTimers;
1185  itTimers = m_a30CqiTimers.find(rnti);
1186  (*itTimers).second = m_cqiTimersThreshold;
1187  }
1188  }
1189  else
1190  {
1191  NS_LOG_ERROR(this << " CQI type unknown");
1192  }
1193  }
1194 }
1195 
1196 double
1197 TdMtFfMacScheduler::EstimateUlSinr(uint16_t rnti, uint16_t rb)
1198 {
1199  std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find(rnti);
1200  if (itCqi == m_ueCqi.end())
1201  {
1202  // no cqi info about this UE
1203  return (NO_SINR);
1204  }
1205  else
1206  {
1207  // take the average SINR value among the available
1208  double sinrSum = 0;
1209  unsigned int sinrNum = 0;
1210  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1211  {
1212  double sinr = (*itCqi).second.at(i);
1213  if (sinr != NO_SINR)
1214  {
1215  sinrSum += sinr;
1216  sinrNum++;
1217  }
1218  }
1219  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1220  // store the value
1221  (*itCqi).second.at(rb) = estimatedSinr;
1222  return (estimatedSinr);
1223  }
1224 }
1225 
1226 void
1229 {
1230  NS_LOG_FUNCTION(this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. "
1231  << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size());
1232 
1233  RefreshUlCqiMaps();
1234 
1235  // Generate RBs map
1237  std::vector<bool> rbMap;
1238  std::set<uint16_t> rntiAllocated;
1239  std::vector<uint16_t> rbgAllocationMap;
1240  // update with RACH allocation map
1241  rbgAllocationMap = m_rachAllocationMap;
1242  // rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1243  m_rachAllocationMap.clear();
1245 
1246  rbMap.resize(m_cschedCellConfig.m_ulBandwidth, false);
1247  // remove RACH allocation
1248  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1249  {
1250  if (rbgAllocationMap.at(i) != 0)
1251  {
1252  rbMap.at(i) = true;
1253  NS_LOG_DEBUG(this << " Allocated for RACH " << i);
1254  }
1255  }
1256 
1257  if (m_harqOn == true)
1258  {
1259  // Process UL HARQ feedback
1260  for (std::size_t i = 0; i < params.m_ulInfoList.size(); i++)
1261  {
1262  if (params.m_ulInfoList.at(i).m_receptionStatus == UlInfoListElement_s::NotOk)
1263  {
1264  // retx correspondent block: retrieve the UL-DCI
1265  uint16_t rnti = params.m_ulInfoList.at(i).m_rnti;
1266  std::map<uint16_t, uint8_t>::iterator itProcId =
1267  m_ulHarqCurrentProcessId.find(rnti);
1268  if (itProcId == m_ulHarqCurrentProcessId.end())
1269  {
1270  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1271  }
1272  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1273  NS_LOG_INFO(this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId
1274  << " i " << i << " size " << params.m_ulInfoList.size());
1275  std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq =
1276  m_ulHarqProcessesDciBuffer.find(rnti);
1277  if (itHarq == m_ulHarqProcessesDciBuffer.end())
1278  {
1279  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1280  continue;
1281  }
1282  UlDciListElement_s dci = (*itHarq).second.at(harqId);
1283  std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1284  m_ulHarqProcessesStatus.find(rnti);
1285  if (itStat == m_ulHarqProcessesStatus.end())
1286  {
1287  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1288  }
1289  if ((*itStat).second.at(harqId) >= 3)
1290  {
1291  NS_LOG_INFO("Max number of retransmissions reached (UL)-> drop process");
1292  continue;
1293  }
1294  bool free = true;
1295  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1296  {
1297  if (rbMap.at(j) == true)
1298  {
1299  free = false;
1300  NS_LOG_INFO(this << " BUSY " << j);
1301  }
1302  }
1303  if (free)
1304  {
1305  // retx on the same RBs
1306  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1307  {
1308  rbMap.at(j) = true;
1309  rbgAllocationMap.at(j) = dci.m_rnti;
1310  NS_LOG_INFO("\tRB " << j);
1311  }
1312  NS_LOG_INFO(this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart
1313  << " to " << dci.m_rbStart + dci.m_rbLen << " RV "
1314  << (*itStat).second.at(harqId) + 1);
1315  }
1316  else
1317  {
1318  NS_LOG_INFO("Cannot allocate retx due to RACH allocations for UE " << rnti);
1319  continue;
1320  }
1321  dci.m_ndi = 0;
1322  // Update HARQ buffers with new HarqId
1323  (*itStat).second.at((*itProcId).second) = (*itStat).second.at(harqId) + 1;
1324  (*itStat).second.at(harqId) = 0;
1325  (*itHarq).second.at((*itProcId).second) = dci;
1326  ret.m_dciList.push_back(dci);
1327  rntiAllocated.insert(dci.m_rnti);
1328  }
1329  else
1330  {
1331  NS_LOG_INFO(this << " HARQ-ACK feedback from RNTI "
1332  << params.m_ulInfoList.at(i).m_rnti);
1333  }
1334  }
1335  }
1336 
1337  std::map<uint16_t, uint32_t>::iterator it;
1338  int nflows = 0;
1339 
1340  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1341  {
1342  std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1343  // select UEs with queues not empty and not yet allocated for HARQ
1344  if (((*it).second > 0) && (itRnti == rntiAllocated.end()))
1345  {
1346  nflows++;
1347  }
1348  }
1349 
1350  if (nflows == 0)
1351  {
1352  if (!ret.m_dciList.empty())
1353  {
1354  m_allocationMaps.insert(
1355  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1357  }
1358 
1359  return; // no flows to be scheduled
1360  }
1361 
1362  // Divide the remaining resources equally among the active users starting from the subsequent
1363  // one served last scheduling trigger
1364  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size());
1365  if (rbPerFlow < 3)
1366  {
1367  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity
1368  // >= 7 bytes
1369  }
1370  int rbAllocated = 0;
1371 
1372  if (m_nextRntiUl != 0)
1373  {
1374  for (it = m_ceBsrRxed.begin(); it != m_ceBsrRxed.end(); it++)
1375  {
1376  if ((*it).first == m_nextRntiUl)
1377  {
1378  break;
1379  }
1380  }
1381  if (it == m_ceBsrRxed.end())
1382  {
1383  NS_LOG_ERROR(this << " no user found");
1384  }
1385  }
1386  else
1387  {
1388  it = m_ceBsrRxed.begin();
1389  m_nextRntiUl = (*it).first;
1390  }
1391  do
1392  {
1393  std::set<uint16_t>::iterator itRnti = rntiAllocated.find((*it).first);
1394  if ((itRnti != rntiAllocated.end()) || ((*it).second == 0))
1395  {
1396  // UE already allocated for UL-HARQ -> skip it
1397  NS_LOG_DEBUG(this << " UE already allocated in HARQ -> discarded, RNTI "
1398  << (*it).first);
1399  it++;
1400  if (it == m_ceBsrRxed.end())
1401  {
1402  // restart from the first
1403  it = m_ceBsrRxed.begin();
1404  }
1405  continue;
1406  }
1407  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1408  {
1409  // limit to physical resources last resource assignment
1410  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1411  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1412  if (rbPerFlow < 3)
1413  {
1414  // terminate allocation
1415  rbPerFlow = 0;
1416  }
1417  }
1418 
1419  UlDciListElement_s uldci;
1420  uldci.m_rnti = (*it).first;
1421  uldci.m_rbLen = rbPerFlow;
1422  bool allocated = false;
1423  NS_LOG_INFO(this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow
1424  << " flows " << nflows);
1425  while ((!allocated) && ((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) &&
1426  (rbPerFlow != 0))
1427  {
1428  // check availability
1429  bool free = true;
1430  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1431  {
1432  if (rbMap.at(j) == true)
1433  {
1434  free = false;
1435  break;
1436  }
1437  }
1438  if (free)
1439  {
1440  uldci.m_rbStart = rbAllocated;
1441 
1442  for (int j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1443  {
1444  rbMap.at(j) = true;
1445  // store info on allocation for managing ul-cqi interpretation
1446  rbgAllocationMap.at(j) = (*it).first;
1447  }
1448  rbAllocated += rbPerFlow;
1449  allocated = true;
1450  break;
1451  }
1452  rbAllocated++;
1453  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1454  {
1455  // limit to physical resources last resource assignment
1456  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1457  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1458  if (rbPerFlow < 3)
1459  {
1460  // terminate allocation
1461  rbPerFlow = 0;
1462  }
1463  }
1464  }
1465  if (!allocated)
1466  {
1467  // unable to allocate new resource: finish scheduling
1468  m_nextRntiUl = (*it).first;
1469  if (!ret.m_dciList.empty())
1470  {
1472  }
1473  m_allocationMaps.insert(
1474  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1475  return;
1476  }
1477 
1478  std::map<uint16_t, std::vector<double>>::iterator itCqi = m_ueCqi.find((*it).first);
1479  int cqi = 0;
1480  if (itCqi == m_ueCqi.end())
1481  {
1482  // no cqi info about this UE
1483  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1484  }
1485  else
1486  {
1487  // take the lowest CQI value (worst RB)
1488  NS_ABORT_MSG_IF((*itCqi).second.empty(),
1489  "CQI of RNTI = " << (*it).first << " has expired");
1490  double minSinr = (*itCqi).second.at(uldci.m_rbStart);
1491  if (minSinr == NO_SINR)
1492  {
1493  minSinr = EstimateUlSinr((*it).first, uldci.m_rbStart);
1494  }
1495  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1496  {
1497  double sinr = (*itCqi).second.at(i);
1498  if (sinr == NO_SINR)
1499  {
1500  sinr = EstimateUlSinr((*it).first, i);
1501  }
1502  if (sinr < minSinr)
1503  {
1504  minSinr = sinr;
1505  }
1506  }
1507 
1508  // translate SINR -> cqi: WILD ACK: same as DL
1509  double s = log2(1 + (std::pow(10, minSinr / 10) / ((-std::log(5.0 * 0.00005)) / 1.5)));
1510  cqi = m_amc->GetCqiFromSpectralEfficiency(s);
1511  if (cqi == 0)
1512  {
1513  it++;
1514  if (it == m_ceBsrRxed.end())
1515  {
1516  // restart from the first
1517  it = m_ceBsrRxed.begin();
1518  }
1519  NS_LOG_DEBUG(this << " UE discarded for CQI = 0, RNTI " << uldci.m_rnti);
1520  // remove UE from allocation map
1521  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1522  {
1523  rbgAllocationMap.at(i) = 0;
1524  }
1525  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1526  }
1527  uldci.m_mcs = m_amc->GetMcsFromCqi(cqi);
1528  }
1529 
1530  uldci.m_tbSize = (m_amc->GetUlTbSizeFromMcs(uldci.m_mcs, rbPerFlow) / 8);
1531  UpdateUlRlcBufferInfo(uldci.m_rnti, uldci.m_tbSize);
1532  uldci.m_ndi = 1;
1533  uldci.m_cceIndex = 0;
1534  uldci.m_aggrLevel = 1;
1535  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1536  uldci.m_hopping = false;
1537  uldci.m_n2Dmrs = 0;
1538  uldci.m_tpc = 0; // no power control
1539  uldci.m_cqiRequest = false; // only period CQI at this stage
1540  uldci.m_ulIndex = 0; // TDD parameter
1541  uldci.m_dai = 1; // TDD parameter
1542  uldci.m_freqHopping = 0;
1543  uldci.m_pdcchPowerOffset = 0; // not used
1544  ret.m_dciList.push_back(uldci);
1545  // store DCI for HARQ_PERIOD
1546  uint8_t harqId = 0;
1547  if (m_harqOn == true)
1548  {
1549  std::map<uint16_t, uint8_t>::iterator itProcId;
1550  itProcId = m_ulHarqCurrentProcessId.find(uldci.m_rnti);
1551  if (itProcId == m_ulHarqCurrentProcessId.end())
1552  {
1553  NS_FATAL_ERROR("No info find in HARQ buffer for UE " << uldci.m_rnti);
1554  }
1555  harqId = (*itProcId).second;
1556  std::map<uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci =
1557  m_ulHarqProcessesDciBuffer.find(uldci.m_rnti);
1558  if (itDci == m_ulHarqProcessesDciBuffer.end())
1559  {
1560  NS_FATAL_ERROR("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI "
1561  << uldci.m_rnti);
1562  }
1563  (*itDci).second.at(harqId) = uldci;
1564  // Update HARQ process status (RV 0)
1565  std::map<uint16_t, UlHarqProcessesStatus_t>::iterator itStat =
1566  m_ulHarqProcessesStatus.find(uldci.m_rnti);
1567  if (itStat == m_ulHarqProcessesStatus.end())
1568  {
1569  NS_LOG_ERROR("No info find in HARQ buffer for UE (might change eNB) "
1570  << uldci.m_rnti);
1571  }
1572  (*itStat).second.at(harqId) = 0;
1573  }
1574 
1575  NS_LOG_INFO(this << " UE Allocation RNTI " << (*it).first << " startPRB "
1576  << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen
1577  << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize "
1578  << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId "
1579  << (uint16_t)harqId);
1580 
1581  it++;
1582  if (it == m_ceBsrRxed.end())
1583  {
1584  // restart from the first
1585  it = m_ceBsrRxed.begin();
1586  }
1587  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1588  {
1589  // Stop allocation: no more PRBs
1590  m_nextRntiUl = (*it).first;
1591  break;
1592  }
1593  } while (((*it).first != m_nextRntiUl) && (rbPerFlow != 0));
1594 
1595  m_allocationMaps.insert(
1596  std::pair<uint16_t, std::vector<uint16_t>>(params.m_sfnSf, rbgAllocationMap));
1598 }
1599 
1600 void
1603 {
1604  NS_LOG_FUNCTION(this);
1605 }
1606 
1607 void
1610 {
1611  NS_LOG_FUNCTION(this);
1612 }
1613 
1614 void
1617 {
1618  NS_LOG_FUNCTION(this);
1619 
1620  std::map<uint16_t, uint32_t>::iterator it;
1621 
1622  for (unsigned int i = 0; i < params.m_macCeList.size(); i++)
1623  {
1624  if (params.m_macCeList.at(i).m_macCeType == MacCeListElement_s::BSR)
1625  {
1626  // buffer status report
1627  // note that this scheduler does not differentiate the
1628  // allocation according to which LCGs have more/less bytes
1629  // to send.
1630  // Hence the BSR of different LCGs are just summed up to get
1631  // a total queue size that is used for allocation purposes.
1632 
1633  uint32_t buffer = 0;
1634  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1635  {
1636  uint8_t bsrId = params.m_macCeList.at(i).m_macCeValue.m_bufferStatus.at(lcg);
1637  buffer += BufferSizeLevelBsr::BsrId2BufferSize(bsrId);
1638  }
1639 
1640  uint16_t rnti = params.m_macCeList.at(i).m_rnti;
1641  NS_LOG_LOGIC(this << "RNTI=" << rnti << " buffer=" << buffer);
1642  it = m_ceBsrRxed.find(rnti);
1643  if (it == m_ceBsrRxed.end())
1644  {
1645  // create the new entry
1646  m_ceBsrRxed.insert(std::pair<uint16_t, uint32_t>(rnti, buffer));
1647  }
1648  else
1649  {
1650  // update the buffer size value
1651  (*it).second = buffer;
1652  }
1653  }
1654  }
1655 }
1656 
1657 void
1660 {
1661  NS_LOG_FUNCTION(this);
1662  // retrieve the allocation for this subframe
1663  switch (m_ulCqiFilter)
1664  {
1666  // filter all the CQIs that are not SRS based
1667  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1668  {
1669  return;
1670  }
1671  }
1672  break;
1674  // filter all the CQIs that are not SRS based
1675  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1676  {
1677  return;
1678  }
1679  }
1680  break;
1681  default:
1682  NS_FATAL_ERROR("Unknown UL CQI type");
1683  }
1684 
1685  switch (params.m_ulCqi.m_type)
1686  {
1687  case UlCqi_s::PUSCH: {
1688  std::map<uint16_t, std::vector<uint16_t>>::iterator itMap;
1689  std::map<uint16_t, std::vector<double>>::iterator itCqi;
1690  NS_LOG_DEBUG(this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4)
1691  << " subframe no. " << (0xF & params.m_sfnSf));
1692  itMap = m_allocationMaps.find(params.m_sfnSf);
1693  if (itMap == m_allocationMaps.end())
1694  {
1695  return;
1696  }
1697  for (uint32_t i = 0; i < (*itMap).second.size(); i++)
1698  {
1699  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1700  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(i));
1701  itCqi = m_ueCqi.find((*itMap).second.at(i));
1702  if (itCqi == m_ueCqi.end())
1703  {
1704  // create a new entry
1705  std::vector<double> newCqi;
1706  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1707  {
1708  if (i == j)
1709  {
1710  newCqi.push_back(sinr);
1711  }
1712  else
1713  {
1714  // initialize with NO_SINR value.
1715  newCqi.push_back(NO_SINR);
1716  }
1717  }
1718  m_ueCqi.insert(
1719  std::pair<uint16_t, std::vector<double>>((*itMap).second.at(i), newCqi));
1720  // generate correspondent timer
1721  m_ueCqiTimers.insert(
1722  std::pair<uint16_t, uint32_t>((*itMap).second.at(i), m_cqiTimersThreshold));
1723  }
1724  else
1725  {
1726  // update the value
1727  (*itCqi).second.at(i) = sinr;
1728  NS_LOG_DEBUG(this << " RNTI " << (*itMap).second.at(i) << " RB " << i << " SINR "
1729  << sinr);
1730  // update correspondent timer
1731  std::map<uint16_t, uint32_t>::iterator itTimers;
1732  itTimers = m_ueCqiTimers.find((*itMap).second.at(i));
1733  (*itTimers).second = m_cqiTimersThreshold;
1734  }
1735  }
1736  // remove obsolete info on allocation
1737  m_allocationMaps.erase(itMap);
1738  }
1739  break;
1740  case UlCqi_s::SRS: {
1741  // get the RNTI from vendor specific parameters
1742  uint16_t rnti = 0;
1743  NS_ASSERT(!params.m_vendorSpecificList.empty());
1744  for (std::size_t i = 0; i < params.m_vendorSpecificList.size(); i++)
1745  {
1746  if (params.m_vendorSpecificList.at(i).m_type == SRS_CQI_RNTI_VSP)
1747  {
1748  Ptr<SrsCqiRntiVsp> vsp =
1749  DynamicCast<SrsCqiRntiVsp>(params.m_vendorSpecificList.at(i).m_value);
1750  rnti = vsp->GetRnti();
1751  }
1752  }
1753  std::map<uint16_t, std::vector<double>>::iterator itCqi;
1754  itCqi = m_ueCqi.find(rnti);
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  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1762  newCqi.push_back(sinr);
1763  NS_LOG_INFO(this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value "
1764  << sinr);
1765  }
1766  m_ueCqi.insert(std::pair<uint16_t, std::vector<double>>(rnti, newCqi));
1767  // generate correspondent timer
1768  m_ueCqiTimers.insert(std::pair<uint16_t, uint32_t>(rnti, m_cqiTimersThreshold));
1769  }
1770  else
1771  {
1772  // update the values
1773  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1774  {
1775  double sinr = LteFfConverter::fpS11dot3toDouble(params.m_ulCqi.m_sinr.at(j));
1776  (*itCqi).second.at(j) = sinr;
1777  NS_LOG_INFO(this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value "
1778  << sinr);
1779  }
1780  // update correspondent timer
1781  std::map<uint16_t, uint32_t>::iterator itTimers;
1782  itTimers = m_ueCqiTimers.find(rnti);
1783  (*itTimers).second = m_cqiTimersThreshold;
1784  }
1785  }
1786  break;
1787  case UlCqi_s::PUCCH_1:
1788  case UlCqi_s::PUCCH_2:
1789  case UlCqi_s::PRACH: {
1790  NS_FATAL_ERROR("TdMtFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1791  }
1792  break;
1793  default:
1794  NS_FATAL_ERROR("Unknown type of UL-CQI");
1795  }
1796 }
1797 
1798 void
1800 {
1801  // refresh DL CQI P01 Map
1802  std::map<uint16_t, uint32_t>::iterator itP10 = m_p10CqiTimers.begin();
1803  while (itP10 != m_p10CqiTimers.end())
1804  {
1805  NS_LOG_INFO(this << " P10-CQI for user " << (*itP10).first << " is "
1806  << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1807  if ((*itP10).second == 0)
1808  {
1809  // delete correspondent entries
1810  std::map<uint16_t, uint8_t>::iterator itMap = m_p10CqiRxed.find((*itP10).first);
1811  NS_ASSERT_MSG(itMap != m_p10CqiRxed.end(),
1812  " Does not find CQI report for user " << (*itP10).first);
1813  NS_LOG_INFO(this << " P10-CQI expired for user " << (*itP10).first);
1814  m_p10CqiRxed.erase(itMap);
1815  std::map<uint16_t, uint32_t>::iterator temp = itP10;
1816  itP10++;
1817  m_p10CqiTimers.erase(temp);
1818  }
1819  else
1820  {
1821  (*itP10).second--;
1822  itP10++;
1823  }
1824  }
1825 
1826  // refresh DL CQI A30 Map
1827  std::map<uint16_t, uint32_t>::iterator itA30 = m_a30CqiTimers.begin();
1828  while (itA30 != m_a30CqiTimers.end())
1829  {
1830  NS_LOG_INFO(this << " A30-CQI for user " << (*itA30).first << " is "
1831  << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1832  if ((*itA30).second == 0)
1833  {
1834  // delete correspondent entries
1835  std::map<uint16_t, SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find((*itA30).first);
1836  NS_ASSERT_MSG(itMap != m_a30CqiRxed.end(),
1837  " Does not find CQI report for user " << (*itA30).first);
1838  NS_LOG_INFO(this << " A30-CQI expired for user " << (*itA30).first);
1839  m_a30CqiRxed.erase(itMap);
1840  std::map<uint16_t, uint32_t>::iterator temp = itA30;
1841  itA30++;
1842  m_a30CqiTimers.erase(temp);
1843  }
1844  else
1845  {
1846  (*itA30).second--;
1847  itA30++;
1848  }
1849  }
1850 }
1851 
1852 void
1854 {
1855  // refresh UL CQI Map
1856  std::map<uint16_t, uint32_t>::iterator itUl = m_ueCqiTimers.begin();
1857  while (itUl != m_ueCqiTimers.end())
1858  {
1859  NS_LOG_INFO(this << " UL-CQI for user " << (*itUl).first << " is "
1860  << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1861  if ((*itUl).second == 0)
1862  {
1863  // delete correspondent entries
1864  std::map<uint16_t, std::vector<double>>::iterator itMap = m_ueCqi.find((*itUl).first);
1865  NS_ASSERT_MSG(itMap != m_ueCqi.end(),
1866  " Does not find CQI report for user " << (*itUl).first);
1867  NS_LOG_INFO(this << " UL-CQI exired for user " << (*itUl).first);
1868  (*itMap).second.clear();
1869  m_ueCqi.erase(itMap);
1870  std::map<uint16_t, uint32_t>::iterator temp = itUl;
1871  itUl++;
1872  m_ueCqiTimers.erase(temp);
1873  }
1874  else
1875  {
1876  (*itUl).second--;
1877  itUl++;
1878  }
1879  }
1880 }
1881 
1882 void
1883 TdMtFfMacScheduler::UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
1884 {
1885  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1886  LteFlowId_t flow(rnti, lcid);
1887  it = m_rlcBufferReq.find(flow);
1888  if (it != m_rlcBufferReq.end())
1889  {
1890  NS_LOG_INFO(this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue "
1891  << (*it).second.m_rlcTransmissionQueueSize << " retxqueue "
1892  << (*it).second.m_rlcRetransmissionQueueSize << " status "
1893  << (*it).second.m_rlcStatusPduSize << " decrease " << size);
1894  // Update queues: RLC tx order Status, ReTx, Tx
1895  // Update status queue
1896  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1897  {
1898  (*it).second.m_rlcStatusPduSize = 0;
1899  }
1900  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) &&
1901  (size >= (*it).second.m_rlcRetransmissionQueueSize))
1902  {
1903  (*it).second.m_rlcRetransmissionQueueSize = 0;
1904  }
1905  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1906  {
1907  uint32_t rlcOverhead;
1908  if (lcid == 1)
1909  {
1910  // for SRB1 (using RLC AM) it's better to
1911  // overestimate RLC overhead rather than
1912  // underestimate it and risk unneeded
1913  // segmentation which increases delay
1914  rlcOverhead = 4;
1915  }
1916  else
1917  {
1918  // minimum RLC overhead due to header
1919  rlcOverhead = 2;
1920  }
1921  // update transmission queue
1922  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
1923  {
1924  (*it).second.m_rlcTransmissionQueueSize = 0;
1925  }
1926  else
1927  {
1928  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
1929  }
1930  }
1931  }
1932  else
1933  {
1934  NS_LOG_ERROR(this << " Does not find DL RLC Buffer Report of UE " << rnti);
1935  }
1936 }
1937 
1938 void
1939 TdMtFfMacScheduler::UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
1940 {
1941  size = size - 2; // remove the minimum RLC overhead
1942  std::map<uint16_t, uint32_t>::iterator it = m_ceBsrRxed.find(rnti);
1943  if (it != m_ceBsrRxed.end())
1944  {
1945  NS_LOG_INFO(this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
1946  if ((*it).second >= size)
1947  {
1948  (*it).second -= size;
1949  }
1950  else
1951  {
1952  (*it).second = 0;
1953  }
1954  }
1955  else
1956  {
1957  NS_LOG_ERROR(this << " Does not find BSR report info of UE " << rnti);
1958  }
1959 }
1960 
1961 void
1963 {
1964  NS_LOG_FUNCTION(this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
1966  params.m_rnti = rnti;
1967  params.m_transmissionMode = txMode;
1969 }
1970 
1971 } // 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
Implements the SCHED SAP and CSCHED SAP for a Time Domain Maximize Throughput scheduler.
void DoSchedDlRachInfoReq(const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters &params)
Sched DL RACH info request.
FfMacCschedSapProvider * m_cschedSapProvider
CSched SAP provider.
std::vector< DlInfoListElement_s > m_dlInfoListBuffered
HARQ retx buffered.
std::map< uint16_t, UlHarqProcessesDciBuffer_t > m_ulHarqProcessesDciBuffer
UL HARQ process DCI buffer.
std::vector< uint16_t > m_rachAllocationMap
RACH allocation map.
void DoSchedDlPagingBufferReq(const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters &params)
Sched DL paging buffer request.
std::map< uint16_t, uint32_t > m_p10CqiTimers
Map of UE's timers on DL CQI P01 received.
FfMacCschedSapUser * m_cschedSapUser
CSched SAP user.
uint8_t m_ulGrantMcs
MCS for UL grant (default 0)
void DoSchedUlCqiInfoReq(const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters &params)
Sched UL CQI info request.
LteFfrSapUser * GetLteFfrSapUser() override
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Transmission mode configuration update function.
void DoSchedDlCqiInfoReq(const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters &params)
Sched DL CQI info request.
FfMacCschedSapProvider * GetFfMacCschedSapProvider() override
FfMacSchedSapProvider * m_schedSapProvider
Sched SAP provider.
std::set< uint16_t > m_flowStatsDl
Set of UE statistics (per RNTI basis) in downlink.
void DoSchedUlSrInfoReq(const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters &params)
Sched UL SR info request.
void DoCschedLcReleaseReq(const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters &params)
CSched LC release request.
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
CSched cell config.
friend class MemberSchedSapProvider< TdMtFfMacScheduler >
allow MemberSchedSapProvider<TdMtFfMacScheduler> class friend access
int GetRbgSize(int dlbandwidth)
Get RBG size function.
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
UL HARQ process status.
void DoSchedUlTriggerReq(const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters &params)
Sched UL trigger request.
void SetFfMacCschedSapUser(FfMacCschedSapUser *s) override
set the user part of the FfMacCschedSap that this Scheduler will interact with.
FfMacSchedSapUser * m_schedSapUser
Sched SAP user.
friend class MemberCschedSapProvider< TdMtFfMacScheduler >
allow MemberCschedSapProvider<TdMtFfMacScheduler> class friend access
bool HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
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 UpdateUlRlcBufferInfo(uint16_t rnti, uint16_t size)
Update UL RLC buffer info function.
std::map< uint16_t, DlHarqRlcPduListBuffer_t > m_dlHarqProcessesRlcPduListBuffer
DL HARQ process RLC PDU list buffer.
std::map< uint16_t, std::vector< double > > m_ueCqi
Map of UEs' UL-CQI per RBG.
std::map< uint16_t, DlHarqProcessesStatus_t > m_dlHarqProcessesStatus
DL HARQ process status.
std::set< uint16_t > m_flowStatsUl
Set of UE statistics (per RNTI basis)
void UpdateDlRlcBufferInfo(uint16_t rnti, uint8_t lcid, uint16_t size)
Update DL RLC buffer info function.
void DoSchedDlTriggerReq(const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters &params)
Sched DL trigger request.
FfMacSchedSapProvider * GetFfMacSchedSapProvider() override
unsigned int LcActivePerFlow(uint16_t rnti)
LC active flow function.
std::map< uint16_t, uint32_t > m_ceBsrRxed
Map of UE's buffer status reports received.
std::map< uint16_t, uint32_t > m_ueCqiTimers
Map of UEs' timers on UL-CQI per RBG.
void DoCschedUeReleaseReq(const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters &params)
CSched UE release request.
void SetFfMacSchedSapUser(FfMacSchedSapUser *s) override
set the user part of the FfMacSchedSap that this Scheduler will interact with.
std::map< uint16_t, DlHarqProcessesDciBuffer_t > m_dlHarqProcessesDciBuffer
DL HARQ process DCI buffer.
std::map< uint16_t, uint8_t > m_uesTxMode
txMode of the UEs
LteFfrSapProvider * m_ffrSapProvider
FFR SAP provider.
void DoSchedUlNoiseInterferenceReq(const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters &params)
Sched UL noise interference request.
void DoCschedUeConfigReq(const struct FfMacCschedSapProvider::CschedUeConfigReqParameters &params)
CSched UE config request.
std::map< uint16_t, SbMeasResult_s > m_a30CqiRxed
Map of UE's DL CQI A30 received.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
void DoSchedDlMacBufferReq(const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters &params)
Sched DL MAC buffer request.
void DoSchedUlMacCtrlInfoReq(const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters &params)
Sched UL MAC control info request.
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
std::map< uint16_t, uint32_t > m_a30CqiTimers
Map of UE's timers on DL CQI A30 received.
std::map< uint16_t, uint8_t > m_dlHarqCurrentProcessId
DL HARQ current process ID.
static TypeId GetTypeId()
Get the type ID.
void SetLteFfrSapProvider(LteFfrSapProvider *s) override
Set the Provider part of the LteFfrSap that this Scheduler will interact with.
LteFfrSapUser * m_ffrSapUser
FFR SAP user.
std::map< uint16_t, uint8_t > m_ulHarqCurrentProcessId
UL HARQ current process ID.
void DoDispose() override
Destructor implementation.
void DoSchedDlRlcBufferReq(const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters &params)
Sched DL RLC buffer request.
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
CSched cell config request.
bool m_harqOn
m_harqOn when false inhibit the HARQ mechanisms (by default active)
void RefreshDlCqiMaps()
Refresh DL CQI maps function.
void DoCschedLcConfigReq(const struct FfMacCschedSapProvider::CschedLcConfigReqParameters &params)
CSched LC config request.
~TdMtFfMacScheduler() override
Destructor.
double EstimateUlSinr(uint16_t rnti, uint16_t rb)
Estimate UL SINR function.
std::vector< struct RachListElement_s > m_rachList
RACH list.
std::map< uint16_t, uint8_t > m_p10CqiRxed
Map of UE's DL CQI P01 received.
uint16_t m_nextRntiUl
RNTI of the next user to be served next scheduling in UL.
void RefreshUlCqiMaps()
Refresh UL CQI maps function.
std::map< uint16_t, DlHarqProcessesTimer_t > m_dlHarqProcessesTimer
DL HARQ process timer.
std::map< LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters > m_rlcBufferReq
Vectors of UE's LC info.
static uint8_t TxMode2LayerNum(uint8_t txMode)
Transmit mode 2 layer number.
Definition: lte-common.cc:203
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NO_SINR
#define HARQ_PROC_NUM
#define HARQ_DL_TIMEOUT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: boolean.h:86
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
#define HARQ_PERIOD
Definition: lte-common.h:30
#define SRS_CQI_RNTI_VSP
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< UlDciListElement_s > UlHarqProcessesDciBuffer_t
UL HARQ process DCI buffer vector.
std::vector< uint8_t > DlHarqProcessesTimer_t
DL HARQ process timer vector typedef.
std::vector< uint8_t > DlHarqProcessesStatus_t
DL HARQ process status vector typedef.
std::vector< RlcPduList_t > DlHarqRlcPduListBuffer_t
vector of the 8 HARQ processes per UE
@ SUCCESS
Definition: ff-mac-common.h:62
static const int TdMtType0AllocationRbg[4]
TDMT 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.
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.