Skip to content

Commit 4f92ef7

Browse files
authored
Add raweth transport (glue) (#286)
1 parent ae3c237 commit 4f92ef7

File tree

35 files changed

+383
-780
lines changed

35 files changed

+383
-780
lines changed

.github/workflows/build-check.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ jobs:
7575
run: |
7676
docker stop zenoh_router
7777
docker rm zenoh_router
78+
79+
raweth_build:
80+
name: Build and test raweth transport on ubuntu-latest
81+
runs-on: ubuntu-latest
82+
strategy:
83+
matrix:
84+
feature_reth: [1, 0]
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v4
88+
89+
- name: Build project
90+
run: |
91+
sudo apt install -y ninja-build
92+
CMAKE_GENERATOR=Ninja make
93+
python3 ./build/tests/raweth.py --reth $Z_FEATURE_RAWETH_TRANSPORT
94+
timeout-minutes: 5
95+
env:
96+
Z_FEATURE_RAWETH_TRANSPORT: ${{ matrix.feature_reth }}
97+

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,18 @@ set(Z_FEATURE_PUBLICATION 1 CACHE STRING "Toggle publication feature")
107107
set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
108108
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
109109
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
110+
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport feature")
110111
add_definition(Z_FEATURE_PUBLICATION=${Z_FEATURE_PUBLICATION})
111112
add_definition(Z_FEATURE_SUBSCRIPTION=${Z_FEATURE_SUBSCRIPTION})
112113
add_definition(Z_FEATURE_QUERY=${Z_FEATURE_QUERY})
113114
add_definition(Z_FEATURE_QUERYABLE=${Z_FEATURE_QUERYABLE})
115+
add_definition(Z_FEATURE_RAWETH_TRANSPORT=${Z_FEATURE_RAWETH_TRANSPORT})
114116
message(STATUS "Building with feature confing:\n\
115117
* PUBLICATION: ${Z_FEATURE_PUBLICATION}\n\
116118
* SUBSCRIPTION: ${Z_FEATURE_SUBSCRIPTION}\n\
117119
* QUERY: ${Z_FEATURE_QUERY}\n\
118-
* QUERYABLE: ${Z_FEATURE_QUERYABLE}")
120+
* QUERYABLE: ${Z_FEATURE_QUERYABLE}\n\
121+
* RAWETH: ${Z_FEATURE_RAWETH_TRANSPORT}")
119122

120123
# Print summary of CMAKE configurations
121124
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
@@ -300,6 +303,7 @@ if(UNIX OR MSVC)
300303
target_link_libraries(z_api_double_drop_test ${Libname})
301304

302305
configure_file(${PROJECT_SOURCE_DIR}/tests/modularity.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modularity.py COPYONLY)
306+
configure_file(${PROJECT_SOURCE_DIR}/tests/raweth.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/raweth.py COPYONLY)
303307

304308
enable_testing()
305309
add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)

GNUmakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Z_FEATURE_PUBLICATION?=1
5151
Z_FEATURE_SUBSCRIPTION?=1
5252
Z_FEATURE_QUERY?=1
5353
Z_FEATURE_QUERYABLE?=1
54+
Z_FEATURE_RAWETH_TRANSPORT?=0
5455

5556
# zenoh-pico/ directory
5657
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
@@ -67,7 +68,7 @@ CROSSIMG_PREFIX=zenoh-pico_
6768

6869
CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\
6970
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
70-
-DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
71+
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
7172

7273
all: make
7374

include/zenoh-pico/link/config/raweth.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
#include "zenoh-pico/config.h"
2121
#include "zenoh-pico/link/link.h"
2222

23-
#if Z_FEATURE_RAWETH_TRANSPORT == 1
24-
2523
#define RAWETH_SCHEMA "reth"
2624

2725
int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint);
28-
2926
int8_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint);
3027

31-
#endif /* Z_FEATURE_RAWETH_TRANSPORT */
3228
#endif /* ZENOH_PICO_LINK_CONFIG_RAWETH_H */

