reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
federate.h
Go to the documentation of this file.
1
17
18#ifndef FEDERATE_H
19#define FEDERATE_H
20
21#include <stdbool.h>
22
23#include "tag.h"
24#include "lf_types.h"
25#include "environment.h"
26#include "low_level_platform.h"
27#include "net_abstraction.h"
28
29#ifndef ADVANCE_MESSAGE_INTERVAL
30#define ADVANCE_MESSAGE_INTERVAL MSEC(10)
31#endif
32
34// Data types
35
203
204#ifdef FEDERATED_DECENTRALIZED
214#endif
215
226
232
234// Global variables
235
240extern lf_mutex_t lf_outbound_net_mutex;
241
246extern lf_cond_t lf_port_status_changed;
247
249// Public functions (in alphabetical order)
250
266void lf_connect_to_federate(uint16_t remote_federate_id);
267
282void lf_connect_to_rti(const char* hostname, int port_number);
283
301void lf_create_server(int specified_port);
302
313
325
338
346
359
379int lf_send_message(int message_type, unsigned short port, unsigned short federate, const char* next_destination_str,
380 size_t length, unsigned char* message);
381
393void lf_send_neighbor_structure_to_RTI(net_abstraction_t);
394
452tag_t lf_send_next_event_tag(environment_t* env, tag_t tag, bool wait_for_reply);
453
466void lf_send_port_absent_to_federate(environment_t* env, interval_t additional_delay, unsigned short port_ID,
467 unsigned short fed_ID);
468
479
513int lf_send_tagged_message(environment_t* env, interval_t additional_delay, int message_type, unsigned short port,
514 unsigned short federate, const char* next_destination_str, size_t length,
515 unsigned char* message);
516
523void lf_set_federation_id(const char* fid);
524
525#ifdef FEDERATED_DECENTRALIZED
534#endif
535
546
554
565
582bool lf_update_max_level(tag_t tag, bool is_provisional);
583
584#ifdef FEDERATED_DECENTRALIZED
598#endif // FEDERATED_DECENTRALIZED
599
600#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
void lf_set_federation_id(const char *fid)
Set the federation_id of this federate.
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)
Connect to the 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:231
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:231
@ FAILED_TO_PARSE
Definition federate.h:231
@ SUCCESS
Definition federate.h:231
@ INVALID_PORT
Definition federate.h:231
@ INVALID_HOST
Definition federate.h:231
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:40
bool is_last_TAG_provisional
Indicates whether the last TAG received is provisional or an ordinary TAG.
Definition federate.h:132
lf_thread_t * inbound_net_listeners
Array of thread IDs for threads that listen for incoming messages.
Definition federate.h:65
size_t number_of_outbound_p2p_connections
Number of outbound peer-to-peer connections from the federate.
Definition federate.h:72
tag_t last_sent_NET
A record of the most recently sent NET (next event tag) signal.
Definition federate.h:170
net_abstraction_t net_to_RTI
The network abstraction for this federate to communicate with the RTI.
Definition federate.h:46
net_abstraction_t server_net
A network abstraction for the server of the federate.
Definition federate.h:118
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:87
lf_thread_t RTI_net_listener
Thread listening for incoming messages from the RTI.
Definition federate.h:51
bool has_upstream
Indicator of whether this federate has upstream federates.
Definition federate.h:138
size_t number_of_inbound_p2p_connections
Number of inbound physical connections to the federate.
Definition federate.h:58
tag_t last_DNET
A record of the most recent DNET (downstream next event tag) signal.
Definition federate.h:185
lf_thread_t staaSetter
Thread responsible for setting ports to absent by an STAA offset if they aren't already known.
Definition federate.h:200
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:193
tag_t last_TAG
Most recent tag advance grant (TAG) received from the RTI, or NEVER if none has been received.
Definition federate.h:125
bool received_any_DNET
Indicator of whether this federate has received any DNET (downstream next event tag) signal.
Definition federate.h:180
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:108
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:102
bool has_downstream
Indicator of whether this federate has downstream federates.
Definition federate.h:144
tag_t last_sent_LTC
A record of the most recently sent LTC (latest tag confirmed) message.
Definition federate.h:165
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:151
tag_t last_skipped_NET
A record of the most recently skipped NET (next event tag) signal.
Definition federate.h:175
Structure for federation metadata.
Definition federate.h:220
const char * federation_id
Definition federate.h:221
char * rti_host
Definition federate.h:222
char * rti_user
Definition federate.h:224
int rti_port
Definition federate.h:223
Base type for actions.
Definition lf_types.h:583
Structure for STAA (safe to assume absent).
Definition federate.h:209
size_t STAA
Definition federate.h:211
size_t num_actions
Definition federate.h:212
lf_action_base_t ** actions
Definition federate.h:210
A tag is a time, microstep pair.
Definition tag.h:119
Time and tag definitions and functions for Lingua Franca.