Skip to content

Commit

Permalink
feat: fuze lease multicast code
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 5, 2023
1 parent bba5162 commit d8835da
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 283 deletions.
4 changes: 2 additions & 2 deletions include/zenoh-pico/transport/multicast/lease.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm);
int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm);
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);
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm);
void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_MULTICAST_LEASE_H */
26 changes: 0 additions & 26 deletions include/zenoh-pico/transport/raweth/lease.h

This file was deleted.

10 changes: 9 additions & 1 deletion include/zenoh-pico/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ _Z_LIST_DEFINE(_z_transport_peer_entry, _z_transport_peer_entry_t)
_z_transport_peer_entry_list_t *_z_transport_peer_entry_list_insert(_z_transport_peer_entry_list_t *root,
_z_transport_peer_entry_t *entry);

// Forward declaration to be used in _zp_f_send_tmsg*
typedef struct _z_transport_multicast_t _z_transport_multicast_t;
// Send function prototype
typedef int8_t (*_zp_f_send_tmsg)(_z_transport_multicast_t *self, const _z_transport_message_t *t_msg);

typedef struct {
// Session associated to the transport

Expand Down Expand Up @@ -93,7 +98,7 @@ typedef struct {
volatile _Bool _transmitted;
} _z_transport_unicast_t;

typedef struct {
typedef struct _z_transport_multicast_t {
// Session associated to the transport
void *_session;

Expand Down Expand Up @@ -121,6 +126,9 @@ typedef struct {
// Known valid peers
_z_transport_peer_entry_list_t *_peers;

// T message send function
_zp_f_send_tmsg _send_f;

#if Z_FEATURE_MULTI_THREAD == 1
_z_task_t *_read_task;
_z_task_t *_lease_task;
Expand Down
10 changes: 5 additions & 5 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,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/transport.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 @@ -221,10 +221,10 @@ int8_t _zp_start_lease_task(_z_session_t *zn, _z_task_attr_t *attr) {
ret = _zp_unicast_start_lease_task(&zn->_tp, attr, task);
break;
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_start_lease_task(&zn->_tp, attr, task);
ret = _zp_multicast_start_lease_task(&zn->_tp._transport._multicast, attr, task);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_start_lease_task(&zn->_tp, attr, task);
ret = _zp_multicast_start_lease_task(&zn->_tp._transport._raweth, attr, task);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
Expand Down Expand Up @@ -265,10 +265,10 @@ int8_t _zp_stop_lease_task(_z_session_t *zn) {
ret = _zp_unicast_stop_lease_task(&zn->_tp);
break;
case _Z_TRANSPORT_MULTICAST_TYPE:
ret = _zp_multicast_stop_lease_task(&zn->_tp);
ret = _zp_multicast_stop_lease_task(&zn->_tp._transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_stop_lease_task(&zn->_tp);
ret = _zp_multicast_stop_lease_task(&zn->_tp._transport._raweth);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
Expand Down
7 changes: 3 additions & 4 deletions src/transport/common/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#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 @@ -30,7 +29,7 @@ int8_t _z_send_keep_alive(_z_transport_t *zt) {
ret = _zp_multicast_send_keep_alive(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_send_keep_alive(&zt->_transport._raweth);
ret = _zp_multicast_send_keep_alive(&zt->_transport._raweth);
break;
default:
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
Expand All @@ -47,12 +46,12 @@ int8_t _z_send_join(_z_transport_t *zt) {
ret = _zp_multicast_send_join(&zt->_transport._multicast);
break;
case _Z_TRANSPORT_RAWETH_TYPE:
ret = _zp_raweth_send_join(&zt->_transport._raweth);
ret = _zp_multicast_send_join(&zt->_transport._raweth);
break;
default:
(void)zt;
ret = _Z_ERR_TRANSPORT_NOT_AVAILABLE;
break;
}
return ret;
}
}
36 changes: 15 additions & 21 deletions src/transport/multicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#include "zenoh-pico/config.h"
#include "zenoh-pico/session/utils.h"
#include "zenoh-pico/transport/common/lease.h"
#include "zenoh-pico/transport/multicast/transport.h"
#include "zenoh-pico/transport/multicast/tx.h"
#include "zenoh-pico/utils/logging.h"

#if Z_FEATURE_MULTICAST_TRANSPORT == 1
#if Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1

static _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) {
_z_zint_t ret = local_lease;
Expand Down Expand Up @@ -68,34 +66,30 @@ int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) {
_z_id_t zid = ((_z_session_t *)ztm->_session)->_local_zid;
_z_transport_message_t jsm = _z_t_msg_make_join(Z_WHATAMI_PEER, Z_TRANSPORT_LEASE, zid, next_sn);

return _z_multicast_send_t_msg(ztm, &jsm);
return ztm->_send_f(ztm, &jsm);
}

int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) {
int8_t ret = _Z_RES_OK;

_z_transport_message_t t_msg = _z_t_msg_make_keep_alive();
ret = _z_multicast_send_t_msg(ztm, &t_msg);

return ret;
return ztm->_send_f(ztm, &t_msg);
}

int8_t _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task) {
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._multicast._lease_task = task;
zt->_transport._multicast._lease_task_running = true;
ztm->_lease_task = task;
ztm->_lease_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_multicast_lease_task, &zt->_transport._multicast) != _Z_RES_OK) {
zt->_transport._multicast._lease_task_running = false;
if (_z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) {
ztm->_lease_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
return _Z_RES_OK;
}

int8_t _zp_multicast_stop_lease_task(_z_transport_t *zt) {
zt->_transport._multicast._lease_task_running = false;
int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) {
ztm->_lease_task_running = false;
return _Z_RES_OK;
}

Expand Down Expand Up @@ -205,20 +199,20 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) {
return _Z_ERR_TRANSPORT_NOT_AVAILABLE;
}

int8_t _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) {
_ZP_UNUSED(zt);
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task) {
_ZP_UNUSED(ztm);
_ZP_UNUSED(attr);
_ZP_UNUSED(task);
return _Z_ERR_TRANSPORT_NOT_AVAILABLE;
}

int8_t _zp_multicast_stop_lease_task(_z_transport_t *zt) {
_ZP_UNUSED(zt);
int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) {
_ZP_UNUSED(ztm);
return _Z_ERR_TRANSPORT_NOT_AVAILABLE;
}

void *_zp_multicast_lease_task(void *ztm_arg) {
_ZP_UNUSED(ztm_arg);
return NULL;
}
#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1
#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1
1 change: 1 addition & 0 deletions src/transport/multicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl,
int8_t ret = _Z_RES_OK;

zt->_type = _Z_TRANSPORT_MULTICAST_TYPE;
zt->_transport._multicast._send_f = _z_multicast_send_t_msg;

#if Z_FEATURE_MULTI_THREAD == 1
// Initialize the mutexes
Expand Down
Loading

0 comments on commit d8835da

Please sign in to comment.