From 3f98ec50ef5cab9e2813dbb74c0b4cfd2745c024 Mon Sep 17 00:00:00 2001 From: Teodora Date: Mon, 3 Feb 2025 12:15:42 +0100 Subject: [PATCH] Add ssh connect function for M-plane --- radio/fhi_72/mplane/CMakeLists.txt | 1 + radio/fhi_72/mplane/connect-mplane.c | 57 ++++++++++++++++++++++++++++ radio/fhi_72/mplane/connect-mplane.h | 29 ++++++++++++++ radio/fhi_72/oran_isolate.c | 10 +++++ 4 files changed, 97 insertions(+) create mode 100644 radio/fhi_72/mplane/connect-mplane.c create mode 100644 radio/fhi_72/mplane/connect-mplane.h diff --git a/radio/fhi_72/mplane/CMakeLists.txt b/radio/fhi_72/mplane/CMakeLists.txt index 7cc53dd40f..b699c35094 100644 --- a/radio/fhi_72/mplane/CMakeLists.txt +++ b/radio/fhi_72/mplane/CMakeLists.txt @@ -26,6 +26,7 @@ target_compile_definitions(oran_fhlib_5g_mplane PRIVATE OAI_MPLANE) target_sources(oran_fhlib_5g_mplane PRIVATE init-mplane.c + connect-mplane.c ) pkg_check_modules(libyang REQUIRED libyang) diff --git a/radio/fhi_72/mplane/connect-mplane.c b/radio/fhi_72/mplane/connect-mplane.c new file mode 100644 index 0000000000..7f4e5e40e6 --- /dev/null +++ b/radio/fhi_72/mplane/connect-mplane.c @@ -0,0 +1,57 @@ +/* + * 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 "connect-mplane.h" +#include "common/utils/assertions.h" + +#include +#include + +static int my_auth_hostkey_check(const char *hostname, ssh_session session, void *priv) +{ + (void)hostname; + (void)session; + (void)priv; + + return 0; +} + +bool connect_mplane(ru_session_t *ru_session) +{ + int port = NC_PORT_SSH; + char *user = "oranbenetel"; + + nc_client_ssh_set_username(user); + + nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PUBLICKEY, 1); // ssh-key identification + nc_client_ssh_set_auth_pref(NC_SSH_AUTH_PASSWORD, -1); + nc_client_ssh_set_auth_pref(NC_SSH_AUTH_INTERACTIVE, -1); + + nc_client_ssh_set_auth_hostkey_check_clb(my_auth_hostkey_check, "DATA"); // host-key identification + + MP_LOG_I("RPC request to RU \"%s\" = with username \"%s\" and port ID \"%d\".\n", ru_session->ru_ip_add, user, port); + ru_session->session = nc_connect_ssh(ru_session->ru_ip_add, port, NULL); + AssertError(ru_session->session != NULL, return false, "[MPLANE] RU IP address %s unreachable. Maybe M-plane is disabled on the RU?\n", ru_session->ru_ip_add); + + MP_LOG_I("Successfuly connected to RU \"%s\" with username \"%s\" and port ID \"%d\".\n", ru_session->ru_ip_add, user, port); + + return true; +} diff --git a/radio/fhi_72/mplane/connect-mplane.h b/radio/fhi_72/mplane/connect-mplane.h new file mode 100644 index 0000000000..5283e6ef75 --- /dev/null +++ b/radio/fhi_72/mplane/connect-mplane.h @@ -0,0 +1,29 @@ +/* + * 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 CONNECT_MPLANE_H +#define CONNECT_MPLANE_H + +#include "ru-mplane-api.h" + +bool connect_mplane(ru_session_t *ru_session); + +#endif /* CONNECT_MPLANE_H */ diff --git a/radio/fhi_72/oran_isolate.c b/radio/fhi_72/oran_isolate.c index 0221892c37..a249924731 100644 --- a/radio/fhi_72/oran_isolate.c +++ b/radio/fhi_72/oran_isolate.c @@ -41,6 +41,7 @@ #ifdef OAI_MPLANE #include "mplane/init-mplane.h" +#include "mplane/connect-mplane.h" #endif typedef struct { @@ -293,6 +294,15 @@ __attribute__((__visibility__("default"))) int transport_init(openair0_device *d ru_session_list_t ru_session_list = {0}; success = init_mplane(&ru_session_list); AssertFatal(success, "[MPLANE] Cannot initialize M-plane.\n"); + + bool ru_configured[ru_session_list.num_rus]; + for (size_t i = 0; i < ru_session_list.num_rus; i++) { + ru_session_t *ru_session = &ru_session_list.ru_session[i]; + ru_configured[i] = connect_mplane(ru_session); + if (!ru_configured[i]) { + continue; + } + } #else success = get_xran_config(openair0_cfg, &fh_init, fh_config); AssertFatal(success, "cannot get configuration for xran\n");