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
36#define MAX_TIME_FOR_REPLY_TO_STOP_REQUEST SEC(30)
37
40
41typedef enum socket_type_t { TCP, UDP } socket_type_t;
42
51typedef struct federate_info_t {
52 scheduling_node_t enclave;
53 bool requested_stop; // Indicates that the federate has requested stop or has replied
54 // to a request for stop from the RTI. Used to prevent double-counting
55 // a federate when handling lf_request_stop().
56 lf_thread_t thread_id; // The ID of the thread handling communication with this federate.
57 int socket; // The TCP socket descriptor for communicating with this federate.
58 struct sockaddr_in UDP_addr; // The UDP address for the federate.
59 bool clock_synchronization_enabled; // Indicates the status of clock synchronization
60 // for this federate. Enabled by default.
61 pqueue_tag_t* in_transit_message_tags; // Record of in-transit messages to this federate that are not
62 // yet processed. This record is ordered based on the time
63 // value of each message for a more efficient access.
64 char server_hostname[INET_ADDRSTRLEN]; // Human-readable IP address and
65 int32_t server_port; // port number of the socket server of the federate
66 // if it has any incoming direct connections from other federates.
67 // The port number will be -1 if there is no server or if the
68 // RTI has not been informed of the port number.
69 struct in_addr server_ip_addr; // Information about the IP address of the socket
70 // server of the federate.
71} federate_info_t;
72
76typedef enum clock_sync_stat { clock_sync_off, clock_sync_init, clock_sync_on } clock_sync_stat;
77
91typedef struct rti_remote_t {
92 rti_common_t base;
93 // Maximum start time seen so far from the federates.
94 int64_t max_start_time;
95
96 // Number of federates that have proposed start times.
97 int num_feds_proposed_start;
98
107 volatile bool all_federates_exited;
108
114 const char* federation_id;
115
116
118 uint16_t user_specified_port;
119
121 uint16_t final_port_TCP;
122
124 int socket_descriptor_TCP;
125
126
128 uint16_t final_port_UDP;
129
131 int socket_descriptor_UDP;
132
133
134 /* Thread performing PTP clock sync sessions periodically. */
135 lf_thread_t clock_thread;
136
141 clock_sync_stat clock_sync_global_status;
142
146 uint64_t clock_sync_period_ns;
147
151 int32_t clock_sync_exchanges_per_interval;
152
156 bool authentication_enabled;
160 bool stop_in_progress;
161} rti_remote_t;
162
173
180
184extern bool _lf_federate_reports_error;
185
200void update_federate_next_event_tag_locked(uint16_t federate_id, tag_t next_event_tag);
201
207void handle_port_absent_message(federate_info_t* sending_federate, unsigned char* buffer);
208
217void handle_timed_message(federate_info_t* sending_federate, unsigned char* buffer);
218
227void handle_latest_tag_confirmed(federate_info_t* fed);
228
236void handle_next_event_tag(federate_info_t* fed);
237
239
247void handle_stop_request_message(federate_info_t* fed);
248
256void handle_stop_request_reply(federate_info_t* fed);
257
259
271void handle_address_query(uint16_t fed_id);
272
288void handle_address_ad(uint16_t federate_id);
289
294void handle_timestamp(federate_info_t* my_fed);
295
306void send_physical_clock(unsigned char message_type, federate_info_t* fed, socket_type_t socket_type);
307
321void handle_physical_clock_sync_message(federate_info_t* my_fed, socket_type_t socket_type);
322
334void* clock_synchronization_thread(void* noargs);
335
341void* federate_info_thread_TCP(void* fed);
342
348void send_reject(int* socket_id, unsigned char error_code);
349
356void lf_connect_to_federates(int socket_descriptor);
357
363void* respond_to_erroneous_connections(void* nothing);
364
369void initialize_federate(federate_info_t* fed, uint16_t id);
370
378int32_t start_rti_server(uint16_t port);
379
385void wait_for_federates(int socket_descriptor);
386
390void usage(int argc, const char* argv[]);
391
401int process_clock_sync_args(int argc, const char* argv[]);
402
408int process_args(int argc, const char* argv[]);
409
413void initialize_RTI(rti_remote_t* rti);
414
415#endif // RTI_REMOTE_H
416#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:910
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...
Execution environment. This struct contains information about the execution environment....
Definition environment.h:49
Definition pqueue_base.h:73
Definition tag.h:81
void usage()
Definition trace_to_chrome.c:58
char buffer[BUFFER_SIZE]
Definition trace_util.c:42