Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raweth transport (implementation) #283

Merged
merged 38 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
976ae71
feat: add new transport config token
jean-roland Nov 22, 2023
ae19d39
feat: add new transport files (wip)
jean-roland Nov 22, 2023
289a0ee
fix: remove obsolete transport function declaration
jean-roland Nov 22, 2023
820eb2c
feat: add rx function
jean-roland Nov 23, 2023
6349597
fix: remove raweth by default
jean-roland Nov 23, 2023
37a8e1f
build: add unix link folder
jean-roland Nov 24, 2023
66da3b7
fix: remove unix header
jean-roland Nov 24, 2023
b1296f9
fix: run clang format
jean-roland Nov 24, 2023
26c101e
feat: add eth header skip in rx
jean-roland Nov 24, 2023
5dc2235
fix: remove linux dependency
jean-roland Nov 24, 2023
8b6ed7c
fix: windows build
jean-roland Nov 24, 2023
9cf5c97
feat: add raweth config files
jean-roland Nov 24, 2023
c7304e8
feat: add array size macro
jean-roland Nov 24, 2023
5a0d72c
feat: use raweth config
jean-roland Nov 24, 2023
fbdb6dd
fix: run clang
jean-roland Nov 24, 2023
ecc07b7
fix: don't check address in locator
jean-roland Nov 27, 2023
2a9d68c
fix: missing newline end of file
jean-roland Nov 27, 2023
3474b44
chore: remove obsolete comments
jean-roland Nov 27, 2023
c715855
fix: remove unused intmap
jean-roland Nov 27, 2023
eb993e0
feat: add missing link header
jean-roland Nov 27, 2023
9542ec8
fix: add missing functions
jean-roland Nov 27, 2023
560505c
feat: add raweth join lease read
jean-roland Nov 28, 2023
85af6b0
feat: switch to ethtype field and remove vlan struct
jean-roland Nov 28, 2023
788eb07
fix: missing functions
jean-roland Nov 28, 2023
79ecd1d
feat: mutualize code with multicast
jean-roland Nov 28, 2023
b7a009e
fix: use raweth link send for join message
jean-roland Nov 28, 2023
a98725e
fix: add missing send function
jean-roland Nov 28, 2023
821cc36
fix: missing eth header on link send function
jean-roland Nov 28, 2023
a019b14
feat: add rx whitelist in config
jean-roland Nov 29, 2023
35342a5
fix: add missing close socket function
jean-roland Nov 29, 2023
9ed1002
feat: add config interface for socket binding
jean-roland Nov 30, 2023
9283187
fix: add big endian comments
jean-roland Nov 30, 2023
07f8992
fix: add missing vlan ether type field
jean-roland Nov 30, 2023
327dd39
fix: return error when keyexpr not found
jean-roland Nov 30, 2023
55cc05e
fix: clear buffer before sending
jean-roland Dec 1, 2023
66ca132
fix: remove read mutex double lock
jean-roland Dec 1, 2023
24b1d1f
fix: run clang
jean-roland Dec 1, 2023
1fb4344
fix: add valid path to read task
jean-roland Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
65 changes: 65 additions & 0 deletions include/zenoh-pico/system/link/raweth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// 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
#define _ZP_ETH_TYPE_VLAN 0x8100

// 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 tag; // Vlan tag
uint16_t ethtype; // Ethertype of frame
} _zp_eth_vlan_header_t;

typedef struct {
_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);
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
Mallets marked this conversation as resolved.
Show resolved Hide resolved
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
55 changes: 55 additions & 0 deletions include/zenoh-pico/transport/raweth/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// 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)
jean-roland marked this conversation as resolved.
Show resolved Hide resolved
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;

// 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
Mallets marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 4 additions & 0 deletions src/system/espidf/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,7 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t
#if Z_FEATURE_LINK_BLUETOOTH == 1
#error "Bluetooth not supported yet on ESP-IDF port of Zenoh-Pico"
#endif

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