liberps

C API

C API reference

The headers in include/erps/ are the reference; this page explains how the pieces fit. All functions return erps_err_t (0 on success) unless noted.

Contract

Lifecycle

FunctionPurpose
erps_config_init(&cfg)Fill a configuration with G.8032 defaults. You must still set node_id and raps_vid.
erps_config_validate(&cfg, why, len)Check ranges and consistency; writes a readable reason on error.
erps_create(&cfg, &ops, user, &e)Allocate and initialise an instance (not started).
erps_init_static(mem, len, &cfg, &ops, user, &e)Same in caller-provided memory of at least erps_instance_size() bytes.
erps_start(e, now)Table 10-2 row 1: program both ports, start transmitting R-APS(NR).
erps_stop(e, now, block_ports)Stop transmission and timers; with block_ports, block both ring ports first. Returns ERPS_E_PLATFORM if a block was not confirmed.
erps_destroy(e)Release the instance. Does not touch the dataplane.
erps_set_timers(e, wtr, guard, holdoff)Change timers at run time, validated.
erps_set_revertive(e, on)Change the mode at run time. Going non-revertive cancels a running WTR or WTB.
erps_set_log_level(e, level)Per-instance log level. At ERPS_LOG_DEBUG every executed row is logged.

Configuration

Timer ranges are enforced unless relaxed_timers is set, which accepts lab values such as a 10-second WTR.

FieldDefaultRange and meaning
name"erps"Instance name in logs, traces and the command layer
ring_id11–239; last octet of the R-APS destination 01-19-A7-00-00-xx (§10.1.1)
raps_vid— (required)1–4094; the dedicated R-APS VLAN (§9.5)
mel70–7; ring MEG level
node_id[6]— (required)A unicast MAC unique to the node; also the default source MAC
port[2]handles 0, 1handle (platform port id, used by the manager), name, mac (source MAC; all-zero uses node_id)
role, rpl_portnone, 0ERPS_ROLE_NONE, _RPL_OWNER or _RPL_NEIGHBOUR, and which port is on the RPL
revertivetrueRevertive operation (§9.1). Forced on by compatible-version 1
compat_version21 filters FS and MS and forces revertive, for rings with 2008-only nodes (§10.1.13)
wtr_ms3000001–12 min in whole minutes (§10.1.4)
guard_ms50010–2000 ms in 10 ms steps (§10.1.5). WTB is always guard + 5 s
holdoff_ms00–10 s in 100 ms steps (§10.1.8)
init_wtbfalseOwner starts WTB instead of WTR at initialisation (Appendix VIII, Table VIII.1); see interpretation 14
relaxed_timersfalseAccept out-of-range timers and Tx timing
raps_pcp7802.1Q priority of transmitted R-APS
tx_versionautoOAM Version field; auto sends 0 with compatible-version 1 and 1 otherwise
tx_interval_ms, tx_burst_us5000, 3333Continuous transmission period and burst spacing (§10.1.3)
sw_raps_forwardingfalseThe instance forwards R-APS between its ring ports (software R-APS_FF)
fop_pm_enabletrueFOP-PM at the RPL owner (§10.4)
fop_to_enable, fop_timeout_msfalse, 17500Per-port R-APS receive watchdog; the timeout also clears FOP-PM
history_depth128Transitions kept, up to ERPS_HISTORY_MAX
log_levelnoticeERPS_LOG_ERR … ERPS_LOG_TRACE

Platform callbacks

CallbackCalled whenThe platform must
tx(user, port, frame, len)The instance transmits R-APSSend the complete tagged frame (no FCS) on that ring port. Locally generated R-APS goes out on both ports even when one is blocked or failed (§9.5, §10.1.3).
set_port_state(user, port, mask)A ring port is blocked or unblockedmask is ERPS_BLOCK_TRAFFIC | ERPS_BLOCK_RAPS or 0. Remove or restore the instance's protected VIDs on the port, and stop or allow forwarding of the R-APS VID through it. Return non-zero if the hardware refused; the call is retried every 100 ms and no new R-APS information is sent until it succeeds.
flush_fdb(user)The topology changedFlush MACs learned on both ring ports, for this instance's VIDs only (§9.6). A failure is retried.
notify(user, event)OptionalReceive state changes (with the row), port changes, flushes, FOP-PM / FOP-TO raise and clear, rejected commands, signal-fail changes and platform errors.
log(user, level, msg)OptionalWrite a log line (no trailing newline).

