From 09a63cb998de7e64d0427a50df7448334c191f5b Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Tue, 5 Jan 2021 22:46:41 +0100
Subject: [PATCH] logging and unitary compilations

---
 openair1/SIMULATION/LTE_PHY/dlsim.c        |  3 ++-
 openair1/SIMULATION/LTE_PHY/ulsim.c        |  2 +-
 openair2/LAYER2/MAC/eNB_scheduler.c        | 11 +++++++++++
 openair2/LAYER2/MAC/eNB_scheduler_fairRR.c | 13 ++++++++-----
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c  |  3 ++-
 openair2/LAYER2/MAC/mac.h                  | 16 ++++++++++++++++
 6 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c
index c6a4142edf..5d5d146049 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim.c
@@ -935,9 +935,10 @@ int main(int argc, char **argv) {
 
     NB_RB = conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL);
   } else {
-    if (rballocset==0) NB_RB = 8;
+    if (rballocset==0) NB_RB = 2+TPC;
     else               NB_RB = DLSCH_RB_ALLOC;
 
+    printf("Common PDSCH: NB_RB = %d\n",NB_RB);
     AssertFatal(NB_RB <= N_RB_DL,"illegal NB_RB %d\n",NB_RB);
   }
 
diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c
index e9de56fd84..7f60cd5ab9 100644
--- a/openair1/SIMULATION/LTE_PHY/ulsim.c
+++ b/openair1/SIMULATION/LTE_PHY/ulsim.c
@@ -1300,7 +1300,7 @@ int main(int argc, char **argv) {
         LOG_UDUMPMSG(SIM,dataArray(table_rx),table_rx->size,LOG_DUMP_DOUBLE,"The receiver raw data: \n");
       }
 
-      dump_ulsch_stats(eNB);
+      dump_ulsch_stats(eNB,0);
       printf("\n**********rb: %d ***mcs : %d  *********SNR = %f dB (%f): TX %u dB (gain %f dB), N0W %f dB, I0 %u dB, delta_IF %d [ (%d,%d) dB / (%u,%u) dB ]**************************\n",
              nb_rb,mcs,SNR,SNR2,
              tx_lev_dB,
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 82db9ba8d3..86704c816a 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -603,6 +603,17 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP,
               UE_scheduling_control->dl_cqi[CC_id],
               (5 * UE_scheduling_control->pusch_snr[CC_id] - 640) / 10, UE_scheduling_control->pucch_tpc_accumulated[CC_id],
               (5 * UE_scheduling_control->pucch1_snr[CC_id] - 640) / 10, UE_scheduling_control->pusch_tpc_accumulated[CC_id]);
+        LOG_I(MAC,"              ULSCH rounds %d/%d/%d/%d, DLSCH rounds %d/%d/%d/%d, ULSCH errors %d, DLSCH errors %d\n",
+              UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_rounds[0],
+              UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_rounds[1],
+              UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_rounds[2],
+              UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_rounds[3],
+              UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[0],
+              UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[1],
+              UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[2],
+              UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[3],
+              UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_errors,
+              UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_errors);
       }
 
       RC.eNB[module_idP][CC_id]->pusch_stats_bsr[UE_id][(frameP * 10) + subframeP] = -63;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
index 59c7bf1ef2..6f5cace879 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
@@ -1495,7 +1495,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
                             subframeP,
                             S_DL_SCHEDULED,
                             rnti);
-          //eNB_UE_stats->dlsch_trials[round]++;
+          UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[round]++;
           UE_info->eNB_UE_stats[CC_id][UE_id].num_retransmission += 1;
           UE_info->eNB_UE_stats[CC_id][UE_id].rbs_used_retx = nb_rb;
           UE_info->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx += nb_rb;
@@ -1936,6 +1936,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
           // store stats
           eNB->eNB_stats[CC_id].dlsch_bytes_tx+=sdu_length_total;
           eNB->eNB_stats[CC_id].dlsch_pdus_tx+=1;
+          UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_rounds[0]++;
           UE_info->eNB_UE_stats[CC_id][UE_id].rbs_used = nb_rb;
           UE_info->eNB_UE_stats[CC_id][UE_id].total_rbs_used += nb_rb;
           UE_info->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1;
@@ -1968,10 +1969,10 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
               UE_info->UE_template[CC_id][UE_id].pucch_tpc_tx_frame=frameP;
               UE_info->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe=subframeP;
 
