iec61850-kit
IEC 61850 in Rust. Publishers and subscribers for the substation process bus, an MMS client and server for the station bus, panic-free decoders, sans-IO state machines, and encoders checked against real substation captures frame for frame.
📖 Documentation and guide · 📋 Changelog
Pre-1.0. The API changes between minor versions, and the crate has not been through a conformance laboratory — see Verification.
Features
| GOOSE (IEC 61850-8-1) | Codec, publisher with the T1…T0 retransmission curve, subscriber with the IEC 62351-6 replay rule and Edition 2 simulation-bit semantics |
| Sampled Values (IEC 61850-9-2) | Codec, template-patching publisher for the 9-2LE and IEC 61869-9 profiles, multi-stream subscriber tracking continuity, sync, grandmaster and staleness. Any engineered data set decodes: the SCL file gives each channel its name, type and offset |
| MMS (IEC 61850-8-1) | TPKT, COTP class 0 with TSDU reassembly, session, presentation, ACSE, the MMS PDUs, and the association state machine over all six in both roles — invoke tracking, segmentation, timeouts, orderly release, ACSE password, typed rejects |
| MMS client | Blocking, no runtime, no dependency. Connect (optionally from the SCD), Status, Identify, GetCapabilityList, paged browse, read and write, type discovery, data-set create and delete, reconnect with a Backoff |
| Arrays (IEC 61850-8-1 §7.3) | read("…/MHAI1.HA.phsAHar(2).cVal.mag.f") becomes one named variable plus an ISO 9506 alternate-access selection. SCL's count and FCDA/@ix are honoured; a selection the server cannot serve is refused |
| Reporting (IEC 61850-8-1 §17) | Configure and enable a control block, request a general interrogation, and receive decoded reports — per member its index, reference, value and reason. Reports larger than the negotiated PDU are segmented by the server and rejoined by the client |
| Files (IEC 61850-8-1 §23) | List, read, delete, and send with SetFile (off by default; size, quota and path checks, published only when complete). The server's sandboxed store is read in ranges |
| Logs (IEC 61850-7-2 §17) | Read the control block, then QueryLogByTime or QueryLogAfterEntry (resumes without a gap or a duplicate). Server-side entries live behind a LogStore trait — in memory, or in a redb file that survives a restart (log-redb) |
| Supervision (IEC 61850-7-4) | LGOS and LSVS: a subscriber's own state — live, ndsCom, arriving confRev, simulated — published into the logical node the SCL file declares |
| Service tracking (IEC 61850-7-2 §14) | Who enabled a control block, which client was refused with what, who queried a log. The file declares the tracking objects by cdc, the server fills them in, and a report control block carries them. All ten classes |
| Setting groups (IEC 61850-7-2 §11) | Read the SGCB, activate a group, or select ▸ write ▸ confirm ▸ release an edit in one call. The server serves each setting under SG and SE and expires an abandoned edit on ResvTms |
| Control (IEC 61850-7-2 §20) | All four models behind one execute, with origin, ctlNum, Check, Test, time-activated operate and Cancel. The model is read from the server unless stated; a refusal returns its AddCause |
| Server (IEC 61850-8-1) | An SCL file is the whole configuration — no generated model, no build step. Browse, read, write, type discovery, a report engine (BufTm, GI, integrity, buffered replay), all four control models behind an application hook, setting groups, a sandboxed file store, logs, and GOOSE/SV control blocks that publish when a client enables them. Optional ACSE password. Writes are limited by functional constraint, commands gated by Beh; the edition comes from the file. Pluggable wall clock; every queue bounded |
| SCL (IEC 61850-6) | Load an IED model from ICD/CID/SCD, resolve subscriptions from Inputs/ExtRef, validate engineering errors with stable diagnostic codes, and edit without reformatting: an untouched file is byte-identical, a rename moves every reference, every edit undoes exactly |
Live interfaces (feature net) |
GOOSE and SV on Linux (AF_PACKET, TPACKET_V3 ring, kernel/NIC timestamps, SO_TXTIME launch time) and macOS (BPF) through rawether, with a kernel filter on EtherType and destination |
ied |
sim, mu, sv monitor, goose sniff, mms sniff, goose publish, mms status/identify/browse/read/write/rcb/report/control/type/files/get/put/log/sg, pcap info, scl validate/show/subs/edit — capture files or --iface |
| Supporting | Panic-free BER codec, the IEC 61850 wire types, classic pcap reader and writer |
Not included: TLS (IEC 62351-3), the IEC 62351-6 authentication extension, routable GOOSE/SV (IEC TR 61850-90-5), unicast SV, and encoding fixed-length GOOSE (decoding it works).
Install
Dependencies are optional and per feature: roxmltree (scl), redb (log-redb) and
rawether (net). The library is #![forbid(unsafe_code)]; the raw-socket unsafe lives in
rawether. The MMS client and server are blocking and need no async runtime. Everything below
std builds no_std (with alloc), e.g. for thumbv7em-none-eabihf. MSRV 1.90.
Use it
Subscribe to a GOOSE stream — feed it frames and timer ticks, drain its events:
use MacAddr;
use ;
let mut sub = new;
for event in sub.feed
Every core takes inputs and the caller's now, yields outputs, and says when to call it again — no sockets, threads or clock reads. Subscribers can be configured from the SCD:
let subs = subscriptions?; // 50 Hz system
for s in &subs.goose
A sampled-value subscription carries the publisher's channel layout, so samples arrive decoded:
let mut sv = new;
sv.on_frame;
An MMS client — connect sets up the OSI layers, ACSE and MMS Initiate:
use ;
let mut c = connect?;
for ld in c.server_directory?
let w = c.read?; // one round trip, typed back
c.release?;
Reports come back decoded, according to the control block's OptFlds:
use ;
c.enable_rcb?;
while let Some = c.next_report?
Controls are one call for all four models; a refusal is an error carrying its AddCause:
use ;
use Dbpos;
c.control
.model // read it from the SCD, or ask the server
.origin
.check
.execute?; // Err(ControlRejected { add_cause })
Files, logs and setting groups:
for f in c.file_directory?
let lcb = c.read_lcb?; // where the log starts
let = lcb.oldest.expect;
let page = c.query_log_after_entry?;
c.edit_setting_group?;
Type discovery:
let oper = c.variable_type?;
assert_eq!;
A server, configured entirely by its SCL file:
use ;
let mut server = bind?;
server.on_control;
let updates = server.handle; // the application never locks
spawn;
server.run?;
ied sim serves every IED in an SCD, each on its own port; with --iface it also publishes the
GOOSE and SV a client enables. goose sniff and sv monitor run the library's own subscriber
state machines, over a capture or a live interface.
Examples
Each runs to completion with no device, no network and no arguments:
Verification
- Real captures: a two-IED SEL GOOSE capture and all 10,161 frames of a 9-2LE capture decode and re-encode byte for byte; a 165-packet MMS association decodes through all six OSI layers (653 of 656 encodings byte-identical — the rest are the peer's non-minimal lengths).
- Wireshark dissects every PDU this crate emits on both buses, asserted field by field.
- Three other stacks in both roles, in CI: libiec61850 (browse, read, types, all four
control models, arrays, reports, logs,
SetFile), IEC61850bean and csp0924's crates — and libiec61850's GOOSE and SV publishers and subscribers in both directions. Each peer is a container built from a pinned, checksummed release; Docker is the only prerequisite. - Loopback: client and server run against each other from an SCL file.
- Live interfaces: GOOSE and SV over a veth pair on a real Linux kernel, on both receive
paths, and the CLI pair
ied mu --iface→ied sv monitor --ifacewithout a gap. - Adversarial simulation of publisher and subscriber under loss, reordering, duplication, replay and partition, across 512 seeds in CI.
- Zero steady-state allocations, asserted by a counting allocator.
- Thirteen fuzz targets,
#![forbid(unsafe_code)], andunwrap/expect/panic/indexing denied by lint; every fuzzer crash is kept as a named regression test. - OpenSCD's SCL files load, every data-set member resolves, and every file round-trips through the editor byte for byte.
What this does not prove: Verification.
Develop
SIM_SEED=42
IEC standards are copyrighted and are not part of this repository.
scripts/fetch-references.sh fetches the freely available material — ITU-T recommendations,
RFCs, public standard previews, sample captures and OpenSCD test fixtures — into a local
reference corpus (IEC61850_REFERENCE chooses where). Tests that need it skip when it is
absent.
Licence
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
An independent implementation, not affiliated with or endorsed by the IEC.