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