From 97a648e35fff860309f10fe31f8ed421aee84d4c Mon Sep 17 00:00:00 2001
From: Melissa Elkadi <melissa@episci.com>
Date: Wed, 28 Jul 2021 15:36:11 -0700
Subject: [PATCH] IP Traffic not working, tun if established by NRUE

Updated the configuration files. Added a sleep to
ensure that the LTE UE gets attached to the EPC
before the bearer is modified to be gNB. Updated
the ifconfig tunnel up command to be brought up
by the NR UE socket when in NSA mode. Lastly,
started the gNB PDCP layer in S1 mode.
---
 .../conf_files/rcc.band7.tm1.nfapi.conf       |  8 +-
 executables/nr-softmodem.c                    |  2 +-
 executables/nr-uesoftmodem.c                  |  2 +-
 openair2/RRC/LTE/rrc_UE.c                     |  2 +-
 openair2/RRC/LTE/rrc_eNB_S1AP.c               | 13 ++--
 openair3/NAS/UE/ESM/esm_ebr_context.c         | 75 ++++++++++++-------
 .../CONF/rcc.band78.tm1.106PRB.nfapi.conf     |  6 +-
 7 files changed, 64 insertions(+), 44 deletions(-)

diff --git a/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
index 08080a5182b..4e596f81b59 100644
--- a/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
+++ b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
@@ -172,7 +172,7 @@ eNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.61.3";
+    mme_ip_address      = ( { ipv4       = "192.168.61.195";
                               ipv6       = "192:168:30::17";
                               port       = 36412 ;
                               active     = "yes";
@@ -180,7 +180,7 @@ eNBs =
                             }
                           );
 
-    enable_measurement_reports = "no";
+    enable_measurement_reports = "yes";
 
     ///X2
     enable_x2 = "yes";
@@ -191,9 +191,9 @@ eNBs =
 
     NETWORK_INTERFACES :
     {
-        ENB_INTERFACE_NAME_FOR_S1_MME            = "ctrl";
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "ctrl0";
         ENB_IPV4_ADDRESS_FOR_S1_MME              = "172.16.0.1";
-        ENB_INTERFACE_NAME_FOR_S1U               = "ctrl";
+        ENB_INTERFACE_NAME_FOR_S1U               = "ctrl0";
         ENB_IPV4_ADDRESS_FOR_S1U                 = "172.16.0.1";
         ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
         ENB_IPV4_ADDRESS_FOR_X2C                 = "172.16.0.1";
diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 50be7537406..0f7ccfb6e67 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -722,7 +722,7 @@ if(!IS_SOFTMODEM_NOS1)
 #endif
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
 
-  if(IS_SOFTMODEM_NOS1)
+  if(!IS_SOFTMODEM_NOS1)
     init_pdcp();
 
   if (RC.nb_nr_L1_inst > 0)
diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index b26e192dcf9..6eaf13ff609 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -469,8 +469,8 @@ void init_pdcp(int ue_id) {
   /*if (rlc_module_init() != 0) {
     LOG_I(RLC, "Problem at RLC initiation \n");
   }
-  pdcp_layer_init();
   nr_DRB_preconfiguration();*/
+  pdcp_layer_init();
   nr_pdcp_module_init(pdcp_initmask, ue_id);
   pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
   pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c
index c1077eaa3d6..51bcc40f806 100644
--- a/openair2/RRC/LTE/rrc_UE.c
+++ b/openair2/RRC/LTE/rrc_UE.c
@@ -4624,7 +4624,7 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint
             if (is_state_connected && is_t304_inactive && have_meas_flag) {
               LOG_I(RRC,"[UE %d] Frame %d: Triggering generation of Meas Report for NR_r15. count = %d\n",
                     ctxt_pP->module_id, ctxt_pP->frame, ue->subframeCount);
-
+              usleep(200000);
               if (ue->measReportList[i][j] == NULL) {
                 ue->measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
               }
diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c
index d34b4164a20..7e457a025ae 100644
--- a/openair2/RRC/LTE/rrc_eNB_S1AP.c
+++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c
@@ -592,14 +592,20 @@ rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
   S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
 
   for (e_rab = 0; e_rab < ue_context_pP->ue_context.nb_of_e_rabs; e_rab++) {
-    if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+   if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE || ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_TOMODIFY) {
       e_rabs_done++;
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
       // TODO add other information from S1-U when it will be integrated
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab];
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab];
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.length = 4;
-      ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+      if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+        ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+        S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
+        S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
+        itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+      }
+
     } else {
       e_rabs_failed++;
       ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
@@ -618,9 +624,6 @@ rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
     ue_context_pP->ue_id_rnti,
     S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).eNB_ue_s1ap_id,
     e_rabs_done, e_rabs_failed);
-  S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
-  S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
-  itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
 }
 
 //------------------------------------------------------------------------------
diff --git a/openair3/NAS/UE/ESM/esm_ebr_context.c b/openair3/NAS/UE/ESM/esm_ebr_context.c
index db935453d81..6ba3fc2a860 100644
--- a/openair3/NAS/UE/ESM/esm_ebr_context.c
+++ b/openair3/NAS/UE/ESM/esm_ebr_context.c
@@ -276,37 +276,37 @@ int esm_ebr_context_create(
                             ipv4_addr, ueid + 10000,
                             UE_NAS_USE_TUN ? "oaitun_ue" : "oip",
                             ueid + 1, ueid + 10000);
