liberps

Get started

Build, test, simulate, embed

liberps has no dependencies beyond a C11 compiler and GNU make. Python 3 is used only by the coverage summary and the Linux end-to-end test.

Build

make                      # liberps.a, liberps.so, erps-sim, erpsd + erpsctl (Linux), examples
make CC=clang             # each compiler / sanitizer mix builds into its own build/<cc>... directory
make install PREFIX=/usr/local   # headers, liberps.a/.so, liberps-sim.a, pkg-config file

Outputs land in build/<compiler>[-<sanitizers>]/. The shared library exports only the public erps_* API. V=1 shows the full compiler command lines.

Test

make test                 # unit + scenario + chaos (300 random rings)
make check                # gcc and clang, each plain and with ASan + UBSan
make cov                  # gcc --coverage, per-file line coverage of the core
make fuzz FUZZ_SECONDS=60 # clang libFuzzer targets
make e2e                  # Linux: four erpsd on kernel bridges, no root needed
ERPS_CHAOS_SEEDS=100000 build/gcc/test-chaos   # deeper property testing

Run one test by name: build/gcc/test-unit -v row20. Scenario tests print every simulator event with ERPS_TEST_LOG=4, and a chaos failure prints the command that replays it.

Run the simulator

The simulator shell builds a ring of any size on a virtual clock, so a five-minute WTR passes instantly. Rings are named n0…n<N-1>; link i joins node i port 1 and node i+1 port 0, and by default the last node owns the RPL.

$ build/cc/erps-sim
erps-sim> sim create 5
ring of 5 nodes, RPL = link 4 (owner n4, neighbour n0), revertive
erps-sim> run 6m
[  300.000000] n4 Pending -> Idle (row 66, WTR-expires)
[  300.000050] n3 Pending -> Idle (row 70, R-APS(NR,RB))
...
erps-sim> link 2 down
erps-sim> run 1s
[  360.001000] n2 port 1 signal fail declared
[  360.001000] n2 port 1 blocked
[  360.001000] n2 Idle -> Protection (row 5, local-SF)
[  360.001000] n3 Idle -> Protection (row 5, local-SF)
[  360.001050] n4 port 1 unblocked
[  360.001050] n4 Idle -> Protection (row 7, R-APS(SF))
...
erps-sim> show
t=361.000000 n0:B[--] n1:B[--] n2:B[-B] n3:B[B-] n4:B[--] links-down 2:x
erps-sim> show erps ring n4 history
erps-sim> pcap ring.pcap          # Wireshark decodes R-APS

Two scripts ship in examples/: appendix3.erps replays Appendix III scenario A, and tour.erps covers manual switch, forced switch, an RPL failure and a node failure. Scripts can assert with expect state, expect blocked and expect no-loops, and the shell exits non-zero when one fails.

Embed the library

A platform implements three callbacks and feeds three kinds of input. examples/two_nodes.c is a complete, runnable integration in about 200 lines.

#include <erps/erps.h>

static int my_tx(void *user, erps_port_t port, const uint8_t *frame, size_t len);
static int my_block(void *user, erps_port_t port, unsigned block_mask);
static int my_flush(void *user);

static const erps_ops_t ops = { .tx = my_tx, .set_port_state = my_block, .flush_fdb = my_flush };

erps_config_t cfg;
erps_config_init(&cfg);
cfg.raps_vid = 100;
memcpy(cfg.node_id, system_mac, 6);
cfg.role = ERPS_ROLE_RPL_OWNER;
cfg.rpl_port = ERPS_PORT1;

erps_t *e;
if (erps_create(&cfg, &ops, my_ctx, &e) != ERPS_OK) { ... }
erps_start(e, now_us());

/* event loop */
erps_rx_frame(e, port, frame, len, now_us());
erps_set_signal_fail(e, port, link_is_down, now_us());
if (now_us() >= erps_next_deadline(e))
    erps_poll(e, now_us());

Link with pkg-config --cflags --libs erps after make install. The C API reference covers the contract of each call.

Run it on Linux

ip link add name br0 type bridge vlan_filtering 1
ip link set eth1 master br0; ip link set eth2 master br0
bridge vlan add dev eth1 vid 10; bridge vlan add dev eth2 vid 10

cat > /etc/erpsd.conf <<'EOF'
erps ring R1 ring-id 1 raps-vid 100 port0 eth1 port1 eth2
erps ring R1 node-id 02:00:00:00:00:01
erps ring R1 protected-vlans 10
erps ring R1 role owner rpl-port 1
erps ring R1 enable
EOF

erpsd -c /etc/erpsd.conf &
erpsctl show erps
erpsctl show erps ring R1 detail json

Keep the R-APS VLAN off the bridge: erpsd receives and forwards R-APS itself. Details are on the Linux page.

Repository layout

PathContents
include/erps/erps.h core API, erps_pdu.h R-APS codec, erps_mgr.h instance manager, erps_cli.h command layer, erps_sim.h simulator
src/core/fsm.c (Table 10-2), priority.c, tx.c, flush.c, fop.c, erps.c, trace.c, pdu.c, mgr.c, config.c
src/cli/Command layer
src/platform/sim/ discrete-event ring simulator, linux/ AF_PACKET and bridge netlink platform
apps/erps-sim, erpsd, erpsctl
tests/unit/, scenario/, chaos/, fuzz/, linux/
docs/This site, plus Markdown references (API, design, conformance, Linux) and the G.8032 implementation notes