A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("TdBetFfMacScheduler");
35 
36 namespace ns3 {
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),
256  MakeUintegerAccessor (&TdBetFfMacScheduler::m_cqiTimersThreshold),
257  MakeUintegerChecker<uint32_t> ())
258  .AddAttribute ("HarqEnabled",
259  "Activate/Deactivate the HARQ [by default is active].",
260  BooleanValue (true),
261  MakeBooleanAccessor (&TdBetFfMacScheduler::m_harqOn),
262  MakeBooleanChecker ())
263  .AddAttribute ("UlGrantMcs",
264  "The MCS of the UL grant, must be [0..15] (default 0)",
265  UintegerValue (0),
266  MakeUintegerAccessor (&TdBetFfMacScheduler::m_ulGrantMcs),
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 {
301  NS_LOG_FUNCTION (this);
302  // Read the subset of parameters used
303  m_cschedCellConfig = params;
306  cnf.m_result = SUCCESS;
308  return;
309 }
310 
311 void
313 {
314  NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
315  std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
316  if (it == m_uesTxMode.end ())
317  {
318  m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
319  // generate HARQ buffers
320  m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
321  DlHarqProcessesStatus_t dlHarqPrcStatus;
322  dlHarqPrcStatus.resize (8,0);
323  m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
324  DlHarqProcessesTimer_t dlHarqProcessesTimer;
325  dlHarqProcessesTimer.resize (8,0);
326  m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
327  DlHarqProcessesDciBuffer_t dlHarqdci;
328  dlHarqdci.resize (8);
329  m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
330  DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
331  dlHarqRlcPdu.resize (2);
332  dlHarqRlcPdu.at (0).resize (8);
333  dlHarqRlcPdu.at (1).resize (8);
334  m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
335  m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
336  UlHarqProcessesStatus_t ulHarqPrcStatus;
337  ulHarqPrcStatus.resize (8,0);
338  m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
339  UlHarqProcessesDciBuffer_t ulHarqdci;
340  ulHarqdci.resize (8);
341  m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
342  }
343  else
344  {
345  (*it).second = params.m_transmissionMode;
346  }
347  return;
348 }
349 
350 void
352 {
353  NS_LOG_FUNCTION (this << " New LC, rnti: " << params.m_rnti);
354 
355  std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
356  for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
357  {
358  it = m_flowStatsDl.find (params.m_rnti);
359 
360  if (it == m_flowStatsDl.end ())
361  {
362  tdbetsFlowPerf_t flowStatsDl;
363  flowStatsDl.flowStart = Simulator::Now ();
364  flowStatsDl.totalBytesTransmitted = 0;
365  flowStatsDl.lastTtiBytesTrasmitted = 0;
366  flowStatsDl.lastAveragedThroughput = 1;
367  m_flowStatsDl.insert (std::pair<uint16_t, tdbetsFlowPerf_t> (params.m_rnti, flowStatsDl));
368  tdbetsFlowPerf_t flowStatsUl;
369  flowStatsUl.flowStart = Simulator::Now ();
370  flowStatsUl.totalBytesTransmitted = 0;
371  flowStatsUl.lastTtiBytesTrasmitted = 0;
372  flowStatsUl.lastAveragedThroughput = 1;
373  m_flowStatsUl.insert (std::pair<uint16_t, tdbetsFlowPerf_t> (params.m_rnti, flowStatsUl));
374  }
375  }
376 
377  return;
378 }
379 
380 void
382 {
383  NS_LOG_FUNCTION (this);
384  for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
385  {
386  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
387  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
388  while (it!=m_rlcBufferReq.end ())
389  {
390  if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
391  {
392  temp = it;
393  it++;
394  m_rlcBufferReq.erase (temp);
395  }
396  else
397  {
398  it++;
399  }
400  }
401  }
402  return;
403 }
404 
405 void
407 {
408  NS_LOG_FUNCTION (this);
409 
410  m_uesTxMode.erase (params.m_rnti);
411  m_dlHarqCurrentProcessId.erase (params.m_rnti);
412  m_dlHarqProcessesStatus.erase (params.m_rnti);
413  m_dlHarqProcessesTimer.erase (params.m_rnti);
414  m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
416  m_ulHarqCurrentProcessId.erase (params.m_rnti);
417  m_ulHarqProcessesStatus.erase (params.m_rnti);
418  m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
419  m_flowStatsDl.erase (params.m_rnti);
420  m_flowStatsUl.erase (params.m_rnti);
421  m_ceBsrRxed.erase (params.m_rnti);
422  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
423  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
424  while (it!=m_rlcBufferReq.end ())
425  {
426  if ((*it).first.m_rnti == params.m_rnti)
427  {
428  temp = it;
429  it++;
430  m_rlcBufferReq.erase (temp);
431  }
432  else
433  {
434  it++;
435  }
436  }
437  if (m_nextRntiUl == params.m_rnti)
438  {
439  m_nextRntiUl = 0;
440  }
441 
442  return;
443 }
444 
445 
446 void
448 {
449  NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
450  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
451 
452  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
453 
454  LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
455 
456  it = m_rlcBufferReq.find (flow);
457 
458  if (it == m_rlcBufferReq.end ())
459  {
460  m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
461  }
462  else
463  {
464  (*it).second = params;
465  }
466 
467  return;
468 }
469 
470 void
472 {
473  NS_LOG_FUNCTION (this);
474  NS_FATAL_ERROR ("method not implemented");
475  return;
476 }
477 
478 void
480 {
481  NS_LOG_FUNCTION (this);
482  NS_FATAL_ERROR ("method not implemented");
483  return;
484 }
485 
486 int
488 {
489  for (int i = 0; i < 4; i++)
490  {
491  if (dlbandwidth < TdBetType0AllocationRbg[i])
492  {
493  return (i + 1);
494  }
495  }
496 
497  return (-1);
498 }
499 
500 
501 int
503 {
504  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
505  int lcActive = 0;
506  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
507  {
508  if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
509  || ((*it).second.m_rlcRetransmissionQueueSize > 0)
510  || ((*it).second.m_rlcStatusPduSize > 0) ))
511  {
512  lcActive++;
513  }
514  if ((*it).first.m_rnti > rnti)
515  {
516  break;
517  }
518  }
519  return (lcActive);
520 
521 }
522 
523 
524 uint8_t
526 {
527  NS_LOG_FUNCTION (this << rnti);
528 
529  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
530  if (it == m_dlHarqCurrentProcessId.end ())
531  {
532  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
533  }
534  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
535  if (itStat == m_dlHarqProcessesStatus.end ())
536  {
537  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
538  }
539  uint8_t i = (*it).second;
540  do
541  {
542  i = (i + 1) % HARQ_PROC_NUM;
543  }
544  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
545  if ((*itStat).second.at (i) == 0)
546  {
547  return (true);
548  }
549  else
550  {
551  return (false); // return a not valid harq proc id
552  }
553 }
554 
555 
556 
557 uint8_t
559 {
560  NS_LOG_FUNCTION (this << rnti);
561 
562  if (m_harqOn == false)
563  {
564  return (0);
565  }
566 
567 
568  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
569  if (it == m_dlHarqCurrentProcessId.end ())
570  {
571  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
572  }
573  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
574  if (itStat == m_dlHarqProcessesStatus.end ())
575  {
576  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
577  }
578  uint8_t i = (*it).second;
579  do
580  {
581  i = (i + 1) % HARQ_PROC_NUM;
582  }
583  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
584  if ((*itStat).second.at (i) == 0)
585  {
586  (*it).second = i;
587  (*itStat).second.at (i) = 1;
588  }
589  else
590  {
591  NS_FATAL_ERROR ("No HARQ process available for RNTI " << rnti << " check before update with HarqProcessAvailability");
592  }
593 
594  return ((*it).second);
595 }
596 
597 
598 void
600 {
601  NS_LOG_FUNCTION (this);
602 
603  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
604  for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
605  {
606  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
607  {
608  if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
609  {
610  // reset HARQ process
611 
612  NS_LOG_DEBUG (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
613  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
614  if (itStat == m_dlHarqProcessesStatus.end ())
615  {
616  NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
617  }
618  (*itStat).second.at (i) = 0;
619  (*itTimers).second.at (i) = 0;
620  }
621  else
622  {
623  (*itTimers).second.at (i)++;
624  }
625  }
626  }
627 
628 }
629 
630 
631 void
633 {
634  NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
635  // API generated by RLC for triggering the scheduling of a DL subframe
636 
637 
638  // evaluate the relative channel quality indicator for each UE per each RBG
639  // (since we are using allocation type 0 the small unit of allocation is RBG)
640  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
641 
642  RefreshDlCqiMaps ();
643 
645  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
646  std::map <uint16_t, std::vector <uint16_t> > allocationMap; // RBs map per RNTI
647  std::vector <bool> rbgMap; // global RBGs map
648  uint16_t rbgAllocatedNum = 0;
649  std::set <uint16_t> rntiAllocated;
650  rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
652 
653  // update UL HARQ proc id
654  std::map <uint16_t, uint8_t>::iterator itProcId;
655  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
656  {
657  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
658  }
659 
660  // RACH Allocation
662  uint16_t rbStart = 0;
663  std::vector <struct RachListElement_s>::iterator itRach;
664  for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
665  {
666  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");
667  BuildRarListElement_s newRar;
668  newRar.m_rnti = (*itRach).m_rnti;
669  // DL-RACH Allocation
670  // Ideal: no needs of configuring m_dci
671  // UL-RACH Allocation
672  newRar.m_grant.m_rnti = newRar.m_rnti;
673  newRar.m_grant.m_mcs = m_ulGrantMcs;
674  uint16_t rbLen = 1;
675  uint16_t tbSizeBits = 0;
676  // find lowest TB size that fits UL grant estimated size
677  while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
678  {
679  rbLen++;
680  tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
681  }
682  if (tbSizeBits < (*itRach).m_estimatedSize)
683  {
684  // no more allocation space: finish allocation
685  break;
686  }
687  newRar.m_grant.m_rbStart = rbStart;
688  newRar.m_grant.m_rbLen = rbLen;
689  newRar.m_grant.m_tbSize = tbSizeBits / 8;
690  newRar.m_grant.m_hopping = false;
691  newRar.m_grant.m_tpc = 0;
692  newRar.m_grant.m_cqiRequest = false;
693  newRar.m_grant.m_ulDelay = false;
694  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);
695  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
696  {
697  m_rachAllocationMap.at (i) = (*itRach).m_rnti;
698  }
699  rbStart = rbStart + rbLen;
700 
701  if (m_harqOn == true)
702  {
703  // generate UL-DCI for HARQ retransmissions
704  UlDciListElement_s uldci;
705  uldci.m_rnti = newRar.m_rnti;
706  uldci.m_rbLen = rbLen;
707  uldci.m_rbStart = rbStart;
708  uldci.m_mcs = m_ulGrantMcs;
709  uldci.m_tbSize = tbSizeBits / 8;
710  uldci.m_ndi = 1;
711  uldci.m_cceIndex = 0;
712  uldci.m_aggrLevel = 1;
713  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
714  uldci.m_hopping = false;
715  uldci.m_n2Dmrs = 0;
716  uldci.m_tpc = 0; // no power control
717  uldci.m_cqiRequest = false; // only period CQI at this stage
718  uldci.m_ulIndex = 0; // TDD parameter
719  uldci.m_dai = 1; // TDD parameter
720  uldci.m_freqHopping = 0;
721  uldci.m_pdcchPowerOffset = 0; // not used
722 
723  uint8_t harqId = 0;
724  std::map <uint16_t, uint8_t>::iterator itProcId;
725  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
726  if (itProcId == m_ulHarqCurrentProcessId.end ())
727  {
728  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
729  }
730  harqId = (*itProcId).second;
731  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
732  if (itDci == m_ulHarqProcessesDciBuffer.end ())
733  {
734  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
735  }
736  (*itDci).second.at (harqId) = uldci;
737  }
738 
739  ret.m_buildRarList.push_back (newRar);
740  }
741  m_rachList.clear ();
742 
743 
744  // Process DL HARQ feedback
746  // retrieve past HARQ retx buffered
747  if (m_dlInfoListBuffered.size () > 0)
748  {
749  if (params.m_dlInfoList.size () > 0)
750  {
751  NS_LOG_INFO (this << " Received DL-HARQ feedback");
752  m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
753  }
754  }
755  else
756  {
757  if (params.m_dlInfoList.size () > 0)
758  {
760  }
761  }
762  if (m_harqOn == false)
763  {
764  // Ignore HARQ feedback
765  m_dlInfoListBuffered.clear ();
766  }
767  std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
768  for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
769  {
770  std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
771  if (itRnti != rntiAllocated.end ())
772  {
773  // RNTI already allocated for retx
774  continue;
775  }
776  uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
777  std::vector <bool> retx;
778  NS_LOG_INFO (this << " Processing DLHARQ feedback");
779  if (nLayers == 1)
780  {
781  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
782  retx.push_back (false);
783  }
784  else
785  {
786  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
787  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
788  }
789  if (retx.at (0) || retx.at (1))
790  {
791  // retrieve HARQ process information
792  uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
793  uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
794  NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
795  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
796  if (itHarq == m_dlHarqProcessesDciBuffer.end ())
797  {
798  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << rnti);
799  }
800 
801  DlDciListElement_s dci = (*itHarq).second.at (harqId);
802  int rv = 0;
803  if (dci.m_rv.size () == 1)
804  {
805  rv = dci.m_rv.at (0);
806  }
807  else
808  {
809  rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
810  }
811 
812  if (rv == 3)
813  {
814  // maximum number of retx reached -> drop process
815  NS_LOG_INFO ("Maximum number of retransmissions reached -> drop process");
816  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
817  if (it == m_dlHarqProcessesStatus.end ())
818  {
819  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
820  }
821  (*it).second.at (harqId) = 0;
822  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
823  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
824  {
825  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
826  }
827  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
828  {
829  (*itRlcPdu).second.at (k).at (harqId).clear ();
830  }
831  continue;
832  }
833  // check the feasibility of retransmitting on the same RBGs
834  // translate the DCI to Spectrum framework
835  std::vector <int> dciRbg;
836  uint32_t mask = 0x1;
837  NS_LOG_INFO ("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
838  for (int j = 0; j < 32; j++)
839  {
840  if (((dci.m_rbBitmap & mask) >> j) == 1)
841  {
842  dciRbg.push_back (j);
843  NS_LOG_INFO ("\t" << j);
844  }
845  mask = (mask << 1);
846  }
847  bool free = true;
848  for (uint8_t j = 0; j < dciRbg.size (); j++)
849  {
850  if (rbgMap.at (dciRbg.at (j)) == true)
851  {
852  free = false;
853  break;
854  }
855  }
856  if (free)
857  {
858  // use the same RBGs for the retx
859  // reserve RBGs
860  for (uint8_t j = 0; j < dciRbg.size (); j++)
861  {
862  rbgMap.at (dciRbg.at (j)) = true;
863  NS_LOG_INFO ("RBG " << dciRbg.at (j) << " assigned");
864  rbgAllocatedNum++;
865  }
866 
867  NS_LOG_INFO (this << " Send retx in the same RBGs");
868  }
869  else
870  {
871  // find RBGs for sending HARQ retx
872  uint8_t j = 0;
873  uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
874  uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
875  std::vector <bool> rbgMapCopy = rbgMap;
876  while ((j < dciRbg.size ())&&(startRbg != rbgId))
877  {
878  if (rbgMapCopy.at (rbgId) == false)
879  {
880  rbgMapCopy.at (rbgId) = true;
881  dciRbg.at (j) = rbgId;
882  j++;
883  }
884  rbgId++;
885  }
886  if (j == dciRbg.size ())
887  {
888  // find new RBGs -> update DCI map
889  uint32_t rbgMask = 0;
890  for (uint16_t k = 0; k < dciRbg.size (); k++)
891  {
892  rbgMask = rbgMask + (0x1 << dciRbg.at (k));
893  rbgAllocatedNum++;
894  }
895  dci.m_rbBitmap = rbgMask;
896  rbgMap = rbgMapCopy;
897  NS_LOG_INFO (this << " Move retx in RBGs " << dciRbg.size ());
898  }
899  else
900  {
901  // HARQ retx cannot be performed on this TTI -> store it
902  dlInfoListUntxed.push_back (params.m_dlInfoList.at (i));
903  NS_LOG_INFO (this << " No resource for this retx -> buffer it");
904  }
905  }
906  // retrieve RLC PDU list for retx TBsize and update DCI
908  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
909  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
910  {
911  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
912  }
913  for (uint8_t j = 0; j < nLayers; j++)
914  {
915  if (retx.at (j))
916  {
917  if (j >= dci.m_ndi.size ())
918  {
919  // for avoiding errors in MIMO transient phases
920  dci.m_ndi.push_back (0);
921  dci.m_rv.push_back (0);
922  dci.m_mcs.push_back (0);
923  dci.m_tbsSize.push_back (0);
924  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no txed (MIMO transition)");
925  }
926  else
927  {
928  dci.m_ndi.at (j) = 0;
929  dci.m_rv.at (j)++;
930  (*itHarq).second.at (harqId).m_rv.at (j)++;
931  NS_LOG_INFO (this << " layer " << (uint16_t)j << " RV " << (uint16_t)dci.m_rv.at (j));
932  }
933  }
934  else
935  {
936  // empty TB of layer j
937  dci.m_ndi.at (j) = 0;
938  dci.m_rv.at (j) = 0;
939  dci.m_mcs.at (j) = 0;
940  dci.m_tbsSize.at (j) = 0;
941  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no retx");
942  }
943  }
944  for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
945  {
946  std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
947  for (uint8_t j = 0; j < nLayers; j++)
948  {
949  if (retx.at (j))
950  {
951  if (j < dci.m_ndi.size ())
952  {
953  rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
954  }
955  }
956  }
957 
958  if (rlcPduListPerLc.size () > 0)
959  {
960  newEl.m_rlcPduList.push_back (rlcPduListPerLc);
961  }
962  }
963  newEl.m_rnti = rnti;
964  newEl.m_dci = dci;
965  (*itHarq).second.at (harqId).m_rv = dci.m_rv;
966  // refresh timer
967  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
968  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
969  {
970  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
971  }
972  (*itHarqTimer).second.at (harqId) = 0;
973  ret.m_buildDataList.push_back (newEl);
974  rntiAllocated.insert (rnti);
975  }
976  else
977  {
978  // update HARQ process status
979  NS_LOG_INFO (this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
980  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
981  if (it == m_dlHarqProcessesStatus.end ())
982  {
983  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
984  }
985  (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
986  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
987  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
988  {
989  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
990  }
991  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
992  {
993  (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
994  }
995  }
996  }
997  m_dlInfoListBuffered.clear ();
998  m_dlInfoListBuffered = dlInfoListUntxed;
999 
1000  if (rbgAllocatedNum == rbgNum)
1001  {
1002  // all the RBGs are already allocated -> exit
1003  if ((ret.m_buildDataList.size () > 0) || (ret.m_buildRarList.size () > 0))
1004  {
1006  }
1007  return;
1008  }
1009 
1010 
1011  std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
1012  std::map <uint16_t, tdbetsFlowPerf_t>::iterator itMax = m_flowStatsDl.end ();
1013  double metricMax = 0.0;
1014  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
1015  {
1016  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1017  if ((itRnti != rntiAllocated.end ())||(!HarqProcessAvailability ((*it).first)))
1018  {
1019  // UE already allocated for HARQ or without HARQ process available -> drop it
1020  if (itRnti != rntiAllocated.end ())
1021  {
1022  NS_LOG_DEBUG (this << " RNTI discared for HARQ tx" << (uint16_t)(*it).first);
1023  }
1024  if (!HarqProcessAvailability ((*it).first))
1025  {
1026  NS_LOG_DEBUG (this << " RNTI discared for HARQ id" << (uint16_t)(*it).first);
1027  }
1028  continue;
1029  }
1030 
1031  double metric = 1 / (*it).second.lastAveragedThroughput;
1032 
1033  if (metric > metricMax)
1034  {
1035  metricMax = metric;
1036  itMax = it;
1037  }
1038  } // end for m_flowStatsDl
1039 
1040 
1041  if (itMax == m_flowStatsDl.end ())
1042  {
1043  // no UE available for downlink
1044  return;
1045  }
1046  else
1047  {
1048  // assign all RBGs to this UE
1049  std::vector <uint16_t> tempMap;
1050  for (int i = 0; i < rbgNum; i++)
1051  {
1052  tempMap.push_back (i);
1053  }
1054  allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax).first, tempMap));
1055  }
1056 
1057 
1058  // reset TTI stats of users
1059  std::map <uint16_t, tdbetsFlowPerf_t>::iterator itStats;
1060  for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1061  {
1062  (*itStats).second.lastTtiBytesTrasmitted = 0;
1063  }
1064 
1065  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1066  // creating the correspondent DCIs
1067  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1068  while (itMap != allocationMap.end ())
1069  {
1070  // create new BuildDataListElement_s for this LC
1071  BuildDataListElement_s newEl;
1072  newEl.m_rnti = (*itMap).first;
1073  // create the DlDciListElement_s
1074  DlDciListElement_s newDci;
1075  newDci.m_rnti = (*itMap).first;
1076  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1077 
1078  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1079  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1080  if (lcActives == 0)
1081  {
1082  // Set to max value, to avoid divide by 0 below
1083  lcActives = (uint16_t)65535; // UINT16_MAX;
1084  }
1085  uint16_t RgbPerRnti = (*itMap).second.size ();
1086  std::map <uint16_t,uint8_t>::iterator itCqi;
1087  itCqi = m_p10CqiRxed.find ((*itMap).first);
1088  std::map <uint16_t,uint8_t>::iterator itTxMode;
1089  itTxMode = m_uesTxMode.find ((*itMap).first);
1090  if (itTxMode == m_uesTxMode.end ())
1091  {
1092  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1093  }
1094  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1095 
1096  uint32_t bytesTxed = 0;
1097  for (uint8_t j = 0; j < nLayer; j++)
1098  {
1099  if (itCqi == m_p10CqiRxed.end ())
1100  {
1101  newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
1102  }
1103  else
1104  {
1105  newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
1106  }
1107 
1108  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)
1109  newDci.m_tbsSize.push_back (tbSize);
1110  bytesTxed += tbSize;
1111  }
1112 
1113  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1114  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1115  uint32_t rbgMask = 0;
1116  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1117  {
1118  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1119  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1120  }
1121  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1122 
1123  // create the rlc PDUs -> equally divide resources among actives LCs
1124  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1125  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1126  {
1127  if (((*itBufReq).first.m_rnti == (*itMap).first)
1128  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1129  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1130  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1131  {
1132  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1133  for (uint8_t j = 0; j < nLayer; j++)
1134  {
1135  RlcPduListElement_s newRlcEl;
1136  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1137  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1138  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1139  newRlcPduLe.push_back (newRlcEl);
1140  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1141  if (m_harqOn == true)
1142  {
1143  // store RLC PDU list for HARQ
1144  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1145  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1146  {
1147  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1148  }
1149  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1150  }
1151  }
1152  newEl.m_rlcPduList.push_back (newRlcPduLe);
1153  }
1154  if ((*itBufReq).first.m_rnti > (*itMap).first)
1155  {
1156  break;
1157  }
1158  }
1159  for (uint8_t j = 0; j < nLayer; j++)
1160  {
1161  newDci.m_ndi.push_back (1);
1162  newDci.m_rv.push_back (0);
1163  }
1164 
1165  newEl.m_dci = newDci;
1166 
1167  if (m_harqOn == true)
1168  {
1169  // store DCI for HARQ
1170  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1171  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1172  {
1173  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1174  }
1175  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1176  // refresh timer
1177  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1178  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1179  {
1180  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1181  }
1182  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1183  }
1184 
1185  // ...more parameters -> ingored in this version
1186 
1187  ret.m_buildDataList.push_back (newEl);
1188  // update UE stats
1189  std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
1190  it = m_flowStatsDl.find ((*itMap).first);
1191  if (it != m_flowStatsDl.end ())
1192  {
1193  (*it).second.lastTtiBytesTrasmitted = bytesTxed;
1194  NS_LOG_INFO (this << " UE total bytes txed " << (*it).second.lastTtiBytesTrasmitted);
1195 
1196 
1197  }
1198  else
1199  {
1200  NS_FATAL_ERROR (this << " No Stats for this allocated UE");
1201  }
1202 
1203  itMap++;
1204  } // end while allocation
1205  ret.m_nrOfPdcchOfdmSymbols = 1;
1206 
1207 
1208  // update UEs stats
1209  NS_LOG_INFO (this << " Update UEs statistics");
1210  for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1211  {
1212  (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1213  // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term Evolution, Ed Wiley)
1214  (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1215  NS_LOG_INFO (this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1216  NS_LOG_INFO (this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1217  (*itStats).second.lastTtiBytesTrasmitted = 0;
1218  }
1219 
1221 
1222 
1223  return;
1224 }
1225 
1226 void
1228 {
1229  NS_LOG_FUNCTION (this);
1230 
1231  m_rachList = params.m_rachList;
1232 
1233  return;
1234 }
1235 
1236 void
1238 {
1239  NS_LOG_FUNCTION (this);
1240 
1241  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1242  {
1243  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1244  {
1245  // wideband CQI reporting
1246  std::map <uint16_t,uint8_t>::iterator it;
1247  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1248  it = m_p10CqiRxed.find (rnti);
1249  if (it == m_p10CqiRxed.end ())
1250  {
1251  // create the new entry
1252  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)
1253  // generate correspondent timer
1254  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1255  }
1256  else
1257  {
1258  // update the CQI value and refresh correspondent timer
1259  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1260  // update correspondent timer
1261  std::map <uint16_t,uint32_t>::iterator itTimers;
1262  itTimers = m_p10CqiTimers.find (rnti);
1263  (*itTimers).second = m_cqiTimersThreshold;
1264  }
1265  }
1266  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1267  {
1268  // subband CQI reporting high layer configured
1269  std::map <uint16_t,SbMeasResult_s>::iterator it;
1270  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1271  it = m_a30CqiRxed.find (rnti);
1272  if (it == m_a30CqiRxed.end ())
1273  {
1274  // create the new entry
1275  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1276  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1277  }
1278  else
1279  {
1280  // update the CQI value and refresh correspondent timer
1281  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1282  std::map <uint16_t,uint32_t>::iterator itTimers;
1283  itTimers = m_a30CqiTimers.find (rnti);
1284  (*itTimers).second = m_cqiTimersThreshold;
1285  }
1286  }
1287  else
1288  {
1289  NS_LOG_ERROR (this << " CQI type unknown");
1290  }
1291  }
1292 
1293  return;
1294 }
1295 
1296 
1297 double
1298 TdBetFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1299 {
1300  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1301  if (itCqi == m_ueCqi.end ())
1302  {
1303  // no cqi info about this UE
1304  return (NO_SINR);
1305 
1306  }
1307  else
1308  {
1309  // take the average SINR value among the available
1310  double sinrSum = 0;
1311  int sinrNum = 0;
1312  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1313  {
1314  double sinr = (*itCqi).second.at (i);
1315  if (sinr != NO_SINR)
1316  {
1317  sinrSum += sinr;
1318  sinrNum++;
1319  }
1320  }
1321  double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1322  // store the value
1323  (*itCqi).second.at (rb) = estimatedSinr;
1324  return (estimatedSinr);
1325  }
1326 }
1327 
1328 void
1330 {
1331  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1332 
1333  RefreshUlCqiMaps ();
1334 
1335  // Generate RBs map
1337  std::vector <bool> rbMap;
1338  uint16_t rbAllocatedNum = 0;
1339  std::set <uint16_t> rntiAllocated;
1340  std::vector <uint16_t> rbgAllocationMap;
1341  // update with RACH allocation map
1342  rbgAllocationMap = m_rachAllocationMap;
1343  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1344  m_rachAllocationMap.clear ();
1346 
1347  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1348  // remove RACH allocation
1349  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1350  {
1351  if (rbgAllocationMap.at (i) != 0)
1352  {
1353  rbMap.at (i) = true;
1354  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1355  }
1356  }
1357 
1358 
1359  if (m_harqOn == true)
1360  {
1361  // Process UL HARQ feedback
1362  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1363  {
1364  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1365  {
1366  // retx correspondent block: retrieve the UL-DCI
1367  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1368  std::map <uint16_t, uint8_t>::iterator itProcId = m_ulHarqCurrentProcessId.find (rnti);
1369  if (itProcId == m_ulHarqCurrentProcessId.end ())
1370  {
1371  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1372  }
1373  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1374  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1375  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1376  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1377  {
1378  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1379  continue;
1380  }
1381  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1382  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1383  if (itStat == m_ulHarqProcessesStatus.end ())
1384  {
1385  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1386  }
1387  if ((*itStat).second.at (harqId) >= 3)
1388  {
1389  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1390  continue;
1391  }
1392  bool free = true;
1393  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1394  {
1395  if (rbMap.at (j) == true)
1396  {
1397  free = false;
1398  NS_LOG_INFO (this << " BUSY " << j);
1399  }
1400  }
1401  if (free)
1402  {
1403  // retx on the same RBs
1404  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1405  {
1406  rbMap.at (j) = true;
1407  rbgAllocationMap.at (j) = dci.m_rnti;
1408  NS_LOG_INFO ("\tRB " << j);
1409  rbAllocatedNum++;
1410  }
1411  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);
1412  }
1413  else
1414  {
1415  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1416  continue;
1417  }
1418  dci.m_ndi = 0;
1419  // Update HARQ buffers with new HarqId
1420  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1421  (*itStat).second.at (harqId) = 0;
1422  (*itHarq).second.at ((*itProcId).second) = dci;
1423  ret.m_dciList.push_back (dci);
1424  rntiAllocated.insert (dci.m_rnti);
1425  }
1426  else
1427  {
1428  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1429  }
1430  }
1431  }
1432 
1433  std::map <uint16_t,uint32_t>::iterator it;
1434  int nflows = 0;
1435 
1436  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1437  {
1438  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1439  // select UEs with queues not empty and not yet allocated for HARQ
1440  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1441  {
1442  nflows++;
1443  }
1444  }
1445 
1446  if (nflows == 0)
1447  {
1448  if (ret.m_dciList.size () > 0)
1449  {
1450  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1452  }
1453 
1454  return; // no flows to be scheduled
1455  }
1456 
1457 
1458  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1459  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1460  if (rbPerFlow < 3)
1461  {
1462  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1463  }
1464  int rbAllocated = 0;
1465 
1466  std::map <uint16_t, tdbetsFlowPerf_t>::iterator itStats;
1467  if (m_nextRntiUl != 0)
1468  {
1469  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1470  {
1471  if ((*it).first == m_nextRntiUl)
1472  {
1473  break;
1474  }
1475  }
1476  if (it == m_ceBsrRxed.end ())
1477  {
1478  NS_LOG_ERROR (this << " no user found");
1479  }
1480  }
1481  else
1482  {
1483  it = m_ceBsrRxed.begin ();
1484  m_nextRntiUl = (*it).first;
1485  }
1486  do
1487  {
1488  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1489  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1490  {
1491  // UE already allocated for UL-HARQ -> skip it
1492  NS_LOG_DEBUG (this << " UE already allocated in HARQ -> discared, RNTI " << (*it).first);
1493  it++;
1494  if (it == m_ceBsrRxed.end ())
1495  {
1496  // restart from the first
1497  it = m_ceBsrRxed.begin ();
1498  }
1499  continue;
1500  }
1501  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1502  {
1503  // limit to physical resources last resource assignment
1504  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1505  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1506  if (rbPerFlow < 3)
1507  {
1508  // terminate allocation
1509  rbPerFlow = 0;
1510  }
1511  }
1512 
1513  UlDciListElement_s uldci;
1514  uldci.m_rnti = (*it).first;
1515  uldci.m_rbLen = rbPerFlow;
1516  bool allocated = false;
1517  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows);
1518  while ((!allocated)&&((rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth) < 1) && (rbPerFlow != 0))
1519  {
1520  // check availability
1521  bool free = true;
1522  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1523  {
1524  if (rbMap.at (j) == true)
1525  {
1526  free = false;
1527  break;
1528  }
1529  }
1530  if (free)
1531  {
1532  uldci.m_rbStart = rbAllocated;
1533 
1534  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1535  {
1536  rbMap.at (j) = true;
1537  // store info on allocation for managing ul-cqi interpretation
1538  rbgAllocationMap.at (j) = (*it).first;
1539  }
1540  rbAllocated += rbPerFlow;
1541  allocated = true;
1542  break;
1543  }
1544  rbAllocated++;
1545  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1546  {
1547  // limit to physical resources last resource assignment
1548  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1549  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1550  if (rbPerFlow < 3)
1551  {
1552  // terminate allocation
1553  rbPerFlow = 0;
1554  }
1555  }
1556  }
1557  if (!allocated)
1558  {
1559  // unable to allocate new resource: finish scheduling
1560  m_nextRntiUl = (*it).first;
1561  if (ret.m_dciList.size () > 0)
1562  {
1564  }
1565  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1566  return;
1567  }
1568 
1569 
1570 
1571  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1572  int cqi = 0;
1573  if (itCqi == m_ueCqi.end ())
1574  {
1575  // no cqi info about this UE
1576  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1577  }
1578  else
1579  {
1580  // take the lowest CQI value (worst RB)
1581  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1582  if (minSinr == NO_SINR)
1583  {
1584  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1585  }
1586  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1587  {
1588  double sinr = (*itCqi).second.at (i);
1589  if (sinr == NO_SINR)
1590  {
1591  sinr = EstimateUlSinr ((*it).first, i);
1592  }
1593  if ((*itCqi).second.at (i) < minSinr)
1594  {
1595  minSinr = (*itCqi).second.at (i);
1596  }
1597  }
1598 
1599  // translate SINR -> cqi: WILD ACK: same as DL
1600  double s = log2 ( 1 + (
1601  std::pow (10, minSinr / 10 ) /
1602  ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1603  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1604  if (cqi == 0)
1605  {
1606  it++;
1607  if (it == m_ceBsrRxed.end ())
1608  {
1609  // restart from the first
1610  it = m_ceBsrRxed.begin ();
1611  }
1612  NS_LOG_DEBUG (this << " UE discared for CQI=0, RNTI " << uldci.m_rnti);
1613  // remove UE from allocation map
1614  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1615  {
1616  rbgAllocationMap.at (i) = 0;
1617  }
1618  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1619  }
1620  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1621  }
1622 
1623  uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1624  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1625  uldci.m_ndi = 1;
1626  uldci.m_cceIndex = 0;
1627  uldci.m_aggrLevel = 1;
1628  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1629  uldci.m_hopping = false;
1630  uldci.m_n2Dmrs = 0;
1631  uldci.m_tpc = 0; // no power control
1632  uldci.m_cqiRequest = false; // only period CQI at this stage
1633  uldci.m_ulIndex = 0; // TDD parameter
1634  uldci.m_dai = 1; // TDD parameter
1635  uldci.m_freqHopping = 0;
1636  uldci.m_pdcchPowerOffset = 0; // not used
1637  ret.m_dciList.push_back (uldci);
1638  // store DCI for HARQ_PERIOD
1639  uint8_t harqId = 0;
1640  if (m_harqOn == true)
1641  {
1642  std::map <uint16_t, uint8_t>::iterator itProcId;
1643  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1644  if (itProcId == m_ulHarqCurrentProcessId.end ())
1645  {
1646  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1647  }
1648  harqId = (*itProcId).second;
1649  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1650  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1651  {
1652  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1653  }
1654  (*itDci).second.at (harqId) = uldci;
1655  }
1656 
1657  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);
1658 
1659  // update TTI UE stats
1660  itStats = m_flowStatsUl.find ((*it).first);
1661  if (itStats != m_flowStatsUl.end ())
1662  {
1663  (*itStats).second.lastTtiBytesTrasmitted = uldci.m_tbSize;
1664  }
1665  else
1666  {
1667  NS_LOG_DEBUG (this << " No Stats for this allocated UE");
1668  }
1669 
1670 
1671  it++;
1672  if (it == m_ceBsrRxed.end ())
1673  {
1674  // restart from the first
1675  it = m_ceBsrRxed.begin ();
1676  }
1677  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1678  {
1679  // Stop allocation: no more PRBs
1680  m_nextRntiUl = (*it).first;
1681  break;
1682  }
1683  }
1684  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1685 
1686 
1687  // Update global UE stats
1688  // update UEs stats
1689  for (itStats = m_flowStatsUl.begin (); itStats != m_flowStatsUl.end (); itStats++)
1690  {
1691  (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1692  // update average throughput (see eq. 12.3 of Sec 12.3.1.2 of LTE – The UMTS Long Term Evolution, Ed Wiley)
1693  (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1694  NS_LOG_INFO (this << " UE total bytes " << (*itStats).second.totalBytesTransmitted);
1695  NS_LOG_INFO (this << " UE average throughput " << (*itStats).second.lastAveragedThroughput);
1696  (*itStats).second.lastTtiBytesTrasmitted = 0;
1697  }
1698  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1700 
1701  return;
1702 }
1703 
1704 void
1706 {
1707  NS_LOG_FUNCTION (this);
1708  return;
1709 }
1710 
1711 void
1713 {
1714  NS_LOG_FUNCTION (this);
1715  return;
1716 }
1717 
1718 void
1720 {
1721  NS_LOG_FUNCTION (this);
1722 
1723  std::map <uint16_t,uint32_t>::iterator it;
1724 
1725  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1726  {
1727  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1728  {
1729  // buffer status report
1730  // note that this scheduler does not differentiate the
1731  // allocation according to which LCGs have more/less bytes
1732  // to send.
1733  // Hence the BSR of different LCGs are just summed up to get
1734  // a total queue size that is used for allocation purposes.
1735 
1736  uint32_t buffer = 0;
1737  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1738  {
1739  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1740  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1741  }
1742 
1743  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1744  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
1745  it = m_ceBsrRxed.find (rnti);
1746  if (it == m_ceBsrRxed.end ())
1747  {
1748  // create the new entry
1749  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1750  }
1751  else
1752  {
1753  // update the buffer size value
1754  (*it).second = buffer;
1755  }
1756  }
1757  }
1758 
1759  return;
1760 }
1761 
1762 void
1764 {
1765  NS_LOG_FUNCTION (this);
1766 // retrieve the allocation for this subframe
1767  switch (m_ulCqiFilter)
1768  {
1770  {
1771  // filter all the CQIs that are not SRS based
1772  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1773  {
1774  return;
1775  }
1776  }
1777  break;
1779  {
1780  // filter all the CQIs that are not SRS based
1781  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1782  {
1783  return;
1784  }
1785  }
1787  break;
1788 
1789  default:
1790  NS_FATAL_ERROR ("Unknown UL CQI type");
1791  }
1792 
1793  switch (params.m_ulCqi.m_type)
1794  {
1795  case UlCqi_s::PUSCH:
1796  {
1797  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1798  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1799  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
1800  itMap = m_allocationMaps.find (params.m_sfnSf);
1801  if (itMap == m_allocationMaps.end ())
1802  {
1803  return;
1804  }
1805  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1806  {
1807  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
1808  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1809  itCqi = m_ueCqi.find ((*itMap).second.at (i));
1810  if (itCqi == m_ueCqi.end ())
1811  {
1812  // create a new entry
1813  std::vector <double> newCqi;
1814  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1815  {
1816  if (i == j)
1817  {
1818  newCqi.push_back (sinr);
1819  }
1820  else
1821  {
1822  // initialize with NO_SINR value.
1823  newCqi.push_back (NO_SINR);
1824  }
1825 
1826  }
1827  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1828  // generate correspondent timer
1829  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1830  }
1831  else
1832  {
1833  // update the value
1834  (*itCqi).second.at (i) = sinr;
1835  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
1836  // update correspondent timer
1837  std::map <uint16_t, uint32_t>::iterator itTimers;
1838  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1839  (*itTimers).second = m_cqiTimersThreshold;
1840 
1841  }
1842 
1843  }
1844  // remove obsolete info on allocation
1845  m_allocationMaps.erase (itMap);
1846  }
1847  break;
1848  case UlCqi_s::SRS:
1849  {
1850  // get the RNTI from vendor specific parameters
1851  uint16_t rnti = 0;
1852  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1853  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1854  {
1855  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1856  {
1857  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1858  rnti = vsp->GetRnti ();
1859  }
1860  }
1861  std::map <uint16_t, std::vector <double> >::iterator itCqi;
1862  itCqi = m_ueCqi.find (rnti);
1863  if (itCqi == m_ueCqi.end ())
1864  {
1865  // create a new entry
1866  std::vector <double> newCqi;
1867  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1868  {
1869  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1870  newCqi.push_back (sinr);
1871  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
1872 
1873  }
1874  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1875  // generate correspondent timer
1876  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1877  }
1878  else
1879  {
1880  // update the values
1881  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1882  {
1883  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1884  (*itCqi).second.at (j) = sinr;
1885  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
1886  }
1887  // update correspondent timer
1888  std::map <uint16_t, uint32_t>::iterator itTimers;
1889  itTimers = m_ueCqiTimers.find (rnti);
1890  (*itTimers).second = m_cqiTimersThreshold;
1891 
1892  }
1893 
1894 
1895  }
1896  break;
1897  case UlCqi_s::PUCCH_1:
1898  case UlCqi_s::PUCCH_2:
1899  case UlCqi_s::PRACH:
1900  {
1901  NS_FATAL_ERROR ("TdBetFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1902  }
1903  break;
1904  default:
1905  NS_FATAL_ERROR ("Unknown type of UL-CQI");
1906  }
1907  return;
1908 }
1909 
1910 void
1912 {
1913  // refresh DL CQI P01 Map
1914  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1915  while (itP10 != m_p10CqiTimers.end ())
1916  {
1917  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1918  if ((*itP10).second == 0)
1919  {
1920  // delete correspondent entries
1921  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1922  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
1923  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
1924  m_p10CqiRxed.erase (itMap);
1925  std::map <uint16_t,uint32_t>::iterator temp = itP10;
1926  itP10++;
1927  m_p10CqiTimers.erase (temp);
1928  }
1929  else
1930  {
1931  (*itP10).second--;
1932  itP10++;
1933  }
1934  }
1935 
1936  // refresh DL CQI A30 Map
1937  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
1938  while (itA30 != m_a30CqiTimers.end ())
1939  {
1940  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1941  if ((*itA30).second == 0)
1942  {
1943  // delete correspondent entries
1944  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
1945  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
1946  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
1947  m_a30CqiRxed.erase (itMap);
1948  std::map <uint16_t,uint32_t>::iterator temp = itA30;
1949  itA30++;
1950  m_a30CqiTimers.erase (temp);
1951  }
1952  else
1953  {
1954  (*itA30).second--;
1955  itA30++;
1956  }
1957  }
1958 
1959  return;
1960 }
1961 
1962 
1963 void
1965 {
1966  // refresh UL CQI Map
1967  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1968  while (itUl != m_ueCqiTimers.end ())
1969  {
1970  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
1971  if ((*itUl).second == 0)
1972  {
1973  // delete correspondent entries
1974  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1975  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
1976  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
1977  (*itMap).second.clear ();
1978  m_ueCqi.erase (itMap);
1979  std::map <uint16_t,uint32_t>::iterator temp = itUl;
1980  itUl++;
1981  m_ueCqiTimers.erase (temp);
1982  }
1983  else
1984  {
1985  (*itUl).second--;
1986  itUl++;
1987  }
1988  }
1989 
1990  return;
1991 }
1992 
1993 void
1994 TdBetFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1995 {
1996  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1997  LteFlowId_t flow (rnti, lcid);
1998  it = m_rlcBufferReq.find (flow);
1999  if (it != m_rlcBufferReq.end ())
2000  {
2001  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);
2002  // Update queues: RLC tx order Status, ReTx, Tx
2003  // Update status queue
2004  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2005  {
2006  (*it).second.m_rlcStatusPduSize = 0;
2007  }
2008  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2009  {
2010  (*it).second.m_rlcRetransmissionQueueSize = 0;
2011  }
2012  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2013  {
2014  uint32_t rlcOverhead;
2015  if (lcid == 1)
2016  {
2017  // for SRB1 (using RLC AM) it's better to
2018  // overestimate RLC overhead rather than
2019  // underestimate it and risk unneeded
2020  // segmentation which increases delay
2021  rlcOverhead = 4;
2022  }
2023  else
2024  {
2025  // minimum RLC overhead due to header
2026  rlcOverhead = 2;
2027  }
2028  // update transmission queue
2029  if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2030  {
2031  (*it).second.m_rlcTransmissionQueueSize = 0;
2032  }
2033  else
2034  {
2035  (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2036  }
2037  }
2038  }
2039  else
2040  {
2041  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2042  }
2043 }
2044 
2045 void
2046 TdBetFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2047 {
2048 
2049  size = size - 2; // remove the minimum RLC overhead
2050  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2051  if (it != m_ceBsrRxed.end ())
2052  {
2053  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2054  if ((*it).second >= size)
2055  {
2056  (*it).second -= size;
2057  }
2058  else
2059  {
2060  (*it).second = 0;
2061  }
2062  }
2063  else
2064  {
2065  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2066  }
2067 
2068 }
2069 
2070 void
2072 {
2073  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2075  params.m_rnti = rnti;
2076  params.m_transmissionMode = txMode;
2078 }
2079 
2080 
2081 }
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:60
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)
Hold a bool native type.
Definition: boolean.h:38
std::map< uint16_t, UlHarqProcessesStatus_t > m_ulHarqProcessesStatus
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
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
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:170
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:223
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
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
void DoCschedCellConfigReq(const struct FfMacCschedSapProvider::CschedCellConfigReqParameters &params)
FfMacCschedSapProvider::CschedCellConfigReqParameters m_cschedCellConfig
Parameters of the SCHED_UL_TRIGGER_REQ primitive.
virtual void SchedDlRlcBufferReq(const struct SchedDlRlcBufferReqParameters &params)
Hold an unsigned integer type.
Definition: uinteger.h:46
static uint8_t TxMode2LayerNum(uint8_t txMode)
Definition: lte-common.cc:170
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:233
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.
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
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 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 time".
Definition: simulator.cc:180
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:114
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:142
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:213
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:193
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
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
std::vector< uint16_t > m_rachAllocationMap
#define HARQ_PROC_NUM
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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...