Repository navigation
Staging: opt-in verified DataSet-first type hints from #155 (no rollback) #193
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
staging
from
integration/p77-dataset-first-optin-staging-20261022
Oct 22, 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
90 changes: 90 additions & 0 deletions
90
src/AR.Iec61850/Discovery/LiveIedDataSetTypeProbePlanner.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,90 @@ | ||
| using AR.Iec61850.Mms; | ||
|
|
||
| namespace AR.Iec61850.Discovery; | ||
|
|
||
| /// <summary> | ||
| /// Builds bounded typed-LN hints from live MMS DataSet directories. A successful | ||
| /// DataSet directory is independent evidence when GetNameList stopped early. | ||
| /// No SCL, guessed LN names, values, or extra MMS name scans are used. | ||
| /// </summary> | ||
| public static class LiveIedDataSetTypeProbePlanner | ||
| { | ||
| public static IReadOnlyList<MmsFcResolvedPoint> BuildVerifiedMemberHints( | ||
| MmsDiscoveryResult discovery, | ||
| int maxExtraLogicalNodes = 48, | ||
| int maxMemberHints = 2048) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(discovery); | ||
| var extraLimit = Math.Clamp(maxExtraLogicalNodes, 0, 256); | ||
| var pointLimit = Math.Clamp(maxMemberHints, 0, 8192); | ||
| if (pointLimit == 0) | ||
| return Array.Empty<MmsFcResolvedPoint>(); | ||
|
|
||
| // Only domains returned by this association can authorize probes. | ||
| var domains = discovery.Snapshot.DomainVariables.Keys | ||
| .Where(domain => !string.IsNullOrWhiteSpace(domain)) | ||
| .ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
| if (domains.Count == 0) | ||
| return Array.Empty<MmsFcResolvedPoint>(); | ||
|
|
||
| static string RootKey(string domain, string ln) => domain + "\u001f" + ln; | ||
| var knownRoots = discovery.IedDirectory.LogicalDevices.Values | ||
| .SelectMany(ld => ld.LogicalNodes.Keys.Select(ln => RootKey(ld.Name, ln))) | ||
| .ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
| var newRoots = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
| var addedReferences = new HashSet<string>(StringComparer.Ordinal); | ||
| var results = new List<MmsFcResolvedPoint>(); | ||
|
|
||
| // ST first (event / control feedback), then MX; stable DataSet and | ||
| // membership order within each priority tier. | ||
| var liveMembers = discovery.DataSetDirectories | ||
| .Where(directory => directory.IsSuccess) | ||
| .OrderBy(directory => directory.DataSetReference, StringComparer.OrdinalIgnoreCase) | ||
| .SelectMany(directory => directory.Members) | ||
| .OrderBy(member => string.Equals(member.FunctionalConstraint, "ST", | ||
| StringComparison.OrdinalIgnoreCase) ? 0 : 1); | ||
|
|
||
| foreach (var member in liveMembers) | ||
| { | ||
| if (results.Count >= pointLimit) | ||
| break; | ||
| if (!domains.Contains(member.Domain) || | ||
| string.IsNullOrWhiteSpace(member.MmsItemName) || | ||
| !(string.Equals(member.FunctionalConstraint, "ST", StringComparison.OrdinalIgnoreCase) || | ||
| string.Equals(member.FunctionalConstraint, "MX", StringComparison.OrdinalIgnoreCase))) | ||
| continue; | ||
|
|
||
| // Do not accept a fabricated LN, incorrect FC, or ambiguous DO. | ||
| if (!MmsIedModelDirectoryBuilder.TryParseLiveMmsVariable( | ||
| member.Domain, member.MmsItemName, out var point) || | ||
| !string.Equals(point.LogicalNode, member.LogicalNode, StringComparison.OrdinalIgnoreCase) || | ||
| !string.Equals(point.FunctionalConstraint, member.FunctionalConstraint, | ||
| StringComparison.OrdinalIgnoreCase) || | ||
| !string.Equals(point.DataObjectPath, member.DataObjectPath, | ||
| StringComparison.OrdinalIgnoreCase)) | ||
| continue; | ||
|
|
||
| var root = RootKey(point.Domain, point.LogicalNode); | ||
| if (!knownRoots.Contains(root) && !newRoots.Contains(root)) | ||
| { | ||
| if (newRoots.Count >= extraLimit) | ||
| continue; | ||
| newRoots.Add(root); | ||
| } | ||
|
|
||
| if (addedReferences.Add(point.MmsReference)) | ||
| results.Add(new MmsFcResolvedPoint | ||
| { | ||
| Domain = point.Domain, | ||
| LogicalNode = point.LogicalNode, | ||
| FunctionalConstraint = point.FunctionalConstraint, | ||
| DataObjectPath = point.DataObjectPath, | ||
| MmsItemName = point.MmsItemName, | ||
| Source = "LiveMmsDataSetDirectoryTypeHint", | ||
| Confidence = member.Confidence | ||
| }); | ||
| } | ||
|
|
||
| return results; | ||
| } | ||
| } |
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
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
91 changes: 91 additions & 0 deletions
91
tests/AR.Iec61850.Tests/Discovery/LiveIedDataSetTypeProbePlannerTests.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,91 @@ | ||
| using AR.Iec61850.Discovery; | ||
| using AR.Iec61850.Mms; | ||
|
|
||
| namespace AR.Iec61850.Tests.Discovery; | ||
|
|
||
| public sealed class LiveIedDataSetTypeProbePlannerTests | ||
| { | ||
| [Fact] | ||
| public void TruncatedNameList_StillAdmitsVerifiedStaticFeedbackRoots() | ||
| { | ||
| var discovery = Sample(); | ||
| Assert.Equal(1, discovery.IedDirectory.LogicalNodeCount); | ||
| var hints = LiveIedDataSetTypeProbePlanner.BuildVerifiedMemberHints(discovery); | ||
|
|
||
| Assert.Contains(hints, x => x.LogicalNode == "eveGGIO1" && x.MmsItemName == "eveGGIO1$ST$Ind11"); | ||
| Assert.Contains(hints, x => x.LogicalNode == "CSWI16" && x.MmsItemName == "CSWI16$ST$Pos"); | ||
| Assert.Contains(hints, x => x.LogicalNode == "MMXU1" && x.MmsItemName == "MMXU1$MX$A"); | ||
| Assert.DoesNotContain(hints, x => x.LogicalNode is "UNTRUSTED" or "BADFC" or "BADLN"); | ||
|
|
||
| // The MMXU membership was already enumerated and must not be duplicated. | ||
| Assert.Equal(2, discovery.IedDirectory.AddSupplementalPoints(hints)); | ||
| Assert.Equal(0, discovery.IedDirectory.AddSupplementalPoints(hints)); | ||
| var roots = LiveIedVariableTypeProbePlanner.BuildLogicalNodeRootCandidates(discovery.IedDirectory); | ||
| Assert.Equal(3, roots.Count); | ||
| Assert.Contains(roots, root => root.Item == "CSWI16"); | ||
| Assert.Contains(roots, root => root.Item == "eveGGIO1"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Budget_BoundsMissingRoots_AndDeduplicatesExactMemberships() | ||
| { | ||
| var discovery = Sample(); | ||
| var hints = LiveIedDataSetTypeProbePlanner.BuildVerifiedMemberHints( | ||
| discovery, maxExtraLogicalNodes: 1, maxMemberHints: 16); | ||
|
|
||
| Assert.Contains(hints, x => x.LogicalNode == "MMXU1"); | ||
| Assert.Contains(hints, x => x.LogicalNode == "CSWI16"); | ||
| Assert.DoesNotContain(hints, x => x.LogicalNode == "eveGGIO1"); | ||
| Assert.Equal(hints.Count, hints.Select(x => x.MmsReference) | ||
| .Distinct(StringComparer.Ordinal).Count()); | ||
| Assert.Empty(LiveIedDataSetTypeProbePlanner.BuildVerifiedMemberHints( | ||
| discovery, maxExtraLogicalNodes: 0, maxMemberHints: 0)); | ||
| } | ||
|
|
||
| private static MmsDiscoveryResult Sample() | ||
| { | ||
| var snapshot = new MmsDiscoverySnapshot | ||
| { | ||
| DomainVariables = new Dictionary<string, IReadOnlyList<string>> | ||
| { | ||
| ["IEDLD0"] = ["MMXU1$MX$A"] | ||
| } | ||
| }; | ||
| return new MmsDiscoveryResult | ||
| { | ||
| Snapshot = snapshot, | ||
| IedDirectory = MmsIedModelDirectoryBuilder.Build(snapshot), | ||
| DataSetDirectories = | ||
| [ | ||
| new MmsDataSetDirectoryResult | ||
| { | ||
| IsSuccess = true, | ||
| DataSetReference = "IEDLD0/LLN0.Analog", | ||
| Members = | ||
| [ | ||
| Member("MMXU1$MX$A", "MMXU1", "A", "MX"), | ||
| Member("CSWI16$ST$Pos", "CSWI16", "Pos", "ST"), | ||
| Member("CSWI16$ST$Pos", "CSWI16", "Pos", "ST"), | ||
| Member("eveGGIO1$ST$Ind11", "eveGGIO1", "Ind11", "ST"), | ||
| Member("UNTRUSTED$ST$Pos", "UNTRUSTED", "Pos", "ST", "OTHER"), | ||
| Member("BADFC$MX$A", "BADFC", "A", "ST") | ||
| ] | ||
| }, | ||
| new MmsDataSetDirectoryResult | ||
| { | ||
| IsSuccess = false, | ||
| DataSetReference = "IEDLD0/LLN0.Bad", | ||
| Members = [Member("BADLN$ST$Pos", "BADLN", "Pos", "ST")] | ||
| } | ||
| ] | ||
| }; | ||
| } | ||
|
|
||
| private static MmsDataSetDirectoryMember Member(string name, string ln, string path, | ||
| string fc, string domain = "IEDLD0") | ||
| => new() | ||
| { | ||
| Domain = domain, MmsItemName = name, LogicalNode = ln, | ||
| DataObjectPath = path, FunctionalConstraint = fc, Confidence = 100 | ||
| }; | ||
| } |
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.
When a DataSet contains a stale or unavailable member, or the subsequent GVA fails because of a negative response, disconnect, or cancellation, this mutates
discovery.IedDirectorybefore any type result is verified. The new LN and point therefore remain in the canonical directory and can be consumed by export andInitialFcReadPlanner.FromLiveDirectoryeven though probing never confirmed them. The existingProbeDataSetMemberTypesSmartAsyncpath deliberately adds membership seeds only for successful responses with non-nullTypeSpecification; this overload should preserve that gate rather than publishing the hints before executing the probes.Useful? React with 👍 / 👎.