Repository navigation
PTP-P1: portable PTPv2 core and ESP32-P4 hardware-timestamped lab broadcaster - #62
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ec760427e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| std::vector<std::uint8_t> PtpCodec::build_pdelay_req(const PtpBuildOptions& options) { | ||
| return build_timestamp_message(PtpMessageType::pdelay_req, options, 0x05U); |
There was a problem hiding this comment.
Append the reserved tail to Pdelay_Req
When build_pdelay_req() is used, it emits only the 10-byte origin timestamp, producing a 44-byte message. A PTPv2 Pdelay_Req also requires a 10-byte reserved field and therefore has a 54-byte message length; conforming peers can discard the current encoding instead of participating in peer delay.
Useful? React with 👍 / 👎.
| if (report.is_healthy()) { | ||
| return SmpSynchValue::global_synchronized; | ||
| } | ||
| if (allow_local_fallback && report.snapshot.has_ptp()) { | ||
| return SmpSynchValue::local_synchronized; |
There was a problem hiding this comment.
Keep packet visibility from promoting smpSynch
When a caller uses this resolver to populate an SV ASDU, a healthy report proves only recent packet visibility, domain/profile matching, and message counts—not that the sampling clock is disciplined—yet it returns global_synchronized; even a report that failed liveness becomes local_synchronized by default as long as any historical PTP packet exists. This can publish a false synchronization claim, so promotion should require explicit measured lock/holdover state rather than passive-monitor health.
Useful? React with 👍 / 👎.
| config AR_PTP_VLAN_ID | ||
| int "PTP VLAN ID" | ||
| range 0 4095 | ||
| default 0 |
There was a problem hiding this comment.
Reject reserved VLAN ID 4095 in configuration
When CONFIG_AR_PTP_VLAN_ID=4095, Kconfig accepts the value and the PTP codec also lets it through, but VlanTag::to_tag_control_information() rejects IDs above 4094 and throws during frame encoding. With tagged PTP enabled, this permitted configuration can terminate the PTP task before it transmits traffic; constrain the option to 0..4094.
Useful? React with 👍 / 👎.
| const auto message_count = source.count(type); | ||
| if (message_count != 0U) { | ||
| checks.push_back({ | ||
| std::move(id), | ||
| PtpHealthSeverity::ok, | ||
| std::move(label) + " messages are visible from " + port_identity_text(source.source_port_identity) + ".", |
There was a problem hiding this comment.
Limit message-presence checks to the liveness window
When Sync/Follow_Up transmission stops but another message such as Announce continues, the source remains active while these lifetime counters stay nonzero, so the analyzer reports Sync and Follow_Up as healthy indefinitely. Presence checks need per-message timestamps or counts restricted to source_timeout; otherwise a capture containing an old successful exchange can conceal a current timing failure.
Useful? React with 👍 / 👎.
| if (options.require_follow_up_for_two_step) { | ||
| add_presence_check(checks, *selected, PtpMessageType::follow_up, "ptp.followup", "Follow_Up"); |
There was a problem hiding this comment.
Require Follow_Up only for two-step Sync
For a valid one-step PTP source, Sync carries its timestamp and no Follow_Up is sent, but the default analyzer unconditionally runs this failure-producing presence check. Consequently ordinary one-step captures are reported unhealthy despite the option being named require_follow_up_for_two_step; track whether the selected source's Sync is two-step before requiring Follow_Up.
Useful? React with 👍 / 👎.
Purpose
Port the ARIEC61850/ARSVIN laboratory PTP stack to the C++ ARStack core and establish the ESP32-P4 timing path needed for SMV troubleshooting/interoperability when a station GPS/PTP server is not yet available.
This is intentionally not a GPS-backed or certified grandmaster. The product role is a lab/field timing companion that can temporarily close the process-bus test gap when a relay requires PTP before it will accept/read Sampled Values.
The same portable C++ PTP core is also the foundation for the future PTP/SMV Analyzer.
PTP-P1 scope implemented
Portable C++ core
0x88F7transportSpecificencode/decode and evidence trackingtransportSpecificmismatch/change diagnosticssmpSynchpolicy primitivesariec61850_ptp_analyzePCAP CLItransportSpecificsmpSynch=0ESP32-P4 lab timing companion
PTP remains default OFF and is enabled explicitly with
CONFIG_AR_PTP_LAB_TX=y.transportSpecific0xFFFFvariance / internal oscillatort2)t2t3)t3transportSpecificAnalyzer direction
The portable parser/monitor is intentionally independent of ESP-IDF and desktop capture libraries. The PCAP CLI already exercises the read-only analyzer direction, and the same core can be reused by a future live ESP32-P4 PTP/SMV analyzer.
The analyzer reports domain, source identity,
transportSpecific, VLAN/QinQ visibility, Announce/Sync/Follow_Up/Pdelay counts, sequence anomalies andtransportSpecificstability. This directly supports diagnosis of cases where PTP is visible in Wireshark but a strict relay ignores it because profile/network identity differs.Current ESP32 RX ownership is suitable for the standalone raw-L2 injector. A future combined analyzer should introduce one shared RX dispatcher rather than competing Ethernet input callbacks.
Validation gates
Dedicated CI covers:
-Werror)-Werror)/W4 /WX)transportSpecific=1, VLAN 100 and PCP 4 so configurable bindings are compiled rather than left as dead configuration pathsThe hardware-timestamped Sync and hardware RX/TX Pdelay paths compile in the ESP32-P4 PTP-enabled profile.
smpSynchboundaryPTP traffic visibility is not treated as proof that the SV sampling clock is disciplined.
PTP-P1 therefore does not automatically promote canonical SMV
smpSynchmerely because the local PTP broadcaster is running. AutomaticsmpSynchpromotion remains reserved for a later measured lock/holdover model.Deliberately deferred
smpSynch=1/2Bench acceptance next
docs/PTP_LAB_TIMING.mddefines the physical runbook. The first relay test should retain evidence for:transportSpecific/ VLAN binding;t2/t3;The PR remains draft until the software CI gates are clean. Physical interoperability is a separate acceptance step.