Skip to content

Commit f5cd92b

Browse files
Add RIOT federated CoAP TEST (#189)
* WIP * WIP * Use tmux * Fix * Create tap interfaces * Add env variables * Read out termination code and print to tmp * Switch to static ipv6 addresses for the riot coap example * Remove ip from build.sh * Cleanup and migrate test to static ip * msg_t -> lf_msg_t * Finish test * Add tmux * Fix ci * Fix CI * Fix * Remove tmux * Add tapsetup * Add sudo * Fix * Make riotbuild container priviliged * Test * Fix * Improve description * msg_t -> lf_msg_t * Move ip configuration to makefile * Cleanup makefiles --------- Co-authored-by: erlingrj <erling.jellum@gmail.com>
1 parent 56bef5b commit f5cd92b

File tree

14 files changed

+407
-176
lines changed

14 files changed

+407
-176
lines changed

.github/actions/riot/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ runs:
1717
cd ${{env.RIOTBASE}}
1818
git checkout ${{env.RIOT_COMMIT_ID}}
1919
shell: bash
20+
21+
- name: Setup tap interfaces
22+
run: |
23+
apt update
24+
apt install -y --no-install-recommends iproute2 sudo
25+
sudo $RIOTBASE/dist/tools/tapsetup/tapsetup
26+
ip a
27+
shell: bash

.github/workflows/riot.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
runs-on: ubuntu-24.04
1010
container:
1111
image: riot/riotbuild:latest
12+
options: --privileged
1213
env:
1314
RIOT_COMMIT_ID: "cb5500b4b7600d95f42a3070abae402be4f63845"
1415
RIOTBASE: "/opt/riot-cb5500b4b7600d95f42a3070abae402be4f63845"
@@ -25,10 +26,10 @@ jobs:
2526
- name: Install LFC dependencies
2627
uses: ./.github/actions/lingua-franca
2728

28-
- name: Build examples
29-
working-directory: ${{ github.workspace }}/examples/riot
30-
run: ./buildAll.sh
31-
3229
- name: Run platform tests
3330
working-directory: ${{ github.workspace }}/test/platform/riot
3431
run: ./runAll.sh
32+
33+
- name: Build examples
34+
working-directory: ${{ github.workspace }}/examples/riot
35+
run: ./buildAll.sh

examples/riot/README.md

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,62 +35,20 @@ First you need to create the `tap` interfaces so that the `sender` and `receiver
3535
sudo $RIOTBASE/dist/tools/tapsetup/tapsetup
3636
```
3737

38-
#### Get IPv6 address of receiver
38+
#### Start the Sender
3939

40-
Enter the directory of the `sender` application:
41-
42-
```shell
43-
cd coap_federated/sender
44-
```
45-
46-
Get the IP address of the `receiver` by specifying the `PORT=tap1` and `ONLY_PRINT_IP=1` environment variables:
47-
48-
*If the program returns more than one IP-Address then select the one that starts with `fe80`*.
49-
50-
```shell
51-
make ONLY_PRINT_IP=1 BOARD=native PORT=tap1 all term
52-
```
53-
54-
The resulting program will print out the IPv6 address of `tap1` and terminate.
55-
This address must be used when starting the sender below.
56-
57-
58-
#### Get IPv6 address of sender
59-
60-
Enter the directory of the `receiver` application:
61-
62-
```shell
63-
cd coap_federated/receiver
64-
```
65-
66-
Get the IP address of the `sender` by specifying the `PORT=tap0` and `ONLY_PRINT_IP=1` environment variables:
67-
68-
*If the program returns more than one IP-Address then select the one that starts with `fe80`*.
69-
70-
```shell
71-
make ONLY_PRINT_IP=1 BOARD=native PORT=tap0 all term
72-
```
73-
74-
The resulting program will print out the IPv6 address of `tap0` and terminate.
75-
This address must be used when starting the receiver below.
76-
77-
#### Start the applications
78-
79-
##### Sender
80-
Start the sender with `PORT=tap0`, make sure to replace `REMOTE_ADDRESS` with
81-
the address of `tap1` that you found above.
40+
Start the sender with `PORT=tap0`:
8241

8342
```shell
8443
cd sender
85-
make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term
44+
make BOARD=native PORT=tap0 all term
8645
```
8746

88-
##### Receiver
47+
#### Start the Receiver
8948

90-
Start the receiver with `PORT=tap1`, make sure to replace `REMOTE_ADDRESS` with
91-
the address of `tap0` that you found above.
49+
Start the receiver with `PORT=tap1`:
9250

9351
```shell
9452
cd receiver
95-
make REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 BOARD=native PORT=tap1 all term
53+
make BOARD=native PORT=tap1 all term
9654
```

examples/riot/coap_federated/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/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
2+
make all -C ./sender
3+
make all -C ./receiver

examples/riot/coap_federated/receiver/Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1
2929
CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400
3030
CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4
3131

32-
# Check if ONLY_PRINT_IP is defined
33-
# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed
34-
ifdef ONLY_PRINT_IP
35-
# ONLY_PRINT_IP is defined => Set CFLAGS for it
36-
CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP)
37-
else ifdef REMOTE_ADDRESS
38-
# REMOTE_ADDRESS is defined => Set CFLAGS for it
39-
CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\"
40-
else
41-
# Neither is defined
42-
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device.)
43-
endif
32+
# Local IPv6 address
33+
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR='"fe80::cafe:cafe:cafe:2"'
34+
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED=1
35+
36+
# Remote Ipv6 address
37+
CFLAGS += -DREMOTE_IP_ADDRESS='"fe80::cafe:cafe:cafe:1"'
4438

