DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rajesh Kumar <rajesh3.kumar@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, aman.deep.singh@intel.com,
	rajesh3.kumar@intel.com
Subject: [RFC v1 2/4] doc: add PTP library programmer's guide
Date: Tue, 28 Apr 2026 06:31:04 +0530	[thread overview]
Message-ID: <20260428010117.692626-3-rajesh3.kumar@intel.com> (raw)
In-Reply-To: <20260428010117.692626-1-rajesh3.kumar@intel.com>

Add 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.

Signed-off-by: Rajesh Kumar <rajesh3.kumar@intel.com>
---
 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

diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md
index 9296042119..bbc79168bb 100644
--- a/doc/api/doxy-api-index.md
+++ b/doc/api/doxy-api-index.md
@@ -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)
diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in
index bedd944681..f15d962733 100644
--- a/doc/api/doxy-api.conf.in
+++ b/doc/api/doxy-api.conf.in
@@ -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 \
diff --git a/doc/guides/prog_guide/index.rst b/doc/guides/prog_guide/index.rst
index e6f24945b0..60dad4475c 100644
--- a/doc/guides/prog_guide/index.rst
+++ b/doc/guides/prog_guide/index.rst
@@ -97,6 +97,7 @@ Protocol Processing Libraries
     :maxdepth: 1
     :numbered:
 
+    ptp_lib
     pdcp_lib
     ipsec_lib
 
