e3ap: add E3 agent configuration and CMake target

Add the E3AP CMake target, which links the external libe3 library
discovered via pkg-config, and the E3Configuration parser that reads
the link and transport selection from the gNB configuration file and
validates the supported link/transport combinations.

libe3 is kept external and is only required when E3_AGENT is enabled.

Signed-off-by: Andrea Lacava <thecave003@gmail.com>
This commit is contained in:
Andrea Lacava
2026-06-17 13:37:10 -04:00
parent 447ff67aba
commit 0a885dcf5a
4 changed files with 156 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ if(E2_AGENT)
endif()
if(E3_AGENT)
message(STATUS "Add E3 Agent capabilities")
#add_subdirectory(E3AP)
add_subdirectory(E3AP)
endif()
add_subdirectory(F1AP)
add_subdirectory(LAYER2)

View File

@@ -0,0 +1,44 @@
# SPDX-License-Identifier: LicenseRef-CSSL-1.0
find_package(PkgConfig REQUIRED)
pkg_check_modules(CLIBE3 REQUIRED libe3)
if(NOT CLIBE3_FOUND)
message(FATAL_ERROR "libe3 not found and required for E3 Agent")
endif()
message(STATUS "Using for E3AP libe3 version: ${CLIBE3_VERSION}")
include_directories(${CLIBE3_INCLUDE_DIRS})
# Set default encoding format if not specified
if(NOT DEFINED E3_ENCODING_FORMAT)
set(E3_ENCODING_FORMAT "ASN1" CACHE STRING "E3AP encoding format (ASN1 or JSON)")
endif()
# Validate encoding format
if(NOT E3_ENCODING_FORMAT MATCHES "^(ASN1|JSON)$")
message(FATAL_ERROR "Invalid E3_ENCODING_FORMAT: ${E3_ENCODING_FORMAT}. Must be ASN1 or JSON")
endif()
message(STATUS "E3AP encoding format: ${E3_ENCODING_FORMAT}")
add_library(e3ap config/e3_config.c)
# target_link_libraries(e3ap PUBLIC OCP_ITTI) # TODO
# Set encoding format compile definitions - both string value and format flags
target_compile_definitions(e3ap PRIVATE E3_ENCODING_FORMAT="${E3_ENCODING_FORMAT}")
if(E3_ENCODING_FORMAT STREQUAL "ASN1")
target_compile_definitions(e3ap PRIVATE E3_ASN1_FORMAT)
target_link_libraries(e3ap PUBLIC ${CLIBE3_LIBRARIES})
elseif(E3_ENCODING_FORMAT STREQUAL "JSON")
target_compile_definitions(e3ap PRIVATE E3_JSON_FORMAT)
pkg_check_modules(JSON_C REQUIRED json-c)
if(NOT JSON_C_FOUND)
message(FATAL_ERROR "JSON-C not found and required for JSON encoding, install it with apt-get install libjson-c-dev")
endif()
target_link_libraries(e3ap PUBLIC ${CLIBE3_LIBRARIES} ${JSON_C_LIBRARIES})
target_include_directories(e3ap PUBLIC ${JSON_C_INCLUDE_DIRS})
endif()

View File