4539
include $(CURDIR)/../../../../make/riot/riot.mk

examples/riot/coap_federated/receiver/main.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
22
#include "reactor-uc/reactor-uc.h"
33

4-
#ifndef REMOTE_ADDRESS
5-
#define REMOTE_ADDRESS "fe80::44e5:1bff:fee4:dac8"
6-
#endif
7-
84
#define REMOTE_PROTOCOL_FAMILY AF_INET6
95

106
typedef struct {
@@ -53,8 +49,8 @@ LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_ex
5349
LF_PORT_REGISTER_EFFECT(self->in, self->r, 1);
5450
}
5551

56-
LF_DEFINE_FEDERATED_INPUT_CONNECTION_STRUCT(Receiver, in, msg_t, 5);
57-
LF_DEFINE_FEDERATED_INPUT_CONNECTION_CTOR(Receiver, in, msg_t, 5, MSEC(100), false);
52+
LF_DEFINE_FEDERATED_INPUT_CONNECTION_STRUCT(Receiver, in, lf_msg_t, 5);
53+
LF_DEFINE_FEDERATED_INPUT_CONNECTION_CTOR(Receiver, in, lf_msg_t, 5, MSEC(100), false);
5854

5955
typedef struct {
6056
FederatedConnectionBundle super;
@@ -65,7 +61,7 @@ typedef struct {
6561

6662
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) {
6763
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE();
68-
CoapUdpIpChannel_ctor(&self->channel, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY);
64+
CoapUdpIpChannel_ctor(&self->channel, REMOTE_IP_ADDRESS, REMOTE_PROTOCOL_FAMILY);
6965
LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR();
7066
LF_INITIALIZE_FEDERATED_INPUT_CONNECTION(Receiver, in, deserialize_msg_t);
7167
}
@@ -89,30 +85,7 @@ LF_REACTOR_CTOR_SIGNATURE(MainRecv) {
8985

9086
LF_ENTRY_POINT_FEDERATED(MainRecv, SEC(1), true, true, 1, false)
9187

92-
void print_ip_addresses(void) {
93-
gnrc_netif_t *netif = gnrc_netif_iter(NULL);
94-
char addr_str[IPV6_ADDR_MAX_STR_LEN];
95-
96-
while (netif) {
97-
size_t max_addr_count = 4;
98-
ipv6_addr_t addrs[max_addr_count];
99-
gnrc_netif_ipv6_addrs_get(netif, addrs, max_addr_count * sizeof(ipv6_addr_t));
100-
101-
for (size_t i = 0; i < 2; i++) {
102-
if (ipv6_addr_to_str(addr_str, &addrs[i], sizeof(addr_str))) {
103-
LF_INFO(NET, "IPv6 address: %s", addr_str);
104-
}
105-
}
106-
107-
netif = gnrc_netif_iter(netif);
108-
}
109-
}
110-
11188
int main() {
112-
#ifdef ONLY_PRINT_IP
113-
print_ip_addresses();
114-
#else
11589
lf_start();
116-
#endif
11790
return 0;
11891
}

examples/riot/coap_federated/sender/Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1
2929
CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400
3030
CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4
3131

32-
# Check if ONLY_PRINT_IP is defined
33-
# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed
34-
ifdef ONLY_PRINT_IP
35-
# ONLY_PRINT_IP is defined => Set CFLAGS for it
36-
CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP)
37-
else ifdef REMOTE_ADDRESS
38-
# REMOTE_ADDRESS is defined => Set CFLAGS for it
39-
CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\"
40-
else
41-
# Neither is defined
42-
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device)
43-
endif
32+
# Local IPv6 address
33+
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR='"fe80::cafe:cafe:cafe:1"'
34+
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED=1
35+
36+
# Remote Ipv6 address
37+
CFLAGS += -DREMOTE_IP_ADDRESS='"fe80::cafe:cafe:cafe:2"'
4438

