libe3 0.6.1
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
libe3::PosixE3Connector Class Reference

POSIX socket-based E3 connector: one endpoint per dApp. More...

#include <posix_connector.hpp>

Inheritance diagram for libe3::PosixE3Connector:
libe3::E3Connector

Classes

struct  Peer
 One accepted connection of a RAN. Closes its socket when the last reference goes. More...
struct  Queued
 A PDU read from a peer and waiting for the thread that takes it. More...

Public Member Functions

 PosixE3Connector (E3TransportLayer transport_layer, const std::string &endpoint, uint16_t port, const PosixOptions &options)
 Create a POSIX connector.
 ~PosixE3Connector () override
 Close every socket.
ErrorCode setup_initial_connection () override
 Set up the initial connection (setup channel).
int recv_setup_request (std::vector< uint8_t > &buffer) override
 Receive a setup request.
ErrorCode send_response (const std::vector< uint8_t > &data) override
 Send a setup response.
ErrorCode setup_inbound_connection () override
 Set up the inbound connection (SUB channel).
int receive (std::vector< uint8_t > &buffer) override
 Receive data from the inbound channel.
ErrorCode setup_outbound_connection () override
 Set up the outbound connection (PUB channel).
ErrorCode send (const std::vector< uint8_t > &data) override
 Send data on the outbound channel.
ErrorCode send_to (uint64_t peer_token, const std::vector< uint8_t > &data, PduClass kind) override
 Send data to one peer, or to all of them (RAN role).
ErrorCode setup_initial_connection_client () override
 Connect the setup channel (dApp role: REQ connect).
ErrorCode send_setup_request_client (const std::vector< uint8_t > &data) override
 Send a SetupRequest on the setup channel (dApp role).
int recv_setup_response_client (std::vector< uint8_t > &buffer) override
 Receive a SetupResponse on the setup channel (dApp role).
