diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index d97ec3a10d..29cb7caeda 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -571,6 +571,50 @@ void init_pdcp(void) { } } +#ifdef E2_AGENT +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); + const gNB_RRC_INST* rrc = RC.nrrrc[0]; + assert(rrc != NULL && "rrc cannot be NULL"); + + const int mcc = rrc->configuration.mcc[0]; + const int mnc = rrc->configuration.mnc[0]; + const int mnc_digit_len = rrc->configuration.mnc_digit_length[0]; + // const ngran_node_t node_type = rrc->node_type; + int nb_id = 0; + int cu_du_id = 0; + if (node_type == ngran_gNB) { + nb_id = rrc->nr_cellid; + } else if (node_type == ngran_gNB_DU) { + AssertFatal(rrc->node_id != 0, "cannot handle node ID 0, please change gNB_ID\n"); + cu_du_id = rrc->node_id; + nb_id = rrc->nr_cellid; + } else if (node_type == ngran_gNB_CU) { + AssertFatal(rrc->node_id != 0, "cannot handle node ID 0, please change gNB_ID\n"); + cu_du_id = rrc->node_id; + nb_id = rrc->nr_cellid; + } else { + LOG_E(NR_RRC, "not supported ran type detect\n"); + } + + 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_du_id, node_type, io, &args); +} +#endif + configmodule_interface_t *uniqCfg = NULL; int main( int argc, char **argv ) { int ru_id, CC_id = 0; @@ -689,54 +733,18 @@ int main( int argc, char **argv ) { config_sync_var=0; - - #ifdef E2_AGENT ////////////////////////////////// ////////////////////////////////// //// Init the E2 Agent - sm_io_ag_ran_t io = init_ran_func_ag(); - // OAI Wrapper e2_agent_args_t oai_args = RCconfig_NR_E2agent(); - 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); - const gNB_RRC_INST* rrc = RC.nrrrc[0]; - assert(rrc != NULL && "rrc cannot be NULL"); - - const int mcc = rrc->configuration.mcc[0]; - const int mnc = rrc->configuration.mnc[0]; - const int mnc_digit_len = rrc->configuration.mnc_digit_length[0]; - // const ngran_node_t node_type = rrc->node_type; - int nb_id = 0; - int cu_du_id = 0; - if (node_type == ngran_gNB) { - nb_id = rrc->configuration.cell_identity; - } else if (node_type == ngran_gNB_DU) { - cu_du_id = rrc->node_id + 1; // Hack to avoid been 0 - nb_id = rrc->configuration.cell_identity; - } else if (node_type == ngran_gNB_CU) { - cu_du_id = rrc->node_id + 1; - nb_id = rrc->configuration.cell_identity; - } else { - LOG_E(NR_RRC, "not supported ran type detect\n"); + if (oai_args.enabled) { + initialize_agent(node_type, oai_args); } - - 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); - init_agent_api(mcc, mnc, mnc_digit_len, nb_id, cu_du_id, node_type, io, &args); -// } #endif // E2_AGENT diff --git a/openair2/E2AP/e2_agent_arg.h b/openair2/E2AP/e2_agent_arg.h index b719c32d97..30f1ce4750 100644 --- a/openair2/E2AP/e2_agent_arg.h +++ b/openair2/E2AP/e2_agent_arg.h @@ -28,6 +28,7 @@ typedef struct{ const char *ip; const char *sm_dir; + const bool enabled; } e2_agent_args_t; #endif diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c index c57f5205f9..a360369c94 100644 --- a/openair2/ENB_APP/enb_config.c +++ b/openair2/ENB_APP/enb_config.c @@ -2942,7 +2942,18 @@ e2_agent_args_t RCconfig_E2agent(void) 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, }; diff --git a/openair2/ENB_APP/enb_paramdef.h b/openair2/ENB_APP/enb_paramdef.h index 6417d3cb75..626705317b 100644 --- a/openair2/ENB_APP/enb_paramdef.h +++ b/openair2/ENB_APP/enb_paramdef.h @@ -1330,9 +1330,8 @@ typedef struct srb1_params_s { //#define E2AGENT_CONFIG_PORT "port" #define E2AGENT_CONFIG_SMDIR "sm_dir" -static const char* const e2agent_config_ip_default = NULL; -static const char* const e2agent_config_smdir_default = NULL; -//static const uint16_t e2agent_config_port_default = 36421; +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}, \ diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index 24b2e639b8..17e74f4608 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -2281,7 +2281,14 @@ e2_agent_args_t RCconfig_NR_E2agent(void) 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 }; } - e2_agent_args_t dst = {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;