23 #include <ns3/pointer.h>
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>
37 int TdBetType0AllocationRbg[4] = {
45 NS_OBJECT_ENSURE_REGISTERED (TdBetFfMacScheduler);
66 TdBetSchedulerMemberCschedSapProvider::TdBetSchedulerMemberCschedSapProvider ()
70 TdBetSchedulerMemberCschedSapProvider::TdBetSchedulerMemberCschedSapProvider (TdBetFfMacScheduler* scheduler) : m_scheduler (scheduler)
78 m_scheduler->DoCschedCellConfigReq (params);
82 TdBetSchedulerMemberCschedSapProvider::CschedUeConfigReq (
const struct CschedUeConfigReqParameters& params)
84 m_scheduler->DoCschedUeConfigReq (params);
89 TdBetSchedulerMemberCschedSapProvider::CschedLcConfigReq (
const struct CschedLcConfigReqParameters& params)
91 m_scheduler->DoCschedLcConfigReq (params);
95 TdBetSchedulerMemberCschedSapProvider::CschedLcReleaseReq (
const struct CschedLcReleaseReqParameters& params)
97 m_scheduler->DoCschedLcReleaseReq (params);
101 TdBetSchedulerMemberCschedSapProvider::CschedUeReleaseReq (
const struct CschedUeReleaseReqParameters& params)
103 m_scheduler->DoCschedUeReleaseReq (params);
135 TdBetSchedulerMemberSchedSapProvider::TdBetSchedulerMemberSchedSapProvider ()
140 TdBetSchedulerMemberSchedSapProvider::TdBetSchedulerMemberSchedSapProvider (TdBetFfMacScheduler* scheduler)
141 : m_scheduler (scheduler)
146 TdBetSchedulerMemberSchedSapProvider::SchedDlRlcBufferReq (
const struct SchedDlRlcBufferReqParameters& params)
148 m_scheduler->DoSchedDlRlcBufferReq (params);
152 TdBetSchedulerMemberSchedSapProvider::SchedDlPagingBufferReq (
const struct SchedDlPagingBufferReqParameters& params)
154 m_scheduler->DoSchedDlPagingBufferReq (params);
158 TdBetSchedulerMemberSchedSapProvider::SchedDlMacBufferReq (
const struct SchedDlMacBufferReqParameters& params)
160 m_scheduler->DoSchedDlMacBufferReq (params);
164 TdBetSchedulerMemberSchedSapProvider::SchedDlTriggerReq (
const struct SchedDlTriggerReqParameters& params)
166 m_scheduler->DoSchedDlTriggerReq (params);
170 TdBetSchedulerMemberSchedSapProvider::SchedDlRachInfoReq (
const struct SchedDlRachInfoReqParameters& params)
172 m_scheduler->DoSchedDlRachInfoReq (params);
176 TdBetSchedulerMemberSchedSapProvider::SchedDlCqiInfoReq (
const struct SchedDlCqiInfoReqParameters& params)
178 m_scheduler->DoSchedDlCqiInfoReq (params);
182 TdBetSchedulerMemberSchedSapProvider::SchedUlTriggerReq (
const struct SchedUlTriggerReqParameters& params)
184 m_scheduler->DoSchedUlTriggerReq (params);
188 TdBetSchedulerMemberSchedSapProvider::SchedUlNoiseInterferenceReq (
const struct SchedUlNoiseInterferenceReqParameters& params)
190 m_scheduler->DoSchedUlNoiseInterferenceReq (params);
194 TdBetSchedulerMemberSchedSapProvider::SchedUlSrInfoReq (
const struct SchedUlSrInfoReqParameters& params)
196 m_scheduler->DoSchedUlSrInfoReq (params);
200 TdBetSchedulerMemberSchedSapProvider::SchedUlMacCtrlInfoReq (
const struct SchedUlMacCtrlInfoReqParameters& params)
202 m_scheduler->DoSchedUlMacCtrlInfoReq (params);
206 TdBetSchedulerMemberSchedSapProvider::SchedUlCqiInfoReq (
const struct SchedUlCqiInfoReqParameters& params)
208 m_scheduler->DoSchedUlCqiInfoReq (params);
216 : m_cschedSapUser (0),
221 m_amc = CreateObject <LteAmc> ();
235 m_dlHarqProcessesDciBuffer.clear ();
236 m_dlHarqProcessesTimer.clear ();
237 m_dlHarqProcessesRlcPduListBuffer.clear ();
238 m_dlInfoListBuffered.clear ();
239 m_ulHarqCurrentProcessId.clear ();
240 m_ulHarqProcessesStatus.clear ();
241 m_ulHarqProcessesDciBuffer.clear ();
242 delete m_cschedSapProvider;
243 delete m_schedSapProvider;
247 TdBetFfMacScheduler::GetTypeId (
void)
251 .AddConstructor<TdBetFfMacScheduler> ()
252 .AddAttribute (
"CqiTimerThreshold",
253 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
255 MakeUintegerAccessor (&TdBetFfMacScheduler::m_cqiTimersThreshold),
256 MakeUintegerChecker<uint32_t> ())
257 .AddAttribute (
"HarqEnabled",
258 "Activate/Deactivate the HARQ [by default is active].",
261 MakeBooleanChecker ())
262 .AddAttribute (
"UlGrantMcs",
263 "The MCS of the UL grant, must be [0..15] (default 0)",
265 MakeUintegerAccessor (&TdBetFfMacScheduler::m_ulGrantMcs),
266 MakeUintegerChecker<uint8_t> ())
288 return m_cschedSapProvider;
294 return m_schedSapProvider;
302 m_cschedCellConfig = params;
303 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
305 cnf.m_result = SUCCESS;
306 m_cschedSapUser->CschedUeConfigCnf (cnf);
311 TdBetFfMacScheduler::DoCschedUeConfigReq (
const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
313 NS_LOG_FUNCTION (
this <<
" RNTI " << params.m_rnti <<
" txMode " << (uint16_t)params.m_transmissionMode);
314 std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
315 if (it == m_uesTxMode.end ())
317 m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
319 m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
320 DlHarqProcessesStatus_t dlHarqPrcStatus;
321 dlHarqPrcStatus.resize (8,0);
322 m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
323 DlHarqProcessesTimer_t dlHarqProcessesTimer;
324 dlHarqProcessesTimer.resize (8,0);
325 m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
326 DlHarqProcessesDciBuffer_t dlHarqdci;
327 dlHarqdci.resize (8);
328 m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
329 DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
330 dlHarqRlcPdu.resize (2);
331 dlHarqRlcPdu.at (0).resize (8);
332 dlHarqRlcPdu.at (1).resize (8);
333 m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
334 m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
335 UlHarqProcessesStatus_t ulHarqPrcStatus;
336 ulHarqPrcStatus.resize (8,0);
337 m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
338 UlHarqProcessesDciBuffer_t ulHarqdci;
339 ulHarqdci.resize (8);
340 m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
344 (*it).second = params.m_transmissionMode;
350 TdBetFfMacScheduler::DoCschedLcConfigReq (
const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
354 std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
355 for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
357 it = m_flowStatsDl.find (params.m_rnti);
359 if (it == m_flowStatsDl.end ())
361 tdbetsFlowPerf_t flowStatsDl;
363 flowStatsDl.totalBytesTransmitted = 0;
364 flowStatsDl.lastTtiBytesTrasmitted = 0;
365 flowStatsDl.lastAveragedThroughput = 1;
366 m_flowStatsDl.insert (std::pair<uint16_t, tdbetsFlowPerf_t> (params.m_rnti, flowStatsDl));
367 tdbetsFlowPerf_t flowStatsUl;
369 flowStatsUl.totalBytesTransmitted = 0;
370 flowStatsUl.lastTtiBytesTrasmitted = 0;
371 flowStatsUl.lastAveragedThroughput = 1;
372 m_flowStatsUl.insert (std::pair<uint16_t, tdbetsFlowPerf_t> (params.m_rnti, flowStatsUl));
384 TdBetFfMacScheduler::DoCschedLcReleaseReq (
const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters& params)
387 for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
389 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
390 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
391 while (it!=m_rlcBufferReq.end ())
393 if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
397 m_rlcBufferReq.erase (temp);
409 TdBetFfMacScheduler::DoCschedUeReleaseReq (
const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters& params)
413 m_uesTxMode.erase (params.m_rnti);
414 m_dlHarqCurrentProcessId.erase (params.m_rnti);
415 m_dlHarqProcessesStatus.erase (params.m_rnti);
416 m_dlHarqProcessesTimer.erase (params.m_rnti);
417 m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
418 m_dlHarqProcessesRlcPduListBuffer.erase (params.m_rnti);
419 m_ulHarqCurrentProcessId.erase (params.m_rnti);
420 m_ulHarqProcessesStatus.erase (params.m_rnti);
421 m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
422 m_flowStatsDl.erase (params.m_rnti);
423 m_flowStatsUl.erase (params.m_rnti);
424 m_ceBsrRxed.erase (params.m_rnti);
425 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
426 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
427 while (it!=m_rlcBufferReq.end ())
429 if ((*it).first.m_rnti == params.m_rnti)
433 m_rlcBufferReq.erase (temp);
440 if (m_nextRntiUl == params.m_rnti)
450 TdBetFfMacScheduler::DoSchedDlRlcBufferReq (
const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters& params)
452 NS_LOG_FUNCTION (
this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
455 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
457 LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
459 it = m_rlcBufferReq.find (flow);
461 if (it == m_rlcBufferReq.end ())
463 m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
467 (*it).second = params;
474 TdBetFfMacScheduler::DoSchedDlPagingBufferReq (
const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters& params)
482 TdBetFfMacScheduler::DoSchedDlMacBufferReq (
const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters& params)
490 TdBetFfMacScheduler::GetRbgSize (
int dlbandwidth)
492 for (
int i = 0; i < 4; i++)
494 if (dlbandwidth < TdBetType0AllocationRbg[i])
505 TdBetFfMacScheduler::LcActivePerFlow (uint16_t rnti)
507 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
509 for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
511 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
512 || ((*it).second.m_rlcRetransmissionQueueSize > 0)
513 || ((*it).second.m_rlcStatusPduSize > 0) ))
517 if ((*it).first.m_rnti > rnti)
532 std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
533 if (it == m_dlHarqCurrentProcessId.end ())
537 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
538 if (itStat == m_dlHarqProcessesStatus.end ())
540 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
542 uint8_t i = (*it).second;
545 i = (i + 1) % HARQ_PROC_NUM;
547 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
548 if ((*itStat).second.at (i) == 0)
571 std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
572 if (it == m_dlHarqCurrentProcessId.end ())
576 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
577 if (itStat == m_dlHarqProcessesStatus.end ())
579 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
581 uint8_t i = (*it).second;
584 i = (i + 1) % HARQ_PROC_NUM;
586 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
587 if ((*itStat).second.at (i) == 0)
590 (*itStat).second.at (i) = 1;
594 NS_FATAL_ERROR (
"No HARQ process available for RNTI " << rnti <<
" check before update with HarqProcessAvailability");
597 return ((*it).second);
606 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
607 for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
609 for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
611 if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
615 NS_LOG_DEBUG (
this <<
" Reset HARQ proc " << i <<
" for RNTI " << (*itTimers).first);
616 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
617 if (itStat == m_dlHarqProcessesStatus.end ())
619 NS_FATAL_ERROR (
"No Process Id Status found for this RNTI " << (*itTimers).first);
621 (*itStat).second.at (i) = 0;
622 (*itTimers).second.at (i) = 0;
626 (*itTimers).second.at (i)++;
637 NS_LOG_FUNCTION (
this <<
" Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf));
647 int rbgSize = GetRbgSize (m_cschedCellConfig.m_dlBandwidth);
648 int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
649 std::map <uint16_t, std::vector <uint16_t> > allocationMap;
650 std::vector <bool> rbgMap;
651 uint16_t rbgAllocatedNum = 0;
652 std::set <uint16_t> rntiAllocated;
653 rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize,
false);
657 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
658 uint16_t rbStart = 0;
659 std::vector <struct RachListElement_s>::iterator itRach;
660 for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
662 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");
664 newRar.m_rnti = (*itRach).m_rnti;
668 newRar.m_grant.m_rnti = newRar.m_rnti;
669 newRar.m_grant.m_mcs = m_ulGrantMcs;
671 uint16_t tbSizeBits = 0;
673 while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
676 tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
678 if (tbSizeBits < (*itRach).m_estimatedSize)
683 newRar.m_grant.m_rbStart = rbStart;
684 newRar.m_grant.m_rbLen = rbLen;
685 newRar.m_grant.m_tbSize = tbSizeBits / 8;
686 newRar.m_grant.m_hopping =
false;
687 newRar.m_grant.m_tpc = 0;
688 newRar.m_grant.m_cqiRequest =
false;
689 newRar.m_grant.m_ulDelay =
false;
690 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);
691 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
693 m_rachAllocationMap.at (i) = (*itRach).m_rnti;
695 rbStart = rbStart + rbLen;
697 ret.m_buildRarList.push_back (newRar);
705 if (m_dlInfoListBuffered.size () > 0)
707 if (params.m_dlInfoList.size () > 0)
709 NS_LOG_INFO (
this <<
" Received DL-HARQ feedback");
710 m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
715 if (params.m_dlInfoList.size () > 0)
717 m_dlInfoListBuffered = params.m_dlInfoList;
723 m_dlInfoListBuffered.clear ();
725 std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
726 for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
728 std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
729 if (itRnti != rntiAllocated.end ())
734 uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
735 std::vector <bool> retx;
736 NS_LOG_INFO (
this <<
" Processing DLHARQ feedback");
739 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
740 retx.push_back (
false);
744 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
745 retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
747 if (retx.at (0) || retx.at (1))
750 uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
751 uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
752 NS_LOG_INFO (
this <<
" HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
753 std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
754 if (itHarq == m_dlHarqProcessesDciBuffer.end ())
759 DlDciListElement_s dci = (*itHarq).second.at (harqId);
761 if (dci.m_rv.size () == 1)
763 rv = dci.m_rv.at (0);
767 rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
773 NS_LOG_INFO (
"Maximum number of retransmissions reached -> drop process");
774 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
775 if (it == m_dlHarqProcessesStatus.end ())
777 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
779 (*it).second.at (harqId) = 0;
780 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
781 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
783 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
785 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
787 (*itRlcPdu).second.at (k).at (harqId).clear ();
793 std::vector <int> dciRbg;
795 NS_LOG_INFO (
"Original RBGs " << dci.m_rbBitmap <<
" rnti " << dci.m_rnti);
796 for (
int j = 0; j < 32; j++)
798 if (((dci.m_rbBitmap & mask) >> j) == 1)
800 dciRbg.push_back (j);
806 for (uint8_t j = 0; j < dciRbg.size (); j++)
808 if (rbgMap.at (dciRbg.at (j)) ==
true)
818 for (uint8_t j = 0; j < dciRbg.size (); j++)
820 rbgMap.at (dciRbg.at (j)) =
true;
821 NS_LOG_INFO (
"RBG " << dciRbg.at (j) <<
" assigned");
825 NS_LOG_INFO (
this <<
" Send retx in the same RBGs");
831 uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
832 uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
833 std::vector <bool> rbgMapCopy = rbgMap;
834 while ((j < dciRbg.size ())&&(startRbg != rbgId))
836 if (rbgMapCopy.at (rbgId) ==
false)
838 rbgMapCopy.at (rbgId) =
true;
839 dciRbg.at (j) = rbgId;
844 if (j == dciRbg.size ())
847 uint32_t rbgMask = 0;
848 for (uint16_t k = 0; k < dciRbg.size (); k++)
850 rbgMask = rbgMask + (0x1 << dciRbg.at (k));
853 dci.m_rbBitmap = rbgMask;
855 NS_LOG_INFO (
this <<
" Move retx in RBGs " << dciRbg.size ());
860 dlInfoListUntxed.push_back (params.m_dlInfoList.at (i));
861 NS_LOG_INFO (
this <<
" No resource for this retx -> buffer it");
865 BuildDataListElement_s newEl;
866 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
867 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
869 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
871 for (uint8_t j = 0; j < nLayers; j++)
875 if (j >= dci.m_ndi.size ())
878 dci.m_ndi.push_back (0);
879 dci.m_rv.push_back (0);
880 dci.m_mcs.push_back (0);
881 dci.m_tbsSize.push_back (0);
882 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no txed (MIMO transition)");
886 dci.m_ndi.at (j) = 0;
888 (*itHarq).second.at (harqId).m_rv.at (j)++;
889 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" RV " << (uint16_t)dci.m_rv.at (j));
895 dci.m_ndi.at (j) = 0;
897 dci.m_mcs.at (j) = 0;
898 dci.m_tbsSize.at (j) = 0;
899 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no retx");
902 for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
904 std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
905 for (uint8_t j = 0; j < nLayers; j++)
909 if (j < dci.m_ndi.size ())
911 rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
916 if (rlcPduListPerLc.size () > 0)
918 newEl.m_rlcPduList.push_back (rlcPduListPerLc);
923 (*itHarq).second.at (harqId).m_rv = dci.m_rv;
925 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
926 if (itHarqTimer== m_dlHarqProcessesTimer.end ())
928 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
930 (*itHarqTimer).second.at (harqId) = 0;
931 ret.m_buildDataList.push_back (newEl);
932 rntiAllocated.insert (rnti);
937 NS_LOG_INFO (
this <<
" HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
938 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
939 if (it == m_dlHarqProcessesStatus.end ())
941 NS_FATAL_ERROR (
"No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
943 (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
944 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
945 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
947 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
949 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
951 (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
955 m_dlInfoListBuffered.clear ();
956 m_dlInfoListBuffered = dlInfoListUntxed;
959 std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
960 std::map <uint16_t, tdbetsFlowPerf_t>::iterator itMax = m_flowStatsDl.end ();
961 double metricMax = 0.0;
962 for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
964 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
968 if (itRnti != rntiAllocated.end ())
970 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ tx" << (uint16_t)(*it).first);
974 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ id" << (uint16_t)(*it).first);
979 double metric = 1 / (*it).second.lastAveragedThroughput;
981 if (metric > metricMax)
989 if (itMax == m_flowStatsDl.end ())
997 std::vector <uint16_t> tempMap;
998 for (
int i = 0; i < rbgNum; i++)
1000 tempMap.push_back (i);
1002 allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax).first, tempMap));
1007 std::map <uint16_t, tdbetsFlowPerf_t>::iterator itStats;
1008 for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1010 (*itStats).second.lastTtiBytesTrasmitted = 0;
1015 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1016 while (itMap != allocationMap.end ())
1019 BuildDataListElement_s newEl;
1020 newEl.m_rnti = (*itMap).first;
1022 DlDciListElement_s newDci;
1023 newDci.m_rnti = (*itMap).first;
1026 uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1027 NS_LOG_INFO (
this <<
"Allocate user " << newEl.m_rnti <<
" rbg " << lcActives);
1028 uint16_t RgbPerRnti = (*itMap).second.size ();
1029 std::map <uint16_t,uint8_t>::iterator itCqi;
1030 itCqi = m_p10CqiRxed.find ((*itMap).first);
1031 std::map <uint16_t,uint8_t>::iterator itTxMode;
1032 itTxMode = m_uesTxMode.find ((*itMap).first);
1033 if (itTxMode == m_uesTxMode.end ())
1035 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*itMap).first);
1037 int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1039 uint32_t bytesTxed = 0;
1040 for (uint8_t j = 0; j < nLayer; j++)
1042 if (itCqi == m_p10CqiRxed.end ())
1044 newDci.m_mcs.push_back (0);
1048 newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
1051 int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (j), RgbPerRnti * rbgSize) / 8);
1052 newDci.m_tbsSize.push_back (tbSize);
1053 bytesTxed += tbSize;
1056 newDci.m_resAlloc = 0;
1057 newDci.m_rbBitmap = 0;
1058 uint32_t rbgMask = 0;
1059 for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1061 rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1062 NS_LOG_INFO (
this <<
" Allocated RBG " << (*itMap).second.at (k));
1064 newDci.m_rbBitmap = rbgMask;
1067 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1068 for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1070 if (((*itBufReq).first.m_rnti == (*itMap).first)
1071 && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1072 || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1073 || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1075 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1076 for (uint8_t j = 0; j < nLayer; j++)
1078 RlcPduListElement_s newRlcEl;
1079 newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1080 newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1081 NS_LOG_INFO (
this <<
" LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity <<
" size " << newRlcEl.m_size <<
" layer " << (uint16_t)j);
1082 newRlcPduLe.push_back (newRlcEl);
1083 UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1087 std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1088 if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1090 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1092 (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1095 newEl.m_rlcPduList.push_back (newRlcPduLe);
1097 if ((*itBufReq).first.m_rnti > (*itMap).first)
1102 for (uint8_t j = 0; j < nLayer; j++)
1104 newDci.m_ndi.push_back (1);
1105 newDci.m_rv.push_back (0);
1108 newEl.m_dci = newDci;
1113 std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1114 if (itDci == m_dlHarqProcessesDciBuffer.end ())
1116 NS_FATAL_ERROR (
"Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1118 (*itDci).second.at (newDci.m_harqProcess) = newDci;
1120 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1121 if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1123 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1125 (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1130 ret.m_buildDataList.push_back (newEl);
1132 std::map <uint16_t, tdbetsFlowPerf_t>::iterator it;
1133 it = m_flowStatsDl.find ((*itMap).first);
1134 if (it != m_flowStatsDl.end ())
1136 (*it).second.lastTtiBytesTrasmitted = bytesTxed;
1137 NS_LOG_INFO (
this <<
" UE total bytes txed " << (*it).second.lastTtiBytesTrasmitted);
1148 ret.m_nrOfPdcchOfdmSymbols = 1;
1153 for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1155 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1157 (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1158 NS_LOG_INFO (
this <<
" UE total bytes " << (*itStats).second.totalBytesTransmitted);
1159 NS_LOG_INFO (
this <<
" UE average throughput " << (*itStats).second.lastAveragedThroughput);
1160 (*itStats).second.lastTtiBytesTrasmitted = 0;
1163 m_schedSapUser->SchedDlConfigInd (ret);
1170 TdBetFfMacScheduler::DoSchedDlRachInfoReq (
const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters& params)
1174 m_rachList = params.m_rachList;
1180 TdBetFfMacScheduler::DoSchedDlCqiInfoReq (
const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters& params)
1184 for (
unsigned int i = 0; i < params.m_cqiList.size (); i++)
1186 if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1189 std::map <uint16_t,uint8_t>::iterator it;
1190 uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1191 it = m_p10CqiRxed.find (rnti);
1192 if (it == m_p10CqiRxed.end ())
1195 m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.m_cqiList.at (i).m_wbCqi.at (0)) );
1197 m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1202 (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1204 std::map <uint16_t,uint32_t>::iterator itTimers;
1205 itTimers = m_p10CqiTimers.find (rnti);
1206 (*itTimers).second = m_cqiTimersThreshold;
1209 else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1212 std::map <uint16_t,SbMeasResult_s>::iterator it;
1213 uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1214 it = m_a30CqiRxed.find (rnti);
1215 if (it == m_a30CqiRxed.end ())
1218 m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1219 m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1224 (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1225 std::map <uint16_t,uint32_t>::iterator itTimers;
1226 itTimers = m_a30CqiTimers.find (rnti);
1227 (*itTimers).second = m_cqiTimersThreshold;
1241 TdBetFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1243 std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1244 if (itCqi == m_ueCqi.end ())
1255 for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1257 double sinr = (*itCqi).second.at (i);
1258 if (sinr != NO_SINR)
1264 double estimatedSinr = sinrSum / (double)sinrNum;
1266 (*itCqi).second.at (rb) = estimatedSinr;
1267 return (estimatedSinr);
1272 TdBetFfMacScheduler::DoSchedUlTriggerReq (
const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
1274 NS_LOG_FUNCTION (
this <<
" UL - Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf) <<
" size " << params.m_ulInfoList.size ());
1276 RefreshUlCqiMaps ();
1279 FfMacSchedSapUser::SchedUlConfigIndParameters ret;
1280 std::vector <bool> rbMap;
1281 uint16_t rbAllocatedNum = 0;
1282 std::set <uint16_t> rntiAllocated;
1283 std::vector <uint16_t> rbgAllocationMap;
1285 rbgAllocationMap = m_rachAllocationMap;
1287 m_rachAllocationMap.clear ();
1288 m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1290 rbMap.resize (m_cschedCellConfig.m_ulBandwidth,
false);
1292 for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1294 if (rbgAllocationMap.at (i) != 0)
1296 rbMap.at (i) =
true;
1306 std::map <uint16_t, uint8_t>::iterator itProcId;
1307 for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
1309 (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
1312 for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1314 if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1317 uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1318 itProcId = m_ulHarqCurrentProcessId.find (rnti);
1319 if (itProcId == m_ulHarqCurrentProcessId.end ())
1321 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1323 uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1324 NS_LOG_INFO (
this <<
" UL-HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId <<
" i " << i <<
" size " << params.m_ulInfoList.size ());
1325 std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1326 if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1328 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1331 UlDciListElement_s dci = (*itHarq).second.at (harqId);
1332 std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1333 if (itStat == m_ulHarqProcessesStatus.end ())
1335 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1337 if ((*itStat).second.at (harqId) >= 3)
1339 NS_LOG_INFO (
"Max number of retransmissions reached (UL)-> drop process");
1343 for (
int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1345 if (rbMap.at (j) ==
true)
1354 for (
int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1356 rbMap.at (j) =
true;
1357 rbgAllocationMap.at (j) = dci.m_rnti;
1361 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);
1365 NS_LOG_INFO (
"Cannot allocate retx due to RACH allocations for UE " << rnti);
1370 (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1371 (*itStat).second.at (harqId) = 0;
1372 (*itHarq).second.at ((*itProcId).second) = dci;
1373 ret.m_dciList.push_back (dci);
1374 rntiAllocated.insert (dci.m_rnti);
1378 NS_LOG_INFO (
this <<
" HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1383 std::map <uint16_t,uint32_t>::iterator it;
1386 for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1388 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1390 if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1398 if (ret.m_dciList.size () > 0)
1400 m_schedSapUser->SchedUlConfigInd (ret);
1408 uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1413 int rbAllocated = 0;
1415 std::map <uint16_t, tdbetsFlowPerf_t>::iterator itStats;
1416 if (m_nextRntiUl != 0)
1418 for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1420 if ((*it).first == m_nextRntiUl)
1425 if (it == m_ceBsrRxed.end ())
1432 it = m_ceBsrRxed.begin ();
1433 m_nextRntiUl = (*it).first;
1437 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1438 if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1442 if (it == m_ceBsrRxed.end ())
1445 it = m_ceBsrRxed.begin ();
1449 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1452 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1461 UlDciListElement_s uldci;
1462 uldci.m_rnti = (*it).first;
1463 uldci.m_rbLen = rbPerFlow;
1464 bool allocated =
false;
1465 NS_LOG_INFO (
this <<
" RB Allocated " << rbAllocated <<
" rbPerFlow " << rbPerFlow);
1466 while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0))
1470 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1472 if (rbMap.at (j) ==
true)
1480 uldci.m_rbStart = rbAllocated;
1482 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1484 rbMap.at (j) =
true;
1486 rbgAllocationMap.at (j) = (*it).first;
1488 rbAllocated += rbPerFlow;
1493 if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1496 rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1508 m_nextRntiUl = (*it).first;
1509 if (ret.m_dciList.size () > 0)
1511 m_schedSapUser->SchedUlConfigInd (ret);
1513 m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1519 std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1521 if (itCqi == m_ueCqi.end ())
1529 double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1530 if (minSinr == NO_SINR)
1532 minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1534 for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1536 double sinr = (*itCqi).second.at (i);
1537 if (sinr == NO_SINR)
1539 sinr = EstimateUlSinr ((*it).first, i);
1541 if ((*itCqi).second.at (i) < minSinr)
1543 minSinr = (*itCqi).second.at (i);
1548 double s = log2 ( 1 + (
1549 pow (10, minSinr / 10 ) /
1550 ( (-log (5.0 * 0.00005 )) / 1.5) ));
1551 cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1555 if (it == m_ceBsrRxed.end ())
1558 it = m_ceBsrRxed.begin ();
1562 uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1565 uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1566 UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1568 uldci.m_cceIndex = 0;
1569 uldci.m_aggrLevel = 1;
1570 uldci.m_ueTxAntennaSelection = 3;
1571 uldci.m_hopping =
false;
1574 uldci.m_cqiRequest =
false;
1575 uldci.m_ulIndex = 0;
1577 uldci.m_freqHopping = 0;
1578 uldci.m_pdcchPowerOffset = 0;
1579 ret.m_dciList.push_back (uldci);
1584 std::map <uint16_t, uint8_t>::iterator itProcId;
1585 itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1586 if (itProcId == m_ulHarqCurrentProcessId.end ())
1588 NS_FATAL_ERROR (
"No info find in HARQ buffer for UE " << uldci.m_rnti);
1590 harqId = (*itProcId).second;
1591 std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1592 if (itDci == m_ulHarqProcessesDciBuffer.end ())
1594 NS_FATAL_ERROR (
"Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1596 (*itDci).second.at (harqId) = uldci;
1599 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);
1602 itStats = m_flowStatsUl.find ((*it).first);
1603 if (itStats != m_flowStatsUl.end ())
1605 (*itStats).second.lastTtiBytesTrasmitted = uldci.m_tbSize;
1609 NS_LOG_DEBUG (
this <<
" No Stats for this allocated UE");
1614 if (it == m_ceBsrRxed.end ())
1617 it = m_ceBsrRxed.begin ();
1619 if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1622 m_nextRntiUl = (*it).first;
1626 while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1631 for (itStats = m_flowStatsUl.begin (); itStats != m_flowStatsUl.end (); itStats++)
1633 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTrasmitted;
1635 (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 / m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 / m_timeWindow) * (double)((*itStats).second.lastTtiBytesTrasmitted / 0.001));
1636 NS_LOG_INFO (
this <<
" UE total bytes " << (*itStats).second.totalBytesTransmitted);
1637 NS_LOG_INFO (
this <<
" UE average throughput " << (*itStats).second.lastAveragedThroughput);
1638 (*itStats).second.lastTtiBytesTrasmitted = 0;
1640 m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1641 m_schedSapUser->SchedUlConfigInd (ret);
1647 TdBetFfMacScheduler::DoSchedUlNoiseInterferenceReq (
const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters& params)
1654 TdBetFfMacScheduler::DoSchedUlSrInfoReq (
const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters& params)
1661 TdBetFfMacScheduler::DoSchedUlMacCtrlInfoReq (
const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters& params)
1665 std::map <uint16_t,uint32_t>::iterator it;
1667 for (
unsigned int i = 0; i < params.m_macCeList.size (); i++)
1669 if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1678 uint32_t buffer = 0;
1679 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1681 uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1682 buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1685 uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1686 NS_LOG_LOGIC (
this <<
"RNTI=" << rnti <<
" buffer=" << buffer);
1687 it = m_ceBsrRxed.find (rnti);
1688 if (it == m_ceBsrRxed.end ())
1691 m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1696 (*it).second = buffer;
1705 TdBetFfMacScheduler::DoSchedUlCqiInfoReq (
const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
1709 switch (m_ulCqiFilter)
1711 case FfMacScheduler::SRS_UL_CQI:
1714 if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1720 case FfMacScheduler::PUSCH_UL_CQI:
1723 if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
1728 case FfMacScheduler::ALL_UL_CQI:
1735 switch (params.m_ulCqi.m_type)
1737 case UlCqi_s::PUSCH:
1739 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1740 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1741 NS_LOG_DEBUG (
this <<
" Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.m_sfnSf));
1742 itMap = m_allocationMaps.find (params.m_sfnSf);
1743 if (itMap == m_allocationMaps.end ())
1747 for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1750 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
1751 itCqi = m_ueCqi.find ((*itMap).second.at (i));
1752 if (itCqi == m_ueCqi.end ())
1755 std::vector <double> newCqi;
1756 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1760 newCqi.push_back (sinr);
1765 newCqi.push_back (NO_SINR);
1769 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1771 m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
1776 (*itCqi).second.at (i) = sinr;
1777 NS_LOG_DEBUG (
this <<
" RNTI " << (*itMap).second.at (i) <<
" RB " << i <<
" SINR " << sinr);
1779 std::map <uint16_t, uint32_t>::iterator itTimers;
1780 itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
1781 (*itTimers).second = m_cqiTimersThreshold;
1787 m_allocationMaps.erase (itMap);
1794 NS_ASSERT (params.m_vendorSpecificList.size () > 0);
1795 for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
1797 if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
1799 Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
1800 rnti = vsp->GetRnti ();
1803 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1804 itCqi = m_ueCqi.find (rnti);
1805 if (itCqi == m_ueCqi.end ())
1808 std::vector <double> newCqi;
1809 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1811 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1812 newCqi.push_back (sinr);
1813 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" new SRS-CQI for RB " << j <<
" value " << sinr);
1816 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1818 m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1823 for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
1825 double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
1826 (*itCqi).second.at (j) = sinr;
1827 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" update SRS-CQI for RB " << j <<
" value " << sinr);
1830 std::map <uint16_t, uint32_t>::iterator itTimers;
1831 itTimers = m_ueCqiTimers.find (rnti);
1832 (*itTimers).second = m_cqiTimersThreshold;
1839 case UlCqi_s::PUCCH_1:
1840 case UlCqi_s::PUCCH_2:
1841 case UlCqi_s::PRACH:
1843 NS_FATAL_ERROR (
"TdBetFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1853 TdBetFfMacScheduler::RefreshDlCqiMaps (
void)
1856 std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
1857 while (itP10 != m_p10CqiTimers.end ())
1859 NS_LOG_INFO (
this <<
" P10-CQI for user " << (*itP10).first <<
" is " << (uint32_t)(*itP10).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1860 if ((*itP10).second == 0)
1863 std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
1864 NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (),
" Does not find CQI report for user " << (*itP10).first);
1865 NS_LOG_INFO (
this <<
" P10-CQI expired for user " << (*itP10).first);
1866 m_p10CqiRxed.erase (itMap);
1867 std::map <uint16_t,uint32_t>::iterator temp = itP10;
1869 m_p10CqiTimers.erase (temp);
1879 std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
1880 while (itA30 != m_a30CqiTimers.end ())
1882 NS_LOG_INFO (
this <<
" A30-CQI for user " << (*itA30).first <<
" is " << (uint32_t)(*itA30).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1883 if ((*itA30).second == 0)
1886 std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
1887 NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (),
" Does not find CQI report for user " << (*itA30).first);
1888 NS_LOG_INFO (
this <<
" A30-CQI expired for user " << (*itA30).first);
1889 m_a30CqiRxed.erase (itMap);
1890 std::map <uint16_t,uint32_t>::iterator temp = itA30;
1892 m_a30CqiTimers.erase (temp);
1906 TdBetFfMacScheduler::RefreshUlCqiMaps (
void)
1909 std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
1910 while (itUl != m_ueCqiTimers.end ())
1912 NS_LOG_INFO (
this <<
" UL-CQI for user " << (*itUl).first <<
" is " << (uint32_t)(*itUl).second <<
" thr " << (uint32_t)m_cqiTimersThreshold);
1913 if ((*itUl).second == 0)
1916 std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
1917 NS_ASSERT_MSG (itMap != m_ueCqi.end (),
" Does not find CQI report for user " << (*itUl).first);
1918 NS_LOG_INFO (
this <<
" UL-CQI exired for user " << (*itUl).first);
1919 (*itMap).second.clear ();
1920 m_ueCqi.erase (itMap);
1921 std::map <uint16_t,uint32_t>::iterator temp = itUl;
1923 m_ueCqiTimers.erase (temp);
1936 TdBetFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
1938 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1939 LteFlowId_t flow (rnti, lcid);
1940 it = m_rlcBufferReq.find (flow);
1941 if (it != m_rlcBufferReq.end ())
1943 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);
1946 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
1948 (*it).second.m_rlcStatusPduSize = 0;
1950 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
1952 (*it).second.m_rlcRetransmissionQueueSize = 0;
1954 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
1957 if ((*it).second.m_rlcTransmissionQueueSize <= size)
1959 (*it).second.m_rlcTransmissionQueueSize = 0;
1964 (*it).second.m_rlcTransmissionQueueSize -= size;
1970 NS_LOG_ERROR (
this <<
" Does not find DL RLC Buffer Report of UE " << rnti);
1975 TdBetFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
1979 std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
1980 if (it != m_ceBsrRxed.end ())
1982 NS_LOG_INFO (
this <<
" UE " << rnti <<
" size " << size <<
" BSR " << (*it).second);
1983 if ((*it).second >= size)
1985 (*it).second -= size;
1994 NS_LOG_ERROR (
this <<
" Does not find BSR report info of UE " << rnti);
2000 TdBetFfMacScheduler::TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode)
2002 NS_LOG_FUNCTION (
this <<
" RNTI " << rnti <<
" txMode " << (uint16_t)txMode);
2003 FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params;
2004 params.m_rnti = rnti;
2005 params.m_transmissionMode = txMode;
2006 m_cschedSapUser->CschedUeConfigUpdateInd (params);
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
#define NS_LOG_FUNCTION(parameters)
#define NS_ASSERT(condition)
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
#define NS_LOG_COMPONENT_DEFINE(name)
TdBetFfMacScheduler()
Constructor.
See section 4.3.10 buildRARListElement.
#define NS_FATAL_ERROR(msg)
fatal error handling
Hold an unsigned integer type.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
#define NS_LOG_LOGIC(msg)
Implements the SCHED SAP and CSCHED SAP for a Time Domain Blind Equal Throughput scheduler.
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
virtual ~TdBetFfMacScheduler()
#define NS_ASSERT_MSG(condition, message)
#define NS_LOG_DEBUG(msg)
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters ¶ms)
CSCHED_CELL_CONFIG_REQ.
#define NS_LOG_ERROR(msg)
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
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)
virtual void DoDispose(void)