include/zenoh-pico/link/link.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "zenoh-pico/system/link/udp.h"
2929
#endif
3030

31+
#if Z_FEATURE_RAWETH_TRANSPORT == 1
32+
#include "zenoh-pico/system/link/raweth.h"
33+
#endif
34+
3135
#if Z_FEATURE_LINK_BLUETOOTH == 1
3236
#include "zenoh-pico/system/link/bt.h"
3337
#endif
@@ -52,6 +56,7 @@
5256
typedef enum {
5357
Z_LINK_CAP_TRANSPORT_UNICAST = 0,
5458
Z_LINK_CAP_TRANSPORT_MULTICAST = 1,
59+
Z_LINK_CAP_TRANSPORT_RAWETH = 2,
5560
} _z_link_cap_transport_t;
5661

5762
/**
@@ -73,7 +78,7 @@ typedef enum {
7378
* transport: 2 bits, see _z_link_cap_transport_t enum.
7479
* flow: 1 bit, see _z_link_cap_flow_t enum.
7580
* reliable: 1 bit, 1 if the link is reliable (network definition)
76-
* reserved: 4 bits, reserved for futur use
81+
* reserved: 4 bits, reserved for future use
7782
*/
7883
typedef struct _z_link_capabilities_t {
7984
uint8_t _transport : 2;
@@ -111,6 +116,9 @@ typedef struct _z_link_t {
111116
#endif
112117
#if Z_FEATURE_LINK_WS == 1
113118
_z_ws_socket_t _ws;
119+
#endif
120+
#if Z_FEATURE_RAWETH_TRANSPORT == 1
121+
_z_raweth_socket_t _raweth;
114122
#endif
115123
} _socket;
116124

include/zenoh-pico/system/platform/unix.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ typedef struct timeval z_time_t;
3535

3636
typedef struct {
3737
union {
38-
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1
38+
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 || \
39+
Z_FEATURE_RAWETH_TRANSPORT == 1
3940
int _fd;
4041
#endif
4142
};

include/zenoh-pico/transport/common/join.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/zenoh-pico/transport/common/lease.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "zenoh-pico/transport/transport.h"
1919

20+
int8_t _z_send_join(_z_transport_t *zt);
2021
int8_t _z_send_keep_alive(_z_transport_t *zt);
21-
void *_zp_lease_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks
2222

2323
#endif /* ZENOH_PICO_TRANSPORT_LEASE_H */

include/zenoh-pico/transport/multicast/join.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/zenoh-pico/transport/multicast/lease.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
#include "zenoh-pico/transport/transport.h"
1919

20+
int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm);
2021
int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm);
21-
int8_t _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
22-
int8_t _zp_multicast_stop_lease_task(_z_transport_t *zt);
22+
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task);
23+
int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm);
2324
void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks
2425

2526
#endif /* ZENOH_PICO_MULTICAST_LEASE_H */

include/zenoh-pico/transport/multicast/rx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "zenoh-pico/transport/transport.h"
1919

2020
int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);
21-
int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);
2221
int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg,
2322
_z_bytes_t *addr);
2423

include/zenoh-pico/transport/raweth/join.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

include/zenoh-pico/transport/raweth/lease.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

include/zenoh-pico/transport/raweth/transport.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

include/zenoh-pico/transport/transport.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ _Z_LIST_DEFINE(_z_transport_peer_entry, _z_transport_peer_entry_t)
5353
_z_transport_peer_entry_list_t *_z_transport_peer_entry_list_insert(_z_transport_peer_entry_list_t *root,
5454
_z_transport_peer_entry_t *entry);
5555

