Commit Graph

4 Commits

Author SHA1 Message Date
romanett 2871355d18 GDS: implement the AliasName Server facet (OPC 10000-17 Annex C) (#4668)
## Summary

Implements the **GDS AliasName Server facet** (OPC 10000-17 Annex C) in
`Opc.Ua.Gds.Server`, so that the CTT conformance unit *GDS AliasName
Discovery* passes apart from two CTT script defects (documented, Mantis
drafts in `plans/ctt-issues.md`).

Spec requirements:
- **C.1:** aggregate the AliasNames of registered Servers that expose
the `ALIAS` capability (OPC 10000-12 Annex D). Pull all
AliasNameCategory instances and merge those whose BrowseNames have the
same Name. Provide the ExpandedNodeId of every referenced node and the
ServerUri of the Server that contains it.
- **C.2:** on registration, merge the Server's AliasNames into a single
tree for TagVariables/Topics, combine aliases that share a name, and add
the ServerUri to `ServerArray`.
- **C.3:** on unregistration, remove that Server's aliases and
categories (but keep those other Servers still provide), remove its
AliasFor references, and remove its ServerUri from `ServerArray`.

### Design
- **`AliasNameAggregator`** (`Opc.Ua.Gds.Server.AliasNames`) holds one
snapshot per registered application and builds the merged view:
- Categories are keyed by their BrowseName path below `Aliases`. Aliases
are merged by name within a category; their targets are the union over
all sources.
- Targets are stored as namespace-URI ExpandedNodeIds. The ServerIndex
is resolved against the server's `ServerArray` each time the view is
built, because removing a ServerUri renumbers the entries after it.
  - Only ServerUris the aggregator added itself are removed again.
- Also implements `FindAlias`/`FindAliasVerbose`, recursive over
sub-categories.
- **`SessionAliasNameSourceReader`** reads a source over a client
Session by browsing the `Aliases` (i=23470) hierarchy and the AliasFor
references.
- It browses instead of calling `FindAlias` because the category
structure has to be aggregated too, and a source whose aliases come from
a NodeSet (like the CTT's embedded server) does not implement
`FindAlias`.
- It connects anonymously, to the most secure endpoint first, falling
back to SecurityMode None. It runs GetEndpoints once per DiscoveryUrl.
- **`ApplicationsNodeManager`** (new partial
`ApplicationsNodeManager.AliasNames.cs`):
- Hooks RegisterApplication (now `OnCallAsync`), UpdateApplication
(background re-read) and UnregisterApplication.
- Materializes the merged view as `AliasNameType` and
`AliasNameCategoryType` nodes in the GDS application-record namespace,
organized by the well-known TagVariables/Topics/Aliases objects. Each
category gets a `FindAlias` answered from the merged list.
- Changes and node updates are serialized, so a read that finishes after
a concurrent unregister cannot re-add the source.
- RegisterApplication waits at most `AliasNameRegistrationWait` (5 s)
for the read; a slower or unreachable source is finished in the
background and never blocks clients past their call timeout.
- Optional periodic re-read via `AliasNameRefreshInterval`; it also
retries sources that could not be read.
-
**`IAliasNameStoreRegistry.RegisterContributor`/`UnregisterContributor`**
(Opc.Ua.Server): a read-only contributor's aliases are added to the
`FindAlias`/`FindAliasVerbose` results of the categories it reports,
next to the owning store's. This lets the aggregated aliases share the
well-known categories with the server's own aliases, which matters for
the reference server, an AliasName Server and a GDS at once.
Contributors never receive Add/Delete calls.
- **Opt-in:**
`GlobalDiscoveryServerConfiguration.EnableAliasNameAggregation` is off
by default, because the GDS then opens client connections to the
DiscoveryUrls of registered applications.
`Ctt.ReferenceServer.Config.xml` enables it.
- `Opc.Ua.Gds.Server` now references `Opc.Ua.Client`; the `Opc.Ua`
meta-package already depends on both.

### CTT (1.05.513 with the patched scripts), p14-gds, reference server
`--ctt`, embedded CTT source + 2 extra AliasName sources

| GDS AliasName Discovery | before | after | after, with the C54/C55
script fixes |
| --- | --- | --- | --- |
| initialize | Skipped (no sources) | Pass | Pass |
| 001 | Error | Error (C55) | Pass |
| 002 | Error | Error (C54) | Warning (RegisterApplication > 100 ms) |
| 003 | Pass | Pass | Pass |
| 004 | Error | Error (C54) | Pass |
| 005 | Skipped | Error (C55) | Pass |
| 006, 007, 009, 011, 012, 014, 015 | Skipped | Error (C54) | Pass |
| 008 | Skipped | Pass | Pass |
| 010, 013 | Skipped | Error (C55) | Pass |

- **C54:** the script compares the GDS's AliasFor target (ServerIndex >
0, namespace URI, as Annex C.1 and Part 4 §7.16 require) with the
source's local NodeId using `equals()`, which can never match.
- **C55:** "no remote aliases" is checked as "no aliases", so it fails
on the reference server's own aliases.

Both are documented with draft Mantis texts (not filed). The remaining
script checks pass in 15/15 test cases.

No regressions:
- Application Directory and Query Applications are unchanged against the
baseline. The only difference is one ActivateSession timing warning in
one run.
- p09 (AliasName CUs) passes 32/32, identical to the baseline.

## Tests
- `AliasNameAggregatorTests` (unit) covers:
  - merging across Servers;
- categories kept while still referenced and removed after the last
source;
  - ServerArray add, remove and renumbering;
  - pre-existing ServerUris kept;
  - local targets;
  - FindAlias/FindAliasVerbose scope, pattern and reference-type filter.
- `GdsAliasNameAggregationTests` (end-to-end) registers a second
in-process reference server with `ALIAS` and reads it with the real
session reader. It checks:
  - aggregated nodes and remote AliasFor targets;
  - the ServerArray entry;
  - FindAlias on TagVariables and on the aggregated category;
  - that unregistering removes everything;
  - that an unreachable source still registers;
  - that a Server without `ALIAS` is ignored.
- Registry contributor tests in `AliasNameStoreRegistryTests`.
- Opc.Ua.Gds.Tests: 1246 passed, 0 failed, 56 skipped.
Opc.Ua.Server.Tests AliasNames: 198/198. InformationModel and Features
alias tests pass. net48 compiles.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 19:10:02 +00:00
romanett d6356766c5 Resolve the open CTT findings: aggregate fixes, de-DE ApplicationName and CTT configuration (#4545)
# Description

Resolves the open items of `plans/ctt-issues.md` (*Needs clarification*,
*Open server findings*, *CTT project configuration notes*). Each item
was checked against the OPC 10000 spec text. A server change was made
only where the server was wrong, and every server change has a
regression test. CTT script and oracle defects are filed in Mantis
instead.

### Server changes (`Opc.Ua.Server`)

- **NumberOfTransitions honours TreatUncertainAsBad.**
- Part 13 §5.4.3.24 does not count Bad values. §4.2.1.2 makes Uncertain
values "equivalent to Bad" when TreatUncertainAsBad is True, and the
aggregate definition doesn't override that.
- Uncertain values are therefore no longer counted, and no longer used
as the previous value, when the setting is True. The now unused
`TimeSlice.NonBadEarlyBound` is removed.
- **DurationInStateZero/NonZero status follows the variable's
interpolation.**
- §5.4.3.2.2: "A region is Uncertain if a region ends in a Bad or
Uncertain value and SlopedInterpolation is used."
- The calculator always built stepped status regions. So on a sloped
variable, the last region stayed Good while TimeAverage2 and Total2 over
the same interval were already Uncertain.
  - The duration value doesn't change.
- **AnnotationCount returns `Bad_NoData` and sets Partial.**
- Table 68 requires `Bad_NoData` for intervals before the start or after
the end of data. §5.3.3.2 requires the Partial bit for incomplete
intervals.
- `HistorianDispatcher` now derives the start and end of data from the
raw history (read with bounds) plus the annotation timestamps. It passes
them to a new `CalculateAnnotationCounts` overload; the old overload is
unchanged.
- Three existing dispatcher tests change their expectations. For
example, a node without any data now returns `Bad_NoData` instead of
Good zeros.

### Reference server sample and CTT configuration

- **`de-DE` ApplicationName.** The server advertises `de-DE` in
LocaleIdArray, but FindServers and GetEndpoints always returned the
en-US name. The sample now keys the ApplicationName and registers en-US
and de-DE translations (Part 4 §5.5.2.2 / §5.5.4.2 localeIds).
- **Subscription limit.** `Max Supported Subscriptions` in
`samples/UAReferenceServer.ctt.xml` and `MaxSubscriptionCount` in
`Ctt.ReferenceServer.Config.xml` go from 100 to 200. Subscription
Publish Min 05 `003.js` needs 190 subscriptions.
- **Alarm Cycle Time.** The CTT template's Alarm Cycle Time is 30 s. At
60 s it equalled `RequestedSessionTimeout`, so a Limit/Level CU that
starts a run finds its session expired (C40).

### Tests only

- **AddNodes duplicate BrowseName test:**
`AddNodeAsync_DuplicateBrowseNameUnderParent_ReturnsBadBrowseNameDuplicatedAsync`
never ran. Its items had no TypeDefinition, so its `Assume` always made
it inconclusive. The finding it belongs to (AddNodes after a rename
returning `BadNodeIdExists`) was already fixed by #4477.
- **RequestHandle echo:** a new test covers the ServiceFault for an
oversized argument in a chunked request (already fixed by #4488).
- **Value-based status:** a new test covers the aggregate status with
TreatUncertainAsBad = false (already fixed by #4503).

### Not changed

- **GDS QueryApplications/QueryServers still return records with
ServerCapability `NA`.** OPC 10000-12 §6.5.10/§6.5.11 says they "shall
not", but the CTT GDS scripts expect those records. Implementing the
exclusion turned 40 GDS test cases from pass to error, so it waits for
the script fix ([Mantis
11458](https://mantis.opcfoundation.org/view.php?id=11458)).
- **Idle SecureChannels are still closed after `ChannelLifetime`.**
Keeping them open would be security relevant. The CTT configuration's
`ChannelLifetime` of 120000 (#4502) covers the CTT case.

### Mantis issues filed

| Id | Issue |
| --- | --- |
| C51 | [11458](https://mantis.opcfoundation.org/view.php?id=11458) GDS
scripts expect NA records in query results |
| C52 | [11459](https://mantis.opcfoundation.org/view.php?id=11459) A &
C Refresh scripts leak subscriptions on the shared alarm session |
| C53 | [11460](https://mantis.opcfoundation.org/view.php?id=11460)
`StartThreadPublish.js` defaults misspelled properties |
| U2 | [11461](https://mantis.opcfoundation.org/view.php?id=11461)
Minimum2 oracle on reverse reads |
| U4 | [11462](https://mantis.opcfoundation.org/view.php?id=11462) Part
13 clarification: TreatUncertainAsBad and simple bounds (DeltaBounds) |

The A & C `BadSubscriptionIdInvalid` failures (Refresh, Refresh2,
Shelving) come from CPU load: with other processes at 100 % CPU, all
subscriptions of the CTT alarm session expire within one second. This
happens with and without this PR (3 of 3 loaded runs, 0 of 2 idle runs).

### CTT verification

CTT 1.05.06, scripts 1.05.513, compared at test-case level against a
build of the starting commit:

| Group | Before | After |
| --- | --- | --- |
| Aggregates | 4,562 error messages | 4,186. NumberOfTransitions: 12
test cases go from error to pass. AnnotationCount
`005-01.js`/`005-02.js` pass. NumberOfTransitions
`003-02.js`/`004-02.js` now fail because of C1 ([Mantis
11420](https://mantis.opcfoundation.org/view.php?id=11420)): they
request TreatUncertainAsBad = false, but the harness makes the server
use its default of true. |
| Discovery | 10 warnings | 0. Find Servers Filter `003.js`/`006.js` and
Get Endpoints `002.js` pass. |
| Subscription | – | Publish Min 05 `003.js` goes from warning to pass.
|
| Historical Access, GDS, Node Management | – | no new failures |

`plans/ctt-issues.md` is updated: resolved items leave the open
sections, and the new Mantis issues are recorded.

## Related Issues

- Related to #4479 (CTT configuration notes)
- Follows #4502

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [ ] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

Tests run locally on net10.0 after merging master:

| Project | Filter | Passed |
| --- | --- | --- |
| `Opc.Ua.Server.Tests` | Aggregate, Historian, NodeManagement, Publish,
Subscription | 1,419 |
| `Opc.Ua.Core.Tests` | TcpServerChannelBuffer | 65 |
| `Opc.Ua.History.Tests` | Aggregate, Annotation | 67 |
| `Opc.Ua.Sessions.Tests` | discovery locale tests | 8 |

Before the merge, the whole `Opc.Ua.Sessions.Tests` ClientTest fixture
passed (372 passed, 0 failed).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-25 12:30:25 +02:00
romanett 13f96fd4ba Raise ChannelLifetime for the CTT reference server and record the full CTT run of the merged CTT PRs (#4502)
# Description

Findings of a full CTT run (23 parts, 3,752 test cases, CTT 1.05.06 /
scripts 1.05.513) against the merge of #4477, #4482, #4485 and #4486,
which are all on master now, plus the CTT defects filed in Mantis.

No server code changes: the PR changes only the CTT configuration of the
reference server sample and the `plans/` documentation.

## CTT configuration: raise `ChannelLifetime` to 120 s

CTT Security None `007.js` and Security Basic256Sha256 `005.js` failed
(also on master): they keep SecureChannels without a Session idle for
about 51 s (60 s token, stretched by the CTT's CloseSession delay, C50)
and expect the newest one to close with Good.
`TcpTransportListener.DetectInactiveChannels` had already closed it
after `ChannelLifetime` (30 s) without traffic
(`CloseSecureChannel().Result received BadInvalidState`).


`samples/Reference/ConsoleReferenceServer/Ctt.ReferenceServer.Config.xml`
now sets `ChannelLifetime` to 120000. The default of 30000 and the
server's inactivity cleanup are unchanged.

An earlier revision of this PR changed the inactivity cleanup instead,
keeping idle Session-less channels open until their token expired (Part
4 §5.6.2.1). That change was withdrawn because it lets an
unauthenticated client hold a channel for up to the
`SecurityTokenLifetime` (one hour by default) instead of 30 s. The
difference to Part 4 §5.6.2.1 is recorded as an open server finding in
`plans/ctt-issues.md`.

Validated on 2026-09-24 with the reverted code and the new configuration
(full run, compared with the run of 2026-09-22 at test-case level):

- Security None `007.js` passes and Security Basic256Sha256 `005.js` has
only the C50 CloseSession delay warnings (both failed with 30 s).
- All other parts have the same error signatures as before; the
remaining differences are *"Response Timestamp shows a delay"* warnings
from a loaded machine (a back-to-back Session Services run with 30 s and
120 s on an idle machine is identical).
- A & C Refresh2 `Err_003.js`/`Err_004.js` and Shelving `initialize.js`
report `BadSubscriptionIdInvalid` in today's runs with both 30 s and 120
s on the same build, so they are unrelated to the configuration (both
passed again in a run on the idle machine with 120 s).

## Mantis

32 CTT defects filed on 2026-09-24 (11420–11454, script issues in *CTT
UA Scripts*, native aggregate oracle issues in *CTT UA Binary*); 12
drafts were already covered by existing reports (including GDS issues
11406–11413 by node-opcua and 11102 for the `opc.https`/`opc.wss`
endpoint selection); 5 are held back for further investigation.
`plans/ctt-issues.md` links every entry.

## CTT documentation (`plans/ctt-issues.md`, `plans/ctt-testing.md`)

- `ctt-issues.md` lists every failing CTT test case with a short
abstract and its Mantis issue; the details live in Mantis. It keeps the
defects not filed yet, the open questions (U1–U4), the open server
findings and the CTT project configuration notes, and no longer lists
findings the server has fixed.
- Notable CTT findings of this run: the aggregate oracle lacks the Part
13 Uncertain status and Calculated bit rules that #4477 implements
(C48/C49, 24 test cases); the CloseSession "delay in excess of 600ms"
warnings are a CTT client artifact (C50: the server answers in 2–5 ms,
the CTT stops the Session's SessionThread between stamping and sending);
the CTT's `FindTokenType` rewrites its cached endpoints, so Security
User Name Password 2 `015.js` reports duplicate PolicyIds (C36); A & C
Comment passes or skips depending on the date (C39).
- Open server finding: AddNodes after a child rename returns
`BadNodeIdExists` (#4477 × #4486 interaction, not covered by the CTT).
- `ctt-testing.md` is a runbook for agents: setup, headless runs,
selection generation, reading and comparing results, triage, recipes per
conformance group (A & C, Session/Subscription, Monitored Items,
security groups with an isolated PKI) and a full partitioned run of
every group (about 80 minutes). It points to `ctt-issues.md` for the
failures to expect.

## Related Issues

- Follow-up to #4477, #4482, #4485, #4486

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [ ] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

Validated locally with a full partitioned CTT run of the Release net10.0
reference server (reverted code, `ChannelLifetime` 120000).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 21:52:44 +02:00
Copilot d525bc3f28 Bound reconnect cleanup and organize samples by domain (#4276)
# Description

This PR fixes bounded ManagedSession reconnect cleanup and reorganizes
the sample applications into domain-focused folders.

## Reconnect cleanup

- Bounds reconnect integration cleanup with independent 30-second close
and dispose limits.
- Sends `CloseSession` through the awaited transport request path during
`Session.DisposeAsync`.
- Preserves explicit `Session.CloseAsync` behavior that waits for or
cancels outstanding publish requests.
- Covers the disposal request path with a regression test.

## Sample organization

- `samples/OpenUsd`: `GeneratorServer`, `SiteCompositionServer`
- `samples/Redundancy`: `RedundantClient`, `RedundantServer`,
`RedundantPubSub`
- `samples/Isa95`: `MinimalIsa95Server`
- `samples/MinimalApi`: `MinimalBoilerServer`, `MinimalCalcServer`,
`MinimalClient`
- `samples/DI`: `PumpDeviceIntegrationServer`
- `samples/Lds`: `ConsoleLdsServer`
- `samples/Reference`: `ConsoleReferenceClient`,
`ConsoleReferenceServer`
- `samples/PubSub`: `ConsoleReferencePubSubClient`

`UA.slnx` now exposes the same requested domain groups. Project
references, tests, runtime sample probes, CI workflows, Dockerfiles,
Compose files, helper scripts, and documentation were updated to the new
paths. `samples/Robotics/MinimalRobotServer` remains under `Robotics`.

## Validation

- `dotnet build UA.slnx`
- 3 Redundancy short-haul sample tests
- 70 DI sample tests
- 914 OpenUSD tests
- 1 WotCon model-materialization test
- 137 AOT tests
- `docker compose config` for all 6 moved Redundancy Compose files

## Related Issues

- Fixes #4273

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce new build or
analyzer warnings.
- [x] I built the complete `UA.slnx` solution locally.
- [ ] I ran all tests locally against at least .NET Framework and .NET
10.
- [ ] I fixed all failing and flaky tests in the CI pipelines and all
CodeQL warnings.
- [x] I have addressed all PR feedback received.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Co-authored-by: Marc Schier <mschier@microsoft.com>
Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
Copilot-Session: a2c2838f-74ae-4997-a1d4-50574d9e0636
2026-08-21 04:35:47 +00:00