src/lte/model/rr-ff-mac-scheduler.cc
changeset 8020 fc705bc87348
parent 7983 b91d5a39aabc
child 8035 d2e70680881a
--- a/src/lte/model/rr-ff-mac-scheduler.cc	Fri May 06 09:43:05 2011 +0200
+++ b/src/lte/model/rr-ff-mac-scheduler.cc	Fri May 06 09:44:24 2011 +0200
@@ -208,7 +208,8 @@
 RrFfMacScheduler::RrFfMacScheduler ()
   :   m_cschedSapUser (0),
     m_schedSapUser (0),
-    m_schedTtiDelay (2) // WILD ACK: based on a m_macChTtiDelay = 1 
+    m_schedTtiDelay (2), // WILD ACK: based on a m_macChTtiDelay = 1 
+    m_nextRnti (0)
 {
   m_cschedSapProvider = new RrSchedulerMemberCschedSapProvider (this);
   m_schedSapProvider = new RrSchedulerMemberSchedSapProvider (this);
@@ -369,7 +370,7 @@
 void
 RrFfMacScheduler::DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params)
 {
-  NS_LOG_FUNCTION (this);
+  NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf>>4) << " subframe no. " << (0xF & params.m_sfnSf));
   // API generated by RLC for triggering the scheduling of a DL subframe
 
   // Get the actual active flows (queue!=0)
@@ -404,7 +405,7 @@
             }
         }
     }
-
+   
   if (nflows == 0)
     {
       return;
@@ -421,16 +422,40 @@
   int rbgAllocated = 0;
 
   FfMacSchedSapUser::SchedDlConfigIndParameters ret;
-  // round robin assignment to all UE-LC registered
-  it = m_rlcBufferReq.begin ();
-  //for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
-  while (it != m_rlcBufferReq.end ())
+  // round robin assignment to all UE-LC registered starting from the subsequent of the one
+  // served last scheduling trigger
+  NS_LOG_DEBUG (this << " next to be served " << m_nextRnti << " nflows " << nflows);
+  if (m_nextRnti!=0)
+    {
+      for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
+        {
+          if ((*it).m_rnti == m_nextRnti)    
+          {
+            break;
+          }
+        }
+        
+        if (it == m_rlcBufferReq.end ())
+        {
+          NS_LOG_ERROR (this << " no user found");
+        }
+    }
+  else
+    {
+      it = m_rlcBufferReq.begin ();
+    }
+  do
     {
       itLcRnti = lcActivesPerRnti.find ((*it).m_rnti);
       if (itLcRnti==lcActivesPerRnti.end ())
       {
         // skip this entry
         it++;
+        if (it==m_rlcBufferReq.end ())
+          {
+            // restart from the first
+            it = m_rlcBufferReq.begin ();
+          }
         continue;
       }
       int lcNum = (*itLcRnti).second;
@@ -445,7 +470,7 @@
       std::map <uint16_t,uint8_t>::iterator itCqi = m_p10CqiRxed.find (newEl.m_rnti);
       if (itCqi == m_p10CqiRxed.end ())
         {
-          newDci.m_mcs.push_back (1); // no info on this user -> lowest MCS
+          newDci.m_mcs.push_back (0); // no info on this user -> lowest MCS
         }
       else
         {
@@ -455,7 +480,7 @@
       std::vector <struct RlcPduListElement_s> newRlcPduLe;
       int totRbg = lcNum * rbgPerFlow;
       int tbSize = (LteAmc::GetTbSizeFromMcs (newDci.m_mcs.at (0), totRbg * rbgSize) / 8);
-      //NS_LOG_DEBUG (this << "Allocate user " << newEl.m_rnti << " LCs " << (uint16_t)(*itLcRnti).second << " bytes " << tbSize);
+      NS_LOG_DEBUG (this << "Allocate user " << newEl.m_rnti << " LCs " << (uint16_t)(*itLcRnti).second << " bytes " << tbSize << " PRBs " << totRbg * rbgSize << " mcs " << (uint16_t) newDci.m_mcs.at (0));
       uint16_t rlcPduSize = tbSize / lcNum;
       for (int i = 0; i < lcNum ; i++)
         {
@@ -465,12 +490,16 @@
           newRlcEl.m_size = rlcPduSize;
           newRlcPduLe.push_back (newRlcEl);
           it++;
+          if (it==m_rlcBufferReq.end ())
+            {
+              // restart from the first
+              it = m_rlcBufferReq.begin ();
+            }
         }
       uint32_t rbgMask = 0;
       for (int i = 0; i < totRbg; i++)
         {
           rbgMask = rbgMask + (0x1 << rbgAllocated);
-          //NS_LOG_DEBUG (this << " Allocated RBG " << rbgAllocated);
           rbgAllocated++;
         }
       newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
@@ -492,9 +521,11 @@
       ret.m_buildDataList.push_back (newEl);
       if (rbgAllocated == rbgNum)
         {
+          NS_LOG_DEBUG (this << " FULL " << (*it).m_rnti);
+          m_nextRnti = (*it).m_rnti; // store last RNTI served
           break;                       // no more RGB to be allocated
         }
-    } // end while
+    } while ((*it).m_rnti != m_nextRnti);
 
   ret.m_nrOfPdcchOfdmSymbols = 1;   // TODO: check correct value according the DCIs txed