From 2a1f5ac5ed7581361d428b7522a659216e11974f Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 28 Oct 2024 15:28:54 +0100 Subject: [PATCH] Introduce library for E1AP message encoding/decoding --- openair2/COMMON/e1ap_messages_types.h | 4 +- openair2/COMMON/ngap_messages_types.h | 1 + openair2/E1AP/CMakeLists.txt | 7 +- openair2/E1AP/lib/CMakeLists.txt | 9 +++ .../E1AP/lib/e1ap_bearer_context_management.c | 39 +++++++++++ .../E1AP/lib/e1ap_bearer_context_management.h | 29 ++++++++ openair2/E1AP/lib/e1ap_lib_common.h | 69 +++++++++++++++++++ openair2/E1AP/lib/e1ap_lib_includes.h | 25 +++++++ openair2/E1AP/tests/CMakeLists.txt | 6 ++ openair2/E1AP/tests/e1ap_lib_test.c | 35 ++++++++++ 10 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 openair2/E1AP/lib/CMakeLists.txt create mode 100644 openair2/E1AP/lib/e1ap_bearer_context_management.c create mode 100644 openair2/E1AP/lib/e1ap_bearer_context_management.h create mode 100644 openair2/E1AP/lib/e1ap_lib_common.h create mode 100644 openair2/E1AP/lib/e1ap_lib_includes.h create mode 100644 openair2/E1AP/tests/CMakeLists.txt create mode 100644 openair2/E1AP/tests/e1ap_lib_test.c diff --git a/openair2/COMMON/e1ap_messages_types.h b/openair2/COMMON/e1ap_messages_types.h index 107d7038f3..3d096c33e0 100644 --- a/openair2/COMMON/e1ap_messages_types.h +++ b/openair2/COMMON/e1ap_messages_types.h @@ -27,8 +27,8 @@ #include #include #include "common/ngran_types.h" -#include "f1ap_messages_types.h" -#include "ngap_messages_types.h" +#include "common/platform_types.h" +#include "common/5g_platform_types.h" /* Definitions according to 3GPP TS 38.463 */ #define E1AP_MAX_NUM_TRANSAC_IDS 4 diff --git a/openair2/COMMON/ngap_messages_types.h b/openair2/COMMON/ngap_messages_types.h index cdba1c5e2d..2ac5652a9f 100644 --- a/openair2/COMMON/ngap_messages_types.h +++ b/openair2/COMMON/ngap_messages_types.h @@ -29,6 +29,7 @@ #ifndef NGAP_MESSAGES_TYPES_H_ #define NGAP_MESSAGES_TYPES_H_ +#include "common/5g_platform_types.h" #include "common/platform_constants.h" #include "common/platform_types.h" #include "common/5g_platform_types.h" diff --git a/openair2/E1AP/CMakeLists.txt b/openair2/E1AP/CMakeLists.txt index c7657eed5a..5849a32fe5 100644 --- a/openair2/E1AP/CMakeLists.txt +++ b/openair2/E1AP/CMakeLists.txt @@ -1,7 +1,12 @@ add_subdirectory(MESSAGES) +add_subdirectory(lib) add_library(e1ap e1ap.c e1ap_common.c) target_link_libraries(e1ap - PUBLIC asn1_e1ap f1ap + PUBLIC asn1_e1ap e1ap_lib PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs asn1_f1ap UTIL e1_if) target_include_directories(e1ap PUBLIC ${CMAKE_CURRENT_DIR}) + +if(ENABLE_TESTS) + add_subdirectory(tests) +endif() diff --git a/openair2/E1AP/lib/CMakeLists.txt b/openair2/E1AP/lib/CMakeLists.txt new file mode 100644 index 0000000000..6e766581fa --- /dev/null +++ b/openair2/E1AP/lib/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(e1ap_lib OBJECT + e1ap_bearer_context_management.c +) + +target_link_libraries(e1ap_lib PRIVATE asn1_e1ap) +target_include_directories(e1ap_lib PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + diff --git a/openair2/E1AP/lib/e1ap_bearer_context_management.c b/openair2/E1AP/lib/e1ap_bearer_context_management.c new file mode 100644 index 0000000000..c9ac400df0 --- /dev/null +++ b/openair2/E1AP/lib/e1ap_bearer_context_management.c @@ -0,0 +1,39 @@ +/* + * 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 + */ + +/*! \file e1ap_bearer_context_management.c + * \brief E1AP library for E1 Bearer Context Management + * \author Guido Casati + * \date 2024 + * \version 0.1 + */ + +#include + +#include "common/utils/assertions.h" +#include "openair3/UTILS/conversions.h" +#include "common/utils/oai_asn1.h" +#include "common/utils/utils.h" + +#include "e1ap_lib_common.h" +#include "e1ap_bearer_context_management.h" +#include "e1ap_lib_includes.h" + diff --git a/openair2/E1AP/lib/e1ap_bearer_context_management.h b/openair2/E1AP/lib/e1ap_bearer_context_management.h new file mode 100644 index 0000000000..1fccb91442 --- /dev/null +++ b/openair2/E1AP/lib/e1ap_bearer_context_management.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 E1AP_BEARER_CONTEXT_MANAGEMENT_H_ +#define E1AP_BEARER_CONTEXT_MANAGEMENT_H_ + +#include +#include "openair2/COMMON/e1ap_messages_types.h" +#include "common/platform_types.h" + +#endif /* E1AP_BEARER_CONTEXT_MANAGEMENT_H_ */ diff --git a/openair2/E1AP/lib/e1ap_lib_common.h b/openair2/E1AP/lib/e1ap_lib_common.h new file mode 100644 index 0000000000..f3c6b24da2 --- /dev/null +++ b/openair2/E1AP/lib/e1ap_lib_common.h @@ -0,0 +1,69 @@ +/* + * 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 E1AP_LIB_COMMON_H_ +#define E1AP_LIB_COMMON_H_ + +#include +#include +#include +#include "openair3/UTILS/conversions.h" + +#ifdef ENABLE_TESTS +#define PRINT_ERROR(...) fprintf(stderr, ##__VA_ARGS__); +#else +#define PRINT_ERROR(...) // Do nothing +#endif + +#define _E1_EQ_CHECK_GENERIC(condition, fmt, ...) \ + do { \ + if (!(condition)) { \ + PRINT_ERROR("E1 Equality Check failure: %s:%d: Condition '%s' failed: " fmt " != " fmt "\n", \ + __FILE__, \ + __LINE__, \ + #condition, \ + ##__VA_ARGS__); \ + return false; \ + } \ + } while (0) + +#define _E1_EQ_CHECK_LONG(A, B) _E1_EQ_CHECK_GENERIC(A == B, "%ld", A, B); +#define _E1_EQ_CHECK_INT(A, B) _E1_EQ_CHECK_GENERIC(A == B, "%d", A, B); +#define _E1_EQ_CHECK_STR(A, B) _E1_EQ_CHECK_GENERIC(strcmp(A, B) == 0, "'%s'", A, B); + +// Macro to look up IE. If mandatory and not found, macro will log an error and return false. +#define E1AP_LIB_FIND_IE(IE_TYPE, ie, container, IE_ID, mandatory) \ + do { \ + ie = NULL; \ + for (int i = 0; i < (container)->protocolIEs.list.count; ++i) { \ + IE_TYPE *current_ie = (container)->protocolIEs.list.array[i]; \ + if (current_ie->id == (IE_ID)) { \ + ie = current_ie; \ + break; \ + } \ + } \ + if (mandatory && ie == NULL) { \ + fprintf(stderr, "%s(): Mandatory element not found: ID" #IE_ID " with type " #IE_TYPE "\n", __func__); \ + return false; \ + } \ + } while (0) + +#endif /* E1AP_LIB_COMMON_H_ */ diff --git a/openair2/E1AP/lib/e1ap_lib_includes.h b/openair2/E1AP/lib/e1ap_lib_includes.h new file mode 100644 index 0000000000..7f64db3da8 --- /dev/null +++ b/openair2/E1AP/lib/e1ap_lib_includes.h @@ -0,0 +1,25 @@ +/* + * 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 E1AP_LIB_INCLUDES_H_ +#define E1AP_LIB_INCLUDES_H_ + +#endif /* E1AP_LIB_INCLUDES_H_ */ diff --git a/openair2/E1AP/tests/CMakeLists.txt b/openair2/E1AP/tests/CMakeLists.txt new file mode 100644 index 0000000000..cd45e89384 --- /dev/null +++ b/openair2/E1AP/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(e1ap_lib_test e1ap_lib_test.c) +add_dependencies(tests e1ap_lib_test) +add_test(NAME e1ap_lib_test COMMAND e1ap_lib_test) +target_link_libraries(e1ap_lib_test PRIVATE e1ap_lib) +target_link_libraries(e1ap_lib_test PRIVATE asn1_f1ap) +target_include_directories(e1ap_lib_test PRIVATE ../../../) diff --git a/openair2/E1AP/tests/e1ap_lib_test.c b/openair2/E1AP/tests/e1ap_lib_test.c new file mode 100644 index 0000000000..ae2871f27d --- /dev/null +++ b/openair2/E1AP/tests/e1ap_lib_test.c @@ -0,0 +1,35 @@ +/* + * 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 + */ + +/*! \file e1ap_lib_test.c + * \brief Unit tests for E1AP libraries + * \author Guido Casati + * \date 2024 + * \version 0.1 + */ + +#include +#include +#include + +#include "common/utils/assertions.h" +#include "e1ap.h" +