From 7a0c00330b2b134f32bf3b1f335a55d189faf729 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Mon, 21 May 2018 14:34:37 +0200
Subject: [PATCH] put intra-/inter slice sharing within slice config

---
 .../CONTROL_MODULES/MAC/flexran_agent_mac.c   |  3 ++
 .../MAC/flexran_agent_mac_internal.c          | 48 +++++++++++++++++++
 .../MAC/flexran_agent_mac_internal.h          |  8 ++++
 .../ENB_APP/MESSAGES/V2/config_messages.proto | 12 ++---
 4 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
index 1daf0d5183..273cb66567 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
+++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
@@ -1393,6 +1393,8 @@ void flexran_create_config_structures(mid_t mod_id)
   sc_update[mod_id] = flexran_agent_create_slice_config(n_dl, m_ul);
   if (!slice_config[mod_id] || !sc_update[mod_id]) return;
 
+  flexran_agent_read_slice_config(mod_id, slice_config[mod_id]);
+  flexran_agent_read_slice_config(mod_id, sc_update[mod_id]);
   for (i = 0; i < n_dl; i++) {
     flexran_agent_read_slice_dl_config(mod_id, i, slice_config[mod_id]->dl[i]);
     flexran_agent_read_slice_dl_config(mod_id, i, sc_update[mod_id]->dl[i]);
@@ -1526,6 +1528,7 @@ void flexran_agent_slice_update(mid_t mod_id)
                                          sc_update[mod_id]->ul[i]);
     flexran_agent_read_slice_ul_config(mod_id, i, slice_config[mod_id]->ul[i]);
   }
+  flexran_agent_read_slice_config(mod_id, slice_config[mod_id]);
   if (n_ue_slice_assoc_updates > 0) {
     changes += apply_ue_slice_assoc_update(mod_id);
   }
diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
index 1289e7551f..1c2aef3baa 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
+++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
@@ -939,6 +939,14 @@ Protocol__FlexSliceConfig *flexran_agent_create_slice_config(int n_dl, int m_ul)
   return fsc;
 }
 
+void flexran_agent_read_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *s)
+{
+  s->intraslice_share_active = flexran_get_intraslice_sharing_active(mod_id);
+  s->has_intraslice_share_active = 1;
+  s->interslice_share_active = flexran_get_interslice_sharing_active(mod_id);
+  s->has_interslice_share_active = 1;
+}
+
 void flexran_agent_read_slice_dl_config(mid_t mod_id, int slice_idx, Protocol__FlexDlSlice *dl_slice)
 {
   dl_slice->id = flexran_get_dl_slice_id(mod_id, slice_idx);
@@ -1042,6 +1050,24 @@ int check_ul_sorting_update(Protocol__FlexUlSlice *old, Protocol__FlexUlSlice *n
   return sorting_update;
 }
 
+void overwrite_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *exist, Protocol__FlexSliceConfig *update)
+{
+  if (update->has_intraslice_share_active
+      && exist->intraslice_share_active != update->intraslice_share_active) {
+    LOG_I(FLEXRAN_AGENT, "[%d] update intraslice_share_active: %d -> %d\n",
+          mod_id, exist->intraslice_share_active, update->intraslice_share_active);
+    exist->intraslice_share_active = update->intraslice_share_active;
+    exist->has_intraslice_share_active = 1;
+  }
+  if (update->has_interslice_share_active
+      && exist->interslice_share_active != update->interslice_share_active) {
+    LOG_I(FLEXRAN_AGENT, "[%d] update interslice_share_active: %d -> %d\n",
+          mod_id, exist->interslice_share_active, update->interslice_share_active);
+    exist->interslice_share_active = update->interslice_share_active;
+    exist->has_interslice_share_active = 1;
+  }
+}
+
 void overwrite_slice_config_dl(mid_t mod_id, Protocol__FlexDlSlice *exist, Protocol__FlexDlSlice *update)
 {
   if (update->label != exist->label) {
@@ -1333,6 +1359,11 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *sup)
   }
 
   pthread_mutex_lock(&sc_update_mtx);