-              if (snr > target_snr + PUSCH_PCHYST) {
+              if (snr > target_snr + PUCCH_PCHYST) {
                 tpc = 0; //-1
                 ue_sched_ctl->pucch_tpc_accumulated[CC_id]--;
-              } else if (snr < target_snr - PUSCH_PCHYST) {
+              } else if (snr < target_snr - PUCCH_PCHYST) {
                 tpc = 2; //+1
                 ue_sched_ctl->pucch_tpc_accumulated[CC_id]++;
               } else {
@@ -3051,10 +3052,10 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
         UE_template->pusch_tpc_tx_frame=frameP;
         UE_template->pusch_tpc_tx_subframe=subframeP;
 
-        if (snr > target_snr + 4) {
+        if (snr > target_snr + PUSCH_PCHYST) {
           tpc = 0; //-1
           UE_sched_ctrl->pusch_tpc_accumulated[CC_id]--;
-        } else if (snr < target_snr - 4) {
+        } else if (snr < target_snr - PUSCH_PCHYST) {
           tpc = 2; //+1
           UE_sched_ctrl->pusch_tpc_accumulated[CC_id]++;
         } else {
@@ -3080,6 +3081,7 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
               UE_sched_ctrl->cqi_req_timer);
         ndi = 1-UE_template->oldNDI_UL[harq_pid];
         UE_template->oldNDI_UL[harq_pid]=ndi;
+        UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_rounds[0]++;
         UE_info->eNB_UE_stats[CC_id][UE_id].snr = snr;
         UE_info->eNB_UE_stats[CC_id][UE_id].target_snr = target_snr;
         UE_info->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1=UE_template->pre_assigned_mcs_ul;
@@ -3257,6 +3259,7 @@ void schedule_ulsch_rnti_fairRR(module_id_t   module_idP,
           T_INT(round));
         UE_info->eNB_UE_stats[CC_id][UE_id].snr = snr;
         UE_info->eNB_UE_stats[CC_id][UE_id].target_snr = target_snr;
+
         uint8_t mcs_rv = 0;
 
         if(rvidx_tab[round&3]==1) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index b941f60458..7e00897474 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -204,7 +204,7 @@ rx_sdu(const module_id_t enb_mod_idP,
       if (UE_scheduling_control->round_UL[CC_idP][harq_pid] == 3) {
         UE_scheduling_control->ul_scheduled &= (~(1 << harq_pid));
         UE_scheduling_control->round_UL[CC_idP][harq_pid] = 0;
-
+        UE_info->eNB_UE_stats[CC_idP][UE_id].ulsch_errors++;
         if (UE_scheduling_control->ul_consecutive_errors++ == 10) {
           UE_scheduling_control->ul_failure_timer = 1;
         }
@@ -221,6 +221,7 @@ rx_sdu(const module_id_t enb_mod_idP,
         }
       } else {
         UE_scheduling_control->round_UL[CC_idP][harq_pid]++;
+        UE_info->eNB_UE_stats[CC_idP][UE_id].ulsch_rounds[UE_scheduling_control->round_UL[CC_idP][harq_pid]]++;
       }
 
       /* CDRX UL HARQ timers */
diff --git a/openair2/LAYER2/MAC/mac.h b/openair2/LAYER2/MAC/mac.h
index 55cb06c28f..bf8db987d3 100644
--- a/openair2/LAYER2/MAC/mac.h
+++ b/openair2/LAYER2/MAC/mac.h
@@ -145,6 +145,8 @@
 #define CQI_VALUE_RANGE 16
 /*!\brief Hysteresis of PUSCH power control loop */
 #define PUSCH_PCHYST 1
+/*!\brief Hysteresis of PUCCH power control loop */
+#define PUCCH_PCHYST 1
 /*!\brief value for indicating BSR Timer is not running */
 #define MAC_UE_BSR_TIMER_NOT_RUNNING   (0xFFFF)
 
@@ -615,6 +617,8 @@ typedef struct {
 
   // here for RX
   //
+
+  uint32_t ulsch_rounds[4];
   uint32_t ulsch_bitrate;
   //
   uint32_t ulsch_bytes_rx;
@@ -684,6 +688,17 @@ typedef struct {
   // Length of SDU Got from LC DL
   uint32_t sdu_length_tx[NB_RB_MAX];
 
+  int lc_bytes_tx[64];
+  int dlsch_rounds[8];
+  int dlsch_errors;
+  int dlsch_total_bytes;
+
+  int lc_bytes_rx[64];
+  int ulsch_rounds[8];
+  int ulsch_errors;
+  int ulsch_total_bytes_scheduled;
+  int ulsch_total_bytes_rx;
+
 
   /// overall
   //
@@ -1324,6 +1339,7 @@ typedef struct {
   uint8_t FeMBMS_flag;
 } COMMON_channels_t;
 /*! \brief top level eNB MAC structure */
+
 typedef struct eNB_MAC_INST_s {
   /// Ethernet parameters for northbound midhaul interface
   eth_params_t eth_params_n;
-- 
2.26.2