Understanding IEEE1588V1-V2
Simple understanding of IEEE 1588 protocol
IEEE 1588 is a precision time protocol (PTP) for synchronizing clocks in computer networks. In local area networks, it can control clock accuracy in the sub-microsecond range, making it suitable for measurement and control systems. The IEEE 1588 standard defines a master-slave architecture for clock distribution, consisting of one or more network segments and one or more clocks. The time synchronization protocol in the TSN network uses the IEEE 802.1AS protocol, which is simplified and modified based on the IEEE 1588 protocol and is also called the gPTP protocol. IEEE 1588 protocol is short for Precision Timing Protocol (PTP), and its full name is "Precision Clock Synchronization Protocol Standard for Network Measurement and Control Systems" (IEEE 1588 Precision Clock Synchronization Protocol). The basic principle of its operation is to send synchronized data frames between master and slave nodes, record the sending time and receiving time information of the data frames, and add the time information to the data frames. The slave node obtains this time information, calculates the time deviation between the slave node's local clock and the master clock and the transmission delay between network nodes, and corrects the local clock to synchronize it with the master node clock. There can only be one master clock in a PTP network. The PTP protocol is mainly divided into two parts to achieve clock synchronization function: 1. Establish a synchronization system: The protocol uses the Best Master Clock Algorithm (BMCA) to select a master clock, establish a master-slave topology, and then establish a synchronization system in the entire PTP network. 2. Synchronize local clock: The protocol uses the Local Clock Synchronization Algorithm (LCS) to calculate the time deviation between the local clock of each slave node and the master clock through the exchange of PTP data packets between the master and slave nodes in the network, and adjust the local clock to synchronize it with the master clock.
IEEE 1588v1 The clocks in the entire PTP network can be divided into ordinary clocks (OC) and boundary clocks (BC) according to the number of PTP communication ports on them: there is only one ordinary clock, while there are multiple boundary clocks. Boundary clocks are generally used at network nodes with low determinism, such as switches or routers, as shown in the figure below. PTP communication is carried out independently on each port. 1. Boundary Clock: Only one slave port is allowed on the boundary clock, which communicates with the master port of the upper node and synchronizes its local clock with the master port. The remaining ports are master ports, which communicate with the slave ports of the downstream nodes. The boundary clock can connect to different network protocols. 2. Synchronous system establishment process: (1) In the initial state, each node port will listen to the Sync data frame in the network within the specified time; if a Sync data frame is received, the node port will determine the port state according to the best master clock algorithm. If no Sync data frame is received, the node state changes to Pre_Master and assumes itself as the master clock node. At this time, the node port state is the master clock, but no Sync frame is sent. (2) The port status remains Pre_Master for a certain period of time: If a Sync data frame is received within the specified time of the port, the port status is determined by the best master clock algorithm. If the port is determined to be a master clock, it will periodically send Sync frames; if it is determined to be a slave clock, it will accept Sync frames, calculate the deviation, and correct the local clock. If the port does not receive a Sync data frame within this time period, the state is changed to the master clock and the Sync data frame is started to be sent regularly. (3) The status of the master clock and slave clock changes with the change of clock performance and operating status. The figure below shows the state transition in BMCA.
3. Time synchronization establishment process:
As shown in the figure below, the PTP synchronization principle
As shown in the figure, the Master is the synchronization clock source in the network, which can be considered to be infinitely close to UTC or GPS time. The Slave is the device that needs to be synchronized in the network. Assuming that the path from the Master to the Slave conforms to the symmetric path, the delay on the path is set as Delay, and the time difference between the Master and Slave devices to be synchronized is Offset, that is, the Slave is slower than the Master at the same time by Offset.
The Slave device can calibrate the local clock according to the calculated Offset. However, the 1588V1 protocol relies on the symmetry of the link, that is, the delay from Master to Slave and from Slave to Master is consistent, which is difficult to meet in actual network conditions, so an additional asymmetric algorithm is needed to calculate and compensate for the link delay difference.
IEEE 1588v2 IEEE1588V2 has made improvements and extensions on IEEE1588V1. Mainly includes:
1. Added independent message mode for point-to-point path delay measurement.
The path delay time Delay between port A and port B is:
In PTPv1, the average path delay is measured by using Sync frames and Delay_Req frames, but in PTPv2, the Sync frame is not required, and the measurement is performed only through the PDelay_Req data frame series. This is an independent delay measurement process that does not rely on the participation of Sync frames and the establishment of a synchronization system, which improves the measurement accuracy and can obtain a more accurate path delay by averaging the average value after multiple measurements. On the other hand, if the synchronization system in the network changes, there is no need to recalculate the path delay between the nodes. The previously measured delay data can be used directly, which greatly enhances the efficiency of the protocol execution and makes the protocol more convenient and flexible. In PTPv2, the use of the PDelay_req data frame series has become the main method for measuring path delay. 2. Added transparent clock model In PTPv1, all the intermediate nodes in the network adopt the boundary clock model. The boundary clock connected to the only master clock in the network, that is, an ordinary clock, receives the synchronization data frame sent by the master node through its only slave port, and synchronizes with the master clock. The remaining master ports and other boundary clocks connected to them send synchronization data frames, and finally synchronize to the ordinary clock at the edge of the network, thus achieving time synchronization of the entire network. Although this method is feasible, since this method is synchronized step by step, the farther the node is from the master clock, the lower the synchronization accuracy. When some nodes in the network do not need clock synchronization or do not have synchronization function, the transparent clock model can be used. Unlike the BC/OC mode, the transparent clock does not require each node to synchronize with the master clock. Its port only forwards the protocol data frame and adds the calculated data frame retention time to the correction domain. This method makes the processing of PTP data frames simpler, reduces the difficulty of implementing the PTP protocol in the network, and improves the synchronization accuracy of each slave node. There are two models of transparent clock: end-to-end transparent clock and point-to-point transparent clock. (1) End-to-end (E2E) transparent clock The E2E transparent clock does not process ordinary data frames in the network, but only transmits them to allow them to pass normally. However, for PTP event data frames, the residence delay time from the receiving port to the sending port is accumulated to the correction field in the data frame to compensate for the delay error caused by the PTP data frame passing through itself. (2) Point-to-point (P2P) transparent clock Point-to-point (P2P) transparent clock only forwards specific PTP messages, including Sync frames, Follo_Up frames, and Announce frames. It also uses the Pdelay_Req data frame series to calculate the path delay time between each port and the port it is connected to, and then combines it with the delay time between ports and adds it to the time correction domain to compensate for the time delay of the data frame from the source port to the point-to-point transparent clock out port. 3. Adding a single-step clock model The single-step clock model solves the problem of matching Follow_Up frames with Sync frames. The basic synchronization process of the PTP protocol adopts a two-step mode, that is, the master clock node sends a Sync frame and a Follow_Up frame with the Sync frame sending time. Although this method can improve the accuracy of the Sync frame timestamp and improve the synchronization effect, when the network load is large, the data frame is likely to be lost or blocked, resulting in errors in the matching of the two data frames. Set a flag in the PTP data frame to use the single-step mode, and use the difference between the sending time of the Sync frame and the time tag in the data frame as the transmission delay, and add it to the correction field. In this way, the master clock can perform time synchronization calibration through a separate Sync frame without the need for Follow_Up. Single-step mode can reduce network traffic and improve the reliability of synchronization when the network load is large. Single-step mode requires additional auxiliary hardware to help calculate the time correction value and accumulate it into the correction domain, which has relatively high requirements on the real-time performance of the network.
BMCA BMCA, or Best Master Clock Algorithm, selects the best performing clock in the network as the master clock, and uses it to establish the network topology, generate a synchronization system, and thus realize the clock synchronization function. The best master clock is selected by transmitting Announce frames in each node in the network, comparing the clock attributes on each node (such as whether the clock is designated as a master or slave clock), the clock level used to identify the accuracy, and the clock type used to identify the clock source type (such as rubidium clock, cesium clock, etc.), as well as clock characteristics such as clock offset and variance, clock address, and clock port number to select the best master clock. When other clock characteristics are the same, the protocol will use the node clock with the smallest port number as the master clock. The IEEE 1588 protocol will form a tree topology with the master clock node as the root node, and to avoid generating loops, the protocol defines those node ports that fail in competition as passive or disabled.
View full article