23 #include <ns3/pointer.h>
26 #include <ns3/simulator.h>
27 #include <ns3/lte-amc.h>
28 #include <ns3/tdtbfq-ff-mac-scheduler.h>
29 #include <ns3/lte-vendor-specific-parameters.h>
30 #include <ns3/boolean.h>
31 #include <ns3/integer.h>
38 int TdTbfqType0AllocationRbg[4] = {
46 NS_OBJECT_ENSURE_REGISTERED (TdTbfqFfMacScheduler);
67 TdTbfqSchedulerMemberCschedSapProvider::TdTbfqSchedulerMemberCschedSapProvider ()
71 TdTbfqSchedulerMemberCschedSapProvider::TdTbfqSchedulerMemberCschedSapProvider (TdTbfqFfMacScheduler* scheduler) : m_scheduler (scheduler)
79 m_scheduler->DoCschedCellConfigReq (params);
83 TdTbfqSchedulerMemberCschedSapProvider::CschedUeConfigReq (
const struct CschedUeConfigReqParameters& params)
85 m_scheduler->DoCschedUeConfigReq (params);
90 TdTbfqSchedulerMemberCschedSapProvider::CschedLcConfigReq (
const struct CschedLcConfigReqParameters& params)
92 m_scheduler->DoCschedLcConfigReq (params);
96 TdTbfqSchedulerMemberCschedSapProvider::CschedLcReleaseReq (
const struct CschedLcReleaseReqParameters& params)
98 m_scheduler->DoCschedLcReleaseReq (params);
102 TdTbfqSchedulerMemberCschedSapProvider::CschedUeReleaseReq (
const struct CschedUeReleaseReqParameters& params)
104 m_scheduler->DoCschedUeReleaseReq (params);
136 TdTbfqSchedulerMemberSchedSapProvider::TdTbfqSchedulerMemberSchedSapProvider ()
141 TdTbfqSchedulerMemberSchedSapProvider::TdTbfqSchedulerMemberSchedSapProvider (TdTbfqFfMacScheduler* scheduler)
142 : m_scheduler (scheduler)
147 TdTbfqSchedulerMemberSchedSapProvider::SchedDlRlcBufferReq (
const struct SchedDlRlcBufferReqParameters& params)
149 m_scheduler->DoSchedDlRlcBufferReq (params);
153 TdTbfqSchedulerMemberSchedSapProvider::SchedDlPagingBufferReq (
const struct SchedDlPagingBufferReqParameters& params)
155 m_scheduler->DoSchedDlPagingBufferReq (params);
159 TdTbfqSchedulerMemberSchedSapProvider::SchedDlMacBufferReq (
const struct SchedDlMacBufferReqParameters& params)
161 m_scheduler->DoSchedDlMacBufferReq (params);
165 TdTbfqSchedulerMemberSchedSapProvider::SchedDlTriggerReq (
const struct SchedDlTriggerReqParameters& params)
167 m_scheduler->DoSchedDlTriggerReq (params);
171 TdTbfqSchedulerMemberSchedSapProvider::SchedDlRachInfoReq (
const struct SchedDlRachInfoReqParameters& params)
173 m_scheduler->DoSchedDlRachInfoReq (params);
177 TdTbfqSchedulerMemberSchedSapProvider::SchedDlCqiInfoReq (
const struct SchedDlCqiInfoReqParameters& params)
179 m_scheduler->DoSchedDlCqiInfoReq (params);
183 TdTbfqSchedulerMemberSchedSapProvider::SchedUlTriggerReq (
const struct SchedUlTriggerReqParameters& params)
185 m_scheduler->DoSchedUlTriggerReq (params);
189 TdTbfqSchedulerMemberSchedSapProvider::SchedUlNoiseInterferenceReq (
const struct SchedUlNoiseInterferenceReqParameters& params)
191 m_scheduler->DoSchedUlNoiseInterferenceReq (params);
195 TdTbfqSchedulerMemberSchedSapProvider::SchedUlSrInfoReq (
const struct SchedUlSrInfoReqParameters& params)
197 m_scheduler->DoSchedUlSrInfoReq (params);
201 TdTbfqSchedulerMemberSchedSapProvider::SchedUlMacCtrlInfoReq (
const struct SchedUlMacCtrlInfoReqParameters& params)
203 m_scheduler->DoSchedUlMacCtrlInfoReq (params);
207 TdTbfqSchedulerMemberSchedSapProvider::SchedUlCqiInfoReq (
const struct SchedUlCqiInfoReqParameters& params)
209 m_scheduler->DoSchedUlCqiInfoReq (params);
217 : m_cschedSapUser (0),
223 m_amc = CreateObject <LteAmc> ();
237 m_dlHarqProcessesDciBuffer.clear ();
238 m_dlHarqProcessesTimer.clear ();
239 m_dlHarqProcessesRlcPduListBuffer.clear ();
240 m_dlInfoListBuffered.clear ();
241 m_ulHarqCurrentProcessId.clear ();
242 m_ulHarqProcessesStatus.clear ();
243 m_ulHarqProcessesDciBuffer.clear ();
244 delete m_cschedSapProvider;
245 delete m_schedSapProvider;
249 TdTbfqFfMacScheduler::GetTypeId (
void)
251 static TypeId tid =
TypeId (
"ns3::TdTbfqFfMacScheduler")
253 .AddConstructor<TdTbfqFfMacScheduler> ()
254 .AddAttribute (
"CqiTimerThreshold",
255 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
257 MakeUintegerAccessor (&TdTbfqFfMacScheduler::m_cqiTimersThreshold),
258 MakeUintegerChecker<uint32_t> ())
259 .AddAttribute (
"DebtLimit",
260 "Flow debt limit (default -625000 bytes)",
262 MakeIntegerAccessor (&TdTbfqFfMacScheduler::m_debtLimit),
263 MakeIntegerChecker<int> ())
264 .AddAttribute (
"CreditLimit",
265 "Flow credit limit (default 625000 bytes)",
267 MakeUintegerAccessor (&TdTbfqFfMacScheduler::m_creditLimit),
268 MakeUintegerChecker<uint32_t> ())
269 .AddAttribute (
"TokenPoolSize",
270 "The maximum value of flow token pool (default 1 bytes)",
272 MakeUintegerAccessor (&TdTbfqFfMacScheduler::m_tokenPoolSize),
273 MakeUintegerChecker<uint32_t> ())
274 .AddAttribute (
"CreditableThreshold",
275 "Threshold of flow credit (default 0 bytes)",
277 MakeUintegerAccessor (&TdTbfqFfMacScheduler::m_creditableThreshold),
278 MakeUintegerChecker<uint32_t> ())
280 .AddAttribute (
"HarqEnabled",
281 "Activate/Deactivate the HARQ [by default is active].",
284 MakeBooleanChecker ())
285 .AddAttribute (
"UlGrantMcs",
286 "The MCS of the UL grant, must be [0..15] (default 0)",
288 MakeUintegerAccessor (&TdTbfqFfMacScheduler::m_ulGrantMcs),
289 MakeUintegerChecker<uint8_t> ())
311 return m_cschedSapProvider;
317 return m_schedSapProvider;
325 m_cschedCellConfig = params;
326 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
328 cnf.m_result = SUCCESS;
329 m_cschedSapUser->CschedUeConfigCnf (cnf);
334 TdTbfqFfMacScheduler::DoCschedUeConfigReq (
const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
336 NS_LOG_FUNCTION (
this <<
" RNTI " << params.m_rnti <<
" txMode " << (uint16_t)params.m_transmissionMode);
337 std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
338 if (it == m_uesTxMode.end ())
340 m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
342 m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
343 DlHarqProcessesStatus_t dlHarqPrcStatus;
344 dlHarqPrcStatus.resize (8,0);
345 m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
346 DlHarqProcessesTimer_t dlHarqProcessesTimer;
347 dlHarqProcessesTimer.resize (8,0);
348 m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
349 DlHarqProcessesDciBuffer_t dlHarqdci;
350 dlHarqdci.resize (8);
351 m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
352 DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
353 dlHarqRlcPdu.resize (2);
354 dlHarqRlcPdu.at (0).resize (8);
355 dlHarqRlcPdu.at (1).resize (8);
356 m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
357 m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
358 UlHarqProcessesStatus_t ulHarqPrcStatus;
359 ulHarqPrcStatus.resize (8,0);
360 m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
361 UlHarqProcessesDciBuffer_t ulHarqdci;
362 ulHarqdci.resize (8);
363 m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
367 (*it).second = params.m_transmissionMode;
373 TdTbfqFfMacScheduler::DoCschedLcConfigReq (
const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
377 std::map <uint16_t, tdtbfqsFlowPerf_t>::iterator it;
378 for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
380 it = m_flowStatsDl.find (params.m_rnti);
382 if (it == m_flowStatsDl.end ())
384 uint64_t mbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateDl / 8;
385 uint64_t mbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateUl / 8;
387 tdtbfqsFlowPerf_t flowStatsDl;
389 flowStatsDl.packetArrivalRate = 0;
390 flowStatsDl.tokenGenerationRate = mbrDlInBytes;
391 flowStatsDl.tokenPoolSize = 0;
392 flowStatsDl.maxTokenPoolSize = m_tokenPoolSize;
393 flowStatsDl.counter = 0;
394 flowStatsDl.burstCredit = m_creditLimit;
395 flowStatsDl.debtLimit = m_debtLimit;
396 flowStatsDl.creditableThreshold = m_creditableThreshold;
397 m_flowStatsDl.insert (std::pair<uint16_t, tdtbfqsFlowPerf_t> (params.m_rnti, flowStatsDl));
398 tdtbfqsFlowPerf_t flowStatsUl;
400 flowStatsUl.packetArrivalRate = 0;
401 flowStatsUl.tokenGenerationRate = mbrUlInBytes;
402 flowStatsUl.tokenPoolSize = 0;
403 flowStatsUl.maxTokenPoolSize = m_tokenPoolSize;
404 flowStatsUl.counter = 0;
405 flowStatsUl.burstCredit = m_creditLimit;
406 flowStatsUl.debtLimit = m_debtLimit;
407 flowStatsUl.creditableThreshold = m_creditableThreshold;
408 m_flowStatsUl.insert (std::pair<uint16_t, tdtbfqsFlowPerf_t> (params.m_rnti, flowStatsUl));
415 uint64_t mbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateDl / 8;
416 uint64_t mbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateUl / 8;
417 m_flowStatsDl[(*it).first].tokenGenerationRate = mbrDlInBytes;
418 m_flowStatsUl[(*it).first].tokenGenerationRate = mbrUlInBytes;
427 TdTbfqFfMacScheduler::DoCschedLcReleaseReq (
const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters& params)
430 for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
432 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
433 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
434 while (it!=m_rlcBufferReq.end ())
436 if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
440 m_rlcBufferReq.erase (temp);
452 TdTbfqFfMacScheduler::DoCschedUeReleaseReq (
const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters& params)
456 m_uesTxMode.erase (params.m_rnti);
457 m_dlHarqCurrentProcessId.erase (params.m_rnti);
458 m_dlHarqProcessesStatus.erase (params.m_rnti);
459 m_dlHarqProcessesTimer.erase (params.m_rnti);
460 m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
461 m_dlHarqProcessesRlcPduListBuffer.erase (params.m_rnti);
462 m_ulHarqCurrentProcessId.erase (params.m_rnti);
463 m_ulHarqProcessesStatus.erase (params.m_rnti);
464 m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
465 m_flowStatsDl.erase (params.m_rnti);
466 m_flowStatsUl.erase (params.m_rnti);
467 m_ceBsrRxed.erase (params.m_rnti);
468 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
469 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
470 while (it!=m_rlcBufferReq.end ())
472 if ((*it).first.m_rnti == params.m_rnti)
476 m_rlcBufferReq.erase (temp);
483 if (m_nextRntiUl == params.m_rnti)
493 TdTbfqFfMacScheduler::DoSchedDlRlcBufferReq (
const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters& params)
495 NS_LOG_FUNCTION (
this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
498 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
500 LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
502 it = m_rlcBufferReq.find (flow);
504 if (it == m_rlcBufferReq.end ())
506 m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
510 (*it).second = params;
517 TdTbfqFfMacScheduler::DoSchedDlPagingBufferReq (
const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters& params)
525 TdTbfqFfMacScheduler::DoSchedDlMacBufferReq (
const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters& params)
533 TdTbfqFfMacScheduler::GetRbgSize (
int dlbandwidth)
535 for (
int i = 0; i < 4; i++)
537 if (dlbandwidth < TdTbfqType0AllocationRbg[i])
548 TdTbfqFfMacScheduler::LcActivePerFlow (uint16_t rnti)
550 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
552 for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
554 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
555 || ((*it).second.m_rlcRetransmissionQueueSize > 0)
556 || ((*it).second.m_rlcStatusPduSize > 0) ))
560 if ((*it).first.m_rnti > rnti)
575 std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
576 if (it == m_dlHarqCurrentProcessId.end ())
580 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
581 if (itStat == m_dlHarqProcessesStatus.end ())
583 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
585 uint8_t i = (*it).second;
588 i = (i + 1) % HARQ_PROC_NUM;
590 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
591 if ((*itStat).second.at (i) == 0)
614 std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
615 if (it == m_dlHarqCurrentProcessId.end ())
619 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
620 if (itStat == m_dlHarqProcessesStatus.end ())
622 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
624 uint8_t i = (*it).second;
627 i = (i + 1) % HARQ_PROC_NUM;
629 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
630 if ((*itStat).second.at (i) == 0)
633 (*itStat).second.at (i) = 1;
637 NS_FATAL_ERROR (
"No HARQ process available for RNTI " << rnti <<
" check before update with HarqProcessAvailability");
640 return ((*it).second);
649 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
650 for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
652 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
654 if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
658 NS_LOG_DEBUG (
this <<
" Reset HARQ proc " << i <<
" for RNTI " << (*itTimers).first);
659 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
660 if (itStat == m_dlHarqProcessesStatus.end ())
662 NS_FATAL_ERROR (
"No Process Id Status found for this RNTI " << (*itTimers).first);
664 (*itStat).second.at (i) = 0;
665 (*itTimers).second.at (i) = 0;
669 (*itTimers).second.at (i)++;
680 NS_LOG_FUNCTION (
this <<
" Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf));
690 int rbgSize = GetRbgSize (m_cschedCellConfig.m_dlBandwidth);
691 int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
692 std::map <uint16_t, std::vector <uint16_t> > allocationMap;
693 std::vector <bool> rbgMap;
694 uint16_t rbgAllocatedNum = 0;
695 std::set <uint16_t> rntiAllocated;
696 rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize,
false);
700 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
701 uint16_t rbStart = 0;
702 std::vector <struct RachListElement_s>::iterator itRach;
703 for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
705 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");
707 newRar.m_rnti = (*itRach).m_rnti;
711 newRar.m_grant.m_rnti = newRar.m_rnti;
712 newRar.m_grant.m_mcs = m_ulGrantMcs;
714 uint16_t tbSizeBits = 0;
716 while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
719 tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
721 if (tbSizeBits < (*itRach).m_estimatedSize)
726 newRar.m_grant.m_rbStart = rbStart;
727 newRar.m_grant.m_rbLen = rbLen;
728 newRar.m_grant.m_tbSize = tbSizeBits / 8;
729 newRar.m_grant.m_hopping =
false;
730 newRar.m_grant.m_tpc = 0;
731 newRar.m_grant.m_cqiRequest =
false;
732 newRar.m_grant.m_ulDelay =
false;
733 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);
734 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
736 m_rachAllocationMap.at (i) = (*itRach).m_rnti;
738 rbStart = rbStart + rbLen;
740 ret.m_buildRarList.push_back (newRar);
748 if (m_dlInfoListBuffered.size () > 0)
750 if (params.m_dlInfoList.size () > 0)
752 NS_LOG_INFO (
this <<
" Received DL-HARQ feedback");
753 m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
758 if (params.m_dlInfoList.size () > 0)
760 m_dlInfoListBuffered = params.m_dlInfoList;
766 m_dlInfoListBuffered.clear ();
768 std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
769 for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
771 std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
772 if (itRnti != rntiAllocated.end ())
777 uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
778 std::vector <bool> retx;
779 NS_LOG_INFO (
this <<
" Processing DLHARQ feedback");
782 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
783 retx.push_back (
false);
787 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
788 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
790 if (retx.at (0) || retx.at (1))
793 uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
794 uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
795 NS_LOG_INFO (
this <<
" HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
796 std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
797 if (itHarq == m_dlHarqProcessesDciBuffer.end ())
802 DlDciListElement_s dci = (*itHarq).second.at (harqId);
804 if (dci.m_rv.size () == 1)
806 rv = dci.m_rv.at (0);
810 rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
816 NS_LOG_INFO (
"Maximum number of retransmissions reached -> drop process");
817 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
818 if (it == m_dlHarqProcessesStatus.end ())
820 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
822 (*it).second.at (harqId) = 0;
823 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
824 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
826 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
828 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
830 (*itRlcPdu).second.at (k).at (harqId).clear ();
836 std::vector <int> dciRbg;
838 NS_LOG_INFO (
"Original RBGs " << dci.m_rbBitmap <<
" rnti " << dci.m_rnti);
839 for (
int j = 0; j < 32; j++)
841 if (((dci.m_rbBitmap & mask) >> j) == 1)
843 dciRbg.push_back (j);
849 for (uint8_t j = 0; j < dciRbg.size (); j++)
851 if (rbgMap.at (dciRbg.at (j)) ==
true)
861 for (uint8_t j = 0; j < dciRbg.size (); j++)
863 rbgMap.at (dciRbg.at (j)) =
true;
864 NS_LOG_INFO (
"RBG " << dciRbg.at (j) <<
" assigned");
868 NS_LOG_INFO (
this <<
" Send retx in the same RBGs");
874 uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
875 uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
876 std::vector <bool> rbgMapCopy = rbgMap;
877 while ((j < dciRbg.size ())&&(startRbg != rbgId))
879 if (rbgMapCopy.at (rbgId) ==
false)
881 rbgMapCopy.at (rbgId) =
true;
882 dciRbg.at (j) = rbgId;
887 if (j == dciRbg.size ())
890 uint32_t rbgMask = 0;
891 for (uint16_t k = 0; k < dciRbg.size (); k++)
893 rbgMask = rbgMask + (0x1 << dciRbg.at (k));
896 dci.m_rbBitmap = rbgMask;
898 NS_LOG_INFO (
this <<
" Move retx in RBGs " << dciRbg.size ());
903 dlInfoListUntxed.push_back (params.m_dlInfoList.at (i));
904 NS_LOG_INFO (
this <<
" No resource for this retx -> buffer it");
908 BuildDataListElement_s newEl;
909 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
910 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
912 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
914 for (uint8_t j = 0; j < nLayers; j++)
918 if (j >= dci.m_ndi.size ())
921 dci.m_ndi.push_back (0);
922 dci.m_rv.push_back (0);
923 dci.m_mcs.push_back (0);
924 dci.m_tbsSize.push_back (0);
925 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no txed (MIMO transition)");
929 dci.m_ndi.at (j) = 0;
931 (*itHarq).second.at (harqId).m_rv.at (j)++;
932 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" RV " << (uint16_t)dci.m_rv.at (j));
938 dci.m_ndi.at (j) = 0;
940 dci.m_mcs.at (j) = 0;
941 dci.m_tbsSize.at (j) = 0;
942 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no retx");
945 for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
947 std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
948 for (uint8_t j = 0; j < nLayers; j++)
952 if (j < dci.m_ndi.size ())
954 rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
959 if (rlcPduListPerLc.size () > 0)
961 newEl.m_rlcPduList.push_back (rlcPduListPerLc);
966 (*itHarq).second.at (harqId).m_rv = dci.m_rv;
968 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
969 if (itHarqTimer== m_dlHarqProcessesTimer.end ())
971 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
973 (*itHarqTimer).second.at (harqId) = 0;
974 ret.m_buildDataList.push_back (newEl);
975 rntiAllocated.insert (rnti);
980 NS_LOG_INFO (
this <<
" HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
981 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
982 if (it == m_dlHarqProcessesStatus.end ())
984 NS_FATAL_ERROR (
"No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
986 (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
987 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
988 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
990 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
992 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
994 (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
998 m_dlInfoListBuffered.clear ();
999 m_dlInfoListBuffered = dlInfoListUntxed;
1003 std::map <uint16_t, tdtbfqsFlowPerf_t>::iterator itStats;
1004 for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1006 if ( (*itStats).second.tokenGenerationRate / 1000 + (*itStats).second.tokenPoolSize > (*itStats).second.maxTokenPoolSize )
1008 (*itStats).second.counter += (*itStats).second.tokenGenerationRate / 1000 - ( (*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize );
1009 (*itStats).second.tokenPoolSize = (*itStats).second.maxTokenPoolSize;
1010 bankSize += (*itStats).second.tokenGenerationRate / 1000 - ( (*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize );
1014 (*itStats).second.tokenPoolSize += (*itStats).second.tokenGenerationRate / 1000;
1020 std::map <uint16_t, tdtbfqsFlowPerf_t>::iterator it;
1021 std::map <uint16_t, tdtbfqsFlowPerf_t>::iterator itMax = m_flowStatsDl.end ();
1022 double metricMax = 0.0;
1023 bool firstRnti =
true;
1024 for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
1026 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1030 if (itRnti != rntiAllocated.end ())
1032 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ tx" << (uint16_t)(*it).first);
1036 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ id" << (uint16_t)(*it).first);
1048 double metric = ( ( (double)(*it).second.counter ) / ( (double)(*it).second.tokenGenerationRate ) );
1050 if (firstRnti ==
true)
1057 if (metric > metricMax)
1064 if (itMax == m_flowStatsDl.end ())
1072 std::vector <uint16_t> tempMap;
1073 for (
int i = 0; i < rbgNum; i++)
1075 if ( rbgMap.at (i) ==
true)
1078 tempMap.push_back (i);
1079 rbgMap.at (i) =
true;
1081 allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax).first, tempMap));
1088 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1089 while (itMap != allocationMap.end ())
1092 BuildDataListElement_s newEl;
1093 newEl.m_rnti = (*itMap).first;
1095 DlDciListElement_s newDci;
1096 newDci.m_rnti = (*itMap).first;
1099 uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1100 NS_LOG_INFO (
this <<
"Allocate user " << newEl.m_rnti <<
" rbg " << lcActives);
1101 uint16_t RgbPerRnti = (*itMap).second.size ();
1102 std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1103 itCqi = m_a30CqiRxed.find ((*itMap).first);
1104 std::map <uint16_t,uint8_t>::iterator itTxMode;
1105 itTxMode = m_uesTxMode.find ((*itMap).first);
1106 if (itTxMode == m_uesTxMode.end ())
1108 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*itMap).first);
1110 int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1111 std::vector <uint8_t> worstCqi (2, 15);
1112 if (itCqi != m_a30CqiRxed.end ())
1114 for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1116 if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1118 for (uint8_t j = 0; j < nLayer; j++)
1120 if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1122 if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1124 worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1130 worstCqi.at (j) = 1;
1136 for (uint8_t j = 0; j < nLayer; j++)
1138 worstCqi.at (j) = 1;
1145 for (uint8_t j = 0; j < nLayer; j++)
1147 worstCqi.at (j) = 1;
1150 uint32_t bytesTxed = 0;
1151 for (uint8_t j = 0; j < nLayer; j++)
1153 newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1154 int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (j), RgbPerRnti * rbgSize) / 8);
1155 newDci.m_tbsSize.push_back (tbSize);
1156 bytesTxed += tbSize;
1159 newDci.m_resAlloc = 0;
1160 newDci.m_rbBitmap = 0;
1161 uint32_t rbgMask = 0;
1162 for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1164 rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1165 NS_LOG_INFO (
this <<
" Allocated RBG " << (*itMap).second.at (k));
1167 newDci.m_rbBitmap = rbgMask;
1170 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1171 for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1173 if (((*itBufReq).first.m_rnti == (*itMap).first)
1174 && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1175 || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1176 || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1178 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1179 for (uint8_t j = 0; j < nLayer; j++)
1181 RlcPduListElement_s newRlcEl;
1182 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1183 newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1184 NS_LOG_INFO (
this <<
" LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity <<
" size " << newRlcEl.m_size <<
" layer " << (uint16_t)j);
1185 newRlcPduLe.push_back (newRlcEl);
1186 UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1190 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1191 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1193 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1195 (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1198 newEl.m_rlcPduList.push_back (newRlcPduLe);
1200 if ((*itBufReq).first.m_rnti > (*itMap).first)
1205 for (uint8_t j = 0; j < nLayer; j++)
1207 newDci.m_ndi.push_back (1);
1208 newDci.m_rv.push_back (0);
1211 newEl.m_dci = newDci;
1216 std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1217 if (itDci == m_dlHarqProcessesDciBuffer.end ())
1219 NS_FATAL_ERROR (
"Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1221 (*itDci).second.at (newDci.m_harqProcess) = newDci;
1223 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1224 if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1226 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1228 (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1233 if ( bytesTxed <= (*itMax).second.tokenPoolSize )
1235 (*itMax).second.tokenPoolSize -= bytesTxed;
1239 (*itMax).second.counter = (*itMax).second.counter - ( bytesTxed - (*itMax).second.tokenPoolSize );
1240 (*itMax).second.tokenPoolSize = 0;
1241 if (bankSize <= ( bytesTxed - (*itMax).second.tokenPoolSize ))
1244 bankSize = bankSize - ( bytesTxed - (*itMax).second.tokenPoolSize );
1250 ret.m_buildDataList.push_back (newEl);
1254 ret.m_nrOfPdcchOfdmSymbols = 1;
1256 m_schedSapUser->SchedDlConfigInd (ret);
1263 TdTbfqFfMacScheduler::DoSchedDlRachInfoReq (
const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters& params)
1267 m_rachList = params.m_rachList;
1273 TdTbfqFfMacScheduler::DoSchedDlCqiInfoReq (
const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters& params)
1277 for (
unsigned int i = 0; i < params.m_cqiList.size (); i++)
1279 if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1282 std::map <uint16_t,uint8_t>::iterator it;
1283 uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1284 it = m_p10CqiRxed.find (rnti);
1285 if (it == m_p10CqiRxed.end ())
1288 m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.m_cqiList.at (i).m_wbCqi.at (0)) );
1290 m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1295 (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1297 std::map <uint16_t,uint32_t>::iterator itTimers;
1298 itTimers = m_p10CqiTimers.find (rnti);
1299 (*itTimers).second = m_cqiTimersThreshold;
1302 else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1305 std::map <uint16_t,SbMeasResult_s>::iterator it;
1306 uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1307 it = m_a30CqiRxed.find (rnti);
1308 if (it == m_a30CqiRxed.end ())
1311 m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1312 m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1317 (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1318 std::map <uint16_t,uint32_t>::iterator itTimers;
1319 itTimers = m_a30CqiTimers.find (rnti);
1320 (*itTimers).second = m_cqiTimersThreshold;
1334 TdTbfqFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1336 std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1337 if (itCqi == m_ueCqi.end ())
1348 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1350 double sinr = (*itCqi).second.at (i);
1351 if (sinr != NO_SINR)
1357 double estimatedSinr = sinrSum / (double)sinrNum;
1359 (*itCqi).second.at (rb) = estimatedSinr;
1360 return (estimatedSinr);
1365 TdTbfqFfMacScheduler::DoSchedUlTriggerReq (
const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
1367 NS_LOG_FUNCTION (
this <<
" UL - Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf) <<
" size " << params.m_ulInfoList.size ());
1369 RefreshUlCqiMaps ();
1372 FfMacSchedSapUser::SchedUlConfigIndParameters ret;
1373 std::vector <bool> rbMap;
1374 uint16_t rbAllocatedNum = 0;
1375 std::set <uint16_t> rntiAllocated;
1376 std::vector <uint16_t> rbgAllocationMap;
1378 rbgAllocationMap = m_rachAllocationMap;
1380 m_rachAllocationMap.clear ();
1381 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1383 rbMap.resize (m_cschedCellConfig.m_ulBandwidth,
false);
1385 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1387 if (rbgAllocationMap.at (i) != 0)
1389 rbMap.at (i) =
true;
1399 std::map <uint16_t, uint8_t>::iterator itProcId;
1400 for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
1402 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
1405 for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1407 if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1410 uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1411 itProcId = m_ulHarqCurrentProcessId.find (rnti);
1412 if (itProcId == m_ulHarqCurrentProcessId.end ())
1414 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1416 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1417 NS_LOG_INFO (
this <<
" UL-HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId <<
" i " << i <<
" size " << params.m_ulInfoList.size ());
1418 std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1419 if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1421 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1424 UlDciListElement_s dci = (*itHarq).second.at (harqId);
1425 std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1426 if (itStat == m_ulHarqProcessesStatus.end ())
1428 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1430 if ((*itStat).second.at (harqId) >= 3)
1432 NS_LOG_INFO (
"Max number of retransmissions reached (UL)-> drop process");
1436 for (
int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1438 if (rbMap.at (j) ==
true)
1447 for (
int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1449 rbMap.at (j) =
true;
1450 rbgAllocationMap.at (j) = dci.m_rnti;
1454 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);
1458 NS_LOG_INFO (
"Cannot allocate retx due to RACH allocations for UE " << rnti);
1463 (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1464 (*itStat).second.at (harqId) = 0;
1465 (*itHarq).second.at ((*itProcId).second) = dci;
1466 ret.m_dciList.push_back (dci);
1467 rntiAllocated.insert (dci.m_rnti);
1471 NS_LOG_INFO (
this <<
" HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1476 std::map <uint16_t,uint32_t>::iterator it;
1479 for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1481 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1483 if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1491 if (ret.m_dciList.size () > 0)
1493 m_schedSapUser->SchedUlConfigInd (ret);
1501 uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1506 int rbAllocated = 0;
1508 std::map <uint16_t, tdtbfqsFlowPerf_t>::iterator itStats;
1509 if (m_nextRntiUl != 0)
1511 for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1513 if ((*it).first == m_nextRntiUl)
1518 if (it == m_ceBsrRxed.end ())
1525 it = m_ceBsrRxed.begin ();
1526 m_nextRntiUl = (*it).first;
1530 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1531 if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1535 if (it == m_ceBsrRxed.end ())
1538 it = m_ceBsrRxed.begin ();
1542 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1545 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1554 UlDciListElement_s uldci;
1555 uldci.m_rnti = (*it).first;
1556 uldci.m_rbLen = rbPerFlow;
1557 bool allocated =
false;
1558 NS_LOG_INFO (
this <<
" RB Allocated " << rbAllocated <<
" rbPerFlow " << rbPerFlow);
1559 while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0))
1563 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1565 if (rbMap.at (j) ==
true)
1573 uldci.m_rbStart = rbAllocated;
1575 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1577 rbMap.at (j) =
true;
1579 rbgAllocationMap.at (j) = (*it).first;
1581 rbAllocated += rbPerFlow;
1586 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1589 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1601 m_nextRntiUl = (*it).first;
1602 if (ret.m_dciList.size () > 0)
1604 m_schedSapUser->SchedUlConfigInd (ret);
1606 m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1612 std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1614 if (itCqi == m_ueCqi.end ())
1622 double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1623 if (minSinr == NO_SINR)
1625 minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1627 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1629 double sinr = (*itCqi).second.at (i);
1630 if (sinr == NO_SINR)
1632 sinr = EstimateUlSinr ((*it).first, i);
1634 if ((*itCqi).second.at (i) < minSinr)
1636 minSinr = (*itCqi).second.at (i);
1641 double s = log2 ( 1 + (
1642 pow (10, minSinr / 10 ) /
1643 ( (-log (5.0 * 0.00005 )) / 1.5) ));
1644 cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1648 if (it == m_ceBsrRxed.end ())
1651 it = m_ceBsrRxed.begin ();
1655 uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1658 uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1659 UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1661 uldci.m_cceIndex = 0;
1662 uldci.m_aggrLevel = 1;
1663 uldci.m_ueTxAntennaSelection = 3;
1664 uldci.m_hopping =
false;
1667 uldci.m_cqiRequest =
false;
1668 uldci.m_ulIndex = 0;
1670 uldci.m_freqHopping = 0;
1671 uldci.m_pdcchPowerOffset = 0;
1672 ret.m_dciList.push_back (uldci);
1677 std::map <uint16_t, uint8_t>::iterator itProcId;
1678 itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1679 if (itProcId == m_ulHarqCurrentProcessId.end ())
1681 NS_FATAL_ERROR (
"No info find in HARQ buffer for UE " << uldci.m_rnti);
1683 harqId = (*itProcId).second;
1684 std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1685 if (itDci == m_ulHarqProcessesDciBuffer.end ())
1687 NS_FATAL_ERROR (
"Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1689 (*itDci).second.at (harqId) = uldci;
1692 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);
1695 if (it == m_ceBsrRxed.end ())
1698 it = m_ceBsrRxed.begin ();
1700 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1703 m_nextRntiUl = (*it).first;
1707 while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1710 m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1711 m_schedSapUser->SchedUlConfigInd (ret);
1717 TdTbfqFfMacScheduler::DoSchedUlNoiseInterferenceReq (
const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters& params)
1724 TdTbfqFfMacScheduler::DoSchedUlSrInfoReq (
const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters& params)
1731 TdTbfqFfMacScheduler::DoSchedUlMacCtrlInfoReq (
const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters& params)
1735 std::map <uint16_t,uint32_t>::iterator it;
1737 for (
unsigned int i = 0; i < params.m_macCeList.size (); i++)
1739 if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1748 uint32_t buffer = 0;
1749 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1751 uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1752 buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1755 uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1756 NS_LOG_LOGIC (
this <<
"RNTI=" << rnti <<
" buffer=" << buffer);
1757 it = m_ceBsrRxed.find (rnti);
1758 if (it == m_ceBsrRxed.end ())
1761 m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1766 (*it).second = buffer;
1775 TdTbfqFfMacScheduler::DoSchedUlCqiInfoReq (
const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
1779 switch (m_ulCqiFilter)
1781 case FfMacScheduler::SRS_UL_CQI:
1784 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1790 case FfMacScheduler::PUSCH_UL_CQI:
1793 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1798 case FfMacScheduler::ALL_UL_CQI:
1805 switch (params.m_ulCqi.m_type)
1807 case UlCqi_s::PUSCH:
1809 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1810 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1811 NS_LOG_DEBUG (
this <<
" Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf));
1812 itMap = m_allocationMaps.find (params.m_sfnSf);
1813 if (itMap == m_allocationMaps.end ())
1817 for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1820 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1821 itCqi = m_ueCqi.find ((*itMap).second.at (i));
1822 if (itCqi == m_ueCqi.end ())
1825 std::vector <double> newCqi;
1826 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1830 newCqi.push_back (sinr);
1835 newCqi.push_back (NO_SINR);
1839 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1841 m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1846 (*itCqi).second.at (i) = sinr;
1847 NS_LOG_DEBUG (
this <<
" RNTI " << (*itMap).second.at (i) <<
" RB " << i <<
" SINR " << sinr);
1849 std::map <uint16_t, uint32_t>::iterator itTimers;
1850 itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1851 (*itTimers).second = m_cqiTimersThreshold;
1857 m_allocationMaps.erase (itMap);
1864 NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1865 for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1867 if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1869 Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1870 rnti = vsp->GetRnti ();
1873 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1874 itCqi = m_ueCqi.find (rnti);
1875 if (itCqi == m_ueCqi.end ())
1878 std::vector <double> newCqi;
1879 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1881 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1882 newCqi.push_back (sinr);
1883 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" new SRS-CQI for RB " << j <<
" value " << sinr);
1886 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1888 m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1893 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1895 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1896 (*itCqi).second.at (j) = sinr;
1897 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" update SRS-CQI for RB " << j <<
" value " << sinr);
1900 std::map <uint16_t, uint32_t>::iterator itTimers;
1901 itTimers = m_ueCqiTimers.find (rnti);
1902 (*itTimers).second = m_cqiTimersThreshold;
1909 case UlCqi_s::PUCCH_1:
1910 case UlCqi_s::PUCCH_2:
1911 case UlCqi_s::PRACH:
1913 NS_FATAL_ERROR (
"TdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1923 TdTbfqFfMacScheduler::RefreshDlCqiMaps (
void)
1926 std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1927 while (itP10 != m_p10CqiTimers.end ())
1929 NS_LOG_INFO (
this <<
" P10-CQI for user " << (*itP10).first <<
" is " << (uint32_t)(*itP10).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1930 if ((*itP10).second == 0)
1933 std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1934 NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (),
" Does not find CQI report for user " << (*itP10).first);
1935 NS_LOG_INFO (
this <<
" P10-CQI expired for user " << (*itP10).first);
1936 m_p10CqiRxed.erase (itMap);
1937 std::map <uint16_t,uint32_t>::iterator temp = itP10;
1939 m_p10CqiTimers.erase (temp);
1949 std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
1950 while (itA30 != m_a30CqiTimers.end ())
1952 NS_LOG_INFO (
this <<
" A30-CQI for user " << (*itA30).first <<
" is " << (uint32_t)(*itA30).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1953 if ((*itA30).second == 0)
1956 std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
1957 NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (),
" Does not find CQI report for user " << (*itA30).first);
1958 NS_LOG_INFO (
this <<
" A30-CQI expired for user " << (*itA30).first);
1959 m_a30CqiRxed.erase (itMap);
1960 std::map <uint16_t,uint32_t>::iterator temp = itA30;
1962 m_a30CqiTimers.erase (temp);
1976 TdTbfqFfMacScheduler::RefreshUlCqiMaps (
void)
1979 std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1980 while (itUl != m_ueCqiTimers.end ())
1982 NS_LOG_INFO (
this <<
" UL-CQI for user " << (*itUl).first <<
" is " << (uint32_t)(*itUl).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1983 if ((*itUl).second == 0)
1986 std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1987 NS_ASSERT_MSG (itMap != m_ueCqi.end (),
" Does not find CQI report for user " << (*itUl).first);
1988 NS_LOG_INFO (
this <<
" UL-CQI exired for user " << (*itUl).first);
1989 (*itMap).second.clear ();
1990 m_ueCqi.erase (itMap);
1991 std::map <uint16_t,uint32_t>::iterator temp = itUl;
1993 m_ueCqiTimers.erase (temp);
2006 TdTbfqFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
2008 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2009 LteFlowId_t flow (rnti, lcid);
2010 it = m_rlcBufferReq.find (flow);
2011 if (it != m_rlcBufferReq.end ())
2013 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);
2016 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2018 (*it).second.m_rlcStatusPduSize = 0;
2020 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2022 (*it).second.m_rlcRetransmissionQueueSize = 0;
2024 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2027 if ((*it).second.m_rlcTransmissionQueueSize <= size)
2029 (*it).second.m_rlcTransmissionQueueSize = 0;
2034 (*it).second.m_rlcTransmissionQueueSize -= size;
2040 NS_LOG_ERROR (
this <<
" Does not find DL RLC Buffer Report of UE " << rnti);
2045 TdTbfqFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2049 std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2050 if (it != m_ceBsrRxed.end ())
2052 NS_LOG_INFO (
this <<
" UE " << rnti <<
" size " << size <<
" BSR " << (*it).second);
2053 if ((*it).second >= size)
2055 (*it).second -= size;
2064 NS_LOG_ERROR (
this <<
" Does not find BSR report info of UE " << rnti);
2070 TdTbfqFfMacScheduler::TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode)
2072 NS_LOG_FUNCTION (
this <<
" RNTI " << rnti <<
" txMode " << (uint16_t)txMode);
2073 FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params;
2074 params.m_rnti = rnti;
2075 params.m_transmissionMode = txMode;
2076 m_cschedSapUser->CschedUeConfigUpdateInd (params);
#define NS_LOG_FUNCTION(parameters)
virtual void DoDispose(void)
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
#define NS_ASSERT(condition)
virtual ~TdTbfqFfMacScheduler()
Hold a signed integer type.
#define NS_LOG_COMPONENT_DEFINE(name)
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
See section 4.3.10 buildRARListElement.
Implements the SCHED SAP and CSCHED SAP for a Time Domain Token Bank Fair Queue scheduler.
#define NS_FATAL_ERROR(msg)
fatal error handling
TdTbfqFfMacScheduler()
Constructor.
Hold an unsigned integer type.
#define NS_LOG_LOGIC(msg)
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters ¶ms)
CSCHED_CELL_CONFIG_REQ.
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
#define NS_ASSERT_MSG(condition, message)
#define NS_LOG_DEBUG(msg)
#define NS_LOG_ERROR(msg)
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)