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