56+
// Forward declaration to be used in _zp_f_send_tmsg*
57+
typedef struct _z_transport_multicast_t _z_transport_multicast_t;
58+
// Send function prototype
59+
typedef int8_t (*_zp_f_send_tmsg)(_z_transport_multicast_t *self, const _z_transport_message_t *t_msg);
60+
5661
typedef struct {
5762
// Session associated to the transport
5863

@@ -93,7 +98,7 @@ typedef struct {
9398
volatile _Bool _transmitted;
9499
} _z_transport_unicast_t;
95100

96-
typedef struct {
101+
typedef struct _z_transport_multicast_t {
97102
// Session associated to the transport
98103
void *_session;
99104

@@ -121,6 +126,9 @@ typedef struct {
121126
// Known valid peers
122127
_z_transport_peer_entry_list_t *_peers;
123128

129+
// T message send function
130+
_zp_f_send_tmsg _send_f;
131+
124132
#if Z_FEATURE_MULTI_THREAD == 1
125133
_z_task_t *_read_task;
126134
_z_task_t *_lease_task;
@@ -135,11 +143,13 @@ typedef struct {
135143
union {
136144
_z_transport_unicast_t _unicast;
137145
_z_transport_multicast_t _multicast;
146+
_z_transport_multicast_t _raweth;
138147
} _transport;
139148

140149
enum {
141150
_Z_TRANSPORT_UNICAST_TYPE,
142151
_Z_TRANSPORT_MULTICAST_TYPE,
152+
_Z_TRANSPORT_RAWETH_TYPE,
143153
} _type;
144154
} _z_transport_t;
145155

src/api/api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) {
547547
// Call transport function
548548
switch (zs._val->_tp._type) {
549549
case _Z_TRANSPORT_MULTICAST_TYPE:
550+
case _Z_TRANSPORT_RAWETH_TYPE:
550551
_zp_multicast_fetch_zid(&zs._val->_tp, callback);
551552
break;
552553
default:
@@ -638,7 +639,7 @@ z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, con
638639
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
639640
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
640641
// resource declarations are only performed on unicast transports.
641-
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
642+
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
642643
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
643644
if (r == NULL) {
644645
uint16_t id = _z_declare_resource(zs._val, keyexpr);
@@ -794,7 +795,7 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o
794795
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
795796
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
796797
// resource declarations are only performed on unicast transports.
797-
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
798+
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
798799
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
799800
if (r == NULL) {
800801
uint16_t id = _z_declare_resource(zs._val, keyexpr);
@@ -897,7 +898,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
897898
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
898899
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
899900
// resource declarations are only performed on unicast transports.
900-
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
901+
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
901902
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
902903
if (r == NULL) {
903904
char *wild = strpbrk(keyexpr._suffix, "*$");

src/link/link.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stddef.h>
1818

1919
#include "zenoh-pico/config.h"
20+
#include "zenoh-pico/link/config/raweth.h"
2021
#include "zenoh-pico/link/manager.h"
2122
#include "zenoh-pico/utils/logging.h"
2223

@@ -56,7 +57,6 @@ int8_t _z_open_link(_z_link_t *zl, const char *locator) {
5657
{
5758
ret = _Z_ERR_CONFIG_LOCATOR_SCHEMA_UNKNOWN;
5859
}
59-
6060
if (ret == _Z_RES_OK) {
6161
// Open transport link for communication
6262
if (zl->_open_f(zl) != _Z_RES_OK) {
@@ -92,10 +92,11 @@ int8_t _z_listen_link(_z_link_t *zl, const char *locator) {
9292
ret = _z_new_link_bt(zl, ep);
9393
} else
9494
#endif
95-
{
95+
if (_z_endpoint_raweth_valid(&ep) == _Z_RES_OK) {
96+
ret = _z_new_link_raweth(zl, ep);
97+
} else {
9698
ret = _Z_ERR_CONFIG_LOCATOR_SCHEMA_UNKNOWN;
9799
}
98-
99100
if (ret == _Z_RES_OK) {
100101
// Open transport link for listening
101102
if (zl->_listen_f(zl) != _Z_RES_OK) {

0 commit comments

Comments
 (0)