@@ -0,0 +1,73 @@
/*
* SPDX-License-Identifier: LicenseRef-CSSL-1.0
*/
#include "e3_config.h"
#include "common/utils/LOG/log.h"
#include "common/config/config_paramdesc.h"
#include "common/config/config_userapi.h"
#define E3CONFIG_SECTION "E3Configuration"
#define simOpt PARAMFLAG_NOFREE | PARAMFLAG_CMDLINE_NOPREFIXENABLED
/* String-to-integer mappings for link, transport, and encoding.
* Values must match the libe3 e3_config_t enum ordering. */
// clang-format off
#define E3_LINK_OKSTRINGS {"zmq", "posix"}
#define E3_LINK_VALUES {E3_LINK_ZMQ, E3_LINK_POSIX}
#define E3_TRANSPORT_OKSTRINGS {"sctp", "tcp", "ipc"}
#define E3_TRANSPORT_VALUES {E3_TRANSPORT_SCTP, E3_TRANSPORT_TCP, E3_TRANSPORT_IPC}
#define E3_ENCODING_OKSTRINGS {"asn1", "json"}
#define E3_ENCODING_VALUES {E3_ENCODING_ASN1, E3_ENCODING_JSON}
#define E3_LINK_IDX 0
#define E3_TRANSPORT_IDX 1
#define E3_ENCODING_IDX 2
// clang-format on
void e3_readconfig(e3_cmdline_config_t *config)
{
/* Temporary string storage for the string→int parameters. */
char *s_link = NULL, *s_transport = NULL, *s_encoding = NULL;
// clang-format off
paramdef_t e3_params[] = {
/* optname helpstr paramflags value defval type numelt */
{"link", "Link layer for E3 (zmq|posix)", simOpt, .strptr = &s_link, .defstrval = "posix", TYPE_STRING, 0},
{"transport", "Transport layer for E3 (sctp|tcp|ipc)", simOpt, .strptr = &s_transport, .defstrval = "ipc", TYPE_STRING, 0},
{"encoding", "Encoding format for E3 (asn1|json)", simOpt, .strptr = &s_encoding, .defstrval = "asn1", TYPE_STRING, 0},
{"setup_port", "E3 setup port (0=libe3 default)", simOpt, .u16ptr = &config->setup_port, .defuintval = 0, TYPE_UINT16, 0},
{"subscriber_port", "E3 subscriber port (0=libe3 default)", simOpt, .u16ptr = &config->subscriber_port, .defuintval = 0, TYPE_UINT16, 0},
{"publisher_port", "E3 publisher port (0=libe3 default)", simOpt, .u16ptr = &config->publisher_port, .defuintval = 0, TYPE_UINT16, 0},
};
checkedparam_t e3_checks[] = {
{.s3a = {config_checkstr_assign_integer, E3_LINK_OKSTRINGS, E3_LINK_VALUES, 2}},
{.s3a = {config_checkstr_assign_integer, E3_TRANSPORT_OKSTRINGS, E3_TRANSPORT_VALUES, 3}},
{.s3a = {config_checkstr_assign_integer, E3_ENCODING_OKSTRINGS, E3_ENCODING_VALUES, 2}},
{.s5 = {NULL}},
{.s5 = {NULL}},
{.s5 = {NULL}},
};
// clang-format on
config_set_checkfunctions(e3_params, e3_checks, sizeofArray(e3_params));
int ret = config_get(config_get_if(), e3_params, sizeofArray(e3_params), E3CONFIG_SECTION);
AssertFatal(ret >= 0, "E3Configuration: config_get failed\n");
config->link_layer = config_get_processedint(config_get_if(), &e3_params[E3_LINK_IDX]);
config->transport_layer = config_get_processedint(config_get_if(), &e3_params[E3_TRANSPORT_IDX]);
config->encoding = config_get_processedint(config_get_if(), &e3_params[E3_ENCODING_IDX]);
/* setup_port, subscriber_port, publisher_port written directly by config_get via u16ptr */
LOG_I(E3AP,
"E3 configuration: link=%d transport=%d encoding=%d setup_port=%u subscriber_port=%u publisher_port=%u\n",
config->link_layer,
config->transport_layer,
config->encoding,
config->setup_port,
config->subscriber_port,
config->publisher_port);
}

View File

@@ -0,0 +1,38 @@
/*
* SPDX-License-Identifier: LicenseRef-CSSL-1.0
*/
#ifndef E3_CONFIG_H
#define E3_CONFIG_H
#include <stdint.h>
/* link_layer values (match libe3 e3_config_t; -1 = libe3 default) */
#define E3_LINK_ZMQ 0
#define E3_LINK_POSIX 1
/* transport_layer values (match libe3 e3_config_t; -1 = libe3 default) */
#define E3_TRANSPORT_SCTP 0
#define E3_TRANSPORT_TCP 1
#define E3_TRANSPORT_IPC 2
/* encoding values (match libe3 e3_config_t; -1 = libe3 default) */
#define E3_ENCODING_ASN1 0
#define E3_ENCODING_JSON 1
typedef struct {
int link_layer; /* E3_LINK_{ZMQ,POSIX}; -1 = libe3 default */
int transport_layer; /* E3_TRANSPORT_{SCTP,TCP,IPC}; -1 = libe3 default */
int encoding; /* E3_ENCODING_{ASN1,JSON}; -1 = libe3 default */
uint16_t setup_port; /* 0 = libe3 default (9990) */
uint16_t subscriber_port; /* 0 = libe3 default */
uint16_t publisher_port; /* 0 = libe3 default */
} e3_cmdline_config_t;
/**
* @brief Read E3 configuration from the OAI config file
* @param config Pointer to configuration structure to fill
*/
void e3_readconfig(e3_cmdline_config_t *config);
#endif // E3_CONFIG_H