Skip to content

Commit

Permalink
feat: bind raweth transport to the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 5, 2023
1 parent ac566f5 commit 80419bc
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 9 deletions.
10 changes: 9 additions & 1 deletion include/zenoh-pico/link/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "zenoh-pico/system/link/udp.h"
#endif

#if Z_FEATURE_RAWETH_TRANSPORT == 1
#include "zenoh-pico/system/link/raweth.h"
#endif

#if Z_FEATURE_LINK_BLUETOOTH == 1
#include "zenoh-pico/system/link/bt.h"
#endif
Expand All @@ -52,6 +56,7 @@
typedef enum {
Z_LINK_CAP_TRANSPORT_UNICAST = 0,
Z_LINK_CAP_TRANSPORT_MULTICAST = 1,
Z_LINK_CAP_TRANSPORT_RAWETH = 2,
} _z_link_cap_transport_t;

/**
Expand All @@ -73,7 +78,7 @@ typedef enum {
* transport: 2 bits, see _z_link_cap_transport_t enum.
* flow: 1 bit, see _z_link_cap_flow_t enum.
* reliable: 1 bit, 1 if the link is reliable (network definition)
* reserved: 4 bits, reserved for futur use
* reserved: 4 bits, reserved for future use
*/
typedef struct _z_link_capabilities_t {
uint8_t _transport : 2;
Expand Down Expand Up @@ -111,6 +116,9 @@ typedef struct _z_link_t {
#endif
#if Z_FEATURE_LINK_WS == 1
_z_ws_socket_t _ws;
#endif
#if Z_FEATURE_RAWETH_TRANSPORT == 1
_z_raweth_socket_t _raweth;
#endif
} _socket;

Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/system/platform/unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ typedef struct timeval z_time_t;

typedef struct {
union {
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1
#if Z_FEATURE_LINK_TCP == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 || Z_FEATURE_LINK_UDP_UNICAST == 1 || \
Z_FEATURE_RAWETH_TRANSPORT == 1
int _fd;
#endif
};
Expand Down
2 changes: 2 additions & 0 deletions include/zenoh-pico/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ typedef struct {
union {
_z_transport_unicast_t _unicast;
_z_transport_multicast_t _multicast;
_z_transport_multicast_t _raweth;
} _transport;

enum {
_Z_TRANSPORT_UNICAST_TYPE,
_Z_TRANSPORT_MULTICAST_TYPE,
_Z_TRANSPORT_RAWETH_TYPE,
} _type;
} _z_transport_t;

Expand Down
7 changes: 4 additions & 3 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ int8_t z_info_peers_zid(const z_session_t zs, z_owned_closure_zid_t *callback) {
// Call transport function
switch (zs._val->_tp._type) {
case _Z_TRANSPORT_MULTICAST_TYPE:
case _Z_TRANSPORT_RAWETH_TYPE:
_zp_multicast_fetch_zid(&zs._val->_tp, callback);
break;
default:
Expand Down Expand Up @@ -638,7 +639,7 @@ z_owned_publisher_t z_declare_publisher(z_session_t zs, z_keyexpr_t keyexpr, con
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
// resource declarations are only performed on unicast transports.
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
if (r == NULL) {
uint16_t id = _z_declare_resource(zs._val, keyexpr);
Expand Down Expand Up @@ -794,7 +795,7 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
// resource declarations are only performed on unicast transports.
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
if (r == NULL) {
uint16_t id = _z_declare_resource(zs._val, keyexpr);
Expand Down Expand Up @@ -897,7 +898,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
// lacks a way to convey them to later-joining nodes. Thus, in the current version automatic
// resource declarations are only performed on unicast transports.
if (zs._val->_tp._type != _Z_TRANSPORT_MULTICAST_TYPE) {
if (zs._val->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) {
_z_resource_t *r = _z_get_resource_by_key(zs._val, &keyexpr);
if (r == NULL) {
char *wild = strpbrk(keyexpr._suffix, "*$");
Expand Down
7 changes: 4 additions & 3 deletions src/link/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stddef.h>

#include "zenoh-pico/config.h"
#include "zenoh-pico/link/config/raweth.h"
#include "zenoh-pico/link/manager.h"
#include "zenoh-pico/utils/logging.h"

Expand Down Expand Up @@ -56,7 +57,6 @@ int8_t _z_open_link(_z_link_t *zl, const char *locator) {
{
ret = _Z_ERR_CONFIG_LOCATOR_SCHEMA_UNKNOWN;
}

if (ret == _Z_RES_OK) {
// Open transport link for communication
if (zl->_open_f(zl) != _Z_RES_OK) {
Expand Down Expand Up @@ -92,10 +92,11 @@ int8_t _z_listen_link(_z_link_t *zl, const char *locator) {
ret = _z_new_link_bt(zl, ep);
} else
#endif
{
if (_z_endpoint_raweth_valid(&ep) == _Z_RES_OK) {
ret = _z_new_link_raweth(zl, ep);
} else {
ret = _Z_ERR_CONFIG_LOCATOR_SCHEMA_UNKNOWN;
}

if (ret == _Z_RES_OK) {
// Open transport link for listening
if (zl->_listen_f(zl) != _Z_RES_OK) {
Expand Down
15 changes: 15 additions & 0 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "zenoh-pico/transport/multicast.h"
#include "zenoh-pico/transport/multicast/lease.h"
#include "zenoh-pico/transport/multicast/read.h"
#include "zenoh-pico/transport/raweth/lease.h"
#include "zenoh-pico/transport/raweth/read.h"
#include "zenoh-pico/transport/unicast.h"
#include "zenoh-pico/transport/unicast/lease.h"
#include "zenoh-pico/transport/unicast/read.h"
Expand Down Expand Up @@ -160,6 +162,7 @@ _z_config_t *_z_info(const _z_session_t *zn) {
_zp_unicast_info_session(&zn->_tp, ps);
break;
case _Z_TRANSPORT_MULTICAST_TYPE:
case _Z_TRANSPORT_RAWETH_TYPE:
_zp_multicast_info_session(&zn->_tp, ps);
break;
default:
Expand Down Expand Up @@ -192,6 +195,9 @@ int8_t _zp_start_read_task(_z_session_t *zn, _z_task_attr_t *attr) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_start_read_task(&zn->_tp, attr, task);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_start_read_task(&zn->_tp, attr, task);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -218,6 +224,9 @@ int8_t _zp_start_lease_task(_z_session_t *zn, _z_task_attr_t *attr) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_start_lease_task(&zn->_tp, attr, task);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_start_lease_task(&zn->_tp, attr, task);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -239,6 +248,9 @@ int8_t _zp_stop_read_task(_z_session_t *zn) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_stop_read_task(&zn->_tp);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_stop_read_task(&zn->_tp);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -256,6 +268,9 @@ int8_t _zp_stop_lease_task(_z_session_t *zn) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_stop_lease_task(&zn->_tp);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_stop_lease_task(&zn->_tp);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand Down
4 changes: 4 additions & 0 deletions src/session/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "zenoh-pico/transport/multicast/tx.h"

#include "zenoh-pico/transport/raweth/tx.h"
#include "zenoh-pico/transport/unicast/tx.h"
#include "zenoh-pico/utils/logging.h"

Expand All @@ -29,6 +30,9 @@ int8_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reli
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _z_multicast_send_n_msg(zn, z_msg, reliability, cong_ctrl);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _z_raweth_send_n_msg(zn, z_msg, reliability, cong_ctrl);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/session/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) {
case _Z_TRANSPORT_MULTICAST_TYPE:
zn->_tp._transport._multicast._session = zn;
break;
case _Z_TRANSPORT_RAWETH_TYPE:
zn->_tp._transport._raweth._session = zn;
break;
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/transport/common/join.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "zenoh-pico/transport/common/join.h"

#include "zenoh-pico/transport/multicast/join.h"
#include "zenoh-pico/transport/raweth/join.h"

int8_t _z_send_join(_z_transport_t *zt) {
int8_t ret = _Z_RES_OK;
Expand All @@ -23,6 +24,9 @@ int8_t _z_send_join(_z_transport_t *zt) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_send_join(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_send_join(&zt->_transport._raweth);
break;
default:
(void)zt;
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
Expand Down
7 changes: 7 additions & 0 deletions src/transport/common/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stddef.h>

#include "zenoh-pico/transport/multicast/lease.h"
#include "zenoh-pico/transport/raweth/lease.h"
#include "zenoh-pico/transport/unicast/lease.h"

int8_t _z_send_keep_alive(_z_transport_t *zt) {
Expand All @@ -28,6 +29,9 @@ int8_t _z_send_keep_alive(_z_transport_t *zt) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_send_keep_alive(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_send_keep_alive(&zt->_transport._raweth);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -45,6 +49,9 @@ void *_zp_lease_task(void *zt_arg) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_lease_task(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_lease_task(&zt->_transport._raweth);
break;
default:
ret = NULL;
break;
Expand Down
7 changes: 7 additions & 0 deletions src/transport/common/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stddef.h>

#include "zenoh-pico/transport/multicast/read.h"
#include "zenoh-pico/transport/raweth/read.h"
#include "zenoh-pico/transport/unicast/read.h"

int8_t _z_read(_z_transport_t *zt) {
Expand All @@ -28,6 +29,9 @@ int8_t _z_read(_z_transport_t *zt) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_read(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_read(&zt->_transport._raweth);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -45,6 +49,9 @@ void *_zp_read_task(void *zt_arg) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_read_task(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_read_task(&zt->_transport._raweth);
break;
default:
ret = NULL;
break;
Expand Down
7 changes: 6 additions & 1 deletion src/transport/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include "zenoh-pico/transport/multicast/tx.h"
#include "zenoh-pico/transport/common/tx.h"

#include "zenoh-pico/api/constants.h"
#include "zenoh-pico/protocol/codec/core.h"
#include "zenoh-pico/protocol/codec/transport.h"
#include "zenoh-pico/protocol/definitions/transport.h"
#include "zenoh-pico/transport/multicast/tx.h"
#include "zenoh-pico/transport/raweth/tx.h"
#include "zenoh-pico/transport/unicast/tx.h"
#include "zenoh-pico/utils/logging.h"

Expand Down Expand Up @@ -76,6 +78,9 @@ int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _z_multicast_send_t_msg(&zt->_transport._multicast, t_msg);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _z_raweth_send_t_msg(&zt->_transport._raweth, t_msg);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand Down
21 changes: 21 additions & 0 deletions src/transport/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>

#include "zenoh-pico/transport/multicast/transport.h"
#include "zenoh-pico/transport/raweth/transport.h"
#include "zenoh-pico/transport/unicast/transport.h"

int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local_zid) {
Expand Down Expand Up @@ -54,6 +55,16 @@ int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local
ret = _z_multicast_transport_create(zt, &zl, &tp_param);
break;
}
case Z_LINK_CAP_TRANSPORT_RAWETH: {
_z_transport_multicast_establish_param_t tp_param;
ret = _z_raweth_open_client(&tp_param, &zl, local_zid);
if (ret != _Z_RES_OK) {
_z_link_clear(&zl);
return ret;
}
ret = _z_raweth_transport_create(zt, &zl, &tp_param);
break;
}
default:
ret = _Z_ERR_GENERIC;
break;
Expand Down Expand Up @@ -92,6 +103,16 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, char *locator, _z_id_t *local_z
ret = _z_multicast_transport_create(zt, &zl, &tp_param);
break;
}
case Z_LINK_CAP_TRANSPORT_RAWETH: {
_z_transport_multicast_establish_param_t tp_param;
ret = _z_raweth_open_peer(&tp_param, &zl, local_zid);
if (ret != _Z_RES_OK) {
_z_link_clear(&zl);
return ret;
}
ret = _z_raweth_transport_create(zt, &zl, &tp_param);
break;
}
default:
ret = _Z_ERR_GENERIC;
break;
Expand Down
9 changes: 9 additions & 0 deletions src/transport/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "zenoh-pico/transport/multicast/rx.h"
#include "zenoh-pico/transport/multicast/transport.h"
#include "zenoh-pico/transport/multicast/tx.h"
#include "zenoh-pico/transport/raweth/rx.h"
#include "zenoh-pico/transport/raweth/transport.h"
#include "zenoh-pico/transport/raweth/tx.h"
#include "zenoh-pico/transport/unicast/rx.h"
#include "zenoh-pico/transport/unicast/transport.h"
#include "zenoh-pico/transport/unicast/tx.h"
Expand All @@ -40,6 +43,9 @@ int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, _Bool link_only) {
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _z_multicast_send_close(&zt->_transport._multicast, reason, link_only);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _z_raweth_send_close(&zt->_transport._raweth, reason, link_only);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
Expand All @@ -57,6 +63,9 @@ void _z_transport_clear(_z_transport_t *zt) {
case _Z_TRANSPORT_MULTICAST_TYPE:
_z_multicast_transport_clear(zt);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
_z_raweth_transport_clear(zt);
break;
default:
break;
}
Expand Down

0 comments on commit 80419bc

Please sign in to comment.