Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Create Network driver instead of directly using sockets. #2256

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1ee306f
Added comment about test
edwardalee Jan 13, 2024
f71a2b5
Spotless
edwardalee Jan 13, 2024
2d77be2
Align reactor-c
edwardalee Jan 14, 2024
0466e8b
Align reactor-c
edwardalee Jan 15, 2024
d9ebe5a
Align reactor-c
edwardalee Jan 15, 2024
fbbf9de
Override hashCode() in TimeValue to match equals()
edwardalee Jan 20, 2024
3cf5b4d
Spotless
edwardalee Jan 20, 2024
e5e78f8
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Jan 23, 2024
3cc5488
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Feb 2, 2024
bc9a001
Update reactor-c
Jakio815 Feb 2, 2024
331665d
Add todos
Jakio815 Feb 15, 2024
7311c83
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Feb 15, 2024
28d2cf2
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Feb 15, 2024
c43193e
Minor fix & sync
Jakio815 Feb 16, 2024
9a0feec
Fix code generator socket things
Jakio815 Feb 16, 2024
386af00
Update branch
Jakio815 Feb 21, 2024
0959353
Add largefile test
Jakio815 Feb 23, 2024
76570b9
Sync main
Jakio815 Feb 23, 2024
8865f12
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Feb 23, 2024
3b7949e
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Feb 27, 2024
4b71ee7
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Mar 12, 2024
696c6e9
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Mar 15, 2024
43942da
Fix reactor-c
Jakio815 Mar 15, 2024
1bce919
Fix reactor-c point
Jakio815 Mar 15, 2024
b749c0b
New target property "comm-type"
Jakio815 Mar 29, 2024
2ce83fe
Add -c options in generator script to find federate's sst config
Jakio815 Apr 6, 2024
81e87de
Make sstconfiggenerator
Jakio815 Apr 6, 2024
a1a4718
Change -c to -sst or --sst to get config path.
Jakio815 Apr 7, 2024
ca6027a
Set rti and federate to get sstconfig by sst config generator.
Jakio815 Apr 7, 2024
af32aa4
Warning fix
Jakio815 Apr 7, 2024
2018d0c
Fix FileAlreadyExistsException for already existing rti.config.
hokeun Apr 8, 2024
6dde189
Make sst config generatory only for sst options
Jakio815 Apr 8, 2024
d45a124
Add some skeleton for OPENSSL_REQUIRED definition
Jakio815 Apr 28, 2024
cb79f08
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Apr 28, 2024
bcd4630
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 May 11, 2024
33eb818
Fix config generator.
Jakio815 Jun 17, 2024
fec1b1d
Minor fix
Jakio815 Jun 17, 2024
60e8ac8
Fix to use message reporter.
Jakio815 Jun 17, 2024
080ffad
Add SST Path Property
Jakio815 Jun 18, 2024
a1daca4
Add todo to add script to execute auth
Jakio815 Jun 18, 2024
2fe2faa
Add cleanAll and generateAll work while compiling lf file.
Jakio815 Jun 18, 2024
3775f17
Create SSTGraphGenerator.java
Jakio815 Jun 18, 2024
d8cda8e
Fix SST process executor
Jakio815 Jun 18, 2024
28480b4
Move code to a single SSTGenerator.java
Jakio815 Jun 18, 2024
814ae53
Add copying credentials and fixing SSTconfig to point the copied files.
Jakio815 Jun 18, 2024
032a84d
Add getSSTAuthPath
Jakio815 Jun 19, 2024
0b1039b
Fix error messages & Copy auth credentials and properties & Fix Auth …
Jakio815 Jun 19, 2024
5af234b
Create Auth execution generation script.
Jakio815 Jun 19, 2024
e85076c
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Jun 25, 2024
b3ee7fb
Match reactor-c
Jakio815 Nov 25, 2024
69f80a7
Merge branch 'netdriver' of github.com:lf-lang/lingua-franca into net…
Jakio815 Nov 25, 2024
52a01ea
Follow submodules
Jakio815 Nov 25, 2024
638a68d
Merge branch 'master' of github.com:lf-lang/lingua-franca into netdriver
Jakio815 Dec 9, 2024
c654686
Fix formatting
Jakio815 Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions core/src/main/java/org/lflang/federated/extensions/CExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ public String generateNetworkSenderBody(
+ " in federate "
+ connection.getDstFederate().name);

