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