Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions ASSOCIATION_RUNTIME_PROFILE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# MMS Association and Report Subscription Runtime Profile

## Scope

Phase 4B adds the stateful runtime that joins the deterministic Phase 3 association codecs
and Phase 4A reporting codecs. The runtime is transport-injected: an application supplies an
`MmsByteTransport` implementation, while the core owns TPKT/COTP framing, Session,
Presentation, ACSE/MMS association, confirmed-service routing, and RCB subscription state.

## Association lifecycle

`MmsAssociationRuntime` implements:

1. byte-transport connect with deadline and `std::stop_token` cancellation;
2. COTP Connection Request/Confirm negotiation and TPDU-size capture;
3. ISO Session Connect, Presentation CP, ACSE AARQ, and MMS Initiate exchange;
4. accepted/rejected association validation and negotiated MMS limits;
5. segmented COTP send and bounded reassembly on receive;
6. monotonically allocated bounded invoke IDs;
7. confirmed-response/error routing while interleaved InformationReports are queued;
8. explicit timeout, cancellation, fault, and disconnect events; and
9. best-effort COTP Disconnect Request before closing the injected transport.

A failed or timed-out confirmed exchange faults the association because the transport stream
may no longer have a trustworthy request/response boundary. Reconnect is explicit: close or
fault the old runtime state, refill/recreate the transport as required, and call `connect` again.

## Report subscription lifecycle

`MmsReportSubscriptionRuntime` implements a persistent static-DataSet RCB workflow:

1. re-probe the selected RCB immediately before any write;
2. refuse takeover when `RptEna`, reservation, or availability evidence indicates another
session owns the RCB;
3. optionally reserve an URCB using `Resv=true`;
4. optionally write `DatSet`, `TrgOps`, and `OptFlds`;
5. enable with `RptEna=true`;
6. optionally request GI after enable;
7. receive, decode, map, and monitor InformationReports until stop/cancellation/fault;
8. disable only when this runtime enabled the RCB;
9. release only reservations touched by this runtime; and
10. record `cleanup_required` when the association is lost before cleanup completes.

`retry_cleanup` can be called after a successful reconnect. BRCB `EntryID` resume, purge
policy, buffer-overflow recovery, and dynamic DataSet create/delete remain separate work.

## Safety and ownership rules

- The core does not silently take over an already enabled or reserved RCB.
- Cleanup writes are limited to state touched by the current runtime instance.
- The runtime does not include a default TCP socket implementation; live network access is
possible only when an application explicitly supplies an `MmsByteTransport`.
- No control service, SBO state machine, file service, dynamic DataSet create/delete, or
automatic BRCB replay is enabled by this phase.

## Validation

The scripted transport regression covers:

- successful COTP/ACSE/MMS association and negotiated limits;
- cancellation followed by a clean reconnect;
- confirmed request/response routing with an interleaved InformationReport;
- confirmed-exchange timeout and fault transition;
- URCB probe, reserve, enable, GI, report receive, disable, and reservation release;
- cleanup-required state after association loss; and
- refusal to take over an enabled RCB.

The repository has 16 CTest entries through Phase 4B. Local GCC, Clang, and Clang
ASan/UBSan runs pass all 16 tests with warnings treated as errors.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)

project(ARIEC61850Cpp
VERSION 0.12.0
VERSION 0.13.0
DESCRIPTION "Incremental C++20 port of the ARIEC61850 protocol stack"
LANGUAGES CXX)

