Repository navigation
P0: verify ARStack M3.H SV decoding with VLAN 0, long BER and 4I+4V #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
masarray
merged 1 commit into
main
from
test/arstack-m3h-vlan0-interoperability-20261024
Oct 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
tests/ProcessBus.Tests/ArstackM3hSvInteroperabilityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| using System.Buffers.Binary; | ||
| using ProcessBus.Iec61850.Raw.Analysis; | ||
| using ProcessBus.Iec61850.Raw.Decoding; | ||
| using Xunit; | ||
|
|
||
| namespace ProcessBus.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Regression for the 24 Oct 2026 ARStack ESP32-P4 M3.H 4I+4V reference | ||
| /// profile. Independent BER / Ethernet fixture, not a DigSub-generated profile. | ||
| /// This proves decoder acceptance, not packet arrival through a real NIC. | ||
| /// </summary> | ||
| public sealed class ArstackM3hSvInteroperabilityTests | ||
| { | ||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public void M3hReference_SvWithPriorityTaggedVlanZeroAndUntagged_Decodes(bool tagged) | ||
| { | ||
| var frame = MakeM3hReferenceFrame(tagged, sampleCount: 3999); | ||
| Assert.True(RawProcessBusDecoder.TryDecode(frame, out var result)); | ||
| Assert.True(result.HasDecodedApdu); | ||
| Assert.NotNull(result.SampledValues); | ||
| Assert.Equal((ushort)0x4000, result.Frame.AppId); | ||
| if (tagged) | ||
| { | ||
| Assert.Equal((ushort)0, result.Frame.Ethernet.Vlan?.VlanId); | ||
| Assert.Equal((byte)4, result.Frame.Ethernet.Vlan?.PriorityCodePoint); | ||
| } | ||
| else | ||
| { | ||
| Assert.Null(result.Frame.Ethernet.Vlan); | ||
| } | ||
|
|
||
| var asdu = Assert.Single(result.SampledValues!.Asdus); | ||
| Assert.Equal("MU01_SV1", asdu.SvId); | ||
| Assert.Equal((ushort)3999, asdu.SmpCnt); | ||
| Assert.Equal((uint)1, asdu.ConfRev); | ||
| Assert.Equal((byte)2, asdu.SmpSynch); | ||
| Assert.Equal(64, asdu.SamplePayload.Length); | ||
| Assert.Equal(2500, BinaryPrimitives.ReadInt32BigEndian(asdu.SamplePayload.Span[..4])); | ||
| Assert.Equal(0u, BinaryPrimitives.ReadUInt32BigEndian(asdu.SamplePayload.Span.Slice(4, 4))); | ||
|
|
||
| var analyzer = new RawProcessBusAnalyzer(); | ||
| analyzer.ObserveFrame(frame); | ||
| var snapshot = analyzer.GetAnalyzerSnapshot(); | ||
| var stream = Assert.Single(snapshot.Streams); | ||
| Assert.Equal("MU01_SV1", stream.SvId); | ||
| } | ||
|
|
||
| private static byte[] MakeM3hReferenceFrame(bool tagged, ushort sampleCount) | ||
| { | ||
| var values = new[] { 2500, -1250, -1250, 0, 330000, -165000, -165000, 0 }; | ||
| var payload = new byte[64]; | ||
| for (var i = 0; i < values.Length; i++) | ||
| BinaryPrimitives.WriteInt32BigEndian(payload.AsSpan(i * 8, 4), values[i]); | ||
|
|
||
| // M3.H prebuilt template uses fixed 2-byte smpCnt and 4-byte confRev. | ||
| // Optional gmIdentity uses context-specific tag 9. | ||
| var asdu = GoldenFrames.Tlv(0x30, | ||
| GoldenFrames.Tlv(0x80, GoldenFrames.Ascii("MU01_SV1")), | ||
| GoldenFrames.Tlv(0x82, GoldenFrames.U16(sampleCount)), | ||
| GoldenFrames.Tlv(0x83, new byte[] { 0x00, 0x00, 0x00, 0x01 }), | ||
| GoldenFrames.Tlv(0x85, new byte[] { 0x02 }), | ||
| GoldenFrames.Tlv(0x87, payload), | ||
| GoldenFrames.Tlv(0x89, new byte[] { 0x02, 0x11, 0x22, 0xFF, 0xFE, 0x33, 0x44, 0x55 })); | ||
|
|
||
| var apdu = GoldenFrames.Tlv(0x60, | ||
| GoldenFrames.Tlv(0x80, new byte[] { 0x01 }), | ||
| GoldenFrames.Tlv(0xA2, asdu)); | ||
|
|
||
| return GoldenFrames.EthernetFrame( | ||
| GoldenFrames.SvEtherType, | ||
| GoldenFrames.ProcessBusPayload(0x4000, apdu), | ||
| tagged ? (ushort)0x8000 : null); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both theory cases generate only short-form BER lengths: the ASDU, ASDU sequence, and outer APDU have value lengths of 99, 101, and 106 bytes, respectively, and
GoldenFrames.Tlvemits long-form lengths only at 128 bytes or above. Consequently, this regression passes even if the decoder rejects every long-form length, leaving the long-BER interoperability case advertised by this commit untested. Explicitly encode long-form lengths in the reference fixture and assert their presence before decoding.Useful? React with 👍 / 👎.