Skip to content

Commit

Permalink
Merge pull request #82 from lf-lang/federated-error-message-on-stp
Browse files Browse the repository at this point in the history
Issue error messages and drop messages when STP violations occur with…
  • Loading branch information
edwardalee authored Jun 10, 2022
2 parents 66ca6b1 + 5cbc718 commit ba7d4dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,6 @@ void wait_until_port_status_known(int port_ID, interval_t STAA) {
*
* This is used for handling incoming timed messages to a federate.
*
*
* @param action The action or timer to be triggered.
* @param tag The tag of the message received over the network.
* @param value Dynamically allocated memory containing the value to send.
Expand Down Expand Up @@ -1810,7 +1809,7 @@ void handle_tagged_message(int socket, int fed_id) {
// was waiting for the message, trigger the corresponding reactions for this
// message.
LF_PRINT_LOG("Inserting reactions directly at tag (%lld, %u).",
intended_tag.time - start_time, intended_tag.microstep);
lf_tag().time - start_time, lf_tag().microstep);
action->intended_tag = intended_tag;
_lf_insert_reactions_for_trigger(action, message_token);

Expand All @@ -1830,7 +1829,11 @@ void handle_tagged_message(int socket, int fed_id) {
// But only if the stop time is not equal to the start time!
if (lf_tag_compare(lf_tag(), stop_tag) >= 0) {
lf_mutex_unlock(&mutex);
lf_print_warning("Received message too late. Already at stopping time. Discarding message.");
lf_print_error("Received message too late. Already at stop tag.\n"
"Current tag is (%lld, %u) and intended tag is (%lld, %u).\n"
"Discarding message.",
lf_tag().time - start_time, lf_tag().microstep,
intended_tag.time - start_time, intended_tag.microstep);
return;
}

Expand Down
15 changes: 13 additions & 2 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,19 +914,28 @@ bool _lf_worker_handle_STP_violation_for_reaction(int worker_number, reaction_t*
if (reaction->is_STP_violated == true) {
reaction_function_t handler = reaction->STP_handler;
LF_PRINT_LOG("STP violation detected.");

// Invoke the STP handler if there is one.
if (handler != NULL) {
LF_PRINT_LOG("Worker %d: Invoking tardiness handler.", worker_number);
LF_PRINT_LOG("Worker %d: Invoking STP violation handler.", worker_number);
// There is a violation
violation_occurred = true;
(*handler)(reaction->self);

// If the reaction produced outputs, put the resulting
// triggered reactions into the queue or execute them directly if possible.
schedule_output_reactions(reaction, worker_number);

// Reset the is_STP_violated because it has been dealt with
reaction->is_STP_violated = false;
} else {
// The intended tag cannot be respected and there is no handler.
// Print an error message and return true.
// NOTE: STP violations are ignored for control reactions, which need to
// execute anyway.
lf_print_error("STP violation occurred in a trigger to reaction %d, "
"and there is no handler.\n**** Invoking reaction at the wrong tag!",
reaction->number + 1); // +1 to align with diagram numbering.
}
}
return violation_occurred;
Expand Down Expand Up @@ -968,6 +977,8 @@ void _lf_worker_invoke_reaction(int worker_number, reaction_t* reaction) {
// If the reaction produced outputs, put the resulting triggered
// reactions into the queue or execute them immediately.
schedule_output_reactions(reaction, worker_number);

reaction->is_STP_violated = false;
}

/**
Expand Down

0 comments on commit ba7d4dd

Please sign in to comment.