27 #include <ns3/pointer.h>
30 #include <ns3/simulator.h>
31 #include <ns3/lte-amc.h>
32 #include <ns3/cqa-ff-mac-scheduler.h>
33 #include <ns3/ff-mac-common.h>
34 #include <ns3/lte-vendor-specific-parameters.h>
35 #include <ns3/boolean.h>
39 #include <ns3/integer.h>
40 #include <ns3/string.h>
131 : m_cschedSapUser (0),
136 m_amc = CreateObject <LteAmc> ();
171 .AddAttribute (
"CqiTimerThreshold",
172 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
175 MakeUintegerChecker<uint32_t> ())
176 .AddAttribute (
"CqaMetric",
177 "CqaFfMacScheduler metric type that can be: CqaFf, CqaPf",
181 .AddAttribute (
"HarqEnabled",
182 "Activate/Deactivate the HARQ [by default is active].",
186 .AddAttribute (
"UlGrantMcs",
187 "The MCS of the UL grant, must be [0..15] (default 0)",
190 MakeUintegerChecker<uint8_t> ())
257 dlHarqPrcStatus.resize (8,0);
260 dlHarqProcessesTimer.resize (8,0);
263 dlHarqdci.resize (8);
266 dlHarqRlcPdu.resize (2);
267 dlHarqRlcPdu.at (0).resize (8);
268 dlHarqRlcPdu.at (1).resize (8);
272 ulHarqPrcStatus.resize (8,0);
275 ulHarqdci.resize (8);
295 std::vector <struct LogicalChannelConfigListElement_s>::const_iterator lcit;
303 NS_LOG_ERROR (
"UE logical channels can not be reconfigured because it was not configured before.");
314 std::vector <struct LogicalChannelConfigListElement_s>::const_iterator lcit;
324 std::map <uint16_t, CqasFlowPerf_t>::iterator it;
370 std::vector <uint8_t>::const_iterator it;
383 NS_FATAL_ERROR (
"Logical channels cannot be released because it can not be found in the list of active LCs");
389 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
390 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
435 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
436 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
439 if ((*it).first.m_rnti == params.
m_rnti)
465 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
473 m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
477 (*it).second = params;
502 for (
int i = 0; i < 4; i++)
517 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
518 unsigned int lcActive = 0;
521 if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
522 || ((*it).second.m_rlcRetransmissionQueueSize > 0)
523 || ((*it).second.m_rlcStatusPduSize > 0) ))
527 if ((*it).first.m_rnti > rnti)
550 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
552 uint8_t i = (*it).second;
557 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
558 if ((*itStat).second.at (i) == 0)
589 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
591 uint8_t i = (*it).second;
596 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
597 if ((*itStat).second.at (i) == 0)
600 (*itStat).second.at (i) = 1;
604 NS_FATAL_ERROR (
"No HARQ process available for RNTI " << rnti <<
" check before update with HarqProcessAvailability");
607 return ((*it).second);
616 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
625 NS_LOG_DEBUG (
this <<
" Reset HARQ proc " << i <<
" for RNTI " << (*itTimers).first);
626 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
m_dlHarqProcessesStatus.find ((*itTimers).first);
629 NS_FATAL_ERROR (
"No Process Id Status found for this RNTI " << (*itTimers).first);
631 (*itStat).second.at (i) = 0;
632 (*itTimers).second.at (i) = 0;
636 (*itTimers).second.at (i)++;
657 std::map <uint16_t, std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> > allocationMapPerRntiPerLCId;
658 std::map <uint16_t, std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> >::iterator itMap;
659 allocationMapPerRntiPerLCId.clear ();
663 int grouping_parameter = 1000;
664 double tolerance = 1.1;
665 std::map<LteFlowId_t,int> UEtoHOL;
666 std::vector <bool> rbgMap;
667 uint16_t rbgAllocatedNum = 0;
668 std::set <uint16_t> rntiAllocated;
672 for (std::vector<bool>::iterator it = rbgMap.begin (); it != rbgMap.end (); it++)
683 std::map <uint16_t, uint8_t>::iterator itProcId;
686 (*itProcId).second = ((*itProcId).second + 1) %
HARQ_PROC_NUM;
691 uint16_t rbAllocatedNum = 0;
692 std::vector <bool> ulRbMap;
695 uint8_t maxContinuousUlBandwidth = 0;
696 uint8_t tmpMinBandwidth = 0;
697 uint16_t ffrRbStartOffset = 0;
698 uint16_t tmpFfrRbStartOffset = 0;
701 for (std::vector<bool>::iterator it = ulRbMap.begin (); it != ulRbMap.end (); it++)
706 if (tmpMinBandwidth > maxContinuousUlBandwidth)
708 maxContinuousUlBandwidth = tmpMinBandwidth;
709 ffrRbStartOffset = tmpFfrRbStartOffset;
715 if (tmpMinBandwidth == 0)
717 tmpFfrRbStartOffset = index;
724 if (tmpMinBandwidth > maxContinuousUlBandwidth)
726 maxContinuousUlBandwidth = tmpMinBandwidth;
727 ffrRbStartOffset = tmpFfrRbStartOffset;
731 uint16_t rbStart = 0;
732 rbStart = ffrRbStartOffset;
733 std::vector <struct RachListElement_s>::iterator itRach;
738 newRar.
m_rnti = (*itRach).m_rnti;
745 uint16_t tbSizeBits = 0;
747 while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < (ffrRbStartOffset + maxContinuousUlBandwidth)))
752 if (tbSizeBits < (*itRach).m_estimatedSize)
764 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);
765 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
793 std::map <uint16_t, uint8_t>::iterator itProcId;
799 harqId = (*itProcId).second;
805 (*itDci).second.at (harqId) = uldci;
808 rbStart = rbStart + rbLen;
821 NS_LOG_INFO (
this <<
" Received DL-HARQ feedback");
837 std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
841 if (itRnti != rntiAllocated.end ())
847 std::vector <bool> retx;
848 NS_LOG_INFO (
this <<
" Processing DLHARQ feedback");
852 retx.push_back (
false);
859 if (retx.at (0) || retx.at (1))
864 NS_LOG_INFO (
this <<
" HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
873 if (dci.
m_rv.size () == 1)
875 rv = dci.
m_rv.at (0);
879 rv = (dci.
m_rv.at (0) > dci.
m_rv.at (1) ? dci.
m_rv.at (0) : dci.
m_rv.at (1));
885 NS_LOG_INFO (
"Maximum number of retransmissions reached -> drop process");
891 (*it).second.at (harqId) = 0;
897 for (uint16_t
k = 0;
k < (*itRlcPdu).second.size ();
k++)
899 (*itRlcPdu).second.at (
k).at (harqId).clear ();
905 std::vector <int> dciRbg;
908 for (
int j = 0; j < 32; j++)
912 dciRbg.push_back (j);
918 for (uint8_t j = 0; j < dciRbg.size (); j++)
920 if (rbgMap.at (dciRbg.at (j)) ==
true)
930 for (uint8_t j = 0; j < dciRbg.size (); j++)
932 rbgMap.at (dciRbg.at (j)) =
true;
933 NS_LOG_INFO (
"RBG " << dciRbg.at (j) <<
" assigned");
937 NS_LOG_INFO (
this <<
" Send retx in the same RBGs");
943 uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % numberOfRBGs;
944 uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
945 std::vector <bool> rbgMapCopy = rbgMap;
946 while ((j < dciRbg.size ())&&(startRbg != rbgId))
948 if (rbgMapCopy.at (rbgId) ==
false)
950 rbgMapCopy.at (rbgId) =
true;
951 dciRbg.at (j) = rbgId;
954 rbgId = (rbgId + 1) % numberOfRBGs;
956 if (j == dciRbg.size ())
959 uint32_t rbgMask = 0;
960 for (uint16_t
k = 0;
k < dciRbg.size ();
k++)
962 rbgMask = rbgMask + (0x1 << dciRbg.at (
k));
967 NS_LOG_INFO (
this <<
" Move retx in RBGs " << dciRbg.size ());
973 NS_LOG_INFO (
this <<
" No resource for this retx -> buffer it");
981 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
983 for (uint8_t j = 0; j < nLayers; j++)
987 if (j >= dci.
m_ndi.size ())
990 dci.
m_ndi.push_back (0);
991 dci.
m_rv.push_back (0);
992 dci.
m_mcs.push_back (0);
994 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no txed (MIMO transition)");
998 dci.
m_ndi.at (j) = 0;
1000 (*itHarq).second.at (harqId).m_rv.at (j)++;
1001 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" RV " << (uint16_t)dci.
m_rv.at (j));
1007 dci.
m_ndi.at (j) = 0;
1008 dci.
m_rv.at (j) = 0;
1009 dci.
m_mcs.at (j) = 0;
1011 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no retx");
1014 for (uint16_t
k = 0;
k < (*itRlcPdu).second.at (0).at (dci.
m_harqProcess).size ();
k++)
1016 std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
1017 for (uint8_t j = 0; j < nLayers; j++)
1021 if (j < dci.
m_ndi.size ())
1024 rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.
m_harqProcess).at (
k));
1033 rlcPduListPerLc.push_back (emptyElement);
1037 if (rlcPduListPerLc.size () > 0)
1044 (*itHarq).second.at (harqId).
m_rv = dci.
m_rv;
1049 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
1051 (*itHarqTimer).second.at (harqId) = 0;
1053 rntiAllocated.insert (rnti);
1070 for (uint16_t
k = 0;
k < (*itRlcPdu).second.size ();
k++)
1079 if (rbgAllocatedNum == numberOfRBGs)
1089 std::map <LteFlowId_t,struct LogicalChannelConfigListElement_s>::iterator itLogicalChannels;
1093 std::set <uint16_t>::iterator itRnti = rntiAllocated.find (itLogicalChannels->first.m_rnti);
1097 if (itRnti != rntiAllocated.end ())
1099 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ tx" << (uint16_t)(itLogicalChannels->first.m_rnti));
1103 NS_LOG_DEBUG (
this <<
" RNTI discared for HARQ id" << (uint16_t)(itLogicalChannels->first.m_rnti));
1109 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itRlcBufferReq =
m_rlcBufferReq.find (itLogicalChannels->first);
1116 if (itRlcBufferReq->second.m_rlcRetransmissionQueueSize > 0)
1118 delay = itRlcBufferReq->second.m_rlcRetransmissionHolDelay;
1119 group = delay/grouping_parameter;
1121 else if (itRlcBufferReq->second.m_rlcTransmissionQueueSize > 0)
1123 delay = itRlcBufferReq->second.m_rlcTransmissionQueueHolDelay;
1124 group = delay/grouping_parameter;
1131 UEtoHOL.insert (std::pair<LteFlowId_t,int>(itLogicalChannels->first,delay));
1133 if (itLogicalChannels->second.m_qosBearerType == itLogicalChannels->second.QBT_NON_GBR )
1135 if (map_nonGBRHOLgroupToUE.count (group)==0)
1137 std::set<LteFlowId_t> v;
1138 v.insert (itRlcBufferReq->first);
1139 map_nonGBRHOLgroupToUE.insert (std::pair<
int,std::set<LteFlowId_t> >(group,v));
1143 map_nonGBRHOLgroupToUE.find (group)->second.insert (itRlcBufferReq->first);
1146 else if (itLogicalChannels->second.m_qosBearerType == itLogicalChannels->second.QBT_GBR) {
1147 if (map_GBRHOLgroupToUE.count (group)==0)
1149 std::set<LteFlowId_t> v;
1150 v.insert (itRlcBufferReq->first);
1151 map_GBRHOLgroupToUE.insert (std::pair<
int,std::set<LteFlowId_t> >(group,v));
1155 map_GBRHOLgroupToUE.find (group)->second.insert (itRlcBufferReq->first);
1163 std::map<LteFlowId_t, int> UeToAmountOfDataToTransfer;
1165 std::map<LteFlowId_t, int> UeToAmountOfAssignedResources;
1167 std::map < uint16_t, uint8_t > sbCqiSum;
1169 for( std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itrbr =
m_rlcBufferReq.begin ();
1175 std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1177 std::map <uint16_t,uint8_t>::iterator itTxMode;
1178 itTxMode =
m_uesTxMode.find ((*itrbr).first.m_rnti);
1181 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*itrbr).first.m_rnti);
1186 for (
int k = 0;
k < numberOfRBGs;
k++)
1188 for (uint8_t j = 0; j < nLayer; j++)
1196 cqiSum += (*itCqi).second.m_higherLayerSelected.at (
k).m_sbCqi.at(j);
1203 NS_LOG_INFO (
"Skip this flow, CQI==0, rnti:"<<(*itrbr).first.m_rnti);
1208 int amountOfDataToTransfer = 8*((int)
m_rlcBufferReq.find (flowId)->second.m_rlcRetransmissionQueueSize +
1209 (int)
m_rlcBufferReq.find (flowId)->second.m_rlcTransmissionQueueSize);
1211 UeToAmountOfDataToTransfer.insert (std::pair<LteFlowId_t,int>(flowId,amountOfDataToTransfer));
1212 UeToAmountOfAssignedResources.insert (std::pair<LteFlowId_t,int>(flowId,0));
1215 for (
int i = 0; i < numberOfRBGs; i++)
1217 std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1219 std::map <uint16_t,uint8_t>::iterator itTxMode;
1220 itTxMode =
m_uesTxMode.find ((*itrbr).first.m_rnti);
1223 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*itrbr).first.m_rnti);
1226 std::vector <uint8_t> sbCqis;
1229 for (uint8_t
k = 0;
k < nLayer;
k++)
1231 sbCqis.push_back (1);
1236 sbCqis = (*itCqi).second.m_higherLayerSelected.at (i).m_sbCqi;
1239 uint8_t cqi1 = sbCqis.at (0);
1241 if (sbCqis.size () > 1)
1243 cqi2 = sbCqis.at (1);
1247 if ((cqi1 > 0)||(cqi2 > 0))
1249 for (uint8_t
k = 0;
k < nLayer;
k++)
1251 if (sbCqis.size () >
k)
1253 sbCqi = sbCqis.at (
k);
1265 sbCqiSum.insert (std::pair<uint16_t, uint8_t> ((*itrbr).first.m_rnti, sum));
1269 std::set<int> availableRBGs;
1270 for (
int i = 0; i < numberOfRBGs; i++)
1272 if (rbgMap.at (i) ==
false)
1274 availableRBGs.insert (i);
1284 while (availableRBGs.size ()>0)
1286 if (UeToAmountOfDataToTransfer.size() == 0)
1288 NS_LOG_INFO (
"No UEs to be scheduled (no data or CQI==0),");
1291 std::set<LteFlowId_t> vUEs;
1294 if (itGBRgroups!=map_GBRHOLgroupToUE.end ())
1296 itCurrentGroup=itGBRgroups;
1299 else if (itnonGBRgroups!=map_nonGBRHOLgroupToUE.end ())
1301 itCurrentGroup=itnonGBRgroups;
1306 NS_LOG_INFO (
"Available RBGs:"<< availableRBGs.size ()<<
"but no users");
1310 while (availableRBGs.size ()>0 and itCurrentGroup->second.size ()>0)
1312 bool currentRBchecked =
false;
1313 int currentRB = *(availableRBGs.begin ());
1314 std::map<LteFlowId_t, CQI_value> UeToCQIValue;
1315 std::map<LteFlowId_t, double > UeToCoitaMetric;
1316 std::map<LteFlowId_t, bool> UeHasReachedGBR;
1317 double maximumValueMetric = 0;
1319 UeToCQIValue.clear ();
1320 UeToCoitaMetric.clear ();
1323 for (std::set<LteFlowId_t>::iterator it=itCurrentGroup->second.begin (); it!=itCurrentGroup->second.end (); it++)
1326 uint8_t cqi_value = 1;
1327 double coita_metric = 1;
1328 double coita_sum = 0;
1330 uint8_t worstCQIAmongRBGsAllocatedForThisUser = 15;
1331 int numberOfRBGAllocatedForThisUser = 0;
1333 std::map <uint16_t,SbMeasResult_s>::iterator itRntiCQIsMap =
m_a30CqiRxed.find (flowId.
m_rnti);
1335 std::map <uint16_t, CqasFlowPerf_t>::iterator itStats;
1346 currentRBchecked =
true;
1349 double tbr_weight = (*itStats).second.targetThroughput / (*itStats).second.lastAveragedThroughput;
1350 if (tbr_weight < 1.0)
1355 for(std::set<int>::iterator it=availableRBGs.begin (); it!=availableRBGs.end (); it++)
1359 int val = (itRntiCQIsMap->second.m_higherLayerSelected.at (*it).m_sbCqi.at (0));
1362 if (*it == currentRB)
1367 catch(std::out_of_range&)
1374 coita_metric =cqi_value/coita_sum;
1375 UeToCQIValue.insert (std::pair<LteFlowId_t,CQI_value>(flowId,cqi_value));
1376 UeToCoitaMetric.insert (std::pair<LteFlowId_t, double>(flowId,coita_metric));
1379 if (allocationMapPerRntiPerLCId.find (flowId.
m_rnti)==allocationMapPerRntiPerLCId.end ())
1381 worstCQIAmongRBGsAllocatedForThisUser=cqi_value;
1385 numberOfRBGAllocatedForThisUser = (allocationMapPerRntiPerLCId.find (flowId.
m_rnti)->second.size ());
1387 for (std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc>::iterator itRBG = allocationMapPerRntiPerLCId.find (flowId.
m_rnti)->second.begin ();
1388 itRBG!=allocationMapPerRntiPerLCId.find (flowId.
m_rnti)->second.end (); itRBG++)
1395 if (cqi_value < worstCQIAmongRBGsAllocatedForThisUser)
1397 worstCQIAmongRBGsAllocatedForThisUser=cqi_value;
1401 int mcsForThisUser =
m_amc->GetMcsFromCqi (worstCQIAmongRBGsAllocatedForThisUser);
1402 int tbSize =
m_amc->GetDlTbSizeFromMcs (mcsForThisUser, (numberOfRBGAllocatedForThisUser+1) * rbgSize)/8;
1405 double achievableRate = ((
m_amc->GetDlTbSizeFromMcs (mcsForThisUser, rbgSize)/ 8) / 0.001);
1406 double pf_weight = achievableRate / (*itStats).second.secondLastAveragedThroughput;
1408 UeToAmountOfAssignedResources.find (flowId)->second = 8*tbSize;
1411 if (UeToAmountOfDataToTransfer.find (flowId)->second - UeToAmountOfAssignedResources.find (flowId)->second < 0)
1413 UeHasReachedGBR.insert (std::pair<LteFlowId_t,bool>(flowId,
false));
1416 double bitRateWithNewRBG = 0;
1424 bitRateWithNewRBG = (1.0 /
m_timeWindow) * (
double)(tbSize*1000);
1429 UeHasReachedGBR.insert (std::pair<LteFlowId_t,bool>(flowId,
true));
1433 UeHasReachedGBR.insert (std::pair<LteFlowId_t,bool>(flowId,
false));
1436 int hol = UEtoHOL.find (flowId)->second;
1443 metric = coita_metric*tbr_weight*hol;
1447 metric = tbr_weight*pf_weight*hol;
1454 if (metric >= maximumValueMetric)
1456 maximumValueMetric = metric;
1457 userWithMaximumMetric = flowId;
1461 if (!currentRBchecked)
1464 availableRBGs.erase (currentRB);
1472 itMap = allocationMapPerRntiPerLCId.find (userWithMaximumMetric.
m_rnti);
1474 if (itMap == allocationMapPerRntiPerLCId.end ())
1476 std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> tempMap;
1477 tempMap.insert (std::pair<uint8_t, qos_rb_and_CQI_assigned_to_lc> (userWithMaximumMetric.
m_lcId,s));
1478 allocationMapPerRntiPerLCId.insert (std::pair <uint16_t, std::multimap <uint8_t,qos_rb_and_CQI_assigned_to_lc> > (userWithMaximumMetric.
m_rnti, tempMap));
1482 itMap->second.insert (std::pair<uint8_t,qos_rb_and_CQI_assigned_to_lc> (userWithMaximumMetric.
m_lcId,s));
1486 availableRBGs.erase (currentRB);
1488 if (UeToAmountOfDataToTransfer.find (userWithMaximumMetric)->second <= UeToAmountOfAssignedResources.find (userWithMaximumMetric)->second*tolerance)
1491 itCurrentGroup->second.erase (userWithMaximumMetric);
1499 std::map <uint16_t, CqasFlowPerf_t>::iterator itStats;
1502 (*itStats).second.lastTtiBytesTransmitted = 0;
1507 itMap = allocationMapPerRntiPerLCId.begin ();
1509 std::map<uint16_t, double> m_rnti_per_ratio;
1511 while (itMap != allocationMapPerRntiPerLCId.end ())
1515 newEl.
m_rnti = (*itMap).first;
1519 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1520 newDci.
m_rnti = (*itMap).first;
1526 uint16_t RgbPerRnti = (*itMap).second.size ();
1527 double doubleRBgPerRnti = RgbPerRnti;
1528 double doubleRbgNum = numberOfRBGs;
1529 double rrRatio = doubleRBgPerRnti/doubleRbgNum;
1530 m_rnti_per_ratio.insert (std::pair<uint16_t,double>((*itMap).first,rrRatio));
1531 std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1533 uint8_t worstCqi = 15;
1536 for ( std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> ::iterator it = (*itMap).second.begin (); it != (*itMap).second.end (); it++)
1538 if (it->second.cqi_value_for_lc<worstCqi)
1540 worstCqi = it->second.cqi_value_for_lc;
1545 newDci.
m_mcs.push_back (
m_amc->GetMcsFromCqi (worstCqi));
1546 int tbSize = (
m_amc->GetDlTbSizeFromMcs (newDci.
m_mcs.at (0), RgbPerRnti * rbgSize) / 8);
1550 uint32_t rbgMask = 0;
1551 std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> ::iterator itRBGsPerRNTI;
1552 for ( itRBGsPerRNTI = (*itMap).second.begin (); itRBGsPerRNTI != (*itMap).second.end (); itRBGsPerRNTI++)
1554 rbgMask = rbgMask + (0x1 << itRBGsPerRNTI->second.resource_block_index);
1559 std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1562 if (((*itBufReq).first.m_rnti == (*itMap).first)
1563 && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1564 || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1565 || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1567 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1573 newRlcEl.
m_size = tbSize / lcActives;
1575 newRlcPduLe.push_back (newRlcEl);
1583 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1586 (*itRlcPdu).second.at (j).at (newDci.
m_harqProcess).push_back (newRlcEl);
1591 if ((*itBufReq).first.m_rnti > (*itMap).first)
1598 newDci.
m_ndi.push_back (1);
1599 newDci.
m_rv.push_back (0);
1604 newEl.
m_dci = newDci;
1628 std::map <uint16_t, CqasFlowPerf_t>::iterator it;
1632 (*it).second.lastTtiBytesTransmitted = tbSize;
1647 if (allocationMapPerRntiPerLCId.find (itStats->first)!= allocationMapPerRntiPerLCId.end ())
1649 (*itStats).second.secondLastAveragedThroughput = ((1.0 - (1 /
m_timeWindow)) * (*itStats).second.secondLastAveragedThroughput) + ((1 /
m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1652 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
1654 (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 /
m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 /
m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
1655 NS_LOG_INFO (
this <<
" UE total bytes " << (*itStats).second.totalBytesTransmitted);
1656 NS_LOG_INFO (
this <<
" UE average throughput " << (*itStats).second.lastAveragedThroughput);
1657 (*itStats).second.lastTtiBytesTransmitted = 0;
1662 int count_allocated_resource_blocks = 0;
1663 for (std::map <uint16_t, std::multimap <uint8_t, qos_rb_and_CQI_assigned_to_lc> >::iterator itMap = allocationMapPerRntiPerLCId.begin (); itMap!=allocationMapPerRntiPerLCId.end (); itMap++)
1665 count_allocated_resource_blocks+=itMap->second.size ();
1667 NS_LOG_INFO (
this <<
" Allocated RBs:" << count_allocated_resource_blocks);
1688 for (
unsigned int i = 0; i < params.
m_cqiList.size (); i++)
1693 std::map <uint16_t,uint8_t>::iterator it;
1694 uint16_t rnti = params.
m_cqiList.at (i).m_rnti;
1699 m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.
m_cqiList.at (i).m_wbCqi.at (0)) );
1706 (*it).second = params.
m_cqiList.at (i).m_wbCqi.at (0);
1708 std::map <uint16_t,uint32_t>::iterator itTimers;
1716 std::map <uint16_t,SbMeasResult_s>::iterator it;
1717 uint16_t rnti = params.
m_cqiList.at (i).m_rnti;
1722 m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.
m_cqiList.at (i).m_sbMeasResult) );
1728 (*it).second = params.
m_cqiList.at (i).m_sbMeasResult;
1729 std::map <uint16_t,uint32_t>::iterator itTimers;
1747 std::map <uint16_t, std::vector <double> >::iterator itCqi =
m_ueCqi.find (rnti);
1758 unsigned int sinrNum = 0;
1761 double sinr = (*itCqi).second.at (i);
1768 double estimatedSinr = (sinrNum > 0) ? (sinrSum / sinrNum) : DBL_MAX;
1770 (*itCqi).second.at (rb) = estimatedSinr;
1771 return (estimatedSinr);
1785 std::vector <bool> rbMap;
1786 uint16_t rbAllocatedNum = 0;
1787 std::set <uint16_t> rntiAllocated;
1788 std::vector <uint16_t> rbgAllocationMap;
1799 for (std::vector<bool>::iterator it = rbMap.begin (); it != rbMap.end (); it++)
1813 if (rbgAllocationMap.at (i) != 0)
1815 rbMap.at (i) =
true;
1824 for (uint16_t i = 0; i < params.
m_ulInfoList.size (); i++)
1833 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1836 NS_LOG_INFO (
this <<
" UL-HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId <<
" i " << i <<
" size " << params.
m_ulInfoList.size ());
1840 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1847 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1849 if ((*itStat).second.at (harqId) >= 3)
1851 NS_LOG_INFO (
"Max number of retransmissions reached (UL)-> drop process");
1858 if (rbMap.at (j) ==
true)
1869 rbMap.at (j) =
true;
1870 rbgAllocationMap.at (j) = dci.
m_rnti;
1878 NS_LOG_INFO (
"Cannot allocate retx due to RACH allocations for UE " << rnti);
1883 (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1884 (*itStat).second.at (harqId) = 0;
1885 (*itHarq).second.at ((*itProcId).second) = dci;
1887 rntiAllocated.insert (dci.
m_rnti);
1896 std::map <uint16_t,uint32_t>::iterator it;
1901 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1903 if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1922 uint16_t tempRbPerFlow = (ffrUlBandwidth) / (nflows + rntiAllocated.size ());
1923 uint16_t rbPerFlow = (minContinuousUlBandwidth < tempRbPerFlow) ? minContinuousUlBandwidth : tempRbPerFlow;
1929 int rbAllocated = 0;
1931 std::map <uint16_t, CqasFlowPerf_t>::iterator itStats;
1953 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1954 if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1957 NS_LOG_DEBUG (
this <<
" UE already allocated in HARQ -> discared, RNTI " << (*it).first);
1980 uldci.
m_rnti = (*it).first;
1982 bool allocated =
false;
1983 NS_LOG_INFO (
this <<
" RB Allocated " << rbAllocated <<
" rbPerFlow " << rbPerFlow <<
" flows " << nflows);
1988 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1990 if (rbMap.at (j) ==
true)
2003 NS_LOG_INFO (
this <<
"RNTI: "<< (*it).first<<
" RB Allocated " << rbAllocated <<
" rbPerFlow " << rbPerFlow <<
" flows " << nflows);
2006 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
2008 rbMap.at (j) =
true;
2010 rbgAllocationMap.at (j) = (*it).first;
2012 rbAllocated += rbPerFlow;
2044 std::map <uint16_t, std::vector <double> >::iterator itCqi =
m_ueCqi.find ((*it).first);
2054 NS_ABORT_MSG_IF ((*itCqi).second.size() == 0,
"CQI of RNTI = " << (*it).first <<
" has expired");
2055 double minSinr = (*itCqi).second.at (uldci.
m_rbStart);
2062 double sinr = (*itCqi).second.at (i);
2074 double s = log2 ( 1 + (
2075 std::pow (10, minSinr / 10 ) /
2076 ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
2077 cqi =
m_amc->GetCqiFromSpectralEfficiency (s);
2090 rbgAllocationMap.at (i) = 0;
2116 std::map <uint16_t, uint8_t>::iterator itProcId;
2122 harqId = (*itProcId).second;
2128 (*itDci).second.at (harqId) = uldci;
2133 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << uldci.
m_rnti);
2135 (*itStat).second.at (harqId) = 0;
2138 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);
2144 (*itStats).second.lastTtiBytesTransmitted = uldci.
m_tbSize;
2148 NS_LOG_DEBUG (
this <<
" No Stats for this allocated UE");
2172 (*itStats).second.totalBytesTransmitted += (*itStats).second.lastTtiBytesTransmitted;
2174 (*itStats).second.lastAveragedThroughput = ((1.0 - (1.0 /
m_timeWindow)) * (*itStats).second.lastAveragedThroughput) + ((1.0 /
m_timeWindow) * (double)((*itStats).second.lastTtiBytesTransmitted / 0.001));
2175 NS_LOG_INFO (
this <<
" UE total bytes " << (*itStats).second.totalBytesTransmitted);
2176 NS_LOG_INFO (
this <<
" UE average throughput " << (*itStats).second.lastAveragedThroughput);
2177 (*itStats).second.lastTtiBytesTransmitted = 0;
2204 std::map <uint16_t,uint32_t>::iterator it;
2206 for (
unsigned int i = 0; i < params.
m_macCeList.size (); i++)
2217 uint32_t buffer = 0;
2218 for (uint8_t lcg = 0; lcg < 4; ++lcg)
2220 uint8_t bsrId = params.
m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
2225 NS_LOG_LOGIC (
this <<
"RNTI=" << rnti <<
" buffer=" << buffer);
2230 m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
2235 (*it).second = buffer;
2272 switch (params.
m_ulCqi.m_type)
2276 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
2277 std::map <uint16_t, std::vector <double> >::iterator itCqi;
2278 NS_LOG_DEBUG (
this <<
" Collect PUSCH CQIs of Frame no. " << (params.
m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.
m_sfnSf));
2284 for (uint32_t i = 0; i < (*itMap).second.size (); i++)
2288 itCqi =
m_ueCqi.find ((*itMap).second.at (i));
2292 std::vector <double> newCqi;
2297 newCqi.push_back (sinr);
2306 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
2313 (*itCqi).second.at (i) = sinr;
2314 NS_LOG_DEBUG (
this <<
" RNTI " << (*itMap).second.at (i) <<
" RB " << i <<
" SINR " << sinr);
2316 std::map <uint16_t, uint32_t>::iterator itTimers;
2329 NS_LOG_DEBUG (
this <<
" Collect SRS CQIs of Frame no. " << (params.
m_sfnSf >> 4) <<
" subframe no. " << (0xF & params.
m_sfnSf));
2338 rnti = vsp->GetRnti ();
2341 std::map <uint16_t, std::vector <double> >::iterator itCqi;
2346 std::vector <double> newCqi;
2350 newCqi.push_back (sinr);
2351 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" new SRS-CQI for RB " << j <<
" value " << sinr);
2354 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
2364 (*itCqi).second.at (j) = sinr;
2365 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" update SRS-CQI for RB " << j <<
" value " << sinr);
2368 std::map <uint16_t, uint32_t>::iterator itTimers;
2381 NS_FATAL_ERROR (
"PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2394 std::map <uint16_t,uint32_t>::iterator itP10 =
m_p10CqiTimers.begin ();
2398 if ((*itP10).second == 0)
2401 std::map <uint16_t,uint8_t>::iterator itMap =
m_p10CqiRxed.find ((*itP10).first);
2403 NS_LOG_INFO (
this <<
" P10-CQI expired for user " << (*itP10).first);
2405 std::map <uint16_t,uint32_t>::iterator temp = itP10;
2417 std::map <uint16_t,uint32_t>::iterator itA30 =
m_a30CqiTimers.begin ();
2421 if ((*itA30).second == 0)
2424 std::map <uint16_t,SbMeasResult_s>::iterator itMap =
m_a30CqiRxed.find ((*itA30).first);
2426 NS_LOG_INFO (
this <<
" A30-CQI expired for user " << (*itA30).first);
2428 std::map <uint16_t,uint32_t>::iterator temp = itA30;
2447 std::map <uint16_t,uint32_t>::iterator itUl =
m_ueCqiTimers.begin ();
2451 if ((*itUl).second == 0)
2454 std::map <uint16_t, std::vector <double> >::iterator itMap =
m_ueCqi.find ((*itUl).first);
2455 NS_ASSERT_MSG (itMap !=
m_ueCqi.end (),
" Does not find CQI report for user " << (*itUl).first);
2456 NS_LOG_INFO (
this <<
" UL-CQI exired for user " << (*itUl).first);
2457 (*itMap).second.clear ();
2459 std::map <uint16_t,uint32_t>::iterator temp = itUl;
2476 std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2481 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);
2484 if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2486 (*it).second.m_rlcStatusPduSize = 0;
2488 else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2490 (*it).second.m_rlcRetransmissionQueueSize = 0;
2492 else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2494 uint32_t rlcOverhead;
2509 if ((*it).second.m_rlcTransmissionQueueSize <= size - rlcOverhead)
2511 (*it).second.m_rlcTransmissionQueueSize = 0;
2515 (*it).second.m_rlcTransmissionQueueSize -= size - rlcOverhead;
2521 NS_LOG_ERROR (
this <<
" Does not find DL RLC Buffer Report of UE " << rnti);
2530 std::map <uint16_t,uint32_t>::iterator it =
m_ceBsrRxed.find (rnti);
2533 NS_LOG_INFO (
this <<
" UE " << rnti <<
" size " << size <<
" BSR " << (*it).second);
2534 if ((*it).second >= size)
2536 (*it).second -= size;
2545 NS_LOG_ERROR (
this <<
" Does not find BSR report info of UE " << rnti);
2553 NS_LOG_FUNCTION (
this <<
" RNTI " << rnti <<
" txMode " << (uint16_t)txMode);