Skip to content

Commit

Permalink
Merge pull request #283 from jean-roland/ft_raweth_transport
Browse files Browse the repository at this point in the history
Add raweth transport (implementation)
  • Loading branch information
p-avital authored Dec 4, 2023
2 parents 3896dfb + 1fb4344 commit 4b8b0a0
Show file tree
Hide file tree
Showing 33 changed files with 1,699 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ elseif(WITH_FREERTOS_PLUS_TCP)
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
file (GLOB Sources_Unix "src/system/unix/*.c")
file (GLOB Sources_Unix "src/system/unix/*.c" "src/system/unix/link/*.c")
list(APPEND Sources ${Sources_Unix})
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
file (GLOB Sources_Emscripten "src/system/emscripten/*.c")
Expand Down
7 changes: 7 additions & 0 deletions include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@
#endif
#endif

/**
* Enable raweth transport/link.
*/
#ifndef Z_FEATURE_RAWETH_TRANSPORT
#define Z_FEATURE_RAWETH_TRANSPORT 0
#endif

/*------------------ Compile-time configuration properties ------------------*/
/**
* Default length for Zenoh ID. Maximum size is 16 bytes.
Expand Down
32 changes: 32 additions & 0 deletions include/zenoh-pico/link/config/raweth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// 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_LINK_CONFIG_RAWETH_H
#define ZENOH_PICO_LINK_CONFIG_RAWETH_H

#include "zenoh-pico/collections/intmap.h"
#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/config.h"
#include "zenoh-pico/link/link.h"

#if Z_FEATURE_RAWETH_TRANSPORT == 1

#define RAWETH_SCHEMA "reth"

int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint);

int8_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint);

#endif /* Z_FEATURE_RAWETH_TRANSPORT */
#endif /* ZENOH_PICO_LINK_CONFIG_RAWETH_H */
67 changes: 67 additions & 0 deletions include/zenoh-pico/system/link/raweth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// 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_SYSTEM_LINK_RAWETH_H
#define ZENOH_PICO_SYSTEM_LINK_RAWETH_H

#include <stdint.h>

#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_RAWETH_TRANSPORT == 1

// Ethernet types (big endian)
#define _ZP_ETH_TYPE_VLAN 0x0081

// Address Sizes
#define _ZP_MAC_ADDR_LENGTH 6

// Max frame size
#define _ZP_MAX_ETH_FRAME_SIZE 1500

// Ethernet header structure type
typedef struct {
uint8_t dmac[_ZP_MAC_ADDR_LENGTH]; // Destination mac address
uint8_t smac[_ZP_MAC_ADDR_LENGTH]; // Source mac address
uint16_t ethtype; // Ethertype of frame
} _zp_eth_header_t;

typedef struct {
uint8_t dmac[_ZP_MAC_ADDR_LENGTH]; // Destination mac address
uint8_t smac[_ZP_MAC_ADDR_LENGTH]; // Source mac address
uint16_t vlan_type; // Vlan ethtype
uint16_t tag; // Vlan tag
uint16_t ethtype; // Ethertype of frame
} _zp_eth_vlan_header_t;

typedef struct {
const char *_interface;
_z_sys_net_socket_t _sock;
uint16_t _vlan;
uint16_t ethtype;
uint8_t _dmac[_ZP_MAC_ADDR_LENGTH];
uint8_t _smac[_ZP_MAC_ADDR_LENGTH];
_Bool _has_vlan;
} _z_raweth_socket_t;

int8_t _z_get_smac_raweth(_z_raweth_socket_t *resock);
int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface);
size_t _z_send_raweth(const _z_sys_net_socket_t *sock, const void *buff, size_t buff_len);
size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_bytes_t *addr);
int8_t _z_close_raweth(_z_sys_net_socket_t *sock);

#endif

#endif /* ZENOH_PICO_SYSTEM_LINK_RAWETH_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/transport/multicast/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _
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_MULTICAST_READ_H */
2 changes: 0 additions & 2 deletions include/zenoh-pico/transport/multicast/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#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);
Expand Down
58 changes: 58 additions & 0 deletions include/zenoh-pico/transport/raweth/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// 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_RAWETH_CONFIG_H
#define ZENOH_PICO_RAWETH_CONFIG_H

#include <stdbool.h>

#include "zenoh-pico/protocol/core.h"
#include "zenoh-pico/system/link/raweth.h"
#include "zenoh-pico/transport/transport.h"
#include "zenoh-pico/utils/result.h"

#if Z_FEATURE_RAWETH_TRANSPORT == 1

typedef struct {
_z_keyexpr_t _keyexpr;
uint16_t _vlan; // vlan tag (pcp + dei + id), big endian
uint8_t _dmac[_ZP_MAC_ADDR_LENGTH];
_Bool _has_vlan;
} _zp_raweth_cfg_entry;

typedef struct {
uint8_t _mac[_ZP_MAC_ADDR_LENGTH];
} _zp_raweth_cfg_whitelist_val;

// Ethertype to use in frame
extern const uint16_t _ZP_RAWETH_CFG_ETHTYPE;

