Skip to content

Commit 275fc50

Browse files
Transient Federates (#251)
* reactor-uc debugging * Drop handshake responses if handshake is already completed. * reverting LF_DEBUG prints * bugs * Bring back interrupt disabling in UartPolledChannel_poll * changes * reverting changes * cleaning * semi working version * transient * adding new parameters to StartupCoordinator_ctor * transient stuff * merging with main * adding joining_policy attribute * cleaning up * refactor * more cleaning up * clean up * stuff * working version * fixing test * lfc shebang * formatting * fixing startup in non-federated * startup coordinator * revert CmakeGenerator changes * revert lfc.cmake * handling joining time announcement * testing support for annotations * feedback from edward * fix lfc * fixing comments on NeighborInformation struct * reverting unnecessary changes * fix example --------- Co-authored-by: erlingrj <[email protected]>
1 parent cac49c3 commit 275fc50

File tree

27 files changed

+388
-102
lines changed

27 files changed

+388
-102
lines changed

examples/posix/federated/receiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) {
6969
}
7070

7171
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 1, 6);
72-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6);
72+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6, JOIN_IMMEDIATELY);
7373

7474
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 1, 2);
7575
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 1, 2, true);

examples/posix/federated/sender.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) {
8080
}
8181

8282
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 1, 6);
83-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6);
83+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6, JOIN_IMMEDIATELY);
8484

8585
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 1, 2);
8686
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 1, 2, true);

examples/riot/coap_federated/receiver/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) {
6969
}
7070

7171
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 1, 6);
72-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6);
72+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6, JOIN_IMMEDIATELY);
7373

7474
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 1, 2);
7575
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 1, 2, false);

examples/riot/coap_federated/sender/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) {
7575
}
7676

7777
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 1, 6);
78-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6);
78+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6, JOIN_IMMEDIATELY);
7979

8080
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 1, 2);
8181
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 1, 1, true);

examples/zephyr/basic_federated/common/receiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) {
8383
}
8484

8585
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 1, 6);
86-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6);
86+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 1, 1, 6, JOIN_IMMEDIATELY);
8787
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 1, 2);
8888
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 1, 2, true);
8989

examples/zephyr/basic_federated/federated_sender/src/sender.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver2) {
134134
}
135135

136136
LF_DEFINE_STARTUP_COORDINATOR_STRUCT(Federate, 2, 9);
137-
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 2, 1, 9);
137+
LF_DEFINE_STARTUP_COORDINATOR_CTOR(Federate, 2, 1, 9, JOIN_IMMEDIATELY);
138138

139139
LF_DEFINE_CLOCK_SYNC_STRUCT(Federate, 2, 3);
140140
LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(Federate, 2, 3, true);
@@ -175,4 +175,4 @@ int main() {
175175
setup_led();
176176
action_ptr = &main_reactor.sender->act;
177177
lf_start();
178-
}
178+
}

external/proto/message.pb.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Automatically generated nanopb constant definitions */
2-
/* Generated by nanopb-1.0.0-dev */
2+
/* Generated by nanopb-0.4.9.1 */
33

4-
#include "message.pb.h"
4+
#include "./message.pb.h"
55
#if PB_PROTO_HEADER_VERSION != 40
66
#error Regenerate this file with the current version of nanopb generator.
77
#endif
@@ -27,6 +27,9 @@ PB_BIND(StartTimeRequest, StartTimeRequest, AUTO)
2727
PB_BIND(StartTimeResponse, StartTimeResponse, AUTO)
2828

2929

30+
PB_BIND(JoiningTimeAnnouncement, JoiningTimeAnnouncement, AUTO)
31+
32+
3033
PB_BIND(StartupCoordination, StartupCoordination, AUTO)
3134

3235

external/proto/message.pb.h

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated nanopb header */
2-
/* Generated by nanopb-1.0.0-dev */
2+
/* Generated by nanopb-0.4.9.1 */
33

4-
#ifndef PB_MESSAGE_PB_H_INCLUDED
5-
#define PB_MESSAGE_PB_H_INCLUDED
6-
#include "nanopb/pb.h"
4+
#ifndef PB_EXTERNAL_PROTO_MESSAGE_PB_H_INCLUDED
5+
#define PB_EXTERNAL_PROTO_MESSAGE_PB_H_INCLUDED
6+
#include <nanopb/pb.h>
77

