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