introduce PTP protocol library and software relay example
Subsystems (2)
cover introduce PTP protocol library and software relay example
This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (ptp_tap_relay_sw) that demonstrates its usage.
Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification: rte_ptp_classify() detects PTP over L2
(EtherType 0x88F7), VLAN-tagged L2, and UDP/IPv4 (ports 319/320)
- Header access: rte_ptp_hdr_get() returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug: rte_ptp_msg_type_str() for human-readable message names
The API is experimental (targeted for 26.07). Dependencies are minimal:
mbuf and net libraries only.
Example: ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.
The relay:
1. Receives packets on the physical NIC via DPDK
2. Classifies PTP packets using rte_ptp_classify()
3. For event messages, records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress
4. Adds residence time to correctionField via rte_ptp_add_correction()
(IEEE 1588-2019 §10.2 Transparent Clock)
5. Forwards bidirectionally: PHY <-> TAP
A two-pass design takes the TX timestamp as close to rte_eth_tx_burst() as possible, minimising untracked delay.
Test Results
------------
Test setup: Intel E610 10GbE NIC (vfio-pci), ptp4l master with HW timestamps on physical port, ptp4l slave with SW timestamps (-S) on TAP interface, logSyncInterval=-4 (16 Sync/sec), 120s duration.
Post-convergence (60s of locked data):
Average RMS offset: 929 ns
Worst max offset: 11615 ns (single transient)
Steady-state range: 489 - 1055 ns RMS
Corrections applied: 3635linuxptp's PI servo uses relaxed gains for software timestamps (kp=0.1, ki=0.001 vs kp=0.7, ki=0.3 for HW), expecting ~5-50 µs jitter. Sub-microsecond RMS is achieved here because the master uses HW timestamps and DPDK's poll-mode relay provides deterministic low-latency forwarding.
Rajesh Kumar (4):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide
MAINTAINERS | 7 + doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 195 ++++++++ doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 210 +++++++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 424 ++++++++++++++++++ lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 195 ++++++++ lib/ptp/rte_ptp.h | 328 ++++++++++++++ 15 files changed, 1426 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
Signature · 1 line
2.52.0
RFC 1/4 ptp: introduce PTP protocol library
Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType 0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Public APIs:
1. rte_ptp_classify()
2. rte_ptp_hdr_get()
3. rte_ptp_msg_type_str()
--- MAINTAINERS | 5 + lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 195 ++++++++++++++++++++++++++ lib/ptp/rte_ptp.h | 328 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 535 insertions(+) create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
MAINTAINERS +5 -0
@@ -1665,6 +1665,11 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - EXPERIMENTAL +M: Rajesh Kumar <[email protected]> +F: lib/ptp/ +F: doc/guides/prog_guide/ptp_lib.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
lib/meson.build +1 -0
@@ -50,6 +50,7 @@ libraries = [ 'member', 'pcapng', 'power', + 'ptp', 'rawdev', 'regexdev', 'mldev',
lib/ptp/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +sources = files('rte_ptp.c') +headers = files('rte_ptp.h') +deps += ['mbuf', 'net']
lib/ptp/rte_ptp.c new file +195 -0
195 lines not on this page · raw message
lib/ptp/rte_ptp.h new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [RFC v1 1/4] ptp: introduce PTP protocol library
lib/ptp/rte_ptp.c line 132
Quoted 3 lines · On Tue, 28 Apr 2026 06:31:03 +0530 Rajesh Kumar <[email protected]> wrote:
lib/ptp/rte_ptp.c new file +3
-0+const struct rte_udp_hdr *udp = + (const struct rte_udp_hdr *) + ((const uint8_t *)eth + offset);
Use rte_pktmbuf_mtod_offset() avoid pointer math as error prone.
Re: [RFC v1 1/4] ptp: introduce PTP protocol library
Quoted 7 lines · Stephen Hemminger
lib/ptp/rte_ptp.c line 132
Quoted 3 lines · On Tue, 28 Apr 2026 06:31:03 +0530 Rajesh Kumar <[email protected]> wrote:
lib/ptp/rte_ptp.c new file +3
-0+const struct rte_udp_hdr *udp = + (const struct rte_udp_hdr *) + ((const uint8_t *)eth + offset);Use
rte_pktmbuf_mtod_offset()avoid pointer math as error prone.
Fixed.
RFC 2/4 doc: add PTP library programmer's guide
In reply to Rajesh KumarAdd programmer's guide for the PTP protocol library covering message types, header structures, packet classification API, inline helpers, and usage examples.
Add PTP header to Doxygen API index under layers section.
--- doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 195 ++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst
doc/api/doxy-api-index.md +1 -0
@@ -137,6 +137,7 @@ The public API headers are grouped by topics: [eCPRI](@ref rte_ecpri.h), [PDCP hdr](@ref rte_pdcp_hdr.h), [PDCP](@ref rte_pdcp.h), + [PTP](@ref rte_ptp.h), [L2TPv2](@ref rte_l2tpv2.h), [PPP](@ref rte_ppp.h), [IB](@ref rte_ib.h)
doc/api/doxy-api.conf.in +1 -0
@@ -72,6 +72,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ @TOPDIR@/lib/pmu \ @TOPDIR@/lib/port \ @TOPDIR@/lib/power \ + @TOPDIR@/lib/ptp \ @TOPDIR@/lib/ptr_compress \ @TOPDIR@/lib/rawdev \ @TOPDIR@/lib/rcu \
doc/guides/prog_guide/index.rst +1 -0
@@ -97,6 +97,7 @@ Protocol Processing Libraries :maxdepth: 1 :numbered: + ptp_lib pdcp_lib ipsec_lib
doc/guides/prog_guide/ptp_lib.rst new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
2.52.0
RFC 3/4 examples/ptp_tap_relay_sw: add software PTP relay example
In reply to Rajesh KumarAdd a minimal PTP Transparent Clock relay that bridges PTP packets between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only.
The relay uses the rte_ptp library for packet classification and correctionField manipulation. For each PTP event message, it records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress, then adds the residence time to the correctionField per IEEE 1588-2019 section 10.2.
A two-pass design is used: first all packets are classified and PTP header pointers saved, then a single TX timestamp is taken immediately before applying corrections and calling rte_eth_tx_burst(). This minimises the gap between the measured timestamp and actual wire egress.
--- MAINTAINERS | 2 + examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 424 +++++++++++++++++++ 5 files changed, 482 insertions(+) create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
MAINTAINERS +2 -0
@@ -1669,6 +1669,8 @@ PTP - EXPERIMENTAL M: Rajesh Kumar <[email protected]> F: lib/ptp/ F: doc/guides/prog_guide/ptp_lib.rst +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]>
examples/meson.build +1 -0
@@ -43,6 +43,7 @@ all_examples = [ 'packet_ordering', 'pipeline', 'ptpclient', + 'ptp_tap_relay_sw', 'qos_meter', 'qos_sched', 'rxtx_callbacks',
examples/ptp_tap_relay_sw/Makefile new file +41 -0
41 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +allow_experimental_apis = true +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net', 'ptp'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +424 -0
424 lines not on this page · raw message
Signature · 1 line
2.52.0
RFC 4/4 doc: add PTP software relay sample app guide
In reply to Rajesh KumarAdd a sample application user guide for the ptp_tap_relay_sw example. The guide covers the application topology, packet flow, compilation, command-line options, and a code walkthrough explaining the two-pass relay burst design and CLOCK_MONOTONIC_RAW timestamp source selection.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 210 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 18 lines · On Tue, 28 Apr 2026 06:31:02 +0530 Rajesh Kumar <[email protected]> wrote:
This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (
ptp_tap_relay_sw) that demonstrates its usage.Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient,ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification:rte_ptp_classify()detects PTP over L2
Quoted 6 lines
(EtherType 0x88F7), VLAN-tagged L2, and UDP/IPv4 (ports 319/320)- Header access:
rte_ptp_hdr_get()returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug:rte_ptp_msg_type_str()for human-readable message names
The things I noticed were:
Do not use older PTP terminology master/slave; we fixed this in DPDK. This would cause a NAK for me, and checkpatch would flag it.
AI had lots more to say...
Subject: Re: [RFC v1 0/4] introduce PTP protocol library and software relay example
Some review comments on this RFC. Overall direction (shared PTP header+classification library) is good, but there are a couple of correctness bugs in patch 1/4 that need to be fixed before this can move out of RFC.
Patch 1/4: ptp: introduce PTP protocol library
==============================================
Error: flag bit positions wrong for the host-order representation
-----------------------------------------------------------------
+#define RTE_PTP_FLAG_TWO_STEP (1 << 1) /**< Two-step flag (bit 1) */ +#define RTE_PTP_FLAG_UNICAST (1 << 2) /**< Unicast flag */ +#define RTE_PTP_FLAG_LI_61 (1 << 0) /**< Leap indicator 61 */ +#define RTE_PTP_FLAG_LI_59 (1 << 1) /**< Leap indicator 59 (byte 1) */
+static inline bool +rte_ptp_is_two_step(const struct rte_ptp_hdr *hdr) +{
+ return (rte_be_to_cpu_16(hdr->flags) & RTE_PTP_FLAG_TWO_STEP) != 0;
+}
twoStepFlag and unicastFlag live in byte 0 of the wire flag field (IEEE 1588-2019 Table 37). leap61/leap59 live in byte 1. After rte_be_to_cpu_16(), byte 0 of the wire ends up in the upper 8 bits of the host value, so:
TWO_STEP needs to be (1 << 9), not (1 << 1)
UNICAST needs to be (1 << 10), not (1 << 2) LI_61 stays at (1 << 0) LI_59 stays at (1 << 1)
As written, rte_ptp_is_two_step() always returns false for any real two-step Sync from the wire, which silently breaks any Transparent Clock or Boundary Clock built on this library. TWO_STEP and LI_59 also collide on (1 << 1), which by itself shows the macro layout isn't right.
Worth adding a unit test that constructs a packet with twoStepFlag set and checks that the helper returns true.
Error: QinQ classification path is unreachable for standard QinQ
----------------------------------------------------------------
In ptp_hdr_find(), the VLAN block is only entered when the outer EtherType is RTE_ETHER_TYPE_VLAN (0x8100):
+ if (ether_type == RTE_ETHER_TYPE_VLAN) {
...
+ /* Double-tagged VLAN (QinQ) */
+ if (ether_type == RTE_ETHER_TYPE_QINQ ||
+ ether_type == RTE_ETHER_TYPE_VLAN) {
Standard 802.1ad QinQ uses outer S-tag 0x88A8 (RTE_ETHER_TYPE_QINQ) followed by a C-tag 0x8100, then the payload EtherType. Packets with the typical S-tag outer never enter the VLAN branch at all, so the "QinQ supported" claim in the cover letter and the prog_guide does not match what the code does.
Either accept 0x88A8 as an entry point to the VLAN parser, or drop the QinQ claim from the documentation.
Warning: VLAN-tagged PTP-over-UDP not handled
---------------------------------------------
The classifier handles plain L2, VLAN-L2, IPv4-UDP, and IPv6-UDP, but there is no path for VLAN -> IPv4/IPv6 -> UDP -> PTP. This is a common deployment pattern. Not fatal, but please mention it in the limitations list if it's intentional.
Warning: signed left shift in rte_ptp_add_correction()
------------------------------------------------------
+ int64_t cf = (int64_t)rte_be_to_cpu_64(hdr->correction);
+ cf += (residence_ns << 16);
residence_ns is int64_t. Left-shift of a signed value where the shifted value is not representable in the result type is undefined behaviour (C11 6.5.7p4). In the relay example residence_ns is computed from (uint64_t)tx_ts - (uint64_t)rx_ts cast to int64_t, so clock noise or a tx_ts < rx_ts edge case turns this negative. GCC and clang happen to produce arithmetic shift, but please make it well-defined:
cf += (int64_t)((uint64_t)residence_ns << 16);
or just multiply by (1LL << 16).
Same issue, lower severity, in rte_ptp_correction_ns():
+ return (int64_t)rte_be_to_cpu_64(hdr->correction) >> 16;
Right-shift of a negative signed value is implementation-defined (not UB), but a divide expresses intent more clearly.
Info: include order
-------------------
+#include "rte_ptp.h"
+
+#include <eal_export.h>
eal_export.h is conventionally included with the other system / EAL headers, before the local rte_ptp.h.
Info: overlap with examples/ptpclient
-------------------------------------
ptpclient.c defines its own struct ptp_header / ptp_message. Since this series adds a shared library, it would be worth converting ptpclient as part of the series (or in a follow-up) to avoid duplicating the same definitions in-tree.
Patch 2/4: doc: add PTP library programmer's guide
==================================================
Just the QinQ wording carryover - prog_guide claims "Double VLAN (QinQ) + EtherType 0x88F7" but the code as posted only handles 0x8100/0x8100 nesting. Update either the code or the doc to match.
Patch 3/4: examples/ptp_tap_relay_sw
====================================
Warning: promiscuous enable failure on PHY port is not fatal
------------------------------------------------------------
+ ret = rte_eth_promiscuous_enable(port);
+ if (ret != 0)
+ LOG_ERR("Failed to enable promiscuous on port %u", port);
+
+ return 0;
For the PHY port this is what lets the relay see the PTP multicast group (01:1B:19:00:00:00 / 01:80:C2:00:00:0E). If it fails, the relay starts up looking healthy but never receives anything. At least exit on failure for the PHY port, or enable allmulticast explicitly so the failure mode is visible.
Info: per-burst single timestamp
--------------------------------
A single rx_ts and tx_ts is taken for the whole burst. At logSyncInterval=-4 (16 packets/sec) bursts are essentially always 1 packet so this doesn't matter, but at higher rates the early packets in a burst get under-corrected and the late ones over-corrected by up to a burst's worth of poll latency. Worth calling out in the comment block; the test results already imply single-packet bursts.
Info: missing release notes for new library
-------------------------------------------
Targeted at 26.07 per RTE_EXPORT_EXPERIMENTAL_SYMBOL. A new library should add an entry under "New Features" in doc/guides/rel_notes/release_26_07.rst.
Quoted 3 lines · Stephen Hemminger
things I noticed were:
Do not use older PTP terminology master/slave; we fixed this in DPDK. This would cause a NAK for me, and checkpatch would flag it
Fixed.
v2 cover introduce PTP protocol library and software relay
In reply to Rajesh KumarThis series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (ptp_tap_relay_sw) that demonstrates its usage.
Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification: rte_ptp_classify() detects PTP over L2
(EtherType 0x88F7), VLAN-tagged L2 (TPIDs 0x8100/0x88A8, single
or double), UDP/IPv4, UDP/IPv6 (ports 319/320), and VLAN-tagged
UDP variants - Header access: rte_ptp_hdr_get() returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug: rte_ptp_msg_type_str() for human-readable message names
The API is experimental (targeted for 26.07). Dependencies are minimal:
mbuf and net libraries only.
Example: ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.
The relay:
1. Receives packets on the physical NIC via DPDK
2. Classifies PTP packets using rte_ptp_classify()
3. For event messages, records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress
4. Adds residence time to correctionField via rte_ptp_add_correction()
(IEEE 1588-2019 §10.2 Transparent Clock)
5. Forwards bidirectionally: PHY <-> TAP
A two-pass design takes the TX timestamp as close to rte_eth_tx_burst() as possible, minimising untracked delay.
Unit Tests: app/test
--------------------
A comprehensive test suite (ptp_autotest) covers all library APIs:
- Packet classification across L2, VLAN, QinQ, IPv4-UDP, IPv6-UDP, and VLAN-tagged UDP encapsulations
- Flag bit position validation (TWO_STEP, UNICAST, LI_61, LI_59)
- correctionField manipulation and round-trip accuracy
- Timestamp conversion, message type helpers, edge cases
- Negative tests: truncated packets, bad IHL, non-PTP traffic
33 test cases total.
ptpclient Conversion
--------------------
The existing ptpclient example is converted to use lib/ptp shared definitions (rte_ptp_hdr, rte_ptp_timestamp, rte_ptp_port_id, RTE_PTP_ETHERTYPE, RTE_PTP_MULTICAST_MAC), removing ~120 lines of duplicate struct and constant definitions.
Test Results
------------
Test setup: Intel E610 10GbE NIC (vfio-pci), ptp4l time transmitter with HW timestamps on physical port, ptp4l time receiver with SW timestamps (-S) on TAP interface, logSyncInterval=-4 (16 Sync/sec), 120s duration.
Post-convergence (60s of locked data):
Average RMS offset: 929 ns
Worst max offset: 11615 ns (single transient)
Steady-state range: 489 - 1055 ns RMS
Corrections applied: 3635linuxptp's PI servo uses relaxed gains for software timestamps (kp=0.1, ki=0.001 vs kp=0.7, ki=0.3 for HW), expecting ~5-50 µs jitter. Sub-microsecond RMS is achieved here because the time transmitter uses HW timestamps and DPDK's poll-mode relay provides deterministic low-latency forwarding.
v2:
Fixed below AI generated Review comments
- Fixed flag bit positions for host-order representation after
rte_be_to_cpu_16(): TWO_STEP (1<<9), UNICAST (1<<10),
LI_61 (1<<0), LI_59 (1<<1). Added unit test for all flags.
- Fixed QinQ classification: outer 0x88A8 (802.1ad S-tag) now
enters the VLAN parser alongside 0x8100. - Fixed signed left-shift UB in rte_ptp_add_correction(): shift is now performed on uint64_t before casting back to int64_t.
- Fixed promiscuous enable failure in relay example: port_init() now returns error instead of logging and continuing silently.
- Replaced deprecated master/slave PTP terminology with IEEE 1588-2019 terms (time transmitter / time receiver) throughout code and documentation.
- Documented per-burst single-timestamp design choice and its accuracy characteristics in the relay example.
- Added IHL validation (reject IHL < 20) in IPv4 PTP-over-UDP path.
- Changed rte_ptp_is_event() parameter from uint8_t to int with negative value guard for safe use with rte_ptp_classify() return.
- Changed rte_ptp_hdr_get() parameter from const to non-const mbuf since it returns a non-const pointer into packet data.
- All pointer accesses use rte_pktmbuf_mtod_offset() — no raw pointer arithmetic.
- Added programmer's guide note about avoiding double-parse when both message type and header pointer are needed.
Rajesh Kumar (6):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide app/test: add PTP library unit tests examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 8 + app/test/meson.build | 1 + app/test/test_ptp.c | 1052 +++++++++++++++++ doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 ++++ doc/guides/rel_notes/release_26_07.rst | 13 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 210 ++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 41 + examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 ++- lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 +++ lib/ptp/rte_ptp.h | 338 ++++++ 20 files changed, 2585 insertions(+), 116 deletions(-) create mode 100644 app/test/test_ptp.c create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
Signature · 1 line
2.53.0
RFC v2 1/6 ptp: introduce PTP protocol library
Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType 0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Public APIs:
1. rte_ptp_classify()
2. rte_ptp_hdr_get()
3. rte_ptp_msg_type_str()
--- MAINTAINERS | 7 + doc/guides/rel_notes/release_26_07.rst | 7 + lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 ++++++++++++++ lib/ptp/rte_ptp.h | 338 +++++++++++++++++++++++++ 6 files changed, 544 insertions(+) create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
MAINTAINERS +7 -0
@@ -1665,6 +1665,13 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - EXPERIMENTAL +M: Rajesh Kumar <[email protected]> +F: lib/ptp/ +F: doc/guides/prog_guide/ptp_lib.rst +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
doc/guides/rel_notes/release_26_07.rst +7 -0
@@ -63,6 +63,13 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol library.** + + Added a new library ``rte_ptp`` for IEEE 1588 Precision Time Protocol + packet processing. The library provides packet classification, header + parsing, and correctionField manipulation across L2, VLAN-tagged, + UDP/IPv4, and UDP/IPv6 transports. + Removed Items -------------
lib/meson.build +1 -0
@@ -50,6 +50,7 @@ libraries = [ 'member', 'pcapng', 'power', + 'ptp', 'rawdev', 'regexdev', 'mldev',
lib/ptp/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +sources = files('rte_ptp.c') +headers = files('rte_ptp.h') +deps += ['mbuf', 'net']
lib/ptp/rte_ptp.c new file +185 -0
185 lines not on this page · raw message
lib/ptp/rte_ptp.h new file +338 -0
338 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v2 2/6 doc: add PTP library programmer's guide
In reply to Rajesh KumarAdd programmer's guide for the PTP protocol library covering message types, header structures, packet classification API, inline helpers, and usage examples.
Add PTP header to Doxygen API index under layers section.
--- doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 ++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst
doc/api/doxy-api-index.md +1 -0
@@ -137,6 +137,7 @@ The public API headers are grouped by topics: [eCPRI](@ref rte_ecpri.h), [PDCP hdr](@ref rte_pdcp_hdr.h), [PDCP](@ref rte_pdcp.h), + [PTP](@ref rte_ptp.h), [L2TPv2](@ref rte_l2tpv2.h), [PPP](@ref rte_ppp.h), [IB](@ref rte_ib.h)
doc/api/doxy-api.conf.in +1 -0
@@ -72,6 +72,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ @TOPDIR@/lib/pmu \ @TOPDIR@/lib/port \ @TOPDIR@/lib/power \ + @TOPDIR@/lib/ptp \ @TOPDIR@/lib/ptr_compress \ @TOPDIR@/lib/rawdev \ @TOPDIR@/lib/rcu \
doc/guides/prog_guide/index.rst +1 -0
@@ -97,6 +97,7 @@ Protocol Processing Libraries :maxdepth: 1 :numbered: + ptp_lib pdcp_lib ipsec_lib
doc/guides/prog_guide/ptp_lib.rst new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v2 3/6 examples/ptp_tap_relay_sw: add software PTP relay example
In reply to Rajesh KumarAdd a minimal PTP Transparent Clock relay that bridges PTP packets between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only.
The relay uses the rte_ptp library for packet classification and correctionField manipulation. For each PTP event message, it records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress, then adds the residence time to the correctionField per IEEE 1588-2019 section 10.2.
A two-pass design is used: first all packets are classified and PTP header pointers saved, then a single TX timestamp is taken immediately before applying corrections and calling rte_eth_tx_burst(). This minimises the gap between the measured timestamp and actual wire egress.
--- doc/guides/rel_notes/release_26_07.rst | 6 + examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++++++++++++++ 5 files changed, 495 insertions(+) create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/rel_notes/release_26_07.rst +6 -0
@@ -70,6 +70,12 @@ New Features parsing, and correctionField manipulation across L2, VLAN-tagged, UDP/IPv4, and UDP/IPv6 transports. +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. + Removed Items -------------
examples/meson.build +1 -0
@@ -43,6 +43,7 @@ all_examples = [ 'packet_ordering', 'pipeline', 'ptpclient', + 'ptp_tap_relay_sw', 'qos_meter', 'qos_sched', 'rxtx_callbacks',
examples/ptp_tap_relay_sw/Makefile new file +41 -0
41 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +allow_experimental_apis = true +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net', 'ptp'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +433 -0
433 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v2 4/6 doc: add PTP software relay sample app guide
In reply to Rajesh KumarAdd a sample application user guide for the ptp_tap_relay_sw example. The guide covers the application topology, packet flow, compilation, command-line options, and a code walkthrough explaining the two-pass relay burst design and CLOCK_MONOTONIC_RAW timestamp source selection.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 210 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v2 5/6 app/test: add PTP library unit tests
In reply to Rajesh KumarAdd autotest for the PTP library covering:
- Transport classification (L2, VLAN, QinQ, UDP/IPv4, UDP/IPv6)
- Message type parsing and string conversion
- Inline helpers (is_event, two_step, seq_id, version, domain)
- Correction field arithmetic (add, accumulate, negative values)
- Timestamp nanosecond conversion
- Flag field extraction (TWO_STEP, UNICAST, LI_61, LI_59)
--- MAINTAINERS | 1 + app/test/meson.build | 1 + app/test/test_ptp.c | 1052 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1054 insertions(+) create mode 100644 app/test/test_ptp.c
MAINTAINERS +1 -0
@@ -1668,6 +1668,7 @@ F: app/test-sad/ PTP - EXPERIMENTAL M: Rajesh Kumar <[email protected]> F: lib/ptp/ +F: app/test/test_ptp.c F: doc/guides/prog_guide/ptp_lib.rst F: examples/ptp_tap_relay_sw/ F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
app/test/meson.build +1 -0
@@ -154,6 +154,7 @@ source_file_deps = { 'test_power_kvm_vm.c': ['power', 'power_kvm_vm'], 'test_prefetch.c': [], 'test_ptr_compress.c': ['ptr_compress'], + 'test_ptp.c': ['ptp'], 'test_rand_perf.c': [], 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'],
app/test/test_ptp.c new file +1052 -0
1,052 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v2 6/6 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarReplace local PTP struct and constant definitions with the shared rte_ptp.h library types introduced earlier in this series:
- struct ptp_header -> struct rte_ptp_hdr - struct tstamp -> struct rte_ptp_timestamp - struct clock_id -> uint8_t clock_id[8] (from rte_ptp_port_id)
- SYNC/FOLLOW_UP/DELAY_* defines -> RTE_PTP_MSGTYPE_* constants
- PTP_PROTOCOL -> RTE_PTP_ETHERTYPE
- hardcoded multicast -> RTE_PTP_MULTICAST_MAC
- ptp_hdr->msg_type switch -> rte_ptp_msg_type() accessor
No functional change.
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 +++++++++++++-------------------- 2 files changed, 73 insertions(+), 116 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['ptp'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +72 -116
323 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [RFC v2 0/6] introduce PTP protocol library and software relay
In reply to Rajesh KumarQuoted 11 lines · On Wed, 29 Apr 2026 03:58:31 +0530 Rajesh Kumar <[email protected]> wrote:
This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (
ptp_tap_relay_sw) that demonstrates its usage.Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient,ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
It would be great to have this, though not sure who would use it now.
AI review spotted some things.
Reviewed v2 of the PTP library series. Findings below. Patch 1/6 (lib/ptp):
RTE_PTP_ETHERTYPE 0x88F7 duplicates RTE_ETHER_TYPE_1588 already in lib/net/rte_ether.h. Use the existing constant or alias to it. Comment on the version byte says "reserved (4) | versionPTP (4)"; IEEE 1588-2019 redefined the upper nibble as minorVersionPTP.
Patch 2/6 (prog guide):
The guide declares rte_ptp_hdr_get(const struct rte_mbuf *m) but the header has it non-const. Fix the doc, or split into const and non-const variants since the function returns a writable interior pointer.
Patch 3/6 (ptp_tap_relay_sw):
The standalone Makefile is missing CFLAGS += -DALLOW_EXPERIMENTAL_API. All three rte_ptp_* APIs the relay uses are __rte_experimental, so make-based builds will warn or fail under -Werror. meson is fine because meson.build sets allow_experimental_apis = true. Match examples/ptpclient/Makefile. relay_burst() calls rte_ptp_classify() and then rte_ptp_hdr_get() on every event packet, parsing it twice. The prog guide added in 2/6 explicitly tells callers to use rte_ptp_hdr_get() once and then rte_ptp_msg_type(hdr). The reference example should follow its own guidance.
Minor: stats.corrections is updated via the global while the other counters are passed in by pointer. Inconsistent.
Patch 4/6 (sample app guide):
Limitations section claims L2-only and PTPv2-only, but the relay uses lib/ptp classification which handles VLAN/QinQ/UDPv4/UDPv6 with no version filter. Reword to "tested with L2 PTP" or drop the restriction.
Patch 5/6 (test_ptp.c):
Several correction tests dereference the rte_ptp_hdr_get() return without TEST_ASSERT_NOT_NULL: test_ptp_correction_zero, test_ptp_correction_known, and the four test_ptp_add_correction_* tests. test_ptp_two_step and test_ptp_seq_id get this right. No coverage for IPv4 with options (IHL > 5). The library's offset += ihl path is exercised by no test.
Patch 6/6: no issues.
RE: [RFC v2 0/6] introduce PTP protocol library and software relay
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: 29 April 2026 09:07 PM
To: Kumar, Rajesh3 <[email protected]>
Cc: [email protected]; Richardson, Bruce <[email protected]>; Singh, Aman Deep <[email protected]>
Subject: Re: [RFC v2 0/6] introduce PTP protocol library and software relay
Quoted 11 lines · On Wed, 29 Apr 2026 03:58:31 +0530 Rajesh Kumar <[email protected]> wrote:
This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (
ptp_tap_relay_sw) that demonstrates its usage.Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient,ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
It would be great to have this, though not sure who would use it now.
AI review spotted some things.
Reviewed v2 of the PTP library series. Findings below. Patch 1/6 (lib/ptp):
RTE_PTP_ETHERTYPE 0x88F7 duplicates RTE_ETHER_TYPE_1588 already in lib/net/rte_ether.h. Use the existing constant or alias to it. Comment on the version byte says "reserved (4) | versionPTP (4)"; IEEE 1588-2019 redefined the upper nibble as minorVersionPTP.
Patch 2/6 (prog guide):
The guide declares rte_ptp_hdr_get(const struct rte_mbuf *m) but the header has it non-const. Fix the doc, or split into const and non-const variants since the function returns a writable interior pointer.
Patch 3/6 (ptp_tap_relay_sw):
The standalone Makefile is missing CFLAGS += -DALLOW_EXPERIMENTAL_API. All three rte_ptp_* APIs the relay uses are __rte_experimental, so make-based builds will warn or fail under -Werror. meson is fine because meson.build sets allow_experimental_apis = true. Match examples/ptpclient/Makefile. relay_burst() calls rte_ptp_classify() and then rte_ptp_hdr_get() on every event packet, parsing it twice. The prog guide added in 2/6 explicitly tells callers to use rte_ptp_hdr_get() once and then rte_ptp_msg_type(hdr). The reference example should follow its own guidance.
Minor: stats.corrections is updated via the global while the other counters are passed in by pointer. Inconsistent.
Patch 4/6 (sample app guide):
Limitations section claims L2-only and PTPv2-only, but the relay uses lib/ptp classification which handles VLAN/QinQ/UDPv4/UDPv6 with no version filter. Reword to "tested with L2 PTP" or drop the restriction.
Patch 5/6 (test_ptp.c):
Several correction tests dereference the rte_ptp_hdr_get() return without TEST_ASSERT_NOT_NULL: test_ptp_correction_zero, test_ptp_correction_known, and the four test_ptp_add_correction_* tests. test_ptp_two_step and test_ptp_seq_id get this right. No coverage for IPv4 with options (IHL > 5). The library's offset += ihl path is exercised by no test.
Patch 6/6: no issues.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Fixed.
v3 cover introduce PTP protocol library and software relay
In reply to Rajesh KumarThis series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (ptp_tap_relay_sw) that demonstrates its usage.
Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification: rte_ptp_classify() detects PTP over L2
(EtherType 0x88F7), VLAN-tagged L2 (TPIDs 0x8100/0x88A8, single
or double), UDP/IPv4, UDP/IPv6 (ports 319/320), and VLAN-tagged
UDP variants - Header access: rte_ptp_hdr_get() returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug: rte_ptp_msg_type_str() for human-readable message names
Example: ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.
The relay:
1. Receives packets on the physical NIC via DPDK
2. Parses packets using rte_ptp_hdr_get()
3. For event messages, records software timestamps (clock_gettime(CLOCK_MONOTONIC)) at ingress and egress
4. Adds residence time to correctionField via rte_ptp_add_correction()
(IEEE 1588-2019 10.2 Transparent Clock)
5. Forwards bidirectionally: PHY <-> TAP
Unit Tests: app/test
--------------------
A comprehensive test suite (ptp_autotest) covers all library APIs, including VLAN/QinQ/IPv4/IPv6 transports, correctionField helpers, flags, and negative tests. This v3 also adds coverage for IPv4 options (IHL > 5).
v3:
- Reused RTE_ETHER_TYPE_1588 via RTE_PTP_ETHERTYPE alias
- Updated version field comment to minorVersionPTP|versionPTP
- Fixed prog guide rte_ptp_hdr_get() signature (non-const mbuf)
- Added ALLOW_EXPERIMENTAL_API to ptp_tap_relay_sw Makefile
- Updated relay example to parse once (rte_ptp_hdr_get + msg_type)
- Updated relay sample app limitations wording to match capabilities
- Added hdr_get NULL checks in correction tests
- Added IPv4 options classification test (IHL > 5)
- Made correction counter update style consistent via pointer arg
v2:
- Fixed flag bit positions for host-order representation after
rte_be_to_cpu_16(): TWO_STEP (1<<9), UNICAST (1<<10),
LI_61 (1<<0), LI_59 (1<<1) - Fixed QinQ classification: outer 0x88A8 now enters VLAN parser
- Fixed signed left-shift UB in rte_ptp_add_correction()
- Fixed promiscuous enable failure handling in relay port_init()
- Replaced deprecated master/slave terminology with IEEE terms
- Added and documented IHL validation for IPv4 PTP-over-UDP
- Changed rte_ptp_is_event() parameter to int with negative guard
- Changed rte_ptp_hdr_get() parameter to non-const mbuf
- Added programmer's guide note about avoiding double-parse
Rajesh Kumar (6):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide app/test: add PTP library unit tests examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 8 + app/test/meson.build | 1 + app/test/test_ptp.c | 1106 +++++++++++++++++ doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 +++ doc/guides/rel_notes/release_26_07.rst | 13 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 + examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 ++- lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 +++ lib/ptp/rte_ptp.h | 339 +++++ 20 files changed, 2644 insertions(+), 116 deletions(-) create mode 100644 app/test/test_ptp.c create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
base-commit: 7baf81674a011ab8a2fe329566b6d43d7377244c
Signature · 1 line
2.53.0
RFC v3 1/6 ptp: introduce PTP protocol library
Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType 0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Public APIs:
1. rte_ptp_classify()
2. rte_ptp_hdr_get()
3. rte_ptp_msg_type_str()
--- MAINTAINERS | 7 + doc/guides/rel_notes/release_26_07.rst | 7 + lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 ++++++++++++++ lib/ptp/rte_ptp.h | 339 +++++++++++++++++++++++++ 6 files changed, 545 insertions(+) create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
MAINTAINERS +7 -0
@@ -1665,6 +1665,13 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - EXPERIMENTAL +M: Rajesh Kumar <[email protected]> +F: lib/ptp/ +F: doc/guides/prog_guide/ptp_lib.rst +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
doc/guides/rel_notes/release_26_07.rst +7 -0
@@ -63,6 +63,13 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol library.** + + Added a new library ``rte_ptp`` for IEEE 1588 Precision Time Protocol + packet processing. The library provides packet classification, header + parsing, and correctionField manipulation across L2, VLAN-tagged, + UDP/IPv4, and UDP/IPv6 transports. + Removed Items -------------
lib/meson.build +1 -0
@@ -50,6 +50,7 @@ libraries = [ 'member', 'pcapng', 'power', + 'ptp', 'rawdev', 'regexdev', 'mldev',
lib/ptp/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +sources = files('rte_ptp.c') +headers = files('rte_ptp.h') +deps += ['mbuf', 'net']
lib/ptp/rte_ptp.c new file +185 -0
185 lines not on this page · raw message
lib/ptp/rte_ptp.h new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v3 2/6 doc: add PTP library programmer's guide
In reply to Rajesh KumarAdd programmer's guide for the PTP protocol library covering message types, header structures, packet classification API, inline helpers, and usage examples.
Add PTP header to Doxygen API index under layers section.
--- doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 ++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst
doc/api/doxy-api-index.md +1 -0
@@ -137,6 +137,7 @@ The public API headers are grouped by topics: [eCPRI](@ref rte_ecpri.h), [PDCP hdr](@ref rte_pdcp_hdr.h), [PDCP](@ref rte_pdcp.h), + [PTP](@ref rte_ptp.h), [L2TPv2](@ref rte_l2tpv2.h), [PPP](@ref rte_ppp.h), [IB](@ref rte_ib.h)
doc/api/doxy-api.conf.in +1 -0
@@ -72,6 +72,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ @TOPDIR@/lib/pmu \ @TOPDIR@/lib/port \ @TOPDIR@/lib/power \ + @TOPDIR@/lib/ptp \ @TOPDIR@/lib/ptr_compress \ @TOPDIR@/lib/rawdev \ @TOPDIR@/lib/rcu \
doc/guides/prog_guide/index.rst +1 -0
@@ -97,6 +97,7 @@ Protocol Processing Libraries :maxdepth: 1 :numbered: + ptp_lib pdcp_lib ipsec_lib
doc/guides/prog_guide/ptp_lib.rst new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v3 3/6 examples/ptp_tap_relay_sw: add software PTP relay example
In reply to Rajesh KumarAdd a minimal PTP Transparent Clock relay that bridges PTP packets between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only.
The relay uses the rte_ptp library for packet classification and correctionField manipulation. For each PTP event message, it records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress, then adds the residence time to the correctionField per IEEE 1588-2019 section 10.2.
A two-pass design is used: first all packets are classified and PTP header pointers saved, then a single TX timestamp is taken immediately before applying corrections and calling rte_eth_tx_burst(). This minimises the gap between the measured timestamp and actual wire egress.
--- doc/guides/rel_notes/release_26_07.rst | 6 + examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++++++++++++++ 5 files changed, 497 insertions(+) create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/rel_notes/release_26_07.rst +6 -0
@@ -70,6 +70,12 @@ New Features parsing, and correctionField manipulation across L2, VLAN-tagged, UDP/IPv4, and UDP/IPv6 transports. +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. + Removed Items -------------
examples/meson.build +1 -0
@@ -43,6 +43,7 @@ all_examples = [ 'packet_ordering', 'pipeline', 'ptpclient', + 'ptp_tap_relay_sw', 'qos_meter', 'qos_sched', 'rxtx_callbacks',
examples/ptp_tap_relay_sw/Makefile new file +43 -0
43 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +allow_experimental_apis = true +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net', 'ptp'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +433 -0
433 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v3 4/6 doc: add PTP software relay sample app guide
In reply to Rajesh KumarAdd a sample application user guide for the ptp_tap_relay_sw example. The guide covers the application topology, packet flow, compilation, command-line options, and a code walkthrough explaining the two-pass relay burst design and CLOCK_MONOTONIC_RAW timestamp source selection.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v3 5/6 app/test: add PTP library unit tests
In reply to Rajesh KumarAdd autotest for the PTP library covering:
- Transport classification (L2, VLAN, QinQ, UDP/IPv4, UDP/IPv6)
- Message type parsing and string conversion
- Inline helpers (is_event, two_step, seq_id, version, domain)
- Correction field arithmetic (add, accumulate, negative values)
- Timestamp nanosecond conversion
- Flag field extraction (TWO_STEP, UNICAST, LI_61, LI_59)
--- MAINTAINERS | 1 + app/test/meson.build | 1 + app/test/test_ptp.c | 1106 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1108 insertions(+) create mode 100644 app/test/test_ptp.c
MAINTAINERS +1 -0
@@ -1668,6 +1668,7 @@ F: app/test-sad/ PTP - EXPERIMENTAL M: Rajesh Kumar <[email protected]> F: lib/ptp/ +F: app/test/test_ptp.c F: doc/guides/prog_guide/ptp_lib.rst F: examples/ptp_tap_relay_sw/ F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
app/test/meson.build +1 -0
@@ -154,6 +154,7 @@ source_file_deps = { 'test_power_kvm_vm.c': ['power', 'power_kvm_vm'], 'test_prefetch.c': [], 'test_ptr_compress.c': ['ptr_compress'], + 'test_ptp.c': ['ptp'], 'test_rand_perf.c': [], 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'],
app/test/test_ptp.c new file +1106 -0
1,106 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v3 6/6 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarReplace local PTP struct and constant definitions with the shared rte_ptp.h library types introduced earlier in this series:
- struct ptp_header -> struct rte_ptp_hdr - struct tstamp -> struct rte_ptp_timestamp - struct clock_id -> uint8_t clock_id[8] (from rte_ptp_port_id)
- SYNC/FOLLOW_UP/DELAY_* defines -> RTE_PTP_MSGTYPE_* constants
- PTP_PROTOCOL -> RTE_PTP_ETHERTYPE
- hardcoded multicast -> RTE_PTP_MULTICAST_MAC
- ptp_hdr->msg_type switch -> rte_ptp_msg_type() accessor
No functional change.
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 +++++++++++++-------------------- 2 files changed, 73 insertions(+), 116 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['ptp'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +72 -116
323 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [RFC v3 0/6] introduce PTP protocol library and software relay
In reply to Rajesh KumarQuoted 114 lines · On Mon, 4 May 2026 14:47:16 +0530 Rajesh Kumar <[email protected]> wrote:
This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (
ptp_tap_relay_sw) that demonstrates its usage.Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient,ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification:rte_ptp_classify()detects PTP over L2(EtherType 0x88F7), VLAN-tagged L2 (TPIDs 0x8100/0x88A8, single or double), UDP/IPv4, UDP/IPv6 (ports 319/320), and VLAN-tagged UDP variants- Header access:
rte_ptp_hdr_get()returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug:rte_ptp_msg_type_str()for human-readable message namesExample:
ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.The relay:
1. Receives packets on the physical NIC via DPDK
2. Parses packets usingrte_ptp_hdr_get()
3. For event messages, records software timestamps (clock_gettime(CLOCK_MONOTONIC)) at ingress and egress
4. Adds residence time to correctionField viarte_ptp_add_correction()(IEEE 1588-2019 10.2 Transparent Clock)5. Forwards bidirectionally: PHY <-> TAP
Unit Tests: app/test
--------------------
A comprehensive test suite (ptp_autotest) covers all library APIs, including VLAN/QinQ/IPv4/IPv6 transports, correctionField helpers, flags, and negative tests. This v3 also adds coverage for IPv4 options (IHL > 5).v3:
- ReusedRTE_ETHER_TYPE_1588viaRTE_PTP_ETHERTYPEalias
- Updated version field comment to minorVersionPTP|versionPTP
- Fixed prog guiderte_ptp_hdr_get()signature (non-const mbuf)
- AddedALLOW_EXPERIMENTAL_APItoptp_tap_relay_swMakefile
- Updated relay example to parse once (rte_ptp_hdr_get+msg_type)
- Updated relay sample app limitations wording to match capabilities
- Addedhdr_getNULL checks in correction tests
- Added IPv4 options classification test (IHL > 5)
- Made correction counter update style consistent via pointer argv2:
- Fixed flag bit positions for host-order representation afterrte_be_to_cpu_16(): TWO_STEP (1<<9), UNICAST (1<<10), LI_61 (1<<0), LI_59 (1<<1)- Fixed QinQ classification: outer
0x88A8now enters VLAN parser
- Fixed signed left-shift UB inrte_ptp_add_correction()
- Fixed promiscuous enable failure handling in relayport_init()
- Replaced deprecated master/slave terminology with IEEE terms
- Added and documented IHL validation for IPv4 PTP-over-UDP
- Changedrte_ptp_is_event()parameter to int with negative guard
- Changedrte_ptp_hdr_get()parameter to non-const mbuf
- Added programmer's guide note about avoiding double-parseRajesh Kumar (6):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide app/test: add PTP library unit tests examples/ptpclient: use shared PTP library definitionsMAINTAINERS | 8 + app/test/meson.build | 1 + app/test/test_ptp.c | 1106 +++++++++++++++++ doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 +++ doc/guides/rel_notes/release_26_07.rst | 13 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 + examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 ++- lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 +++ lib/ptp/rte_ptp.h | 339 +++++ 20 files changed, 2644 insertions(+), 116 deletions(-) create mode 100644 app/test/test_ptp.c create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
Quoted 1 line
base-commit:
7baf81674a011ab8a2fe329566b6d43d7377244c
Lots of build failures in CI.
Looks like alot around c++ build of header etc.
g++ -Ibuildtools/chkincs/chkincs-cpp-exp.p -Ibuildtools/chkincs -I../buildtools/chkincs -I. -I.. -Iconfig -I../config -Ibuildtools/chkincs/staging -I../buildtools/chkincs/staging -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -g -include rte_config.h -march=corei7 -mrtm -Wno-missing-field-initializers -Wno-vla -DALLOW_EXPERIMENTAL_API -MD -MQ buildtools/chkincs/chkincs-cpp-exp.p/meson-generated_rte_ptp.cpp.o -MF buildtools/chkincs/chkincs-cpp-exp.p/meson-generated_rte_ptp.cpp.o.d -o buildtools/chkincs/chkincs-cpp-exp.p/meson-generated_rte_ptp.cpp.o -c buildtools/chkincs/chkincs-cpp-exp.p/rte_ptp.cpp In file included from buildtools/chkincs/staging/rte_memory.h:18,
from buildtools/chkincs/staging/rte_ring_core.h:29,
from buildtools/chkincs/staging/rte_ring.h:38,
from buildtools/chkincs/staging/rte_mempool.h:49,
from buildtools/chkincs/staging/rte_mbuf.h:39,
from buildtools/chkincs/staging/rte_ether.h:20,
from /home/runner/work/dpdk/dpdk/lib/ptp/rte_ptp.h:32,
from buildtools/chkincs/chkincs-cpp-exp.p/rte_ptp.cpp:1:
buildtools/chkincs/staging/rte_bitops.h:1468:1: error: conflicting declaration of C function ‘bool rte_bit_test(const volatile uint32_t*, unsigned int)’
1468 | rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_name) \
| ^~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1475:9: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_V_2R’
1475 | __RTE_BIT_OVERLOAD_V_2R(family, v_, fun, qualifier volatile, size, ret_type, arg1_type, \
| ^~~~~~~~~~~~~~~~~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1479:9: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_SZ_2R’
1479 | __RTE_BIT_OVERLOAD_SZ_2R(family, fun, qualifier, 32, ret_type, arg1_type, arg1_name) \
| ^~~~~~~~~~~~~~~~~~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1575:1: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_2R’
1575 | __RTE_BIT_OVERLOAD_2R(, test, const, bool, unsigned int, nr)
| ^~~~~~~~~~~~~~~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1468:1: note: previous declaration ‘bool rte_bit_test(const uint32_t*, unsigned int)’
1468 | rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_name) \
| ^~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1474:9: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_V_2R’
1474 | __RTE_BIT_OVERLOAD_V_2R(family,, fun, qualifier, size, ret_type, arg1_type, arg1_name) \
| ^~~~~~~~~~~~~~~~~~~~~~~
buildtools/chkincs/staging/rte_bitops.h:1479:9: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_SZ_2R’
1479 | __RTE_BIT_OVERLOAD_SZ_2R(family, fun, qualifier, 32, ret_type, arg1_type, arg1_name) \
| ^~~~~~~~~~~~~~~~~~~~~~~~buildtools/chkincs/staging/rte_bitops.h:1575:1: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_2R’
1575 | __RTE_BIT_OVERLOAD_2R(, test, const, bool, unsigned int, nr)
v4 cover introduce PTP protocol library and software relay
In reply to Rajesh KumarThis series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (ptp_tap_relay_sw) that demonstrates its usage.
Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification: rte_ptp_classify() detects PTP over L2
(EtherType 0x88F7), VLAN-tagged L2 (TPIDs 0x8100/0x88A8, single
or double), UDP/IPv4, UDP/IPv6 (ports 319/320), and VLAN-tagged
UDP variants - Header access: rte_ptp_hdr_get() returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug: rte_ptp_msg_type_str() for human-readable message names
Example: ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.
The relay:
1. Receives packets on the physical NIC via DPDK
2. Parses packets using rte_ptp_hdr_get()
3. For event messages, records software timestamps (clock_gettime(CLOCK_MONOTONIC)) at ingress and egress
4. Adds residence time to correctionField via rte_ptp_add_correction()
(IEEE 1588-2019 10.2 Transparent Clock)
5. Forwards bidirectionally: PHY <-> TAP
Unit Tests: app/test
--------------------
A comprehensive test suite (ptp_autotest) covers all library APIs, including VLAN/QinQ/IPv4/IPv6 transports, correctionField helpers, flags, and negative tests. Also covers IPv4 options (IHL > 5).
v4:
- Fixed C++ header check (chkincs) failure: moved #include directives above extern "C" guard in rte_ptp.h to prevent rte_bitops.h C++ overloads from being forced into C linkage
v3:
- Reused RTE_ETHER_TYPE_1588 via RTE_PTP_ETHERTYPE alias
- Updated version field comment to minorVersionPTP|versionPTP
- Fixed prog guide rte_ptp_hdr_get() signature (non-const mbuf)
- Added ALLOW_EXPERIMENTAL_API to ptp_tap_relay_sw Makefile
- Updated relay example to parse once (rte_ptp_hdr_get + msg_type)
- Updated relay sample app limitations wording to match capabilities
- Added hdr_get NULL checks in correction tests
- Added IPv4 options classification test (IHL > 5)
- Made correction counter update style consistent via pointer arg
v2:
- Fixed flag bit positions for host-order representation after
rte_be_to_cpu_16(): TWO_STEP (1<<9), UNICAST (1<<10),
LI_61 (1<<0), LI_59 (1<<1)Rajesh Kumar (6):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide app/test: add PTP library unit tests examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 8 + app/test/meson.build | 1 + app/test/test_ptp.c | 1106 +++++++++++++++++ doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 +++ doc/guides/rel_notes/release_26_07.rst | 13 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 + examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 ++- lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 +++ lib/ptp/rte_ptp.h | 339 +++++ 20 files changed, 2644 insertions(+), 116 deletions(-) create mode 100644 app/test/test_ptp.c create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
base-commit: 7baf81674a011ab8a2fe329566b6d43d7377244c
Signature · 1 line
2.53.0
RFC v4 1/6 ptp: introduce PTP protocol library
Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType 0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Public APIs:
1. rte_ptp_classify()
2. rte_ptp_hdr_get()
3. rte_ptp_msg_type_str()
--- MAINTAINERS | 7 + doc/guides/rel_notes/release_26_07.rst | 7 + lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 ++++++++++++++ lib/ptp/rte_ptp.h | 339 +++++++++++++++++++++++++ 6 files changed, 545 insertions(+) create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
MAINTAINERS +7 -0
@@ -1665,6 +1665,13 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - EXPERIMENTAL +M: Rajesh Kumar <[email protected]> +F: lib/ptp/ +F: doc/guides/prog_guide/ptp_lib.rst +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
doc/guides/rel_notes/release_26_07.rst +7 -0
@@ -63,6 +63,13 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol library.** + + Added a new library ``rte_ptp`` for IEEE 1588 Precision Time Protocol + packet processing. The library provides packet classification, header + parsing, and correctionField manipulation across L2, VLAN-tagged, + UDP/IPv4, and UDP/IPv6 transports. + Removed Items -------------
lib/meson.build +1 -0
@@ -50,6 +50,7 @@ libraries = [ 'member', 'pcapng', 'power', + 'ptp', 'rawdev', 'regexdev', 'mldev',
lib/ptp/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +sources = files('rte_ptp.c') +headers = files('rte_ptp.h') +deps += ['mbuf', 'net']
lib/ptp/rte_ptp.c new file +185 -0
185 lines not on this page · raw message
lib/ptp/rte_ptp.h new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v4 2/6 doc: add PTP library programmer's guide
In reply to Rajesh KumarAdd programmer's guide for the PTP protocol library covering message types, header structures, packet classification API, inline helpers, and usage examples.
Add PTP header to Doxygen API index under layers section.
--- doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 ++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst
doc/api/doxy-api-index.md +1 -0
@@ -137,6 +137,7 @@ The public API headers are grouped by topics: [eCPRI](@ref rte_ecpri.h), [PDCP hdr](@ref rte_pdcp_hdr.h), [PDCP](@ref rte_pdcp.h), + [PTP](@ref rte_ptp.h), [L2TPv2](@ref rte_l2tpv2.h), [PPP](@ref rte_ppp.h), [IB](@ref rte_ib.h)
doc/api/doxy-api.conf.in +1 -0
@@ -72,6 +72,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ @TOPDIR@/lib/pmu \ @TOPDIR@/lib/port \ @TOPDIR@/lib/power \ + @TOPDIR@/lib/ptp \ @TOPDIR@/lib/ptr_compress \ @TOPDIR@/lib/rawdev \ @TOPDIR@/lib/rcu \
doc/guides/prog_guide/index.rst +1 -0
@@ -97,6 +97,7 @@ Protocol Processing Libraries :maxdepth: 1 :numbered: + ptp_lib pdcp_lib ipsec_lib
doc/guides/prog_guide/ptp_lib.rst new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v4 3/6 examples/ptp_tap_relay_sw: add software PTP relay example
In reply to Rajesh KumarAdd a minimal PTP Transparent Clock relay that bridges PTP packets between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only.
The relay uses the rte_ptp library for packet classification and correctionField manipulation. For each PTP event message, it records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress, then adds the residence time to the correctionField per IEEE 1588-2019 section 10.2.
A two-pass design is used: first all packets are classified and PTP header pointers saved, then a single TX timestamp is taken immediately before applying corrections and calling rte_eth_tx_burst(). This minimises the gap between the measured timestamp and actual wire egress.
--- doc/guides/rel_notes/release_26_07.rst | 6 + examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 433 +++++++++++++++++++ 5 files changed, 497 insertions(+) create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/rel_notes/release_26_07.rst +6 -0
@@ -70,6 +70,12 @@ New Features parsing, and correctionField manipulation across L2, VLAN-tagged, UDP/IPv4, and UDP/IPv6 transports. +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. + Removed Items -------------
examples/meson.build +1 -0
@@ -43,6 +43,7 @@ all_examples = [ 'packet_ordering', 'pipeline', 'ptpclient', + 'ptp_tap_relay_sw', 'qos_meter', 'qos_sched', 'rxtx_callbacks',
examples/ptp_tap_relay_sw/Makefile new file +43 -0
43 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +allow_experimental_apis = true +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net', 'ptp'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +433 -0
433 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v4 4/6 doc: add PTP software relay sample app guide
In reply to Rajesh KumarAdd a sample application user guide for the ptp_tap_relay_sw example. The guide covers the application topology, packet flow, compilation, command-line options, and a code walkthrough explaining the two-pass relay burst design and CLOCK_MONOTONIC_RAW timestamp source selection.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v4 5/6 app/test: add PTP library unit tests
In reply to Rajesh KumarAdd autotest for the PTP library covering:
- Transport classification (L2, VLAN, QinQ, UDP/IPv4, UDP/IPv6)
- Message type parsing and string conversion
- Inline helpers (is_event, two_step, seq_id, version, domain)
- Correction field arithmetic (add, accumulate, negative values)
- Timestamp nanosecond conversion
- Flag field extraction (TWO_STEP, UNICAST, LI_61, LI_59)
--- MAINTAINERS | 1 + app/test/meson.build | 1 + app/test/test_ptp.c | 1106 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1108 insertions(+) create mode 100644 app/test/test_ptp.c
MAINTAINERS +1 -0
@@ -1668,6 +1668,7 @@ F: app/test-sad/ PTP - EXPERIMENTAL M: Rajesh Kumar <[email protected]> F: lib/ptp/ +F: app/test/test_ptp.c F: doc/guides/prog_guide/ptp_lib.rst F: examples/ptp_tap_relay_sw/ F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
app/test/meson.build +1 -0
@@ -154,6 +154,7 @@ source_file_deps = { 'test_power_kvm_vm.c': ['power', 'power_kvm_vm'], 'test_prefetch.c': [], 'test_ptr_compress.c': ['ptr_compress'], + 'test_ptp.c': ['ptp'], 'test_rand_perf.c': [], 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'],
app/test/test_ptp.c new file +1106 -0
1,106 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v4 6/6 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarReplace local PTP struct and constant definitions with the shared rte_ptp.h library types introduced earlier in this series:
- struct ptp_header -> struct rte_ptp_hdr - struct tstamp -> struct rte_ptp_timestamp - struct clock_id -> uint8_t clock_id[8] (from rte_ptp_port_id)
- SYNC/FOLLOW_UP/DELAY_* defines -> RTE_PTP_MSGTYPE_* constants
- PTP_PROTOCOL -> RTE_PTP_ETHERTYPE
- hardcoded multicast -> RTE_PTP_MULTICAST_MAC
- ptp_hdr->msg_type switch -> rte_ptp_msg_type() accessor
No functional change.
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 188 +++++++++++++-------------------- 2 files changed, 73 insertions(+), 116 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['ptp'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +72 -116
323 lines not on this page · raw message
Signature · 1 line
2.53.0
v5 cover introduce PTP protocol library and software relay
In reply to Rajesh KumarThis series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019 PTP protocol packet processing and a companion example application (ptp_tap_relay_sw) that demonstrates its usage.
Motivation
----------
Several DPDK applications need to classify and manipulate PTP packets (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each application re-implements its own PTP header parsing and correctionField handling. A shared library avoids duplication and provides a tested, standards-compliant foundation.
Library: lib/ptp
----------------
The library provides:
- PTP header structures (IEEE 1588-2019 common header, timestamp, port identity)
- Packet classification: rte_ptp_classify() detects PTP over L2
(EtherType 0x88F7), VLAN-tagged L2 (TPIDs 0x8100/0x88A8, single
or double), UDP/IPv4, UDP/IPv6 (ports 319/320), and VLAN-tagged
UDP variants - Header access: rte_ptp_hdr_get() returns a pointer to the PTP header inside an mbuf
- Inline helpers: correctionField manipulation (48.16 fixed-point), message type extraction, two-step flag check, timestamp conversion
- Debug: rte_ptp_msg_type_str() for human-readable message names
Example: ptp_tap_relay_sw
-------------------------
A minimal PTP Transparent Clock relay between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only. No patched kernel modules, custom TAP PMD, or hardware timestamp support is required.
The relay:
1. Receives packets on the physical NIC via DPDK
2. Parses packets using rte_ptp_hdr_get()
3. For event messages, records software timestamps (clock_gettime(CLOCK_MONOTONIC)) at ingress and egress
4. Adds residence time to correctionField via rte_ptp_add_correction()
(IEEE 1588-2019 10.2 Transparent Clock)
5. Forwards bidirectionally: PHY <-> TAP
Unit Tests: app/test
--------------------
A comprehensive test suite (ptp_autotest) covers all library APIs, including VLAN/QinQ/IPv4/IPv6 transports, correctionField helpers, flags, and negative tests. Also covers IPv4 options (IHL > 5).
v5:
- Fixed checkpatch warnings: removed unnecessary #include <stdio.h> from example and test files
v4:
- Fixed C++ header check (chkincs) failure: moved #include directives above extern "C" guard in rte_ptp.h to prevent rte_bitops.h C++ overloads from being forced into C linkage
v3:
- Reused RTE_ETHER_TYPE_1588 via RTE_PTP_ETHERTYPE alias
- Updated version field comment to minorVersionPTP|versionPTP
- Fixed prog guide rte_ptp_hdr_get() signature (non-const mbuf)
- Added ALLOW_EXPERIMENTAL_API to ptp_tap_relay_sw Makefile
- Updated relay example to parse once (rte_ptp_hdr_get + msg_type)
- Updated relay sample app limitations wording to match capabilities
- Added hdr_get NULL checks in correction tests
- Added IPv4 options classification test (IHL > 5)
- Made correction counter update style consistent via pointer arg
v2:
- Fixed flag bit positions for host-order representation after
rte_be_to_cpu_16(): TWO_STEP (1<<9), UNICAST (1<<10),
LI_61 (1<<0), LI_59 (1<<1)Rajesh Kumar (6):
ptp: introduce PTP protocol library
doc: add PTP library programmer's guide examples/ptp_tap_relay_sw: add software PTP relay example
doc: add PTP software relay sample app guide app/test: add PTP library unit tests examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 8 + app/test/meson.build | 1 + app/test/test_ptp.c | 1105 +++++++++++++++++ doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 +++ doc/guides/rel_notes/release_26_07.rst | 13 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++ examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 + examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 +++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 189 ++- lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 +++ lib/ptp/rte_ptp.h | 339 +++++ 20 files changed, 2643 insertions(+), 116 deletions(-) create mode 100644 app/test/test_ptp.c create mode 100644 doc/guides/prog_guide/ptp_lib.rst create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
base-commit: 7baf81674a011ab8a2fe329566b6d43d7377244c
Signature · 1 line
2.53.0
RFC v5 1/6 ptp: introduce PTP protocol library
Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType 0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Public APIs:
1. rte_ptp_classify()
2. rte_ptp_hdr_get()
3. rte_ptp_msg_type_str()
--- MAINTAINERS | 7 + doc/guides/rel_notes/release_26_07.rst | 7 + lib/meson.build | 1 + lib/ptp/meson.build | 6 + lib/ptp/rte_ptp.c | 185 ++++++++++++++ lib/ptp/rte_ptp.h | 339 +++++++++++++++++++++++++ 6 files changed, 545 insertions(+) create mode 100644 lib/ptp/meson.build create mode 100644 lib/ptp/rte_ptp.c create mode 100644 lib/ptp/rte_ptp.h
MAINTAINERS +7 -0
@@ -1665,6 +1665,13 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - EXPERIMENTAL +M: Rajesh Kumar <[email protected]> +F: lib/ptp/ +F: doc/guides/prog_guide/ptp_lib.rst +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
doc/guides/rel_notes/release_26_07.rst +7 -0
@@ -63,6 +63,13 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol library.** + + Added a new library ``rte_ptp`` for IEEE 1588 Precision Time Protocol + packet processing. The library provides packet classification, header + parsing, and correctionField manipulation across L2, VLAN-tagged, + UDP/IPv4, and UDP/IPv6 transports. + Removed Items -------------
lib/meson.build +1 -0
@@ -50,6 +50,7 @@ libraries = [ 'member', 'pcapng', 'power', + 'ptp', 'rawdev', 'regexdev', 'mldev',
lib/ptp/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +sources = files('rte_ptp.c') +headers = files('rte_ptp.h') +deps += ['mbuf', 'net']
lib/ptp/rte_ptp.c new file +185 -0
185 lines not on this page · raw message
lib/ptp/rte_ptp.h new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
2.53.0
RE: [RFC v5 1/6] ptp: introduce PTP protocol library
Quoted 16 lines
From: Rajesh Kumar [mailto:[email protected]]
Sent: Wednesday, 6 May 2026 17.41Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)
Quoted 7 lines
Public APIs:
1.rte_ptp_classify()
2.rte_ptp_hdr_get()
3.rte_ptp_msg_type_str()Signed-off-by Rajesh Kumar <[email protected]>---
Improved PTP support seems like a good addition to DPDK.
Here's some high level feedback to the library:
I think much of this belongs into /lib/net/, which holds similar protocol structure definitions and helper functions for many other protocols. Please familiarize yourself with the code conventions in that directory, and move the relevant parts of the PTP library there (following the code conventions there).
Remember to define the packet structures with endianness in mind; e.g. use rte_be32_t instead of uint32_t where appropriate.
Don't define simple aliases, just use RTE_ETHER_TYPE_1588 directly.
Your DPI (deep packet inspection) parser function that can parse all kinds of PTP encapsulation does not belong in the library. Applications would rely on a layered packet parser, such as rte_net_get_ptype().
If you need a DPI parser for the examples, feel free to add it there.
Re: [RFC v5 1/6] ptp: introduce PTP protocol library
Quoted 30 lines · Morten Brørup
Quoted 16 lines
From: Rajesh Kumar [mailto:[email protected]]
Sent: Wednesday, 6 May 2026 17.41Add IEEE 1588-2019 Precision Time Protocol (PTP) processing library.
The library provides packet classification, header structures, and helper functions for PTP packet processing in DPDK. This avoids duplicate PTP header definitions across multiple applications and drivers.
Supported transports:
1. L2 PTP (EtherType0x88F7)
2. VLAN-tagged L2 PTP (single and QinQ)
3. PTP over UDP/IPv4 (ports 319/320)
4. PTP over UDP/IPv6 (ports 319/320)Quoted 7 lines
Public APIs:
1.rte_ptp_classify()
2.rte_ptp_hdr_get()
3.rte_ptp_msg_type_str()Signed-off-by Rajesh Kumar <[email protected]>---
Improved PTP support seems like a good addition to DPDK.
Here's some high level feedback to the library:
I think much of this belongs into
/lib/net/, which holds similar protocol structure definitions and helper functions for many other protocols. Please familiarize yourself with the code conventions in that directory, and move the relevant parts of the PTP library there (following the code conventions there).
Quoted 8 lines
Remember to define the packet structures with endianness in mind; e.g. use
rte_be32_tinstead ofuint32_twhere appropriate.Don't define simple aliases, just use
RTE_ETHER_TYPE_1588directly.Your DPI (deep packet inspection) parser function that can parse all kinds of PTP encapsulation does not belong in the library. Applications would rely on a layered packet parser, such as
rte_net_get_ptype().If you need a DPI parser for the examples, feel free to add it there.
Thank you for the feedback, Morten! All comments addressed in v6:
- Moved to lib/net/ as a header-only library (following rte_tcp.h conventions)
- All multi-byte struct fields now use rte_beXX_t types
- Removed RTE_ETHER_TYPE_1588 alias; using constant directly
- DPI parser moved to example-local ptp_parse.h (not library API)
RFC v5 2/6 doc: add PTP library programmer's guide
In reply to Rajesh KumarAdd programmer's guide for the PTP protocol library covering message types, header structures, packet classification API, inline helpers, and usage examples.
Add PTP header to Doxygen API index under layers section.
--- doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf.in | 1 + doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/ptp_lib.rst | 205 ++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 doc/guides/prog_guide/ptp_lib.rst
doc/api/doxy-api-index.md +1 -0
@@ -137,6 +137,7 @@ The public API headers are grouped by topics: [eCPRI](@ref rte_ecpri.h), [PDCP hdr](@ref rte_pdcp_hdr.h), [PDCP](@ref rte_pdcp.h), + [PTP](@ref rte_ptp.h), [L2TPv2](@ref rte_l2tpv2.h), [PPP](@ref rte_ppp.h), [IB](@ref rte_ib.h)
doc/api/doxy-api.conf.in +1 -0
@@ -72,6 +72,7 @@ INPUT = @TOPDIR@/doc/api/doxy-api-index.md \ @TOPDIR@/lib/pmu \ @TOPDIR@/lib/port \ @TOPDIR@/lib/power \ + @TOPDIR@/lib/ptp \ @TOPDIR@/lib/ptr_compress \ @TOPDIR@/lib/rawdev \ @TOPDIR@/lib/rcu \
doc/guides/prog_guide/index.rst +1 -0
@@ -97,6 +97,7 @@ Protocol Processing Libraries :maxdepth: 1 :numbered: + ptp_lib pdcp_lib ipsec_lib
doc/guides/prog_guide/ptp_lib.rst new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v5 3/6 examples/ptp_tap_relay_sw: add software PTP relay example
In reply to Rajesh KumarAdd a minimal PTP Transparent Clock relay that bridges PTP packets between a DPDK-bound physical NIC and a kernel TAP interface using software timestamps only.
The relay uses the rte_ptp library for packet classification and correctionField manipulation. For each PTP event message, it records software timestamps (CLOCK_MONOTONIC_RAW) at ingress and egress, then adds the residence time to the correctionField per IEEE 1588-2019 section 10.2.
A two-pass design is used: first all packets are classified and PTP header pointers saved, then a single TX timestamp is taken immediately before applying corrections and calling rte_eth_tx_burst(). This minimises the gap between the measured timestamp and actual wire egress.
--- doc/guides/rel_notes/release_26_07.rst | 6 + examples/meson.build | 1 + examples/ptp_tap_relay_sw/Makefile | 43 ++ examples/ptp_tap_relay_sw/meson.build | 14 + examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 +++++++++++++++++++ 5 files changed, 496 insertions(+) create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/rel_notes/release_26_07.rst +6 -0
@@ -70,6 +70,12 @@ New Features parsing, and correctionField manipulation across L2, VLAN-tagged, UDP/IPv4, and UDP/IPv6 transports. +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. + Removed Items -------------
examples/meson.build +1 -0
@@ -43,6 +43,7 @@ all_examples = [ 'packet_ordering', 'pipeline', 'ptpclient', + 'ptp_tap_relay_sw', 'qos_meter', 'qos_sched', 'rxtx_callbacks',
examples/ptp_tap_relay_sw/Makefile new file +43 -0
43 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +allow_experimental_apis = true +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net', 'ptp'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v5 4/6 doc: add PTP software relay sample app guide
In reply to Rajesh KumarAdd a sample application user guide for the ptp_tap_relay_sw example. The guide covers the application topology, packet flow, compilation, command-line options, and a code walkthrough explaining the two-pass relay burst design and CLOCK_MONOTONIC_RAW timestamp source selection.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 ++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v5 5/6 app/test: add PTP library unit tests
In reply to Rajesh KumarAdd autotest for the PTP library covering:
- Transport classification (L2, VLAN, QinQ, UDP/IPv4, UDP/IPv6)
- Message type parsing and string conversion
- Inline helpers (is_event, two_step, seq_id, version, domain)
- Correction field arithmetic (add, accumulate, negative values)
- Timestamp nanosecond conversion
- Flag field extraction (TWO_STEP, UNICAST, LI_61, LI_59)
--- MAINTAINERS | 1 + app/test/meson.build | 1 + app/test/test_ptp.c | 1105 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1107 insertions(+) create mode 100644 app/test/test_ptp.c
MAINTAINERS +1 -0
@@ -1668,6 +1668,7 @@ F: app/test-sad/ PTP - EXPERIMENTAL M: Rajesh Kumar <[email protected]> F: lib/ptp/ +F: app/test/test_ptp.c F: doc/guides/prog_guide/ptp_lib.rst F: examples/ptp_tap_relay_sw/ F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst
app/test/meson.build +1 -0
@@ -154,6 +154,7 @@ source_file_deps = { 'test_power_kvm_vm.c': ['power', 'power_kvm_vm'], 'test_prefetch.c': [], 'test_ptr_compress.c': ['ptr_compress'], + 'test_ptp.c': ['ptp'], 'test_rand_perf.c': [], 'test_rawdev.c': ['rawdev', 'bus_vdev', 'raw_skeleton'], 'test_rcu_qsbr.c': ['rcu', 'hash'],
app/test/test_ptp.c new file +1105 -0
1,105 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC v5 6/6 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarReplace local PTP struct and constant definitions with the shared rte_ptp.h library types introduced earlier in this series:
- struct ptp_header -> struct rte_ptp_hdr - struct tstamp -> struct rte_ptp_timestamp - struct clock_id -> uint8_t clock_id[8] (from rte_ptp_port_id)
- SYNC/FOLLOW_UP/DELAY_* defines -> RTE_PTP_MSGTYPE_* constants
- PTP_PROTOCOL -> RTE_PTP_ETHERTYPE
- hardcoded multicast -> RTE_PTP_MULTICAST_MAC
- ptp_hdr->msg_type switch -> rte_ptp_msg_type() accessor
No functional change.
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 189 +++++++++++++-------------------- 2 files changed, 74 insertions(+), 116 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['ptp'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +73 -116
330 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [RFC v5 0/6] introduce PTP protocol library and software relay
In reply to Rajesh KumarQuoted 1 line · On Wed, 6 May 2026 21:11:22 +0530 Rajesh Kumar <[email protected]> wrote:
- Fixed checkpatch warnings: removed unnecessary #include <
stdio.h>
PS. spelling error complaints about stdio.h are bogus
v6 cover PTP protocol support in lib/net
In reply to Rajesh KumarAdd IEEE 1588-2019 Precision Time Protocol (PTP) support to DPDK via a new header library in lib/net/. This patchset provides wire-format packet structure definitions and inline helpers for Transparent Clock and ordinary clock applications.
## Design Rationale
Following DPDK conventions for protocol libraries (rte_tcp.h, rte_ip.h), PTP definitions are provided as a header-only library with inline functions for zero-overhead packet processing. All functions are suitable for real-time, performance-critical code paths.
## Contents
**Patch 1:** lib/net/rte_ptp.h - Header structures and inline helpers
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte PTP v2 common message header
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
- Message type constants (Sync, Delay_Req, Announce, etc.)
- Flag field bits (two-step, unicast, leap indicator)
- Inline helpers: rte_ptp_msg_type(), rte_ptp_seq_id(), rte_ptp_is_event(), rte_ptp_correction_ns(), rte_ptp_add_correction(), rte_ptp_timestamp_to_ns()
**Patch 2:** examples/ptp_tap_relay_sw - Software PTP Transparent Clock relay
- Relays PTP packets between a DPDK-bound physical NIC and Linux TAP interface
- Software timestamp-based residence time measurement (CLOCK_MONOTONIC)
- Accumulates residence time to PTP correctionField per IEEE 1588-2019 §10.2
- Handles L2, VLAN/QinQ, UDP/IPv4, UDP/IPv6 PTP encapsulations
- Works with unmodified Linux kernel and stock DPDK (no patches required)
- Compatible with standard linuxptp (ptp4l) tooling
**Patch 3:** doc/guides/rel_notes/release_26_07.rst - Release notes update
**Patch 4:** examples/ptpclient - Update to use lib/net PTP definitions
- Uses RTE_ETHER_TYPE_1588 constant
- Adds lib/net dependency
## Testing
- Build: ninja -C build — clean compilation
- Examples: Both ptpclient and ptp_tap_relay_sw compile and link correctly
- No stale references to old patterns or removed functions
## Changelog
v6 changes:
- Restructured to lib/net (header-only, following lib/net conventions)
- Removed separate DPI library functions (moved to example-local ptp_parse.h)
- Removed app/test unit tests (library now header-only, example-driven testing)
- Removed programmer's guide doc (lib/net headers use Doxygen API docs only)
Rajesh Kumar (4):
lib/net: add IEEE 1588 PTP v2 protocol header definitions examples/ptp_tap_relay_sw: add PTP software transparent clock relay
doc: update release notes for PTP protocol library examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 6 + doc/guides/rel_notes/release_26_07.rst | 12 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 4 +- lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 +++++++++++ 11 files changed, 1195 insertions(+), 2 deletions(-) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/net/rte_ptp.h
Signature · 1 line
2.53.0
PATCH v6 1/4 lib/net: add IEEE 1588 PTP v2 protocol header definitions
Add PTP (Precision Time Protocol) header structures and inline helper functions to lib/net following DPDK conventions for protocol libraries (similar to rte_tcp.h, rte_ip.h).
Provides wire-format structures with endian-annotated types:
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte common message header with correctionField
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
PTP message type constants for all IEEE 1588-2019 message types (Sync, Delay_Req, Announce, Management, etc.) and flag field bits (two-step, unicast, leap indicator).
Inline accessor and utility functions for performance:
- rte_ptp_msg_type(), rte_ptp_version(), rte_ptp_domain()
- rte_ptp_seq_id(), rte_ptp_is_event(), rte_ptp_is_two_step()
- rte_ptp_correction_ns(), rte_ptp_add_correction()
- rte_ptp_timestamp_to_ns() for timestamp conversion
Supports all PTP encapsulations: L2 (EtherType 0x88F7), VLAN/QinQ, UDP/IPv4, and UDP/IPv6 (ports 319/320).
All inline functions — zero function call overhead, suitable for real-time packet processing.
--- MAINTAINERS | 6 + lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 lib/net/rte_ptp.h
MAINTAINERS +6 -0
@@ -1665,6 +1665,12 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - lib/net +M: Rajesh Kumar <[email protected]> +F: lib/net/rte_ptp.h +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
lib/net/meson.build +1 -0
@@ -28,6 +28,7 @@ headers = files( 'rte_geneve.h', 'rte_l2tpv2.h', 'rte_ppp.h', + 'rte_ptp.h', 'rte_ib.h', )
lib/net/rte_ptp.h new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v6 2/4 examples/ptp_tap_relay_sw: add PTP software transparent clock relay
In reply to Rajesh KumarAdd a new example application demonstrating a software PTP Transparent Clock relay between a DPDK-bound physical NIC and a Linux kernel TAP virtual interface.
The relay uses software timestamps (CLOCK_MONOTONIC) to measure residence time and accumulates it into the PTP correctionField per IEEE 1588-2019 §10.2, enabling synchronized time distribution via standard linuxptp (ptp4l) on both sides.
Features:
- Handles L2, VLAN/QinQ, and UDP/IPv4/IPv6 PTP encapsulations
- Supports PTP v2 event messages (Sync, Delay_Req, PDelay_Req, PDelay_Resp)
- Two-pass burst processing: classify then timestamp immediately before TX
- Unmodified Linux kernel and stock DPDK (no kernel patches required)
- Bidirectional relay: PHY ↔ TAP
Includes:
- ptp_tap_relay_sw.c: Main relay logic with burst processing
- ptp_parse.h: Local DPI parser for PTP classification (not a library API)
- Sample app guide with topology, command-line options, and example output
Uses lib/net/rte_ptp.h inline helpers for correctionField manipulation and header parsing.
--- doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ 5 files changed, 909 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
@@ -0,0 +1,212 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright(c) 2026 Intel Corporation. + +PTP Software Relay Sample Application +====================================== + +The PTP Software Relay sample application demonstrates how to build a +minimal PTP Transparent Clock relay between a DPDK-bound physical NIC +and a kernel TAP interface using **software timestamps only**. It uses +the PTP definitions from ``rte_ptp.h`` (in ``lib/net/``) together with a +local packet parser. + +The application works with an unmodified Linux kernel and stock DPDK. + +For background on PTP see: +`Precision Time Protocol +<https://en.wikipedia.org/wiki/Precision_Time_Protocol>`_. + + +Limitations +----------- + +* Tested with L2 PTP (EtherType 0x88F7) on the wire. + The local parser also classifies VLAN/QinQ and UDP/IPv4/IPv6. +* Only PTP v2 messages are processed. +* Software timestamps have microsecond-class jitter; sub-microsecond + precision depends on system load and NIC-to-TAP forwarding latency. +* The PTP time transmitter must be reachable on the physical NIC's L2 network. +* Only one physical port and one TAP port are supported. + + +How the Application Works +------------------------- + +Topology +~~~~~~~~ + +:: + + PTP Time Transmitter Physical NIC TAP (kernel) + (ptp4l -H) ──L2── (DPDK vfio-pci) ────── dtap0 + │ │ + ptp_tap_relay_sw ptp4l -S + (correctionField += (SW timestamps, + residence time) adjusts CLOCK_REALTIME) + +The relay sits between a DPDK-owned physical NIC and a kernel TAP +virtual interface. ``ptp4l`` runs on the TAP interface in software +timestamp mode (``-S``) as a PTP time receiver. + +Packet Flow +~~~~~~~~~~~ + +1. The physical NIC receives PTP (and non-PTP) packets via DPDK RX. +2. A software RX timestamp is recorded using + ``clock_gettime(CLOCK_MONOTONIC)``. +3. Each packet is parsed to locate the PTP header. +4. For PTP **event** messages (Sync, Delay_Req, PDelay_Req, PDelay_Resp), + a TX software timestamp is taken just before transmission. +5. The residence time (``tx_ts − rx_ts``) is added to the PTP + ``correctionField`` via ``rte_ptp_add_correction()`` — standard + IEEE 1588-2019 Transparent Clock behaviour (§10.2). +6. Packets are forwarded bidirectionally: + + * PHY → TAP (network → ptp4l) + * TAP → PHY (ptp4l → network) + +A two-pass design is used: first all packets are classified and PTP +header pointers saved, then a single TX timestamp is taken immediately +before applying corrections and calling ``rte_eth_tx_burst()``. +This minimises the gap between the measured timestamp and the actual +wire egress. + + +Compiling the Application +------------------------- + +To compile the sample application see :doc:`compiling`. + +The application is located in the ``ptp_tap_relay_sw`` sub-directory. + +.. note:: + + The application uses ``rte_ptp.h`` from ``lib/net/`` (built by default) + and a local ``ptp_parse.h`` header for packet classification. + + +Running the Application +----------------------- + +Prerequisites +~~~~~~~~~~~~~ + +* A PTP-capable physical NIC bound to DPDK (e.g. via ``vfio-pci``). +* ``linuxptp`` (``ptp4l``) installed on the system. +* A PTP time transmitter reachable on the same L2 network. + +Start the relay +~~~~~~~~~~~~~~~~ + +.. code-block:: console + + ./<build_dir>/examples/dpdk-ptp_tap_relay_sw \ + -l 18-19 -a 0000:cc:00.1 --vdev=net_tap0,iface=dtap0 -- \ + -p 0 -t 1 -T 10 + +Command-line Options +~~~~~~~~~~~~~~~~~~~~ + +* ``-p PORT`` — Physical NIC port ID (default: 0). +* ``-t PORT`` — TAP port ID (default: 1). +* ``-T SECS`` — Statistics print interval in seconds (default: 10). + +Start PTP time transmitter +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +On a separate terminal or remote host, start ``ptp4l`` as time +transmitter with hardware timestamps on the physical NIC: + +.. code-block:: console + + ptp4l -i <iface> -m -2 -H --serverOnly=1 \ + --logSyncInterval=-4 --logMinDelayReqInterval=-4 + +Start PTP time receiver +~~~~~~~~~~~~~~~~~~~~~~~ + +On the TAP interface, start ``ptp4l`` in software timestamp mode: + +.. code-block:: console + + ptp4l -i dtap0 -m -2 -s -S \ + --delay_filter=moving_median --delay_filter_length=10 + +The time receiver will enter UNCALIBRATED state for approximately 60 +seconds while the PI servo estimates the frequency offset, then step +the clock and enter time-receiver (synchronized) state. +Steady-state RMS offset of 500–1000 ns is typical on a lightly loaded +system with a hardware-timestamped time transmitter. + +Example Output +~~~~~~~~~~~~~~ + +Relay statistics printed every ``-T`` seconds: + +:: + + [PTP-SW] === Statistics === + [PTP-SW] PHY RX total: 5646 + [PTP-SW] PHY RX PTP: 5598 + [PTP-SW] TAP TX: 5646 + [PTP-SW] TAP RX total: 1800 + [PTP-SW] TAP RX PTP: 1788 + [PTP-SW] PHY TX: 1800 + [PTP-SW] Corrections: 3635 + +Time receiver ``ptp4l`` output after convergence: + +:: + + ptp4l[451534.520]: rms 630 max 1166 freq -44365 +/- 100 delay 37668 +/- 71 + ptp4l[451539.525]: rms 602 max 1177 freq -44339 +/- 119 delay 37517 +/- 43 + ptp4l[451544.530]: rms 535 max 1194 freq -44345 +/- 103 delay 37410 +/- 81 + + +Code Explanation +---------------- + +The following sections explain the main components of the application. + +Relay Burst Function +~~~~~~~~~~~~~~~~~~~~ + +The core relay logic is in ``relay_burst()``, which handles one direction +(PHY→TAP or TAP→PHY) per call: + +**Pass 1 — Classify:** + +For each received packet, ``ptp_hdr_find()`` locates the PTP header +(if present). For event messages, the header pointer is saved for the +second pass. + +**Pass 2 — Timestamp and correct:** + +A single software TX timestamp is taken via +``clock_gettime(CLOCK_MONOTONIC)``. The residence time +(``tx_ts − rx_ts``) is added to each saved PTP header's +``correctionField`` using ``rte_ptp_add_correction()``. +The burst is then transmitted with ``rte_eth_tx_burst()``. + +Main Loop +~~~~~~~~~ + +The ``relay_loop()`` function polls both directions in a tight loop: + +.. code-block:: c + + while (!force_quit) { + relay_burst(phy_port, tap_port, ...); /* PHY → TAP */ + relay_burst(tap_port, phy_port, ...); /* TAP → PHY */ + } + +Statistics are printed at the interval specified by ``-T``. + +Timestamp Source +~~~~~~~~~~~~~~~~ + +``CLOCK_MONOTONIC`` is used rather than ``CLOCK_REALTIME`` because +the PTP time receiver's servo continuously adjusts ``CLOCK_REALTIME``. +Using ``CLOCK_REALTIME`` would corrupt residence time measurements +during clock stepping or frequency slewing. ``CLOCK_MONOTONIC`` is +portable across Linux and FreeBSD.
examples/ptp_tap_relay_sw/Makefile new file +41 -0
41 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_parse.h new file +211 -0
211 lines not on this page · raw message
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v6 3/4 doc: update release notes for PTP protocol library
In reply to Rajesh KumarUpdate release notes with IEEE 1588 PTP additions:
- PTP protocol definitions in lib/net/rte_ptp.h (header-only library with inline helpers and wire-format structures)
- PTP software relay example application (ptp_tap_relay_sw)
--- doc/guides/rel_notes/release_26_07.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_26_07.rst +12 -0
@@ -63,6 +63,18 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol definitions (rte_ptp.h).** + + Added IEEE 1588 Precision Time Protocol header structures, constants, + and inline helpers to ``lib/net/rte_ptp.h``. Provides wire-format + structures with endian-annotated types and correctionField manipulation + for Transparent Clock implementations. + +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. Removed Items -------------
Signature · 1 line
2.53.0
PATCH v6 4/4 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarUpdate ptpclient example to use IEEE 1588 PTP definitions from lib/net:
- Replace PTP_PROTOCOL macro with standard RTE_ETHER_TYPE_1588
- Remove local duplicate PTP header definitions
- Add net library dependency in meson.build
- Leverage rte_ptp.h inline helpers for header access
This aligns with DPDK library patterns and reduces code duplication. The example remains compatible with standard linuxptp (ptp4l) tooling for time synchronization.
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['net'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +2 -2
@@ -441,7 +441,7 @@ parse_fup(struct ptpv2_time_receiver_ordinary *ptp_data)/* Set multicast address 01-1B-19-00-00-00. */ rte_ether_addr_copy (ð_multicast, ð_hdr->dst_addr); - eth_hdr->ether_type =htons (PTP_PROTOCOL ); + eth_hdr->ether_type =htons (RTE_ETHER_TYPE_1588 ); req_msg =rte_pktmbuf_mtod_offset (created_pkt, struct delay_req_msg *, sizeof(structrte_ether_hdr ));
@@ -582,7 +582,7 @@ parse_ptp_frames(uint16_t portid, struct rte_mbuf *m) { eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); eth_type =rte_be_to_cpu_16 (eth_hdr->ether_type); -if (eth_type ==PTP_PROTOCOL ) { +if (eth_type ==RTE_ETHER_TYPE_1588 ) { ptp_data.m = m; ptp_data.portid = portid; ptp_hdr = rte_pktmbuf_mtod_offset(m, struct ptp_header *,
Signature · 1 line
2.53.0
v7 cover IEEE 1588 PTP v2 protocol support in lib/net
In reply to Rajesh KumarAdd IEEE 1588-2019 Precision Time Protocol (PTP) support to DPDK via a new header library in lib/net/. This patchset provides wire-format packet structure definitions and inline helpers for Transparent Clock and ordinary clock applications.
Design Rationale
================
Following DPDK conventions for protocol libraries (rte_tcp.h, rte_ip.h), PTP definitions are provided as a header-only library with inline functions for zero-overhead packet processing. All functions are suitable for real-time, performance-critical code paths.
Contents
========
Patch 1: lib/net/rte_ptp.h - Header structures and inline helpers
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte PTP v2 common message header
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
- Message type constants (Sync, Delay_Req, Announce, etc.)
- Flag field bits (two-step, unicast, leap indicator)
- Inline helpers: rte_ptp_msg_type(), rte_ptp_seq_id(),
rte_ptp_is_event(), rte_ptp_correction_ns(), rte_ptp_add_correction(),
rte_ptp_timestamp_to_ns()Patch 2: examples/ptp_tap_relay_sw - Software PTP Transparent Clock relay
- Relays PTP packets between a DPDK-bound physical NIC and Linux TAP
- Software timestamp-based residence time measurement (CLOCK_MONOTONIC)
- Accumulates residence time to correctionField per IEEE 1588-2019 §10.2
- Handles L2, VLAN/QinQ, UDP/IPv4, UDP/IPv6 PTP encapsulations
- Works with unmodified Linux kernel and stock DPDK (no patches required)
- Compatible with standard linuxptp (ptp4l) tooling
Patch 3: doc/guides/rel_notes/release_26_07.rst - Release notes update
Patch 4: examples/ptpclient - Update to use lib/net PTP definitions
- Replace local struct ptp_header with struct rte_ptp_hdr
- Replace local struct tstamp with struct rte_ptp_timestamp
- Replace local struct clock_id with uint8_t[8] arrays
- Use RTE_PTP_MSGTYPE_* constants instead of local defines
- Use rte_ptp_msg_type(), rte_ptp_seq_id() inline helpers
- Remove local PTP_PROTOCOL macro (use RTE_ETHER_TYPE_1588)
- Add lib/net dependency in meson.build
Testing
=======
- Build: ninja -C build - clean compilation
- Examples: Both ptpclient and ptp_tap_relay_sw compile and link correctly
- No stale references to old patterns or removed functions
Changelog
=========
v7 changes:
- Added sample app guide to sample_app_ug toctree to fix Sphinx warning
- Fixed all checkpatch warnings (commit message line lengths <= 75 chars)
- Refactored ptpclient to use shared lib/net/rte_ptp.h definitions
- All 5 patches (cover + 4 functional) pass checkpatch validation
v6 changes:
- Restructured to lib/net (header-only, following lib/net conventions)
- Removed separate DPI library functions (moved to example local parser)
- Removed app/test unit tests (header-only, example-driven testing)
- Removed programmer's guide (lib/net headers use Doxygen API docs only)
Rajesh Kumar (4):
lib/net: add IEEE 1588 PTP v2 protocol header definitions examples/ptp_tap_relay_sw: add PTP software transparent clock relay
doc: update release notes for PTP protocol library examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 6 + doc/guides/rel_notes/release_26_07.rst | 12 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 204 ++++----- lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 +++++++++++ 12 files changed, 1274 insertions(+), 124 deletions(-) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/net/rte_ptp.h
Signature · 1 line
2.53.0
PATCH v7 1/4 lib/net: add IEEE 1588 PTP v2 protocol header definitions
Add PTP (Precision Time Protocol) header structures and inline helper functions to lib/net following DPDK conventions for protocol libraries (similar to rte_tcp.h, rte_ip.h).
Provides wire-format structures with endian-annotated types:
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte common message header with correctionField
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
PTP message type constants for all IEEE 1588-2019 message types (Sync, Delay_Req, Announce, Management, etc.) and flag field bits (two-step, unicast, leap indicator).
Inline accessor and utility functions for performance:
- rte_ptp_msg_type(), rte_ptp_version(), rte_ptp_domain()
- rte_ptp_seq_id(), rte_ptp_is_event(), rte_ptp_is_two_step()
- rte_ptp_correction_ns(), rte_ptp_add_correction()
- rte_ptp_timestamp_to_ns() for timestamp conversion
Supports all PTP encapsulations: L2 (EtherType 0x88F7), VLAN/QinQ, UDP/IPv4, and UDP/IPv6 (ports 319/320).
All inline functions — zero function call overhead, suitable for real-time packet processing.
--- MAINTAINERS | 6 + lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 lib/net/rte_ptp.h
MAINTAINERS +6 -0
@@ -1665,6 +1665,12 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - lib/net +M: Rajesh Kumar <[email protected]> +F: lib/net/rte_ptp.h +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
lib/net/meson.build +1 -0
@@ -28,6 +28,7 @@ headers = files( 'rte_geneve.h', 'rte_l2tpv2.h', 'rte_ppp.h', + 'rte_ptp.h', 'rte_ib.h', )
lib/net/rte_ptp.h new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.53.0
RE: [PATCH v7 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions
Quoted 23 lines
From: Rajesh Kumar [mailto:[email protected]]
Sent: Thursday, 7 May 2026 15.45
To: [email protected]Add PTP (Precision Time Protocol) header structures and inline helper functions to lib/net following DPDK conventions for protocol libraries (similar to
rte_tcp.h,rte_ip.h).Provides wire-format structures with endian-annotated types:
-rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
-rte_ptp_hdr: 34-byte common message header with correctionField
-rte_ptp_timestamp: 10-byte nanosecond-precision timestampPTP message type constants for all IEEE 1588-2019 message types (Sync,
Delay_Req, Announce, Management, etc.) and flag field bits (two-step, unicast, leap indicator).Inline accessor and utility functions for performance:
-rte_ptp_msg_type(),rte_ptp_version(),rte_ptp_domain()
-rte_ptp_seq_id(),rte_ptp_is_event(),rte_ptp_is_two_step()
-rte_ptp_correction_ns(),rte_ptp_add_correction()
-rte_ptp_timestamp_to_ns()for timestamp conversion
Quoted 7 lines
Supports all PTP encapsulations: L2 (EtherType
0x88F7), VLAN/QinQ, UDP/IPv4, and UDP/IPv6 (ports 319/320).All inline functions — zero function call overhead, suitable for real-time packet processing.
Signed-off-by Rajesh Kumar <[email protected]>
Great progress.
My next wave of comments inline below. :-)
Quoted 12 lines
--- MAINTAINERS | 6 + lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 lib/net/rte_ptp.hMAINTAINERS +0
-0
MAINTAINERS F: doc/guides/prog_guide/ipsec_lib.rst · line 1668
Quoted 4 lines
MAINTAINERS +1
-0@@ -1665,6 +1665,12 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP - lib/net
Please remove lib/net from this headline.
Intead, suggest:
PTP (IEEE 1588 Precision Time Protocol)
Quoted 58 lines
MAINTAINERS +5
-0+M: Rajesh Kumar <[email protected]> +F: lib/net/rte_ptp.h +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>lib/net/meson.build +1
-0@@ -28,6 +28,7 @@ headers = files( 'rte_geneve.h', 'rte_l2tpv2.h', 'rte_ppp.h', + 'rte_ptp.h', 'rte_ib.h', )lib/net/rte_ptp.h new file +28
-0@@ -0,0 +1,264 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2026 Intel Corporation +*/ + +#ifndef _RTE_PTP_H_ +#define _RTE_PTP_H_ + +/** + * @file + * + * PTP (IEEE 1588) protocol definitions + */ + +#include <stdint.h> +#include <stdbool.h> + +#include <rte_byteorder.h> +#include <rte_common.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * PTP Constants + */ + +/** PTP over UDP event port (Sync, Delay_Req, PDelay_Req,
PDelay_Resp). */lib/net/rte_ptp.h new file +3
-0+#define RTE_PTP_EVENT_PORT 319 + +/** PTP over UDP general port (Follow_Up, Delay_Resp, Announce, etc.).
Quoted 2 lines
*/
+#defineRTE_PTP_GENERAL_PORT320
The libc header <netinet/in.h> defines IPPORT_xxx. We should use something similar:
#define RTE_IPPORT_PTP_EVENT and RTE_IPPORT_PTP_GENERAL
Quoted 8 lines
lib/net/rte_ptp.h new file +3
-0+ +/** PTP multicast MAC address: 01:1B:19:00:00:00. */ +#define RTE_PTP_MULTICAST_MAC { 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00}
lib/net/rte_ptp.h new file +3
-0+ +/** PTP peer delay multicast MAC: 01:80:C2:00:00:0E. */ +#define RTE_PTP_PDELAY_MULTICAST_MAC { 0x01, 0x80, 0xC2, 0x00, 0x00,
0x0E}
Similarly here; we should establish a convention for MAC addresses, like RTE_ETHER_TYPE_xxx in DPDK <lib/net/rte_ether.h>. Suggest:RTE_ETHER_ADDR_PTP_MULTICAST and RTE_ETHER_ADDR_PTP_MULTICAST_PDELAY
This also follows the general naming convention of having the broadest scope is first and the narrowest scope last.
Quoted 10 lines
lib/net/rte_ptp.h new file +7
-0+ +/* +* PTP Message Types (IEEE 1588-2019 Table 36) +*/ + +#define RTE_PTP_MSGTYPE_SYNC 0x0/**< Sync (event). */ +#define RTE_PTP_MSGTYPE_DELAY_REQ 0x1/**< Delay_Req (event). */
+#defineRTE_PTP_MSGTYPE_PDELAY_REQ0x2/**<Peer_Delay_Req
(event). */
Quoted 8 lines
+#define
RTE_PTP_MSGTYPE_PDELAY_RESP0x3/**<Peer_Delay_Resp
(event). */
+#defineRTE_PTP_MSGTYPE_FOLLOW_UP0x8/**<Follow_Up(general).
*/
+#defineRTE_PTP_MSGTYPE_DELAY_RESP0x9/**<Delay_Resp
(general). */
+#defineRTE_PTP_MSGTYPE_PDELAY_RESP_FU0xA/**<Peer_Delay_Resp_Follow_Up. */
Missing in the description: (general)
For consistency, consider renaming RTE_PTP_MSGTYPE_FOLLOW_UP to RTE_PTP_MSGTYPE_FU.
Quoted 9 lines
+#define
RTE_PTP_MSGTYPE_ANNOUNCE0xB/**< Announce (general).
*/
+#defineRTE_PTP_MSGTYPE_SIGNALING0xC/**< Signaling (general).
*/
+#defineRTE_PTP_MSGTYPE_MANAGEMENT0xD/**< Management
(general). */lib/net/rte_ptp.h new file +3
-0+ +/* +* PTP Flag Field Bits (IEEE 1588-2019 Table 37)
lib/net/rte_ptp.h line 66
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* +* These constants are for use after rte_be_to_cpu_16(hdr->flags). +* flagField[0] (octet 6) maps to host bits 8-15. +* flagField[1] (octet 7) maps to host bits 0-7. +*/ + +#define RTE_PTP_FLAG_TWO_STEP (1 << 9)/**< Two-step flag. */ +#define RTE_PTP_FLAG_UNICAST (1 << 10)/**< Unicast flag. */ +#define RTE_PTP_FLAG_LI_61 (1 << 0)/**< Leap indicator 61. */ +#define RTE_PTP_FLAG_LI_59 (1 << 1)/**< Leap indicator 59. */
We don't have a RTE_BIT16() macro like the RTE_BIT32/64() macros, so maybe use:
#define RTE_PTP_FLAG_TWO_STEP (UINT16_C(1) << 9) /**< Two-step flag. */ #define RTE_PTP_FLAG_UNICAST (UINT16_C(1) << 10) /**< Unicast flag. */ #define RTE_PTP_FLAG_LI_61 (UINT16_C(1) << 0) /**< Leap indicator 61. */ #define RTE_PTP_FLAG_LI_59 (UINT16_C(1) << 1) /**< Leap indicator 59. */
Quoted 20 lines
lib/net/rte_ptp.h new file +18
-0+ +/* +* PTP Header Structures (IEEE 1588-2019) +*/ + +/** +* PTP Port Identity (10 bytes). +*/ +struct __rte_packed_begin rte_ptp_port_id { +uint8_t clock_id[8 ];/**< clockIdentity (EUI-64). */ +rte_be16_t port_number;/**< portNumber. */ +} __rte_packed_end; + +/** +* PTP Common Message Header (34 bytes). +*/ +struct __rte_packed_begin rte_ptp_hdr { +uint8_t msg_type;/**< transportSpecific (4) | messageType (4). */
lib/net/rte_ptp.h new file +1
-0+uint8_t version;/**< minorVersionPTP (4) | versionPTP
Quoted 1 line
(4). */
The two fields above should be split into their nibbles, for direct access, like the version_ihl field in the IPv4 header:
https://elixir.bootlin.com/dpdk/v26.03/source/lib/net/rte_ip4.h#L43
E.g.:
__extension__
union {
uint8_t ts_msgtype; /**< Message type */
struct {
#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
uint8_t msg_type:4; /**< messageType */
uint8_t ts:4; /**< transportSpecific */
#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
uint8_t ts:4; /**< transportSpecific */
uint8_t msg_type:4; /**< messageType */
#endif
};
};Warning: I'm not sure I got the nibble order right. Make sure you do! :-)
Quoted 13 lines
lib/net/rte_ptp.h new file +4
-0+rte_be16_t msg_length;/**< Total message length in bytes. */ +uint8_t domain_number;/**< PTP domain (0-255). */ +uint8_t minor_sdo_id;/**< minorSdoId (IEEE 1588-2019). */ +rte_be16_t flags;/**< Flag field (see RTE_PTP_FLAG_*). */
lib/net/rte_ptp.h new file +1
-0+rte_be64_t correction;/**< correctionField (scaled ns, 48.16 fixed). */
lib/net/rte_ptp.h new file +2
-0+rte_be32_t msg_type_specific;/**< messageTypeSpecific. */ +struct rte_ptp_port_id source_port_id;/**< sourcePortIdentity. */
lib/net/rte_ptp.h new file +2
-0+rte_be16_t sequence_id;/**< sequenceId. */ +uint8_t control;/**< controlField (deprecated in 1588- 2019). */
lib/net/rte_ptp.h line 99
Quoted 5 lines
lib/net/rte_ptp.h new file +5
-0+int8_t log_msg_interval;/**< logMessageInterval. */ +} __rte_packed_end; + +/** +* PTP Timestamp (10 bytes, used in Sync/Delay_Req/Follow_Up bodies).
The PTP timestamp origo should be mentioned here. E.g. the UNIX time_t origo is Jan 1st 00:00:00 1970.
Quoted 70 lines
+ */
lib/net/rte_ptp.h new file +69
-0+struct __rte_packed_begin rte_ptp_timestamp { +rte_be16_t seconds_hi;/**< Upper 16 bits of seconds. */ +rte_be32_t seconds_lo;/**< Lower 32 bits of seconds. */ +rte_be32_t nanoseconds;/**< Nanoseconds (0-999999999). */ +} __rte_packed_end; + +/* +* Inline Helpers +*/ + +/** +* Extract PTP message type from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* Message type (0x0-0xF). +*/ +static inline uint8_t +rte_ptp_msg_type (const struct rte_ptp_hdr *hdr) +{ +return hdr->msg_type &0x0F ; +} + +/** +* Extract transport-specific field from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* Transport-specific value (upper nibble, 0x0-0xF). +*/ +static inline uint8_t +rte_ptp_transport_specific (const struct rte_ptp_hdr *hdr) +{ +return (hdr->msg_type >>4 ) &0x0F ; +} + +/** +* Extract PTP version from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* PTP version number (typically 2). +*/ +static inline uint8_t +rte_ptp_version (const struct rte_ptp_hdr *hdr) +{ +return hdr->version &0x0F ; +} + +/** +* Get sequence ID from PTP header (host byte order). +* +* @param hdr +* Pointer to PTP header. +* @return +* Sequence ID in host byte order. +*/ +static inline uint16_t +rte_ptp_seq_id (const struct rte_ptp_hdr *hdr) +{ +return rte_be_to_cpu_16 (hdr->sequence_id); +} + +/** +* Get PTP domain number. +*
lib/net/rte_ptp.h line 179
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* @param hdr +* Pointer to PTP header. +* @return +* Domain number (0-255). +*/ +static inline uint8_t +rte_ptp_domain (const struct rte_ptp_hdr *hdr) +{ +return hdr->domain_number; +}
The above "get" accessor functions are superfluous. Please remove:rte_ptp_msg_type()rte_ptp_transport_specific()rte_ptp_version()rte_ptp_seq_id()rte_ptp_domain()
Quoted 5 lines
lib/net/rte_ptp.h new file +5
-0+ +/** +* Check if PTP message type is an event message. +* Event messages (msg_type 0x0-0x3) require timestamps. +*
lib/net/rte_ptp.h line 194
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* @param msg_type +* PTP message type value (0x0-0xF). +* @return +* true if event message, false otherwise. +*/ +static inline bool +rte_ptp_is_event (int msg_type) +{ +return msg_type >=0 && msg_type <=RTE_PTP_MSGTYPE_PDELAY_RESP ; +}
Suggest passing the parameter as const struct rte_ptp_hdr *hdr, like in rte_ptp_is_two_step() below.
Quoted 13 lines
lib/net/rte_ptp.h new file +13
-0+ +/** +* Check if the two-step flag is set in a PTP header. +* +* @param hdr +* Pointer to PTP header. +* @return +* true if two-step flag is set. +*/ +static inline bool +rte_ptp_is_two_step (const struct rte_ptp_hdr *hdr) +{ + return (rte_be_to_cpu_16(hdr->flags) & RTE_PTP_FLAG_TWO_STEP) !=
Quoted 1 line
0;
Faster way:
return (hdr->flags & RTE_BE16(RTE_PTP_FLAG_TWO_STEP)) != 0;
Quoted 5 lines
lib/net/rte_ptp.h new file +5
-0+} + +/** +* Get correctionField value in nanoseconds (from 48.16 fixed-point). +*
lib/net/rte_ptp.h line 222
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* @param hdr +* Pointer to PTP header. +* @return +* Correction value in nanoseconds. +*/ +static inline int64_t +rte_ptp_correction_ns (const struct rte_ptp_hdr *hdr) +{ +return (int64_t )rte_be_to_cpu_64 (hdr->correction) >>16 ; +}
This "get" accessor function is superfluous. Please remove:rte_ptp_correction_ns()
The "correction" field in the PTP header structure should sufficiently describe the field's fixed-point encoding.
Quoted 12 lines
lib/net/rte_ptp.h new file +5
-0+ +/** +* Add a residence time (in nanoseconds) to the correctionField. +* Used by Transparent Clocks to account for relay transit delay. +* The correctionField uses IEEE 1588 scaled nanoseconds (48.16 fixed- point).
+ *
+ * @param hdr
+ * Pointer to PTP header (will be modified in-place).
+ * @paramresidence_ns
+ * Residence time in nanoseconds to add.
+ */
lib/net/rte_ptp.h line 241
Quoted 8 lines
lib/net/rte_ptp.h new file +8
-0+static inline void +rte_ptp_add_correction (struct rte_ptp_hdr *hdr,int64_t residence_ns) +{ +int64_t cf = (int64_t )rte_be_to_cpu_64 (hdr->correction); + + cf += (int64_t )((uint64_t )residence_ns <<16 ); + hdr->correction =rte_cpu_to_be_64 (cf); +}
I don't think negative time can be added, so please use uint64_t instead of int64_t for the parameter and inside the function.
Note to reviewers: "residence time" is the term in the standard. "sojourn time" is not used.
Quoted 14 lines
lib/net/rte_ptp.h new file +13
-0+ +/** +* Convert a PTP timestamp structure to nanoseconds since epoch. +* +* @param ts +* Pointer to PTP timestamp. +* @return +* Time in nanoseconds since epoch. +*/ +static inline uint64_t +rte_ptp_timestamp_to_ns (const struct rte_ptp_timestamp *ts) +{ +uint64_t sec = ((uint64_t )rte_be_to_cpu_16 (ts->seconds_hi) <<32 )|
lib/net/rte_ptp.h line 258
Quoted 4 lines
lib/net/rte_ptp.h new file +4
-0+rte_be_to_cpu_32 (ts->seconds_lo); + +return sec *1000000000ULL +rte_be_to_cpu_32 (ts->nanoseconds); +}
1000000000ULL -> UINT64_C(1000000000)
Quoted 8 lines
lib/net/rte_ptp.h new file +6
-1+ +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_PTP_H_ */ --2.53.0
Re: [PATCH v7 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions
Quoted 26 lines · Morten Brørup
Quoted 26 lines
From: Rajesh Kumar [mailto:[email protected]]
Sent: Thursday, 7 May 2026 15.45
To: [email protected]Add PTP (Precision Time Protocol) header structures and inline helper functions to lib/net following DPDK conventions for protocol libraries (similar to
rte_tcp.h,rte_ip.h).Provides wire-format structures with endian-annotated types:
-rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
-rte_ptp_hdr: 34-byte common message header with correctionField
-rte_ptp_timestamp: 10-byte nanosecond-precision timestampPTP message type constants for all IEEE 1588-2019 message types (Sync,
Delay_Req, Announce, Management, etc.) and flag field bits (two-step, unicast, leap indicator).Inline accessor and utility functions for performance:
-rte_ptp_msg_type(),rte_ptp_version(),rte_ptp_domain()
-rte_ptp_seq_id(),rte_ptp_is_event(),rte_ptp_is_two_step()
-rte_ptp_correction_ns(),rte_ptp_add_correction()
-rte_ptp_timestamp_to_ns()for timestamp conversionSupports all PTP encapsulations: L2 (EtherType
0x88F7), VLAN/QinQ, UDP/IPv4, and UDP/IPv6 (ports 319/320).
Quoted 7 lines
Quoted 4 lines
All inline functions — zero function call overhead, suitable for real-time packet processing.
Signed-off-by Rajesh Kumar <[email protected]>Great progress.
My next wave of comments inline below. :-)
Appreciate your time and feedback :-)
Quoted 16 lines
Quoted 16 lines
--- MAINTAINERS | 6 + lib/net/meson.build | 1 + lib/net/rte_ptp.h | 264 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+)create mode 100644
lib/net/rte_ptp.hMAINTAINERS +0
-0@@ -1665,6 +1665,12 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/
Quoted 4 lines
MAINTAINERS F: doc/guides/prog_guide/ipsec_lib.rst · line 1668
Quoted 1 line
MAINTAINERS +1
-0+PTP - lib/netPlease remove lib/net from this headline.
Intead, suggest:
PTP (IEEE 1588 Precision Time Protocol)
Done. Changed to PTP (IEEE 1588 Precision Time Protocol)
Quoted 56 lines
Quoted 56 lines
MAINTAINERS +5
-0+M: Rajesh Kumar <[email protected]> +F: lib/net/rte_ptp.h +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>lib/net/meson.build +1
-0@@ -28,6 +28,7 @@ headers = files( 'rte_geneve.h', 'rte_l2tpv2.h', 'rte_ppp.h', + 'rte_ptp.h', 'rte_ib.h', )lib/net/rte_ptp.h new file +28
-0@@ -0,0 +1,264 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2026 Intel Corporation +*/ + +#ifndef _RTE_PTP_H_ +#define _RTE_PTP_H_ + +/** + * @file + * + * PTP (IEEE 1588) protocol definitions + */ + +#include <stdint.h> +#include <stdbool.h> + +#include <rte_byteorder.h> +#include <rte_common.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * PTP Constants + */ + +/** PTP over UDP event port (Sync, Delay_Req, PDelay_Req,
PDelay_Resp). */
Quoted 8 lines
Quoted 5 lines
lib/net/rte_ptp.h new file +3
-0+#define RTE_PTP_EVENT_PORT 319 + +/** PTP over UDP general port (Follow_Up, Delay_Resp, Announce, etc.). */
+#defineRTE_PTP_GENERAL_PORT320The libc header <
netinet/in.h> definesIPPORT_xxx. We should use something similar:
#defineRTE_IPPORT_PTP_EVENTandRTE_IPPORT_PTP_GENERAL
Done. Renamed RTE_PTP_EVENT_PORT → RTE_IPPORT_PTP_EVENT and RTE_PTP_GENERAL_PORT → RTE_IPPORT_PTP_GENERAL. Updated all usages in ptp_parse.h (IPv4 and IPv6 sections).
Quoted 13 lines
Quoted 8 lines
lib/net/rte_ptp.h new file +3
-0+ +/** PTP multicast MAC address: 01:1B:19:00:00:00. */ +#define RTE_PTP_MULTICAST_MAC { 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00}
lib/net/rte_ptp.h new file +3
-0+ +/** PTP peer delay multicast MAC: 01:80:C2:00:00:0E. */ +#define RTE_PTP_PDELAY_MULTICAST_MAC { 0x01, 0x80, 0xC2, 0x00, 0x00,
0x0E}Similarly here; we should establish a convention for MAC addresses, like
RTE_ETHER_TYPE_xxxin DPDK <lib/net/rte_ether.h>. Suggest:RTE_ETHER_ADDR_PTP_MULTICASTandRTE_ETHER_ADDR_PTP_MULTICAST_PDELAY
Quoted 1 line
This also follows the general naming convention of having the broadest scope is first and the narrowest scope last.
Done. Renamed to RTE_ETHER_ADDR_PTP_MULTICAST and RTE_ETHER_ADDR_PTP_MULTICAST_PDELAY.
Quoted 12 lines
Quoted 12 lines
lib/net/rte_ptp.h new file +7
-0+ +/* +* PTP Message Types (IEEE 1588-2019 Table 36) +*/ + +#define RTE_PTP_MSGTYPE_SYNC 0x0/**< Sync (event). */ +#define RTE_PTP_MSGTYPE_DELAY_REQ 0x1/**< Delay_Req (event). */
+#defineRTE_PTP_MSGTYPE_PDELAY_REQ0x2/**<Peer_Delay_Req
(event). */
+#defineRTE_PTP_MSGTYPE_PDELAY_RESP0x3/**<Peer_Delay_Resp
Quoted 8 lines
Quoted 7 lines
(event). */
+#defineRTE_PTP_MSGTYPE_FOLLOW_UP0x8/**<Follow_Up(general).
*/
+#defineRTE_PTP_MSGTYPE_DELAY_RESP0x9/**<Delay_Resp
(general). */
+#defineRTE_PTP_MSGTYPE_PDELAY_RESP_FU0xA/**<Peer_Delay_Resp_Follow_Up. */Missing in the description: (general)
Done. Changed to Peer_Delay_Resp_Follow_Up (general).
Quoted 2 lines
For consistency, consider renaming
RTE_PTP_MSGTYPE_FOLLOW_UPtoRTE_PTP_MSGTYPE_FU.
Done. Renamed RTE_PTP_MSGTYPE_FOLLOW_UP to RTE_PTP_MSGTYPE_FU.
Quoted 22 lines
Quoted 10 lines
+#define
RTE_PTP_MSGTYPE_ANNOUNCE0xB/**< Announce (general).
*/
+#defineRTE_PTP_MSGTYPE_SIGNALING0xC/**< Signaling (general).
*/
+#defineRTE_PTP_MSGTYPE_MANAGEMENT0xD/**< Management
(general). */lib/net/rte_ptp.h new file +3
-0+ +/* +* PTP Flag Field Bits (IEEE 1588-2019 Table 37) lib/net/rte_ptp.h line 66
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* +* These constants are for use after rte_be_to_cpu_16(hdr->flags). +* flagField[0] (octet 6) maps to host bits 8-15. +* flagField[1] (octet 7) maps to host bits 0-7. +*/ + +#define RTE_PTP_FLAG_TWO_STEP (1 << 9)/**< Two-step flag. */ +#define RTE_PTP_FLAG_UNICAST (1 << 10)/**< Unicast flag. */ +#define RTE_PTP_FLAG_LI_61 (1 << 0)/**< Leap indicator 61. */ +#define RTE_PTP_FLAG_LI_59 (1 << 1)/**< Leap indicator 59. */ We don't have a
RTE_BIT16()macro like the RTE_BIT32/64() macros, so maybe use:
Quoted 4 lines
#define RTE_PTP_FLAG_TWO_STEP (UINT16_C(1) << 9) /**< Two-step flag. */ #define RTE_PTP_FLAG_UNICAST (UINT16_C(1) << 10) /**< Unicast flag. */ #define RTE_PTP_FLAG_LI_61 (UINT16_C(1) << 0) /**< Leap indicator 61. */ #define RTE_PTP_FLAG_LI_59 (UINT16_C(1) << 1) /**< Leap indicator 59. */
Done. All four flag macros now use (UINT16_C(1) << N).
Quoted 40 lines
Quoted 20 lines
lib/net/rte_ptp.h new file +18
-0+ +/* +* PTP Header Structures (IEEE 1588-2019) +*/ + +/** +* PTP Port Identity (10 bytes). +*/ +struct __rte_packed_begin rte_ptp_port_id { +uint8_t clock_id[8 ];/**< clockIdentity (EUI-64). */ +rte_be16_t port_number;/**< portNumber. */ +} __rte_packed_end; + +/** +* PTP Common Message Header (34 bytes). +*/ +struct __rte_packed_begin rte_ptp_hdr { +uint8_t msg_type;/**< transportSpecific (4) | messageType (4). */
lib/net/rte_ptp.h new file +1
-0+uint8_t version;/**< minorVersionPTP (4) | versionPTP Quoted 1 line
(4). */
The two fields above should be split into their nibbles, for direct access, like the
version_ihlfield in the IPv4 header:
https://elixir.bootlin.com/dpdk/v26.03/source/lib/net/rte_ip4.h#L43E.g.:
__extension__ union { uint8_t ts_msgtype; /**< Message type */ struct { #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN uint8_t msg_type:4; /**< messageType */ uint8_t ts:4; /**< transportSpecific */ #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN uint8_t ts:4; /**< transportSpecific */ uint8_t msg_type:4; /**< messageType */ #endif }; };
Quoted 1 line
Warning: I'm not sure I got the nibble order right. Make sure you do! :-)
Done. Used __extension__ union { uint8_t ts_msgtype; struct { uint8_t msg_type:4; uint8_t ts:4; }; }; with RTE_BYTE_ORDER conditional for endianness, matching rte_ipv4_hdr convention.
Quoted 13 lines
Quoted 13 lines
lib/net/rte_ptp.h new file +4
-0+rte_be16_t msg_length;/**< Total message length in bytes. */ +uint8_t domain_number;/**< PTP domain (0-255). */ +uint8_t minor_sdo_id;/**< minorSdoId (IEEE 1588-2019). */ +rte_be16_t flags;/**< Flag field (see RTE_PTP_FLAG_*). */
lib/net/rte_ptp.h new file +1
-0+rte_be64_t correction;/**< correctionField (scaled ns, 48.16 fixed). */
lib/net/rte_ptp.h new file +2
-0+rte_be32_t msg_type_specific;/**< messageTypeSpecific. */ +struct rte_ptp_port_id source_port_id;/**< sourcePortIdentity. */
lib/net/rte_ptp.h new file +2
-0+rte_be16_t sequence_id;/**< sequenceId. */ +uint8_t control;/**< controlField (deprecated in 1588-
Quoted 8 lines
lib/net/rte_ptp.h line 99
Quoted 6 lines
2019). */
lib/net/rte_ptp.h new file +5
-0+int8_t log_msg_interval;/**< logMessageInterval. */ +} __rte_packed_end; + +/** +* PTP Timestamp (10 bytes, used in Sync/Delay_Req/Follow_Up bodies). The PTP timestamp origo should be mentioned here. E.g. the UNIX
time_torigo is Jan 1st 00:00:00 1970.
Done. Added Seconds since PTP epoch (1 January 1970 00:00:00 TAI) to struct docstring.
Quoted 79 lines
Quoted 79 lines
+ */
lib/net/rte_ptp.h new file +77
-0+struct __rte_packed_begin rte_ptp_timestamp { +rte_be16_t seconds_hi;/**< Upper 16 bits of seconds. */ +rte_be32_t seconds_lo;/**< Lower 32 bits of seconds. */ +rte_be32_t nanoseconds;/**< Nanoseconds (0-999999999). */ +} __rte_packed_end; + +/* +* Inline Helpers +*/ + +/** +* Extract PTP message type from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* Message type (0x0-0xF). +*/ +static inline uint8_t +rte_ptp_msg_type (const struct rte_ptp_hdr *hdr) +{ +return hdr->msg_type &0x0F ; +} + +/** +* Extract transport-specific field from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* Transport-specific value (upper nibble, 0x0-0xF). +*/ +static inline uint8_t +rte_ptp_transport_specific (const struct rte_ptp_hdr *hdr) +{ +return (hdr->msg_type >>4 ) &0x0F ; +} + +/** +* Extract PTP version from header. +* +* @param hdr +* Pointer to PTP header. +* @return +* PTP version number (typically 2). +*/ +static inline uint8_t +rte_ptp_version (const struct rte_ptp_hdr *hdr) +{ +return hdr->version &0x0F ; +} + +/** +* Get sequence ID from PTP header (host byte order). +* +* @param hdr +* Pointer to PTP header. +* @return +* Sequence ID in host byte order. +*/ +static inline uint16_t +rte_ptp_seq_id (const struct rte_ptp_hdr *hdr) +{ +return rte_be_to_cpu_16 (hdr->sequence_id); +} + +/** +* Get PTP domain number. +* +* @param hdr +* Pointer to PTP header. +* @return +* Domain number (0-255). +*/ +static inline uint8_t +rte_ptp_domain (const struct rte_ptp_hdr *hdr) +{
Quoted 8 lines
lib/net/rte_ptp.h
Quoted 2 lines
lib/net/rte_ptp.h new file +2
-0+return hdr->domain_number; +}The above "get" accessor functions are superfluous. Please remove:
rte_ptp_msg_type()rte_ptp_transport_specific()rte_ptp_version()rte_ptp_seq_id()rte_ptp_domain()
Done. All five removed. Callers updated to use direct field access: hdr->msg_type, hdr->version, hdr->domain_number, rte_be_to_cpu_16(hdr->sequence_id), etc.
Quoted 17 lines
Quoted 6 lines
lib/net/rte_ptp.h new file +5
-0+ +/** +* Check if PTP message type is an event message. +* Event messages (msg_type 0x0-0x3) require timestamps. +* lib/net/rte_ptp.h line 194
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* @param msg_type +* PTP message type value (0x0-0xF). +* @return +* true if event message, false otherwise. +*/ +static inline bool +rte_ptp_is_event (int msg_type) +{ +return msg_type >=0 && msg_type <=RTE_PTP_MSGTYPE_PDELAY_RESP ; +}Suggest passing the parameter as const struct
rte_ptp_hdr*hdr, like inrte_ptp_is_two_step()below.
Done. Parameter changed from int msg_type to const struct rte_ptp_hdr *hdr. Body uses hdr->msg_type. All callers updated.
Quoted 8 lines
Quoted 8 lines
lib/net/rte_ptp.h new file +8
-0+ +/** +* Check if the two-step flag is set in a PTP header. +* +* @param hdr +* Pointer to PTP header. +* @return +* true if two-step flag is set.
Quoted 8 lines
Quoted 6 lines
+ */
lib/net/rte_ptp.h new file +4
-0+static inline bool +rte_ptp_is_two_step (const struct rte_ptp_hdr *hdr) +{ + return (rte_be_to_cpu_16(hdr->flags) & RTE_PTP_FLAG_TWO_STEP) !=0;
Faster way:
return (hdr->flags&RTE_BE16(RTE_PTP_FLAG_TWO_STEP)) != 0;
Done. Uses hdr->flags & RTE_BE16(RTE_PTP_FLAG_TWO_STEP) for compile-time constant comparison.
Quoted 43 lines
Quoted 6 lines
lib/net/rte_ptp.h new file +5
-0+} + +/** +* Get correctionField value in nanoseconds (from 48.16 fixed-point). +* lib/net/rte_ptp.h line 222
Quoted 10 lines
lib/net/rte_ptp.h new file +10
-0+* @param hdr +* Pointer to PTP header. +* @return +* Correction value in nanoseconds. +*/ +static inline int64_t +rte_ptp_correction_ns (const struct rte_ptp_hdr *hdr) +{ +return (int64_t )rte_be_to_cpu_64 (hdr->correction) >>16 ; +}This "get" accessor function is superfluous. Please remove:
rte_ptp_correction_ns()The "correction" field in the PTP header structure should sufficiently describe the field's fixed-point encoding.
Quoted 12 lines
lib/net/rte_ptp.h new file +5
-0+ +/** +* Add a residence time (in nanoseconds) to the correctionField. +* Used by Transparent Clocks to account for relay transit delay. +* The correctionField uses IEEE 1588 scaled nanoseconds (48.16 fixed- point).
+ *
+ * @param hdr
+ * Pointer to PTP header (will be modified in-place).
+ * @paramresidence_ns
+ * Residence time in nanoseconds to add.
+ */lib/net/rte_ptp.h line 241
Quoted 8 lines
lib/net/rte_ptp.h new file +8
-0+static inline void +rte_ptp_add_correction (struct rte_ptp_hdr *hdr,int64_t residence_ns) +{ +int64_t cf = (int64_t )rte_be_to_cpu_64 (hdr->correction); + + cf += (int64_t )((uint64_t )residence_ns <<16 ); + hdr->correction =rte_cpu_to_be_64 (cf); +}I don't think negative time can be added, so please use
uint64_tinstead ofint64_tfor the parameter and inside the function.
Quoted 1 line
Note to reviewers: "residence time" is the term in the standard. "sojourn time" is not used.
Done. Parameter changed from int64_t residence_ns to uint64_t residence_ns.
Quoted 12 lines
Quoted 12 lines
lib/net/rte_ptp.h new file +11
-0+ +/** +* Convert a PTP timestamp structure to nanoseconds since epoch. +* +* @param ts +* Pointer to PTP timestamp. +* @return +* Time in nanoseconds since epoch. +*/ +static inline uint64_t +rte_ptp_timestamp_to_ns (const struct rte_ptp_timestamp *ts)
Quoted 8 lines
lib/net/rte_ptp.h line 258
Quoted 7 lines
lib/net/rte_ptp.h new file +2
-0+{ +uint64_t sec = ((uint64_t )rte_be_to_cpu_16 (ts->seconds_hi) <<32 )|
lib/net/rte_ptp.h new file +4
-0+rte_be_to_cpu_32 (ts->seconds_lo); + +return sec *1000000000ULL +rte_be_to_cpu_32 (ts->nanoseconds); +}1000000000ULL ->
UINT64_C(1000000000)
Done. Changed 1000000000ULL -> UINT64_C(1000000000).
Quoted 9 lines
Quoted 9 lines
lib/net/rte_ptp.h new file +6
-1+ +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_PTP_H_ */ --2.53.0
PATCH v7 2/4 examples/ptp_tap_relay_sw: add PTP software transparent clock relay
In reply to Rajesh KumarAdd a new example application demonstrating a software PTP Transparent Clock relay between a DPDK-bound physical NIC and a Linux kernel TAP virtual interface.
The relay uses software timestamps (CLOCK_MONOTONIC) to measure residence time and accumulates it into the PTP correctionField per IEEE 1588-2019 §10.2, enabling synchronized time distribution via standard linuxptp (ptp4l) on both sides.
Features:
- Handles L2, VLAN/QinQ, and UDP/IPv4/IPv6 PTP encapsulations
- Supports PTP v2 event messages (Sync, Delay_Req, PDelay_Req, PDelay_Resp)
- Two-pass burst processing: classify before TX, timestamp before relay
- Unmodified Linux kernel and stock DPDK (no kernel patches required)
- Bidirectional relay: PHY ↔ TAP
Includes:
- ptp_tap_relay_sw.c: Main relay logic with burst processing
- ptp_parse.h: Local DPI parser for PTP classification (not a library API)
- Sample app guide with topology, command-line options, and example output
Uses lib/net/rte_ptp.h inline helpers for correctionField manipulation and header parsing.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ 6 files changed, 910 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
212 lines not on this page · raw message
examples/ptp_tap_relay_sw/Makefile new file +41 -0
41 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_parse.h new file +211 -0
211 lines not on this page · raw message
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 3/4 doc: update release notes for PTP protocol library
In reply to Rajesh KumarUpdate release notes with IEEE 1588 PTP additions:
- PTP protocol definitions in lib/net/rte_ptp.h (header-only library with inline helpers and wire-format structures)
- PTP software relay example application (ptp_tap_relay_sw)
--- doc/guides/rel_notes/release_26_07.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_26_07.rst +12 -0
@@ -63,6 +63,18 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol definitions (rte_ptp.h).** + + Added IEEE 1588 Precision Time Protocol header structures, constants, + and inline helpers to ``lib/net/rte_ptp.h``. Provides wire-format + structures with endian-annotated types and correctionField manipulation + for Transparent Clock implementations. + +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. Removed Items -------------
Signature · 1 line
2.53.0
PATCH v7 4/4 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarUpdate ptpclient to use the lib/net/rte_ptp.h library instead of duplicated local PTP header structures and message type constants.
Changes:
- Add #include <rte_ptp.h>
- Replace local struct ptp_header with struct rte_ptp_hdr
- Replace local struct tstamp with struct rte_ptp_timestamp
- Replace local struct clock_id with uint8_t[8] arrays
- Use RTE_PTP_MSGTYPE_* constants instead of local message types
- Use rte_ptp_msg_type(), rte_ptp_seq_id() inline helpers
- Remove local PTP_PROTOCOL definition (use RTE_ETHER_TYPE_1588)
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 204 +++++++++++++-------------------- 2 files changed, 81 insertions(+), 124 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['net'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +80 -124
334 lines not on this page · raw message
Signature · 1 line
2.53.0
v8 cover IEEE 1588 PTP v2 protocol support in lib/net
In reply to Rajesh KumarAdd IEEE 1588-2019 Precision Time Protocol (PTP) support to DPDK via a new header library in lib/net/. This patchset provides wire-format packet structure definitions and inline helpers for Transparent Clock and ordinary clock applications.
Design Rationale
================
Following DPDK conventions for protocol libraries (rte_tcp.h, rte_ip.h), PTP definitions are provided as a header-only library with inline functions for zero-overhead packet processing. All functions are suitable for real-time, performance-critical code paths.
Contents
========
Patch 1: lib/net/rte_ptp.h - Header structures and inline helpers
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte PTP v2 common message header with nibble bitfields for msg_type/transportSpecific and version/minorVersion
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
- Message type constants (Sync, Delay_Req, Announce, etc.)
- Flag field bits (two-step, unicast, leap indicator)
- Port and MAC address constants (RTE_IPPORT_PTP_*, RTE_ETHER_ADDR_PTP_*)
- Inline helpers: rte_ptp_is_event(), rte_ptp_is_two_step(), rte_ptp_add_correction(), rte_ptp_timestamp_to_ns()
Patch 2: examples/ptp_tap_relay_sw - Software PTP Transparent Clock relay
- Relays PTP packets between a DPDK-bound physical NIC and Linux TAP
- Software timestamp-based residence time measurement (CLOCK_MONOTONIC)
- Accumulates residence time to correctionField per IEEE 1588-2019 §10.2
- Handles L2, VLAN/QinQ, UDP/IPv4, UDP/IPv6 PTP encapsulations
- Works with unmodified Linux kernel and stock DPDK (no patches required)
- Compatible with standard linuxptp (ptp4l) tooling
Patch 3: doc/guides/rel_notes/release_26_07.rst - Release notes update
Patch 4: examples/ptpclient - Update to use lib/net PTP definitions
- Replace local struct ptp_header with struct rte_ptp_hdr
- Replace local struct tstamp with struct rte_ptp_timestamp
- Replace local struct clock_id with uint8_t[8] arrays
- Use RTE_PTP_MSGTYPE_* constants instead of local defines
- Use hdr->msg_type bitfield and rte_be_to_cpu_16(hdr->sequence_id) for direct field access
- Remove local PTP_PROTOCOL macro (use RTE_ETHER_TYPE_1588)
- Add lib/net dependency in meson.build
Testing
=======
- Build: ninja -C build - clean compilation
- Examples: Both ptpclient and ptp_tap_relay_sw compile and link correctly
- Checkpatches: All 4 patches pass validation
- Functional: ptpclient tested with ptp4l in L2 mode (HW timestamps)
- Functional: ptp_tap_relay_sw tested with E810 master and TAP slave
Changelog
=========
v8 changes:
- Renamed port macros: RTE_IPPORT_PTP_EVENT, RTE_IPPORT_PTP_GENERAL
- Renamed MAC macros: RTE_ETHER_ADDR_PTP_MULTICAST, RTE_ETHER_ADDR_PTP_MULTICAST_PDELAY
- Renamed RTE_PTP_MSGTYPE_FOLLOW_UP to RTE_PTP_MSGTYPE_FU for consistency with RTE_PTP_MSGTYPE_PDELAY_RESP_FU
- Split msg_type and version bytes into 4-bit bitfields using __extension__ union pattern (matching rte_ipv4_hdr convention)
- Changed flag bits to use UINT16_C(1) << N
- Removed 6 accessor functions (rte_ptp_msg_type, rte_ptp_seq_id, rte_ptp_version, rte_ptp_domain, rte_ptp_transport_specific, rte_ptp_correction_ns) - use direct field access instead
- Changed rte_ptp_is_event() parameter from int to const struct rte_ptp_hdr *
- Changed rte_ptp_add_correction() parameter from int64_t to uint64_t
- Used UINT64_C(1000000000) in rte_ptp_timestamp_to_ns()
- Added "(general)" to PDELAY_RESP_FU description
- Documented PTP timestamp epoch
- Updated MAINTAINERS headline
- Updated ptpclient and ptp_tap_relay_sw for direct field access
v7 changes:
- Added sample app guide to sample_app_ug toctree to fix Sphinx warning
- Fixed all checkpatch warnings (commit message line lengths <= 75 chars)
- Refactored ptpclient to use shared lib/net/rte_ptp.h definitions
- All 5 patches (cover + 4 functional) pass checkpatch validation
v6 changes:
- Restructured to lib/net (header-only, following lib/net conventions)
- Removed separate DPI library functions (moved to example local parser)
- Removed app/test unit tests (header-only, example-driven testing)
- Removed programmer's guide (lib/net headers use Doxygen API docs only)
Rajesh Kumar (4):
lib/net: add IEEE 1588 PTP v2 protocol header definitions examples/ptp_tap_relay_sw: add PTP software transparent clock relay
doc: update release notes for PTP protocol library examples/ptpclient: use shared PTP library definitions
MAINTAINERS | 6 + doc/guides/rel_notes/release_26_07.rst | 12 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 204 ++++----- lib/net/meson.build | 1 + lib/net/rte_ptp.h | 205 +++++++++ 12 files changed, 1215 insertions(+), 124 deletions(-) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c create mode 100644 lib/net/rte_ptp.h
Signature · 1 line
2.53.0
PATCH v8 1/4 lib/net: add IEEE 1588 PTP v2 protocol header definitions
Add PTP (Precision Time Protocol) header structures and inline helper functions to lib/net following DPDK conventions for protocol libraries (similar to rte_tcp.h, rte_ip.h).
Provides wire-format structures with endian-annotated types:
- rte_ptp_port_id: 10-byte port identity with EUI-64 clock ID
- rte_ptp_hdr: 34-byte common message header with nibble bitfields for msg_type/transportSpecific and version/minorVersion
- rte_ptp_timestamp: 10-byte nanosecond-precision timestamp
PTP message type constants for all IEEE 1588-2019 message types (Sync, Delay_Req, Announce, Management, etc.) and flag field bits (two-step, unicast, leap indicator).
Inline utility functions:
- rte_ptp_is_event(), rte_ptp_is_two_step()
- rte_ptp_add_correction(), rte_ptp_timestamp_to_ns()
Supports all PTP encapsulations: L2 (EtherType 0x88F7), VLAN/QinQ, UDP/IPv4, and UDP/IPv6 (ports 319/320).
All inline functions — zero function call overhead, suitable for real-time packet processing.
--- MAINTAINERS | 6 ++ lib/net/meson.build | 1 + lib/net/rte_ptp.h | 205 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 lib/net/rte_ptp.h
MAINTAINERS +6 -0
@@ -1665,6 +1665,12 @@ F: doc/guides/prog_guide/ipsec_lib.rst M: Vladimir Medvedkin <[email protected]> F: app/test-sad/ +PTP (IEEE 1588 Precision Time Protocol) +M: Rajesh Kumar <[email protected]> +F: lib/net/rte_ptp.h +F: examples/ptp_tap_relay_sw/ +F: doc/guides/sample_app_ug/ptp_tap_relay_sw.rst + PDCP - EXPERIMENTAL M: Anoob Joseph <[email protected]> M: Volodymyr Fialko <[email protected]>
lib/net/meson.build +1 -0
@@ -28,6 +28,7 @@ headers = files( 'rte_geneve.h', 'rte_l2tpv2.h', 'rte_ppp.h', + 'rte_ptp.h', 'rte_ib.h', )
lib/net/rte_ptp.h new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v8 2/4 examples/ptp_tap_relay_sw: add PTP software transparent clock relay
In reply to Rajesh KumarAdd a new example application demonstrating a software PTP Transparent Clock relay between a DPDK-bound physical NIC and a Linux kernel TAP virtual interface.
The relay uses software timestamps (CLOCK_MONOTONIC) to measure residence time and accumulates it into the PTP correctionField per IEEE 1588-2019 §10.2, enabling synchronized time distribution via standard linuxptp (ptp4l) on both sides.
Features:
- Handles L2, VLAN/QinQ, and UDP/IPv4/IPv6 PTP encapsulations
- Supports PTP v2 event messages (Sync, Delay_Req, PDelay_Req, PDelay_Resp)
- Two-pass burst processing: classify before TX, timestamp before relay
- Unmodified Linux kernel and stock DPDK (no kernel patches required)
- Bidirectional relay: PHY ↔ TAP
Includes:
- ptp_tap_relay_sw.c: Main relay logic with burst processing
- ptp_parse.h: Local DPI parser for PTP classification (not a library API)
- Sample app guide with topology, command-line options, and example output
Uses lib/net/rte_ptp.h inline helpers for correctionField manipulation and header parsing.
--- doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ 6 files changed, 910 insertions(+) create mode 100644 doc/guides/sample_app_ug/ptp_tap_relay_sw.rst create mode 100644 examples/ptp_tap_relay_sw/Makefile create mode 100644 examples/ptp_tap_relay_sw/meson.build create mode 100644 examples/ptp_tap_relay_sw/ptp_parse.h create mode 100644 examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c
doc/guides/sample_app_ug/index.rst +1 -0
@@ -51,6 +51,7 @@ Sample Applications User Guides dist_app vm_power_management ptpclient + ptp_tap_relay_sw fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/ptp_tap_relay_sw.rst new file +212 -0
212 lines not on this page · raw message
examples/ptp_tap_relay_sw/Makefile new file +41 -0
41 lines not on this page · raw message
examples/ptp_tap_relay_sw/meson.build new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Intel Corporation + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +sources = files( + 'ptp_tap_relay_sw.c', +) +deps += ['net'] +cflags += no_shadow_cflag
examples/ptp_tap_relay_sw/ptp_parse.h new file +211 -0
211 lines not on this page · raw message
examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v8 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay
10/05/2026 01:25, Rajesh Kumar:
Quoted 3 lines
Add a new example application demonstrating a software PTP Transparent Clock relay between a DPDK-bound physical NIC and a Linux kernel TAP virtual interface.
[...]
Quoted 7 lines
doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ 6 files changed, 910 insertions(+)
You didn't update the file MAINTAINERS.
I assume you will be the maintainer for this new example? I will update when merging.
Re: [PATCH v8 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay
09/06/2026 10:52, Thomas Monjalon:
Quoted 13 lines
10/05/2026 01:25, Rajesh Kumar:
Quoted 3 lines
Add a new example application demonstrating a software PTP Transparent Clock relay between a DPDK-bound physical NIC and a Linux kernel TAP virtual interface.
[...]
Quoted 7 lines
doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/ptp_tap_relay_sw.rst | 212 +++++++++ examples/ptp_tap_relay_sw/Makefile | 41 ++ examples/ptp_tap_relay_sw/meson.build | 13 + examples/ptp_tap_relay_sw/ptp_parse.h | 211 +++++++++ examples/ptp_tap_relay_sw/ptp_tap_relay_sw.c | 432 ++++++++++++++++++ 6 files changed, 910 insertions(+)
Quoted 3 lines
You didn't update the file
MAINTAINERS.
I assume you will be the maintainer for this new example? I will update when merging.
Sorry I see you did the update in the lib patch.
PATCH v8 3/4 doc: update release notes for PTP protocol library
In reply to Rajesh KumarUpdate release notes with IEEE 1588 PTP additions:
- PTP protocol definitions in lib/net/rte_ptp.h (header-only library with inline helpers and wire-format structures)
- PTP software relay example application (ptp_tap_relay_sw)
--- doc/guides/rel_notes/release_26_07.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_26_07.rst +12 -0
@@ -63,6 +63,18 @@ New Features ``rte_eal_init`` and the application is responsible for probing each device, * ``--auto-probing`` enables the initial bus probing, which is the current default behavior. +* **Added PTP protocol definitions (rte_ptp.h).** + + Added IEEE 1588 Precision Time Protocol header structures, constants, + and inline helpers to ``lib/net/rte_ptp.h``. Provides wire-format + structures with endian-annotated types and correctionField manipulation + for Transparent Clock implementations. + +* **Added PTP software relay example application.** + + Added a new example application ``ptp_tap_relay_sw`` demonstrating a + software PTP Transparent Clock relay between a DPDK port and a kernel + TAP interface. Removed Items -------------
Signature · 1 line
2.53.0
PATCH v8 4/4 examples/ptpclient: use shared PTP library definitions
In reply to Rajesh KumarUpdate ptpclient to use the lib/net/rte_ptp.h library instead of duplicated local PTP header structures and message type constants.
Changes:
- Add #include <rte_ptp.h>
- Replace local struct ptp_header with struct rte_ptp_hdr
- Replace local struct tstamp with struct rte_ptp_timestamp
- Replace local struct clock_id with uint8_t[8] arrays
- Use RTE_PTP_MSGTYPE_* constants instead of local message types
- Use hdr->msg_type bitfield and hdr->sequence_id direct access
- Remove local PTP_PROTOCOL definition (use RTE_ETHER_TYPE_1588)
--- examples/ptpclient/meson.build | 1 + examples/ptpclient/ptpclient.c | 204 +++++++++++++-------------------- 2 files changed, 81 insertions(+), 124 deletions(-)
examples/ptpclient/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['net'] sources = files( 'ptpclient.c', )
examples/ptpclient/ptpclient.c +80 -124
334 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v8 0/4] IEEE 1588 PTP v2 protocol support in lib/net
In reply to Rajesh KumarQuoted 5 lines
Rajesh Kumar (4):
lib/net: add IEEE 1588 PTP v2 protocol header definitions examples/ptp_tap_relay_sw: add PTP software transparent clock relay
doc: update release notes for PTP protocol library examples/ptpclient: use shared PTP library definitions
Squashed in 2 atomic commits (lib and new example), thanks.