diff --git a/radio/fhi_72/mplane/connect-mplane.c b/radio/fhi_72/mplane/connect-mplane.c index 7f4e5e40e6..08b758bef1 100644 --- a/radio/fhi_72/mplane/connect-mplane.c +++ b/radio/fhi_72/mplane/connect-mplane.c @@ -55,3 +55,19 @@ bool connect_mplane(ru_session_t *ru_session) return true; } + +void disconnect_mplane(void *rus_disconnect) +{ + ru_session_list_t *ru_session_list = (ru_session_list_t *)rus_disconnect; + + for (size_t i = 0; i num_rus; i++) { + ru_session_t *ru_session = &ru_session_list->ru_session[i]; + if (ru_session->session == NULL) + continue; + MP_LOG_I("Disconnecting from RU \"%s\".\n", ru_session->ru_ip_add); + nc_session_free(ru_session->session, NULL); + ru_session->session = NULL; + } + + nc_client_destroy(); +} diff --git a/radio/fhi_72/mplane/connect-mplane.h b/radio/fhi_72/mplane/connect-mplane.h index 5283e6ef75..e46aa60f19 100644 --- a/radio/fhi_72/mplane/connect-mplane.h +++ b/radio/fhi_72/mplane/connect-mplane.h @@ -26,4 +26,6 @@ bool connect_mplane(ru_session_t *ru_session); +void disconnect_mplane(void *rus_disconnect); + #endif /* CONNECT_MPLANE_H */ diff --git a/radio/fhi_72/mplane/init-mplane.c b/radio/fhi_72/mplane/init-mplane.c index 352a564cec..39e8cfb995 100644 --- a/radio/fhi_72/mplane/init-mplane.c +++ b/radio/fhi_72/mplane/init-mplane.c @@ -186,6 +186,18 @@ bool manage_ru(ru_session_t *ru_session, const openair0_config_t *oai, const siz AssertError(success, return false, "[MPLANE] Unable to commit the RU configuration.\n"); } + const char *usage_state = get_ru_xml_node(operational_ds, "usage-state"); + MP_LOG_I("Usage state = \"%s\" for RU \"%s\".\n", usage_state, ru_session->ru_ip_add); + if (strcmp(usage_state, "busy") == 0) { // carriers are already activated + ru_session->ru_notif.rx_carrier_state = true; + ru_session->ru_notif.tx_carrier_state = true; + ru_session->ru_notif.config_change = true; + } else { + ru_session->ru_notif.rx_carrier_state = false; + ru_session->ru_notif.tx_carrier_state = false; + ru_session->ru_notif.config_change = false; + } + free(operational_ds); free(watchdog_answer); diff --git a/radio/fhi_72/mplane/ru-mplane-api.h b/radio/fhi_72/mplane/ru-mplane-api.h index 1afabd4d23..70857adea6 100644 --- a/radio/fhi_72/mplane/ru-mplane-api.h +++ b/radio/fhi_72/mplane/ru-mplane-api.h @@ -35,6 +35,7 @@ typedef struct { bool ptp_state; bool rx_carrier_state; bool tx_carrier_state; + bool config_change; // to be extended with any notification callback } ru_notif_t; diff --git a/radio/fhi_72/mplane/subscribe-mplane.c b/radio/fhi_72/mplane/subscribe-mplane.c index d96d367d35..9a8e28c4c1 100644 --- a/radio/fhi_72/mplane/subscribe-mplane.c +++ b/radio/fhi_72/mplane/subscribe-mplane.c @@ -79,6 +79,8 @@ static void recv_notif_v2(struct lyd_node_inner *op, ru_notif_t *answer) } else { // "DISABLED" or "BUSY" answer->tx_carrier_state = false; } + } else if (strcmp(notif, "netconf-config-change") == 0) { + answer->config_change = true; } } diff --git a/radio/fhi_72/oran_isolate.c b/radio/fhi_72/oran_isolate.c index 8104b1a2c2..a5e2d5baf7 100644 --- a/radio/fhi_72/oran_isolate.c +++ b/radio/fhi_72/oran_isolate.c @@ -49,6 +49,7 @@ typedef struct { rru_config_msg_type_t last_msg; int capabilities_sent; void *oran_priv; + void *mplane_priv; } oran_eth_state_t; notifiedFIFO_t oran_sync_fifo; @@ -81,6 +82,10 @@ int trx_oran_stop(openair0_device *device) printf("ORAN: %s\n", __FUNCTION__); oran_eth_state_t *s = device->priv; xran_stop(s->oran_priv); +#ifdef OAI_MPLANE + printf("[MPLANE] Stopping M-plane.\n"); + disconnect_mplane(s->mplane_priv); +#endif return (0); } @@ -304,6 +309,41 @@ __attribute__((__visibility__("default"))) int transport_init(openair0_device *d } ru_configured[i] = manage_ru(ru_session, openair0_cfg, ru_session_list.num_rus); } + + bool all_ok = true; + bool ru_ready[ru_session_list.num_rus]; + for (size_t i = 0; i < ru_session_list.num_rus; i++) { + if (!ru_configured[i]) { + MP_LOG_I("RU with IP %s couldn't be configured.\n", ru_session_list.ru_session[i].ru_ip_add); + all_ok = false; + } + ru_ready[i] = false; + } + + if (!all_ok) { + disconnect_mplane((void *)&ru_session_list); + AssertFatal(false, "[MPLANE] Stopping M-plane.\n"); + } + + while (true) { + sleep(1); + bool all_rus_ready = true; + for (int i = 0; i < ru_session_list.num_rus; i++) { + ru_session_t *ru_session = &ru_session_list.ru_session[i]; + if (!ru_ready[i] && ru_session->ru_notif.config_change && ru_session->ru_notif.rx_carrier_state && ru_session->ru_notif.tx_carrier_state) { + MP_LOG_I("RU \"%s\" is now ready.\n", ru_session->ru_ip_add); + ru_ready[i] = true; + } else { + all_rus_ready = false; + break; + } + } + if (all_rus_ready) { + break; + } + } + + eth->mplane_priv = (void *)&ru_session_list; #else success = get_xran_config(openair0_cfg, &fh_init, fh_config); AssertFatal(success, "cannot get configuration for xran\n");