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
10 changes: 9 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.3.0
VERSION 0.4.0
DESCRIPTION "Incremental C++20 port of the ARIEC61850 protocol stack"
LANGUAGES CXX)

Expand All @@ -15,6 +15,8 @@ add_library(ariec61850_core
src/goose/retransmission_schedule.cpp
src/goose/pdu_codec.cpp
src/goose/frame_codec.cpp
src/goose/subscriber_supervisor.cpp
src/goose/publisher_runtime.cpp
src/mms/utc_time.cpp
src/mms/data_value.cpp
src/mms/data_codec.cpp)
Expand Down Expand Up @@ -60,4 +62,10 @@ if(ARIEC61850_BUILD_TESTS)
ariec61850_apply_warnings(ariec61850_${test_name}_tests)
add_test(NAME ariec61850_${test_name}_tests COMMAND ariec61850_${test_name}_tests)
endforeach()

add_executable(ariec61850_goose_runtime_tests tests/test_goose_runtime.cpp)
target_link_libraries(ariec61850_goose_runtime_tests PRIVATE ARIEC61850::core)
target_compile_features(ariec61850_goose_runtime_tests PRIVATE cxx_std_20)
ariec61850_apply_warnings(ariec61850_goose_runtime_tests)
add_test(NAME ariec61850_goose_runtime_tests COMMAND ariec61850_goose_runtime_tests)
endif()
44 changes: 34 additions & 10 deletions MIGRATION_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,49 @@ interoperability is complete.

**Phase 0 status: complete.**

## Phase 1 — deterministic process-bus codecs
## Phase 1 — deterministic process-bus codecs and runtime

### Phase 1A — MMS data foundation

- [x] IEC 61850 8-byte UTC time with quality byte.
- [x] Recursive MMS Data value model.
- [x] MMS AllData BER encoder/decoder.

### Phase 1B — GOOSE wire codec

- [x] GOOSE PDU model.
- [x] GOOSE PDU BER encoder/decoder.
- [x] GOOSE `numDatSetEntries` consistency validation.
- [x] GOOSE Ethernet/VLAN/process-bus frame encoder/decoder.
- [x] GOOSE C#-compatible byte-for-byte golden vectors.
- [x] GOOSE malformed/truncated-input regression tests.
- [ ] GOOSE subscriber TTL, `stNum`/`sqNum` supervision, and duplicate detection.
- [ ] GOOSE publisher session and retransmission state machine.

### Phase 1C — GOOSE supervision and publisher runtime

- [x] Subscriber TimeAllowedToLive deadline supervision.
- [x] One-shot expiry events and expiration statistics.
- [x] First/retransmission/duplicate classification.
- [x] Sequence gap and sequence regression detection.
- [x] State change, state jump, and state regression detection.
- [x] `stNum` and `sqNum` 32-bit wraparound behavior.
- [x] Expected control-block, dataset, and configuration-revision checks.
- [x] Changed AllData without `stNum` increment detection.
- [x] Publisher session with C#-compatible state/sequence behavior.
- [x] Publisher retransmission runtime with exponential scheduling.
- [x] Schedule reset and `sqNum = 0` on state changes.
- [x] Stable state timestamp across retransmissions.
- [x] Offline encoded-frame output with no raw-network activation.

### Phase 1D — Sampled Values and evidence hardening

- [ ] Sampled Values ASDU model.
- [ ] Sampled Values APDU and Ethernet frame codec.
- [ ] Sampled Values sequence supervision and stream diagnostics.
- [ ] Captured PCAP equivalence tests from real or simulated IED traffic.
- [ ] Decoder fuzzing corpus for BER, GOOSE, and SV.

**Phase 1 status: GOOSE wire codec complete; runtime publisher/subscriber behavior and
Sampled Values remain.**
**Phase 1 status: MMS and GOOSE wire/runtime layers complete; Sampled Values and
capture/fuzz evidence remain.**

