Skip to content

Commit

Permalink
Refactor transport layer (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland authored Nov 15, 2023
1 parent d86ad8d commit e420029
Show file tree
Hide file tree
Showing 46 changed files with 1,540 additions and 896 deletions.
3 changes: 1 addition & 2 deletions include/zenoh-pico/link/config/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "zenoh-pico/collections/intmap.h"
#include "zenoh-pico/collections/string.h"

#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1

#define UDP_CONFIG_ARGC 3

#define UDP_CONFIG_IFACE_KEY 0x01
Expand All @@ -31,6 +29,7 @@
#define UDP_CONFIG_JOIN_KEY 0x03
#define UDP_CONFIG_JOIN_STR "join"

#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1
#define UDP_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[UDP_CONFIG_ARGC]; \
args[0]._key = UDP_CONFIG_IFACE_KEY; \
Expand Down
22 changes: 22 additions & 0 deletions include/zenoh-pico/transport/common/join.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_JOIN_H
#define ZENOH_PICO_TRANSPORT_JOIN_H

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

int8_t _z_send_join(_z_transport_t *zt);

#endif /* ZENOH_PICO_TRANSPORT_JOIN_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/transport/common/lease.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LEASE_H
#define ZENOH_PICO_TRANSPORT_LEASE_H

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

int8_t _z_send_keep_alive(_z_transport_t *zt);
void *_zp_lease_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_TRANSPORT_LEASE_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/transport/common/read.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_READ_H
#define ZENOH_PICO_TRANSPORT_READ_H

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

int8_t _z_read(_z_transport_t *zt);
void *_zp_read_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_TRANSPORT_READ_H */
24 changes: 24 additions & 0 deletions include/zenoh-pico/transport/common/rx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_RX_H
#define ZENOH_PICO_TRANSPORT_RX_H

#include "zenoh-pico/link/link.h"
#include "zenoh-pico/transport/transport.h"

/*------------------ Transmission and Reception helpers ------------------*/
int8_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl);

#endif /* ZENOH_PICO_TRANSPORT_RX_H */
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LINK_TX_H
#define ZENOH_PICO_TRANSPORT_LINK_TX_H
#ifndef ZENOH_PICO_TRANSPORT_TX_H
#define ZENOH_PICO_TRANSPORT_TX_H

#include "zenoh-pico/link/link.h"
#include "zenoh-pico/net/session.h"
Expand All @@ -26,20 +26,7 @@ void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, _Bool is_streamed);
int8_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn);

/*------------------ Transmission and Reception helpers ------------------*/
int8_t _z_unicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);
int8_t _z_multicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);

int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);
int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);

int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg);
int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg);
int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg);

int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg);

#endif /* ZENOH_PICO_TRANSPORT_LINK_TX_H */
#endif /* ZENOH_PICO_TRANSPORT_TX_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/transport/multicast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_MULTICAST_H
#define ZENOH_PICO_MULTICAST_H

#include "zenoh-pico/api/types.h"

void _zp_multicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback);
void _zp_multicast_info_session(const _z_transport_t *zt, _z_config_t *ps);

#endif /* ZENOH_PICO_MULTICAST_H */
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LINK_TASK_JOIN_H
#define ZENOH_PICO_TRANSPORT_LINK_TASK_JOIN_H
#ifndef ZENOH_MULTICAST_JOIN_H
#define ZENOH_MULTICAST_JOIN_H

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

int8_t _z_send_join(_z_transport_t *zt);
int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm);

#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_JOIN_H */
#endif /* ZENOH_MULTICAST_JOIN_H */
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H
#define ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H
#ifndef ZENOH_PICO_MULTICAST_LEASE_H
#define ZENOH_PICO_MULTICAST_LEASE_H

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

int8_t _z_send_keep_alive(_z_transport_t *zt);
int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu);
int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm);

