26inline std::optional<uint32_t> opt_u32(
int v) {
27 if (v < 0)
return std::nullopt;
28 return static_cast<uint32_t
>(v);
32inline void set_refusal(
E3Event& ev,
const std::optional<libe3::Cause>& cause,
33 const std::optional<std::string>& detail) {
34 if (cause) ev.
cause =
static_cast<int>(*cause);
35 if (detail) ev.
detail = *detail;
48 queue(queue_capacity) {}
50 std::unique_ptr<libe3::E3Agent>
agent;
55 std::atomic<unsigned long long>
dropped{0};
69 const uint64_t kind =
static_cast<uint64_t
>(ev.
kind);
74 if (
queue.push(std::move(ev)) != libe3::ErrorCode::SUCCESS) {
75 dropped.fetch_add(1, std::memory_order_relaxed);
85 impl_ = std::make_unique<Impl>(std::move(config), queue_capacity);
86 Impl* impl = impl_.get();
87 auto& agent = *impl->
agent;
133 std::lock_guard<std::mutex> lk(impl->
setup_mu);
172 if (r.control_outcome && !r.control_outcome->empty()) {
174 ev.
payload = *r.control_outcome;
183 impl_->queue.shutdown();
184 if (impl_->agent) impl_->agent->stop();
192 impl_->queue.rearm();
193 return static_cast<int>(impl_->agent->start());
197 return static_cast<int>(
198 impl_->agent->wait_for_setup(std::chrono::milliseconds(timeout_ms)));
202 return static_cast<int>(impl_->agent->release());
206 impl_->queue.shutdown();
207 impl_->agent->stop();
211 auto id = impl_->agent->dapp_id();
212 return id ?
static_cast<long>(*id) : -1;
216 std::lock_guard<std::mutex> lk(impl_->setup_mu);
217 return impl_->have_setup ? impl_->setup.ran_identifier : std::string{};
221 std::lock_guard<std::mutex> lk(impl_->setup_mu);
222 if (!impl_->have_setup)
return -1;
223 return static_cast<int>(impl_->setup.response_code);
227 std::lock_guard<std::mutex> lk(impl_->setup_mu);
228 return impl_->have_setup ? impl_->setup.ran_function_list.size() : 0;
232 std::lock_guard<std::mutex> lk(impl_->setup_mu);
233 if (!impl_->have_setup || i >= impl_->setup.ran_function_list.size())
return 0;
234 return impl_->setup.ran_function_list[i].ran_function_identifier;
238 std::lock_guard<std::mutex> lk(impl_->setup_mu);
239 if (!impl_->have_setup || i >= impl_->setup.ran_function_list.size())
return {};
240 return impl_->setup.ran_function_list[i].telemetry_identifier_list;
244 std::lock_guard<std::mutex> lk(impl_->setup_mu);
245 if (!impl_->have_setup || i >= impl_->setup.ran_function_list.size())
return {};
246 return impl_->setup.ran_function_list[i].control_identifier_list;
250 std::lock_guard<std::mutex> lk(impl_->setup_mu);
251 if (!impl_->have_setup || i >= impl_->setup.ran_function_list.size())
return {};
252 return impl_->setup.ran_function_list[i].ran_function_data;
256 std::vector<uint32_t> telemetry_ids,
257 std::vector<uint32_t> control_ids,
260 uint32_t request_id = 0;
262 ran_function_id, std::move(telemetry_ids), std::move(control_ids),
263 opt_u32(sub_time_ms), opt_u32(periodicity), &request_id);
267 if (rc == ErrorCode::SUCCESS) {
268 return static_cast<int64_t
>(request_id);
270 return static_cast<int64_t
>(rc);
274 return static_cast<int>(impl_->agent->unsubscribe(ran_function_id));
278 std::vector<uint8_t> action_data,
279 uint32_t sequence_id,
281 uint32_t message_id = 0;
282 ErrorCode rc = impl_->agent->send_control(
283 ran_function_id, control_id, std::move(action_data), sequence_id, &message_id, request_ack);
287 if (rc == ErrorCode::SUCCESS) {
288 return static_cast<int64_t
>(message_id);
290 return static_cast<int64_t
>(rc);
294 uint32_t sequence_id) {
295 uint32_t message_id = 0;
296 ErrorCode rc = impl_->agent->send_report(
297 ran_function_id, std::move(report_data), sequence_id, &message_id);
299 if (rc == ErrorCode::SUCCESS) {
300 return static_cast<int64_t
>(message_id);
302 return static_cast<int64_t
>(rc);
306 return static_cast<int>(impl_->agent->send_message_ack(
311 uint32_t control_id,
int response_code,
int cause,
312 std::string detail, std::vector<uint8_t> outcome) {
317 if (!detail.empty()) result.
detail = std::move(detail);
318 result.
outcome = std::move(outcome);
319 return static_cast<int>(
320 impl_->agent->send_control_response(request_id, ran_function_id, control_id, result));
324 std::vector<E3Event> out;
325 if (max_batch == 0)
return out;
326 auto& queue = impl_->queue;
334 std::optional<E3Event> first =
335 (timeout_ms <= 0) ? queue.try_pop()
336 : queue.pop(std::chrono::milliseconds(timeout_ms));
337 if (!first)
return out;
339 out.reserve(std::min(max_batch, queue.capacity()));
340 out.push_back(std::move(*first));
341 while (out.size() < max_batch) {
342 auto next = queue.try_pop();
344 out.push_back(std::move(*next));
348 for (std::size_t i = 0; i < out.size(); ++i) {
355 return impl_->dropped.load(std::memory_order_relaxed);
E3Agent - Main façade for RAN vendor integration.
Lock-free bounded blocking queue.
uint32_t setup_ran_function_id(std::size_t i) const
RAN function id of an advertised entry.
int send_control_response(uint32_t request_id, uint32_t ran_function_id, uint32_t control_id, int response_code, int cause, std::string detail, std::vector< uint8_t > outcome)
Answer an xApp control that has request_ack (E3_EVENT_XAPP_CONTROL).
int setup_response_code() const
SetupResponse code.
int unsubscribe(uint32_t ran_function_id)
Delete a previously created subscription.
std::vector< E3Event > poll_events(std::size_t max_batch, int timeout_ms)
Drain up to max_batch inbound events, waiting up to timeout_ms for the first.
std::vector< uint8_t > setup_ran_function_data(std::size_t i) const
Opaque ranFunctionData bytes of an advertised entry.
std::vector< uint32_t > setup_ran_function_telemetry(std::size_t i) const
Telemetry ids of an advertised entry.
std::string ran_identifier() const
RAN identifier from the SetupResponse.
unsigned long long dropped_events() const
Total inbound events dropped due to ring overflow (backpressure).
void stop()
Stop the agent and shut down the ring so a blocked poll_events returns an empty batch (i....
int release()
Send a ReleaseMessage (session keeps running until stop).
int send_message_ack(uint32_t request_id, int response_code)
Acknowledge a request. DEPRECATED TO BE REMOVED: answer an xApp control with send_control_response.
int start()
Start the agent, re-arming the inbound ring so a stop()->start() cycle works again.
int wait_for_setup(int timeout_ms)
Block until the setup handshake completes.
~DAppSession()
Stops the agent and drops the queue.
int64_t send_report(uint32_t ran_function_id, std::vector< uint8_t > report_data, uint32_t sequence_id)
Send a dApp report to the RAN.
int64_t send_control(uint32_t ran_function_id, uint32_t control_id, std::vector< uint8_t > action_data, uint32_t sequence_id=0, bool request_ack=false)
Send a dApp control action to the RAN.
long dapp_id() const
dApp id assigned at setup.
int64_t subscribe(uint32_t ran_function_id, std::vector< uint32_t > telemetry_ids, std::vector< uint32_t > control_ids, int sub_time_ms, int periodicity)
Subscribe to a RAN function (after a positive setup).
std::size_t setup_ran_function_count() const
Number of RAN functions advertised in the SetupResponse.
DAppSession(libe3::E3Config config, std::size_t queue_capacity=8192)
Construct the session and register all inbound handlers.
std::vector< uint32_t > setup_ran_function_control(std::size_t i) const
Control ids of an advertised entry.
E3Agent - Main façade class for RAN vendors.
Python-facing dApp session over libe3 — batched, low-latency seam.
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_tnow(void)
static void latrec_tstamp_at(uint64_t seq, uint8_t stage, uint64_t aux, uint64_t aux2, uint64_t t_ns)
@ LATREC_DROP_SESSION_QUEUE
uint64_t latrec_seq_next(void)
latrec_t * latrec_tls_open_as(const char *role)
Lock-free bounded blocking queue for the E3AP hot paths.
@ E3_EVENT_SUBSCRIPTION_RESPONSE
RAN → dApp SubscriptionResponse.
@ E3_EVENT_SETUP_RESPONSE
RAN → dApp SetupResponse.
@ E3_EVENT_INDICATION
RAN → dApp IndicationMessage.
@ E3_EVENT_DISCONNECT
the RAN is gone; see E3Event::disconnect_reason
@ E3_EVENT_XAPP_CONTROL
xApp → dApp XAppControlAction
@ E3_EVENT_CONTROL_RESPONSE
RAN → dApp ControlResponse.
@ E3_EVENT_MESSAGE_ACK
RAN → dApp MessageAck. DEPRECATED TO BE REMOVED: libe3 does not send one.
ErrorCode
Error codes returned by libe3 operations Use shared error-code list (see libe3/error_codes....
@ DAPP
dApp (connects to a RAN agent)
ResponseCode
E3AP response codes.
@ NEGATIVE
Request rejected.
@ POSITIVE
Request accepted.
Cause cause_from_value(long value) noexcept
Read a Cause from its wire value.
DisconnectReason
Why a dApp's session with the RAN ended (see DisconnectHandler).
E3AP Control Response structure.
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.
Configuration for E3Agent.
E3Role role
Role: RAN (today's default — binds sockets) or DAPP (connects).
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.
std::optional< Cause > cause
Why the request was refused (negative only).
ResponseCode response_code
Response code (positive/negative).
std::optional< std::string > detail
UTF-8 text for the cause, up to MAX_DETAIL_SIZE bytes.
uint32_t request_id
ID of the request being acknowledged.
E3AP Setup Response structure.
E3AP Subscription Response structure.
std::optional< Cause > cause
Why the subscription was refused (negative only).
std::optional< uint32_t > subscription_id
Subscription ID (optional).
std::optional< std::vector< uint32_t > > telemetry_identifier_list
Granted telemetry ids (absent = not reported, empty = none granted).
std::optional< uint32_t > ran_function_identifier
RAN function the grant is for.
uint32_t request_id
ID of the corresponding SubscriptionRequest.
std::optional< std::string > detail
UTF-8 text for the cause, up to MAX_DETAIL_SIZE bytes.
uint32_t dapp_identifier
dApp identifier
std::optional< uint32_t > periodicity
Least microseconds the RAN keeps between two indications (absent = not reported).
std::optional< std::vector< uint32_t > > control_identifier_list
Granted control ids (absent = not reported, empty = none granted).
ResponseCode response_code
Response code (positive/negative).
E3AP xApp Control Action structure.
std::vector< uint8_t > xapp_control_data
uint32_t dapp_identifier
dApp the control is for
uint32_t ran_function_identifier
RAN function the control is for.
What a DAppSession holds: the agent, the event queue and the setup snapshot.
void enqueue(E3Event ev)
Queue an event for poll_events().
std::mutex setup_mu
Guards have_setup and setup.
bool have_setup
Whether a setup response has been seen.
libe3::SetupResponse setup
The latest setup response.
std::atomic< unsigned long long > dropped
Events dropped because the queue was full.
std::unique_ptr< libe3::E3Agent > agent
The dApp agent.
Impl(libe3::E3Config config, std::size_t queue_capacity)
Create the agent and the event queue.
libe3::LockFreeQueue< E3Event > queue
Events waiting for poll_events().
One inbound E3AP event, POD-flat for a clean SWIG crossing.
uint32_t ran_function_id
RAN function (indication / xApp control / subscription response).
uint32_t sequence_id
loop correlation id (xApp control); echo it on the control you re-issue
int kind
one of E3EventKind
uint32_t dapp_id
dApp identifier the message targets
std::vector< uint32_t > control_granted
granted control ids
bool has_outcome
control response: payload is the Service Model's outcome
std::vector< uint32_t > telemetry_granted
granted telemetry ids
uint32_t request_id
request/message id (subscription response / control response / xApp control); for a control response,...
int disconnect_reason
disconnect: 0=released by RAN, 1=connection lost, -1=n/a
long periodicity
least microseconds the RAN keeps between two indications (subscription response), -1 = not reported
uint32_t subscription_id
subscription id (subscription response)
int response_code
0=positive, 1=negative, -1=n/a
bool has_control_granted
control_granted was reported
uint64_t trace_seq
set when queued; keys the [latrec] LQ-stage records
std::vector< uint8_t > payload
opaque E3SM bytes (indication / xApp control)
int cause
why a negative response (setup, subscription or control) was refused, a libe3::Cause value 0 to 14; -...
bool request_ack
xApp control: the RAN wants a control response; answer it with send_control_response
bool has_telemetry_granted
telemetry_granted was reported
uint32_t control_id
control identifier (control response)
std::string detail
the RAN's text for the refusal; empty = none given