## Phase 2 — engineering file formats

Expand Down Expand Up @@ -84,18 +106,20 @@ Sampled Values remain.**

- [x] GCC C++20 build with warnings as errors.
- [x] Clang C++20 build with warnings as errors.
- [x] Windows MSVC build for Phase 1A.
- [x] Windows MSVC build and CTest for Phase 1B.
- [x] Windows MSVC build and CTest through Phase 1B.
- [x] Windows MSVC build and CTest for Phase 1C.
- [x] MMS C#-derived golden vector.
- [x] GOOSE PDU C#-derived golden vector.
- [x] GOOSE complete Ethernet frame golden vector with VLAN and process-bus header.
- [x] Malformed BER and GOOSE count-mismatch rejection.
- [x] Deterministic subscriber and publisher runtime regression suite.
- [ ] C# and C++ executable oracle comparison in one CI job.
- [ ] Sanitizer jobs and fuzzing.
- [ ] Isolated-lab IED interoperability.

## Safety gate

Active GOOSE publishing, MMS write/control, and raw-Ethernet transmission remain outside
the enabled runtime surface. They should only be enabled after sequence, timeout,
cancellation, disconnect cleanup, PCAP equivalence, and isolated-lab tests pass.
The Phase 1C publisher is an offline state machine that returns encoded bytes. Active
Npcap transmission, MMS write/control, and IED operation remain outside the enabled
runtime surface until timeout, cancellation, disconnect cleanup, PCAP equivalence, and
isolated-lab tests pass.
99 changes: 62 additions & 37 deletions PORT_STATUS.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
# C++ Port Status

## Current milestone: Phase 1B

The C++20 port now includes the deterministic foundation, MMS Data values, IEC 61850 UTC
time, and the complete GOOSE wire codec from BER PDU through Ethernet/VLAN/process-bus
framing.

| Original C# area | C++ target | Status |
|---|---|---|
| ASN.1 BER primitives | `asn1` | Ported and tested |
| Ethernet, VLAN, process-bus header | `ethernet` | Ported and tested |
| Classic PCAP | `capture` | Ported and tested |
| GOOSE retransmission schedule | `goose/retransmission_schedule` | Ported and tested |
| IEC 61850 UTC time | `mms/utc_time` | Ported and tested |
| MMS Data / AllData | `mms/data_value`, `mms/data_codec` | Ported and tested |
| GOOSE PDU | `goose/pdu`, `goose/pdu_codec` | Ported and tested |
| GOOSE Ethernet frame | `goose/frame`, `goose/frame_codec` | Ported and tested |
| GOOSE runtime publisher/subscriber | Phase 1C | Pending |
| Sampled Values | Phase 1D | Pending |
| SCL and COMTRADE | Phase 2 | Pending |
| TPKT/COTP/ACSE/MMS association | Phase 3 | Pending |
| Reporting, control, and file service | Phase 4 | Pending |
| Simulator, CLI, and native UI | Phase 5 | Pending |

## Phase 1B validation

- C++20 GCC 14.2, warnings as errors: passed.
- C++20 Clang 17, warnings as errors: passed.
- Three CTest executables: core, MMS, and GOOSE.
- GOOSE PDU golden vector matches the C# encoder field order and BER representation.
- Complete VLAN-tagged GOOSE Ethernet frame has a byte-for-byte golden vector.
- PDU and frame round trips pass.
- Dataset entry-count mismatch, invalid UTC time, wrong outer tag, and wrong EtherType are rejected.
- No external C++ runtime dependency is required.

See `MIGRATION_CHECKLIST.md` for the complete roadmap and current checkboxes.
## Current milestone

**Phase 1C — GOOSE subscriber supervision and publisher runtime is implemented.**

The C++ stack now covers the deterministic path from MMS values through a complete
GOOSE Ethernet frame and the state machines immediately above that wire codec.

## Delivered modules