ErrorCode setup_inbound_connection_client () override
 Connect the inbound channel (dApp role: SUB connect to the RAN's publisher endpoint).
ErrorCode setup_outbound_connection_client () override
 Connect the outbound channel (dApp role: PUB connect to the RAN's subscriber endpoint).
void dispose () override
 Clean up and release all resources.
void shutdown () override
 Interrupt blocking operations for shutdown.
uint64_t last_peer_token () const override
 Which peer supplied the bytes the last receive() returned (RAN role).
uint64_t last_setup_peer_token () const override
 Which peer sent the setup request the last recv_setup_request() returned (RAN role).
std::vector< uint64_t > take_closed_peers () override
 Peers whose connection has closed since the last call (RAN role).
E3LinkLayer link_layer () const noexcept override
 Get the link layer type.
E3TransportLayer transport_layer () const noexcept override
 Get the transport layer type.
bool is_connected () const noexcept override
 Check if connector is connected.
Public Member Functions inherited from libe3::E3Connector
virtual ~E3Connector ()=default
 E3Connector (const E3Connector &)=delete
E3Connector & operator= (const E3Connector &)=delete
 E3Connector (E3Connector &&)=default
 Move constructor.
E3Connector & operator= (E3Connector &&)=default
 Move assignment.
void set_role (E3Role role) noexcept
 Set role (RAN or DAPP). Affects bind vs connect direction and cleanup behaviour. Must be set before any setup_* call. Default RAN.
E3Role role () const noexcept
 Get current role.
const std::string & setup_endpoint () const noexcept
 Get setup endpoint.
const std::string & inbound_endpoint () const noexcept
 Get inbound endpoint.
const std::string & outbound_endpoint () const noexcept
 Get outbound endpoint.

Additional Inherited Members

Protected Member Functions inherited from libe3::E3Connector
 E3Connector ()=default
Protected Attributes inherited from libe3::E3Connector
std::string setup_endpoint_
 Endpoint of the setup channel.
std::string inbound_endpoint_
 Endpoint of the inbound channel.
std::string outbound_endpoint_
 Endpoint of the outbound channel.
E3Role role_ {E3Role::RAN}
 Role of this peer.

Detailed Description

POSIX socket-based E3 connector: one endpoint per dApp.

Supports TCP, SCTP and IPC. A dApp opens one connection to the RAN's single endpoint and the setup, inbound and outbound traffic all use it; the three channels of E3Connector are logical. The first PDU on a connection is the dApp's setup request and goes to recv_setup_request(); every later PDU goes to receive(). The inbound thread is the only reader of the sockets, so the receive path costs the same as with one channel per socket.

Each PDU is one message. SCTP and IPC (a sequenced-packet socket) keep message boundaries and carry no prefix. TCP is a byte stream and prefixes each PDU with its length as four bytes in network order, in both directions. SCTP stamps payload protocol id 0x00E3A001 and sends indications on stream 1, everything else on stream 0.

The RAN names each accepted connection with a token that is never reused (see E3Connector::last_peer_token) and can send to one peer or to all.

Definition at line 42 of file posix_connector.hpp.

Constructor & Destructor Documentation

◆ PosixE3Connector()

libe3::PosixE3Connector::PosixE3Connector ( E3TransportLayer transport_layer,
const std::string & endpoint,
uint16_t port,
const PosixOptions & options )

Create a POSIX connector.

Parameters
transport_layerSCTP, TCP or IPC
endpointEndpoint of the link. IPC: a path, "ipc://" prefix optional, and the library's shared default is replaced by /tmp/dapps/e3. TCP and SCTP: "tcp://host:port" or "sctp://host:port" (a host in brackets for IPv6); anything else means the default host and port
portPort of the link (SCTP and TCP) when the endpoint names none
optionsSocket and admission options

Definition at line 380 of file posix_connector.cpp.

◆ ~PosixE3Connector()

libe3::PosixE3Connector::~PosixE3Connector ( )
override

Close every socket.

Definition at line 400 of file posix_connector.cpp.

Member Function Documentation

◆ dispose()

void libe3::PosixE3Connector::dispose ( )
overridevirtual

Clean up and release all resources.

Implements libe3::E3Connector.

Definition at line 1139 of file posix_connector.cpp.

◆ is_connected()

bool libe3::PosixE3Connector::is_connected ( ) const
inlineoverridevirtualnoexcept

Check if connector is connected.

Returns
true once the connector has set up its connections

Implements libe3::E3Connector.

Definition at line 95 of file posix_connector.hpp.

◆ last_peer_token()

uint64_t libe3::PosixE3Connector::last_peer_token ( ) const
overridevirtual

Which peer supplied the bytes the last receive() returned (RAN role).

Call it on the thread that calls receive(), right after a receive() that returned bytes. A token names one accepted connection and is never reused by the same connector, so a closed peer's token cannot name a later one.

Returns
The peer's token, or 0 for a connector that cannot tell its peers apart (the default, and ZeroMQ)

Reimplemented from libe3::E3Connector.

Definition at line 963 of file posix_connector.cpp.

◆ last_setup_peer_token()

uint64_t libe3::PosixE3Connector::last_setup_peer_token ( ) const
overridevirtual

Which peer sent the setup request the last recv_setup_request() returned (RAN role).

Call it on the thread that calls recv_setup_request(), right after a call that returned bytes. The token is the one last_peer_token() gives for the same peer's later bytes, so a RAN can tie a dApp to its connection at setup.

Returns
The peer's token, or 0 for a connector that cannot tell its peers apart (the default, and ZeroMQ)

Reimplemented from libe3::E3Connector.

Definition at line 967 of file posix_connector.cpp.

◆ link_layer()

E3LinkLayer libe3::PosixE3Connector::link_layer ( ) const
inlineoverridevirtualnoexcept

Get the link layer type.

Returns
The link layer this connector runs on

Implements libe3::E3Connector.

Definition at line 87 of file posix_connector.hpp.

◆ receive()

int libe3::PosixE3Connector::receive ( std::vector< uint8_t > & buffer)
overridevirtual

Receive data from the inbound channel.

Parameters
bufferBuffer to store received data
Returns
Number of bytes received; 0 on timeout (nothing yet); ErrorCode::NOT_CONNECTED once the peer has closed (dApp role); any other negative ErrorCode on a transport error

Implements libe3::E3Connector.

Definition at line 840 of file posix_connector.cpp.

◆ recv_setup_request()

int libe3::PosixE3Connector::recv_setup_request ( std::vector< uint8_t > & buffer)
overridevirtual

Receive a setup request.

Blocks until a setup request is received on the setup channel.

Parameters
bufferBuffer to store received data
Returns
Number of bytes received, or negative error code

Implements libe3::E3Connector.

Definition at line 867 of file posix_connector.cpp.

◆ recv_setup_response_client()

int libe3::PosixE3Connector::recv_setup_response_client ( std::vector< uint8_t > & )
overridevirtual

Receive a SetupResponse on the setup channel (dApp role).

Returns
Number of bytes received, 0 on timeout, a negative ErrorCode on error

Reimplemented from libe3::E3Connector.

Definition at line 1034 of file posix_connector.cpp.

◆ send()

ErrorCode libe3::PosixE3Connector::send ( const std::vector< uint8_t > & data)
overridevirtual

Send data on the outbound channel.

Parameters
dataData to send
Returns
ErrorCode::SUCCESS on success, error code otherwise

Implements libe3::E3Connector.

Definition at line 914 of file posix_connector.cpp.

◆ send_response()

ErrorCode libe3::PosixE3Connector::send_response ( const std::vector< uint8_t > & data)
overridevirtual

Send a setup response.

Parameters
dataResponse data to send
Returns
ErrorCode::SUCCESS on success, error code otherwise

Implements libe3::E3Connector.

Definition at line 905 of file posix_connector.cpp.

◆ send_setup_request_client()

ErrorCode libe3::PosixE3Connector::send_setup_request_client ( const std::vector< uint8_t > & )
overridevirtual

Send a SetupRequest on the setup channel (dApp role).

Returns
ErrorCode::SUCCESS on success, an error code otherwise

Reimplemented from libe3::E3Connector.

Definition at line 1017 of file posix_connector.cpp.

◆ send_to()

ErrorCode libe3::PosixE3Connector::send_to ( uint64_t peer_token,
const std::vector< uint8_t > & data,
PduClass kind )
overridevirtual

Send data to one peer, or to all of them (RAN role).

The default broadcasts with send(), which is what a connector that cannot tell its peers apart does.

Parameters
peer_tokenThe peer named by last_peer_token() or last_setup_peer_token(); 0 sends to every peer
dataData to send
kindWhat the PDU is for
Returns
ErrorCode::SUCCESS on success, an error code otherwise

Reimplemented from libe3::E3Connector.

Definition at line 918 of file posix_connector.cpp.

◆ setup_inbound_connection()

ErrorCode libe3::PosixE3Connector::setup_inbound_connection ( )
overridevirtual

Set up the inbound connection (SUB channel).

This establishes the channel for receiving control actions from dApps.

Returns
ErrorCode::SUCCESS on success, error code otherwise

Implements libe3::E3Connector.

Definition at line 680 of file posix_connector.cpp.

◆ setup_inbound_connection_client()

ErrorCode libe3::PosixE3Connector::setup_inbound_connection_client ( )
overridevirtual

Connect the inbound channel (dApp role: SUB connect to the RAN's publisher endpoint).

Returns
ErrorCode::SUCCESS on success, an error code otherwise

Reimplemented from libe3::E3Connector.

Definition at line 1068 of file posix_connector.cpp.

◆ setup_initial_connection()

ErrorCode libe3::PosixE3Connector::setup_initial_connection ( )
overridevirtual

Set up the initial connection (setup channel).

This establishes the REQ/REP channel used for E3 Setup procedures.

Returns
ErrorCode::SUCCESS on success, error code otherwise

Implements libe3::E3Connector.

Definition at line 670 of file posix_connector.cpp.

◆ setup_initial_connection_client()

ErrorCode libe3::PosixE3Connector::setup_initial_connection_client ( )
overridevirtual

Connect the setup channel (dApp role: REQ connect).

Returns
ErrorCode::SUCCESS on success, ErrorCode::INVALID_PARAM if the connector has no dApp role

Reimplemented from libe3::E3Connector.

Definition at line 982 of file posix_connector.cpp.

◆ setup_outbound_connection()

ErrorCode libe3::PosixE3Connector::setup_outbound_connection ( )
overridevirtual

Set up the outbound connection (PUB channel).

This establishes the channel for sending indications to dApps.

Returns
ErrorCode::SUCCESS on success, error code otherwise

Implements libe3::E3Connector.

Definition at line 685 of file posix_connector.cpp.

◆ setup_outbound_connection_client()

ErrorCode libe3::PosixE3Connector::setup_outbound_connection_client ( )
overridevirtual

Connect the outbound channel (dApp role: PUB connect to the RAN's subscriber endpoint).

Returns
ErrorCode::SUCCESS on success, an error code otherwise

Reimplemented from libe3::E3Connector.

Definition at line 1072 of file posix_connector.cpp.

◆ shutdown()

void libe3::PosixE3Connector::shutdown ( )
overridevirtual

Interrupt blocking operations for shutdown.

Called before joining threads to unblock any blocking socket operations. Default implementation does nothing (for connectors that use timeouts).

Reimplemented from libe3::E3Connector.

Definition at line 1120 of file posix_connector.cpp.

◆ take_closed_peers()

std::vector< uint64_t > libe3::PosixE3Connector::take_closed_peers ( )
overridevirtual

Peers whose connection has closed since the last call (RAN role).

Call it on the thread that calls receive(). Each token is returned once, and only after the bytes that peer sent before closing were delivered. The default returns nothing: a connector that cannot tell its peers apart cannot tell that one left.

Returns
The tokens of the peers that closed, oldest first

Reimplemented from libe3::E3Connector.

Definition at line 971 of file posix_connector.cpp.

◆ transport_layer()

E3TransportLayer libe3::PosixE3Connector::transport_layer ( ) const
inlineoverridevirtualnoexcept

Get the transport layer type.

Returns
The transport layer this connector runs on

Implements libe3::E3Connector.

Definition at line 91 of file posix_connector.hpp.


The documentation for this class was generated from the following files: