libe3 0.6.1
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
c_api.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#include "libe3/c_api.h"
7
8#include "libe3/e3_agent.hpp"
10#include "libe3/types.hpp"
11#include "libe3/error_codes.h"
12#include "libe3/logger.hpp"
13#include "libe3/latrec.h"
14
15#include <string>
16#include <vector>
17#include <memory>
18#include <cstring>
19
20using namespace libe3;
21
22namespace {
23constexpr const char* LOG_TAG = "CApi";
24}
25
26/// What `e3_agent_handle_t` points to: the agent a C caller holds.
28 std::unique_ptr<E3Agent> agent; ///< The agent the handle owns
29};
30
31/// What `e3_service_model_handle_t` points to: a ServiceModel that calls back into C.
33 // store copied values
34 std::string name_s; ///< Service Model name
35 uint32_t version_s; ///< Service Model version
36 uint32_t ran_function_id_s; ///< RAN function identifier
37 std::vector<uint32_t> telemetry_ids_s; ///< Telemetry identifiers it supports
38 std::vector<uint32_t> control_ids_s; ///< Control identifiers it supports
39 std::vector<uint8_t> ran_function_data_s; ///< Opaque RAN function data
40
41 // callbacks
42 e3_sm_init_cb sm_init = nullptr; ///< Called on registration
43 e3_sm_destroy_cb sm_destroy = nullptr; ///< Called on destruction
44 e3_sm_start_cb sm_start = nullptr; ///< Called when the SM should start
45 e3_sm_stop_cb sm_stop = nullptr; ///< Called when the SM should stop
46 e3_sm_is_running_cb sm_is_running = nullptr; ///< Called to ask whether the SM runs
47 e3_sm_process_control_cb sm_process_control = nullptr; ///< Called for each control action
48 e3_sm_granted_periodicity_cb sm_granted_periodicity = nullptr; ///< Asked for the interval it keeps
49 void* sm_context = nullptr; ///< Passed to every callback
50
51 /// Whether ownership was transferred to an agent.
53
54 /**
55 * @brief Copy a descriptor
56 * @param desc What the C caller described
57 */
59 if (desc.name) name_s = desc.name;
60 version_s = desc.version;
62 if (desc.telemetry_ids && desc.telemetry_ids_len) {
64 }
65 if (desc.control_ids && desc.control_ids_len) {
66 control_ids_s.assign(desc.control_ids, desc.control_ids + desc.control_ids_len);
67 }
68 // Copy ran_function_data if provided
71 }
72 sm_init = desc.sm_init;
74 sm_start = desc.sm_start;
75 sm_stop = desc.sm_stop;
79 }
80
81 // ServiceModel virtuals
82 std::string name() const override { return name_s; }
83 uint32_t version() const override { return version_s; }
84 uint32_t ran_function_id() const override { return ran_function_id_s; }
85 std::vector<uint32_t> telemetry_ids() const override { return telemetry_ids_s; }
86 std::vector<uint32_t> control_ids() const override { return control_ids_s; }
87 std::vector<uint8_t> ran_function_data() const override { return ran_function_data_s; }
88 ErrorCode init() override {
89 if (sm_init) return static_cast<ErrorCode>(sm_init(sm_context));
90 return ErrorCode::SUCCESS;
91 }
92 void destroy() override {
94 }
95 ErrorCode start() override {
96 if (sm_start) return static_cast<ErrorCode>(sm_start(sm_context));
97 return ErrorCode::SUCCESS;
98 }
99 void stop() override {
101 }
102 bool is_running() const override {
103 if (sm_is_running) return sm_is_running(sm_context) != 0;
104 return false;
105 }
106
107 std::optional<uint32_t> granted_periodicity(uint32_t requested_us) const override {
108 if (!sm_granted_periodicity) return std::nullopt;
109 return sm_granted_periodicity(sm_context, requested_us);
110 }
111
113 uint32_t request_message_id,
114 const DAppControlAction& action
115 ) override {
116 if (!sm_process_control) {
117 return ErrorCode::NOT_FOUND;
118 }
119 return static_cast<ErrorCode>(sm_process_control(
120 this,
122 request_message_id,
123 action.dapp_identifier,
125 action.control_identifier,
126 action.action_data.empty() ? nullptr : action.action_data.data(),
127 action.action_data.size(),
128 action.sequence_id
129 ));
130 }
131
132 /**
133 * @brief Queue a PDU the SM emits
134 * @param pdu The PDU
135 * @return ErrorCode::SUCCESS if it was queued
136 */
138 return emit_outbound(std::move(pdu));
139 }
140
141 /**
142 * @brief Answer a dApp control
143 * @param dapp_id dApp that sent the control
144 * @param request_id Message id of the control
145 * @param result The answer
146 * @return What ServiceModel::respond_to_control returns
147 */
148 ErrorCode answer_control(uint32_t dapp_id, uint32_t request_id, const ControlResult& result) {
149 return respond_to_control(dapp_id, request_id, result);
150 }
151};
152
153extern "C" {
154
156 if (!desc) return nullptr;
157 try {
158 return new e3_service_model_handle_s(*desc);
159 } catch (...) {
160 return nullptr;
161 }
162}
163
167) {
168 // Once registered the agent's threads may be reading the callback.
169 if (!sm || sm->transferred_to_agent) return static_cast<int>(ErrorCode::INVALID_PARAM);
170 sm->sm_granted_periodicity = cb;
171 return static_cast<int>(ErrorCode::SUCCESS);
172}
173
175 if (!sm) return;
176 // If ownership was transferred to an agent, we must not delete here.
177 if (sm->transferred_to_agent) return;
178 delete sm;
179}
180
183 uint32_t dapp_id,
184 uint32_t ran_function_id,
185 const uint8_t* data,
186 size_t data_len
187) {
188 if (!sm) return static_cast<int>(ErrorCode::INVALID_PARAM);
189
191 // Keys the outbound leg from this boundary, so the payload copy and the Pdu
192 // construction below fall inside it. aux carries the producer's own trace
193 // seq, which joins its stages to this leg.
195 latrec_tstamp(pdu.enqueue_seq, LATREC_EMIT_ENTER, latrec_ctx(), ran_function_id);
196
198 msg.dapp_identifier = dapp_id;
199 msg.ran_function_identifier = ran_function_id;
200 if (data && data_len) {
201 msg.protocol_data.assign(data, data + data_len);
202 }
203 pdu.choice = std::move(msg);
204
205 return static_cast<int>(sm->emit_pdu(std::move(pdu)));
206}
207
210 uint32_t request_id,
211 int response_code
212) {
213 if (!sm) return static_cast<int>(ErrorCode::INVALID_PARAM);
214
216 MessageAck ack;
217 ack.request_id = request_id;
218 ack.response_code = (response_code == 0) ? ResponseCode::POSITIVE : ResponseCode::NEGATIVE;
219 pdu.choice = ack;
220
221 return static_cast<int>(sm->emit_pdu(std::move(pdu)));
222}
223
226 uint32_t dapp_id,
227 uint32_t request_id,
228 int response_code,
229 int cause,
230 const char* detail,
231 const uint8_t* outcome,
232 size_t outcome_len
233) {
234 if (!sm) return static_cast<int>(ErrorCode::INVALID_PARAM);
235 if (outcome_len > MAX_CONTROL_OUTCOME_SIZE) return static_cast<int>(ErrorCode::INVALID_PARAM);
236
237 ControlResult result;
238 result.response_code = (response_code == 0) ? ResponseCode::POSITIVE : ResponseCode::NEGATIVE;
239 if (cause >= 0) result.cause = cause_from_value(cause);
240 if (detail) result.detail = std::string(detail);
241 if (outcome && outcome_len) result.outcome.assign(outcome, outcome + outcome_len);
242
243 return static_cast<int>(sm->answer_control(dapp_id, request_id, result));
244}
245
249
251 try {
252 E3Config cfg;
253 if (config) {
254 if (config->ran_identifier) cfg.ran_identifier = config->ran_identifier;
255 if (config->link_layer >= 0 && config->link_layer <= 1)
256 cfg.link_layer = static_cast<E3LinkLayer>(config->link_layer);
257 if (config->transport_layer >= 0 && config->transport_layer <= 2)
258 cfg.transport_layer = static_cast<E3TransportLayer>(config->transport_layer);
259 if (config->setup_port != 0) cfg.setup_port = config->setup_port;
260 if (config->subscriber_port != 0) cfg.subscriber_port = config->subscriber_port;
261 if (config->publisher_port != 0) cfg.publisher_port = config->publisher_port;
262 if (config->setup_endpoint) cfg.setup_endpoint = config->setup_endpoint;
265 if (config->encoding >= 0 && config->encoding <= 2)
266 cfg.encoding = static_cast<EncodingFormat>(config->encoding);
267 if (config->io_threads != 0) cfg.io_threads = config->io_threads;
268 if (config->log_level >= 0) cfg.log_level = config->log_level;
269 if (config->log_path) cfg.log_path = config->log_path;
270 // Gated by the flag, not a sentinel: core 0 is a real target.
271 if (config->pin_io_threads)
273 // Gated by the flag, not a sentinel: 0 means "never remove a quiet dApp".
274 if (config->set_dapp_idle_timeout)
276 }
278 h->agent = std::make_unique<E3Agent>(std::move(cfg));
279 return h;
280 } catch (...) {
281 return nullptr;
282 }
283}
284
286 if (!agent) return;
287 delete agent;
288}
289
291 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::STATE_ERROR);
292 return static_cast<int>(agent->agent->init());
293}
294
296 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::STATE_ERROR);
297 return static_cast<int>(agent->agent->start());
298}
299
301 if (!agent || !agent->agent) return;
302 agent->agent->stop();
303}
304
306 if (!agent || !agent->agent || !sm) return static_cast<int>(ErrorCode::INVALID_PARAM);
307
308 // Screen the E3AP ranFunctionData constraint here, before the ownership
309 // transfer below. register_sm() takes the unique_ptr by value, so a
310 // rejection on the far side destroys the object while the caller still
311 // holds the handle; rejecting first is what lets the caller keep it and
312 // call e3_service_model_destroy() as this function documents.
313 const size_t rfd_len = sm->ran_function_data_s.size();
314 if (rfd_len == 0 || rfd_len > MAX_PROTOCOL_DATA_SIZE) {
315 E3_LOG_ERROR(LOG_TAG) << "SM '" << sm->name_s << "' advertises " << rfd_len
316 << " bytes of ran_function_data; E3AP requires 1.."
318 return static_cast<int>(ErrorCode::INVALID_PARAM);
319 }
320
321 // Transfer ownership into the agent
322 try {
323 sm->transferred_to_agent = true;
324 std::unique_ptr<ServiceModel> uptr(sm);
325 return static_cast<int>(agent->agent->register_sm(std::move(uptr)));
326 } catch (...) {
327 return static_cast<int>(ErrorCode::INTERNAL_ERROR);
328 }
329}
330
332 if (!agent || !agent->agent) return static_cast<int>(AgentState::ERROR);
333 return static_cast<int>(agent->agent->state());
334 }
335
337 if (!agent || !agent->agent) return 0;
338 return agent->agent->is_running() ? 1 : 0;
339 }
340
342 e3_agent_handle_t* agent,
343 e3_dapp_report_cb handler
344) {
345 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::INVALID_PARAM);
346
347 if (!handler) {
348 agent->agent->set_dapp_report_handler(DAppReportHandler{});
349 return static_cast<int>(ErrorCode::SUCCESS);
350 }
351
352 agent->agent->set_dapp_report_handler(
353 [handler](const DAppReport& report) {
354 const uint8_t* report_data =
355 report.report_data.empty() ? nullptr : report.report_data.data();
356 handler(
357 report.dapp_identifier,
359 report_data,
360 report.report_data.size(),
361 report.sequence_id
362 );
363 }
364 );
365
366 return static_cast<int>(ErrorCode::SUCCESS);
367 }
368
369 static uint32_t* copy_vector_u32_to_c(const std::vector<uint32_t>& v, size_t* out_len) {
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());
375 return arr;
376 }
377
378 uint32_t* e3_agent_get_available_ran_functions(e3_agent_handle_t* agent, size_t* out_len) {
379 if (!agent || !agent->agent) { if (out_len) *out_len = 0; return nullptr; }
380 auto v = agent->agent->get_available_ran_functions();
381 return copy_vector_u32_to_c(v, out_len);
382 }
383
384 uint32_t* e3_agent_get_registered_dapps(e3_agent_handle_t* agent, size_t* out_len) {
385 if (!agent || !agent->agent) { if (out_len) *out_len = 0; return nullptr; }
386 auto v = agent->agent->get_registered_dapps();
387 return copy_vector_u32_to_c(v, out_len);
388 }
389
390 uint32_t* e3_agent_get_dapp_subscriptions(e3_agent_handle_t* agent, uint32_t dapp_id, size_t* out_len) {
391 if (!agent || !agent->agent) { if (out_len) *out_len = 0; return nullptr; }
392 auto v = agent->agent->get_dapp_subscriptions(dapp_id);
393 return copy_vector_u32_to_c(v, out_len);
394 }
395
396 uint32_t* e3_agent_get_ran_function_subscribers(e3_agent_handle_t* agent, uint32_t ran_function_id, size_t* out_len) {
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);
399 return copy_vector_u32_to_c(v, out_len);
400 }
401
402 uint32_t* e3_agent_get_active_ran_functions(e3_agent_handle_t* agent, size_t* out_len) {
403 if (!agent || !agent->agent) { if (out_len) *out_len = 0; return nullptr; }
404 auto v = agent->agent->get_active_ran_functions();
405 return copy_vector_u32_to_c(v, out_len);
406 }
407
409 e3_agent_handle_t* agent,
410 uint32_t dapp_id,
411 uint32_t ran_function_id
412 ) {
413 if (!agent || !agent->agent) return 0;
414 return agent->agent->get_subscription_periodicity(dapp_id, ran_function_id);
415 }
416
418 e3_agent_handle_t* agent,
419 uint32_t dapp_id,
420 uint32_t ran_function_id,
421 size_t* out_len
422 ) {
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);
425 return copy_vector_u32_to_c(v, out_len);
426 }
427
429 e3_agent_handle_t* agent,
430 uint32_t dapp_id,
431 uint32_t ran_function_id,
432 size_t* out_len
433 ) {
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);
436 return copy_vector_u32_to_c(v, out_len);
437 }
438
439 void e3_agent_free_uint32_array(uint32_t* arr) {
440 free(arr);
441 }
442
444 e3_agent_handle_t* agent,
445 uint32_t dapp_id,
446 uint32_t ran_function_id,
447 const uint8_t* data,
448 size_t data_len
449 ) {
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));
454 }
455
457 e3_agent_handle_t* agent,
458 uint32_t dapp_id,
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,
464 int request_ack
465 ) {
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));
472 }
473
474 e3_error_t e3_agent_send_message_ack( // DEPRECATED TO BE REMOVED
475 e3_agent_handle_t* agent,
476 uint32_t request_id,
477 int response_code
478 ) {
479 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::INVALID_PARAM);
480 ResponseCode rc = (response_code == 0) ? ResponseCode::POSITIVE : ResponseCode::NEGATIVE;
481 return static_cast<int>(agent->agent->send_message_ack(request_id, rc));
482 }
483
485 e3_agent_handle_t* agent,
487 ) {
488 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::INVALID_PARAM);
489
490 if (!handler) {
491 agent->agent->set_control_response_handler(ControlResponseHandler{});
492 return static_cast<int>(ErrorCode::SUCCESS);
493 }
494
495 agent->agent->set_control_response_handler(
496 [handler](const ControlResponse& resp) {
497 const uint8_t* outcome = (resp.control_outcome && !resp.control_outcome->empty())
498 ? resp.control_outcome->data() : nullptr;
499 const size_t outcome_len = resp.control_outcome ? resp.control_outcome->size() : 0;
500 handler(
501 resp.dapp_identifier,
502 resp.request_id,
506 resp.cause ? static_cast<int>(*resp.cause) : -1,
507 resp.detail ? resp.detail->c_str() : nullptr,
508 outcome,
509 outcome_len
510 );
511 }
512 );
513
514 return static_cast<int>(ErrorCode::SUCCESS);
515 }
516
518 if (!agent || !agent->agent) return 0;
519 return agent->agent->dapp_count();
520 }
521
523 if (!agent || !agent->agent) return 0;
524 return agent->agent->subscription_count();
525 }
526
528 switch (code) {
529#define X(name, val) case val: return #name;
531#undef X
532 default: return "UNKNOWN_ERROR_CODE";
533 }
534}
535
537 e3_agent_handle_t* agent,
539) {
540 if (!agent || !agent->agent) return static_cast<int>(ErrorCode::INVALID_PARAM);
541
542 if (!handler) {
543 agent->agent->set_dapp_status_changed_handler(DAppStatusChangedHandler{});
544 return static_cast<int>(ErrorCode::SUCCESS);
545 }
546
547 agent->agent->set_dapp_status_changed_handler(
548 [handler]() { handler(); }
549 );
550
551 return static_cast<int>(ErrorCode::SUCCESS);
552}
553
554} // extern "C"
void e3_agent_free_uint32_array(uint32_t *arr)
Free an array previously returned by the e3_agent_get_* helpers.
Definition c_api.cpp:439
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.
Definition c_api.cpp:305
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.
Definition c_api.cpp:164
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.
Definition c_api.cpp:155
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.
Definition c_api.cpp:408
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...
Definition c_api.cpp:484
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.
Definition c_api.cpp:396
void e3_agent_destroy(e3_agent_handle_t *agent)
Destroy an E3Agent handle.
Definition c_api.cpp:285
void e3_agent_stop(e3_agent_handle_t *agent)
Stop the agent and release runtime resources.
Definition c_api.cpp:300
size_t e3_agent_subscription_count(e3_agent_handle_t *agent)
Total number of active subscriptions tracked by the agent.
Definition c_api.cpp:522
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).
Definition c_api.cpp:341
const char * e3_error_to_string(e3_error_t code)
Convert a numeric error code to a human-readable name.
Definition c_api.cpp:527
e3_agent_handle_t * e3_agent_create_default()
Create/destroy an E3Agent handle.
Definition c_api.cpp:246
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).
Definition c_api.cpp:474
int e3_agent_is_running(e3_agent_handle_t *agent)
Query whether the agent is currently running.
Definition c_api.cpp:336
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.
Definition c_api.cpp:384
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.
Definition c_api.cpp:224
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).
Definition c_api.cpp:456
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.
Definition c_api.cpp:208
int e3_agent_get_state(e3_agent_handle_t *agent)
Get the agent state as an integer matching libe3::AgentState.
Definition c_api.cpp:331
e3_error_t e3_agent_start(e3_agent_handle_t *agent)
Start the agent processing threads and accept dApp connections.
Definition c_api.cpp:295
void e3_service_model_destroy(e3_service_model_handle_t *sm)
Destroy a C-backed ServiceModel handle.
Definition c_api.cpp:174
e3_agent_handle_t * e3_agent_create_with_config(const e3_config_t *config)
Create a new E3Agent with the given configuration.
Definition c_api.cpp:250
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.
Definition c_api.cpp:443
e3_error_t e3_agent_init(e3_agent_handle_t *agent)
Initialize the agent.
Definition c_api.cpp:290
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...
Definition c_api.cpp:402
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.
Definition c_api.cpp:390
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.
Definition c_api.cpp:428
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.
Definition c_api.cpp:181
size_t e3_agent_dapp_count(e3_agent_handle_t *agent)
Number of registered dApps known to the agent.
Definition c_api.cpp:517
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.
Definition c_api.cpp:417
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.
Definition c_api.cpp:378
static uint32_t * copy_vector_u32_to_c(const std::vector< uint32_t > &v, size_t *out_len)
Definition c_api.cpp:369
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.
Definition c_api.cpp:536
void(* e3_dapp_status_changed_cb)(void)
Definition c_api.h:89
struct e3_agent_handle_s e3_agent_handle_t
Definition c_api.h:21
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)
Definition c_api.h:65
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)
Definition c_api.h:50
void(* e3_sm_destroy_cb)(void *sm_context)
Definition c_api.h:27
e3_error_t(* e3_sm_start_cb)(void *sm_context)
Definition c_api.h:28
void(* e3_sm_stop_cb)(void *sm_context)
Definition c_api.h:29
int(* e3_sm_is_running_cb)(void *sm_context)
Definition c_api.h:30
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.
Definition c_api.h:48
struct e3_service_model_handle_s e3_service_model_handle_t
Definition c_api.h:22
e3_error_t(* e3_sm_init_cb)(void *sm_context)
Definition c_api.h:26
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)
Definition c_api.h:76
ErrorCode respond_to_control(uint32_t dapp_id, uint32_t request_message_id, const ControlResult &result)
Answer a dApp control.
ServiceModel()=default
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.
Definition error_codes.h:67
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)
Definition latrec.h:720
static uint64_t latrec_ctx(void)
Definition latrec.h:751
@ LATREC_EMIT_ENTER
Definition latrec.h:199
uint64_t latrec_seq_next(void)
Definition latrec.c:164
Logging facility for libe3.
#define E3_LOG_ERROR(component)
Definition logger.hpp:225
ErrorCode
Error codes returned by libe3 operations Use shared error-code list (see libe3/error_codes....
Definition types.hpp:177
E3TransportLayer
Transport layer types (matches Python E3TransportLayer).
Definition types.hpp:85
@ ERROR
Error state.
Definition types.hpp:170
std::function< void()> DAppStatusChangedHandler
Definition e3_agent.hpp:33
ResponseCode
E3AP response codes.
Definition types.hpp:103
@ NEGATIVE
Request rejected.
Definition types.hpp:105
@ POSITIVE
Request accepted.
Definition types.hpp:104
std::function< void(const DAppReport &)> DAppReportHandler
Definition e3_agent.hpp:30
constexpr size_t MAX_PROTOCOL_DATA_SIZE
Largest protocolData of an indication, in bytes.
Definition types.hpp:200
@ MESSAGE_ACK
DEPRECATED TO BE REMOVED: libe3 no longer sends it, see CONTROL_RESPONSE.
Definition types.hpp:155
E3LinkLayer
Link layer types (matches Python E3LinkLayer).
Definition types.hpp:62
EncodingFormat
E3AP encoding formats supported by the library.
Definition types.hpp:53
std::function< void(const ControlResponse &)> ControlResponseHandler
Called for a ControlResponse: on a dApp, the RAN's answer to its control; on a RAN,...
Definition e3_agent.hpp:47
Cause cause_from_value(long value) noexcept
Read a Cause from its wire value.
Definition types.hpp:790
constexpr size_t MAX_CONTROL_OUTCOME_SIZE
Largest controlOutcome of a control response, in bytes.
Definition types.hpp:205
Service Model Interface - Extension point for RAN vendors.
What e3_agent_handle_t points to: the agent a C caller holds.
Definition c_api.cpp:27
std::unique_ptr< E3Agent > agent
The agent the handle owns.
Definition c_api.cpp:28
Descriptor describing a ServiceModel implemented in C.
Definition c_api.h:115
const uint32_t * control_ids
Array of supported control IDs (copied by library).
Definition c_api.h:123
uint32_t version
Service Model version.
Definition c_api.h:117
e3_sm_stop_cb sm_stop
Called when SM should stop.
Definition c_api.h:137
const uint8_t * ran_function_data
Opaque RAN function data (must be non-NULL).
Definition c_api.h:130
const uint32_t * telemetry_ids
Array of supported telemetry IDs (copied by library).
Definition c_api.h:120
size_t control_ids_len
Number of control IDs.
Definition c_api.h:124
const char * name
Service Model name (null-terminated string).
Definition c_api.h:116
size_t telemetry_ids_len
Number of telemetry IDs.
Definition c_api.h:121
e3_sm_start_cb sm_start
Called when SM should start.
Definition c_api.h:136
e3_sm_init_cb sm_init
Called on SM registration.
Definition c_api.h:134
e3_sm_is_running_cb sm_is_running
Called to query running state.
Definition c_api.h:138
void * sm_context
Opaque pointer passed to all callbacks.
Definition c_api.h:141
size_t ran_function_data_len
Length in bytes; must be 1..32768.
Definition c_api.h:131
e3_sm_process_control_cb sm_process_control
Called to process control actions.
Definition c_api.h:139
uint32_t ran_function_id
RAN function ID for this SM.
Definition c_api.h:118
e3_sm_destroy_cb sm_destroy
Called on SM destruction.
Definition c_api.h:135
Configuration for creating an E3Agent from C.
Definition c_api.h:250
int encoding
0=ASN1, 1=JSON, 2=PROTOBUF, -1=default
Definition c_api.h:260
int log_level
Logging level; -1=default.
Definition c_api.h:262
uint16_t subscriber_port
Port of the subscriber channel (SCTP and TCP); 0 keeps the default.
Definition c_api.h:255
int pin_io_threads
Pin the I/O threads when non-zero; 0=no pinning.
Definition c_api.h:265
const char * setup_endpoint
Endpoint of the setup channel; NULL keeps the default.
Definition c_api.h:257
int link_layer
0=ZMQ, 1=POSIX, -1=default
Definition c_api.h:252
const char * log_path
Log file; NULL=auto (/tmp/e3_ROLE[_ID]_EUID.log).
Definition c_api.h:263
size_t io_threads
Number of I/O threads; 0=default.
Definition c_api.h:261
uint16_t setup_port
Port of the setup channel (SCTP and TCP); 0 keeps the default.
Definition c_api.h:254
uint16_t publisher_port
Port of the publisher channel (SCTP and TCP); 0 keeps the default.
Definition c_api.h:256
int io_thread_affinity
Logical core to pin to; Linux only, best-effort.
Definition c_api.h:266
const char * ran_identifier
RAN identifier; NULL keeps the default.
Definition c_api.h:251
const char * subscriber_endpoint
Endpoint of the subscriber channel; NULL keeps the default.
Definition c_api.h:258
int transport_layer
0=SCTP, 1=TCP, 2=IPC, -1=default
Definition c_api.h:253
uint32_t dapp_idle_timeout_s
Seconds without a message from a dApp before the RAN releases and removes it; 0=never.
Definition c_api.h:269
const char * publisher_endpoint
Endpoint of the publisher channel; NULL keeps the default.
Definition c_api.h:259
int set_dapp_idle_timeout
Apply dapp_idle_timeout_s when non-zero; 0=keep the library default (1800 s).
Definition c_api.h:268
What e3_service_model_handle_t points to: a ServiceModel that calls back into C.
Definition c_api.cpp:32
e3_sm_stop_cb sm_stop
Called when the SM should stop.
Definition c_api.cpp:45
ErrorCode start() override
Start the SM processing.
Definition c_api.cpp:95
uint32_t ran_function_id_s
RAN function identifier.
Definition c_api.cpp:36
void stop() override
Stop the SM processing.
Definition c_api.cpp:99
void destroy() override
Destroy the SM and release resources.
Definition c_api.cpp:92
e3_sm_process_control_cb sm_process_control
Called for each control action.
Definition c_api.cpp:47
e3_sm_init_cb sm_init
Called on registration.
Definition c_api.cpp:42
void * sm_context
Passed to every callback.
Definition c_api.cpp:49
std::string name_s
Service Model name.
Definition c_api.cpp:34
ErrorCode handle_control_action(uint32_t request_message_id, const DAppControlAction &action) override
Process a control action from a dApp.
Definition c_api.cpp:112
std::vector< uint32_t > control_ids_s
Control identifiers it supports.
Definition c_api.cpp:38
ErrorCode init() override
Initialize the SM.
Definition c_api.cpp:88
bool is_running() const override
Check if SM is currently running.
Definition c_api.cpp:102
std::vector< uint32_t > telemetry_ids() const override
Get telemetry IDs supported by this SM.
Definition c_api.cpp:85
e3_sm_start_cb sm_start
Called when the SM should start.
Definition c_api.cpp:44
bool transferred_to_agent
Whether ownership was transferred to an agent.
Definition c_api.cpp:52
std::string name() const override
Get SM name.
Definition c_api.cpp:82
e3_sm_granted_periodicity_cb sm_granted_periodicity
Asked for the interval it keeps.
Definition c_api.cpp:48
std::vector< uint32_t > control_ids() const override
Get control IDs supported by this SM.
Definition c_api.cpp:86
uint32_t ran_function_id() const override
Get RAN function ID for this SM.
Definition c_api.cpp:84
std::vector< uint32_t > telemetry_ids_s
Telemetry identifiers it supports.
Definition c_api.cpp:37
uint32_t version() const override
Get SM version.
Definition c_api.cpp:83
uint32_t version_s
Service Model version.
Definition c_api.cpp:35
std::vector< uint8_t > ran_function_data_s
Opaque RAN function data.
Definition c_api.cpp:39
e3_sm_is_running_cb sm_is_running
Called to ask whether the SM runs.
Definition c_api.cpp:46
std::vector< uint8_t > ran_function_data() const override
RAN-function-specific opaque data (required, 1..32768 bytes).
Definition c_api.cpp:87
e3_sm_destroy_cb sm_destroy
Called on destruction.
Definition c_api.cpp:43
ErrorCode emit_pdu(Pdu &&pdu)
Queue a PDU the SM emits.
Definition c_api.cpp:137
ErrorCode answer_control(uint32_t dapp_id, uint32_t request_id, const ControlResult &result)
Answer a dApp control.
Definition c_api.cpp:148
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.
Definition c_api.cpp:107
e3_service_model_handle_s(const e3_c_service_model_desc_t &desc)
Copy a descriptor.
Definition c_api.cpp:58
E3AP Control Response structure.
Definition types.hpp:366
uint32_t request_id
Message id of the control this answers.
Definition types.hpp:367
uint32_t control_identifier
Control the answer is about.
Definition types.hpp:370
std::optional< Cause > cause
Why the control was refused (negative only).
Definition types.hpp:372
ResponseCode response_code
Response code (positive/negative).
Definition types.hpp:371
uint32_t ran_function_identifier
RAN function of the control.
Definition types.hpp:369
uint32_t dapp_identifier
dApp the control belongs to
Definition types.hpp:368
std::optional< std::string > detail
Definition types.hpp:373
std::optional< std::vector< uint8_t > > control_outcome
Definition types.hpp:376
What a Service Model answers to a control (see ServiceModel::respond_to_control).
Definition types.hpp:382
ResponseCode response_code
Whether the control was applied.
Definition types.hpp:383
std::optional< std::string > detail
UTF-8 text for the cause, up to MAX_DETAIL_SIZE bytes.
Definition types.hpp:385
std::optional< Cause > cause
Why not (negative only).
Definition types.hpp:384
std::vector< uint8_t > outcome
Opaque service-model content; empty for none.
Definition types.hpp:386
E3AP dApp Control Action structure.
Definition types.hpp:332
uint32_t ran_function_identifier
RAN function the control is for.
Definition types.hpp:334
std::vector< uint8_t > action_data
Definition types.hpp:336
uint32_t dapp_identifier
dApp that sends the control
Definition types.hpp:333
uint32_t control_identifier
Control identifier.
Definition types.hpp:335
E3AP dApp Report structure.
Definition types.hpp:392
uint32_t dapp_identifier
dApp that sends the report
Definition types.hpp:393
uint32_t sequence_id
Definition types.hpp:398
std::vector< uint8_t > report_data
Definition types.hpp:395
uint32_t ran_function_identifier
RAN function the report is for.
Definition types.hpp:394
Configuration for E3Agent.
Definition types.hpp:506
std::string log_path
Path of the shared log file. Empty (default) => auto-generated.
Definition types.hpp:667
std::string subscriber_endpoint
Endpoint URI of the inbound channel (ZeroMQ).
Definition types.hpp:544
int log_level
Logging verbosity: 0=none, 1=error, 2=warn, 3=info, 4=debug, 5=trace.
Definition types.hpp:655
uint16_t setup_port
Port of the setup channel; the one port of the POSIX link.
Definition types.hpp:534
int io_thread_affinity
CPU core to pin the subscriber and publisher I/O threads to.
Definition types.hpp:640
EncodingFormat encoding
PDU encoding format (ASN.1 PER or JSON).
Definition types.hpp:583
E3LinkLayer link_layer
Link-layer transport (ZMQ or POSIX).
Definition types.hpp:528
std::string publisher_endpoint
Endpoint URI of the outbound channel (ZeroMQ).
Definition types.hpp:545
uint16_t subscriber_port
Port of the inbound control/subscription channel (ZeroMQ).
Definition types.hpp:535
uint32_t dapp_idle_timeout_s
Seconds a RAN waits for a message from a dApp before it removes the dApp.
Definition types.hpp:605
std::string ran_identifier
Unique identifier for this RAN function (e.g. "DU-1").
Definition types.hpp:511
E3TransportLayer transport_layer
Transport-layer protocol (SCTP, TCP, IPC).
Definition types.hpp:530
size_t io_threads
Number of I/O threads (used by ZMQ context).
Definition types.hpp:627
std::string setup_endpoint
Endpoint URI of the setup channel; the one endpoint of the POSIX link.
Definition types.hpp:543
uint16_t publisher_port
Port of the outbound indication/publication channel (ZeroMQ).
Definition types.hpp:536
E3AP Indication Message structure.
Definition types.hpp:323
uint32_t ran_function_identifier
RAN function identifier.
Definition types.hpp:325
std::vector< uint8_t > protocol_data
Opaque payload of the service model.
Definition types.hpp:326
uint32_t dapp_identifier
dApp the indication is for
Definition types.hpp:324
E3AP Message Acknowledgment structure.
Definition types.hpp:351
ResponseCode response_code
Response code (positive/negative).
Definition types.hpp:353
uint32_t request_id
ID of the request being acknowledged.
Definition types.hpp:352
Generic E3AP PDU structure.
Definition types.hpp:448
uint64_t enqueue_seq
Set by queue_outbound; keys the [latrec] L-stage records.
Definition types.hpp:452
PduChoice choice
The message itself.
Definition types.hpp:450
E3AP Protocol Types - Vendor-neutral type definitions.