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

Zephyr federated support #232

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions core/federated/clock-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef FEDERATED
#ifdef PLATFORM_ZEPHYR
#else
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include <errno.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include "platform.h"
#include "clock-sync.h"
Expand Down
3 changes: 3 additions & 0 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef FEDERATED
#ifdef PLATFORM_ARDUINO
#error To be implemented. No support for federation on Arduino yet.
#elif PLATFORM_ZEPHYR
#warning Federated support on Zephyr is still experimental.
#else
#include <arpa/inet.h> // inet_ntop & inet_pton
#include <netdb.h> // Defines getaddrinfo(), freeaddrinfo() and struct addrinfo.
Expand Down Expand Up @@ -2439,6 +2441,7 @@ void terminate_execution(environment_t* env) {
// possibility of deadlock. To ensure this, this
// function should NEVER be called while holding any mutex lock.
lf_mutex_lock(&outbound_socket_mutex);
// FIXME: Should this be _fed.number_of_outbound_p2p_connections instead?
for (int i=0; i < NUMBER_OF_FEDERATES; i++) {
// Close outbound connections, in case they have not closed themselves.
// This will result in EOF being sent to the remote federate, I think.
Expand Down
33 changes: 32 additions & 1 deletion core/platform/lf_zephyr_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ int _lf_unthreaded_notify_of_event() {
#warning "Threaded support on Zephyr is still experimental."

// FIXME: What is an appropriate stack size?
#define _LF_STACK_SIZE 1024
#define _LF_STACK_SIZE 4096
// FIXME: What is an appropriate thread prio?
#define _LF_THREAD_PRIORITY 5

Expand All @@ -315,7 +315,38 @@ int _lf_unthreaded_notify_of_event() {
#define USER_THREADS 0
#endif

#if defined(FEDERATED) && defined(FEDERATED_DECENTRALIZED)
#define RTI_SOCKET_LISTENER_THREAD 1
#define FEDERATE_SOCKET_LISTENER_THREADS NUMBER_OF_FEDERATES
#define P2P_HANDLER_THREAD 1

#elif defined(FEDERATED) && defined(FEDERATED_CENTRALIZED)
#define RTI_SOCKET_LISTENER_THREAD 1
#define FEDERATE_SOCKET_LISTENER_THREADS 0
#define P2P_HANDLER_THREAD 0

#else
#define RTI_SOCKET_LISTENER_THREAD 0
#define FEDERATE_SOCKET_LISTENER_THREADS 0
#define P2P_HANDLER_THREAD 0
#endif

#if defined(FEDERATED) && defined(_LF_CLOCK_SYNC_ON)
#define CLOCK_SYNC_THREAD 1
#else
#define CLOCK_SYNC_THREAD 0
#endif

#ifndef WORKERS_NEEDED_FOR_FEDERATE
#define WORKERS_NEEDED_FOR_FEDERATE 0
#endif

#define NUMBER_OF_THREADS (NUMBER_OF_WORKERS \
+ WORKERS_NEEDED_FOR_FEDERATE \
+ RTI_SOCKET_LISTENER_THREAD \
+ FEDERATE_SOCKET_LISTENER_THREADS \
+ P2P_HANDLER_THREAD \
+ CLOCK_SYNC_THREAD \
+ USER_THREADS)

K_MUTEX_DEFINE(thread_mutex);
Expand Down
6 changes: 5 additions & 1 deletion include/core/federated/net_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifdef PLATFORM_ARDUINO
#error To be implemented. No support for federation on Arduino yet.
#elif PLATFORM_ZEPHYR
#warning Federated support on Zephyr is still experimental.
#else
#include <sys/socket.h>
#include <regex.h>
#endif

#include <sys/types.h>
#include <regex.h>
#include <stdbool.h>

#include "../platform.h"
Expand Down Expand Up @@ -364,12 +366,14 @@ bool validate_user(const char* user);
bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group,
int max_len, int min_len, const char* err_msg);


/**
* Extract match groups from the rti_addr regex.
* @return true if success, else false.
*/
bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array, int* gids, int* max_lens, int* min_lens, const char** err_msgs);


/**
* Extract the host, port and user from rti_addr.
*/
Expand Down
2 changes: 2 additions & 0 deletions include/core/platform/lf_zephyr_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h> //malloc, calloc, free, realloc

#include <zephyr/kernel.h>
#include <zephyr/posix/sys/socket.h>
#include <zephyr/posix/netdb.h>

#define NO_TTY
#ifdef LF_THREADED
Expand Down