diff --git a/doc/guides/prog_guide/ptp_lib.rst b/doc/guides/prog_guide/ptp_lib.rst
new file mode 100644
index 0000000000..46770f1bd7
--- /dev/null
+++ b/doc/guides/prog_guide/ptp_lib.rst
@@ -0,0 +1,195 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+    Copyright(c) 2026 Intel Corporation.
+
+PTP Protocol Library
+====================
+
+The DPDK PTP library provides IEEE 1588 / Precision Time Protocol (PTP)
+packet structures, constants, and helper functions for PTP packet processing.
+
+The library supports classification and header parsing of PTP messages
+across multiple transport encapsulations:
+
+- L2 PTP (EtherType 0x88F7)
+- VLAN-tagged L2 PTP (single and double/QinQ)
+- PTP over UDP/IPv4 (destination ports 319 and 320)
+- PTP over UDP/IPv6 (destination ports 319 and 320)
+
+The library conforms to
+`IEEE 1588-2019 <https://standards.ieee.org/ieee/1588/6825/>`_
+(Precision Time Protocol).
+
+Overview
+--------
+
+PTP is the foundation of time synchronization in networking.
+DPDK applications that relay, classify, or timestamp PTP packets
+currently duplicate header definitions and parsing logic.
+This library provides a shared, tested implementation.
+
+The library provides:
+
+#. Packed header structures matching the IEEE 1588-2019 wire format
+#. Constants for message types, flags, ports, and multicast addresses
+#. Inline helpers for common field extraction and manipulation
+#. Packet classification across L2, VLAN, UDP/IPv4, and UDP/IPv6 transports
+#. Correction field manipulation for Transparent Clock residence time
+
+PTP Message Types
+-----------------
+
+IEEE 1588-2019 defines the following message types, all supported by the library:
+
+.. csv-table:: PTP Message Types
+   :header: "Type", "Name", "Category", "Macro"
+   :widths: 5, 20, 10, 30
+
+   "0x0", "Sync", "Event", "``RTE_PTP_MSGTYPE_SYNC``"
+   "0x1", "Delay_Req", "Event", "``RTE_PTP_MSGTYPE_DELAY_REQ``"
+   "0x2", "Peer_Delay_Req", "Event", "``RTE_PTP_MSGTYPE_PDELAY_REQ``"
+   "0x3", "Peer_Delay_Resp", "Event", "``RTE_PTP_MSGTYPE_PDELAY_RESP``"
+   "0x8", "Follow_Up", "General", "``RTE_PTP_MSGTYPE_FOLLOW_UP``"
+   "0x9", "Delay_Resp", "General", "``RTE_PTP_MSGTYPE_DELAY_RESP``"
+   "0xA", "PDelay_Resp_Follow_Up", "General", "``RTE_PTP_MSGTYPE_PDELAY_RESP_FU``"
+   "0xB", "Announce", "General", "``RTE_PTP_MSGTYPE_ANNOUNCE``"
+   "0xC", "Signaling", "General", "``RTE_PTP_MSGTYPE_SIGNALING``"
+   "0xD", "Management", "General", "``RTE_PTP_MSGTYPE_MANAGEMENT``"
+
+Event messages (types 0x0–0x3) require hardware timestamps for accurate
+time transfer.
+
+Header Structures
+-----------------
+
+The library defines the following packed structures that map directly to
+the IEEE 1588-2019 wire format:
+
+``struct rte_ptp_hdr``
+   Common PTP message header (34 bytes). All PTP messages begin with this header.
+   Contains message type, version, flags, correction field, source port identity,
+   sequence ID, and log message interval.
+
+``struct rte_ptp_timestamp``
+   PTP timestamp (10 bytes). Used in Sync, Delay_Req, and Follow_Up message bodies.
+   Contains seconds (48-bit) and nanoseconds (32-bit).
+
+``struct rte_ptp_port_id``
+   PTP port identity (10 bytes). Contains an EUI-64 clock identity and a
+   16-bit port number.
+
+Packet Classification API
+--------------------------
+
+``rte_ptp_classify()``
+~~~~~~~~~~~~~~~~~~~~~~
+
+Classify a packet and return the PTP message type.
+
+.. code-block:: C
+
+   int rte_ptp_classify(const struct rte_mbuf *m);
+
+Examines the mbuf to determine if it contains a PTP message.
+Returns the PTP message type (0x0–0xF) on success,
+or ``RTE_PTP_MSGTYPE_INVALID`` (-1) if the packet is not PTP.
+
+Supported encapsulations:
+
+- EtherType 0x88F7 (L2 PTP)
+- Single VLAN + EtherType 0x88F7
+- Double VLAN (QinQ) + EtherType 0x88F7
+- IPv4 + UDP destination port 319 or 320
+- IPv6 + UDP destination port 319 or 320
+
+``rte_ptp_hdr_get()``
+~~~~~~~~~~~~~~~~~~~~~
+
+Get a pointer to the PTP header inside a packet.
+
+.. code-block:: C
+
+   struct rte_ptp_hdr *rte_ptp_hdr_get(const struct rte_mbuf *m);
+
+Returns a pointer to the PTP header, or NULL if the packet is not PTP.
+Handles the same set of encapsulations as ``rte_ptp_classify()``.
+
+``rte_ptp_msg_type_str()``
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Convert a PTP message type to a human-readable string.
+
+.. code-block:: C
+
+   const char *rte_ptp_msg_type_str(int msg_type);
+
+Returns a string such as ``"Sync"``, ``"Delay_Req"``, ``"Follow_Up"``, etc.
+Returns ``"Not_PTP"`` for invalid message types.
+
+Inline Helpers
+--------------
+
+The following inline functions operate on ``struct rte_ptp_hdr`` and require
+no function call overhead:
+
+.. csv-table:: Inline Helper Functions
+   :header: "Function", "Returns", "Description"
+   :widths: 30, 15, 40
+
+   "``rte_ptp_msg_type()``", "``uint8_t``", "Extract message type (lower nibble)"
+   "``rte_ptp_transport_specific()``", "``uint8_t``", "Extract transport-specific field (upper nibble)"
+   "``rte_ptp_version()``", "``uint8_t``", "Extract PTP version number"
+   "``rte_ptp_seq_id()``", "``uint16_t``", "Get sequence ID in host byte order"
+   "``rte_ptp_domain()``", "``uint8_t``", "Get PTP domain number"
+   "``rte_ptp_is_event()``", "``bool``", "Check if message type is an event (0x0–0x3)"
+   "``rte_ptp_is_two_step()``", "``bool``", "Check if two-step flag is set"
+   "``rte_ptp_correction_ns()``", "``int64_t``", "Get correctionField in nanoseconds (from 48.16 fixed-point)"
+   "``rte_ptp_add_correction()``", "``void``", "Add residence time to correctionField (for Transparent Clocks)"
+   "``rte_ptp_timestamp_to_ns()``", "``uint64_t``", "Convert PTP timestamp struct to nanoseconds"
+
+Usage Example
+-------------
+
+Classifying and processing PTP packets:
+
+.. code-block:: C
+
+   #include <rte_ptp.h>
+
+   void process_packets(struct rte_mbuf **pkts, uint16_t nb_pkts)
+   {
+       for (uint16_t i = 0; i < nb_pkts; i++) {
+           int ptp_type = rte_ptp_classify(pkts[i]);
+           if (ptp_type == RTE_PTP_MSGTYPE_INVALID)
+               continue;
+
+           struct rte_ptp_hdr *hdr = rte_ptp_hdr_get(pkts[i]);
+
+           printf("PTP %s seq=%u domain=%u\n",
+                  rte_ptp_msg_type_str(ptp_type),
+                  rte_ptp_seq_id(hdr),
+                  rte_ptp_domain(hdr));
+
+           if (rte_ptp_is_event((uint8_t)ptp_type)) {
+               /* Event message — needs hardware timestamp */
+           }
+       }
+   }
+
+Adding residence time for a Transparent Clock:
+
+.. code-block:: C
+
+   struct rte_ptp_hdr *hdr = rte_ptp_hdr_get(pkt);
+   if (hdr != NULL) {
+       int64_t residence_ns = egress_ts - ingress_ts;
+       rte_ptp_add_correction(hdr, residence_ns);
+   }
+
+Limitations
+-----------
+
+- IPv6 extension headers are not traversed. Only the base IPv6 header
+  with ``next_header == UDP`` is handled.
+- Multi-segment mbufs are not supported. PTP event messages are
+  typically less than 128 bytes and fit in a single segment.
+- PTP over MPLS or other tunneling protocols is not supported.
-- 
2.52.0


  parent reply	other threads:[~2026-04-27 19:35 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  1:01 [RFC v1 0/4] introduce PTP protocol library and software relay example Rajesh Kumar
2026-04-27 23:42 ` Stephen Hemminger
2026-04-28 16:52   ` Kumar, Rajesh
2026-04-28  1:01 ` [RFC v1 1/4] ptp: introduce PTP protocol library Rajesh Kumar
2026-04-27 23:01   ` Stephen Hemminger
2026-04-28 16:50     ` Kumar, Rajesh
2026-04-28  1:01 ` Rajesh Kumar [this message]
2026-04-28  1:01 ` [RFC v1 3/4] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-04-28  1:01 ` [RFC v1 4/4] doc: add PTP software relay sample app guide Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 0/6] introduce PTP protocol library and software relay Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-04-28 22:28   ` [RFC v2 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-04-29 15:37   ` [RFC v2 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-04  3:49     ` Kumar, Rajesh3
2026-05-04  9:17 ` [RFC v3 " Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-04  9:17   ` [RFC v3 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-04 17:56   ` [RFC v3 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-05 16:38 ` [RFC v4 " Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-05 16:38   ` [RFC v4 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 0/6] introduce PTP protocol library and software relay Rajesh Kumar
2026-05-06 15:41   ` [RFC v5 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-06 11:02     ` Morten Brørup
2026-05-07  4:45       ` Kumar, Rajesh
2026-05-06 15:41   ` [RFC v5 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-06 15:41   ` [RFC v5 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-06 15:41   ` [RFC v5 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-06 15:41   ` [RFC v5 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-06 15:41   ` [RFC v5 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-06 15:45   ` [RFC v5 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-07 10:13 ` [PATCH v6 0/4] PTP protocol support in lib/net Rajesh Kumar
2026-05-07 10:13   ` [PATCH v6 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-07 10:13   ` [PATCH v6 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-07 10:13   ` [PATCH v6 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-07 10:13   ` [PATCH v6 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-07 13:45 ` [PATCH v7 0/4] IEEE 1588 PTP v2 protocol support in lib/net Rajesh Kumar
2026-05-07 13:45   ` [PATCH v7 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-07 15:27     ` Morten Brørup
2026-05-09 17:57       ` Kumar, Rajesh
2026-05-07 13:45   ` [PATCH v7 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-07 13:45   ` [PATCH v7 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-07 13:45   ` [PATCH v7 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 0/4] IEEE 1588 PTP v2 protocol support in lib/net Rajesh Kumar
2026-05-09 23:25   ` [PATCH v8 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-09 23:25   ` [PATCH v8 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-09 23:25   ` [PATCH v8 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-09 23:25   ` [PATCH v8 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260428010117.692626-3-rajesh3.kumar@intel.com \
    --to=rajesh3.kumar@intel.com \
    --cc=aman.deep.singh@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox