imsys

CLS loopback simulator

Read a simulated IEC 61850 meter over mutual TLS, then drive a CLS connection with your own clock and transport.

Run the first read

Run the commands from the workspace root with Rust 1.90 or newer. The simulator needs OpenSSL development headers and a provider supporting Brainpool P-256. On Linux, install the OpenSSL development package and pkg-config. On macOS, Homebrew's OpenSSL works.

cargo run --locked -p xtask -- gen-pki
cargo run --locked -p smgw-cls --features simulator --example mms_read

The Controllable Local System (CLS) serves the reading using Manufacturing Message Specification (MMS). The first command creates credentials under target/test-pki. Run the second command as often as needed during their validity period. A successful run reads a named value from the bundled IEC 61850 model and completes the MMS release handshake.

CLSLD0/MMXU1$MX$TotW$mag$f = 1250 W (MMS read over HAN and WAN mutual TLS)

Follow the connection

The gateway accepts one connection on the home area network (HAN) and opens a second on the wide area network (WAN). Both use mutual TLS and ephemeral loopback ports in the simulator.

ConnectionWhat the TLS client does
HAN · CLS → gatewayThe meter supplies the configured proxy ID, meter.test, through the TLS Server Name Indication (SNI) extension.
WAN · gateway → aEMTAfter authenticating the meter and authorizing its route, the gateway dials the provisioned endpoint of the active external market participant (aEMT).

The aEMT acts as the MMS client and the meter serves the read. The gateway terminates TLS on each leg and relays application bytes in both directions. Each side verifies its immediate peer's certificate chain and configured leaf fingerprint. The two gateway identities have distinct keys. The fixture selects TLS 1.2, ECDHE-ECDSA-AES128-GCM-SHA256 and brainpoolP256r1. Hardware interoperability requires a separate test against the intended gateway. BSI operating processes, §3.13.3

Renew fixtures by generating a fresh directory and passing it to the simulator. The CLS fixture uses four endpoint identities across two trust domains, HAN and WAN. The same generator provisions a third trust domain for gateway management. All fixture certificates have a seven-day validity period. Inspect manifest.tsv for the roles, leaf fingerprints, trust-anchor paths and reference time. The generator refuses to replace an existing directory.

cargo run --locked -p xtask -- gen-pki target/renewed-pki
cargo run --locked -p smgw-cls --features simulator --example mms_read -- target/renewed-pki

To repeat the same read with a token-generated HAN gateway key, use the PKCS#11 walkthrough. Security providers and token keys

Drive a session

Use engine::Session when your application owns the sockets and clock. The default smgw-cls build tracks one connection without an allocator or operating system. Session API

  1. Call start(now). Execute the returned Connect action and keep its generation with that transport.
  2. After peer verification and route authorization succeed, call connected(generation, now). A timely Ready action permits application traffic. Report failure with failed and make authentication or configuration failures permanent.
  3. After every change, re-arm the timer from deadline(). Supply monotonic time from one origin, including when the socket is idle. At the deadline call tick(now), execute its action and recheck the deadline. A connect callback arriving exactly at its deadline is late.
  4. On Close, release resources for that generation. On shutdown call cancel(). Older callbacks cannot activate a new connection.

The default policy gives each connect attempt five seconds, bounds an active session at sixty seconds, and allows three additional attempts with delays of one, two and four seconds. The one-shot MMS example uses its own fifteen-second overall budget.