void *_zp_lease_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks
void *_zp_unicast_lease_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks
int8_t _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_multicast_stop_lease_task(_z_transport_t *zt);
void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H */
#endif /* ZENOH_PICO_MULTICAST_LEASE_H */
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LINK_TASK_READ_H
#define ZENOH_PICO_TRANSPORT_LINK_TASK_READ_H
#ifndef ZENOH_PICO_MULTICAST_READ_H
#define ZENOH_PICO_MULTICAST_READ_H

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

int8_t _z_read(_z_transport_t *zt);
int8_t _zp_unicast_read(_z_transport_unicast_t *ztu);
int8_t _zp_multicast_read(_z_transport_multicast_t *ztm);

void *_zp_read_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks
void *_zp_unicast_read_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks
int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_multicast_stop_read_task(_z_transport_t *zt);
void *_zp_multicast_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_READ_H */
#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_READ_H */
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_TRANSPORT_LINK_RX_H
#define ZENOH_PICO_TRANSPORT_LINK_RX_H
#ifndef ZENOH_PICO_MULTICAST_RX_H
#define ZENOH_PICO_MULTICAST_RX_H

#include "zenoh-pico/link/link.h"
#include "zenoh-pico/transport/transport.h"

/*------------------ Transmission and Reception helpers ------------------*/
int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg);
int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);

int8_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl);

int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg);
int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);

int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg);
int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg,
_z_bytes_t *addr);

#endif /* ZENOH_PICO_TRANSPORT_LINK_RX_H */
#endif /* ZENOH_PICO_TRANSPORT_LINK_RX_H */
29 changes: 29 additions & 0 deletions include/zenoh-pico/transport/multicast/transport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_MULTICAST_TRANSPORT_H
#define ZENOH_PICO_MULTICAST_TRANSPORT_H

#include "zenoh-pico/api/types.h"

int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl,
_z_transport_multicast_establish_param_t *param);
int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _Bool link_only);
int8_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason);
void _z_multicast_transport_clear(_z_transport_t *zt);
#endif /* ZENOH_PICO_MULTICAST_TRANSPORT_H */
27 changes: 27 additions & 0 deletions include/zenoh-pico/transport/multicast/tx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_MULTICAST_TX_H
#define ZENOH_PICO_MULTICAST_TX_H

#include "zenoh-pico/net/session.h"
#include "zenoh-pico/transport/transport.h"

int8_t _z_multicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);
int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability,
z_congestion_control_t cong_ctrl);
int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg);

#endif /* ZENOH_PICO_MULTICAST_TX_H */
20 changes: 0 additions & 20 deletions include/zenoh-pico/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,28 +164,8 @@ typedef struct {
uint8_t _seq_num_res;
} _z_transport_multicast_establish_param_t;

int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param);
int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param);

int8_t _z_transport_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_transport_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_transport_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_transport_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);

int8_t _z_transport_close(_z_transport_t *zt, uint8_t reason);
int8_t _z_transport_unicast_close(_z_transport_unicast_t *ztu, uint8_t reason);
int8_t _z_transport_multicast_close(_z_transport_multicast_t *ztm, uint8_t reason);

void _z_transport_unicast_clear(_z_transport_unicast_t *ztu);
void _z_transport_multicast_clear(_z_transport_multicast_t *ztm);

void _z_transport_clear(_z_transport_t *zt);
void _z_transport_free(_z_transport_t **zt);
void _z_transport_unicast_free(_z_transport_unicast_t **ztu);
void _z_transport_multicast_free(_z_transport_multicast_t **ztm);

#endif /* INCLUDE_ZENOH_PICO_TRANSPORT_TRANSPORT_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/transport/unicast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_UNICAST_H
#define ZENOH_PICO_UNICAST_H

#include "zenoh-pico/api/types.h"

void _zp_unicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback);
void _zp_unicast_info_session(const _z_transport_t *zt, _z_config_t *ps);

#endif /* ZENOH_PICO_UNICAST_H */
25 changes: 25 additions & 0 deletions include/zenoh-pico/transport/unicast/lease.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_UNICAST_LEASE_H
#define ZENOH_PICO_UNICAST_LEASE_H

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

int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu);
int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt);
void *_zp_unicast_lease_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H */
Loading

0 comments on commit e420029

Please sign in to comment.