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