// In case sendRef is a multiport or is in a bank, this reaction will be triggered when any
// In case sendRef is a multiport or is in a bank, this reaction will be
// triggered when any
// channel or bank index of sendRef is present
// ex. if a.out[i] is present, the entire output a.out is triggered.
if (connection.getSrcBank() != -1 || connection.getSrcChannel() != -1) {
Expand All @@ -300,10 +301,13 @@ public String generateNetworkSenderBody(
result.pr("}");
}

// If the connection is physical and the receiving federate is remote, send it directly on a
// If the connection is physical and the receiving federate is remote, send it
// directly on a
// socket.
// If the connection is logical and the coordination mode is centralized, send via RTI.
// If the connection is logical and the coordination mode is decentralized, send directly
// If the connection is logical and the coordination mode is centralized, send
// via RTI.
// If the connection is logical and the coordination mode is decentralized, send
// directly
String messageType;
// Name of the next immediate destination of this message
var next_destination_name = "\"federate " + connection.getDstFederate().id + "\"";
Expand Down Expand Up @@ -682,10 +686,11 @@ private String generateCodeToInitializeFederate(
String.join(
"\n",
"// Initialize the socket mutexes",
"lf_mutex_init(&lf_outbound_socket_mutex);",
"lf_mutex_init(&socket_mutex);",
"lf_mutex_init(&lf_outbound_netdrv_mutex);",
"lf_mutex_init(&netdrv_mutex);",
"lf_cond_init(&lf_port_status_changed, &env->mutex);"));

// CExtensionUtils.surroundWithIfOpenSSLRequired(
// "OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, NULL);"),
// Find the STA (A.K.A. the global STP offset) for this federate.
if (federate.targetConfig.get(CoordinationProperty.INSTANCE)
== CoordinationMode.DECENTRALIZED) {
Expand Down Expand Up @@ -738,14 +743,16 @@ else if (globalSTP instanceof CodeExprImpl)
"\n",
"// Initialize the array of socket for incoming connections to -1.",
"for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {",
" _fed.sockets_for_inbound_p2p_connections[i] = -1;",
" _fed.netdrv_for_inbound_p2p_connections[i] = NULL;",
// " _fed.netdrv_to_inbound[i] = NULL;",
"}"));
code.pr(
String.join(
"\n",
"// Initialize the array of socket for outgoing connections to -1.",
"for (int i = 0; i < NUMBER_OF_FEDERATES; i++) {",
" _fed.sockets_for_outbound_p2p_connections[i] = -1;",
" _fed.netdrv_for_outbound_p2p_connections[i] = NULL;",
// " _fed.netdrv_to_outbound[i] = NULL;",
"}"));
var clockSyncOptions = federate.targetConfig.getOrDefault(ClockSyncOptionsProperty.INSTANCE);
// If a test clock offset has been specified, insert code to set it here.
Expand All @@ -771,7 +778,7 @@ else if (globalSTP instanceof CodeExprImpl)
// Disable clock synchronization for the federate if it resides on the same host as the RTI,
// unless that is overridden with the clock-sync-options target property.
if (CExtensionUtils.clockSyncIsOn(federate, rtiConfig)) {
code.pr("synchronize_initial_physical_clock_with_rti(&_fed.socket_TCP_RTI);");
code.pr("synchronize_initial_physical_clock_with_rti(_fed.netdrv_to_rti);");
}

