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