// Interface to use
extern const char *_ZP_RAWETH_CFG_INTERFACE;

// Source mac address
extern const uint8_t _ZP_RAWETH_CFG_SMAC[_ZP_MAC_ADDR_LENGTH];

// Main config array
extern const _zp_raweth_cfg_entry _ZP_RAWETH_CFG_ARRAY[];

// Mac address rx whitelist array
extern const _zp_raweth_cfg_whitelist_val _ZP_RAWETH_CFG_WHITELIST[];

// Array size
extern const size_t _ZP_RAWETH_CFG_SIZE;
extern const size_t _ZP_RAWETH_CFG_WHITELIST_SIZE;

#endif // Z_FEATURE_RAWETH_TRANSPORT == 1
#endif // ZENOH_PICO_RAWETH_CONFIG_H
22 changes: 22 additions & 0 deletions include/zenoh-pico/transport/raweth/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_RAWETH_JOIN_H
#define ZENOH_RAWETH_JOIN_H

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

int8_t _zp_raweth_send_join(_z_transport_multicast_t *ztm);

#endif /* ZENOH_RAWETH_JOIN_H */
25 changes: 25 additions & 0 deletions include/zenoh-pico/transport/raweth/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_RAWETH_LEASE_H
#define ZENOH_PICO_RAWETH_LEASE_H

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

int8_t _zp_raweth_send_keep_alive(_z_transport_multicast_t *ztm);
int8_t _zp_raweth_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_raweth_stop_lease_task(_z_transport_t *zt);
void *_zp_raweth_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_RAWETH_LEASE_H */
25 changes: 25 additions & 0 deletions include/zenoh-pico/transport/raweth/read.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_RAWETH_READ_H
#define ZENOH_PICO_RAWETH_READ_H

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

int8_t _zp_raweth_read(_z_transport_multicast_t *ztm);
int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_raweth_stop_read_task(_z_transport_t *zt);
void *_zp_raweth_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#endif /* ZENOH_PICO_RAWETH_READ_H */
23 changes: 23 additions & 0 deletions include/zenoh-pico/transport/raweth/rx.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_RAWETH_RX_H
#define ZENOH_PICO_RAWETH_RX_H

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

int8_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);
int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_bytes_t *addr);

#endif /* ZENOH_PICO_RAWETH_RX_H */
28 changes: 28 additions & 0 deletions include/zenoh-pico/transport/raweth/transport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// 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_RAWETH_TRANSPORT_H
#define ZENOH_PICO_RAWETH_TRANSPORT_H

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

int8_t _z_raweth_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param);
int8_t _z_raweth_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_raweth_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl,
const _z_id_t *local_zid);
int8_t _z_raweth_send_close(_z_transport_multicast_t *ztm, uint8_t reason, _Bool link_only);
int8_t _z_raweth_transport_close(_z_transport_multicast_t *ztm, uint8_t reason);
void _z_raweth_transport_clear(_z_transport_t *zt);
#endif /* ZENOH_PICO_RAWETH_TRANSPORT_H */
26 changes: 26 additions & 0 deletions include/zenoh-pico/transport/raweth/tx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// 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_RAWETH_TX_H
#define ZENOH_PICO_RAWETH_TX_H

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

int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg);
int8_t _z_raweth_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_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg);

#endif /* ZENOH_PICO_RAWETH_TX_H */
2 changes: 0 additions & 2 deletions include/zenoh-pico/transport/unicast/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "zenoh-pico/net/session.h"
#include "zenoh-pico/transport/transport.h"

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_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_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg);
Expand Down
1 change: 1 addition & 0 deletions include/zenoh-pico/utils/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define ZENOH_PICO_UTILS_RESULT_H

#define _ZP_UNUSED(x) (void)(x)
#define _ZP_ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))

#define _Z_ERR_MESSAGE_MASK 0x88
#define _Z_ERR_ENTITY_MASK 0x90
Expand Down
4 changes: 4 additions & 0 deletions src/system/arduino/esp32/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,4 +858,8 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t
}
#endif

#if Z_FEATURE_RAWETH_TRANSPORT == 1
#error "Raw ethernet transport not supported yet on ESP32 port of Zenoh-Pico"
#endif

} // extern "C"
4 changes: 4 additions & 0 deletions src/system/arduino/opencr/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,8 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr,
#if Z_FEATURE_LINK_SERIAL == 1
#error "Serial not supported yet on OpenCR port of Zenoh-Pico"
#endif

#if Z_FEATURE_RAWETH_TRANSPORT == 1
#error "Raw ethernet transport not supported yet on OpenCR port of Zenoh-Pico"
#endif
}
4 changes: 4 additions & 0 deletions src/system/emscripten/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ size_t _z_send_ws(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len
#if Z_FEATURE_LINK_SERIAL == 1
#error "Serial not supported yet on Emscripten port of Zenoh-Pico"
#endif

#if Z_FEATURE_RAWETH_TRANSPORT == 1
#error "Raw ethernet transport not supported yet on Emscripten port of Zenoh-Pico"
#endif
Loading

0 comments on commit 4b8b0a0

Please sign in to comment.