This file is the authoritative direction for future coding agents working on this repository.
Product name: Process Bus Timing Lab
Current module name: PTP Lab Clock Simulator / PtpLabClock
Target users: IEC 61850 process bus engineers, FAT/SAT engineers, protection/automation test engineers, and developers validating SV/GOOSE/PTP analyzers.
The product is not a GPS/PTP grandmaster replacement. It is a Windows-friendly lab simulator and diagnostic companion for quick PTP visibility checks, analyzer validation, Pdelay response testing, and controlled fault scenarios.
The repository is licensed as Apache-2.0.
Rules:
- Keep the
LICENSEfile as the full Apache License 2.0 text. - Keep
Directory.Build.propswithPackageLicenseExpression=Apache-2.0. - Add REUSE/SPDX-compatible Apache-2.0 license headers to new source files. Keep examples out of Markdown prose so REUSE does not parse them as real file metadata.
- Do not copy source code from linuxptp, Meinberg, PTPSync, Npcap samples, SharpPcap samples, or other references unless a license review explicitly permits it.
- Do not bundle Npcap installer by default. Link to Npcap install instructions instead.
- Maintain
THIRD-PARTY-NOTICES.mdwhenever dependencies change. - Keep Demo Mode and protocol validation independent from any raw packet dependency.
We may study public behavior and architecture, but implementation must remain our own.
- Manager UI controls an engine/service.
- Clear adapter selection and configuration workflow.
- Service mode can be added later after the engine is stable.
- Logs and status must be visible to non-developer engineers.
- Separate clock, port, transport, message serialization, scheduler, profile, and diagnostics.
- Transport must be abstracted so Layer-2, UDP, demo, and future replay modes do not leak into UI.
- Hardware timestamping, PHC, clock servo, BMCA, boundary clock, and transparent clock are future/non-MVP features.
- Current app must not adjust OS time.
- Engineer needs visibility: detected GM, domain, profile, message rates, master change, interval issues.
- Status views must be readable at a glance.
- Diagnostic timeline is as important as raw packet counters.
Never put packet/protocol logic inside WPF views or ViewModels.
Recommended responsibilities:
PtpLabClock.App
WPF manager UI only: commands, binding, visual status, event presentation.
PtpLabClock.Core
Engine orchestration, scheduler, counters, scenarios, diagnostics, runtime state.
PtpLabClock.Protocol
PTP header/body serialization, Ethernet frame builder, parser/validator.
PtpLabClock.Pcap
RAW packet transport boundary. Keep any future Npcap/wrapper implementation isolated here after license review.
PtpLabClock.Config
JSON profile/settings storage only.
PtpLabClock.Console
CLI smoke tests and Wireshark validation runner.
Status: active.
- Apache-2.0 license.
- Clean-room policy.
- Safety disclaimer.
- Demo Mode must always work without Npcap.
- RAW Mode must clearly say Npcap/admin/NIC requirements.
Goal: Wireshark-decodable PTPv2 packets.
Tasks:
- Split serializer into explicit message classes:
PtpHeader,AnnounceBody,SyncBody,FollowUpBody,PdelayRespBody. - Add unit tests for byte offsets, messageType, versionPTP, messageLength, domain, flags, correctionField, sourcePortIdentity, sequenceId, controlField, logMessageInterval.
- Validate Ethernet frame layout: destination MAC, source MAC, EtherType
0x88F7, payload length. - Add PCAP sample export from Console mode.
Do not add fancy features until Wireshark validation is reliable.
Goal: stable raw Ethernet TX/RX on Windows.
Tasks:
- Harden
NpcapPtpTransporterror messages. - Add adapter capability display: description, MAC address if available, status hint.
- Use VLAN-aware BPF filter
ether proto 0x88f7 or (vlan and ether proto 0x88f7) or (vlan and vlan and ether proto 0x88f7)by default. - Add clear failure hints: not admin, Npcap missing, adapter cannot transmit, selected Wi-Fi/VPN adapter unsuitable.
- Keep Console runner for smoke tests.
Goal: quick IED response check and analyzer Pdelay visibility.
Tasks:
- Parse incoming
Pdelay_Reqrobustly. - Respond with
Pdelay_RespandPdelay_Resp_Follow_Upusing matching sequenceId and requestingPortIdentity. - Track per-peer Pdelay counters.
- Add peer table:
ClockIdentity, last seen, sequence, request rate, response count. - Add scenario: stop Pdelay reply, delayed Pdelay reply, wrong sequence.
Goal: product becomes diagnostic companion, not only simulator.
Tasks:
- Passive monitor mode for existing PTP networks.
- Detected grandmaster list.
- Domain list.
- Message rates and interval checker.
- Follow_Up pairing checker.
- Multiple GM warning.
- GM switch event detection.
- Profile guess: Generic / IEC 61850-9-3-like / C37.238-like / Unknown.
Goal: analyzer-grade diagnostic states.
Tasks:
- Add health cards: Visibility, Profile, Stability, Pdelay, Analyzer Readiness.
- Add scenario timeline player with start/stop/restore.
- Scenarios: GM Lost, Wrong Domain, Missing Follow_Up, Clock Degraded, Sequence Jump, GM Switch, Sync Jitter, Multiple GM conflict.
- Each scenario must emit event-log entries suitable for report export.
Goal: FAT/lab/customer communication.
Tasks:
- Export Markdown first, then DOCX/PDF later.
- Include selected adapter, profile settings, domain, GM identity, scenario actions, counters, warnings, and timeline.
- Keep report wording conservative: lab simulator, not timing accuracy validation.
Goal: become part of a full Process Bus engineering suite.
Tasks:
- Add PTP Timing tab in Process Bus Analyzer.
- Correlate PTP health with SV stream stale/live and GOOSE event timeline.
- Unified event journal: PTP lost → SV timestamp warning → GOOSE/SV observation.
Use a modern web-dashboard feel, not default WPF.
Rules:
- Calm bright premium background.
- Segmented pill navigation/profile controls.
- Smooth hover/press states; buttons should feel tactile but not chaotic.
- Typography: regular/medium, clear hierarchy, not bulky.
- Use numbers boldly only where they are key counters.
- Do not overload the main screen with raw fields.
- Main hierarchy:
- status and mode,
- profile/domain/GM identity,
- live flow counters,
- scenarios,
- event timeline.
Allowed product claims:
- Synthetic PTP traffic generator.
- Lab clock simulator.
- Analyzer validation companion.
- Quick sync visibility check.
- Pdelay response simulator.
- PTP diagnostic monitor.
Forbidden product claims unless future certified implementation exists:
- GPS grandmaster replacement.
- Certified timing source.
- Nanosecond accuracy validation.
- Protection-class time reference.
- FAT/SAT official grandmaster.
- Prefer small, readable classes.
- Avoid heavy frameworks unless truly needed.
- No Prism/MVVM framework until the UI becomes too large.
- Keep ViewModels simple and testable.
- Use async cancellation correctly.
- Never block UI thread during capture/transmit.
- Prefer explicit error logs over swallowed exceptions.
- Demo Mode must not break when RAW Mode fails.
- Fix any Visual Studio build errors reported by user.
- Add protocol unit tests for byte offsets, message lengths, flags, sequence IDs, and timestamp pairing.
- Add Console/Wireshark validation runner that prints selected adapter + TX sequence IDs.
- Add passive parser for Announce, Sync, and Follow_Up.
- Add peer table for Pdelay requesters and detected grandmasters.
- Start Passive Monitor mode.
Visual design is locked unless a change is strictly required for usability. New work must focus on engine verification:
- Run
dotnet run -- --validate-protocol --domain 0fromsrc/PtpLabClock.Consoleafter packet builder changes. - Keep TX frames Wireshark-verifiable with
eth.type == 0x88f7. - Do not bypass
PtpFrameInspectorfor outbound frame sanity checks. - Event logs should help correlate engine TX/RX sequence IDs with Wireshark captures.
- Any future UDP or VLAN feature must preserve the Layer-2 validation baseline first.
- Visual design is locked unless a change directly supports test evidence visibility.
- Prefer byte-level protocol validation and Wireshark-verifiable outputs over new visual features.
- PCAP files must be classic Ethernet PCAP unless pcapng metadata becomes necessary.
- Keep recorder code dependency-free and simple; do not introduce heavy capture frameworks. Any future packet wrapper must stay isolated in
PtpLabClock.Pcapafter license review. - Use
--validate-protocol --export-pcapfor deterministic builder evidence before live NIC testing. - Use
--record-pcapfor live TX/RX evidence capture during raw adapter tests.
Visual design is locked. Do not redesign the UI unless a new data surface is strictly required.
Engine direction after v13:
- Passive monitor must decode RX PTP frames using
PtpFrameInspector. - Track detected domains, message types, source clock identities, sequence IDs, and last-seen timestamps.
- Console monitor mode is the first validation surface.
- Do not claim compliance or timing accuracy from passive monitoring alone.
- Next phase should convert monitor snapshots into Timing Health Validator Lite statuses.
- Visual design remains locked.
- Health diagnostics must be derived from passive monitor snapshots.
- Use PASS / WARN / FAIL wording for engineering readability.
- Do not claim timing accuracy validation.
- Initial health checks are PTP Visibility, Domain Match, GM Stability, Follow_Up Pairing, Pdelay Activity, Sequence Continuity, and Analyzer Readiness.
- Console
--healthmode is the reference path for validator testing.
- Visual design remains locked.
- WPF dashboard now surfaces Timing Health Validator results as compact diagnostic cards.
- Health UI is driven by
PtpMasterEngine.MonitorSnapshotUpdatedandPtpTimingHealthValidator. - Do not add major visual redesign in health-card work; keep it compact and diagnostic-oriented.
Visual design remains locked. v16 adds PtpLabClock.Reporting, an isolated evidence report module. Keep this module isolated from Core so protocol/engine code does not depend on PDF rendering. Do not overclaim timing accuracy. All generated reports must preserve lab-only safety wording.
The current report generator uses a small internal Apache-2.0 PDF writer to avoid external PDF licensing friction. If a third-party PDF package is added later, update THIRD-PARTY-NOTICES.md and review license compatibility first.
The WPF app may expose a compact Export PDF action. Keep visual design locked. Use PtpSessionReportGenerator.GeneratePdf through the reporting project. Reports are engineering/lab evidence only, not timing-accuracy certificates.
- Keep visual design locked.
- Evidence package export is implemented as a ZIP bundle containing
report.pdf,session.json,events.csv,metadata.json, andREADME.txt. - Use
PtpSessionPackageExporter.ExportZip(...)for ZIP package export. - Do not put PCAP files into the package automatically until the recorder lifecycle and selected path are explicitly tracked by the UI.
- Keep report/package generation inside
PtpLabClock.Reporting; Core must stay independent from PDF/ZIP concerns.