Method for realizing PTP (Precision Time Protocol) main interface function by chip and switch chip
By implementing the PTP master interface function through an Ethernet switching chip, PTP messages are automatically processed, which solves the problem of high CPU load and cache overhead in multi-clock domain protocol stacks and improves the security and robustness of the system.
Patent Information
- Application Number
- CN202511659624.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-02-24
AI Technical Summary
In a multi-clock domain PTP protocol stack, the CPU load and cache overhead are too high, which increases chip development costs and poses a single point of failure risk.
The PTP master interface function is implemented through an Ethernet switching chip, which automatically sends subsequent messages and responds to delay requests or peer delay request messages, reducing CPU load and cache overhead.
It reduces the CPU load on running the PTP multi-clock domain protocol stack and the cache overhead for sending and receiving PTP messages, thereby improving the system's security and robustness.
Smart Images

Figure CN121567253A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Ethernet switching chip technology, and in particular to a method for implementing PTP host interface function in a chip and a switch chip. Background Technology
[0002] With the development of large-scale distributed systems such as smart grids, data centers, and 5G communication networks, a single PTP clock domain is insufficient to manage thousands or even tens of thousands of nodes. For example, the State Grid dispatch system needs to synchronize provincial master stations, substations, and distributed energy equipment. If all nodes are forced to synchronize to the same master clock, long-distance transmission will lead to excessive cumulative latency, affecting synchronization accuracy. The PTP multi-clock domain architecture achieves hierarchical synchronization through boundary clocks (BC). The provincial master station acts as the root clock domain, and time signals are progressively distributed to city-level subdomains via boundary clocks. Each subdomain independently optimizes synchronization parameters, allowing the system to scale horizontally to tens of thousands of nodes while keeping single-hop latency below 100ns, meeting the millisecond-level response requirements of power monitoring. Furthermore, in high-security fields such as financial transactions and military communications, a single clock domain poses a "single point of failure" risk. The PTP multi-clock domain architecture enables a dual-master clock hot standby architecture, with primary and backup clocks operating independently in different domains, allowing for seamless switching and significantly improving system security and robustness.
[0003] The PTP protocol stack calculates the time skew and average link delay between master and slave devices by sending and receiving synchronization messages (sync), delay request messages (delay_req), and delay response messages (delay_resp) through a delay request mechanism. Alternatively, it can use a peer-to-peer delay mechanism to send and receive peer delay request messages (pdelay_req) and peer delay response messages (pdelay_resp) to calculate the average link delay, and then calculate the time skew between master and slave devices based on the measured average link delay by sending and receiving synchronization messages (sync).
[0004] A multi-clock-domain PTP protocol stack runs an independent protocol stack program in each clock domain of the CPU core. Each enabled PTP master interface periodically sends a synchronization message (sync) and responds to delay request messages (delay_req) or peer delay request messages (pdelay_req) sent by downstream slave interfaces. For the two-step method, it is also necessary to send follow-up messages of the synchronization message (follow_up) and follow-up messages of the peer delay response message (pdelay_resp_follow_up). As can be seen, as the number of clock domains increases, the CPU load will also increase exponentially.
[0005] To reduce the overall development cost of chips, existing technologies set up a template for each message type defined by the protocol. When sending a message, only the basic message content (such as message type, length, and tags) is filled into the template. The time information or related calculations that need to be obtained through chip hardware are generated by the chip logic or inserted into the message after processing. This can reduce some of the CPU's computational overhead, but it does not reduce the number of PTP messages sent and received by the CPU. Compared with the PTP single-clock-domain protocol stack, the CPU needs to respond to more packet reception interrupts and send more PTP messages when running a multi-clock-domain protocol stack. In addition, the cache overhead occupied by sending and receiving PTP messages is also very large. Summary of the Invention
[0006] To address the aforementioned technical issues, this invention replaces the CPU with an Ethernet switching chip to implement the two-step automatic sending of subsequent messages and automatic response to delay requests or peer delay request messages in the PTP master interface. This effectively reduces the CPU load on running the PTP multi-clock domain protocol stack and the buffering overhead for sending and receiving PTP messages.
[0007] To achieve the above objectives, the present invention provides a method for implementing PTP master interface functionality in a chip, comprising the following steps: S1: Receiving a PTP message; S2: Identifying the type of the received PTP message; if the received PTP message is a synchronization message from the CPU port and the master interface uses a two-step method, proceed to step S3; if the received PTP message is a delay request message from the Ethernet physical port, proceed to step S4; if the received PTP message is a peer-to-peer delay request message from the Ethernet physical port, proceed to step S5; S3: Copying the synchronization message and modifying it into a subsequent message, then sending the synchronization message and the subsequent message, wherein the sending timestamp of the synchronization message is inserted into the subsequent message; S4: Modifying the delay request message into a delay response message, and sending the delay request message into a peer-to-peer delay response message. The message's reception timestamp is inserted into the delayed response message, and then the delayed response message is sent; S5: If the main interface uses a one-step method, the peer-to-peer delayed request message is modified into a peer-to-peer delayed response message, the difference between the sending timestamp and the receiving timestamp of the peer-to-peer delayed response message is inserted into the peer-to-peer delayed response message, and then the peer-to-peer delayed response message is sent; If the main interface uses a two-step method, the peer-to-peer delayed request message is modified into a peer-to-peer delayed response message, the receiving timestamp of the peer-to-peer delayed request message is inserted into the peer-to-peer delayed response message, and then the peer-to-peer delayed response message is sent, and the peer-to-peer delayed request message is copied and modified into a peer-to-peer delayed response follow-up message, the sending timestamp of the peer-to-peer delayed response message is inserted into the peer-to-peer delayed response follow-up message, and then the peer-to-peer delayed response follow-up message is sent.
[0008] Furthermore, in step S1, the Mac module receives the PTP message and records the receiving timestamp at the same time as receiving the PTP message.
[0009] Further, step S3 specifically includes: S31: Based on the PTP message type being a synchronous message and the chip having enabled the automatic sending of subsequent messages function, the PTP two-step message processing module copies the synchronous message as a subsequent message and marks the copied message as to be forwarded following the synchronous message; S32: The PTP message forwarding processing module determines the forwarding destination port of the synchronous message, which is also the forwarding destination port of the copied message; S33: The PTP message modification module passes the synchronous message through to the Mac module according to the destination port number, modifies the copied message as a subsequent message, and sends it to the Mac module according to the destination port; S34: The Mac module sends the synchronous message directly without modification, inserts the sending timestamp of the synchronous message into the subsequent message, and then the Mac module sends the subsequent message.
[0010] Further, step S4 specifically includes: S41: The PTP two-step message processing module forwards the received delay request message to the PTP message forwarding processing module; S42: Based on the PTP message type being a delay request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the delay request message as the source port; S43: The PTP message modification module modifies the delay request message into a delay response message, inserts the received timestamp of the delay request message into the delay response message, and then sends the modified delay response message to the Mac module according to the destination port; S44: The Mac module sends out the received delay response message.
[0011] Further, step S5 specifically includes: S51: Based on the PTP message type being a peer-to-peer delay request message and the chip having enabled the automatic sending of subsequent messages function, the PTP two-step message processing module copies the peer-to-peer delay request message as a peer-to-peer delay response subsequent message and marks the copied message as to be forwarded following the peer-to-peer delay request message; S52: Based on the PTP message type being a peer-to-peer delay request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the peer-to-peer delay request message as the source port, which is also the destination port of the copied message; S53: If it is a one-step method, the PTP message modification module modifies the peer-to-peer delay request message into a peer-to-peer delay response message, inserts the difference between the sending timestamp of the peer-to-peer delay response message and the receiving timestamp of the peer-to-peer delay request message into the peer-to-peer delay response message, and then, based on the destination port, modifies the message into a peer-to-peer delay response message. The modified peer-to-peer delay response message is sent to the Mac module; if it is a two-step method, the PTP message modification module modifies the peer-to-peer delay request message into a peer-to-peer delay response message, inserts the receiving timestamp of the peer-to-peer delay request message into the peer-to-peer delay response message, and then sends the modified peer-to-peer delay response message to the Mac module according to the destination port. Additionally, the PTP message modification module modifies the copy message into a peer-to-peer delay response follow-up message, and then sends the modified peer-to-peer delay response follow-up message to the Mac module according to the destination port; S54: If it is a one-step method, the Mac module sends out the peer-to-peer delay response message; if it is a two-step method, the Mac module sends out the peer-to-peer delay response message, inserts the sending timestamp of the peer-to-peer delay response message into the peer-to-peer delay response follow-up message, and then sends out the peer-to-peer delay response follow-up message.
[0012] Further, in step S2, the PTP message identification module identifies the message as a PTP message based on EtherType being 0x88F7 or the UDP port number used by PTP, and parses the PTP message type according to the protocol.
[0013] Furthermore, in step S32, the PTP message forwarding processing module determines the forwarding destination port of the synchronization message and the copy message based on the interface or the destination port specified by the user; and in step S34, the MAC module records the hardware timestamp of the synchronization message while sending the synchronization message to obtain the sending timestamp of the synchronization message.
[0014] Furthermore, in step S54, the sending timestamp of the peer-to-peer delayed response message is obtained by recording the hardware timestamp of the message sent by the Mac module while sending the peer-to-peer delayed response message.
[0015] The technical solution of the present invention also provides a switch chip for implementing the method described above, wherein the switch chip includes a MAC module, a PTP message recognition module, a PTP two-step message processing module, a PTP message forwarding processing module, and a PTP message modification module. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of the key modules of the switching chip in this invention for processing PTP messages;
[0018] Figure 2 This is a flowchart of the PTP two-step message processing module of the present invention;
[0019] Figure 3 This is a flowchart of the PTP message forwarding processing module of the present invention;
[0020] Figure 4 This is a flowchart of the PTP message modification module and MacTx direction processing of the present invention. Detailed Implementation
[0021] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] The chip mainly implements the function of the main interface replacing the CPU in sending subsequent messages of synchronous messages and subsequent messages of peer-to-peer delayed responses in a two-step manner, as well as the function of downstream slave interfaces sending delay request messages or peer-to-peer delayed messages and automatically responding to delay request messages and peer-to-peer delayed response messages.
[0023] The chip implements a two-step method to replace the CPU's follow-up messages for synchronous messages and peer-to-peer delayed responses. This involves copying the original PTP message, modifying the copied PTP message to the format of the follow-up message, automatically inserting the timestamp of the original PTP message on MacTx into the copied message, and then forwarding it along with the original PTP message.
[0024] The chip implements automatic response to delayed request messages and peer-to-peer delayed request messages by modifying the original PTP request message into the corresponding response message according to the message type, automatically inserting the timestamp of the original PTP message on MacRx into the modified message, and then forwarding it from the source port.
[0025] The method for implementing the PTP master interface function in a chip disclosed in this invention is as follows: Figure 1 As shown, it mainly involves five modules in the Ethernet switching chip: MAC module, PTP message recognition module, PTP two-step message processing module, PTP message forwarding processing module, and PTP message modification module.
[0026] The Mac module processes PTP messages in two directions. The RX receiving direction records the hardware timestamp when a PTP message is received, while the TX sending direction records the hardware timestamp when a PTP message is sent or inserts the timestamp into the PTP message header.
[0027] The PTP message recognition module identifies the message as a PTP message based on EtherType being 0x88F7 or the UDP port number used by PTP, and parses out the PTP message type and other content in the message header according to the protocol.
[0028] PTP two-step message processing module, such as Figure 2 As shown, the main interface uses a two-step method to identify synchronization messages (sync) and peer-to-peer delay request messages (pdelay_req) based on the PTP message recognition module. If the synchronization message (sync) originates from the CPU and the chip registers are configured to enable automatic subsequent message sending, the chip will copy the synchronization message, and the copied PTP message will be sent out from the same output port along with the original synchronization message. If the peer-to-peer delay request message originates from the Ethernet port and the chip registers are configured to enable automatic subsequent message sending, the chip will copy the peer-to-peer delay request message, and the copied PTP message will be sent out from the same output port along with the original peer-to-peer delay request message.
[0029] PTP message forwarding processing module, such as Figure 3 As shown, the PTP message recognition module identifies delay request messages (delay_req) and peer delay request messages (pdelay_req). If the chip registers are configured to enable automatic acknowledgment, the chip will set the forwarding destination port of delay request messages and peer delay request messages as the source port. Other PTP messages will have their forwarding destination port determined according to the interface's PTP configuration.
[0030] PTP message modification module, such as Figure 4As shown, the message header content is modified according to the message type identified by the PTP message recognition module. If the original message is a synchronous message, the copied PTP synchronous message will be modified into a subsequent message. The synchronous message records a hardware timestamp in the Mac module's Tx direction, while the subsequent message inserts the recorded hardware timestamp into the message header in the Mac module's Tx direction before being sent out from the destination port. If the original message is a delayed request message, it will be modified into a delayed response message. The hardware timestamp recorded in the delayed request message in the Mac module's Rx direction will be inserted into the delayed response message header before being sent out from the destination port.
[0031] The following will provide specific embodiments of the present invention in conjunction with specific PTP message types:
[0032] The CPU is configured in advance via registers to enable a two-step process instead of the CPU sending subsequent messages and automatically responding to delayed or peer-to-peer delayed request messages.
[0033] I. Example of Synchronous Message Sending Subsequent Messages
[0034] 1. The CPU specifies a two-step method for sending synchronization messages to the switching chip CPU Mac module.
[0035] 2. CPU Mac module Rx direction
[0036] Receive the PTP message and send it to the PTP message recognition module.
[0037] 3. PTP Message Recognition Module
[0038] The PTP message was identified as a synchronization message.
[0039] 4. PTP Two-Step Message Processing Module
[0040] Based on the PTP message type being a synchronous message (source port being the CPU port) and the chip having its automatic follow-up message sending function enabled, this PTP message is copied as a follow-up message, and it is marked that this copied message should be forwarded following the original PTP message.
[0041] 5. PTP Message Forwarding Processing Module
[0042] Determine the destination port for forwarding the original synchronization message based on the interface or the destination port specified by the user; that is, determine the destination port for forwarding the copy message of the PTP message.
[0043] 6. PTP Message Modification Module
[0044] The original synchronization message is passed through to the Mac module based on the destination port number. The copied PTP message is modified into a subsequent message and sent to the Mac module based on the destination port number.
[0045] 7. Mac module Tx direction
[0046] The original synchronization message is sent out without modification, and the hardware timestamp of the sending is recorded. Subsequent messages will insert the timestamp recorded in the original synchronization message into the message header and update the relevant information in the header before being sent out.
[0047] II. Examples of Automatic Response Delayed Request Messages
[0048] 1. Mac module Rx direction
[0049] Upon receiving a PTP message, the hardware timestamp of the received message is recorded, and the PTP message is then sent to the PTP message recognition module.
[0050] 2. PTP Message Recognition Module
[0051] The PTP message was identified as a delayed request message.
[0052] 3. PTP Two-Step Message Processing Module
[0053] The delay request message is passed through to the PTP message forwarding processing module.
[0054] 4. PTP Message Forwarding Processing Module
[0055] Based on the PTP message type being a Delayed Request Message (source port being an Ethernet port) and the automatic response function being enabled, the destination port of this PTP message is determined to be the source port.
[0056] 5. PTP Message Modification Module
[0057] Based on the PTP message type being a Delay Request message, it is modified to a Delay Response message, and the hardware timestamp recorded in the Rx direction by the Mac module is inserted into the Delay Response message. Then, the modified Delay Response message is sent to the Mac module according to the destination port.
[0058] 6. Mac module Tx direction
[0059] Send out the PTP delayed response message.
[0060] III. Examples of Automatic Response to Peer-to-Peer Delay Request Messages
[0061] 1. Mac module Rx direction
[0062] Upon receiving a PTP message, the hardware timestamp of the received message is recorded, and the PTP message is then sent to the PTP message recognition module.
[0063] 2. PTP Message Recognition Module
[0064] The PTP message was identified as a peer-to-peer delay request message.
[0065] 3. PTP Two-Step Message Processing Module
[0066] Based on the PTP message type being a peer-to-peer delay request message (source port being an Ethernet port) and the chip having its automatic follow-up message sending function enabled, this PTP message is copied as a peer-to-peer delay response follow-up message, and this copied message is marked as being forwarded following the original PTP message.
[0067] 4. PTP Message Forwarding Processing Module
[0068] Based on the PTP message type being a peer-to-peer delay request message and the automatic response function being enabled, the destination port of this PTP message is determined to be the source port, which is also the destination port for forwarding the copy message of this PTP message.
[0069] 5. PTP Message Modification Module
[0070] - Based on the PTP message type being a peer-to-peer delay request message, the original peer-to-peer delay request message is modified into a peer-to-peer delay response message. The hardware timestamp recorded in the Rx direction by the Mac module is inserted into the header of the peer-to-peer delay response message. Then, the modified delay response message is sent to the Mac module according to the destination port.
[0071] - Based on the PTP message type being a peer-to-peer delay request message, modify the copied peer-to-peer delay request message into a peer-to-peer delay response follow-up message, and then send the modified delay response message to the Mac module according to the destination port.
[0072] 6. Mac module Tx direction
[0073] Send the PTP peer delay response message and record the hardware timestamp of the message; insert the timestamp of the peer delay response message into the header of the subsequent peer delay response message, update the relevant information in the header, and then send it out.
[0074] In an embodiment of the present invention, a method for implementing a PTP master interface function on a chip is provided, comprising the following steps: S1: receiving a PTP message; S2: identifying the type of the received PTP message; if the received PTP message is a synchronization message from a CPU port and the master interface uses a two-step method, proceed to step S3; if the received PTP message is a delay request message from an Ethernet physical port, proceed to step S4; if the received PTP message is a peer-to-peer delay request message from an Ethernet physical port, proceed to step S5; S3: copying the synchronization message and modifying it into a subsequent message, then sending the synchronization message and the subsequent message, wherein the sending timestamp of the synchronization message is inserted into the subsequent message; S4: modifying the delay request message into a delay response message, and modifying the delay request message into a delay response message. S5: If the main interface uses a one-step method, modify the peer delay request message into a peer delay response message, insert the difference between the sending timestamp and the receiving timestamp of the peer delay response message into the peer delay response message, and then send the peer delay response message; If the main interface uses a two-step method, modify the peer delay request message into a peer delay response message, insert the receiving timestamp of the peer delay request message into the peer delay response message, and then send the peer delay response message, and copy the peer delay request message and modify it into a peer delay response follow-up message, insert the sending timestamp of the peer delay response message into the peer delay response follow-up message, and then send the peer delay response follow-up message.
[0075] Furthermore, in step S1, the Mac module receives the PTP message and records the receiving timestamp at the same time as receiving the PTP message.
[0076] Further, step S3 specifically includes: S31: Based on the PTP message type being a synchronous message and the chip having enabled the automatic sending of subsequent messages function, the PTP two-step message processing module copies the synchronous message as a subsequent message and marks the copied message as to be forwarded following the synchronous message; S32: The PTP message forwarding processing module determines the forwarding destination port of the synchronous message, which is also the forwarding destination port of the copied message; S33: The PTP message modification module passes the synchronous message through to the Mac module according to the destination port number, modifies the copied message as a subsequent message, and sends it to the Mac module according to the destination port; S34: The Mac module sends the synchronous message directly without modification, inserts the sending timestamp of the synchronous message into the subsequent message, and then the Mac module sends the subsequent message.
[0077] Further, step S4 specifically includes: S41: The PTP two-step message processing module forwards the received delay request message to the PTP message forwarding processing module; S42: Based on the PTP message type being a delay request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the delay request message as the source port; S43: The PTP message modification module modifies the delay request message into a delay response message, inserts the received timestamp of the delay request message into the delay response message, and then sends the modified delay response message to the Mac module according to the destination port; S44: The Mac module sends out the received delay response message.
[0078] Further, step S5 specifically includes: S51: Based on the PTP message type being a peer-to-peer delay request message and the chip having enabled the automatic sending of subsequent messages function, the PTP two-step message processing module copies the peer-to-peer delay request message as a peer-to-peer delay response subsequent message and marks the copied message as to be forwarded following the peer-to-peer delay request message; S52: Based on the PTP message type being a peer-to-peer delay request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the peer-to-peer delay request message as the source port, which is also the destination port of the copied message; S53: If it is a one-step method, the PTP message modification module modifies the peer-to-peer delay request message into a peer-to-peer delay response message, inserts the difference between the sending timestamp of the peer-to-peer delay response message and the receiving timestamp of the peer-to-peer delay request message into the peer-to-peer delay response message, and then, based on the destination port, modifies the message into a peer-to-peer delay response message. The modified peer-to-peer delay response message is sent to the Mac module; if it is a two-step method, the PTP message modification module modifies the peer-to-peer delay request message into a peer-to-peer delay response message, inserts the receiving timestamp of the peer-to-peer delay request message into the peer-to-peer delay response message, and then sends the modified peer-to-peer delay response message to the Mac module according to the destination port. Additionally, the PTP message modification module modifies the copy message into a peer-to-peer delay response follow-up message, and then sends the modified peer-to-peer delay response follow-up message to the Mac module according to the destination port; S54: If it is a one-step method, the Mac module sends out the peer-to-peer delay response message; if it is a two-step method, the Mac module sends out the peer-to-peer delay response message, inserts the sending timestamp of the peer-to-peer delay response message into the peer-to-peer delay response follow-up message, and then sends out the peer-to-peer delay response follow-up message.
[0079] Further, in step S2, the PTP message identification module identifies the message as a PTP message based on EtherType being 0x88F7 or the UDP port number used by PTP, and parses the PTP message type according to the protocol.
[0080] Furthermore, in step S32, the PTP message forwarding processing module determines the forwarding destination port of the synchronization message and the copy message based on the interface or the destination port specified by the user; and in step S34, the MAC module records the hardware timestamp of the synchronization message while sending the synchronization message to obtain the sending timestamp of the synchronization message.
[0081] Furthermore, in step S54, the sending timestamp of the peer-to-peer delayed response message is obtained by recording the hardware timestamp of the message sent by the Mac module while sending the peer-to-peer delayed response message.
[0082] In another embodiment of the present invention, a switch chip is also provided for implementing the method described above, wherein the switch chip includes a MAC module, a PTP message recognition module, a PTP two-step message processing module, a PTP message forwarding processing module, and a PTP message modification module.
[0083] Beneficial technical effects of the present invention:
[0084] This invention implements the 1588 protocol main interface PTP message processing function through a chip. When the main interface uses the two-step method, it does not send subsequent messages. When receiving delay request or peer delay request messages sent by the downstream slave interface, it does not need to send them to the CPU for processing, nor does it require the CPU to send delay response messages and peer delay response messages. Therefore, it can significantly reduce the CPU load, and also reduce the performance requirements and cost of the on-chip SOC.
[0085] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for implementing PTP master interface functions on a chip, characterized in that, Includes the following steps: S1: Receive PTP messages; S2: Identify the type of the received PTP message. If the received PTP message is a synchronization message from the CPU port and the main interface uses the two-step method, proceed to step S3. If the received PTP message is a delay request message from the Ethernet physical port, proceed to step S4. If the received PTP message is a peer delay request message from the Ethernet physical port, proceed to step S5. S3: Copy the synchronous message and modify it into a subsequent message, then send the synchronous message and the subsequent message, inserting the sending timestamp of the synchronous message into the subsequent message; S4: Modify the delayed request message into a delayed response message, insert the received timestamp of the delayed request message into the delayed response message, and then send the delayed response message; S5: If the main interface uses the one-step method, modify the peer-to-peer delay request message into a peer-to-peer delay response message, insert the difference between the sending timestamp of the peer-to-peer delay response message and the receiving timestamp of the peer-to-peer delay request message into the peer-to-peer delay response message, and then send the peer-to-peer delay response message. If the main interface uses a two-step method, modify the peer delay request message into a peer delay response message, insert the receive timestamp of the peer delay request message into the peer delay response message, and then send the peer delay response message. Alternatively, copy the peer delay request message and modify it into a peer delay response follow-up message, insert the send timestamp of the peer delay response message into the peer delay response follow-up message, and then send the peer delay response follow-up message.
2. The method according to claim 1, characterized in that, In step S1, the Mac module receives the PTP message and records the receiving timestamp at the same time.
3. The method according to claim 2, characterized in that, Step S3 specifically includes: S31: Since the PTP message type is a synchronous message and the chip has enabled the automatic sending of subsequent messages, the PTP two-step message processing module copies the synchronous message as a subsequent message and marks the copied message as a message to be forwarded following the synchronous message. S32: The PTP message forwarding processing module determines the destination port for forwarding the synchronization message, which is also the destination port for forwarding the copy message; S33: The PTP message modification module forwards the synchronization message to the Mac module according to the destination port number, modifies the copy message into a subsequent message, and sends it to the Mac module according to the destination port. S34: The Mac module sends the synchronization message directly without modification, inserts the sending timestamp of the synchronization message into subsequent messages, and then sends the subsequent messages out.
4. The method according to claim 2, characterized in that, Step S4 specifically includes: S41: The PTP two-step message processing module forwards the received delayed request message to the PTP message forwarding processing module. S42: Based on the PTP message type being a delayed request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the delayed request message as the source port. S43: The PTP message modification module modifies the delayed request message into a delayed response message, inserts the received timestamp of the delayed request message into the delayed response message, and then sends the modified delayed response message to the Mac module according to the destination port; S44: The Mac module sends out the received delayed response message.
5. The method according to claim 2, characterized in that, Step S5 specifically includes: S51: Based on the PTP message type being a peer delay request message and the chip having enabled the automatic sending of subsequent messages function, the PTP two-step message processing module copies the peer delay request message as a peer delay response subsequent message and marks the copied message as being forwarded following the peer delay request message. S52: Based on the PTP message type being a peer-to-peer delay request message and the chip having enabled the automatic response function, the PTP message forwarding processing module determines the destination port of the peer-to-peer delay request message as the source port, which is also the destination port of the copied message. S53: If it is a one-step method, the PTP message modification module modifies the peer delay request message into a peer delay response message, inserts the difference between the sending timestamp of the peer delay response message and the receiving timestamp of the peer delay request message into the peer delay response message, and then sends the modified peer delay response message to the Mac module according to the destination port. If it is a two-step method, the PTP message modification module modifies the peer delay request message into a peer delay response message, inserts the received timestamp of the peer delay request message into the peer delay response message, and then sends the modified peer delay response message to the Mac module according to the destination port. In addition, the PTP message modification module also modifies the copy message into a peer delay response follow-up message, and then sends the modified peer delay response follow-up message to the Mac module according to the destination port. S54: If it is a one-step method, the Mac module will send out the equivalent delayed response message; In the two-step method, the Mac module sends out the peer-to-peer delayed response message, inserts the sending timestamp of the peer-to-peer delayed response message into the subsequent peer-to-peer delayed response message, and then the Mac module sends out the subsequent peer-to-peer delayed response message.
6. The method according to claim 1, characterized in that, In step S2, the PTP message identification module identifies the message as a PTP message based on EtherType being 0x88F7 or the UDP port number used by PTP, and parses the PTP message type according to the protocol.
7. The method according to claim 3, characterized in that, In step S32, the PTP message forwarding processing module determines the forwarding destination port for synchronization and replication messages based on the interface or the destination port specified by the user; and In step S34, the Mac module records the hardware timestamp of the synchronization message while sending it, thus obtaining the sending timestamp of the synchronization message.
8. The method according to claim 5, characterized in that, In step S54, the Mac module records the hardware timestamp of the sent peer-to-peer delayed response message while sending the message, thus obtaining the sending timestamp of the peer-to-peer delayed response message.
9. A switch chip, characterized in that, The switch chip is used to implement the method as described in any one of claims 1-8, wherein the switch chip includes a MAC module, a PTP message recognition module, a PTP two-step message processing module, a PTP message forwarding processing module, and a PTP message modification module.