PTP - Precision Time Protocol =============================== .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is PTP?** The PTP (Precision Time Protocol) is a protocol used to synchronize clocks across a computer network with sub-microsecond accuracy. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What standard defines PTP?** PTP is defined by the IEEE 1588 standard. The first version, IEEE 1588-2002, is known as PTP v1. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the main use of PTP?** PTP is used in precise time coordination systems, such as industrial automation, telecommunications, power systems, and financial trading. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How does PTP achieve high accuracy?** PTP uses hardware timestamping and a master-slave hierarchy to minimize jitter and delay, achieving sub-microsecond synchronization. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the difference between PTP and NTP?** * PTP offers much higher precision (sub-microsecond) compared to NTP (millisecond-level), making it suitable for time-critical applications. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a PTP master-slave?** * The master clock provides the reference time, while slave clocks synchronize to it. This hierarchy ensures consistent time distribution. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Does PTP require special hardware?** For high accuracy, PTP benefits from hardware timestamping support in network interface cards (NICs) and switches. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What transport protocols does PTP use?** PTP typically uses UDP over IP networks, often on port 319 (event messages) and 320 (general messages). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Can PTP work over wireless communication?** While possible, wireless introduces variable latency and jitter, which can reduce synchronization accuracy. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the limitations of PTP v1?** PTP v1 lacks some features of later versions like profile support, improved fault tolerance, and better scalability. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **IS PTP Windows specific?** * No, PTP is not Windows-specific. * However, native PTP support on Windows is limited compared to Linux. * Some versions of Windows (like Windows 10 Enterprise and Windows Server) offer partial PTP support. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **IS PTP Linux Specific?** * No, PTP is not Linux-specific. * Linux has robust support for PTP, especially with hardware timestamping and tools like `linuxptp`. * PTP is also supported on BSD, real-time OSes, and embedded systems. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Transport Protocol is used by PTP?** * PTP typically uses **UDP** as the transport protocol. * It can also operate directly over Ethernet (Layer 2) in some implementations for higher precision. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Which Port is used by PTP?** * **UDP port 319** – for event messages (e.g., Sync, Delay_Req). * **UDP port 320** – for general messages (e.g., Follow_Up, Delay_Resp). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Is PTP using Client server model?** * No, PTP uses a **master-slave model**, not a traditional client-server model. * The best master clock is elected automatically, and other devices synchronize to it. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Terminology ` * :ref:`Version Info ` * :ref:`PTP Version&RFC Details ` * :ref:`PTP Basic Setup on Ubuntu using IPv4 ` * :ref:`PTP Basic Setup on Ubuntu using IPv6 ` * :ref:`PTP Protocol Packet Details ` * :ref:`PTP Usecases ` * :ref:`PTP Basic Features ` * :ref:`PTP Feature : High Precision Time Sync ` * :ref:`PTP Feature : Master-Slave Architecture ` * :ref:`PTP Feature : Hardware Timestamping ` * :ref:`PTP Feature : Event and General Messages ` * :ref:`PTP Feature : Loopback Testing Support ` * :ref:`PTP Feature : Delay Measurement and Mechanism ` * :ref:`PTP Feature : Best Master Clock Algorithm ` * :ref:`PTP Feature : Multicast and Unicast Support ` * :ref:`PTP Feature : Profile-Based Configuration ` * :ref:`PTP Feature : Scalability ` * :ref:`Reference links ` .. _PTP_step1: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. _PTP_step2: .. tab-set:: .. tab-item:: Terminology * Terminology .. _PTP_step3: .. tab-set:: .. tab-item:: Version Info * Version Info .. _PTP_step5: .. tab-set:: .. tab-item:: PTP Version&RFC Details .. csv-table:: :file: ./PTP/PTP_RFC_Details.csv :widths: 10,10,10,30,40 :header-rows: 1 .. _PTP_step19: .. tab-set:: .. tab-item:: PTP Basic Setup on Ubuntu using IPv4 **SetUp for IPv4** * Step-1: Assign IPv4 Addresses for two VM's. .. code-block:: shell test:~$sudo ip addr add 192.168.100.1/24 dev enp0s8 test:~$sudo ip link set enp0s8 up test:~$sudo ip addr add 192.168.100.2/24 dev enp0s8 test:~$sudo ip link set enp0s8 up * Step-2: Verify IPv4 Connectivity on both VM's. .. code-block:: shell test:~$ping 192.168.100.2 test:~$ping 192.168.100.1 * Step-3: Allow PTP Ports on both VM's. .. code-block:: shell test:~$sudo ufw allow 319/udp test:~$sudo ufw allow 320/udp * Step-4:Create config file on both VMs. .. code-block:: shell test:~$sudo nano /etc/linuxptp/ptp4l_ipv4.conf [global] verbose 1 clockClass 248 clockAccuracy 0xFE delay_mechanism E2E network_transport UDPv4 boundary_clock_jbod 0 time_stamping software [enp0s8] **Unicast PTP Message Exchange Test Case** * Verify that PTP messages are correctly transmitted over IPv4 in unicast mode. * Step-1: Install required packages (ptp4l and tshark). .. code-block:: shell test:~$sudo apt update test:~$sudo apt install linuxptp tshark -y * Step-2: Run PTP Grandmaster (GM) on VM1. .. code-block:: shell test:~$sudo ip netns exec VM1 ptp4l -i veth-VM1 -m -s -S & Note - '-m' prints log messages - '-s' enables Grandmaster mode - `-S` enables software timestamping * Step-3: Run PTP Slave on VM2. .. code-block:: shell test:~$sudo ip netns exec VM1 ptp4l -i veth-VM2 -m -S & Note - '-m' prints log messages - `-S` enables software timestamping * Step-4: Wireshark Capture on VM2. :download:Download wireshark capture .. _PTP_step20: .. tab-set:: .. tab-item:: PTP Basic Setup on Ubuntu using IPv6 **SetUp For IPv6** * Step-1: Assign IPv6 Addresses for two VM's. .. code-block:: shell test:~$sudo ip -6 addr add 2001:db8:1::1/64 dev enp0s8 test:~$sudo ip link set enp0s8 up test:~$sudo ip -6 addr add 2001:db8:1::2/64 dev enp0s8 test:~$sudo ip link set enp0s8 up * Step-2: Verify IPv6 Connectivity for two VM's. .. code-block:: shell test:~$ping6 2001:db8:1::2 test:~$ping6 2001:db8:1::1 * Step-3: Allow PTP Ports for two VM's. .. code-block:: shell test:~$sudo ufw allow 319/udp test:~$sudo ufw allow 320/udp * Step-4: Configure ptp4l for two VM's. .. code-block:: shell test:~$sudo nano /etc/linuxptp/ptp4l_ipv6.conf [global] clockClass 248 clockAccuracy 0xFE delay_mechanism E2E network_transport UDP_IPv6 time_stamping software boundary_clock_jbod 0 [enp0s8] **Software Timestamping with Unicast over enp0s8 Testcase** * Step-1: Install linuxptp for two VM's . .. code-block:: shell test:~$sudo apt update test:~$sudo apt install linuxptp * Step-2: Run ptp4l on VM1 . .. code-block:: shell test:~$sudo ptp4l -i enp0s8 -f /etc/linuxptp/ptp4l_ipv6.conf -m -S Note - '-m' prints log messages - `-S` enables software timestamping * Step-3: Run ptp4l on VM2 . .. code-block:: shell test:~$sudo ptp4l -i enp0s8 -f /etc/linuxptp/ptp4l_ipv6.conf -m -S Note - '-m' prints log messages - `-S` enables software timestamping * Step-4: Wireshark Capture on VM2. :download:Download wireshark capture .. _PTP_step6: .. tab-set:: .. tab-item:: PTP Protocol Packet Details **Syn Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_1.csv :widths: 10,20,30,10 :header-rows: 1 **Follow_up Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_2.csv :widths: 10,20,30,10 :header-rows: 1 **Delay_Req Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_3.csv :widths: 10,20,30,10 :header-rows: 1 **Delay_Resp Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_4.csv :widths: 10,20,30,10 :header-rows: 1 **Management Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_5.csv :widths: 10,20,30,10 :header-rows: 1 **Announce Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet-6.csv :widths: 10,20,30,10 :header-rows: 1 **Signaling Message Packet** .. csv-table:: :file: ./PTP/PTP_Protocol_Packet_7.csv :widths: 10,20,30,10 :header-rows: 1 .. _PTP_step7: .. tab-set:: .. tab-item:: PTP Usecases .. csv-table:: :file: ./PTP/PTP_Usecases.csv :widths: 10,20,30 :header-rows: 1 .. _PTP_step8: .. tab-set:: .. tab-item:: PTP Basic Features .. csv-table:: :file: ./PTP/PTP_Features.csv :widths: 10,10,30 :header-rows: 1 .. _PTP_step9: .. tab-set:: .. tab-item:: PTP Feature : High Presion Time Sync **High Precision Time Sync- Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-1_High_Precision_Time_sync_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step10: .. tab-set:: .. tab-item:: PTP Feature : Master Slave Architecture **Master Slave Architecture - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-2_Master-Slave_Architecture_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step11: .. tab-set:: .. tab-item:: PTP Feature : Hardware Timestamping **Hardware Timestamping - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-3_Hardware_Timestamping_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step12: .. tab-set:: .. tab-item:: PTP Feature : Event and General Messages **Event and General Messages - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-4_Event_and_General_Messages_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step13: .. tab-set:: .. tab-item:: PTP Feature : Loopback Testing Support Algorithm **Loopback Testing Support Algorithm - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-5_Loopback_Testing_Support_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step14: .. tab-set:: .. tab-item:: PTP Feature : Delay Measurement Mechanism **Delay Measurement Mechanism - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-6_Delay_Measurement_Mechanism_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step15: .. tab-set:: .. tab-item:: PTP Feature : Best Master CLock Algorithm **Best Master CLock Algorithm - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-7_Best_Master_Clock_Algorithm_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step16: .. tab-set:: .. tab-item:: PTP Feature : Multicasr and Unicast Support **Multicast and Unicast Support - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-8_Multicast_and_Unicast_Support_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step17: .. tab-set:: .. tab-item:: PTP Feature : Profile-Based Configuration **Profile-Based Configuration - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-9_Profile-Based_Configuration_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step18: .. tab-set:: .. tab-item:: PTP Feature : Scalability **Scalability - Testcases** .. csv-table:: :file: ./PTP/PTP_Feature-10_Scalability_Testcase.csv :widths: 10,10,30,20 :header-rows: 1 .. _PTP_step21: .. tab-set:: .. tab-item:: Reference links * Reference links