-
-              res = sprintf(command_line,
-                            "ip address add %s/%d broadcast %s dev %s%d && "
-                            "ip link set %s%d up && "
-                            "ip rule add from %s/32 table %d && "
-                            "ip rule add to %s/32 table %d && "
-                            "ip route add default dev %s%d table %d",
-                            ipv4_addr, netmask, broadcast,
-                            UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
-                            UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
-                            ipv4_addr, ueid + 10000,
-                            ipv4_addr, ueid + 10000,
-                            UE_NAS_USE_TUN ? "oaitun_ue" : "oip",
-                            ueid + 1, ueid + 10000);
-
-              if ( res<0 ) {
-                LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
-              }
-
-              /* Calling system() here disrupts UE's realtime processing in some cases.
-               * This may be because of the call to fork(), which, for some
-               * unidentified reason, interacts badly with other (realtime) threads.
-               * background_system() is a replacement mechanism relying on a
-               * background process that does the system() and reports result to
-               * the parent process (lte-softmodem, oaisim, ...). The background
-               * process is created very early in the life of the parent process.
-               * The processes interact through standard pipes. See
-               * common/utils/system.c for details.
-               */
               if (get_softmodem_params()->nsa == 0)
               {
+                res = sprintf(command_line,
+                              "ip address add %s/%d broadcast %s dev %s%d && "
+                              "ip link set %s%d up && "
+                              "ip rule add from %s/32 table %d && "
+                              "ip rule add to %s/32 table %d && "
+                              "ip route add default dev %s%d table %d",
+                              ipv4_addr, netmask, broadcast,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
+                              ipv4_addr, ueid + 10000,
+                              ipv4_addr, ueid + 10000,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip",
+                              ueid + 1, ueid + 10000);
+
+                if ( res<0 ) {
+                  LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
+                }
+
+                /* Calling system() here disrupts UE's realtime processing in some cases.
+                * This may be because of the call to fork(), which, for some
+                * unidentified reason, interacts badly with other (realtime) threads.
+                * background_system() is a replacement mechanism relying on a
+                * background process that does the system() and reports result to
+                * the parent process (lte-softmodem, oaisim, ...). The background
+                * process is created very early in the life of the parent process.
+                * The processes interact through standard pipes. See
+                * common/utils/system.c for details.
+                */
+
                 LOG_TRACE(INFO, "Melissa Elkadi ESM-PROC  - executing %s ",
                         command_line);
                 if (background_system(command_line) != 0)
@@ -315,6 +315,23 @@ int esm_ebr_context_create(
                 }
               }
               else if (get_softmodem_params()->nsa) {
+                res = sprintf(command_line,
+                              "ip address add %s/%d broadcast %s dev %s%d && "
+                              "ip link set %s%d up && "
+                              "ip rule add from %s/32 table %d && "
+                              "ip rule add to %s/32 table %d && "
+                              "ip route add default dev %s%d table %d",
+                              ipv4_addr, netmask, broadcast,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip", ueid + 1,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip", ueid + 1,
+                              ipv4_addr, ueid + 10000,
+                              ipv4_addr, ueid + 10000,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip",
+                              ueid + 1, ueid + 10000);
+
+                if ( res<0 ) {
+                  LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
+                }
                 LOG_I(NAS, "Melissa Elkadi, sending NAS_OAI_TUN_NSA msg to LTE UE via itti\n");
                 MessageDef *msg_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_OAI_TUN_NSA);
                 memcpy(NAS_OAI_TUN_NSA(msg_p).buffer, command_line, sizeof(NAS_OAI_TUN_NSA(msg_p).buffer));
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band78.tm1.106PRB.nfapi.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band78.tm1.106PRB.nfapi.conf
index 00c7ef6346d..638e1340a48 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band78.tm1.106PRB.nfapi.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band78.tm1.106PRB.nfapi.conf
@@ -225,7 +225,7 @@ gNBs =
 
 
     ////////// MME parameters:
-    mme_ip_address      = ( { ipv4       = "192.168.61.3";
+    mme_ip_address      = ( { ipv4       = "192.168.61.195";
                               ipv6       = "192:168:30::17";
                               active     = "yes";
                               preference = "ipv4";
@@ -248,9 +248,9 @@ gNBs =
     {   # All of these have to be IP addr of gNB
                 # if in CORE container, make it 172.16.0.X
                 # if not launched in CORE, can set to lo (127.0.0.2)
-        GNB_INTERFACE_NAME_FOR_S1_MME            = "ctrl";
+        GNB_INTERFACE_NAME_FOR_S1_MME            = "ctrl0";
         GNB_IPV4_ADDRESS_FOR_S1_MME              = "172.16.0.2";
-        GNB_INTERFACE_NAME_FOR_S1U               = "ctrl";
+        GNB_INTERFACE_NAME_FOR_S1U               = "ctrl0";
         GNB_IPV4_ADDRESS_FOR_S1U                 = "172.16.0.2";
         GNB_PORT_FOR_S1U                         = 2152; # Spec 2152
         GNB_IPV4_ADDRESS_FOR_X2C                 = "172.16.0.2";
-- 
GitLab