if (numberOfInboundConnections > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.lflang.target.property.ClockSyncOptionsProperty;
import org.lflang.target.property.ClockSyncOptionsProperty.ClockSyncOptions;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CommunicationTypeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.CoordinationOptionsProperty;
import org.lflang.target.property.CoordinationProperty;
Expand Down Expand Up @@ -201,6 +202,10 @@ public static void handleCompileDefinitions(
if (federate.targetConfig.get(AuthProperty.INSTANCE)) {
definitions.put("FEDERATED_AUTHENTICATED", "");
}
if (federate.targetConfig.isSet(CommunicationTypeProperty.INSTANCE)) {
definitions.put(
"COMM_TYPE", federate.targetConfig.get(CommunicationTypeProperty.INSTANCE).toString());
}
definitions.put("NUMBER_OF_FEDERATES", String.valueOf(federateNames.size()));
definitions.put("EXECUTABLE_PREAMBLE", "");
definitions.put("FEDERATE_ID", String.valueOf(federate.id));
Expand Down Expand Up @@ -342,7 +347,7 @@ public static String generateFederateNeighborStructure(FederateInstance federate
"* information is needed for the RTI to perform the centralized coordination.",
"* @see MSG_TYPE_NEIGHBOR_STRUCTURE in net_common.h",
"*/",
"void lf_send_neighbor_structure_to_RTI(int rti_socket) {"));
"void lf_send_neighbor_structure_to_RTI(netdrv_t *netdrv) {"));
code.indent();
// Initialize the array of information about the federate's immediate upstream
// and downstream relayed (through the RTI) logical connections, to send to the
Expand Down Expand Up @@ -444,8 +449,8 @@ public static String generateFederateNeighborStructure(FederateInstance federate
code.pr(
String.join(
"\n",
"write_to_socket_fail_on_error(",
" &rti_socket, ",
"write_to_netdrv_fail_on_error(",
" netdrv, ",
" buffer_size,",
" buffer_to_send,",
" NULL,",
Expand Down Expand Up @@ -525,6 +530,20 @@ public static String surroundWithIfFederatedDecentralized(String code) {
.formatted(code);
}

// /**
// * Surround {@code code} with blocks to ensure that code only executes if the program is
// federated
// * and has a decentralized coordination.
// */
// public static String surroundWithIfOpenSSLRequired(String code) {
// return """
// #ifdef OPENSSL_REQUIRED
// %s
// #endif // OPENSSL_REQUIRED
// """
// .formatted(code);
// }

/** Generate preamble code needed for enabled serializers of the federate. */
public static String generateSerializationIncludes(FederateInstance federate) {
CodeBuilder code = new CodeBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.lflang.lf.VarRef;
import org.lflang.target.Target;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.CommunicationTypeProperty;
import org.lflang.target.property.CoordinationProperty;
import org.lflang.target.property.DockerProperty;
import org.lflang.target.property.DockerProperty.DockerOptions;
Expand Down Expand Up @@ -159,6 +160,15 @@ public boolean doGenerate(Resource resource, LFGeneratorContext context) throws
// for logical connections.
replaceFederateConnectionsWithProxies(federation, main, resource);

// Generate Credentials for SST.
if (context
.getTargetConfig()
.get(CommunicationTypeProperty.INSTANCE)
.toString()
.equals("SST")) {
SSTGenerator.setupSST(fileConfig, federates, messageReporter, context);
}

FedEmitter fedEmitter =
new FedEmitter(
fileConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* @author Soroush Bateni
*/
public class FederateInstance {

// TODO: DONGHA: Need to take out network related things.
/**
* Construct a new federate instance on the basis of an instantiation in the federated reactor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ public Path getFedBinPath() {
return getFedGenPath().resolve("bin");
}

public Path getSSTPath() {
return getGenPath().resolve("sst");
}

public Path getSSTConfigPath() {
return getSSTPath().resolve("configs");
}

public Path getSSTCredentialsPath() {
return getSSTPath().resolve("credentials");
}

public Path getSSTGraphsPath() {
return getSSTPath().resolve("graphs");
}

public Path getSSTAuthPath() {
return getSSTPath().resolve("auth");
}

@Override
public void doClean() throws IOException {
super.doClean();
Expand Down
Loading