src/lte/model/rr-ff-mac-scheduler.cc
changeset 9307 694926420210
parent 9306 2601b437f6aa
parent 8729 74de12409ee5
child 9319 dbe853670778
equal deleted inserted replaced
9306:2601b437f6aa 9307:694926420210
    19  */
    19  */
    20 
    20 
    21 #include <ns3/log.h>
    21 #include <ns3/log.h>
    22 #include <ns3/pointer.h>
    22 #include <ns3/pointer.h>
    23 
    23 
    24 #include "lte-amc.h"
    24 #include <ns3/lte-amc.h>
    25 #include "rr-ff-mac-scheduler.h"
    25 #include <ns3/rr-ff-mac-scheduler.h>
    26 #include <ns3/simulator.h>
    26 #include <ns3/simulator.h>
       
    27 #include <ns3/lte-common.h>
    27 
    28 
    28 NS_LOG_COMPONENT_DEFINE ("RrFfMacScheduler");
    29 NS_LOG_COMPONENT_DEFINE ("RrFfMacScheduler");
    29 
    30 
    30 namespace ns3 {
    31 namespace ns3 {
    31 
    32 
   209 
   210 
   210 
   211 
   211 RrFfMacScheduler::RrFfMacScheduler ()
   212 RrFfMacScheduler::RrFfMacScheduler ()
   212   :   m_cschedSapUser (0),
   213   :   m_cschedSapUser (0),
   213     m_schedSapUser (0),
   214     m_schedSapUser (0),
   214     m_schedTtiDelay (2),
       
   215     // WILD ACK: based on a m_macChTtiDelay = 1
       
   216     m_nextRntiDl (0),
   215     m_nextRntiDl (0),
   217     m_nextRntiUl (0)
   216     m_nextRntiUl (0)
   218 {
   217 {
   219   m_amc = CreateObject <LteAmc> ();
   218   m_amc = CreateObject <LteAmc> ();
   220   m_cschedSapProvider = new RrSchedulerMemberCschedSapProvider (this);
   219   m_cschedSapProvider = new RrSchedulerMemberCschedSapProvider (this);
   288 }
   287 }
   289 
   288 
   290 void
   289 void
   291 RrFfMacScheduler::DoCschedUeConfigReq (const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
   290 RrFfMacScheduler::DoCschedUeConfigReq (const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
   292 {
   291 {
   293   NS_LOG_FUNCTION (this);
   292   NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
   294   // Not used at this stage
   293   std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
       
   294   if (it==m_uesTxMode.end ())
       
   295     {
       
   296       m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
       
   297     }
       
   298   else
       
   299     {
       
   300       (*it).second = params.m_transmissionMode;
       
   301     }
   295   return;
   302   return;
   296 }
   303 }
   297 
   304 
   298 void
   305 void
   299 RrFfMacScheduler::DoCschedLcConfigReq (const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
   306 RrFfMacScheduler::DoCschedLcConfigReq (const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
   391 
   398 
   392 
   399 
   393 void
   400 void
   394 RrFfMacScheduler::DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params)
   401 RrFfMacScheduler::DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params)
   395 {
   402 {
   396   NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
   403   NS_LOG_FUNCTION (this << " DL Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
   397   // API generated by RLC for triggering the scheduling of a DL subframe
   404   // API generated by RLC for triggering the scheduling of a DL subframe
   398   
   405   
   399   RefreshDlCqiMaps ();
   406   RefreshDlCqiMaps ();
   400 
   407 
   401   // Get the actual active flows (queue!=0)
   408   // Get the actual active flows (queue!=0)
   479   else
   486   else
   480     {
   487     {
   481       it = m_rlcBufferReq.begin ();
   488       it = m_rlcBufferReq.begin ();
   482       m_nextRntiDl = (*it).m_rnti;
   489       m_nextRntiDl = (*it).m_rnti;
   483     }
   490     }
       
   491   std::map <uint16_t,uint8_t>::iterator itTxMode;
   484   do
   492   do
   485     {
   493     {
   486       itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
   494       itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
   487       if (itLcRnti == lcActivesPerRnti.end ())
   495       if (itLcRnti == lcActivesPerRnti.end ())
   488         {
   496         {
   493               // restart from the first
   501               // restart from the first
   494               it = m_rlcBufferReq.begin ();
   502               it = m_rlcBufferReq.begin ();
   495             }
   503             }
   496           continue;
   504           continue;
   497         }
   505         }
       
   506       itTxMode = m_uesTxMode.find ((*it).m_rnti);
       
   507       if (itTxMode == m_uesTxMode.end())
       
   508         {
       
   509           NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).m_rnti);
       
   510         }
       
   511       int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
   498       int lcNum = (*itLcRnti).second;
   512       int lcNum = (*itLcRnti).second;
   499       // create new BuildDataListElement_s for this RNTI
   513       // create new BuildDataListElement_s for this RNTI
   500       BuildDataListElement_s newEl;
   514       BuildDataListElement_s newEl;
   501       newEl.m_rnti = (*it).m_rnti;
   515       newEl.m_rnti = (*it).m_rnti;
   502       // create the DlDciListElement_s
   516       // create the DlDciListElement_s
   503       DlDciListElement_s newDci;
   517       DlDciListElement_s newDci;
   504       newDci.m_rnti = (*it).m_rnti;
   518       newDci.m_rnti = (*it).m_rnti;
   505       newDci.m_resAlloc = 0;
   519       newDci.m_resAlloc = 0;
   506       newDci.m_rbBitmap = 0;
   520       newDci.m_rbBitmap = 0;
   507       std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find (newEl.m_rnti);
   521       std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find (newEl.m_rnti);
   508       if (itCqi == m_p10CqiRxed.end ())
   522       for (uint8_t i = 0; i < nLayer; i++) 
   509         {
   523         {
   510           newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
   524           if (itCqi == m_p10CqiRxed.end ())
   511         }
   525             {
   512       else
   526               newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
   513         {
   527             }
   514           newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
   528           else
       
   529             {
       
   530               newDci.m_mcs.push_back ( m_amc->GetMcsFromCqi ((*itCqi).second) );
       
   531             }
   515         }
   532         }
   516       // group the LCs of this RNTI
   533       // group the LCs of this RNTI
   517       std::vector <struct RlcPduListElement_s> newRlcPduLe;
   534       std::vector <struct RlcPduListElement_s> newRlcPduLe;
   518 //       int totRbg = lcNum * rbgPerFlow;
   535 //       int totRbg = lcNum * rbgPerFlow;
   519 //       totRbg = rbgNum / nTbs;
   536 //       totRbg = rbgNum / nTbs;
   520 int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (0), rbgPerTb * rbgSize) / 8);
   537       int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (0), rbgPerTb * rbgSize) / 8);
   521       NS_LOG_DEBUG (this << "Allocate user " << newEl.m_rnti << " LCs " << (uint16_t)(*itLcRnti).second << " bytes " << tbSize << " PRBs " << rbgPerTb * rbgSize << " mcs " << (uint16_t) newDci.m_mcs.at (0));
   538       NS_LOG_DEBUG (this << "Allocate user " << newEl.m_rnti << " LCs " << (uint16_t)(*itLcRnti).second << " bytes " << tbSize << " PRBs " <<  rbgAllocated * rbgSize << "..." << (rbgAllocated* rbgSize) + (rbgPerTb * rbgSize) - 1 << " mcs " << (uint16_t) newDci.m_mcs.at (0) << " layers " << nLayer);
   522       uint16_t rlcPduSize = tbSize / lcNum;
   539       uint16_t rlcPduSize = tbSize / lcNum;
   523       for (int i = 0; i < lcNum ; i++)
   540       for (int i = 0; i < lcNum ; i++)
   524         {
   541         {
   525           RlcPduListElement_s newRlcEl;
   542           for (uint8_t j = 0; j < nLayer; j++)
   526           newRlcEl.m_logicalChannelIdentity = (*it).m_logicalChannelIdentity;
   543             {
   527           NS_LOG_DEBUG (this << "LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << rlcPduSize << " ID " << (*it).m_rnti);
   544               RlcPduListElement_s newRlcEl;
   528           newRlcEl.m_size = rlcPduSize;
   545               newRlcEl.m_logicalChannelIdentity = (*it).m_logicalChannelIdentity;
   529           UpdateDlRlcBufferInfo ((*it).m_rnti, newRlcEl.m_logicalChannelIdentity, rlcPduSize);
   546 //               NS_LOG_DEBUG (this << "LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << rlcPduSize << " ID " << (*it).m_rnti << " layer " << (uint16_t)j);
   530           newRlcPduLe.push_back (newRlcEl);
   547               newRlcEl.m_size = rlcPduSize;
       
   548               UpdateDlRlcBufferInfo ((*it).m_rnti, newRlcEl.m_logicalChannelIdentity, rlcPduSize);
       
   549               newRlcPduLe.push_back (newRlcEl);
       
   550             }
   531           it++;
   551           it++;
   532           if (it == m_rlcBufferReq.end ())
   552           if (it == m_rlcBufferReq.end ())
   533             {
   553             {
   534               // restart from the first
   554               // restart from the first
   535               it = m_rlcBufferReq.begin ();
   555               it = m_rlcBufferReq.begin ();
   541           rbgMask = rbgMask + (0x1 << rbgAllocated);
   561           rbgMask = rbgMask + (0x1 << rbgAllocated);
   542           rbgAllocated++;
   562           rbgAllocated++;
   543         }
   563         }
   544       newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
   564       newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
   545 
   565 
   546       int nbOfTbsInNewDci = 1;  // SISO -> only one TB
   566       for (int i = 0; i < nLayer; i++)
   547       for (int i = 0; i < nbOfTbsInNewDci; i++)
       
   548         {
   567         {
   549           newDci.m_tbsSize.push_back (tbSize);
   568           newDci.m_tbsSize.push_back (tbSize);
   550           newDci.m_ndi.push_back (1); // TBD (new data indicator)
   569           newDci.m_ndi.push_back (1); // TBD (new data indicator)
   551           newDci.m_rv.push_back (0); // TBD (redundancy version)
   570           newDci.m_rv.push_back (0); // TBD (redundancy version)
   552         }
   571         }
   627 }
   646 }
   628 
   647 
   629 void
   648 void
   630 RrFfMacScheduler::DoSchedUlTriggerReq (const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
   649 RrFfMacScheduler::DoSchedUlTriggerReq (const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
   631 {
   650 {
   632 //   NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
   651   NS_LOG_FUNCTION (this << " Ul - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
   633 
   652 
   634 
   653 
   635   RefreshUlCqiMaps ();
   654   RefreshUlCqiMaps ();
   636   
   655   
   637   std::map <uint16_t,uint32_t>::iterator it; 
   656   std::map <uint16_t,uint32_t>::iterator it; 
   697       int cqi = 0;
   716       int cqi = 0;
   698       if (itCqi == m_ueCqi.end ())
   717       if (itCqi == m_ueCqi.end ())
   699         {
   718         {
   700           // no cqi info about this UE
   719           // no cqi info about this UE
   701           uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
   720           uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
   702           //NS_LOG_DEBUG (this << " UE does not have ULCQI " << (*it).first );
   721           NS_LOG_DEBUG (this << " UE does not have ULCQI " << (*it).first );
   703         }
   722         }
   704       else
   723       else
   705         {
   724         {
   706           // take the lowest CQI value (worst RB)
   725           // take the lowest CQI value (worst RB)
   707           double minSinr = (*itCqi).second.at (uldci.m_rbStart);
   726           double minSinr = (*itCqi).second.at (uldci.m_rbStart);
   708           for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
   727           for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
   709             {
   728             {
   710               //NS_LOG_DEBUG (this << " UE " << (*it).first << " has CQI " << (*itCqi).second.at(i));
       
   711               if ((*itCqi).second.at (i) < minSinr)
   729               if ((*itCqi).second.at (i) < minSinr)
   712                 {
   730                 {
   713                   minSinr = (*itCqi).second.at (i);
   731                   minSinr = (*itCqi).second.at (i);
   714                 }
   732                 }
   715             }
   733             }
   729                   it = m_ceBsrRxed.begin ();
   747                   it = m_ceBsrRxed.begin ();
   730                 }
   748                 }
   731               continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
   749               continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
   732             }
   750             }
   733           uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
   751           uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
   734           //NS_LOG_DEBUG (this << " UE " <<  (*it).first << " minsinr " << minSinr << " -> mcs " << (uint16_t)uldci.m_mcs);
   752 //           NS_LOG_DEBUG (this << " UE " <<  (*it).first << " minsinr " << minSinr << " -> mcs " << (uint16_t)uldci.m_mcs);
   735 
   753 
   736         }
   754         }
   737       
   755       
   738       rbAllocated += rbPerFlow;
   756       rbAllocated += rbPerFlow;
   739       // store info on allocation for managing ul-cqi interpretation
   757       // store info on allocation for managing ul-cqi interpretation
   741         {
   759         {
   742           rbgAllocationMap.push_back ((*it).first);
   760           rbgAllocationMap.push_back ((*it).first);
   743         }
   761         }
   744         
   762         
   745       uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8); // MCS 0 -> UL-AMC TBD
   763       uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8); // MCS 0 -> UL-AMC TBD
   746       NS_LOG_DEBUG (this << " 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);
   764       NS_LOG_DEBUG (this << " UL - 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);
   747       UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
   765       UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
   748       uldci.m_ndi = 1;
   766       uldci.m_ndi = 1;
   749       uldci.m_cceIndex = 0;
   767       uldci.m_cceIndex = 0;
   750       uldci.m_aggrLevel = 1;
   768       uldci.m_aggrLevel = 1;
   751       uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
   769       uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
   828 
   846 
   829 void
   847 void
   830 RrFfMacScheduler::DoSchedUlCqiInfoReq (const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
   848 RrFfMacScheduler::DoSchedUlCqiInfoReq (const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
   831 {
   849 {
   832   NS_LOG_FUNCTION (this);
   850   NS_LOG_FUNCTION (this);
   833 //   NS_LOG_DEBUG (this << " RX SFNID " << params.m_sfnSf);
   851   NS_LOG_DEBUG (this << " RX SFNID " << params.m_sfnSf);
   834   // correlate info on UL-CQIs with previous scheduling -> calculate m_sfnSf of transmission
       
   835   uint32_t frameNo = (0x3FF & (params.m_sfnSf >> 4));
       
   836   uint32_t subframeNo = (0xF & params.m_sfnSf);
       
   837   //NS_LOG_DEBUG (this << " sfn " << frameNo << " sbfn " << subframeNo);
       
   838   if (subframeNo <= m_schedTtiDelay)
       
   839     {
       
   840       frameNo--;
       
   841       subframeNo = (10 + subframeNo - m_schedTtiDelay) % 11;
       
   842     }
       
   843   else
       
   844     {
       
   845       subframeNo = (subframeNo - m_schedTtiDelay) % 11;
       
   846     }
       
   847   uint16_t sfnSf = ((0x3FF & frameNo) << 4) | (0xF & subframeNo);
       
   848 //     NS_LOG_DEBUG (this << " Actual sfn " << frameNo << " sbfn " << subframeNo << " sfnSf "  << sfnSf);
   852 //     NS_LOG_DEBUG (this << " Actual sfn " << frameNo << " sbfn " << subframeNo << " sfnSf "  << sfnSf);
   849   // retrieve the allocation for this subframe
   853   // retrieve the allocation for this subframe
   850   std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
   854   std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
   851   std::map <uint16_t, std::vector <double> >::iterator itCqi;
   855   std::map <uint16_t, std::vector <double> >::iterator itCqi;
   852   itMap = m_allocationMaps.find (sfnSf);
   856   itMap = m_allocationMaps.find (params.m_sfnSf);
   853   if (itMap == m_allocationMaps.end ())
   857   if (itMap == m_allocationMaps.end ())
   854     {
   858     {
   855       NS_LOG_DEBUG (this << " Does not find info on allocation");
   859       NS_LOG_DEBUG (this << " Does not find info on allocation");
   856       return;
   860       return;
   857     }
   861     }
   858   for (uint32_t i = 0; i < (*itMap).second.size (); i++)
   862   for (uint32_t i = 0; i < (*itMap).second.size (); i++)
   859     {
   863     {
   860       // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
   864       // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
   861       double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
   865       double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
   862       //NS_LOG_DEBUG (this << " UE " << (*itMap).second.at (i) << " SINRfp " << params.m_ulCqi.m_sinr.at (i) << " sinrdb " << sinr);
   866 //       NS_LOG_DEBUG (this << " RB " << i << "UE " << (*itMap).second.at (i) << " SINRfp " << params.m_ulCqi.m_sinr.at (i) << " sinrdb " << sinr);
   863       itCqi = m_ueCqi.find ((*itMap).second.at (i));
   867       itCqi = m_ueCqi.find ((*itMap).second.at (i));
   864       if (itCqi == m_ueCqi.end ())
   868       if (itCqi == m_ueCqi.end ())
   865         {
   869         {
   866           // create a new entry
   870           // create a new entry
   867           std::vector <double> newCqi;
   871           std::vector <double> newCqi;
  1033       NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
  1037       NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
  1034     }
  1038     }
  1035   
  1039   
  1036 }
  1040 }
  1037 
  1041 
  1038 }
  1042 
       
  1043 void
       
  1044 RrFfMacScheduler::TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode)
       
  1045 {
       
  1046   NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
       
  1047   FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params;
       
  1048   params.m_rnti = rnti;
       
  1049   params.m_transmissionMode = txMode;
       
  1050   m_cschedSapUser->CschedUeConfigUpdateInd (params);
       
  1051 }
       
  1052 
       
  1053 
       
  1054 
       
  1055 }