libe3 0.2.5
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
zmq_connector.hpp
Go to the documentation of this file.
1/**
2 * @file zmq_connector.hpp
3 * @brief ZeroMQ-based E3 Connector
4 *
5 * SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef LIBE3_ZMQ_CONNECTOR_HPP
10#define LIBE3_ZMQ_CONNECTOR_HPP
11
13#include <atomic>
14#include <memory>
15
16namespace libe3 {
17
18/**
19 * @brief ZeroMQ-based E3 connector
20 *
21 * Provides transport using ZeroMQ sockets. Supports TCP and IPC transports.
22 * Ported from the original C implementation's zeromq_* functions.
23 */
25public:
28 const std::string& setup_endpoint,
29 const std::string& inbound_endpoint,
30 const std::string& outbound_endpoint,
31 uint16_t setup_port,
32 uint16_t inbound_port,
33 uint16_t outbound_port,
34 size_t io_threads
35 );
36
37 ~ZmqE3Connector() override;
38
40 int recv_setup_request(std::vector<uint8_t>& buffer) override;
41 ErrorCode send_response(const std::vector<uint8_t>& data) override;
43 int receive(std::vector<uint8_t>& buffer) override;
45 ErrorCode send(const std::vector<uint8_t>& data) override;
46
47 // Client-side (dApp role) operations
49 ErrorCode send_setup_request_client(const std::vector<uint8_t>& data) override;
50 int recv_setup_response_client(std::vector<uint8_t>& buffer) override;
53
54 void dispose() override;
55 void shutdown() override;
56
57 E3LinkLayer link_layer() const noexcept override {
58 return E3LinkLayer::ZMQ;
59 }
60
61 E3TransportLayer transport_layer() const noexcept override {
62 return transport_layer_;
63 }
64
65 bool is_connected() const noexcept override {
66 return connected_;
67 }
68
69private:
70 E3TransportLayer transport_layer_;
71 size_t io_threads_;
72 uint16_t setup_port_;
73 uint16_t inbound_port_;
74 uint16_t outbound_port_;
75
76 void* context_{nullptr};
77 void* setup_socket_{nullptr};
78 void* inbound_socket_{nullptr};
79 void* outbound_socket_{nullptr};
80
81 bool connected_{false};
82
83 // Set by shutdown(). shutdown() itself does not touch outbound_socket_
84 // (only recv timeouts matter there), so send() cannot tell a genuine
85 // transport failure apart from one racing a concurrent shutdown()
86 // without this -- see the equivalent check in PosixE3Connector::send().
87 std::atomic<bool> shutdown_requested_{false};
88
89 void setup_ipc_permissions(const std::string& path);
90 bool reset_setup_socket();
91};
92
93} // namespace libe3
94
95#endif // LIBE3_ZMQ_CONNECTOR_HPP
const std::string & inbound_endpoint() const noexcept
Get inbound endpoint.
const std::string & setup_endpoint() const noexcept
Get setup endpoint.
const std::string & outbound_endpoint() const noexcept
Get outbound endpoint.
E3Connector(const E3Connector &)=delete
ErrorCode setup_outbound_connection_client() override
Connect the outbound channel (dApp role: PUB connect to the RAN's subscriber endpoint).
E3LinkLayer link_layer() const noexcept override
Get the link layer type.
ErrorCode send_setup_request_client(const std::vector< uint8_t > &data) override
Send a SetupRequest on the setup channel (dApp role).
E3TransportLayer transport_layer() const noexcept override
Get the transport layer type.
ErrorCode setup_initial_connection() override
Set up the initial connection (setup channel).
ErrorCode setup_initial_connection_client() override
Connect the setup channel (dApp role: REQ connect).
void dispose() override
Clean up and release all resources.
int recv_setup_request(std::vector< uint8_t > &buffer) override
Receive a setup request.
ZmqE3Connector(E3TransportLayer transport_layer, const std::string &setup_endpoint, const std::string &inbound_endpoint, const std::string &outbound_endpoint, uint16_t setup_port, uint16_t inbound_port, uint16_t outbound_port, size_t io_threads)
int receive(std::vector< uint8_t > &buffer) override
Receive data from the inbound channel.
ErrorCode setup_inbound_connection_client() override
Connect the inbound channel (dApp role: SUB connect to the RAN's publisher endpoint).
ErrorCode setup_inbound_connection() override
Set up the inbound connection (SUB channel).
ErrorCode send_response(const std::vector< uint8_t > &data) override
Send a setup response.
ErrorCode send(const std::vector< uint8_t > &data) override
Send data on the outbound channel.
ErrorCode setup_outbound_connection() override
Set up the outbound connection (PUB channel).
int recv_setup_response_client(std::vector< uint8_t > &buffer) override
Receive a SetupResponse on the setup channel (dApp role).
void shutdown() override
Interrupt blocking operations for shutdown.
bool is_connected() const noexcept override
Check if connector is connected.
Abstract E3 Connector interface for transport layer.
ErrorCode
Error codes returned by libe3 operations Use shared error-code list (see libe3/error_codes....
Definition types.hpp:141
E3TransportLayer
Transport layer types (matches Python E3TransportLayer).
Definition types.hpp:83
E3LinkLayer
Link layer types (matches Python E3LinkLayer).
Definition types.hpp:60
@ ZMQ
ZeroMQ-based transport.
Definition types.hpp:61