From 81547750f3f9222b99d91bc4354aa4c7f7815d63 Mon Sep 17 00:00:00 2001 From: Xin Zhe Khooi Date: Sun, 18 Feb 2024 02:55:20 +0000 Subject: [PATCH 1/5] added telnetsrv_rrc for rrc release --- common/utils/telnetsrv/CMakeLists.txt | 7 +- common/utils/telnetsrv/telnetsrv_rrc.c | 108 +++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 common/utils/telnetsrv/telnetsrv_rrc.c diff --git a/common/utils/telnetsrv/CMakeLists.txt b/common/utils/telnetsrv/CMakeLists.txt index d7b9b3cf9d..a7a364d80e 100644 --- a/common/utils/telnetsrv/CMakeLists.txt +++ b/common/utils/telnetsrv/CMakeLists.txt @@ -64,8 +64,13 @@ add_library(telnetsrv_bearer MODULE telnetsrv_bearer.c) target_link_libraries(telnetsrv_bearer PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_dependencies(telnetsrv telnetsrv_bearer) +message(STATUS "Add RRC specific telnet functions in libtelnetsrv_rrc.so") +add_library(telnetsrv_rrc MODULE telnetsrv_rrc.c) +target_link_libraries(telnetsrv_rrc PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) +add_dependencies(telnetsrv telnetsrv_rrc) + # all libraries should be written to root build dir -set_target_properties(telnetsrv telnetsrv_enb telnetsrv_5Gue telnetsrv_ci telnetsrv_bearer +set_target_properties(telnetsrv telnetsrv_enb telnetsrv_5Gue telnetsrv_ci telnetsrv_bearer telnetsrv_rrc PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../.. ) diff --git a/common/utils/telnetsrv/telnetsrv_rrc.c b/common/utils/telnetsrv/telnetsrv_rrc.c new file mode 100644 index 0000000000..ad5ca94c43 --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_rrc.c @@ -0,0 +1,108 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include "openair2/RRC/NR/rrc_gNB_UE_context.h" + +#define TELNETSERVERCODE +#include "telnetsrv.h" + +#define ERROR_MSG_RET(mSG, aRGS...) do { prnt(mSG, ##aRGS); return 1; } while (0) + +static int get_single_ue_id(void) +{ + rrc_gNB_ue_context_t *ue_context_p = NULL; + RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &(RC.nrrrc[0]->rrc_ue_head)) { + return ue_context_p->ue_context.rrc_ue_id; + } + return -1; +} + +int rrc_gNB_trigger_release(char *buf, int debug, telnet_printfunc_t prnt) { + ue_id_t ue_id = -1; + protocol_ctxt_t ctxt; + gNB_RRC_INST *rrc = RC.nrrrc[0]; + + if (!buf) { + ue_id = get_single_ue_id(); + if (ue_id < 1) { + prnt("no UE found\n"); + ERROR_MSG_RET("no UE found\n"); + } + } else { + ue_id = strtol(buf, NULL, 10); + if (ue_id < 1 || ue_id >= 0xfffffe) { + prnt("UE ID needs to be [1,0xfffffe]\n"); + ERROR_MSG_RET("UE ID needs to be [1,0xfffffe]\n"); + } + } + + /* get RRC and UE */ + rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(rrc, ue_id); + if (!ue_context_p) { + prnt("Could not find UE context associated with UE ID %u\n", ue_id); + LOG_E(RRC, "Could not find UE context associated with UE ID %u\n", ue_id); + return -1; + } + gNB_RRC_UE_t *UE = &ue_context_p->ue_context; + + PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, 0, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0); + ctxt.eNB_index = 0; + + rrc_gNB_generate_RRCRelease(&ctxt, ue_context_p); + prnt("RRC Release triggered for UE %u\n", ue_id); + + return 0; +} + +int rrc_gNB_trigger_release_all(char *buf, int debug, telnet_printfunc_t prnt) { + rrc_gNB_ue_context_t *ue_context_p = NULL; + protocol_ctxt_t ctxt; + RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &(RC.nrrrc[0]->rrc_ue_head)) { + gNB_RRC_UE_t *UE = &ue_context_p->ue_context; + PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, 0, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0); + ctxt.eNB_index = 0; + rrc_gNB_generate_RRCRelease(&ctxt, ue_context_p); + prnt("RRC Release triggered for UE %u\n", UE->rrc_ue_id); + } + return -1; +} + +static telnetshell_cmddef_t rrc_cmds[] = { + {"release_rrc", "[rrc_ue_id(int,opt)]", rrc_gNB_trigger_release}, + {"release_rrc_all", "", rrc_gNB_trigger_release_all}, + {"", "", NULL}, +}; + +static telnetshell_vardef_t rrc_vars[] = { + {"", 0, 0, NULL} +}; + +void add_rrc_cmds(void) { + add_telnetcmd("rrc", rrc_vars, rrc_cmds); +} From 4003936da580faba038d093dc518f5dd8e800ac1 Mon Sep 17 00:00:00 2001 From: Xin Zhe Khooi Date: Sun, 18 Feb 2024 02:57:09 +0000 Subject: [PATCH 2/5] telnetsrv_rrc: resolve warning --- common/utils/telnetsrv/telnetsrv_rrc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/utils/telnetsrv/telnetsrv_rrc.c b/common/utils/telnetsrv/telnetsrv_rrc.c index ad5ca94c43..3e879aa988 100644 --- a/common/utils/telnetsrv/telnetsrv_rrc.c +++ b/common/utils/telnetsrv/telnetsrv_rrc.c @@ -65,8 +65,8 @@ int rrc_gNB_trigger_release(char *buf, int debug, telnet_printfunc_t prnt) { /* get RRC and UE */ rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(rrc, ue_id); if (!ue_context_p) { - prnt("Could not find UE context associated with UE ID %u\n", ue_id); - LOG_E(RRC, "Could not find UE context associated with UE ID %u\n", ue_id); + prnt("Could not find UE context associated with UE ID %lu\n", ue_id); + LOG_E(RRC, "Could not find UE context associated with UE ID %lu\n", ue_id); return -1; } gNB_RRC_UE_t *UE = &ue_context_p->ue_context; From 819f7c1d22b3e9df5e71b4c0949145905b6a357e Mon Sep 17 00:00:00 2001 From: Xin Zhe Khooi Date: Sun, 18 Feb 2024 03:23:00 +0000 Subject: [PATCH 3/5] telnetsrv_rrc: clean up and documentation --- common/utils/telnetsrv/telnetsrv_rrc.c | 37 +++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/common/utils/telnetsrv/telnetsrv_rrc.c b/common/utils/telnetsrv/telnetsrv_rrc.c index 3e879aa988..464fb99853 100644 --- a/common/utils/telnetsrv/telnetsrv_rrc.c +++ b/common/utils/telnetsrv/telnetsrv_rrc.c @@ -34,6 +34,18 @@ #define ERROR_MSG_RET(mSG, aRGS...) do { prnt(mSG, ##aRGS); return 1; } while (0) +/** + * Module brief: + * This module is used to add RRCRelease commands to the telnet server in the + * absence of full support for E2SM RAN Control (RC) function in the RIC. + * This provides similar functionality to the ORAN.WG3.E2SM-RC-R003-v05.00 + * 8.4.5.4 RRC Connection Release Control which is initiated by the RIC. + * + * Implementation notes: + * We refer to the method call rrc_gNB_generate_RRCRelease at rrc_gNB_NGAP.c + * during rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND message generation. +*/ + static int get_single_ue_id(void) { rrc_gNB_ue_context_t *ue_context_p = NULL; @@ -43,16 +55,22 @@ static int get_single_ue_id(void) return -1; } +/** + * @brief Trigger RRC Release for a specific UE + * @param buf: RRC UE ID + * @param debug: Debug flag + * @param prnt: Print function + * @return 0 on success, -1 on failure +*/ int rrc_gNB_trigger_release(char *buf, int debug, telnet_printfunc_t prnt) { ue_id_t ue_id = -1; protocol_ctxt_t ctxt; - gNB_RRC_INST *rrc = RC.nrrrc[0]; if (!buf) { ue_id = get_single_ue_id(); if (ue_id < 1) { - prnt("no UE found\n"); - ERROR_MSG_RET("no UE found\n"); + prnt("No UE found!\n"); + ERROR_MSG_RET("No UE found!\n"); } } else { ue_id = strtol(buf, NULL, 10); @@ -63,14 +81,15 @@ int rrc_gNB_trigger_release(char *buf, int debug, telnet_printfunc_t prnt) { } /* get RRC and UE */ + gNB_RRC_INST *rrc = RC.nrrrc[0]; rrc_gNB_ue_context_t *ue_context_p = rrc_gNB_get_ue_context(rrc, ue_id); if (!ue_context_p) { prnt("Could not find UE context associated with UE ID %lu\n", ue_id); LOG_E(RRC, "Could not find UE context associated with UE ID %lu\n", ue_id); return -1; } + gNB_RRC_UE_t *UE = &ue_context_p->ue_context; - PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, 0, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0); ctxt.eNB_index = 0; @@ -80,17 +99,23 @@ int rrc_gNB_trigger_release(char *buf, int debug, telnet_printfunc_t prnt) { return 0; } +/** + * @brief Trigger RRC Release for all UEs +*/ int rrc_gNB_trigger_release_all(char *buf, int debug, telnet_printfunc_t prnt) { rrc_gNB_ue_context_t *ue_context_p = NULL; - protocol_ctxt_t ctxt; + protocol_ctxt_t ctxt; /* Not sure what exactly is this */ + RB_FOREACH(ue_context_p, rrc_nr_ue_tree_s, &(RC.nrrrc[0]->rrc_ue_head)) { gNB_RRC_UE_t *UE = &ue_context_p->ue_context; PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, 0, GNB_FLAG_YES, UE->rrc_ue_id, 0, 0); ctxt.eNB_index = 0; + rrc_gNB_generate_RRCRelease(&ctxt, ue_context_p); prnt("RRC Release triggered for UE %u\n", UE->rrc_ue_id); } - return -1; + + return 0; } static telnetshell_cmddef_t rrc_cmds[] = { From 13521c681f2f63463e8368b7697351f0b3d1d921 Mon Sep 17 00:00:00 2001 From: Xin Zhe Khooi Date: Sun, 18 Feb 2024 03:24:10 +0000 Subject: [PATCH 4/5] telnetsrv_rrc: update documentation --- common/utils/telnetsrv/telnetsrv_rrc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/telnetsrv/telnetsrv_rrc.c b/common/utils/telnetsrv/telnetsrv_rrc.c index 464fb99853..b7ded95802 100644 --- a/common/utils/telnetsrv/telnetsrv_rrc.c +++ b/common/utils/telnetsrv/telnetsrv_rrc.c @@ -37,7 +37,7 @@ /** * Module brief: * This module is used to add RRCRelease commands to the telnet server in the - * absence of full support for E2SM RAN Control (RC) function in the RIC. + * absence of full support for E2SM RAN Control (RC). * This provides similar functionality to the ORAN.WG3.E2SM-RC-R003-v05.00 * 8.4.5.4 RRC Connection Release Control which is initiated by the RIC. * From 7ca22db7d25de732f1a97597ebb8655d2cfa6df5 Mon Sep 17 00:00:00 2001 From: Xin Zhe Khooi Date: Sun, 18 Feb 2024 03:29:31 +0000 Subject: [PATCH 5/5] telnetsrv_rrc: update documentation on building and usage --- common/utils/telnetsrv/telnetsrv_rrc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/utils/telnetsrv/telnetsrv_rrc.c b/common/utils/telnetsrv/telnetsrv_rrc.c index b7ded95802..aab85a825f 100644 --- a/common/utils/telnetsrv/telnetsrv_rrc.c +++ b/common/utils/telnetsrv/telnetsrv_rrc.c @@ -44,6 +44,12 @@ * Implementation notes: * We refer to the method call rrc_gNB_generate_RRCRelease at rrc_gNB_NGAP.c * during rrc_gNB_process_NGAP_UE_CONTEXT_RELEASE_COMMAND message generation. + * + * Building the telnetsrv and module: + * ./build_oai --build-lib telnetsrv + * + * Loading the module: + * sudo ./nr-softmodem --sa -E --rfsim --log_config.global_log_options level,nocolor,time -O ~/gnb.sa.band78.106prb.rfsim.conf --telnetsrv --telnetsrv.shrmod rrc */ static int get_single_ue_id(void)