reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
federate.h
Go to the documentation of this file.
1
18
19#ifndef FEDERATE_H
20#define FEDERATE_H
21
22#include <stdbool.h>
23
24#include "environment.h"
25#include "lf_types.h"
26#include "low_level_platform.h"
27#include "net_abstraction.h"
28#include "tag.h"
29
30#ifndef ADVANCE_MESSAGE_INTERVAL
31#define ADVANCE_MESSAGE_INTERVAL MSEC(10)
32#endif
33
35// Data types
36
41typedef struct federate_instance_t {
47 net_abstraction_t net_to_RTI;
48
52 lf_thread_t RTI_net_listener;
53
60
65
72
79
84
92 tag_t downstream_p2p_joined_tag[NUMBER_OF_FEDERATES];
93
107 net_abstraction_t net_for_inbound_p2p_connections[NUMBER_OF_FEDERATES];
108
116 bool upstream_fed_is_transient[NUMBER_OF_FEDERATES];
117
125 bool upstream_fed_is_connected[NUMBER_OF_FEDERATES];
126
140 net_abstraction_t net_for_outbound_p2p_connections[NUMBER_OF_FEDERATES];
141
147 bool transients[NUMBER_OF_FEDERATES];
148
154
163 net_abstraction_t server_net;
164
171
178
185
192
199
213
218
223
228
233
241
247
248#ifdef FEDERATED_DECENTRALIZED
253 lf_thread_t staaSetter;
254#endif
256
257#ifdef FEDERATED_DECENTRALIZED
267#endif
268
279
285
287// Global variables
288
293extern lf_mutex_t lf_outbound_net_mutex;
294
299extern lf_cond_t lf_port_status_changed;
300
302// Public functions (in alphabetical order)
303
326void lf_connect_to_federate(uint16_t remote_federate_id, tag_t joined_tag, int32_t port, uint32_t ip_address);
327
342void lf_connect_to_rti(const char* hostname, int port_number);
343
361void lf_create_server(int specified_port);
362
373
385
398
406
419
438int lf_send_message(int message_type, unsigned short port, unsigned short federate, const char* next_destination_str,
439 size_t length, unsigned char* message);
440
452void lf_send_neighbor_structure_to_RTI(net_abstraction_t);
453
511tag_t lf_send_next_event_tag(environment_t* env, tag_t tag, bool wait_for_reply);
512
525void lf_send_port_absent_to_federate(environment_t* env, interval_t additional_delay, unsigned short port_ID,
526 unsigned short fed_ID);
527
538
575int lf_send_tagged_message(environment_t* env, interval_t additional_delay, int message_type, unsigned short port,
576 unsigned short federate, const char* next_destination_str, size_t length,
577 unsigned char* message);
578
579#ifdef FEDERATED_DECENTRALIZED
588#endif
589
600
609
620
637bool lf_update_max_level(tag_t tag, bool is_provisional);
638
639#ifdef FEDERATED_DECENTRALIZED
653#endif // FEDERATED_DECENTRALIZED
654
655#endif // FEDERATE_H
API for the environment data structure.
int64_t instant_t
Time instant.
Definition tag.h:101
int64_t interval_t
Interval of time.
Definition tag.h:107
int lf_send_tagged_message(environment_t *env, interval_t additional_delay, int message_type, unsigned short port, unsigned short federate, const char *next_destination_str, size_t length, unsigned char *message)
Send a tagged message to the specified port of the specified federate.
lf_mutex_t lf_outbound_net_mutex
Mutex lock held while performing outbound network abstraction write and close operations.
void lf_connect_to_federate(uint16_t remote_federate_id, tag_t joined_tag, int32_t port, uint32_t ip_address)
Connect to the downstream federate with the specified id.
int lf_send_message(int message_type, unsigned short port, unsigned short federate, const char *next_destination_str, size_t length, unsigned char *message)
Send a message to another federate.
tag_t lf_send_next_event_tag(environment_t *env, tag_t tag, bool wait_for_reply)
Send a next event tag (NET) signal.
void lf_synchronize_with_other_federates(void)
Synchronize the start with other federates via the RTI.
void lf_spawn_staa_thread(void)
Spawn a thread to iterate through STAA structs.
lf_cond_t lf_port_status_changed
Condition variable for blocking on unkonwn federate input ports.
void lf_send_port_absent_to_federate(environment_t *env, interval_t additional_delay, unsigned short port_ID, unsigned short fed_ID)
Send a port absent message.
void lf_latest_tag_confirmed(tag_t tag_to_send)
Send a latest tag confirmed (LTC) signal to the RTI.
bool lf_update_max_level(tag_t tag, bool is_provisional)
Update the max level allowed to advance (MLAA).
void lf_create_server(int specified_port)
Create a server to listen to incoming P2P connections.
void lf_connect_to_rti(const char *hostname, int port_number)
Connect to the RTI at the specified host and port.
void lf_stall_advance_level_federation(environment_t *env, size_t level)
Wait until inputs statuses are known up to and including the specified level.
parse_rti_code_t
Code returned by lf_parse_rti_addr().
Definition federate.h:284
instant_t lf_wait_until_time(tag_t tag)
Return the physical time that we should wait until before advancing to the specified tag.
void lf_stall_advance_level_federation_locked(size_t level)
Version of lf_stall_advance_level_federation() that assumes the caller holds the mutex lock.
int lf_send_stop_request_to_rti(tag_t stop_tag)
Send a MSG_TYPE_STOP_REQUEST message to the RTI.
void lf_send_neighbor_structure_to_RTI(net_abstraction_t)
Send information about connections to the RTI.
void lf_reset_status_fields_on_input_port_triggers(void)
Reset the status fields on network input ports to unknown or absent.
void lf_enqueue_port_absent_reactions(environment_t *env)
Enqueue port absent reactions.
parse_rti_code_t lf_parse_rti_addr(const char *rti_addr)
Parse the address of the RTI and store them into the global federation_metadata struct.
void * lf_handle_p2p_connections_from_federates(void *ignored)
Thread to accept connections from other federates.
@ INVALID_USER
Definition federate.h:284
@ FAILED_TO_PARSE
Definition federate.h:284
@ SUCCESS
Definition federate.h:284
@ INVALID_PORT
Definition federate.h:284
@ INVALID_HOST
Definition federate.h:284
Type definitions that are widely used across different parts of the runtime.
Platform API support for the C target of Lingua Franca.
Execution environment.
Definition environment.h:52
Structure that a federate instance uses to keep track of its own state.
Definition federate.h:41
bool is_last_TAG_provisional
Indicates whether the last TAG received is provisional or an ordinary TAG.
Definition federate.h:177
lf_thread_t * inbound_net_listeners
Array of thread IDs for threads that listen for incoming messages.
Definition federate.h:71
bool transients[NUMBER_OF_FEDERATES]
An array indicating whether each federate is transient.
Definition federate.h:147
tag_t downstream_p2p_joined_tag[NUMBER_OF_FEDERATES]
An array that holds the tag at which the downstream federate joined.
Definition federate.h:92
size_t number_of_outbound_p2p_connections
Number of outbound peer-to-peer connections from the federate.
Definition federate.h:78
bool upstream_fed_is_transient[NUMBER_OF_FEDERATES]
An array indexed by federate ID indicating whether the corresponding inbound peer-to-peer federate is...
Definition federate.h:116
tag_t last_sent_NET
A record of the most recently sent NET (next event tag) signal.
Definition federate.h:217
net_abstraction_t net_to_RTI
The network abstraction for this federate to communicate with the RTI.
Definition federate.h:47
net_abstraction_t server_net
A network abstraction for the server of the federate.
Definition federate.h:163
net_abstraction_t net_for_inbound_p2p_connections[NUMBER_OF_FEDERATES]
An array that holds the network abstractions for inbound connections from each federate.
Definition federate.h:107
lf_thread_t RTI_net_listener
Thread listening for incoming messages from the RTI.
Definition federate.h:52
bool has_upstream
Indicator of whether this federate has upstream federates.
Definition federate.h:184
size_t number_of_inbound_p2p_connections
Number of inbound physical connections to the federate.
Definition federate.h:59
tag_t last_DNET
A record of the most recent DNET (downstream next event tag) signal.
Definition federate.h:232
size_t number_of_inbound_p2p_transients
Number of inbound peer-to-peer connections from transient federates.
Definition federate.h:64
lf_thread_t staaSetter
Thread responsible for setting ports to absent by an STAA offset if they aren't already known.
Definition federate.h:253
instant_t min_delay_from_physical_action_to_federate_output
For use in federates with centralized coordination, the minimum time delay between a physical action ...
Definition federate.h:240
bool is_transient
Indicator of whether this federate is transient.
Definition federate.h:246
tag_t last_TAG
Most recent tag advance grant (TAG) received from the RTI, or NEVER if none has been received.
Definition federate.h:170
bool received_any_DNET
Indicator of whether this federate has received any DNET (downstream next event tag) signal.
Definition federate.h:227
lf_thread_t inbound_p2p_handling_thread_id
Thread ID for a thread that accepts network abstractions and then supervises listening to those netwo...
Definition federate.h:153
size_t number_of_downstream_p2p_transients
Number of outbound peer-to-peer connections to transient federates.
Definition federate.h:83
net_abstraction_t net_for_outbound_p2p_connections[NUMBER_OF_FEDERATES]
An array that holds the network abstractions for outbound direct connections to each remote federate.
Definition federate.h:140
bool has_downstream
Indicator of whether this federate has downstream federates.
Definition federate.h:191
bool upstream_fed_is_connected[NUMBER_OF_FEDERATES]
An array indexed by federate ID indicating whether the corresponding inbound peer-to-peer connection ...
Definition federate.h:125
tag_t last_sent_LTC
A record of the most recently sent LTC (latest tag confirmed) message.
Definition federate.h:212
bool received_stop_request_from_rti
Used to prevent the federate from sending a REQUEST_STOP message if it has already received a stop re...
Definition federate.h:198
tag_t last_skipped_NET
A record of the most recently skipped NET (next event tag) signal.
Definition federate.h:222
Structure for federation metadata.
Definition federate.h:273
const char * federation_id
Definition federate.h:274
char * rti_host
Definition federate.h:275
char * rti_user
Definition federate.h:277
int rti_port
Definition federate.h:276
Base type for actions.
Definition lf_types.h:583
Structure for STAA (safe to assume absent).
Definition federate.h:262
size_t STAA
Definition federate.h:264
size_t num_actions
Definition federate.h:265
lf_action_base_t ** actions
Definition federate.h:263
A tag is a time, microstep pair.
Definition tag.h:119
Time and tag definitions and functions for Lingua Franca.