22 #include <ns3/pointer.h>
26 #include <ns3/lte-amc.h>
27 #include <ns3/rr-ff-mac-scheduler.h>
28 #include <ns3/simulator.h>
29 #include <ns3/lte-common.h>
30 #include <ns3/lte-vendor-specific-parameters.h>
31 #include <ns3/boolean.h>
142 : m_scheduler (scheduler)
217 : m_cschedSapUser (0),
222 m_amc = CreateObject <LteAmc> ();
252 .AddConstructor<RrFfMacScheduler> ()
253 .AddAttribute (
"CqiTimerThreshold",
254 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
257 MakeUintegerChecker<uint32_t> ())
258 .AddAttribute (
"HarqEnabled",
259 "Activate/Deactivate the HARQ [by default is active].",
262 MakeBooleanChecker ())
263 .AddAttribute (
"UlGrantMcs",
264 "The MCS of the UL grant, must be [0..15] (default 0)",
267 MakeUintegerChecker<uint8_t> ())
322 dlHarqPrcStatus.resize (8,0);
325 dlHarqProcessesTimer.resize (8,0);
328 dlHarqdci.resize (8);
331 dlHarqRlcPdu.resize (2);
332 dlHarqRlcPdu.at (0).resize (8);
333 dlHarqRlcPdu.at (1).resize (8);
337 ulHarqPrcStatus.resize (8,0);
340 ulHarqdci.resize (8);
364 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
395 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
398 if ((*it).m_rnti == params.
m_rnti)
400 NS_LOG_INFO (
this <<
" Erase RNTI " << (*it).m_rnti <<
" LC " << (uint16_t)(*it).m_logicalChannelIdentity);
427 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
475 for (
int i = 0; i < 4; i++)
506 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
508 uint8_t i = (*it).second;
513 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
514 if ((*itStat).second.at (i) == 0)
545 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
547 uint8_t i = (*it).second;
552 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
553 if ((*itStat).second.at (i) == 0)
556 (*itStat).second.at (i) = 1;
563 return ((*it).second);
572 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
581 NS_LOG_INFO (
this <<
" Reset HARQ proc " << i <<
" for RNTI " << (*itTimers).first);
582 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
m_dlHarqProcessesStatus.find ((*itTimers).first);
585 NS_FATAL_ERROR (
"No Process Id Status found for this RNTI " << (*itTimers).first);
587 (*itStat).second.at (i) = 0;
588 (*itTimers).second.at (i) = 0;
592 (*itTimers).second.at (i)++;
613 std::vector <bool> rbgMap;
614 uint16_t rbgAllocatedNum = 0;
615 std::set <uint16_t> rntiAllocated;
620 uint16_t rbStart = 0;
621 std::vector <struct RachListElement_s>::iterator itRach;
626 newRar.
m_rnti = (*itRach).m_rnti;
630 newRar.m_grant.m_rnti = newRar.m_rnti;
633 uint16_t tbSizeBits = 0;
640 if (tbSizeBits < (*itRach).m_estimatedSize)
645 newRar.m_grant.m_rbStart = rbStart;
646 newRar.m_grant.m_rbLen = rbLen;
647 newRar.m_grant.m_tbSize = tbSizeBits / 8;
648 newRar.m_grant.m_hopping =
false;
649 newRar.m_grant.m_tpc = 0;
650 newRar.m_grant.m_cqiRequest =
false;
651 newRar.m_grant.m_ulDelay =
false;
652 NS_LOG_INFO (
this <<
" UL grant allocated to RNTI " << (*itRach).m_rnti <<
" rbStart " << rbStart <<
" rbLen " << rbLen <<
" MCS " << (uint16_t)
m_ulGrantMcs <<
" tbSize " << newRar.m_grant.m_tbSize);
653 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
657 rbStart = rbStart + rbLen;
670 NS_LOG_INFO (
this <<
" Received DL-HARQ feedback");
686 std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
690 if (itRnti != rntiAllocated.end ())
696 std::vector <bool> retx;
697 NS_LOG_INFO (
this <<
" Processing DLHARQ feedback");
701 retx.push_back (
false);
708 if (retx.at (0) || retx.at (1))
713 NS_LOG_INFO (
this <<
" HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
722 if (dci.
m_rv.size () == 1)
724 rv = dci.
m_rv.at (0);
728 rv = (dci.
m_rv.at (0) > dci.
m_rv.at (1) ? dci.
m_rv.at (0) : dci.
m_rv.at (1));
734 NS_LOG_INFO (
"Max number of retransmissions reached -> drop process");
740 (*it).second.at (harqId) = 0;
746 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
748 (*itRlcPdu).second.at (k).at (harqId).clear ();
754 std::vector <int> dciRbg;
757 for (
int j = 0; j < 32; j++)
761 dciRbg.push_back (j);
767 for (uint8_t j = 0; j < dciRbg.size (); j++)
769 if (rbgMap.at (dciRbg.at (j)) ==
true)
779 for (uint8_t j = 0; j < dciRbg.size (); j++)
781 rbgMap.at (dciRbg.at (j)) =
true;
782 NS_LOG_INFO (
"RBG " << dciRbg.at (j) <<
" assigned");
786 NS_LOG_INFO (
this <<
" Send retx in the same RBGs");
792 uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
793 uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
794 std::vector <bool> rbgMapCopy = rbgMap;
795 while ((j < dciRbg.size ())&&(startRbg != rbgId))
797 if (rbgMapCopy.at (rbgId) ==
false)
799 rbgMapCopy.at (rbgId) =
true;
800 dciRbg.at (j) = rbgId;
805 if (j == dciRbg.size ())
808 uint32_t rbgMask = 0;
809 for (uint16_t k = 0; k < dciRbg.size (); k++)
811 rbgMask = rbgMask + (0x1 << dciRbg.at (k));
812 NS_LOG_INFO (
this <<
" New allocated RBG " << dciRbg.at (k));
821 dlInfoListUntxed.push_back (params.
m_dlInfoList.at (i));
822 NS_LOG_INFO (
this <<
" No resource for this retx -> buffer it");
830 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
832 for (uint8_t j = 0; j < nLayers; j++)
836 if (j >= dci.
m_ndi.size ())
839 dci.
m_ndi.push_back (0);
840 dci.
m_rv.push_back (0);
841 dci.
m_mcs.push_back (0);
843 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no txed (MIMO transition)");
848 dci.
m_ndi.at (j) = 0;
850 (*itHarq).second.at (harqId).m_rv.at (j)++;
851 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" RV " << (uint16_t)dci.
m_rv.at (j));
857 dci.
m_ndi.at (j) = 0;
859 dci.
m_mcs.at (j) = 0;
861 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no retx");
865 for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.
m_harqProcess).size (); k++)
867 std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
868 for (uint8_t j = 0; j < nLayers; j++)
872 if (j < dci.
m_ndi.size ())
874 rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.
m_harqProcess).at (k));
879 if (rlcPduListPerLc.size () > 0)
886 (*itHarq).second.at (harqId).
m_rv = dci.
m_rv;
891 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
893 (*itHarqTimer).second.at (harqId) = 0;
895 rntiAllocated.insert (rnti);
912 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
922 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
926 std::map <uint16_t,uint8_t> lcActivesPerRnti;
927 std::map <uint16_t,uint8_t>::iterator itLcRnti;
931 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
932 if ( (((*it).m_rlcTransmissionQueueSize > 0)
933 || ((*it).m_rlcRetransmissionQueueSize > 0)
934 || ((*it).m_rlcStatusPduSize > 0))
935 && (itRnti == rntiAllocated.end ())
939 NS_LOG_LOGIC (
this <<
" User " << (*it).m_rnti <<
" LC " << (uint16_t)(*it).m_logicalChannelIdentity <<
" is active, status " << (*it).m_rlcStatusPduSize <<
" retx " << (*it).m_rlcRetransmissionQueueSize <<
" tx " << (*it).m_rlcTransmissionQueueSize);
940 std::map <uint16_t,uint8_t>::iterator itCqi =
m_p10CqiRxed.find ((*it).m_rnti);
944 cqi = (*itCqi).second;
954 itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
955 if (itLcRnti != lcActivesPerRnti.end ())
957 (*itLcRnti).second++;
961 lcActivesPerRnti.insert (std::pair<uint16_t, uint8_t > ((*it).m_rnti, 1));
980 int rbgPerTb = (rbgNum - rbgAllocatedNum) / nTbs;
981 NS_LOG_INFO (
this <<
" Flows to be transmitted " << nflows <<
" rbgPerTb " << rbgPerTb);
986 int rbgAllocated = 0;
1010 std::map <uint16_t,uint8_t>::iterator itTxMode;
1013 itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
1014 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
1015 if ((itLcRnti == lcActivesPerRnti.end ())||(itRnti != rntiAllocated.end ()))
1018 uint16_t rntiDiscared = (*it).m_rnti;
1021 if ((*it).m_rnti != rntiDiscared)
1037 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*it).m_rnti);
1040 int lcNum = (*itLcRnti).second;
1043 newEl.
m_rnti = (*it).m_rnti;
1046 newDci.
m_rnti = (*it).m_rnti;
1051 for (uint8_t i = 0; i < nLayer; i++)
1055 newDci.
m_mcs.push_back (0);
1063 uint16_t rlcPduSize = tbSize / lcNum;
1066 if ( ((*it).m_rlcTransmissionQueueSize > 0)
1067 || ((*it).m_rlcRetransmissionQueueSize > 0)
1068 || ((*it).m_rlcStatusPduSize > 0) )
1070 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1071 for (uint8_t j = 0; j < nLayer; j++)
1076 newRlcEl.
m_size = rlcPduSize;
1078 newRlcPduLe.push_back (newRlcEl);
1086 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << (*it).m_rnti);
1088 (*itRlcPdu).second.at (j).at (newDci.
m_harqProcess).push_back (newRlcEl);
1102 uint32_t rbgMask = 0;
1104 NS_LOG_INFO (
this <<
" DL - Allocate user " << newEl.
m_rnti <<
" LCs " << (uint16_t)(*itLcRnti).second <<
" bytes " << tbSize <<
" mcs " << (uint16_t) newDci.
m_mcs.at (0) <<
" harqId " << (uint16_t)newDci.
m_harqProcess <<
" layers " << nLayer);
1106 while (i < rbgPerTb)
1108 if (rbgMap.at (rbgAllocated) ==
false)
1110 rbgMask = rbgMask + (0x1 << rbgAllocated);
1113 rbgMap.at (rbgAllocated) =
true;
1119 for (
int i = 0; i < nLayer; i++)
1122 newDci.
m_ndi.push_back (1);
1123 newDci.
m_rv.push_back (0);
1125 newEl.
m_dci = newDci;
1132 NS_FATAL_ERROR (
"Unable to find RNTI entry in DCI HARQ buffer for RNTI " << (*it).m_rnti);
1146 if (rbgAllocated == rbgNum)
1175 std::map <uint16_t,uint8_t>::iterator it;
1176 for (
unsigned int i = 0; i < params.
m_cqiList.size (); i++)
1181 std::map <uint16_t,uint8_t>::iterator it;
1182 uint16_t rnti = params.
m_cqiList.at (i).m_rnti;
1187 m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.
m_cqiList.at (i).m_wbCqi.at (0)) );
1194 (*it).second = params.
m_cqiList.at (i).m_wbCqi.at (0);
1196 std::map <uint16_t,uint32_t>::iterator itTimers;
1225 std::vector <bool> rbMap;
1226 uint16_t rbAllocatedNum = 0;
1227 std::set <uint16_t> rntiAllocated;
1228 std::vector <uint16_t> rbgAllocationMap;
1239 if (rbgAllocationMap.at (i) != 0)
1241 rbMap.at (i) =
true;
1249 std::map <uint16_t, uint8_t>::iterator itProcId;
1252 (*itProcId).second = ((*itProcId).second + 1) %
HARQ_PROC_NUM;
1254 for (uint16_t i = 0; i < params.
m_ulInfoList.size (); i++)
1263 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1266 NS_LOG_INFO (
this <<
" UL-HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
1270 NS_LOG_ERROR (
"No info find in UL-HARQ buffer for UE (might change eNB) " << rnti);
1276 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1278 if ((*itStat).second.at (harqId) > 3)
1280 NS_LOG_INFO (
"Max number of retransmissions reached (UL)-> drop process");
1286 if (rbMap.at (j) ==
true)
1297 rbMap.at (j) =
true;
1298 rbgAllocationMap.at (j) = dci.
m_rnti;
1306 NS_LOG_INFO (
"Cannot allocate retx due to RACH allocations for UE " << rnti);
1311 (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1312 (*itStat).second.at (harqId) = 0;
1313 (*itHarq).second.at ((*itProcId).second) = dci;
1315 rntiAllocated.insert (dci.
m_rnti);
1320 std::map <uint16_t,uint32_t>::iterator it;
1325 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1327 NS_LOG_INFO (
this <<
" UE " << (*it).first <<
" queue " << (*it).second);
1328 if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1350 uint16_t rbAllocated = 0;
1371 NS_LOG_INFO (
this <<
" NFlows " << nflows <<
" RB per Flow " << rbPerFlow);
1374 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1375 if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1397 NS_LOG_INFO (
this <<
" try to allocate " << (*it).first);
1399 uldci.
m_rnti = (*it).first;
1401 bool allocated =
false;
1406 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1408 if (rbMap.at (j) ==
true)
1418 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1420 rbMap.at (j) =
true;
1422 rbgAllocationMap.at (j) = (*it).first;
1425 rbAllocated += rbPerFlow;
1453 std::map <uint16_t, std::vector <double> >::iterator itCqi =
m_ueCqi.find ((*it).first);
1459 NS_LOG_INFO (
this <<
" UE does not have ULCQI " << (*it).first );
1464 double minSinr = (*itCqi).second.at (uldci.
m_rbStart);
1467 if ((*itCqi).second.at (i) < minSinr)
1469 minSinr = (*itCqi).second.at (i);
1473 double s = log2 ( 1 + (
1474 std::pow (10, minSinr / 10 ) /
1475 ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1487 NS_LOG_INFO (
this <<
" UE discarded for CQI = 0");
1512 std::map <uint16_t, uint8_t>::iterator itProcId;
1518 harqId = (*itProcId).second;
1524 (*itDci).second.at (harqId) = uldci;
1526 NS_LOG_INFO (
this <<
" UL Allocation - UE " << (*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 <<
" harqId " << (uint16_t)harqId);
1568 std::map <uint16_t,uint32_t>::iterator it;
1570 for (
unsigned int i = 0; i < params.
m_macCeList.size (); i++)
1581 uint32_t buffer = 0;
1582 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1584 uint8_t bsrId = params.
m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1593 m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1594 NS_LOG_INFO (
this <<
" Insert RNTI " << rnti <<
" queue " << buffer);
1599 (*it).second = buffer;
1600 NS_LOG_INFO (
this <<
" Update RNTI " << rnti <<
" queue " << buffer);
1642 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1643 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1650 for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1654 itCqi =
m_ueCqi.find ((*itMap).second.at (i));
1658 std::vector <double> newCqi;
1663 newCqi.push_back (sinr);
1668 newCqi.push_back (30.0);
1672 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1679 (*itCqi).second.at (i) = sinr;
1681 std::map <uint16_t, uint32_t>::iterator itTimers;
1702 rnti = vsp->GetRnti ();
1705 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1710 std::vector <double> newCqi;
1714 newCqi.push_back (sinr);
1715 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" new SRS-CQI for RB " << j <<
" value " << sinr);
1718 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1728 (*itCqi).second.at (j) = sinr;
1729 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" update SRS-CQI for RB " << j <<
" value " << sinr);
1732 std::map <uint16_t, uint32_t>::iterator itTimers;
1745 NS_FATAL_ERROR (
"PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1760 std::map <uint16_t,uint32_t>::iterator itP10 =
m_p10CqiTimers.begin ();
1764 if ((*itP10).second == 0)
1767 std::map <uint16_t,uint8_t>::iterator itMap =
m_p10CqiRxed.find ((*itP10).first);
1769 NS_LOG_INFO (
this <<
" P10-CQI exired for user " << (*itP10).first);
1771 std::map <uint16_t,uint32_t>::iterator temp = itP10;
1790 std::map <uint16_t,uint32_t>::iterator itUl =
m_ueCqiTimers.begin ();
1794 if ((*itUl).second == 0)
1797 std::map <uint16_t, std::vector <double> >::iterator itMap =
m_ueCqi.find ((*itUl).first);
1798 NS_ASSERT_MSG (itMap !=
m_ueCqi.end (),
" Does not find CQI report for user " << (*itUl).first);
1799 NS_LOG_INFO (
this <<
" UL-CQI exired for user " << (*itUl).first);
1800 (*itMap).second.clear ();
1802 std::map <uint16_t,uint32_t>::iterator temp = itUl;
1820 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1823 if (((*it).m_rnti == rnti) && ((*it).m_logicalChannelIdentity == lcid))
1825 NS_LOG_INFO (
this <<
" UE " << rnti <<
" LC " << (uint16_t)lcid <<
" txqueue " << (*it).m_rlcTransmissionQueueSize <<
" retxqueue " << (*it).m_rlcRetransmissionQueueSize <<
" status " << (*it).m_rlcStatusPduSize <<
" decrease " << size);
1828 if (((*it).m_rlcStatusPduSize > 0) && (size >= (*it).m_rlcStatusPduSize))
1830 (*it).m_rlcStatusPduSize = 0;
1832 else if (((*it).m_rlcRetransmissionQueueSize > 0) && (size >= (*it).m_rlcRetransmissionQueueSize))
1834 (*it).m_rlcRetransmissionQueueSize = 0;
1836 else if ((*it).m_rlcTransmissionQueueSize > 0)
1839 if ((*it).m_rlcTransmissionQueueSize <= size)
1841 (*it).m_rlcTransmissionQueueSize = 0;
1846 (*it).m_rlcTransmissionQueueSize -= size;
1859 std::map <uint16_t,uint32_t>::iterator it =
m_ceBsrRxed.find (rnti);
1862 NS_LOG_INFO (
this <<
" Update RLC BSR UE " << rnti <<
" size " << size <<
" BSR " << (*it).second);
1863 if ((*it).second >= size)
1865 (*it).second -= size;
1874 NS_LOG_ERROR (
this <<
" Does not find BSR report info of UE " << rnti);
1883 NS_LOG_FUNCTION (
this <<
" RNTI " << rnti <<
" txMode " << (uint16_t)txMode);