From f79b0e7d9b273bb1fd561574fcd49ed8cf5e17df Mon Sep 17 00:00:00 2001
From: gauthier <lionel.gauthier@eurecom.fr>
Date: Wed, 23 Mar 2016 21:15:49 +0100
Subject: [PATCH] added hotfix for DCCH bad size limitation (to be checked
 after merge with develop).  Changed UL idle scheduling to improve 5MHz
 performance, changed DCI aggregation for ue-specific DCIs (reduces contention
 with SI and RA in subframe 5 for 5 MHz). Added RRC timer for UE release which
 cleans L1.  Still issues in 10 MHz throughput with TCP. 5 MHz seems almost
 fine.

---
 openair1/SCHED/phy_procedures_lte_eNb.c        | 3 ++-
 openair2/LAYER2/MAC/eNB_scheduler.c            | 4 ++--
 openair2/LAYER2/MAC/eNB_scheduler_primitives.c | 4 ++--
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c      | 2 --
 openair2/RRC/LITE/defs.h                       | 1 +
 openair2/RRC/LITE/rrc_common.c                 | 9 +++++++++
 openair2/RRC/LITE/rrc_eNB.c                    | 2 ++
 7 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 68ea6270e9..03a0ad1088 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -2980,8 +2980,9 @@ void prach_procedures(PHY_VARS_eNB *phy_vars_eNB,uint8_t sched_subframe,uint8_t
     mac_xface->macphy_exit("Exiting for PRACH debug\n");
     */
 
-    UE_id = find_next_ue_index(phy_vars_eNB);
 
+    UE_id = find_next_ue_index(phy_vars_eNB);
+ 
     if (UE_id>=0) {
       phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].UE_timing_offset = preamble_delay_list[preamble_max]&0x1FFF; //limit to 13 (=11+2) bits
       //phy_vars_eNb->eNB_UE_stats[(uint32_t)UE_id].mode = PRACH;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index a73daad499..570a7a1608 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -145,7 +145,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 	  UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=1;
 	  
 	  // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
-	  LOG_I(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    
+	  LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    
 	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
 	  *(uint32_t*)DLSCH_dci = 0;
 	  if (PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.frame_type == TDD) {
@@ -224,7 +224,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 	// check threshold
 	if (UE_list->UE_sched_ctrl[i].ul_failure_timer > 200) {
 	  // inform RRC of failure and clear timer
-	  LOG_I(MAC,"UE %d rnti %x: UL Failure Triggering RRC \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
+	  LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
 	  mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
 	  UE_list->UE_sched_ctrl[i].ul_failure_timer=0;
 	  UE_list->UE_sched_ctrl[i].ul_out_of_sync=1;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index 4145d8c045..fe06e8081f 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -193,7 +193,7 @@ uint8_t find_active_UEs(module_id_t module_idP,int CC_id){
 // get aggregatiob form phy for a give UE
 unsigned char process_ue_cqi (module_id_t module_idP, int ue_idP)
 {
-  unsigned char aggregation=2;
+  unsigned char aggregation=1;
   // check the MCS and SNR and set the aggregation accordingly
   return aggregation;
 }
@@ -707,7 +707,7 @@ uint8_t UE_is_to_be_scheduled(module_id_t module_idP,int CC_id,uint8_t UE_id)
       (UE_template->bsr_info[LCGID2]>0) ||
       (UE_template->bsr_info[LCGID3]>0) ||
       (UE_template->ul_SR>0) || // uplink scheduling request
-      ((UE_sched_ctl->ul_inactivity_timer>50)&&
+      ((UE_sched_ctl->ul_inactivity_timer>20)&&
        (UE_sched_ctl->ul_scheduled==0))||  // every 2 frames when RRC_CONNECTED
       ((UE_sched_ctl->ul_inactivity_timer>10)&&
        (UE_sched_ctl->ul_scheduled==0)&&
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index ea10f5a9fd..3d7efad87d 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -400,7 +400,6 @@ void rx_sdu(
 	  UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] = 0;
 
         //  This check is just to make sure we didn't get a bogus SDU length, to be removed ...
-        if (rx_lengths[i]<CCCH_PAYLOAD_SIZE_MAX) {
           LOG_D(MAC,"[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d \n",
                 enb_mod_idP,CC_idP,frameP, rx_lengths[i], UE_id, rx_lcids[i]);
 
@@ -418,7 +417,6 @@ void rx_sdu(
 			   NULL);//(unsigned int*)crc_status);
           UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]]+=1;
           UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]]+=rx_lengths[i];
-        }
       } /* UE_id != -1 */
 
       //      }
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index 49dc4d06ad..7a52115440 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -358,6 +358,7 @@ typedef struct eNB_RRC_UE_s {
   rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
 #endif
   uint32_t                           ul_failure_timer;
+  uint32_t                           ue_release_timer;
 } eNB_RRC_UE_t;
 
 typedef uid_t ue_uid_t;
diff --git a/openair2/RRC/LITE/rrc_common.c b/openair2/RRC/LITE/rrc_common.c
index 595e87a534..e6cbb2dcfb 100644
--- a/openair2/RRC/LITE/rrc_common.c
+++ b/openair2/RRC/LITE/rrc_common.c
@@ -531,6 +531,15 @@ rrc_rx_tx(
 	  break;
 	}
       }
+      if (ue_context_p->ue_context.ue_release_timer>0) {
+	ue_context_p->ue_context.ue_release_timer++;
+	if (ue_context_p->ue_context.ue_release_timer >= 100) {
+	  // remove UE after 10 frames after RRCConnectionRelease is triggered
+	  LOG_I(RRC,"Removing UE %x instance\n",ue_context_p->ue_context.rnti);
+	  ue_to_be_removed = ue_context_p;
+	  break;
+	}
+      }
     }
     if (ue_to_be_removed)
       rrc_eNB_free_UE(ctxt_pP->module_id,ue_to_be_removed);
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index abc7435b79..b22cd5c38e 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -1090,6 +1090,8 @@ rrc_eNB_generate_RRCConnectionRelease(
   memset(buffer, 0, RRC_BUF_SIZE);
 
   size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
+  // set release timer
+  ue_context_pP->ue_context.ue_release_timer=1;
 
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
-- 
2.26.2