ADR 0017: The IEC 61850 servers run on libiec61850 1.6.1 from the pyiec61850-ng wheel, called through its C interface
- Status: Accepted for the test job and
inprocuse. Decisions 4 and 6 are this project's readings of the design, and the code follows them. - Date: 2026-11-13
- SDD: 5, 8.5, 12.4; ADR 0003, 0004, 0012; requirements
ADC-IEC-001,-002,-003,-005
Context
Section 8.5 asks for one MMS server per protection relay, built from generated SCL, on libiec61850. ADR 0004 decided the licence position: the library is GPL-3.0, agentic-datacenter-iec61850 is GPL-3.0-or-later and is the only place the library is used. What was left open was how Python reaches the library, and whether that route works where the tests run.
What was checked
On 2026-11-13, on the development machine (macOS 14, arm64, Python 3.12) and in the reference image of the workflows (uv:python3.12-bookworm-slim, glibc 2.36, run as linux/arm64).
| Route | Version, date | Licence | Wheels | Result |
|---|---|---|---|---|
pyiec61850 on PyPI |
1.5.2a1, one upload, 2023-10-04 | none declared in its metadata; the library inside is GPL-3.0 | Linux x86_64, aarch64, i686; CPython 3.6 to 3.12 | Installs and imports in the reference image. libiec61850 1.5.2. Its module has no access handler for control blocks, data sets or files. Not maintained since the upload |
pyiec61850-ng on PyPI |
1.6.1.10, 2026-08-19; 24 releases since 1.6.0.0 | GPLv3 declared; carries Mbed TLS (Apache-2.0) | Linux x86_64 and aarch64 (manylinux 2.28), Windows x86_64; CPython 3.9 to 3.14. No macOS wheel, no source distribution | Installs and imports in the reference image. Carries libiec61850 1.6.1 as a shared object beside a SWIG module. Calls itself experimental |
| libiec61850 1.6.1 built from source | tag v1.6.1 |
GPL-3.0 | none; needs CMake and a C compiler, and SWIG for its own Python module | The C library builds on the macOS machine in about a minute with CMake 4.4 and Apple clang 15. SWIG is not installed there, so its Python module was not built |
iec61850 on PyPI |
0.16.0, 2026-11-01 | MIT or Apache-2.0 | Linux x86_64, Windows | Not libiec61850: a separate implementation in Rust that calls itself pre-alpha. Not evaluated further. It is mentioned because its licence would remove the question ADR 0004 answers; choosing it would be a change to the design document |
No route gives a working MMS server on macOS without a compiler.
A server and a client were then built on the pyiec61850-ng wheel in the reference image. Two things did not work through its SWIG module:
- It stops for good when a client and a server share a process. A SWIG call keeps the interpreter lock while it waits for the answer. The library delivers a report, and asks the server's handlers, from threads of its own, and those need the same lock. The first enabled report hung the process.
- It cannot refuse with an event. The handlers that refuse a write, a control-block change or a file request are C function pointers. The SWIG module has callback classes for reports and for control only.
Both go away when the C interface of the shared object in the wheel is called through ctypes from the standard library: a ctypes call releases the interpreter lock, and a Python function can be passed as a C function pointer. Everything this package needs is exported by that shared object, with one exception noted under decision 5.
Decision
- The library is
libiec618501.6.1 as carried bypyiec61850-ng, pinned>=1.6.1.10,<1.6.2and locked. The dependency has the markersys_platform == 'linux', souv sync --all-groupsstill works on macOS; there the package installs, generates SCL, and serves nothing. agentic_datacenter_iec61850.libraryis the only module that imports the wheel, and it calls the C interface throughctypes. It declares the argument and result types of the functions it uses, holds the numeric constants of version 1.6.1, and refuses to load a library that reports another version. The SWIG module is not called. A test compares every constant with the SWIG module of the installed wheel.- The server is built from the generated SCD.
agentic_datacenter_iec61850.sclwrites the SCD and one ICD per relay type fromagentic_datacenter_iec61850.model, and reads the SCD back;Iec61850Servercreates the library's data model attribute by attribute from what was read. The library's own configuration-file format and its code generator are not used. - Where the protocol tests run. They need the library, so:
- They run in the job
protocolof theintegrationworkflow (new), which installs--group iec61850in the reference image, fails if the library does not load, and runstests/protocol,tests/conformance/test_iec61850_denied_services.pyand the package's own tests. They also run in the jobwithout-remoraof the same workflow, which installs the same group and runs the whole suite. - They are skipped wherever the package or the library is absent: in the
prjobsconformance,traceability,propertyandunit(which install without the group), in the jobwithout-iec61850, and on macOS and Windows. - A developer on macOS can run them in the reference image through Docker, or against a library built from source by naming it in
ADC_LIBIEC61850. That variable is a convenience; no workflow sets it. [tool.agentic-datacenter] stageis still 5, so the traceability job does not yet requireADC-IEC-001to-003. When the stage is raised, that job has to install the group, or those requirements will count as unverified.- What the relay refuses, and what it can say about it. A refusal is the library's access error on the wire and a
net.device_violationevent from the server. The library decides how much the server learns:
| Attempt | Answer on the wire | Event |
|---|---|---|
Operate (Oper) on XCBR1.Pos or CSWI1.Pos |
access denied | yes, with client address |
Select with value (SBOw) |
object does not exist | no |
Write to configuration, description or setting data (CF, DC, SP) |
access denied | yes, with client address |
| Write to status or measurement data | access denied | no |
| Any write to the setting-group control block | access denied | yes, with client address |
| Create or delete a data set; change a report control block beyond enabling it | access denied | yes, with client address |
| File directory, read, write, delete, rename | access denied | yes, with the addresses of every client connected at that moment |
- Operate. The library refuses a status-only control object itself and tells the server nothing. To learn of the attempt, each control object is registered inside the library as direct-operate with a check that refuses every request. The
ctlModela client reads is status-only, and the SCD says the same; the SCD also shows theOperstructure the attempt is addressed to. - Select. The model has no select object, the library answers for an object that does not exist, and it has no hook for that. The conduit records such an attempt; the relay does not.
- Files. The file handler receives a connection handle whose address function the shared object does not export.
- The server follows ADR 0012: a view without the library (
RelayView) and a server withstart(host, port, allow_external=False) -> portandstop(). The loopback rule ofagentic_datacenter.net.guardis repeated inagentic_datacenter_iec61850.guard, because this package may not importagentic_datacenter.net. The server reads the point database in the process it runs in; the separate process with a local socket that section 8.5 describes belongs tocomposemode and is not built here. - Timestamps. The relays' clocks show simulated time counted from 2026-01-01T00:00:00Z. A data object's
tis the step in which its value or quality last changed, so its resolution is the control step, 100 ms. - The conduit and the scenarios do not use the library. In
agentic_datacenter.netthe relays are the MMS devices of theC1allowlist (IED-FDR-A, not the switchboard), and into a relay the conduit passes by client, relay and service class:connect,readandreportpass;control,setting-group,writeandfileare dropped with a violation event. The harness may not import this package, so scenariosOP-12andAD-10run on the plant's relay model and the virtual network: a trip must be visible in the point database within one simulated second, and arelay_requestevent is put to the conduit and to the relay model, which refuses it and publishesprotection.refused. The MMS report and the refusal on the wire are the protocol tests' to show; each scenario file says so.
Consequences
- The package depends on the layout of one wheel: the shared object under
pyiec61850_ng.libs. A new wheel can move it; the version bound and the load check make that a clear failure, not a silent one. - The argument types in
agentic_datacenter_iec61850.libraryare written by hand from the headers of 1.6.1. A wrong one is a crash, not an exception. Moving to another library version means checking each against its headers. - The client used by the tests is the same library as the server. The tests show that the served model is the generated one and that refusals are the ones asked for; they do not show interoperability with another implementation.
- Only linux/arm64 was run. The x86_64 wheel is locked with its hash and was not executed here.
- The plant model has no start signal, no voltage elements on the incomers and one group of settings. The served model says so:
StrfollowsOp,PTUV1andPTOV1on the incomers have behaviouroff, and the setting-group control block has one group. - GOOSE, Sampled Values and MMS over TLS are not served.
Addendum, 2026-11-17: the client drives its own association
The protocol tests failed now and then on a loaded machine with connection-lost on the first request of a new association, while the TCP connection was open at both ends and the server had accepted the client.
The cause is in libiec61850 1.6.1. MmsConnection_connectAsync starts the association and only then writes the state "connecting". The library's connection thread can finish the association in between, when the calling thread is kept waiting for a few milliseconds. The late write then replaces "connected", IedConnection_connect still reports success, and every request is refused with MMS_ERROR_CONNECTION_LOST because the state is not "connected". IedConnection_connectAsync goes through the same lines.
It was reproduced with the library built from tag v1.6.1 and named in ADC_LIBIEC61850: unchanged, the tests pass; with a 100 ms sleep before that write, every association fails in this way.
MmsClient therefore creates its connection without a thread of the library's (IedConnection_createEx), starts the association with IedConnection_connectAsync, and only then starts a thread of its own that calls IedConnection_tick. Nothing can finish the association before the state "connecting" is written. With the same 100 ms sleep the tests pass. The server is not affected: it makes no associations.