| Area | Status |
|---|---|
| BER primitives | Complete |
| Ethernet, VLAN, process-bus header | Complete |
| Classic PCAP reader/writer | Complete |
| IEC 61850 UTC time | Complete |
| MMS Data / AllData codec | Complete |
| GOOSE PDU codec | Complete |
| GOOSE Ethernet frame codec | Complete |
| GOOSE subscriber supervision | Complete |
| GOOSE publisher session/runtime | Complete, offline frame output only |
| Sampled Values | Not started |
| SCL and COMTRADE | Not started |
| TPKT/COTP/ACSE/MMS association | Not started |
| Reporting and control | Not started |
| Simulator and native UI | Not started |

## Phase 1C behavior

Subscriber supervision includes:

- TimeAllowedToLive deadline calculation and one-shot expiry reporting;
- arrival-gap tracking;
- duplicate, retransmission, sequence-gap, sequence-regression, state-change,
state-jump, and state-regression classification;
- `uint32` counter wraparound;
- expected stream identity validation;
- configuration revision change indication; and
- detection of changed AllData while `stNum` remains unchanged.

Publisher runtime includes:

- initial publication with configured state and sequence counters;
- state-change publication with `stNum` increment and `sqNum = 0`;
- retransmissions with `sqNum` increment and wraparound;
- exponential min-time to max-time scheduling;
- schedule reset after every state change; and
- a deterministic `poll(now)` API that avoids sleeping threads and timing-flaky tests.

## Validation

- GNU C++ 14.2, Release, warnings as errors: passed.
- Clang 17, Release, warnings as errors: passed.
- Four CTest executables passed under both compilers:
- core foundation;
- MMS values;
- GOOSE wire codec; and
- GOOSE subscriber/publisher runtime.
- Windows MSVC verification is performed by GitHub Actions for every stacked PR.

## Safety boundary

This milestone provides offline codecs only. It does not start a raw-Ethernet publisher,
subscribe to a network interface, perform MMS writes, or execute IED control.
No network adapter is opened by Phase 1C. The publisher runtime only returns encoded
Ethernet-frame bytes. Npcap transmission, background network threads, active GOOSE
publishing, MMS writes, and IED controls remain disabled until PCAP equivalence and
isolated-lab interoperability are completed.
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,69 @@
# ARIEC61850 C++ Port

Incremental C++20 migration of the ARIEC61850 C# stack. The C# implementation remains
the behavioral oracle while each module gains byte-for-byte vectors and malformed-input
tests.
Incremental C++20 migration of the ARIEC61850 C# protocol stack. The C# implementation
remains the behavioral oracle until cross-language comparison and isolated-laboratory
interoperability are complete.

## Implemented through Phase 1B
## Implemented

- BER primitives, Ethernet/VLAN/process-bus framing, PCAP, and GOOSE retransmission timing.
- IEC 61850 UTC time and recursive MMS Data / AllData codecs.
- GOOSE PDU encoder/decoder for `gocbRef`, `timeAllowedToLive`, `datSet`, `goID`, `t`,
`stNum`, `sqNum`, `test`, `confRev`, `ndsCom`, `numDatSetEntries`, and `allData`.
- Complete GOOSE Ethernet frame encoder/decoder with optional VLAN.
- GCC, Clang, and MSVC GitHub Actions coverage.
- C#-compatible MMS and GOOSE golden vectors.
### Phase 0 — portable foundation

See [`MIGRATION_CHECKLIST.md`](MIGRATION_CHECKLIST.md) for detailed progress.
- CMake-based C++20 static library.
- BER TLV and primitive codecs.
- MAC, VLAN, Ethernet, IEC 61850 process-bus, and classic PCAP codecs.
- GOOSE retransmission schedule.

## Build
### Phase 1A — MMS data foundation

```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure
```
- IEC 61850 8-byte UTC time and quality byte.
- Recursive MMS Data values and AllData BER codec.
- C#-derived byte-for-byte golden vectors.

