From ccb83d16e1f323cd0c0b9acebe19ec522ac24dcc Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Mon, 21 Sep 2020 13:46:14 +0200
Subject: [PATCH] Add NR_UE_list_t type

---
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     | 34 ++++---------------
 openair2/LAYER2/NR_MAC_gNB/mac_proto.h        |  2 +-
 openair2/LAYER2/NR_MAC_gNB/main.c             | 14 ++------
 openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h       | 14 +++++---
 4 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index 24fbc97136f..720a3b863dc 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -1592,26 +1592,9 @@ int extract_length(int startSymbolAndLength) {
 /*
  * Dump the UL or DL UE_info into LOG_T(MAC)
  */
-void
-dump_nr_ue_list(NR_UE_info_t *listP,
-             int ul_flag)
-//------------------------------------------------------------------------------
-{
-  if (ul_flag == 0) {
-    for (int j = listP->head; j >= 0; j = listP->next[j]) {
-      LOG_T(MAC, "DL list node %d => %d\n",
-            j,
-            listP->next[j]);
-    }
-  } else {
-    for (int j = listP->head_ul; j >= 0; j = listP->next_ul[j]) {
-      LOG_T(MAC, "UL list node %d => %d\n",
-            j,
-            listP->next_ul[j]);
-    }
-  }
-
-  return;
+void dump_nr_ue_list(NR_UE_list_t *listP) {
+  for (int j = listP->head; j >= 0; j = listP->next[j])
+    LOG_T(MAC, "DL list node %d => %d\n", j, listP->next[j]);
 }
 
 int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP)
@@ -1641,12 +1624,11 @@ int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
   int num_slots_ul = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots;
   if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols>0)
     num_slots_ul++;
-  LOG_I(MAC, "[gNB %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n",
+  LOG_I(MAC, "[gNB %d] Adding UE with rnti %x (num_UEs %d)\n",
         mod_idP,
         rntiP,
-        UE_info->avail,
         UE_info->num_UEs);
-  dump_nr_ue_list(UE_info, 0);
+  dump_nr_ue_list(&UE_info->list);
 
   for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (UE_info->active[i])
@@ -1674,15 +1656,13 @@ int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
           mod_idP,
           UE_id,
           rntiP);
-    dump_nr_ue_list(UE_info,
-		    0);
+    dump_nr_ue_list(&UE_info->list);
     return (UE_id);
   }
 
   // printf("MAC: cannot add new UE for rnti %x\n", rntiP);
   LOG_E(MAC, "error in add_new_ue(), could not find space in UE_info, Dumping UE list\n");
-  dump_nr_ue_list(UE_info,
-		  0);
+  dump_nr_ue_list(&UE_info->list);
   return -1;
 }
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index b4b8da852a7..df822329642 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -300,7 +300,7 @@ int NRRIV2BW(int locationAndBandwidth,int N_RB);
 
 int NRRIV2PRBOFFSET(int locationAndBandwidth,int N_RB);
 
-void dump_nr_ue_list(NR_UE_info_t *listP, int ul_flag);
+void dump_nr_ue_list(NR_UE_list_t *listP);
 
 int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP);
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c
index 72d139153a8..a06bde869c0 100644
--- a/openair2/LAYER2/NR_MAC_gNB/main.c
+++ b/openair2/LAYER2/NR_MAC_gNB/main.c
@@ -106,13 +106,9 @@ void mac_top_init_gNB(void)
     
     UE_info = &nrmac->UE_info;
     UE_info->num_UEs = 0;
-    UE_info->head = -1;
-    UE_info->head_ul = -1;
-    UE_info->avail = 0;
-
-    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB - 1; list_el++) {
-       UE_info->next[list_el] = list_el + 1;
-      UE_info->next_ul[list_el] = list_el + 1;
+    UE_info->list.head = -1;
+    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB; list_el++) {
+      UE_info->list.next[list_el] = -1;
       UE_info->active[list_el] = FALSE;
       for (int list_harq = 0; list_harq < NR_MAX_NB_HARQ_PROCESSES; list_harq++) {
         UE_info->UE_sched_ctrl[list_el].harq_processes[list_harq].round = 0;
@@ -123,10 +119,6 @@ void mac_top_init_gNB(void)
         UE_info->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].state = 0;
       }
     }
-
-    UE_info->next[list_el] = -1;
-    UE_info->next_ul[list_el] = -1;
-    UE_info->active[list_el] = FALSE;
   }
 
   srand48(0);
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index 24591955486..ba2ef0e7e33 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -343,17 +343,21 @@ typedef struct {
   int ulsch_total_bytes_rx;
 } NR_mac_stats_t;
 
+
+/*! \brief UNR_E_list_t is a "list" of users within UE_info_t. Especial useful in
+ * the scheduler and to keep "classes" of users. */
+typedef struct {
+  int head;
+  int next[MAX_MOBILES_PER_GNB];
+} NR_UE_list_t;
+
 /*! \brief UE list used by gNB to order UEs/CC for scheduling*/
 typedef struct {
   DLSCH_PDU DLSCH_pdu[4][MAX_MOBILES_PER_GNB];
   /// scheduling control info
   NR_UE_sched_ctrl_t UE_sched_ctrl[MAX_MOBILES_PER_GNB];
   NR_mac_stats_t mac_stats[MAX_MOBILES_PER_GNB];
-  int next[MAX_MOBILES_PER_GNB];
-  int head;
-  int next_ul[MAX_MOBILES_PER_GNB];
-  int head_ul;
-  int avail;
+  NR_UE_list_t list;
   int num_UEs;
   boolean_t active[MAX_MOBILES_PER_GNB];
   boolean_t fiveG_connected[MAX_MOBILES_PER_GNB];
-- 
GitLab