88
#if PB_PROTO_HEADER_VERSION != 40
99
#error Regenerate this file with the current version of nanopb generator.
@@ -58,9 +58,14 @@ typedef struct _StartTimeRequest {
5858

5959
/* The response to a StartTimeRequest, telling the transient federate the start time of the federation. */
6060
typedef struct _StartTimeResponse {
61-
int64_t time;
61+
int64_t elapsed_logical_time;
62+
int64_t federation_start_time;
6263
} StartTimeResponse;
6364

65+
typedef struct _JoiningTimeAnnouncement {
66+
int64_t joining_time;
67+
} JoiningTimeAnnouncement;
68+
6469
/* The union of all messages that is handled by the StartupCoordinator. */
6570
typedef struct _StartupCoordination {
6671
pb_size_t which_message;
@@ -70,6 +75,7 @@ typedef struct _StartupCoordination {
7075
StartTimeProposal start_time_proposal;
7176
StartTimeResponse start_time_response;
7277
StartTimeRequest start_time_request;
78+
JoiningTimeAnnouncement joining_time_announcement;
7379
} message;
7480
} StartupCoordination;
7581

@@ -164,14 +170,16 @@ extern "C" {
164170

165171

166172

173+
167174
/* Initializer values for message structs */
168175
#define Tag_init_default {0, 0}
169176
#define TaggedMessage_init_default {Tag_init_default, 0, {0, {0}}}
170177
#define StartupHandshakeRequest_init_default {0}
171178
#define StartupHandshakeResponse_init_default {_StartupCoordinationState_MIN}
172179
#define StartTimeProposal_init_default {0, 0}
173180
#define StartTimeRequest_init_default {0}
174-
#define StartTimeResponse_init_default {0}
181+
#define StartTimeResponse_init_default {0, 0}
182+
#define JoiningTimeAnnouncement_init_default {0}
175183
#define StartupCoordination_init_default {0, {StartupHandshakeRequest_init_default}}
176184
#define ClockPriorityRequest_init_default {0}
177185
#define ClockPriorityBroadcastRequest_init_default {0}
@@ -188,7 +196,8 @@ extern "C" {
188196
#define StartupHandshakeResponse_init_zero {_StartupCoordinationState_MIN}
189197
#define StartTimeProposal_init_zero {0, 0}
190198
#define StartTimeRequest_init_zero {0}
191-
#define StartTimeResponse_init_zero {0}
199+
#define StartTimeResponse_init_zero {0, 0}
200+
#define JoiningTimeAnnouncement_init_zero {0}
192201
#define StartupCoordination_init_zero {0, {StartupHandshakeRequest_init_zero}}
193202
#define ClockPriorityRequest_init_zero {0}
194203
#define ClockPriorityBroadcastRequest_init_zero {0}
@@ -209,12 +218,15 @@ extern "C" {
209218
#define StartupHandshakeResponse_state_tag 1
210219
#define StartTimeProposal_time_tag 1
211220
#define StartTimeProposal_step_tag 2
212-
#define StartTimeResponse_time_tag 1
221+
#define StartTimeResponse_elapsed_logical_time_tag 1
222+
#define StartTimeResponse_federation_start_time_tag 2
223+
#define JoiningTimeAnnouncement_joining_time_tag 1
213224
#define StartupCoordination_startup_handshake_request_tag 1
214225
#define StartupCoordination_startup_handshake_response_tag 2
215226
#define StartupCoordination_start_time_proposal_tag 3
216227
#define StartupCoordination_start_time_response_tag 4
217228
#define StartupCoordination_start_time_request_tag 5
229+
#define StartupCoordination_joining_time_announcement_tag 6
218230
#define ClockPriority_priority_tag 1
219231
#define RequestSync_sequence_number_tag 1
220232
#define SyncResponse_sequence_number_tag 1
@@ -270,23 +282,31 @@ X(a, STATIC, REQUIRED, UINT32, step, 2)
270282
#define StartTimeRequest_DEFAULT NULL
271283

272284
#define StartTimeResponse_FIELDLIST(X, a) \
273-
X(a, STATIC, REQUIRED, INT64, time, 1)
285+
X(a, STATIC, REQUIRED, INT64, elapsed_logical_time, 1) \
286+
X(a, STATIC, REQUIRED, INT64, federation_start_time, 2)
274287
#define StartTimeResponse_CALLBACK NULL
275288
#define StartTimeResponse_DEFAULT NULL
276289

290+
#define JoiningTimeAnnouncement_FIELDLIST(X, a) \
291+
X(a, STATIC, REQUIRED, INT64, joining_time, 1)
292+
#define JoiningTimeAnnouncement_CALLBACK NULL
293+
#define JoiningTimeAnnouncement_DEFAULT NULL
294+
277295
#define StartupCoordination_FIELDLIST(X, a) \
278296
X(a, STATIC, ONEOF, MESSAGE, (message,startup_handshake_request,message.startup_handshake_request), 1) \
279297
X(a, STATIC, ONEOF, MESSAGE, (message,startup_handshake_response,message.startup_handshake_response), 2) \
280298
X(a, STATIC, ONEOF, MESSAGE, (message,start_time_proposal,message.start_time_proposal), 3) \
281299
X(a, STATIC, ONEOF, MESSAGE, (message,start_time_response,message.start_time_response), 4) \
282-
X(a, STATIC, ONEOF, MESSAGE, (message,start_time_request,message.start_time_request), 5)
300+
X(a, STATIC, ONEOF, MESSAGE, (message,start_time_request,message.start_time_request), 5) \
301+
X(a, STATIC, ONEOF, MESSAGE, (message,joining_time_announcement,message.joining_time_announcement), 6)
283302
#define StartupCoordination_CALLBACK NULL
284303
#define StartupCoordination_DEFAULT NULL
285304
#define StartupCoordination_message_startup_handshake_request_MSGTYPE StartupHandshakeRequest
286305
#define StartupCoordination_message_startup_handshake_response_MSGTYPE StartupHandshakeResponse
287306
#define StartupCoordination_message_start_time_proposal_MSGTYPE StartTimeProposal
288307
#define StartupCoordination_message_start_time_response_MSGTYPE StartTimeResponse
289308
#define StartupCoordination_message_start_time_request_MSGTYPE StartTimeRequest
309+
#define StartupCoordination_message_joining_time_announcement_MSGTYPE JoiningTimeAnnouncement
290310

291311
#define ClockPriorityRequest_FIELDLIST(X, a) \
292312

@@ -360,6 +380,7 @@ extern const pb_msgdesc_t StartupHandshakeResponse_msg;
360380
extern const pb_msgdesc_t StartTimeProposal_msg;
361381
extern const pb_msgdesc_t StartTimeRequest_msg;
362382
extern const pb_msgdesc_t StartTimeResponse_msg;
383+
extern const pb_msgdesc_t JoiningTimeAnnouncement_msg;
363384
extern const pb_msgdesc_t StartupCoordination_msg;
364385
extern const pb_msgdesc_t ClockPriorityRequest_msg;
365386
extern const pb_msgdesc_t ClockPriorityBroadcastRequest_msg;
@@ -379,6 +400,7 @@ extern const pb_msgdesc_t FederateMessage_msg;
379400
#define StartTimeProposal_fields &StartTimeProposal_msg
380401
#define StartTimeRequest_fields &StartTimeRequest_msg
381402
#define StartTimeResponse_fields &StartTimeResponse_msg
403+
#define JoiningTimeAnnouncement_fields &JoiningTimeAnnouncement_msg
382404
#define StartupCoordination_fields &StartupCoordination_msg
383405
#define ClockPriorityRequest_fields &ClockPriorityRequest_msg
384406
#define ClockPriorityBroadcastRequest_fields &ClockPriorityBroadcastRequest_msg
@@ -397,13 +419,14 @@ extern const pb_msgdesc_t FederateMessage_msg;
397419
#define ClockSyncMessage_size 24
398420
#define DelayRequest_size 11
399421
#define DelayResponse_size 22
422+
#define EXTERNAL_PROTO_MESSAGE_PB_H_MAX_SIZE FederateMessage_size
400423
#define FederateMessage_size 868
401-
#define MESSAGE_PB_H_MAX_SIZE FederateMessage_size
424+
#define JoiningTimeAnnouncement_size 11
402425
#define RequestSync_size 11
403426
#define StartTimeProposal_size 17
404427
#define StartTimeRequest_size 0
405-
#define StartTimeResponse_size 11
406-
#define StartupCoordination_size 19
428+
#define StartTimeResponse_size 22
429+
#define StartupCoordination_size 24
407430
#define StartupHandshakeRequest_size 0
408431
#define StartupHandshakeResponse_size 2
409432
#define SyncResponse_size 22

external/proto/message.proto

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ message StartTimeProposal {
4141
message StartTimeRequest{ }
4242

4343
// The response to a StartTimeRequest, telling the transient federate the start time of the federation.
44-
message StartTimeResponse{ required int64 time = 1; }
44+
message StartTimeResponse {
45+
required int64 elapsed_logical_time = 1;
46+
required int64 federation_start_time = 2;
47+
}
48+
49+
message JoiningTimeAnnouncement {
50+
required int64 joining_time = 1;
51+
}
4552

4653
// The union of all messages that is handled by the StartupCoordinator.
4754
message StartupCoordination {
@@ -51,6 +58,7 @@ message StartupCoordination {
5158
StartTimeProposal start_time_proposal = 3;
5259
StartTimeResponse start_time_response = 4;
5360
StartTimeRequest start_time_request = 5;
61+
JoiningTimeAnnouncement joining_time_announcement = 6;
5462
}
5563
}
5664

@@ -110,4 +118,4 @@ message FederateMessage {
110118
StartupCoordination startup_coordination = 3;
111119
ClockSyncMessage clock_sync_msg = 4;
112120
}
113-
}
121+
}

include/reactor-uc/environment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,7 @@ struct Environment {
150150
void Environment_ctor(Environment *self, Reactor *main, Scheduler *scheduler, bool fast_mode);
151151
void Environment_free(Environment *self);
152152

153+
void Environment_schedule_startups(const Environment *self, tag_t start_tag);
154+
void Environment_schedule_timers(Environment *self, const Reactor *reactor, tag_t start_tag);
155+
153156
#endif

0 commit comments

Comments
 (0)