For Visual Studio multi-configuration builds:
### Phase 1B — GOOSE wire codec

- Complete GOOSE PDU encode/decode.
- Ethernet/VLAN/process-bus GOOSE frame encode/decode.
- Dataset count and malformed-frame validation.

### Phase 1C — GOOSE runtime state machines

- Subscriber TTL supervision and one-shot expiry events.
- `stNum`/`sqNum` classification: first, retransmission, duplicate, gap, regression,
state change, state jump, and state regression.
- 32-bit sequence and state wraparound handling.
- Expected control-block, dataset, and configuration-revision identity checks.
- Detection of data changes without a matching `stNum` increment.
- Publisher session matching the C# counter semantics.
- Deterministic publisher runtime with exponential retransmission scheduling.
- State timestamps remain stable during retransmission and change only on a state event.

The publisher runtime returns encoded frames to its caller. It does not open Npcap,
raw sockets, or a network interface.

## Build

### Windows — Visual Studio

```powershell
cmake -S . -B build -A x64
cmake -S . -B build -A x64 -DARIEC61850_WARNINGS_AS_ERRORS=ON
cmake --build build --config Release --parallel
ctest --test-dir build -C Release --output-on-failure
```

### Linux — GCC or Clang

```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DARIEC61850_WARNINGS_AS_ERRORS=ON
cmake --build build --parallel
ctest --test-dir build --output-on-failure
```

## Migration rule

A module is complete only after C++ tests, C#-versus-C++ vectors, malformed-input coverage,
and relevant PCAP or laboratory evidence. Active publishing and control remain disabled
until their state-machine safety gates pass.
1. Capture deterministic C# behavior and byte vectors.
2. Port the same behavior to C++.
3. Run strict multi-compiler builds and semantic state-machine tests.
4. Compare real or simulated PCAP/SCL evidence.
5. Enable active transport only after safety and interoperability gates pass.

See `MIGRATION_CHECKLIST.md` for the detailed progress ledger.
46 changes: 28 additions & 18 deletions VALIDATION.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
ARIEC61850 C++ Phase 1A validation
ARIEC61850 C++ Phase 1C validation
Date: 2026-08-06

Local toolchains:
- GNU C++ 14.2.0, C++20, -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Werror: PASS
- Clang 17.0.0, C++20, same strict warning policy: PASS
GNU C++ 14.2 / Release / warnings-as-errors:
Configure: PASS
Build: PASS
CTest: PASS (4/4 test executables)

CTest:
- ariec61850_core_tests: PASS
- ariec61850_mms_tests: PASS
- Internal checks: 12/12 PASS
Clang 17 / Release / warnings-as-errors:
Configure: PASS
Build: PASS
CTest: PASS (4/4 test executables)

New parity evidence:
- IEC 61850 UTC time vector: 6A2B77254000000A
- MMS AllData vector: byte-for-byte match with the C# MmsDataCodec behavior
- Recursive Structure, BitString, Unknown high-tag, and malformed nested TLV coverage: PASS
Windows MSVC / Release / warnings-as-errors / GitHub Actions:
Configure: PASS
Build: PASS
CTest: PASS (4/4 test executables)

CI added:
- Ubuntu GCC
- Ubuntu Clang
- Windows MSVC
Test executables:
1. ariec61850_core_tests
2. ariec61850_mms_tests
3. ariec61850_goose_tests
4. ariec61850_goose_runtime_tests

Safety boundary:
No active IED control or raw-Ethernet publisher session is enabled by this phase.
Phase 1C runtime checks:
- subscriber sequence and state classification
- TTL expiry and one-shot timeout reporting
- expected stream identity rejection
- state and sequence counter wraparound
- publisher C# sequence semantics
- retransmission schedule and state-change reset
- stable state timestamp across retransmissions
- publisher state and sequence wraparound
Loading
Loading