From e7db367c9d61f20147738d190fa8478bf21743af Mon Sep 17 00:00:00 2001 From: Teodora Date: Mon, 7 Jul 2025 15:03:59 +0200 Subject: [PATCH] Rearrange , , and RPCs Refactor these RPCs to facilitate their use in other Management functionalities, not only Configuration Management. --- radio/fhi_72/mplane/config-mplane.c | 44 +++++++++---------- radio/fhi_72/mplane/config-mplane.h | 6 +-- radio/fhi_72/mplane/connect-mplane.c | 5 +++ radio/fhi_72/mplane/init-mplane.c | 18 +++++--- radio/fhi_72/mplane/ru-mplane-api.h | 1 + radio/fhi_72/mplane/yang/create-yang-config.c | 28 ++++++------ radio/fhi_72/mplane/yang/create-yang-config.h | 2 +- radio/fhi_72/mplane/yang/get-yang.c | 4 +- radio/fhi_72/mplane/yang/get-yang.h | 2 +- 9 files changed, 58 insertions(+), 52 deletions(-) diff --git a/radio/fhi_72/mplane/config-mplane.c b/radio/fhi_72/mplane/config-mplane.c index 69ff1fd2b3..da28665023 100644 --- a/radio/fhi_72/mplane/config-mplane.c +++ b/radio/fhi_72/mplane/config-mplane.c @@ -21,14 +21,12 @@ #include "config-mplane.h" #include "rpc-send-recv.h" -#include "yang/get-yang.h" -#include "yang/create-yang-config.h" #include "common/utils/assertions.h" #include #include -bool edit_config_mplane(ru_session_t *ru_session, const char *buffer, const openair0_config_t *oai, const size_t num_rus) +static bool edit_config_mplane(ru_session_t *ru_session, const char *content) { int timeout = CLI_RPC_REPLY_TIMEOUT; struct nc_rpc *rpc; @@ -39,37 +37,21 @@ bool edit_config_mplane(ru_session_t *ru_session, const char *buffer, const open NC_RPC_EDIT_TESTOPT test = NC_RPC_EDIT_TESTOPT_UNKNOWN; NC_RPC_EDIT_ERROPT err = NC_RPC_EDIT_ERROPT_UNKNOWN; - bool success = false; - - struct ly_ctx *ctx = NULL; - success = load_yang_models(ru_session, buffer, &ctx); - AssertError(success, return false, "[MPLANE] Unable to continue.\n"); - - char *content = NULL; - success = configure_ru_from_yang(&ctx, ru_session, oai, num_rus, &content); - AssertError(success, return false, "[MPLANE] Unable to create content for RPC.\n"); - MP_LOG_I("RPC request to RU \"%s\" = :\n%s\n", ru_session->ru_ip_add, content); rpc = nc_rpc_edit(target, op, test, err, content, param); AssertError(rpc != NULL, return false, "[MPLANE] RPC creation failed.\n"); - success = rpc_send_recv((struct nc_session *)ru_session->session, rpc, wd, timeout, NULL); + bool success = rpc_send_recv((struct nc_session *)ru_session->session, rpc, wd, timeout, NULL); AssertError(success, return false, "[MPLANE] Failed to edit configuration for the candidate datastore.\n"); MP_LOG_I("Successfully edited the candidate datastore for RU \"%s\".\n", ru_session->ru_ip_add); nc_rpc_free(rpc); - free(content); -#ifdef MPLANE_V1 - ly_ctx_destroy(ctx, NULL); -#elif defined MPLANE_V2 - ly_ctx_destroy(ctx); -#endif return true; } -bool validate_config_mplane(ru_session_t *ru_session) +static bool validate_config_mplane(ru_session_t *ru_session) { int timeout = CLI_RPC_REPLY_TIMEOUT; struct nc_rpc *rpc; @@ -92,7 +74,7 @@ bool validate_config_mplane(ru_session_t *ru_session) return true; } -bool commit_config_mplane(ru_session_t *ru_session) +static bool commit_config_mplane(ru_session_t *ru_session) { int timeout = CLI_RPC_REPLY_TIMEOUT; struct nc_rpc *rpc; @@ -109,9 +91,25 @@ bool commit_config_mplane(ru_session_t *ru_session) bool success = rpc_send_recv((struct nc_session *)ru_session->session, rpc, wd, timeout, NULL); AssertError(success, return false, "[MPLANE] Failed to commit candidate datastore.\n"); - MP_LOG_I("Successfully commited CU-planes configuration into running datastore for RU \"%s\".\n", ru_session->ru_ip_add); + MP_LOG_I("Successfully commited configuration into running datastore for RU \"%s\".\n", ru_session->ru_ip_add); nc_rpc_free(rpc); return true; } + +bool edit_val_commmit_rpc(ru_session_t *ru_session, const char *content) +{ + bool success = false; + + success = edit_config_mplane(ru_session, content); + AssertError(success, return false, "[MPLANE] Unable to edit the RU configuration.\n"); + + success = validate_config_mplane(ru_session); + AssertError(success, return false, "[MPLANE] Unable to validate the RU configuration.\n"); + + success = commit_config_mplane(ru_session); + AssertError(success, return false, "[MPLANE] Unable to commit the RU configuration.\n"); + + return success; +} diff --git a/radio/fhi_72/mplane/config-mplane.h b/radio/fhi_72/mplane/config-mplane.h index c8451ca8a0..dae2dbea63 100644 --- a/radio/fhi_72/mplane/config-mplane.h +++ b/radio/fhi_72/mplane/config-mplane.h @@ -25,10 +25,6 @@ #include "ru-mplane-api.h" #include "radio/COMMON/common_lib.h" -bool edit_config_mplane(ru_session_t *ru_session, const char *buffer, const openair0_config_t *oai, const size_t num_rus); - -bool validate_config_mplane(ru_session_t *ru_session); - -bool commit_config_mplane(ru_session_t *ru_session); +bool edit_val_commmit_rpc(ru_session_t *ru_session, const char *content); #endif /* CONFIGURE_MPLANE_H */ diff --git a/radio/fhi_72/mplane/connect-mplane.c b/radio/fhi_72/mplane/connect-mplane.c index 08b758bef1..c63cc3d0c1 100644 --- a/radio/fhi_72/mplane/connect-mplane.c +++ b/radio/fhi_72/mplane/connect-mplane.c @@ -67,6 +67,11 @@ void disconnect_mplane(void *rus_disconnect) MP_LOG_I("Disconnecting from RU \"%s\".\n", ru_session->ru_ip_add); nc_session_free(ru_session->session, NULL); ru_session->session = NULL; +#ifdef MPLANE_V1 + ly_ctx_destroy((struct ly_ctx *)ru_session->ctx, NULL); +#elif defined MPLANE_V2 + ly_ctx_destroy((struct ly_ctx *)ru_session->ctx); +#endif } nc_client_destroy(); diff --git a/radio/fhi_72/mplane/init-mplane.c b/radio/fhi_72/mplane/init-mplane.c index 39e8cfb995..200333398d 100644 --- a/radio/fhi_72/mplane/init-mplane.c +++ b/radio/fhi_72/mplane/init-mplane.c @@ -25,6 +25,8 @@ #include "subscribe-mplane.h" #include "config-mplane.h" #include "xml/get-xml.h" +#include "yang/get-yang.h" +#include "yang/create-yang-config.h" #include #include @@ -175,15 +177,17 @@ bool manage_ru(ru_session_t *ru_session, const openair0_config_t *oai, const siz success = get_uplane_info(operational_ds, &ru_session->ru_mplane_config); AssertError(success, return false, "[MPLANE] Unable to get U-plane info from RU operational datastore.\n"); + success = load_yang_models(ru_session, operational_ds); + AssertError(success, return false, "[MPLANE] Unable to load yang models.\n"); + if (ru_session->ru_notif.ptp_state) { - success = edit_config_mplane(ru_session, operational_ds, oai, num_rus); - AssertError(success, return false, "[MPLANE] Unable to edit the RU configuration.\n"); + char *content = NULL; + success = configure_ru_from_yang(ru_session, oai, num_rus, &content); + AssertError(success, return false, "[MPLANE] Unable to create content for RPC for start-up procedure.\n"); - success = validate_config_mplane(ru_session); - AssertError(success, return false, "[MPLANE] Unable to validate the RU configuration.\n"); - - success = commit_config_mplane(ru_session); - AssertError(success, return false, "[MPLANE] Unable to commit the RU configuration.\n"); + success = edit_val_commmit_rpc(ru_session, content); + AssertError(success, return false, "[MPLANE] Unable to continue.\n"); + free(content); } const char *usage_state = get_ru_xml_node(operational_ds, "usage-state"); diff --git a/radio/fhi_72/mplane/ru-mplane-api.h b/radio/fhi_72/mplane/ru-mplane-api.h index df6a89042f..581c0a164d 100644 --- a/radio/fhi_72/mplane/ru-mplane-api.h +++ b/radio/fhi_72/mplane/ru-mplane-api.h @@ -85,6 +85,7 @@ typedef struct { char *ru_ip_add; ru_mplane_config_t ru_mplane_config; void *session; + void *ctx; xran_mplane_t xran_mplane; ru_notif_t ru_notif; diff --git a/radio/fhi_72/mplane/yang/create-yang-config.c b/radio/fhi_72/mplane/yang/create-yang-config.c index dac1ee810e..78281a558a 100644 --- a/radio/fhi_72/mplane/yang/create-yang-config.c +++ b/radio/fhi_72/mplane/yang/create-yang-config.c @@ -26,11 +26,11 @@ const char *scs_name[] = {"KHZ_15", "KHZ_30", "KHZ_60", "KHZ_120", "KHZ_240", NULL}; #ifdef MPLANE_V2 -static bool create_cu_interface_v2(struct ly_ctx **ctx, const ru_session_t *ru_session, const size_t idx, const char *int_name, struct lyd_node **root) +static bool create_cu_interface_v2(const ru_session_t *ru_session, const size_t idx, const char *int_name, struct lyd_node **root) { LY_ERR ret = LY_SUCCESS; - ret = lyd_new_path(NULL, *ctx, "/ietf-interfaces:interfaces", NULL, 0, root); + ret = lyd_new_path(NULL, (struct ly_ctx *)ru_session->ctx, "/ietf-interfaces:interfaces", NULL, 0, root); VERIFY_SUCCESS(ret == LY_SUCCESS, "[MPLANE] Failed to create root \"interfaces\" node.\n"); struct lyd_node *interface_node = NULL; @@ -44,7 +44,7 @@ static bool create_cu_interface_v2(struct ly_ctx **ctx, const ru_session_t *ru_s ret = lyd_new_term(interface_node, NULL, "enabled", "true", 0, NULL); VERIFY_SUCCESS(ret == LY_SUCCESS, "[MPLANE] Failed to create \"enabled\" node.\n"); - const struct lys_module *oran_int_mod = ly_ctx_get_module_implemented(*ctx, "o-ran-interfaces"); + const struct lys_module *oran_int_mod = ly_ctx_get_module_implemented((struct ly_ctx *)ru_session->ctx, "o-ran-interfaces"); VERIFY_SUCCESS(oran_int_mod != NULL, "[MPLANE] Failed to get \"o-ran-interfaces\" module.\n"); struct lyd_node *base_int = NULL; @@ -64,11 +64,11 @@ static bool create_cu_interface_v2(struct ly_ctx **ctx, const ru_session_t *ru_s return true; } -static bool create_proc_elem_v2(struct ly_ctx **ctx, const ru_session_t *ru_session, const size_t idx, const char *int_name, struct lyd_node **root) +static bool create_proc_elem_v2(const ru_session_t *ru_session, const size_t idx, const char *int_name, struct lyd_node **root) { LY_ERR ret = LY_SUCCESS; - ret = lyd_new_path(NULL, *ctx, "/o-ran-processing-element:processing-elements", NULL, 0, root); + ret = lyd_new_path(NULL, (struct ly_ctx *)ru_session->ctx, "/o-ran-processing-element:processing-elements", NULL, 0, root); VERIFY_SUCCESS(ret == LY_SUCCESS, "[MPLANE] Failed to create root \"processing-elements\" node.\n"); ret = lyd_new_term(*root, NULL, "transport-session-type", "ETH-INTERFACE", 0, NULL); @@ -225,12 +225,12 @@ static bool fill_uplane_ch_tx_v2(const xran_mplane_t *xran_mplane, const openair return true; } -static bool create_uplane_conf_v2(struct ly_ctx **ctx, const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, const char *u_proc_elem, struct lyd_node **root) +static bool create_uplane_conf_v2(const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, const char *u_proc_elem, struct lyd_node **root) { LY_ERR ret = LY_SUCCESS; bool success = true; - ret = lyd_new_path(NULL, *ctx, "/o-ran-uplane-conf:user-plane-configuration", NULL, 0, root); + ret = lyd_new_path(NULL, (struct ly_ctx *)ru_session->ctx, "/o-ran-uplane-conf:user-plane-configuration", NULL, 0, root); VERIFY_SUCCESS(ret == LY_SUCCESS, "[MPLANE] Failed to create root \"user-plane-configuration\" node.\n"); if (ru_session->ru_mplane_config.rx_carriers.num != 1 || ru_session->ru_mplane_config.tx_carriers.num !=1) @@ -398,7 +398,7 @@ static bool create_uplane_conf_v2(struct ly_ctx **ctx, const ru_session_t *ru_se } #endif -bool configure_ru_from_yang(struct ly_ctx **ctx, const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, char **result) +bool configure_ru_from_yang(const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, char **result) { bool success = false; @@ -420,12 +420,12 @@ bool configure_ru_from_yang(struct ly_ctx **ctx, const ru_session_t *ru_session, struct lyd_node *cu_interface = NULL; char int_name[12]; snprintf(int_name, sizeof(int_name), "INTERFACE_%ld", i); - success = create_cu_interface_v2(ctx, ru_session, i, int_name, &cu_interface); + success = create_cu_interface_v2(ru_session, i, int_name, &cu_interface); VERIFY_SUCCESS(success, "[MPLANE] Cannot create CU-plane interface.\n"); // struct lyd_node *proc_elem = NULL; - success = create_proc_elem_v2(ctx, ru_session, i, int_name, &proc_elem); + success = create_proc_elem_v2(ru_session, i, int_name, &proc_elem); VERIFY_SUCCESS(success, "[MPLANE] Cannot create CU-plane processing element.\n"); ret = lyd_merge_siblings(&all_merge, cu_interface, 0); @@ -439,13 +439,13 @@ bool configure_ru_from_yang(struct ly_ctx **ctx, const ru_session_t *ru_session, // struct lyd_node *uplane_conf = NULL; - success = create_uplane_conf_v2(ctx, ru_session, oai, num_rus, "PLANE_0", &uplane_conf); + success = create_uplane_conf_v2(ru_session, oai, num_rus, "PLANE_0", &uplane_conf); VERIFY_SUCCESS(success, "[MPLANE] Cannot create U-plane configuration.\n"); - - ret = lyd_merge_siblings(&uplane_conf, all_merge, 0); + + ret = lyd_merge_siblings(&all_merge, uplane_conf, 0); VERIFY_SUCCESS(ret == LY_SUCCESS, "[MPLANE] Cannot merge CU-plane interface, processing element and U-plane configuration.\n"); - lyd_print_mem(result, uplane_conf, LYD_XML, LYD_PRINT_WITHSIBLINGS); + lyd_print_mem(result, all_merge, LYD_XML, LYD_PRINT_WITHSIBLINGS); lyd_free_siblings(all_merge); lyd_free_siblings(uplane_conf); diff --git a/radio/fhi_72/mplane/yang/create-yang-config.h b/radio/fhi_72/mplane/yang/create-yang-config.h index 9e06bdc923..45c8f6ea1c 100644 --- a/radio/fhi_72/mplane/yang/create-yang-config.h +++ b/radio/fhi_72/mplane/yang/create-yang-config.h @@ -27,6 +27,6 @@ #include -bool configure_ru_from_yang(struct ly_ctx **ctx, const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, char **result); +bool configure_ru_from_yang(const ru_session_t *ru_session, const openair0_config_t *oai, const size_t num_rus, char **result); #endif /* CREATE_MPLANE_YANG_CONFIG_H */ diff --git a/radio/fhi_72/mplane/yang/get-yang.c b/radio/fhi_72/mplane/yang/get-yang.c index c27454136f..e06128846f 100644 --- a/radio/fhi_72/mplane/yang/get-yang.c +++ b/radio/fhi_72/mplane/yang/get-yang.c @@ -95,8 +95,10 @@ static bool load_from_operational_ds(xmlNode *node, ru_session_t *ru_session, st return false; } -bool load_yang_models(ru_session_t *ru_session, const char *buffer, struct ly_ctx **ctx) +bool load_yang_models(ru_session_t *ru_session, const char *buffer) { + struct ly_ctx **ctx = (struct ly_ctx **)&ru_session->ctx; + // Initialize the xml file size_t len = strlen(buffer) + 1; xmlDoc *doc = xmlReadMemory(buffer, len, NULL, NULL, 0); diff --git a/radio/fhi_72/mplane/yang/get-yang.h b/radio/fhi_72/mplane/yang/get-yang.h index 5956bde203..7ca191d234 100644 --- a/radio/fhi_72/mplane/yang/get-yang.h +++ b/radio/fhi_72/mplane/yang/get-yang.h @@ -26,6 +26,6 @@ #include -bool load_yang_models(ru_session_t *ru_session, const char *buffer, struct ly_ctx **ctx); +bool load_yang_models(ru_session_t *ru_session, const char *buffer); #endif /* GET_MPLANE_YANG_MODELS_H */