Expand All @@ -27,6 +27,8 @@ add_library(ariec61850_core
src/mms/services.cpp
src/mms/invoke_router.cpp
src/mms/reporting.cpp
src/mms/association_runtime.cpp
src/mms/report_subscription_runtime.cpp
src/sampled_values/pdu_codec.cpp
src/sampled_values/frame_codec.cpp
src/sampled_values/quality.cpp
Expand Down Expand Up @@ -181,6 +183,13 @@ if(ARIEC61850_BUILD_TESTS)
ariec61850_apply_sanitizers(ariec61850_reporting_tests)
add_test(NAME ariec61850_reporting_tests COMMAND ariec61850_reporting_tests)

add_executable(ariec61850_mms_runtime_tests tests/test_mms_runtime.cpp)
target_link_libraries(ariec61850_mms_runtime_tests PRIVATE ARIEC61850::core)
target_compile_features(ariec61850_mms_runtime_tests PRIVATE cxx_std_20)
ariec61850_apply_warnings(ariec61850_mms_runtime_tests)
ariec61850_apply_sanitizers(ariec61850_mms_runtime_tests)
add_test(NAME ariec61850_mms_runtime_tests COMMAND ariec61850_mms_runtime_tests)

add_executable(ariec61850_fuzz_smoke_tests tests/test_fuzz_smoke.cpp)
target_link_libraries(ariec61850_fuzz_smoke_tests PRIVATE ARIEC61850::core)
target_include_directories(ariec61850_fuzz_smoke_tests PRIVATE
Expand Down
15 changes: 15 additions & 0 deletions MIGRATION_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ until laboratory interoperability is complete.
- [x] Bounded offline report stream/frame retention.
- [x] MMS-reporting mutation smoke and LLVM libFuzzer corpus.

### Phase 4B — association and subscription runtime

- [x] Transport-injected TPKT/COTP/Session/Presentation/ACSE/MMS lifecycle.
- [x] Negotiated TPDU and MMS association limits.
- [x] Deadline and `std::stop_token` cancellation paths.
- [x] Bounded invoke-ID allocation and confirmed-result routing.
- [x] InformationReport delivery while confirmed requests are pending.
- [x] RCB re-probe and occupied-control takeover protection.
- [x] URCB reservation, RptEna enable/disable, optional GI, and touched-state cleanup.
- [x] Persistent report polling and Phase 4A monitor ingestion.
- [x] Cleanup-required evidence and retry path after association loss.
- [ ] Built-in TCP socket transport and physical IED association validation.
- [ ] BRCB EntryID resume, purge decisioning, and buffer-overflow recovery.

### Later Phase 4 work

- [ ] Direct and SBO control state machines.
Expand All @@ -121,6 +135,7 @@ until laboratory interoperability is complete.
- [x] Full stacked-branch GCC/Clang/MSVC and security workflows through Phase 3C.
- [x] PR #6 through PR #10 squash-merged sequentially to `main`.
- [x] Full main-based branch GCC/Clang/MSVC and security workflows through Phase 4A.
- [x] Full stacked-branch GCC/Clang/MSVC and security workflows through Phase 4B.
- [ ] Controlled physical-lab process-bus capture evidence.
- [ ] C# and C++ executable-oracle comparison in one CI job.

Expand Down
28 changes: 20 additions & 8 deletions PORT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current milestone

**Phase 4A — offline DataSet/RCB inventory, InformationReport parsing, and bounded report monitoring are implemented and validated on the published branch.**
**Phase 4B — transport-injected association lifecycle and persistent report-subscription runtime are implemented and validated on the published stacked branch.**

## Delivered modules

Expand All @@ -19,7 +19,9 @@
| Sequence and segmentation continuity tracker | Implemented |
| Bounded offline report monitor | Implemented |
| MMS reporting mutation smoke/libFuzzer | Complete |
| Active MMS association/client runtime | Disabled |
| Transport-injected MMS association/client runtime | Implemented |
| Persistent RCB subscription runtime | Implemented |
| Built-in TCP socket transport | Not included |

## Phase 4A behavior

Expand All @@ -34,13 +36,22 @@ The offline reporting layer:
- detects sequence gaps, duplicates, wraps, resets, configuration/DataSet changes, buffer overflow, and segmentation discontinuity; and
- retains only configured numbers of streams and recent frames.

## Phase 4B behavior

- TPKT/COTP, Session, Presentation, ACSE, and MMS Initiate are orchestrated as one bounded lifecycle.
- Confirmed service responses are routed by invoke ID while InformationReports remain deliverable.
- Deadline and cancellation failures produce explicit fault/cancel events.
- A selected RCB is re-probed before writes and occupied RCBs are not taken over.
- URCB reservation, optional DatSet/TrgOps/OptFlds writes, RptEna, GI, polling, stop, and cleanup retry are stateful.
- Lost associations preserve cleanup-required evidence instead of pretending the RCB was disabled.

## Validation

- GNU C++ 14.2, Release, warnings as errors: passed.
- Clang 17, Release, warnings as errors: passed.
- Clang 17, ASan + UBSan: passed.
- Eleven deterministic Phase 4A reporting groups: passed.
- Full repository CTest: 15/15 passed.
- Full repository CTest: 16/16 passed through Phase 4B.
- C# exact OptFlds/report-item shape: passed.
- Local MMS-reporting libFuzzer: 5,000 runs, no crash artifact.
- GitHub GCC, Clang, and Windows MSVC matrix: passed.
Expand All @@ -49,11 +60,12 @@ The offline reporting layer:

## Remaining acceptance gates

- Live association lifecycle, timeout, cancellation, RCB enable/reservation, GI, and IED interoperability remain outside this phase.
- Direct/SBO control and file services remain later Phase 4 work.
- Built-in platform TCP transport and physical IED interoperability remain separate acceptance work.
- BRCB EntryID resume, purge/buffer-overflow recovery, dynamic DataSet lifecycle, Direct/SBO control, and file services remain later work.

## Safety boundary

Phase 4A consumes saved bytes and supplied discovery/read evidence only. It does not open
a socket, connect to an IED, enable or reserve an RCB, trigger GI, execute a live read or
write, or perform a control operation.
Phase 4B can perform association and RCB Read/Write operations only through an explicitly
injected `MmsByteTransport`. The core does not provide or auto-enable a socket backend. It
never takes over an occupied RCB and only cleans up state touched by the current runtime.
Control operations, dynamic DataSet mutation, and file services are not exposed.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ interoperability are complete.
No enabled runtime opens TCP sockets, Npcap, raw sockets, or a network interface. Physical IED
interoperability and all active transmission remain gated.

## Phase 4B: association and report-subscription runtime

The C++ core now includes a transport-injected MMS association runtime and persistent RCB
subscription state machine. It performs COTP, Session, Presentation, ACSE/MMS Initiate,
confirmed-service routing, timeout/cancellation handling, RCB re-probe, URCB reservation,
`RptEna`, optional GI, InformationReport delivery, and ownership-aware cleanup. See
`ASSOCIATION_RUNTIME_PROFILE.md`.

The core deliberately does not ship a default socket transport in this phase. Applications
that intentionally enable live IED access must provide an `MmsByteTransport` implementation.

## Build

### Windows — Visual Studio
Expand Down
47 changes: 22 additions & 25 deletions VALIDATION.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
ARIEC61850 C++ Phase 4A local validation
ARIEC61850 C++ Phase 4B validation
Date: 2026-08-06

GNU C++ 14.2 / Release / warnings-as-errors:
Configure: PASS
Build: PASS
CTest: PASS (15/15)
CTest: PASS (16/16)

Clang 17 / Release / warnings-as-errors:
Configure: PASS
Build: PASS
CTest: PASS (15/15)
CTest: PASS (16/16)

Clang 17 / RelWithDebInfo / ASan + UBSan:
Configure: PASS
Build: PASS
CTest: PASS (15/15)
CTest: PASS (16/16)

Phase 4A deterministic evidence:
- DataSet and BRCB/URCB inventory grouping
- GetNamedVariableListAttributes request/response round trips
- InformationReport raw MMS and P-DATA round trips
- exact C# OptFlds/report-item semantic vector
- included values, partial failures, data references, and reasons
- RCB attribute state and availability confidence mapping
- sequence gap/duplicate/wrap/reset and configuration/DataSet changes
- buffer-overflow and segmented-report continuity
- bounded stream and frame retention
- malformed/trailing/limit rejection and deterministic mutation smoke

Local libFuzzer:
MMS-reporting corpus: PASS (5,000 runs, no crash artifact)
Phase 4B deterministic evidence:
- COTP/ACSE/MMS association success and negotiated limits
- cancelled connect followed by explicit reconnect
- confirmed response routing with interleaved InformationReport
- confirmed-exchange timeout and association fault transition
- RCB live-state re-probe before any write
- URCB Resv=true, RptEna=true, optional GI, report delivery, and cleanup
- occupied/enabled RCB takeover protection
- cleanup-required state after association loss
- persistent report mapping into the bounded Phase 4A monitor

GitHub Actions:
GCC / Clang / Windows MSVC matrix: PASS (15/15 tests on each compiler)
Clang ASan + UBSan: PASS (15/15 tests)
Ten-corpus libFuzzer smoke: PASS (including MMS reporting; no crash artifact)
GCC / Clang / Windows MSVC matrix: PASS
Clang ASan + UBSan: PASS
Existing ten-corpus libFuzzer: PASS (no crash artifact)

Physical interoperability:
Active TCP association: DISABLED
Live RCB enable/reservation/GI: DISABLED
Live IED read/write/control: DISABLED
Runtime boundary:
Byte transport interface: IMPLEMENTED
Built-in TCP socket backend: NOT INCLUDED
Physical IED association: NOT VALIDATED
Direct/SBO control and file service: DISABLED
Loading
Loading