23constexpr const char* LOG_TAG =
"CApi";
90 return ErrorCode::SUCCESS;
97 return ErrorCode::SUCCESS;
113 uint32_t request_message_id,
117 return ErrorCode::NOT_FOUND;
156 if (!desc)
return nullptr;
171 return static_cast<int>(ErrorCode::SUCCESS);
184 uint32_t ran_function_id,
188 if (!sm)
return static_cast<int>(ErrorCode::INVALID_PARAM);
200 if (data && data_len) {
203 pdu.
choice = std::move(msg);
205 return static_cast<int>(sm->
emit_pdu(std::move(pdu)));
213 if (!sm)
return static_cast<int>(ErrorCode::INVALID_PARAM);
221 return static_cast<int>(sm->
emit_pdu(std::move(pdu)));
231 const uint8_t* outcome,
234 if (!sm)
return static_cast<int>(ErrorCode::INVALID_PARAM);
240 if (detail) result.
detail = std::string(detail);
241 if (outcome && outcome_len) result.
outcome.assign(outcome, outcome + outcome_len);
243 return static_cast<int>(sm->
answer_control(dapp_id, request_id, result));
278 h->
agent = std::make_unique<E3Agent>(std::move(cfg));
291 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::STATE_ERROR);
292 return static_cast<int>(agent->
agent->init());
296 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::STATE_ERROR);
297 return static_cast<int>(agent->
agent->start());
301 if (!agent || !agent->
agent)
return;
302 agent->
agent->stop();
306 if (!agent || !agent->
agent || !sm)
return static_cast<int>(ErrorCode::INVALID_PARAM);
316 <<
" bytes of ran_function_data; E3AP requires 1.."
318 return static_cast<int>(ErrorCode::INVALID_PARAM);
324 std::unique_ptr<ServiceModel> uptr(sm);
325 return static_cast<int>(agent->
agent->register_sm(std::move(uptr)));
327 return static_cast<int>(ErrorCode::INTERNAL_ERROR);
333 return static_cast<int>(agent->
agent->state());
337 if (!agent || !agent->
agent)
return 0;
338 return agent->
agent->is_running() ? 1 : 0;
345 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
349 return static_cast<int>(ErrorCode::SUCCESS);
352 agent->
agent->set_dapp_report_handler(
354 const uint8_t* report_data =
366 return static_cast<int>(ErrorCode::SUCCESS);
370 if (out_len) *out_len = v.size();
371 if (v.empty())
return nullptr;
372 uint32_t* arr = (uint32_t*)malloc(
sizeof(uint32_t) * v.size());
373 if (!arr)
return nullptr;
374 memcpy(arr, v.data(),
sizeof(uint32_t) * v.size());
379 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
380 auto v = agent->
agent->get_available_ran_functions();
385 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
386 auto v = agent->
agent->get_registered_dapps();
391 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
392 auto v = agent->
agent->get_dapp_subscriptions(dapp_id);
397 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
398 auto v = agent->
agent->get_ran_function_subscribers(ran_function_id);
403 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
404 auto v = agent->
agent->get_active_ran_functions();
411 uint32_t ran_function_id
413 if (!agent || !agent->
agent)
return 0;
414 return agent->
agent->get_subscription_periodicity(dapp_id, ran_function_id);
420 uint32_t ran_function_id,
423 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
424 auto v = agent->
agent->get_subscription_telemetry_ids(dapp_id, ran_function_id);
431 uint32_t ran_function_id,
434 if (!agent || !agent->
agent) {
if (out_len) *out_len = 0;
return nullptr; }
435 auto v = agent->
agent->get_subscription_control_ids(dapp_id, ran_function_id);
446 uint32_t ran_function_id,
450 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
451 std::vector<uint8_t> buf;
452 if (data && data_len) buf.assign(data, data + data_len);
453 return static_cast<int>(agent->
agent->send_indication(dapp_id, ran_function_id, buf));
459 uint32_t ran_function_id,
460 const uint8_t* control_data,
461 size_t control_data_len,
462 uint32_t sequence_id,
463 uint32_t* out_message_id,
466 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
467 std::vector<uint8_t> buf;
468 if (control_data && control_data_len) buf.assign(control_data, control_data + control_data_len);
469 return static_cast<int>(
470 agent->
agent->send_xapp_control(dapp_id, ran_function_id, buf, sequence_id,
471 out_message_id, request_ack != 0));
479 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
481 return static_cast<int>(agent->
agent->send_message_ack(request_id, rc));
488 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
492 return static_cast<int>(ErrorCode::SUCCESS);
495 agent->
agent->set_control_response_handler(
506 resp.
cause ?
static_cast<int>(*resp.
cause) : -1,
514 return static_cast<int>(ErrorCode::SUCCESS);
518 if (!agent || !agent->
agent)
return 0;
519 return agent->
agent->dapp_count();
523 if (!agent || !agent->
agent)
return 0;
524 return agent->
agent->subscription_count();
529#define X(name, val) case val: return #name;
532 default:
return "UNKNOWN_ERROR_CODE";
540 if (!agent || !agent->
agent)
return static_cast<int>(ErrorCode::INVALID_PARAM);
544 return static_cast<int>(ErrorCode::SUCCESS);
547 agent->
agent->set_dapp_status_changed_handler(
548 [handler]() { handler(); }
551 return static_cast<int>(ErrorCode::SUCCESS);
void e3_agent_free_uint32_array(uint32_t *arr)
Free an array previously returned by the e3_agent_get_* helpers.
e3_error_t e3_agent_register_sm(e3_agent_handle_t *agent, e3_service_model_handle_t *sm)
Register a ServiceModel implementation with the agent.
e3_error_t e3_service_model_set_granted_periodicity_cb(e3_service_model_handle_t *sm, e3_sm_granted_periodicity_cb cb)
Let a C-backed ServiceModel report the interval it keeps between indications.
e3_service_model_handle_t * e3_service_model_create_from_c(const e3_c_service_model_desc_t *desc)
Create a ServiceModel implementation backed by C callbacks.
uint32_t e3_agent_get_subscription_periodicity(e3_agent_handle_t *agent, uint32_t dapp_id, uint32_t ran_function_id)
Get the reporting periodicity a dApp requested for a RAN function.
e3_error_t e3_agent_set_control_response_handler(e3_agent_handle_t *agent, e3_control_response_cb handler)
Set callback for incoming control responses (dApp -> RAN): a dApp's answer to an xApp control that as...
uint32_t * e3_agent_get_ran_function_subscribers(e3_agent_handle_t *agent, uint32_t ran_function_id, size_t *out_len)
Return a newly-allocated array of dApp IDs subscribed to a RAN function.
void e3_agent_destroy(e3_agent_handle_t *agent)
Destroy an E3Agent handle.
void e3_agent_stop(e3_agent_handle_t *agent)
Stop the agent and release runtime resources.
size_t e3_agent_subscription_count(e3_agent_handle_t *agent)
Total number of active subscriptions tracked by the agent.
e3_error_t e3_agent_set_dapp_report_handler(e3_agent_handle_t *agent, e3_dapp_report_cb handler)
Set callback for incoming dApp reports (dApp -> RAN).
const char * e3_error_to_string(e3_error_t code)
Convert a numeric error code to a human-readable name.
e3_agent_handle_t * e3_agent_create_default()
Create/destroy an E3Agent handle.
e3_error_t e3_agent_send_message_ack(e3_agent_handle_t *agent, uint32_t request_id, int response_code)
Send a message acknowledgment (e.g. ack a control/request from dApp).
int e3_agent_is_running(e3_agent_handle_t *agent)
Query whether the agent is currently running.
uint32_t * e3_agent_get_registered_dapps(e3_agent_handle_t *agent, size_t *out_len)
Return a newly-allocated array of registered dApp IDs.
e3_error_t e3_service_model_emit_control_response(e3_service_model_handle_t *sm, uint32_t dapp_id, uint32_t request_id, int response_code, int cause, const char *detail, const uint8_t *outcome, size_t outcome_len)
Answer a dApp control from a ServiceModel.
e3_error_t e3_agent_send_xapp_control(e3_agent_handle_t *agent, uint32_t dapp_id, uint32_t ran_function_id, const uint8_t *control_data, size_t control_data_len, uint32_t sequence_id, uint32_t *out_message_id, int request_ack)
Send an xApp control action to a specific dApp (e.g. from E2/SM).
e3_error_t e3_service_model_emit_message_ack(e3_service_model_handle_t *sm, uint32_t request_id, int response_code)
Emit a message acknowledgment from a ServiceModel.
int e3_agent_get_state(e3_agent_handle_t *agent)
Get the agent state as an integer matching libe3::AgentState.
e3_error_t e3_agent_start(e3_agent_handle_t *agent)
Start the agent processing threads and accept dApp connections.
void e3_service_model_destroy(e3_service_model_handle_t *sm)
Destroy a C-backed ServiceModel handle.
e3_agent_handle_t * e3_agent_create_with_config(const e3_config_t *config)
Create a new E3Agent with the given configuration.
e3_error_t e3_agent_send_indication(e3_agent_handle_t *agent, uint32_t dapp_id, uint32_t ran_function_id, const uint8_t *data, size_t data_len)
Send an indication message to a specific dApp.
e3_error_t e3_agent_init(e3_agent_handle_t *agent)
Initialize the agent.
uint32_t * e3_agent_get_active_ran_functions(e3_agent_handle_t *agent, size_t *out_len)
Return a newly-allocated array of RAN function IDs that currently have at least one subscriber (RAN r...
uint32_t * e3_agent_get_dapp_subscriptions(e3_agent_handle_t *agent, uint32_t dapp_id, size_t *out_len)
Return a newly-allocated array of RAN function IDs subscribed by a dApp.
uint32_t * e3_agent_get_subscription_control_ids(e3_agent_handle_t *agent, uint32_t dapp_id, uint32_t ran_function_id, size_t *out_len)
Get the control IDs a dApp requested for a RAN function.
e3_error_t e3_service_model_emit_indication(e3_service_model_handle_t *sm, uint32_t dapp_id, uint32_t ran_function_id, const uint8_t *data, size_t data_len)
Emit an indication message from a ServiceModel to the outbound queue.
size_t e3_agent_dapp_count(e3_agent_handle_t *agent)
Number of registered dApps known to the agent.
uint32_t * e3_agent_get_subscription_telemetry_ids(e3_agent_handle_t *agent, uint32_t dapp_id, uint32_t ran_function_id, size_t *out_len)
Get the telemetry IDs a dApp requested for a RAN function.
uint32_t * e3_agent_get_available_ran_functions(e3_agent_handle_t *agent, size_t *out_len)
Return a newly-allocated array of available RAN function IDs.
static uint32_t * copy_vector_u32_to_c(const std::vector< uint32_t > &v, size_t *out_len)
e3_error_t e3_agent_set_dapp_status_changed_handler(e3_agent_handle_t *agent, e3_dapp_status_changed_cb handler)
Set callback for dApp status changes.
void(* e3_dapp_status_changed_cb)(void)
struct e3_agent_handle_s e3_agent_handle_t
void(* e3_dapp_report_cb)(uint32_t dapp_id, uint32_t ran_function_id, const uint8_t *report_data, size_t report_data_len, uint32_t sequence_id)
e3_error_t(* e3_sm_process_control_cb)(e3_service_model_handle_t *sm_handle, void *sm_context, uint32_t request_message_id, uint32_t dapp_id, uint32_t ran_function_id, uint32_t control_id, const uint8_t *data, size_t data_len, uint32_t sequence_id)
void(* e3_sm_destroy_cb)(void *sm_context)
e3_error_t(* e3_sm_start_cb)(void *sm_context)
void(* e3_sm_stop_cb)(void *sm_context)
int(* e3_sm_is_running_cb)(void *sm_context)
uint32_t(* e3_sm_granted_periodicity_cb)(void *sm_context, uint32_t requested_us)
Interval a C Service Model keeps between two indications of a subscription.
struct e3_service_model_handle_s e3_service_model_handle_t
e3_error_t(* e3_sm_init_cb)(void *sm_context)
void(* e3_control_response_cb)(uint32_t dapp_id, uint32_t request_id, uint32_t ran_function_id, uint32_t control_id, int response_code, int cause, const char *detail, const uint8_t *outcome, size_t outcome_len)
ErrorCode respond_to_control(uint32_t dapp_id, uint32_t request_message_id, const ControlResult &result)
Answer a dApp control.
ErrorCode emit_outbound(Pdu &&pdu)
Emit an outbound PDU produced by the SM.
E3Agent - Main façade class for RAN vendors.
libe3 error codes - shared C/C++ definitions
int e3_error_t
C error type alias.
#define LIBE3_ERROR_CODE_LIST
X-macro list of all libe3 error codes.
Lock-free per-thread latency stamp recorder (header-only, C99).
static void latrec_tstamp(uint64_t seq, uint8_t stage, uint64_t aux, uint64_t aux2)
static uint64_t latrec_ctx(void)
uint64_t latrec_seq_next(void)
Logging facility for libe3.
#define E3_LOG_ERROR(component)
ErrorCode
Error codes returned by libe3 operations Use shared error-code list (see libe3/error_codes....
E3TransportLayer
Transport layer types (matches Python E3TransportLayer).
std::function< void()> DAppStatusChangedHandler
ResponseCode
E3AP response codes.
@ NEGATIVE
Request rejected.
@ POSITIVE
Request accepted.
std::function< void(const DAppReport &)> DAppReportHandler
constexpr size_t MAX_PROTOCOL_DATA_SIZE
Largest protocolData of an indication, in bytes.
@ MESSAGE_ACK
DEPRECATED TO BE REMOVED: libe3 no longer sends it, see CONTROL_RESPONSE.
E3LinkLayer
Link layer types (matches Python E3LinkLayer).
EncodingFormat
E3AP encoding formats supported by the library.
std::function< void(const ControlResponse &)> ControlResponseHandler
Called for a ControlResponse: on a dApp, the RAN's answer to its control; on a RAN,...
Cause cause_from_value(long value) noexcept
Read a Cause from its wire value.
constexpr size_t MAX_CONTROL_OUTCOME_SIZE
Largest controlOutcome of a control response, in bytes.
Service Model Interface - Extension point for RAN vendors.
What e3_agent_handle_t points to: the agent a C caller holds.
std::unique_ptr< E3Agent > agent
The agent the handle owns.
Descriptor describing a ServiceModel implemented in C.
const uint32_t * control_ids
Array of supported control IDs (copied by library).
uint32_t version
Service Model version.
e3_sm_stop_cb sm_stop
Called when SM should stop.
const uint8_t * ran_function_data
Opaque RAN function data (must be non-NULL).
const uint32_t * telemetry_ids
Array of supported telemetry IDs (copied by library).
size_t control_ids_len
Number of control IDs.
const char * name
Service Model name (null-terminated string).
size_t telemetry_ids_len
Number of telemetry IDs.
e3_sm_start_cb sm_start
Called when SM should start.
e3_sm_init_cb sm_init
Called on SM registration.
e3_sm_is_running_cb sm_is_running
Called to query running state.
void * sm_context
Opaque pointer passed to all callbacks.
size_t ran_function_data_len
Length in bytes; must be 1..32768.
e3_sm_process_control_cb sm_process_control
Called to process control actions.
uint32_t ran_function_id
RAN function ID for this SM.
e3_sm_destroy_cb sm_destroy
Called on SM destruction.
Configuration for creating an E3Agent from C.
int encoding
0=ASN1, 1=JSON, 2=PROTOBUF, -1=default
int log_level
Logging level; -1=default.
uint16_t subscriber_port
Port of the subscriber channel (SCTP and TCP); 0 keeps the default.
int pin_io_threads
Pin the I/O threads when non-zero; 0=no pinning.
const char * setup_endpoint
Endpoint of the setup channel; NULL keeps the default.
int link_layer
0=ZMQ, 1=POSIX, -1=default
const char * log_path
Log file; NULL=auto (/tmp/e3_ROLE[_ID]_EUID.log).
size_t io_threads
Number of I/O threads; 0=default.
uint16_t setup_port
Port of the setup channel (SCTP and TCP); 0 keeps the default.
uint16_t publisher_port
Port of the publisher channel (SCTP and TCP); 0 keeps the default.
int io_thread_affinity
Logical core to pin to; Linux only, best-effort.
const char * ran_identifier
RAN identifier; NULL keeps the default.
const char * subscriber_endpoint
Endpoint of the subscriber channel; NULL keeps the default.
int transport_layer
0=SCTP, 1=TCP, 2=IPC, -1=default
uint32_t dapp_idle_timeout_s
Seconds without a message from a dApp before the RAN releases and removes it; 0=never.
const char * publisher_endpoint
Endpoint of the publisher channel; NULL keeps the default.
int set_dapp_idle_timeout
Apply dapp_idle_timeout_s when non-zero; 0=keep the library default (1800 s).
What e3_service_model_handle_t points to: a ServiceModel that calls back into C.
e3_sm_stop_cb sm_stop
Called when the SM should stop.
ErrorCode start() override
Start the SM processing.
uint32_t ran_function_id_s
RAN function identifier.
void stop() override
Stop the SM processing.
void destroy() override
Destroy the SM and release resources.
e3_sm_process_control_cb sm_process_control
Called for each control action.
e3_sm_init_cb sm_init
Called on registration.
void * sm_context
Passed to every callback.
std::string name_s
Service Model name.
ErrorCode handle_control_action(uint32_t request_message_id, const DAppControlAction &action) override
Process a control action from a dApp.
std::vector< uint32_t > control_ids_s
Control identifiers it supports.
ErrorCode init() override
Initialize the SM.
bool is_running() const override
Check if SM is currently running.
std::vector< uint32_t > telemetry_ids() const override
Get telemetry IDs supported by this SM.
e3_sm_start_cb sm_start
Called when the SM should start.
bool transferred_to_agent
Whether ownership was transferred to an agent.
std::string name() const override
Get SM name.
e3_sm_granted_periodicity_cb sm_granted_periodicity
Asked for the interval it keeps.
std::vector< uint32_t > control_ids() const override
Get control IDs supported by this SM.
uint32_t ran_function_id() const override
Get RAN function ID for this SM.
std::vector< uint32_t > telemetry_ids_s
Telemetry identifiers it supports.
uint32_t version() const override
Get SM version.
uint32_t version_s
Service Model version.
std::vector< uint8_t > ran_function_data_s
Opaque RAN function data.
e3_sm_is_running_cb sm_is_running
Called to ask whether the SM runs.
std::vector< uint8_t > ran_function_data() const override
RAN-function-specific opaque data (required, 1..32768 bytes).
e3_sm_destroy_cb sm_destroy
Called on destruction.
ErrorCode emit_pdu(Pdu &&pdu)
Queue a PDU the SM emits.
ErrorCode answer_control(uint32_t dapp_id, uint32_t request_id, const ControlResult &result)
Answer a dApp control.
std::optional< uint32_t > granted_periodicity(uint32_t requested_us) const override
The least time between two indications that this SM keeps for a subscription.
e3_service_model_handle_s(const e3_c_service_model_desc_t &desc)
Copy a descriptor.
E3AP Control Response structure.
uint32_t request_id
Message id of the control this answers.
uint32_t control_identifier
Control the answer is about.
std::optional< Cause > cause
Why the control was refused (negative only).
ResponseCode response_code
Response code (positive/negative).
uint32_t ran_function_identifier
RAN function of the control.
uint32_t dapp_identifier
dApp the control belongs to
std::optional< std::string > detail
std::optional< std::vector< uint8_t > > control_outcome
What a Service Model answers to a control (see ServiceModel::respond_to_control).
ResponseCode response_code
Whether the control was applied.
std::optional< std::string > detail
UTF-8 text for the cause, up to MAX_DETAIL_SIZE bytes.
std::optional< Cause > cause
Why not (negative only).
std::vector< uint8_t > outcome
Opaque service-model content; empty for none.
E3AP dApp Control Action structure.
uint32_t ran_function_identifier
RAN function the control is for.
std::vector< uint8_t > action_data
uint32_t dapp_identifier
dApp that sends the control
uint32_t control_identifier
Control identifier.
E3AP dApp Report structure.
uint32_t dapp_identifier
dApp that sends the report
std::vector< uint8_t > report_data
uint32_t ran_function_identifier
RAN function the report is for.
Configuration for E3Agent.
std::string log_path
Path of the shared log file. Empty (default) => auto-generated.
std::string subscriber_endpoint
Endpoint URI of the inbound channel (ZeroMQ).
int log_level
Logging verbosity: 0=none, 1=error, 2=warn, 3=info, 4=debug, 5=trace.
uint16_t setup_port
Port of the setup channel; the one port of the POSIX link.
int io_thread_affinity
CPU core to pin the subscriber and publisher I/O threads to.
EncodingFormat encoding
PDU encoding format (ASN.1 PER or JSON).
E3LinkLayer link_layer
Link-layer transport (ZMQ or POSIX).
std::string publisher_endpoint
Endpoint URI of the outbound channel (ZeroMQ).
uint16_t subscriber_port
Port of the inbound control/subscription channel (ZeroMQ).
uint32_t dapp_idle_timeout_s
Seconds a RAN waits for a message from a dApp before it removes the dApp.
std::string ran_identifier
Unique identifier for this RAN function (e.g. "DU-1").
E3TransportLayer transport_layer
Transport-layer protocol (SCTP, TCP, IPC).
size_t io_threads
Number of I/O threads (used by ZMQ context).
std::string setup_endpoint
Endpoint URI of the setup channel; the one endpoint of the POSIX link.
uint16_t publisher_port
Port of the outbound indication/publication channel (ZeroMQ).
E3AP Indication Message structure.
uint32_t ran_function_identifier
RAN function identifier.
std::vector< uint8_t > protocol_data
Opaque payload of the service model.
uint32_t dapp_identifier
dApp the indication is for
E3AP Message Acknowledgment structure.
ResponseCode response_code
Response code (positive/negative).
uint32_t request_id
ID of the request being acknowledged.
Generic E3AP PDU structure.
uint64_t enqueue_seq
Set by queue_outbound; keys the [latrec] L-stage records.
PduChoice choice
The message itself.
E3AP Protocol Types - Vendor-neutral type definitions.