Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Mqtt.IntegrationTests/SparkplugSimulator/SparkplugEdgeNodeOptions.cs
T
Joseph Doherty 767e7031b3 test(mqtt): C# Sparkplug edge-node simulator + §3.6 live matrix
Adds a project-owned, controllable Sparkplug B edge node (SparkplugEdgeNode) that
encodes with the SAME generated Tahu schema the driver decodes with — so the live
gate checks encode/decode symmetry rather than the driver against itself — and
drives the §3.6 matrix end-to-end over the real TLS+auth Mosquitto fixture.

The simulator frames its topics independently of SparkplugTopic.Format: a
simulator borrowing the parser's formatter could not detect a bug in it, because
both sides of the comparison would be wrong together. It registers a real NDEATH
Last Will at CONNECT, restarts seq at 0 on NBIRTH, publishes DATA metrics as
alias-only, carries bdSeq per session, and encodes signed ints as two's
complement in the unsigned proto field.

SparkplugLiveTests (Category=LiveIntegration, env-gated, skip-clean) covers:
birth -> alias-only data -> OnDataChange under the RawPath; late-join rebirth
NCMD honoured by an independent decoder; alias reuse across a rebirth routing by
metric NAME; a stale-bdSeq NDEATH ignored while the current one stales; the real
broker-published Will staling and the next birth restoring; seq wrap 255->0
requesting no rebirth while a deliberate gap does; and the browser's passive
window asserted ON THE WIRE (a third client watching spBv1.0/{group}/NCMD/#),
plus RequestRebirthAsync node-vs-group enumeration.

Two things make the suite falsifiable rather than decorative: the seq-wrap test
builds its ingestor with rebirthDebounce: TimeSpan.Zero (at the shipped 10s
default a wrap-triggered NCMD would be swallowed and the test would pass for the
wrong reason) and pairs the silence with a deliberate gap that must produce one;
and the passivity assertion observes the broker rather than the session's own
publish counter, which can only see the seam it guards.

Docker/docker-compose.yml gains a profile-gated `sparkplug-sim` service running
the same engine standalone against the same broker (TLS, CA-pinned) — a manual
driving aid for the AdminUI picker, deliberately NOT a test dependency, since the
matrix needs an edge node it can command mid-test. Its app directory is publish
output (publish-simulator.sh), gitignored like secrets/.

Offline: 15 skipped, 0 failed with no env set. Live: 15/15 passed against
10.100.0.35:8883. Falsifiability spot-check: mutating AliasTable.RebuildFromBirth
to merge instead of replace, and neutering SparkplugCodec.ReinterpretSigned for
Int32, turned exactly the two corresponding tests red and nothing else; both
mutations reverted.

Claude-Session: https://claude.ai/code/session_01GASWkNEi68FSCtvr6rLoEW
2026-07-24 23:18:08 -04:00

59 lines
2.5 KiB
C#

namespace ZB.MOM.WW.OtOpcUa.Driver.Mqtt.SparkplugSimulator;
/// <summary>
/// Connection + identity settings for one simulated Sparkplug B edge node.
/// </summary>
/// <remarks>
/// Deliberately its own shape rather than a reuse of the driver's <c>MqttDriverOptions</c>: an edge
/// node is the driver's <i>counterparty</i>, and reusing the driver's options record would drag the
/// driver assembly into this project and blur which side of the wire a setting belongs to. The TLS
/// knobs mirror the driver's by name so a rig configured for one is configured for the other.
/// </remarks>
public sealed record SparkplugEdgeNodeOptions
{
/// <summary>Broker hostname or IP.</summary>
public string Host { get; init; } = "localhost";
/// <summary>Broker TCP port.</summary>
public int Port { get; init; } = 8883;
/// <summary>Connect over TLS.</summary>
public bool UseTls { get; init; } = true;
/// <summary>
/// PEM CA file pinning the broker chain. <see langword="null"/>/empty falls back to the OS
/// trust store (or to <see cref="AllowUntrustedServerCertificate"/> when that is set).
/// </summary>
public string? CaCertificatePath { get; init; }
/// <summary>Accept any broker certificate. Fixture escape hatch; never a deployment posture.</summary>
public bool AllowUntrustedServerCertificate { get; init; }
/// <summary>Broker username. The fixture broker runs <c>allow_anonymous false</c>.</summary>
public string? Username { get; init; }
/// <summary>Broker password.</summary>
public string? Password { get; init; }
/// <summary>The Sparkplug group id this node publishes under.</summary>
public string GroupId { get; init; } = "Plant1";
/// <summary>The Sparkplug edge-node id.</summary>
public string EdgeNodeId { get; init; } = "EdgeA";
/// <summary>
/// MQTT client id. Left unset a unique one is generated — two simulated nodes sharing a client
/// id would knock each other off the broker.
/// </summary>
public string? ClientId { get; init; }
/// <summary>Bounded connect/publish deadline, in seconds.</summary>
public int TimeoutSeconds { get; init; } = 15;
/// <summary>
/// QoS for NBIRTH/DBIRTH/NDATA/DDATA/DDEATH. Sparkplug B publishes all of these at QoS 0
/// (only NDEATH — the broker-issued Will — and STATE are QoS 1), which is the default here.
/// </summary>
public int DataQos { get; init; }
}