4539
include $(CURDIR)/../../../../make/riot/riot.mk

examples/riot/coap_federated/sender/main.c

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#include "reactor-uc/reactor-uc.h"
22
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"
33

4-
#ifndef REMOTE_ADDRESS
5-
#define REMOTE_ADDRESS "fe80::8cc3:33ff:febb:1b3"
6-
#endif
7-
84
#define REMOTE_PROTOCOL_FAMILY AF_INET6
95

106
typedef struct {
@@ -60,8 +56,8 @@ LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_ex
6056
LF_PORT_REGISTER_SOURCE(self->out, self->r, 1);
6157
}
6258

63-
LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_STRUCT(Sender, out, msg_t)
64-
LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_CTOR(Sender, out, msg_t)
59+
LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_STRUCT(Sender, out, lf_msg_t)
60+
LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_CTOR(Sender, out, lf_msg_t)
6561

6662
typedef struct {
6763
FederatedConnectionBundle super;
@@ -72,7 +68,7 @@ typedef struct {
7268

7369
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Sender, Receiver) {
7470
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE();
75-
CoapUdpIpChannel_ctor(&self->channel, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY);
71+
CoapUdpIpChannel_ctor(&self->channel, REMOTE_IP_ADDRESS, REMOTE_PROTOCOL_FAMILY);
7672
LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR();
7773
LF_INITIALIZE_FEDERATED_OUTPUT_CONNECTION(Sender, out, serialize_msg_t);
7874
}
@@ -99,30 +95,7 @@ LF_REACTOR_CTOR_SIGNATURE(MainSender) {
9995

10096
LF_ENTRY_POINT_FEDERATED(MainSender, SEC(1), true, false, 1, true)
10197

102-
void print_ip_addresses(void) {
103-
gnrc_netif_t *netif = gnrc_netif_iter(NULL);
104-
char addr_str[IPV6_ADDR_MAX_STR_LEN];
105-
106-
while (netif) {
107-
size_t max_addr_count = 4;
108-
ipv6_addr_t addrs[max_addr_count];
109-
gnrc_netif_ipv6_addrs_get(netif, addrs, max_addr_count * sizeof(ipv6_addr_t));
110-
111-
for (size_t i = 0; i < 2; i++) {
112-
if (ipv6_addr_to_str(addr_str, &addrs[i], sizeof(addr_str))) {
113-
LF_INFO(NET, "IPv6 address: %s", addr_str);
114-
}
115-
}
116-
117-
netif = gnrc_netif_iter(netif);
118-
}
119-
}
120-
12198
int main() {
122-
#ifdef ONLY_PRINT_IP
123-
print_ip_addresses();
124-
#else
12599
lf_start();
126-
#endif
127100
return 0;
128101
}
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
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)
2+
platform: RIOT,
3+
timeout: 1sec
4+
}
355

36-
@interface_coap(name="if1", address="fe80::8cc3:33ff:febb:1b3")
37-
r2 = new Dst()
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+
}
3813

39-
@link(left="if1", right="if1")
40-
r1.out -> r2.in
41-
}
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+
}

0 commit comments

Comments
 (0)