From 56843fc1d72f6bfb718459996d0e4471c1bf7440 Mon Sep 17 00:00:00 2001 From: Teodora Date: Wed, 17 Jan 2024 15:51:52 +0100 Subject: [PATCH] Add E2 agent in CU-UP --- CMakeLists.txt | 8 +++-- executables/nr-cuup.c | 53 +++++++++++++++++++++++++++++++ executables/nr-softmodem.c | 2 +- openair2/E2AP/CMakeLists.txt | 1 + openair2/E2AP/e2_agent_arg.c | 50 +++++++++++++++++++++++++++++ openair2/E2AP/e2_agent_arg.h | 4 +++ openair2/E2AP/e2_agent_paramdef.h | 42 ++++++++++++++++++++++++ openair2/ENB_APP/enb_config.c | 32 ------------------- openair2/ENB_APP/enb_paramdef.h | 25 --------------- openair2/GNB_APP/gnb_config.c | 30 ----------------- 10 files changed, 157 insertions(+), 90 deletions(-) create mode 100644 openair2/E2AP/e2_agent_arg.c create mode 100644 openair2/E2AP/e2_agent_paramdef.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ddda5d3e07..bd1c3d0618 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1433,7 +1433,7 @@ target_link_libraries(L2 PRIVATE x2ap s1ap lte_rrc m2ap) target_link_libraries(L2 PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) if(E2_AGENT) - target_link_libraries(L2 PUBLIC e2_agent e2_ran_func) + target_link_libraries(L2 PUBLIC e2_agent e2_agent_arg e2_ran_func) target_compile_definitions(L2 PRIVATE E2_AGENT) target_compile_definitions(L2 PRIVATE ${E2AP_VERSION} ${KPM_VERSION}) endif() @@ -1460,7 +1460,7 @@ target_link_libraries(e1_if PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs asn1_f1ap target_link_libraries(L2_NR PRIVATE f1ap x2ap s1ap ngap nr_rrc e1ap nr_rlc) if(E2_AGENT) - target_link_libraries(L2_NR PUBLIC e2_agent e2_ran_func) + target_link_libraries(L2_NR PUBLIC e2_agent e2_agent_arg e2_ran_func) target_compile_definitions(L2_NR PRIVATE ${E2AP_VERSION} ${KPM_VERSION}) target_compile_definitions(L2_NR PRIVATE E2_AGENT) endif() @@ -2114,6 +2114,10 @@ target_link_libraries(nr-cuup PRIVATE GTPV1U e1ap f1ap SIMU_ETH z sctp dl pthread shlib_loader ${T_LIB}) target_link_libraries(nr-cuup PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) +if(E2_AGENT) + target_link_libraries(nr-cuup PRIVATE e2_agent e2_agent_arg) # RAN functions to be added + target_compile_definitions(nr-cuup PRIVATE ${E2AP_VERSION} ${KPM_VERSION} E2_AGENT) +endif() # nr-uesoftmodem is UE implementation ####################################### diff --git a/executables/nr-cuup.c b/executables/nr-cuup.c index 5fb66bc73a..d78f671a05 100644 --- a/executables/nr-cuup.c +++ b/executables/nr-cuup.c @@ -39,6 +39,43 @@ int asn1_xer_print; int oai_exit = 0; instance_t CUuniqInstance = 0; +#ifdef E2_AGENT +#include "openair2/E2AP/flexric/src/agent/e2_agent_api.h" +#include "openair2/E2AP/RAN_FUNCTION/init_ran_func.h" + +static void initialize_agent(ngran_node_t node_type, e2_agent_args_t oai_args) +{ + AssertFatal(oai_args.sm_dir != NULL , "Please, specify the directory where the SMs are located in the config file, i.e., add in config file the next line: e2_agent = {near_ric_ip_addr = \"127.0.0.1\"; sm_dir = \"/usr/local/lib/flexric/\");} "); + AssertFatal(oai_args.ip != NULL , "Please, specify the IP address of the nearRT-RIC in the config file, i.e., e2_agent = {near_ric_ip_addr = \"127.0.0.1\"; sm_dir = \"/usr/local/lib/flexric/\""); + + printf("After RCconfig_NR_E2agent %s %s \n",oai_args.sm_dir, oai_args.ip ); + + fr_args_t args = { .ip = oai_args.ip }; // init_fr_args(0, NULL); + memcpy(args.libs_dir, oai_args.sm_dir, 128); + + sleep(1); + + // Only 1 instances is supported in one executable + // Advice: run multiple executables to have multiple instances + const e1ap_upcp_inst_t *e1inst = getCxtE1(CUuniqInstance); + + const int nb_id = e1inst->gnb_id; + const int cu_up_id = e1inst->cuup.setupReq.gNB_cu_up_id; + const int mcc = e1inst->cuup.setupReq.plmn[0].id.mcc; + const int mnc = e1inst->cuup.setupReq.plmn[0].id.mnc; + const int mnc_digit_len = e1inst->cuup.setupReq.plmn[0].id.mnc_digit_length; + // const ngran_node_t node_type = ngran_gNB_CUUP; + + printf("[E2 NODE]: mcc = %d mnc = %d mnc_digit = %d nb_id = %d \n", mcc, mnc, mnc_digit_len, nb_id); + + printf("[E2 NODE]: Args %s %s \n", args.ip, args.libs_dir); + + // sm_io_ag_ran_t io = init_ran_func_ag(); + // init_agent_api(mcc, mnc, mnc_digit_len, nb_id, cu_up_id, node_type, io, &args); +} +#endif // E2_AGENT + + void exit_function(const char *file, const char *function, const int line, const char *s, const int assert) { if (assert) { @@ -135,6 +172,22 @@ int main(int argc, char **argv) AssertFatal(msg != NULL, "Send init to task for E1AP UP failed\n"); itti_send_msg_to_task(TASK_CUUP_E1, 0, msg); + #ifdef E2_AGENT + ////////////////////////////////// + ////////////////////////////////// + //// Init the E2 Agent + + // OAI Wrapper + e2_agent_args_t oai_args = RCconfig_NR_E2agent(); + + if (oai_args.enabled) { + const ngran_node_t node_type = get_node_type(); + assert(node_type == ngran_gNB_CUUP); + initialize_agent(node_type, oai_args); + } + + #endif // E2_AGENT + printf("TYPE TO TERMINATE\n"); itti_wait_tasks_end(NULL); diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index aa8dd6025e..ad24e55755 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -600,7 +600,7 @@ static void initialize_agent(ngran_node_t node_type, e2_agent_args_t oai_args) AssertFatal(mac != NULL, "MAC not initialized\n"); cu_du_id = mac->f1_config.gnb_id; nb_id = mac->f1_config.setup_req->gNB_DU_id; - } else if (node_type == ngran_gNB_CU) { + } else if (node_type == ngran_gNB_CU || node_type == ngran_gNB_CUCP) { // agent buggy: the CU has no second ID, it is the CU-UP ID // however, that is not a problem her for us, so put the same ID twice nb_id = rrc->node_id; diff --git a/openair2/E2AP/CMakeLists.txt b/openair2/E2AP/CMakeLists.txt index c5603849a3..c7f79ae06f 100644 --- a/openair2/E2AP/CMakeLists.txt +++ b/openair2/E2AP/CMakeLists.txt @@ -128,3 +128,4 @@ add_subdirectory(flexric/src/sm) add_subdirectory(flexric/src/util) add_subdirectory(RAN_FUNCTION) +add_library(e2_agent_arg STATIC e2_agent_arg.c) diff --git a/openair2/E2AP/e2_agent_arg.c b/openair2/E2AP/e2_agent_arg.c new file mode 100644 index 0000000000..ea0eee3f1a --- /dev/null +++ b/openair2/E2AP/e2_agent_arg.c @@ -0,0 +1,50 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "e2_agent_arg.h" +#include "e2_agent_paramdef.h" +#include "common/config/config_userapi.h" + +e2_agent_args_t RCconfig_NR_E2agent(void) +{ + paramdef_t e2agent_params[] = E2AGENT_PARAMS_DESC; + int ret = config_get(config_get_if(), e2agent_params, sizeofArray(e2agent_params), CONFIG_STRING_E2AGENT); + if (ret < 0) { + printf("configuration file does not contain a \"%s\" section, applying default parameters from FlexRIC\n", CONFIG_STRING_E2AGENT); + return (e2_agent_args_t) { 0 }; + } + + bool enabled = config_isparamset(e2agent_params, E2AGENT_CONFIG_SMDIR_IDX) + && config_isparamset(e2agent_params, E2AGENT_CONFIG_IP_IDX); + e2_agent_args_t dst = {.enabled = enabled}; + if (!enabled) { + printf("E2 agent is DISABLED (for activation, define .%s.{%s,%s} parameters)\n", CONFIG_STRING_E2AGENT, E2AGENT_CONFIG_IP, E2AGENT_CONFIG_SMDIR); + return dst; + } + + if (e2agent_params[E2AGENT_CONFIG_SMDIR_IDX].strptr != NULL) + dst.sm_dir = *e2agent_params[E2AGENT_CONFIG_SMDIR_IDX].strptr; + + if (e2agent_params[E2AGENT_CONFIG_IP_IDX].strptr != NULL) + dst.ip = *e2agent_params[E2AGENT_CONFIG_IP_IDX].strptr; + + return dst; +} diff --git a/openair2/E2AP/e2_agent_arg.h b/openair2/E2AP/e2_agent_arg.h index 30f1ce4750..48ec8b3a24 100644 --- a/openair2/E2AP/e2_agent_arg.h +++ b/openair2/E2AP/e2_agent_arg.h @@ -23,6 +23,8 @@ #define E2_AGENT_ARGS_H #include +#include +#include // Wrapper for OAI typedef struct{ @@ -31,6 +33,8 @@ typedef struct{ const bool enabled; } e2_agent_args_t; +e2_agent_args_t RCconfig_NR_E2agent(void); + #endif diff --git a/openair2/E2AP/e2_agent_paramdef.h b/openair2/E2AP/e2_agent_paramdef.h new file mode 100644 index 0000000000..8d68c8898a --- /dev/null +++ b/openair2/E2AP/e2_agent_paramdef.h @@ -0,0 +1,42 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef E2_AGENT_PARAMDEF_H_ +#define E2_AGENT_PARAMDEF_H_ + +/* E2 Agent configuration */ +#define CONFIG_STRING_E2AGENT "e2_agent" + +#define E2AGENT_CONFIG_IP "near_ric_ip_addr" +#define E2AGENT_CONFIG_SMDIR "sm_dir" + +static const char* const e2agent_config_ip_default = "127.0.0.1"; +static const char* const e2agent_config_smdir_default = "."; + +#define E2AGENT_PARAMS_DESC { \ + {E2AGENT_CONFIG_IP, "RIC IP address", 0, strptr:NULL, defstrval:(char*)e2agent_config_ip_default, TYPE_STRING, 0}, \ + {E2AGENT_CONFIG_SMDIR, "Directory with SMs to load", 0, strptr:NULL, defstrval:(char*)e2agent_config_smdir_default, TYPE_STRING, 0}, \ +} + +#define E2AGENT_CONFIG_IP_IDX 0 +#define E2AGENT_CONFIG_SMDIR_IDX 1 + +#endif diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c index a360369c94..0debcc3264 100644 --- a/openair2/ENB_APP/enb_config.c +++ b/openair2/ENB_APP/enb_config.c @@ -2931,35 +2931,3 @@ void read_config_and_init(void) { RCconfig_RRC(enb_id, RC.rrc[enb_id]); } } - -#ifdef E2_AGENT - -e2_agent_args_t RCconfig_E2agent(void) -{ - paramdef_t e2agent_params[] = E2AGENT_PARAMS_DESC; - int ret = config_get(config_get_if(), e2agent_params, sizeofArray(e2agent_params), CONFIG_STRING_E2AGENT); - if (ret < 0) { - LOG_W(GNB_APP, "configuration file does not contain a \"%s\" section, applying default parameters\n", CONFIG_STRING_E2AGENT); - return (e2_agent_args_t) {0}; - } - - bool enabled = config_isparamset(e2agent_params, E2AGENT_CONFIG_SMDIR_IDX) - && config_isparamset(e2agent_params, E2AGENT_CONFIG_IP_IDX); - if (!enabled) { - LOG_W(GNB_APP, "E2 agent is DISABLED (for activation, define .%s.{%s,%s} parameters)\n", CONFIG_STRING_E2AGENT, E2AGENT_CONFIG_IP, E2AGENT_CONFIG_SMDIR); - return (e2_agent_args_t) { - .enabled = false, - }; - } - - return (e2_agent_args_t) { - .enabled = true, - .ip = *e2agent_params[E2AGENT_CONFIG_IP_IDX].strptr, - .sm_dir = *e2agent_params[E2AGENT_CONFIG_SMDIR_IDX].strptr, - }; -} - - -#endif - - diff --git a/openair2/ENB_APP/enb_paramdef.h b/openair2/ENB_APP/enb_paramdef.h index 626705317b..ed3be8c024 100644 --- a/openair2/ENB_APP/enb_paramdef.h +++ b/openair2/ENB_APP/enb_paramdef.h @@ -1321,32 +1321,7 @@ typedef struct srb1_params_s { #define CONFIG_HLP_PARALLEL "PARALLEL_SINGLE_THREAD, PARALLEL_RU_L1_SPLIT, or PARALLEL_RU_L1_TRX_SPLIT(RU_L1_TRX_SPLIT by defult)\n" /*-------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#ifdef E2_AGENT -/* E2 Agent configuration */ -#define CONFIG_STRING_E2AGENT "e2_agent" - -#define E2AGENT_CONFIG_IP "near_ric_ip_addr" -//#define E2AGENT_CONFIG_PORT "port" -#define E2AGENT_CONFIG_SMDIR "sm_dir" - -static const char* const e2agent_config_ip_default = "127.0.0.1"; -static const char* const e2agent_config_smdir_default = "."; - -#define E2AGENT_PARAMS_DESC { \ - {E2AGENT_CONFIG_IP, "RIC IP address", 0, strptr:NULL, defstrval:(char*)e2agent_config_ip_default, TYPE_STRING, 0}, \ - {E2AGENT_CONFIG_SMDIR, "Directory with SMs to load", 0, strptr:NULL, defstrval:(char*)e2agent_config_smdir_default, TYPE_STRING, 0}, \ -} -/* -// {E2AGENT_CONFIG_PORT, "RIC port", 0, u16ptr:NULL, defuintval:e2agent_config_port_default, TYPE_UINT16, 0}, \ -} -*/ - -#define E2AGENT_CONFIG_IP_IDX 0 -#define E2AGENT_CONFIG_SMDIR_IDX 1 -//#define E2AGENT_CONFIG_PORT_IDX 2 - -#endif // E2_AGENT #include "enb_paramdef_emtc.h" diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index de0373e37a..8be6543010 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -2266,33 +2266,3 @@ ngran_node_t get_node_type(void) return ngran_gNB; } } - -#ifdef E2_AGENT - -e2_agent_args_t RCconfig_NR_E2agent(void) -{ - paramdef_t e2agent_params[] = E2AGENT_PARAMS_DESC; - int ret = config_get(config_get_if(), e2agent_params, sizeofArray(e2agent_params), CONFIG_STRING_E2AGENT); - if (ret < 0) { - LOG_W(GNB_APP, "configuration file does not contain a \"%s\" section, applying default parameters from FlexRIC\n", CONFIG_STRING_E2AGENT); - return (e2_agent_args_t) { 0 }; - } - - bool enabled = config_isparamset(e2agent_params, E2AGENT_CONFIG_SMDIR_IDX) - && config_isparamset(e2agent_params, E2AGENT_CONFIG_IP_IDX); - e2_agent_args_t dst = {.enabled = enabled}; - if (!enabled) { - LOG_W(GNB_APP, "E2 agent is DISABLED (for activation, define .%s.{%s,%s} parameters)\n", CONFIG_STRING_E2AGENT, E2AGENT_CONFIG_IP, E2AGENT_CONFIG_SMDIR); - return dst; - } - - if (e2agent_params[E2AGENT_CONFIG_SMDIR_IDX].strptr != NULL) - dst.sm_dir = *e2agent_params[E2AGENT_CONFIG_SMDIR_IDX].strptr; - - if (e2agent_params[E2AGENT_CONFIG_IP_IDX].strptr != NULL) - dst.ip = *e2agent_params[E2AGENT_CONFIG_IP_IDX].strptr; - - return dst; -} - -#endif // E2_AGENT