Inputs and time

FunctionPurpose
erps_rx_frame(e, port, frame, len, now)A received frame with its 802.1Q tag. Returns ERPS_OK if accepted as an R-APS for this instance, ERPS_E_DROPPED if the validity check discarded it (reason counted).
erps_rx_pdu(e, port, &meta, pdu, len, now)The same for platforms that strip the Ethernet header or tag: meta carries destination, source, VID and PCP.
erps_set_signal_fail(e, port, ssf, now)Ring-port signal fail (carrier, CCM). SF is declared after the hold-off time if still present; clearing is immediate.
erps_command(e, cmd, port, now, &why)ERPS_CMD_FORCED_SWITCH, _MANUAL_SWITCH (with a port) or _CLEAR. Returns ERPS_E_REJECTED with an erps_reject_t when the local priority logic refuses it.
erps_poll(e, now)Fire due timers and transmissions, in deadline order.
erps_next_deadline(e)The time by which erps_poll() must be called, or ERPS_TIME_NEVER.
erps_send_flush_event(e, now)Send a burst of three R-APS Event (flush) messages, for diagnostics and interop tests.

Command rejections: COMPAT_V1 (FS or MS in compatible-version 1), FS_ACTIVE (a local FS exists), HIGHER_PRIORITY (local SF or FS outranks an MS), MS_IN_RING (an MS, FS or SF already exists in the ring), CLEAR_NOT_APPLICABLE, NOT_RUNNING.

Introspection

erps_status_t st;   erps_get_status(e, &st);     /* state, ports, top request, timers, Tx message, FOP */
erps_counters_t c;  erps_get_counters(e, &c);    /* per port and kind Rx/Tx, drops by reason, flushes  */
erps_trace_t h[32]; size_t n = erps_get_history(e, h, 32);   /* oldest first */
uint8_t rows[9];    erps_get_row_coverage(e, rows);  /* bit r = Table 10-2 row r has run */

int need = erps_dump(e, ERPS_DUMP_ALL, ERPS_FMT_JSON, NULL, 0);   /* snprintf semantics */
char line[256];     erps_trace_format(&h[0], line, sizeof line);

A history entry records the time, the triggering request (R-APS node ID, BPR and receiving port), the state transition, the Table 10-2 row, the actions in order and the port states before and after:

#4 t=301.001050 A->B row 7 R-APS(SF) 02:00:00:00:00:03 bpr0 @p0 [unblock-p1 stop-tx] ports -B->--

Every enum has a name function (erps_state_str, erps_req_type_str, erps_drop_str, erps_reject_str, erps_strerror, …) and messages and requests have formatters (erps_raps_msg_format, erps_req_format).

Several instances: erps_mgr

A node usually runs several ERP instances on the same ring ports, each with its own R-APS VID and VLAN set. The manager owns them and does what an event loop needs:

erps_mgr_t *m = erps_mgr_create();
erps_mgr_add(m, &cfg, &ops, user, &e);           /* names unique; (ring ID, VID) unique per port */
erps_mgr_rx_frame(m, port_handle, frame, len, now); /* demultiplex by port, VID and ring ID */
erps_mgr_set_signal_fail(m, port_handle, ssf, now); /* fan out to every instance on the port */
erps_mgr_poll(m, now);
erps_time_t next = erps_mgr_next_deadline(m);

R-APS codec: erps_pdu.h

The codec the core uses is public, for adapters and tools: erps_eth_parse() (up to two VLAN tags), erps_pdu_decode() (length, opcode 40, TLV offset, request and event validity), erps_pdu_encode(), erps_frame_encode() (a tagged frame padded to 60 octets), erps_raps_dmac(), erps_msg_kind() and erps_node_id_cmp().

offset  field
0       DA 01-19-A7-00-00-<ring id>
6       SA
12      0x8100  PCP | DEI | VID (R-APS VID)
16      0x8902  Ethernet OAM
18      MEL(3) | Version(5)   OpCode 40   Flags 0   TLV offset 32
22      Request/State(4) | Sub-code(4)
23      Status: RB 0x80  DNF 0x40  BPR 0x20
24      Node ID (6 octets)
30      Reserved (24 octets)
54      End TLV
55      padding to 60 octets