NTP vs PTP

What is NTP?

The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over networks. NTP is intended to synchronize all participating computers to within a few milliseconds of UTC.

NTP uses a hierarchical, semi-layered system of time sources. Each level of this hierarchy is termed a stratum and is assigned a number starting with zero for reference clock at the top. A server synchronized to a stratum n server runs at stratum n + 1.

Clock strata

Network_Time_Protocol_servers_and_clients svg

  • Yellow arrorws indicate a direct connection
  • Red arrows indicate a network connection

How NTP works?

image5

The synchronization process is as follows:

  • Device A sends Device B an NTP message, which is timestamped when it leaves Device A. The timestamp is 10:00:00 am (T1).
  • When this NTP message arrives at Device B, it is timestamped by Device B. The timestamp is 11:00:01 am (T2).
  • When the NTP message leaves Device B, Device B timestamps it. The timestamp is 11:00:02 am (T3).
  • When Device A receives the NTP message, the local time of Device A is 10:00:03 am (T4).

Up to now, Device A can calculate the following parameters based on the timestamps:

  • The roundtrip delay of NTP message: Delay = (T4–T1) – (T3-T2) = 2 seconds.
  • Time difference between Device A and Device B: Offset = ((T2-T1) + (T3-T4))/2 = 1 hour.

What is PTP?

The Precision Time Protocol (PTP) is a protocol used to synchronize clocks throughout a computer network.

The first version of PTP, IEEE 1588-2002, was published in 2002. IEEE 1588-2008, also known as PTP Version 2 is not backward compatible with the 2002 version. IEEE 1588-2019 was published in November 2019 and includes backward-compatible improvements to the 2008 publication.

According to John Eidson, who led the IEEE 1588-2002 standardization effort, “IEEE 1588 is designed to fill a niche not well served by either of the two dominant protocols, NTP and GPS. IEEE 1588 is designed for local systems requiring accuracies beyond those attainable using NTP. It is also designed for applications that cannot bear the cost of a GPS receiver at each node, or for which GPS signals are inaccessible.”

How PTP works?

PTP

Two separate delay values must be determined: the delay from the master to slave, and from the slave to master.

To calculate the delay from the master to slave:

T1 is the initial timestamp, and is the exact time the sync message is sent by the master. Since T1 is an accurate recording of when the sync message was transmitted via the Ethernet port, it is sent in the follow-up message.

T2 is the second timestamp, and is the exact time the slave receives the sync message.

Once both T1 and T2 are available at the slave, the delay value between the master and the slave can be determined through the calculation T2 – T1.

To calculate the delay from the slave to the master:

T3 is the third timestamp, and is the exact time the delay request message is sent from the slave. T4 is the fourth and final timestamp, and is the exact time the master receives the delay request message.

Once both T3 and T4 are available at the slave, the delay value between the slave and the master can be determined through the calculation T4 – T3.

Once both the master to slave, and slave to master differences are available at the slave, the one-way delay can be determined. One-way delay = (master to slave difference + slave to master difference) / 2

An offset value is then calculated to adjust the slave clock: Offset = master to slave difference – one-way delay

This can be simplified as: Offset = ((T2 - T1) - (T4 - T3)) / 2

By utilising this offset, the slave clock can adjust its time to ensure it matches the master clock.

Advantages of PTP over NTP

One of the main advantages that PTP has over NTP is the hardware support present in various network interface controllers (NIC) and network switches. The specialized hardware allows PTP to account for delays in message transfer and improves the accuracy of time synchronization. To achieve the best possible accuracy, it is recommended that all networking components between PTP clocks are PTP hardware enabled.

Hardware-based PTP provides optimal accuracy, since the NIC can time stamp the PTP packets at the exact moment they are sent and received. Compare this to software-based PTP, which requires additional processing of the PTP packets by the operating system.

[0] https://www.bodet-time.com/time-servers/articles-and-resources/1774-how-works-the-precision-time-protocol-ptp.html
[1] https://en.wikipedia.org/wiki/Precision_Time_Protocol
[2] https://en.wikipedia.org/wiki/Network_Time_Protocol
[3] https://docs.openshift.com/container-platform/4.12/networking/using-ptp.html

Written on April 10, 2023