Skip to content

Commit 5144e03

Browse files
LFC federated RIOT fixes (#192)
* Have LFC generate a main function that can optionally be included in the build * CI * CI * CI * Setup LFC in RIOT container * Switch to riot master * Fix * Install LFC deps in zephyr CI also * WIP * WIP * WIP: SimpleFederated.lf now compiles. But invoking CMake correctly to generate two binaries and a shell script in `bin` is not working * Generate a launch script for federated native * Make federated launch script executable * WIP * Rework the handling of connections * Various fixes to get all standalone tests to pass again * Formatting * More WIP * Formatting * More WIP * Add @interface attr * More WIP * More WIP * More WIP * All tests are passing * Refactor * Formatting * Refactorings * More docs * CI * Fixes * TcpIp fixes * Revert more tcp stuff * Avoid flooding log when a federate closes a socket * Remove merge mistake * Formatting * Fix posix federated * More minor fixes * Format * Minimum event queue of 2 * Remove some dead code * Also close send_failed socketpair on reset * Generate return 0 in main function * Only generate launch script when we target native * Set timeout of 1minute on our LF tests * Add some info prints * Add was_ever_connected API to network_channel * Fix some warnings in unit-tests * Avoid some unnecessary LF_INFO calls * Do not timestamp logs for FlexPRET * Format * Make RIOT compile * Fix makefile and missing comma * Remove build.sh in riot Lf example * Use global _lf_environment * Fix missing _lf_environment in test * Dont need environment arg to TcpIp and CoapUdp ctors * Coap updates * Remove stale ref * Fix APPLICATION name * Fix make clean * Add all riot examples to the CI again * Fix hello_lf example make clean command not working * Rename FEDERATION -> FEDERATE * Make build scripts more realistic --------- Co-authored-by: erlingrj <[email protected]>
1 parent c592b89 commit 5144e03

File tree

12 files changed

+148
-40
lines changed

12 files changed

+148
-40
lines changed

examples/riot/blinky/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
make all

examples/riot/buildAll.sh

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22

33
set -e
44

5-
# List of folders
6-
FOLDERS=("blinky" "hello" "hello_lf")
7-
8-
# List of boards
9-
BOARDS=("native" "nucleo-f429zi")
10-
11-
# Iterate over each board
12-
for board in "${BOARDS[@]}"; do
13-
# Command to execute in each folder
14-
COMMAND="make BOARD=$board all"
15-
16-
# Iterate over each folder and execute the command
17-
for dir in "${FOLDERS[@]}"; do
18-
echo "Entering $dir"
19-
pushd $dir
20-
$COMMAND
21-
popd
22-
done
5+
# Iterate over each folder and execute the command
6+
for dir in ./*; do
7+
if [ -d $dir ]; then
8+
echo "Entering $dir"
9+
pushd $dir
10+
./build.sh
11+
popd
12+
fi
2313
done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 make all -C ./sender
3+
REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 make all -C ./receiver
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
REACTOR_UC_PATH ?= $(CURDIR)/../../../
2+
3+
# The name of the LF application inside "./src" to build/run/flash etc.
4+
LF_MAIN ?= CoapFederatedLF
5+
FEDERATE ?= r1
6+
7+
# Execute the LF compiler if build target is "all"
8+
ifeq ($(firstword $(MAKECMDGOALS)),all)
9+
_ := $(shell $(REACTOR_UC_PATH)/lfc/bin/lfc-dev src/$(LF_MAIN).lf)
10+
endif
11+
12+
# ---- RIOT specific configuration ----
13+
# This has to be the absolute path to the RIOT base directory:
14+
RIOTBASE ?= $(CURDIR)/../../../../RIOT
15+
16+
# If no BOARD is found in the environment, use this default:
17+
BOARD ?= native
18+
19+
# Comment this out to disable code in RIOT that does safety checking
20+
# which is not needed in a production environment but helps in the
21+
# development process:
22+
DEVELHELP ?= 1
23+
24+
# Change this to 0 show compiler invocation lines by default:
25+
QUIET ?= 1
26+
27+
# Enable reactor-uc features
28+
CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT
29+
30+
# Configure CoAP retransmission timeout
31+
CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1
32+
CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400
33+
CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4
34+
35+
include $(REACTOR_UC_PATH)/make/riot/riot-lfc.mk
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
FEDERATE=r1 PORT=tap0 make all
3+
FEDERATE=r2 PORT=tap1 make all
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
target uC {
2+
platform: RIOT,
3+
timeout: 1sec
4+
}
5+
6+
reactor Src(id: int = 0) {
7+
output out: int
8+
reaction(startup) -> out{=
9+
printf("Hello from Src!\n");
10+
lf_set(out, self->id);
11+
=}
12+
}
13+
14+
reactor Dst {
15+
input in: int
16+
state check: bool = false
17+
reaction(startup) {=
18+
printf("Hello from Dst!\n");
19+
=}
20+
reaction(in) {=
21+
printf("Received %d from Src\n", in->value);
22+
validate(in->value == 42);
23+
self->check = true;
24+
env->request_shutdown(env);
25+
=}
26+
27+
reaction(shutdown) {=
28+
validate(self->check);
29+
=}
30+
}
31+
32+
federated reactor {
33+
@interface_coap(name="if1", address="fe80::44e5:1bff:fee4:dac8")
34+
r1 = new Src(id=42)
35+
36+
@interface_coap(name="if1", address="fe80::8cc3:33ff:febb:1b3")
37+
r2 = new Dst()
38+
39+
@link(left="if1", right="if1")
40+
r1.out -> r2.in
41+
}

examples/riot/hello/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
make all

examples/riot/hello_lf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LF_MAIN ?= HelloLF
88
# CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT
99

1010
# Execute the LF compiler if build target is "all"
11-
ifeq ($(MAKECMDGOALS),all)
11+
ifeq ($(firstword $(MAKECMDGOALS)),all)
1212
_ := $(shell $(REACTOR_UC_PATH)/lfc/bin/lfc-dev src/$(LF_MAIN).lf)
1313
endif
1414

examples/riot/hello_lf/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
make all

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcIpAddress.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import org.lflang.AttributeUtils.getInterfaceAttributes
44
import org.lflang.lf.Attribute
55
import java.math.BigInteger
66
import java.util.concurrent.atomic.AtomicInteger
7+
import java.net.InetAddress
8+
import java.net.UnknownHostException
79

810

911
/** A class representing an IPAddress, either v4 or v6. */
@@ -22,10 +24,12 @@ sealed class IPAddress {
2224
}
2325

2426
companion object {
25-
fun isValidIPv4(address: String): Boolean {
26-
val regex = Regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}$")
27-
return regex.matches(address) &&
28-
address.split(".").all { it.toIntOrNull() in 0..255 }
27+
fun isValidIPv4(ip: String): Boolean {
28+
return try {
29+
InetAddress.getByName(ip) is java.net.Inet4Address
30+
} catch (e: UnknownHostException) {
31+
false
32+
}
2933
}
3034
}
3135
}
@@ -36,9 +40,12 @@ sealed class IPAddress {
3640
}
3741

3842
companion object {
39-
fun isValidIPv6(address: String): Boolean {
40-
val regex = Regex("(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})|(::)")
41-
return regex.matches(address)
43+
fun isValidIPv6(ip: String): Boolean {
44+
return try {
45+
InetAddress.getByName(ip) is java.net.Inet6Address
46+
} catch (e: UnknownHostException) {
47+
false
48+
}
4249
}
4350
}
4451
}

0 commit comments

Comments
 (0)