22 #include <ns3/pointer.h>
27 #include <ns3/lte-amc.h>
28 #include <ns3/rr-ff-mac-scheduler.h>
29 #include <ns3/simulator.h>
30 #include <ns3/lte-common.h>
31 #include <ns3/lte-vendor-specific-parameters.h>
32 #include <ns3/boolean.h>
143 : m_scheduler (scheduler)
218 : m_cschedSapUser (0),
223 m_amc = CreateObject <LteAmc> ();
253 .AddConstructor<RrFfMacScheduler> ()
254 .AddAttribute (
"CqiTimerThreshold",
255 "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
258 MakeUintegerChecker<uint32_t> ())
259 .AddAttribute (
"HarqEnabled",
260 "Activate/Deactivate the HARQ [by default is active].",
263 MakeBooleanChecker ())
264 .AddAttribute (
"UlGrantMcs",
265 "The MCS of the UL grant, must be [0..15] (default 0)",
268 MakeUintegerChecker<uint8_t> ())
323 dlHarqPrcStatus.resize (8,0);
326 dlHarqProcessesTimer.resize (8,0);
329 dlHarqdci.resize (8);
332 dlHarqRlcPdu.resize (2);
333 dlHarqRlcPdu.at (0).resize (8);
334 dlHarqRlcPdu.at (1).resize (8);
338 ulHarqPrcStatus.resize (8,0);
341 ulHarqdci.resize (8);
365 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
396 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
399 if ((*it).m_rnti == params.
m_rnti)
401 NS_LOG_INFO (
this <<
" Erase RNTI " << (*it).m_rnti <<
" LC " << (uint16_t)(*it).m_logicalChannelIdentity);
428 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it =
m_rlcBufferReq.begin ();
476 for (
int i = 0; i < 4; i++)
507 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
509 uint8_t i = (*it).second;
514 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
515 if ((*itStat).second.at (i) == 0)
546 NS_FATAL_ERROR (
"No Process Id Statusfound for this RNTI " << rnti);
548 uint8_t i = (*it).second;
553 while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
554 if ((*itStat).second.at (i) == 0)
557 (*itStat).second.at (i) = 1;
564 return ((*it).second);
573 std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
582 NS_LOG_INFO (
this <<
" Reset HARQ proc " << i <<
" for RNTI " << (*itTimers).first);
583 std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat =
m_dlHarqProcessesStatus.find ((*itTimers).first);
586 NS_FATAL_ERROR (
"No Process Id Status found for this RNTI " << (*itTimers).first);
588 (*itStat).second.at (i) = 0;
589 (*itTimers).second.at (i) = 0;
593 (*itTimers).second.at (i)++;
614 std::vector <bool> rbgMap;
615 uint16_t rbgAllocatedNum = 0;
616 std::set <uint16_t> rntiAllocated;
621 uint16_t rbStart = 0;
622 std::vector <struct RachListElement_s>::iterator itRach;
627 newRar.
m_rnti = (*itRach).m_rnti;
631 newRar.m_grant.m_rnti = newRar.m_rnti;
634 uint16_t tbSizeBits = 0;
641 if (tbSizeBits < (*itRach).m_estimatedSize)
646 newRar.m_grant.m_rbStart = rbStart;
647 newRar.m_grant.m_rbLen = rbLen;
648 newRar.m_grant.m_tbSize = tbSizeBits / 8;
649 newRar.m_grant.m_hopping =
false;
650 newRar.m_grant.m_tpc = 0;
651 newRar.m_grant.m_cqiRequest =
false;
652 newRar.m_grant.m_ulDelay =
false;
653 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);
654 for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
658 rbStart = rbStart + rbLen;
671 NS_LOG_INFO (
this <<
" Received DL-HARQ feedback");
687 std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
691 if (itRnti != rntiAllocated.end ())
697 std::vector <bool> retx;
698 NS_LOG_INFO (
this <<
" Processing DLHARQ feedback");
702 retx.push_back (
false);
709 if (retx.at (0) || retx.at (1))
714 NS_LOG_INFO (
this <<
" HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
723 if (dci.
m_rv.size () == 1)
725 rv = dci.
m_rv.at (0);
729 rv = (dci.
m_rv.at (0) > dci.
m_rv.at (1) ? dci.
m_rv.at (0) : dci.
m_rv.at (1));
735 NS_LOG_INFO (
"Max number of retransmissions reached -> drop process");
741 (*it).second.at (harqId) = 0;
747 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
749 (*itRlcPdu).second.at (k).at (harqId).clear ();
755 std::vector <int> dciRbg;
758 for (
int j = 0; j < 32; j++)
762 dciRbg.push_back (j);
768 for (uint8_t j = 0; j < dciRbg.size (); j++)
770 if (rbgMap.at (dciRbg.at (j)) ==
true)
780 for (uint8_t j = 0; j < dciRbg.size (); j++)
782 rbgMap.at (dciRbg.at (j)) =
true;
783 NS_LOG_INFO (
"RBG " << dciRbg.at (j) <<
" assigned");
787 NS_LOG_INFO (
this <<
" Send retx in the same RBGs");
793 uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
794 uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
795 std::vector <bool> rbgMapCopy = rbgMap;
796 while ((j < dciRbg.size ())&&(startRbg != rbgId))
798 if (rbgMapCopy.at (rbgId) ==
false)
800 rbgMapCopy.at (rbgId) =
true;
801 dciRbg.at (j) = rbgId;
806 if (j == dciRbg.size ())
809 uint32_t rbgMask = 0;
810 for (uint16_t k = 0; k < dciRbg.size (); k++)
812 rbgMask = rbgMask + (0x1 << dciRbg.at (k));
813 NS_LOG_INFO (
this <<
" New allocated RBG " << dciRbg.at (k));
822 dlInfoListUntxed.push_back (params.
m_dlInfoList.at (i));
823 NS_LOG_INFO (
this <<
" No resource for this retx -> buffer it");
831 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
833 for (uint8_t j = 0; j < nLayers; j++)
837 if (j >= dci.
m_ndi.size ())
840 dci.
m_ndi.push_back (0);
841 dci.
m_rv.push_back (0);
842 dci.
m_mcs.push_back (0);
844 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no txed (MIMO transition)");
849 dci.
m_ndi.at (j) = 0;
851 (*itHarq).second.at (harqId).m_rv.at (j)++;
852 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" RV " << (uint16_t)dci.
m_rv.at (j));
858 dci.
m_ndi.at (j) = 0;
860 dci.
m_mcs.at (j) = 0;
862 NS_LOG_INFO (
this <<
" layer " << (uint16_t)j <<
" no retx");
866 for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.
m_harqProcess).size (); k++)
868 std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
869 for (uint8_t j = 0; j < nLayers; j++)
873 if (j < dci.
m_ndi.size ())
875 rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.
m_harqProcess).at (k));
880 if (rlcPduListPerLc.size () > 0)
887 (*itHarq).second.at (harqId).
m_rv = dci.
m_rv;
892 NS_FATAL_ERROR (
"Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
894 (*itHarqTimer).second.at (harqId) = 0;
896 rntiAllocated.insert (rnti);
913 for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
923 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
927 std::map <uint16_t,uint8_t> lcActivesPerRnti;
928 std::map <uint16_t,uint8_t>::iterator itLcRnti;
932 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
933 if ( (((*it).m_rlcTransmissionQueueSize > 0)
934 || ((*it).m_rlcRetransmissionQueueSize > 0)
935 || ((*it).m_rlcStatusPduSize > 0))
936 && (itRnti == rntiAllocated.end ())
940 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);
941 std::map <uint16_t,uint8_t>::iterator itCqi =
m_p10CqiRxed.find ((*it).m_rnti);
945 cqi = (*itCqi).second;
955 itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
956 if (itLcRnti != lcActivesPerRnti.end ())
958 (*itLcRnti).second++;
962 lcActivesPerRnti.insert (std::pair<uint16_t, uint8_t > ((*it).m_rnti, 1));
981 int rbgPerTb = (nTbs > 0) ? ((rbgNum - rbgAllocatedNum) / nTbs) : DBL_MAX;
982 NS_LOG_INFO (
this <<
" Flows to be transmitted " << nflows <<
" rbgPerTb " << rbgPerTb);
987 int rbgAllocated = 0;
1011 std::map <uint16_t,uint8_t>::iterator itTxMode;
1014 itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
1015 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).m_rnti);
1016 if ((itLcRnti == lcActivesPerRnti.end ())||(itRnti != rntiAllocated.end ()))
1019 uint16_t rntiDiscared = (*it).m_rnti;
1022 if ((*it).m_rnti != rntiDiscared)
1038 NS_FATAL_ERROR (
"No Transmission Mode info on user " << (*it).m_rnti);
1041 int lcNum = (*itLcRnti).second;
1044 newEl.
m_rnti = (*it).m_rnti;
1047 newDci.
m_rnti = (*it).m_rnti;
1052 for (uint8_t i = 0; i < nLayer; i++)
1056 newDci.
m_mcs.push_back (0);
1064 uint16_t rlcPduSize = tbSize / lcNum;
1065 while ((*it).m_rnti == newEl.
m_rnti)
1067 if ( ((*it).m_rlcTransmissionQueueSize > 0)
1068 || ((*it).m_rlcRetransmissionQueueSize > 0)
1069 || ((*it).m_rlcStatusPduSize > 0) )
1071 std::vector <struct RlcPduListElement_s> newRlcPduLe;
1072 for (uint8_t j = 0; j < nLayer; j++)
1077 newRlcEl.
m_size = rlcPduSize;
1079 newRlcPduLe.push_back (newRlcEl);
1087 NS_FATAL_ERROR (
"Unable to find RlcPdcList in HARQ buffer for RNTI " << (*it).m_rnti);
1089 (*itRlcPdu).second.at (j).at (newDci.
m_harqProcess).push_back (newRlcEl);
1104 uint32_t rbgMask = 0;
1106 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);
1108 while (i < rbgPerTb)
1110 if (rbgMap.at (rbgAllocated) ==
false)
1112 rbgMask = rbgMask + (0x1 << rbgAllocated);
1115 rbgMap.at (rbgAllocated) =
true;
1122 for (
int i = 0; i < nLayer; i++)
1125 newDci.
m_ndi.push_back (1);
1126 newDci.
m_rv.push_back (0);
1128 newEl.
m_dci = newDci;
1149 if (rbgAllocatedNum == rbgNum)
1178 std::map <uint16_t,uint8_t>::iterator it;
1179 for (
unsigned int i = 0; i < params.
m_cqiList.size (); i++)
1184 std::map <uint16_t,uint8_t>::iterator it;
1185 uint16_t rnti = params.
m_cqiList.at (i).m_rnti;
1190 m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.
m_cqiList.at (i).m_wbCqi.at (0)) );
1197 (*it).second = params.
m_cqiList.at (i).m_wbCqi.at (0);
1199 std::map <uint16_t,uint32_t>::iterator itTimers;
1227 std::vector <bool> rbMap;
1228 uint16_t rbAllocatedNum = 0;
1229 std::set <uint16_t> rntiAllocated;
1230 std::vector <uint16_t> rbgAllocationMap;
1241 if (rbgAllocationMap.at (i) != 0)
1243 rbMap.at (i) =
true;
1252 std::map <uint16_t, uint8_t>::iterator itProcId;
1255 (*itProcId).second = ((*itProcId).second + 1) %
HARQ_PROC_NUM;
1257 for (uint16_t i = 0; i < params.
m_ulInfoList.size (); i++)
1266 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1269 NS_LOG_INFO (
this <<
" UL-HARQ retx RNTI " << rnti <<
" harqId " << (uint16_t)harqId);
1273 NS_LOG_ERROR (
"No info find in UL-HARQ buffer for UE (might change eNB) " << rnti);
1279 NS_LOG_ERROR (
"No info find in HARQ buffer for UE (might change eNB) " << rnti);
1281 if ((*itStat).second.at (harqId) > 3)
1283 NS_LOG_INFO (
"Max number of retransmissions reached (UL)-> drop process");
1289 if (rbMap.at (j) ==
true)
1300 rbMap.at (j) =
true;
1301 rbgAllocationMap.at (j) = dci.
m_rnti;
1309 NS_LOG_INFO (
"Cannot allocate retx due to RACH allocations for UE " << rnti);
1314 (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1315 (*itStat).second.at (harqId) = 0;
1316 (*itHarq).second.at ((*itProcId).second) = dci;
1318 rntiAllocated.insert (dci.
m_rnti);
1323 std::map <uint16_t,uint32_t>::iterator it;
1328 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1330 NS_LOG_INFO (
this <<
" UE " << (*it).first <<
" queue " << (*it).second);
1331 if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1353 uint16_t rbAllocated = 0;
1374 NS_LOG_INFO (
this <<
" NFlows " << nflows <<
" RB per Flow " << rbPerFlow);
1377 std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1378 if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1400 NS_LOG_INFO (
this <<
" try to allocate " << (*it).first);
1402 uldci.
m_rnti = (*it).first;
1404 bool allocated =
false;
1405 NS_LOG_INFO (
this <<
" RB Allocated " << rbAllocated <<
" rbPerFlow " << rbPerFlow <<
" flows " << nflows);
1410 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1412 if (rbMap.at (j) ==
true)
1422 for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1424 rbMap.at (j) =
true;
1426 rbgAllocationMap.at (j) = (*it).first;
1429 rbAllocated += rbPerFlow;
1457 std::map <uint16_t, std::vector <double> >::iterator itCqi =
m_ueCqi.find ((*it).first);
1463 NS_LOG_INFO (
this <<
" UE does not have ULCQI " << (*it).first );
1468 double minSinr = (*itCqi).second.at (uldci.
m_rbStart);
1471 if ((*itCqi).second.at (i) < minSinr)
1473 minSinr = (*itCqi).second.at (i);
1477 double s = log2 ( 1 + (
1478 std::pow (10, minSinr / 10 ) /
1479 ( (-std::log (5.0 * 0.00005 )) / 1.5) ));
1495 rbgAllocationMap.at (i) = 0;
1521 std::map <uint16_t, uint8_t>::iterator itProcId;
1527 harqId = (*itProcId).second;
1533 (*itDci).second.at (harqId) = uldci;
1535 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);
1577 std::map <uint16_t,uint32_t>::iterator it;
1579 for (
unsigned int i = 0; i < params.
m_macCeList.size (); i++)
1590 uint32_t buffer = 0;
1591 for (uint8_t lcg = 0; lcg < 4; ++lcg)
1593 uint8_t bsrId = params.
m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1602 m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1603 NS_LOG_INFO (
this <<
" Insert RNTI " << rnti <<
" queue " << buffer);
1608 (*it).second = buffer;
1609 NS_LOG_INFO (
this <<
" Update RNTI " << rnti <<
" queue " << buffer);
1651 std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1652 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1659 for (uint32_t i = 0; i < (*itMap).second.size (); i++)
1663 itCqi =
m_ueCqi.find ((*itMap).second.at (i));
1667 std::vector <double> newCqi;
1672 newCqi.push_back (sinr);
1677 newCqi.push_back (30.0);
1681 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
1688 (*itCqi).second.at (i) = sinr;
1690 std::map <uint16_t, uint32_t>::iterator itTimers;
1711 rnti = vsp->GetRnti ();
1714 std::map <uint16_t, std::vector <double> >::iterator itCqi;
1719 std::vector <double> newCqi;
1723 newCqi.push_back (sinr);
1724 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" new SRS-CQI for RB " << j <<
" value " << sinr);
1727 m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
1737 (*itCqi).second.at (j) = sinr;
1738 NS_LOG_INFO (
this <<
" RNTI " << rnti <<
" update SRS-CQI for RB " << j <<
" value " << sinr);
1741 std::map <uint16_t, uint32_t>::iterator itTimers;
1754 NS_FATAL_ERROR (
"PfFfMacScheduler supports only PUSCH and SRS UL-CQIs");
1769 std::map <uint16_t,uint32_t>::iterator itP10 =
m_p10CqiTimers.begin ();
1773 if ((*itP10).second == 0)
1776 std::map <uint16_t,uint8_t>::iterator itMap =
m_p10CqiRxed.find ((*itP10).first);
1778 NS_LOG_INFO (
this <<
" P10-CQI exired for user " << (*itP10).first);
1780 std::map <uint16_t,uint32_t>::iterator temp = itP10;
1799 std::map <uint16_t,uint32_t>::iterator itUl =
m_ueCqiTimers.begin ();
1803 if ((*itUl).second == 0)
1806 std::map <uint16_t, std::vector <double> >::iterator itMap =
m_ueCqi.find ((*itUl).first);
1807 NS_ASSERT_MSG (itMap !=
m_ueCqi.end (),
" Does not find CQI report for user " << (*itUl).first);
1808 NS_LOG_INFO (
this <<
" UL-CQI exired for user " << (*itUl).first);
1809 (*itMap).second.clear ();
1811 std::map <uint16_t,uint32_t>::iterator temp = itUl;
1829 std::list<FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
1832 if (((*it).m_rnti == rnti) && ((*it).m_logicalChannelIdentity == lcid))
1834 NS_LOG_INFO (
this <<
" UE " << rnti <<
" LC " << (uint16_t)lcid <<
" txqueue " << (*it).m_rlcTransmissionQueueSize <<
" retxqueue " << (*it).m_rlcRetransmissionQueueSize <<
" status " << (*it).m_rlcStatusPduSize <<
" decrease " << size);
1837 if (((*it).m_rlcStatusPduSize > 0) && (size >= (*it).m_rlcStatusPduSize))
1839 (*it).m_rlcStatusPduSize = 0;
1841 else if (((*it).m_rlcRetransmissionQueueSize > 0) && (size >= (*it).m_rlcRetransmissionQueueSize))
1843 (*it).m_rlcRetransmissionQueueSize = 0;
1845 else if ((*it).m_rlcTransmissionQueueSize > 0)
1847 uint32_t rlcOverhead;
1862 if ((*it).m_rlcTransmissionQueueSize <= size - rlcOverhead)
1864 (*it).m_rlcTransmissionQueueSize = 0;
1868 (*it).m_rlcTransmissionQueueSize -= size - rlcOverhead;
1881 std::map <uint16_t,uint32_t>::iterator it =
m_ceBsrRxed.find (rnti);
1884 NS_LOG_INFO (
this <<
" Update RLC BSR UE " << rnti <<
" size " << size <<
" BSR " << (*it).second);
1885 if ((*it).second >= size)
1887 (*it).second -= size;
1896 NS_LOG_ERROR (
this <<
" Does not find BSR report info of UE " << rnti);
1905 NS_LOG_FUNCTION (
this <<
" RNTI " << rnti <<
" txMode " << (uint16_t)txMode);