reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
rti_remote.h
Go to the documentation of this file.
1#if defined STANDALONE_RTI
15#ifndef RTI_REMOTE_H
16#define RTI_REMOTE_H
17
18#include <sys/socket.h>
19#include <sys/types.h> // Provides select() function to read from multiple sockets.
20#include <netinet/in.h> // Defines struct sockaddr_in
21#include <arpa/inet.h> // inet_ntop & inet_pton
22#include <unistd.h> // Defines read(), write(), and close()
23#include <strings.h> // Defines bzero().
24
25#include "rti_common.h"
26
27#ifdef __RTI_AUTH__
28#include <openssl/rand.h> // For secure random number generation.
29#include <openssl/hmac.h> // For HMAC authentication.
30#endif
31
32#include "lf_types.h"
33#include "pqueue_tag.h"
34#include "socket_common.h"
35
37#define MAX_TIME_FOR_REPLY_TO_STOP_REQUEST SEC(30)
38
41
50typedef struct federate_info_t {
51 scheduling_node_t enclave;
52 bool requested_stop; // Indicates that the federate has requested stop or has replied
53 // to a request for stop from the RTI. Used to prevent double-counting
54 // a federate when handling lf_request_stop().
55 lf_thread_t thread_id; // The ID of the thread handling communication with this federate.
56 int socket; // The TCP socket descriptor for communicating with this federate.
57 struct sockaddr_in UDP_addr; // The UDP address for the federate.
58 bool clock_synchronization_enabled; // Indicates the status of clock synchronization
59 // for this federate. Enabled by default.
60 pqueue_tag_t* in_transit_message_tags; // Record of in-transit messages to this federate that are not
61 // yet processed. This record is ordered based on the time
62 // value of each message for a more efficient access.
63 char server_hostname[INET_ADDRSTRLEN]; // Human-readable IP address and
64 int32_t server_port; // port number of the socket server of the federate
65 // if it has any incoming direct connections from other federates.
66 // The port number will be -1 if there is no server or if the
67 // RTI has not been informed of the port number.
68 struct in_addr server_ip_addr; // Information about the IP address of the socket
69 // server of the federate.
70} federate_info_t;
71
75typedef enum clock_sync_stat { clock_sync_off, clock_sync_init, clock_sync_on } clock_sync_stat;
76
90typedef struct rti_remote_t {
91 rti_common_t base;
92 // Maximum start time seen so far from the federates.
93 int64_t max_start_time;
94
95 // Number of federates that have proposed start times.
96 int num_feds_proposed_start;
97
106 volatile bool all_federates_exited;
107
113 const char* federation_id;
114
115
117 uint16_t user_specified_port;
118
120 uint16_t final_port_TCP;
121
123 int socket_descriptor_TCP;
124
125
127 uint16_t final_port_UDP;
128
130 int socket_descriptor_UDP;
131
132
133 /* Thread performing PTP clock sync sessions periodically. */
134 lf_thread_t clock_thread;
135
140 clock_sync_stat clock_sync_global_status;
141
145 uint64_t clock_sync_period_ns;
146
150 int32_t clock_sync_exchanges_per_interval;
151
155 bool authentication_enabled;
159 bool stop_in_progress;
160} rti_remote_t;
161
172
179
183extern bool _lf_federate_reports_error;
184
199void update_federate_next_event_tag_locked(uint16_t federate_id, tag_t next_event_tag);
200
206void handle_port_absent_message(federate_info_t* sending_federate, unsigned char* buffer);
207
216void handle_timed_message(federate_info_t* sending_federate, unsigned char* buffer);
217
226void handle_latest_tag_confirmed(federate_info_t* fed);
227
235void handle_next_event_tag(federate_info_t* fed);
236
238
246void handle_stop_request_message(federate_info_t* fed);
247
255void handle_stop_request_reply(federate_info_t* fed);
256
258
270void handle_address_query(uint16_t fed_id);
271
287void handle_address_ad(uint16_t federate_id);
288
293void handle_timestamp(federate_info_t* my_fed);
294
305void send_physical_clock(unsigned char message_type, federate_info_t* fed, socket_type_t socket_type);
306
320void handle_physical_clock_sync_message(federate_info_t* my_fed, socket_type_t socket_type);
321
333void* clock_synchronization_thread(void* noargs);
334
340void* federate_info_thread_TCP(void* fed);
341
347void send_reject(int* socket_id, unsigned char error_code);
348
355void lf_connect_to_federates(int socket_descriptor);
356
362void* respond_to_erroneous_connections(void* nothing);
363
368void initialize_federate(federate_info_t* fed, uint16_t id);
369
377int32_t start_rti_server(uint16_t port);
378
384void wait_for_federates(int socket_descriptor);
385
389void usage(int argc, const char* argv[]);
390
400int process_clock_sync_args(int argc, const char* argv[]);
401
407int process_args(int argc, const char* argv[]);
408
412void initialize_RTI(rti_remote_t* rti);
413
414#endif // RTI_REMOTE_H
415#endif // STANDALONE_RTI
K nothing
Definition hashmap.h:54
void * lf_thread_t
Definition lf_arduino_support.h:120
Type definitions that are widely used across different parts of the runtime.
Priority queue that uses tags for sorting.
int process_args(int argc, const char *argv[])
Definition reactor_common.c:942
int lf_critical_section_enter(environment_t *env)
Enter critical section by locking the global mutex.
Definition reactor_threaded.c:1153
int lf_critical_section_exit(environment_t *env)
Leave a critical section by unlocking the global mutex.
Definition reactor_threaded.c:1165
Common declarations for runtime infrastructure (RTI) for scheduling enclaves and distributed Lingua F...
socket_type_t
Definition socket_common.h:69
Execution environment. This struct contains information about the execution environment....
Definition environment.h:49
Definition pqueue_base.h:73
Definition tag.h:78
void usage()
Definition trace_to_chrome.c:58
char buffer[BUFFER_SIZE]
Definition trace_util.c:42