+  /* no need for tests in the current state as there are only two protobuf
+    * bools for intra-/interslice sharing. The function applies new values if
+    * applicable */
+  overwrite_slice_config(mod_id, sc_update[mod_id], sup);
+
   if (sup->n_dl == 0) {
     LOG_I(FLEXRAN_AGENT, "[%d] no DL slice configuration in flex_slice_config message\n", mod_id);
   } else {
@@ -1408,6 +1439,23 @@ void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *sup)
   perform_slice_config_update_count = 1;
 }
 
+int apply_new_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *olds, Protocol__FlexSliceConfig *news)
+{
+  /* not setting the old configuration is intentional, as it will be picked up
+   * later when reading the configuration. There is thus a direct feedback
+   * whether it has been set. */
+  int changes = 0;
+  if (olds->intraslice_share_active != news->intraslice_share_active) {
+    flexran_set_intraslice_sharing_active(mod_id, news->intraslice_share_active);
+    changes++;
+  }
+  if (olds->interslice_share_active != news->interslice_share_active) {
+    flexran_set_interslice_sharing_active(mod_id, news->interslice_share_active);
+    changes++;
+  }
+  return changes;
+}
+
 int apply_new_slice_dl_config(mid_t mod_id, Protocol__FlexDlSlice *oldc, Protocol__FlexDlSlice *newc)
 {
   /* not setting the old configuration is intentional, as it will be picked up
diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.h b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.h
index 2f8f3f8258..01fc51f6a6 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.h
+++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.h
@@ -113,6 +113,10 @@ int load_dl_scheduler_function(mid_t mod_id, const char *function_name);
  * configs and m_ul UL slice configs */
 Protocol__FlexSliceConfig *flexran_agent_create_slice_config(int n_dl, int m_ul);
 
+/* read the general slice parameters via RAN into the given
+ * Protocol__FlexSliceConfig struct */
+void flexran_agent_read_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *s);
+
 /* read the DL slice config via the RAN into a given Protocol__FlexDlSlice
  * struct */
 void flexran_agent_read_slice_dl_config(mid_t mod_id, int slice_idx, Protocol__FlexDlSlice *dl_slice);
@@ -125,6 +129,10 @@ void flexran_agent_read_slice_ul_config(mid_t mod_id, int slice_idx, Protocol__F
  * applied later by performing a diff between slice_config and sc_update */
 void prepare_update_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *slice);
 
+/* apply generic slice parameters (e.g. intra-/interslice sharing activated or
+ * not) if there are changes. Returns the number of changed parameters. */
+int apply_new_slice_config(mid_t mod_id, Protocol__FlexSliceConfig *olds, Protocol__FlexSliceConfig *news);
+
 /* apply new configuration of slice in DL if there are changes between the
  * parameters. Returns the number of changed parameters. */
 int apply_new_slice_dl_config(mid_t mod_id, Protocol__FlexDlSlice *oldc, Protocol__FlexDlSlice *newc);
diff --git a/openair2/ENB_APP/MESSAGES/V2/config_messages.proto b/openair2/ENB_APP/MESSAGES/V2/config_messages.proto
index b186193b8c..0dd5140efa 100644
--- a/openair2/ENB_APP/MESSAGES/V2/config_messages.proto
+++ b/openair2/ENB_APP/MESSAGES/V2/config_messages.proto
@@ -44,16 +44,16 @@ message flex_cell_config {
 	optional int32 dl_pdsch_power = 38;       // operating downlink power 
 	optional int32 ul_pusch_power = 39;       // operating uplink power
 
-	// whether remaining RBs after first intra-slice allocation will
-	// be allocated to UEs of the same slice
-	optional bool   intraslice_share_active = 40;
-	// whether remaining RBs after slice allocation will be allocated
-	// to UEs of another slice. Isolated slices will be ignored.
-	optional bool   interslice_share_active = 41;
 	optional flex_slice_config slice_config = 42;
 }
 
 message flex_slice_config {
+	// whether remaining RBs after first intra-slice allocation will
+	// be allocated to UEs of the same slice
+	optional bool   intraslice_share_active = 4;
+	// whether remaining RBs after slice allocation will be allocated
+	// to UEs of another slice. Isolated slices will be ignored.
+	optional bool   interslice_share_active = 3;
 	repeated flex_dl_slice dl = 1;
 	repeated flex_ul_slice ul = 2;
 }
-- 
GitLab