Method and system for time synchronization between network devices

By calculating the mapping relationship through interactive messages and the least squares algorithm, time synchronization between FPGA network cards and P4 switches was achieved, solving the problem of timestamp format and unit differences caused by differences in operating frequencies, and realizing time synchronization between devices.

CN121887341APending Publication Date: 2026-04-17INST OF ACOUSTICS CHINESE ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INST OF ACOUSTICS CHINESE ACAD OF SCI
Filing Date
2024-10-17
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Different manufacturers and types of network devices, such as FPGA network cards and P4 switches, have different operating frequencies, resulting in differences in timestamp formats and units. This makes it impossible to modify timestamps in the data plane, and existing time synchronization protocols cannot achieve time synchronization.

Method used

The device timestamp is obtained by exchanging messages, and the mapping relationship between timestamps is calculated using the least squares algorithm to achieve time synchronization without modifying the device timestamp.

Benefits of technology

It enables time synchronization between network devices, solves the synchronization difficulties caused by differences in timestamp format and unit, and avoids the need to modify device timestamps.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121887341A_ABST
    Figure CN121887341A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for time synchronization between network devices. The method comprises the following steps: a first network device sends a request message carrying a first timestamp recorded when a port is out to a second network device; receiving a response message carrying the first timestamp, the second timestamp and the third timestamp from the second network equipment, and recording a fourth timestamp when the response message enters the port; and obtaining a mapping relationship between the first network equipment timestamp and the second network equipment timestamp according to the multiple groups of timestamps. According to the method and the device, the mapping relationship between the timestamps of different devices is obtained by using the least square algorithm according to the multiple groups of timestamps obtained according to the interaction message, and the first network device time corresponding to the timestamp of the second network device is obtained by using the mapping relationship, so that time synchronization can be realized without modifying the timestamps of the devices; the problem that when the network equipment has no absolute timestamp and the timestamp does not support modification, the existing time synchronization protocol cannot be used for time synchronization is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of time synchronization, specifically relating to a method and system for time synchronization between network devices. Background Technology

[0002] The purpose of time synchronization is to ensure that the local clock's time is consistent with the time of a reference clock source to some extent. Many network technologies, such as load balancing and congestion control, require the use of one-way packet delay. Since some network devices' timestamps only represent relative time rather than absolute time, accurate calculation of one-way delay requires the relevant network devices (NICs, switches) to unify relative time. In computer networks, the general method for synchronizing the time of two network devices is to record the timestamps between the master and slave clocks, exchange timestamp data, and use the four timestamps to calculate the time deviation between the slave and master clocks. This allows for correction of the slave clock, achieving time synchronization between the slave and master clocks. NTP and PTP (IEEE 1588) network protocols are typical examples of this model and are widely used for network time synchronization to meet different levels of time precision.

[0003] However, several technical challenges currently limit the application and implementation of the aforementioned protocols in time synchronization scenarios across different types of network devices. First, network devices from different manufacturers and of different types, such as FPGA network cards and P4 switches, have different timestamp formats and units due to their different operating frequencies; their timestamps can only represent local relative time. Second, P4 switches cannot modify local relative timestamps in the data plane, and time synchronization protocols such as NTP and PTP cannot synchronize the timestamps of both devices in the data plane. Existing technologies cannot solve these problems. Summary of the Invention

[0004] The purpose of this application is to overcome the limitation that existing time synchronization protocols cannot be used for time synchronization when network devices lack absolute timestamps and these timestamps cannot be modified. This application obtains the timestamps of the devices to be synchronized through communication messages between devices, uses a least squares algorithm to obtain the mapping relationship between timestamps, and uses the mapping relationship to obtain the local time corresponding to the timestamps of other network devices, thus achieving time synchronization without modifying the device timestamps.

[0005] To achieve the above objectives, this application proposes a method for time synchronization between network devices, involving a first network device and a second network device, including:

[0006] Step S0: The first network device sends a request message to the second network device; the request message carries a first timestamp recorded when the port is exiting;

[0007] Step S1: The second network device receives the request message and generates a response message carrying a first timestamp, a second timestamp, and a third timestamp; the second timestamp is the second network device timestamp when the second network device receives the request message, and the third timestamp is the second network device timestamp when the second network device sends the response message;

[0008] Step S2: The first network device receives the response message from the second network device and records the fourth timestamp of the ingress port of the response message;

[0009] Step S3: The first network device obtains the mapping relationship between the first network device timestamp and the second network device timestamp based on multiple sets of first timestamp, second timestamp, third timestamp, and fourth timestamp;

[0010] The first network device converts the timestamp of the second network device based on the mapping relationship to obtain a mapping value of the timestamp of the second network device, and uses the mapping value and the timestamp of the first network device to calculate the latency between the devices.

[0011] As an improvement to the above method, the mapping relationship between the timestamps of the first network device and the second network device is as follows:

[0012] T' = A * T + OFFSET

[0013] Where T represents the timestamp of the second network device; T' represents the mapped timestamp of the first network device, i.e., the mapping value of the timestamp of the second network device; A represents the ratio of the counting frequencies of the timestamp of the first network device to the timestamp of the second network device; OFFSET represents the time deviation of the network device.

[0014] As an improvement to the above method, the mapping relationship between the timestamps of the first network device and the second network device is calculated using the least squares algorithm:

[0015] Obtain N sets of timestamps: first timestamp t1, second timestamp t2, third timestamp t3, and fourth timestamp t4. Calculate A and OFFSET; where A and OFFSET satisfy the following relationship with the timestamps:

[0016] t1+t4=A*(t2+t3)+2*OFFSET

[0017] The formula for calculating A is:

[0018]

[0019] in, This represents the average value of (t1+t4) for N sets of timestamps; This represents the average value of (t2+t3) for N sets of timestamps;

[0020] The formula for calculating OFFSET is:

[0021]

[0022] This application also provides a time synchronization system between network devices, implemented based on the above method, wherein the system includes a first network device and a second network device; wherein...

[0023] The first network device is configured to send a request message carrying a first timestamp recorded at the outgoing port to the second network device; receive a response message carrying a first timestamp, a second timestamp, and a third timestamp from the second network device, and record a fourth timestamp at the incoming port of the response message; obtain a mapping relationship between the timestamps of the first network device and the timestamps of the second network device based on multiple sets of first timestamps, second timestamps, third timestamps, and fourth timestamps; convert the timestamps of the second network device based on the mapping relationship to obtain a mapping value of the timestamps of the second network device; and use the mapping value and the timestamps of the first network device to calculate the latency between the devices.

[0024] The second network device is configured to receive a request message sent by the first network device, generate a response message with a first timestamp, a second timestamp, and a third timestamp, and send it to the first network device.

[0025] As an improvement to the above system, the first network device includes:

[0026] A timestamp generator is used to generate local timestamps.

[0027] The timed request module is used to periodically generate request messages and send them to the TX timestamp filling module;

[0028] The TX timestamp filling module is used to fill the timestamp generated by the timestamp generator into the request message to be sent and send it to the TX module.

[0029] The TX module is used to send request messages to the second network device;

[0030] The RX module is used to receive response messages from the second network device and send them to the RX timestamp filling module.

[0031] The RX timestamp filling module is used to fill the response message with the timestamp generated by the timestamp generator and send it to the timestamp parsing module.

[0032] The timestamp parsing module is used to parse the input response message and output the parsed first timestamp, second timestamp, third timestamp, and fourth timestamp to the calculation module and the mapping storage module.

[0033] The calculation module is used to calculate the parameters A and OFFSET of the mapping relationship and send the results to the mapping storage module;

[0034] The mapping storage module is used to calculate the time of the first network device corresponding to the timestamp of the second network device based on A and OFFSET when the timestamp of the second network device is received.

[0035] Compared with existing technologies, the advantages of this application are:

[0036] The technical solution of this application can achieve time synchronization without modifying the timestamp of the device, effectively solving the problem that when the network device has no absolute timestamp and the timestamp does not support modification, the existing time synchronization protocol cannot be used for time synchronization. Attached Figure Description

[0037] Figure 1 The diagram shows a flowchart of a time synchronization method between network devices.

[0038] Figure 2 The diagram shown is a time synchronization framework diagram for an FPGA network card.

[0039] Figure 3 The diagram shows the timestamp locations of a P4 switch; where PHY: Physical Layer; MAC: Data Link Layer; Ingress pipeline; Traffic manager; Egress pipeline; Queue.

[0040] Figure 4 The diagram shows a time synchronization diagram between the first network device and the second network device. Detailed Implementation

[0041] The technical solution of this application will be described in detail below with reference to the accompanying drawings.

[0042] like Figure 1 As shown, this application provides a method and system for time synchronization between network devices, used for one network device to synchronize its time based on messages exchanged with another network device. The method includes:

[0043] Step S0: The first network device sends a request message to the second network device, which carries the first timestamp recorded at the outgoing port;

[0044] Step S1: The second network device receives the request message and generates a response message carrying the first timestamp, the second timestamp, and the third timestamp;

[0045] The second timestamp indicates the timestamp of the second network device when it receives the request message. The third timestamp indicates the timestamp of the second network device when it sends the response message.

[0046] Step S2: The first network device receives a response message carrying the first, second, and third timestamps from the second network device, and records the fourth timestamp when the response message enters the port;

[0047] Step S3: The first network device obtains the mapping relationship between the first network device timestamp and the second network device timestamp based on multiple sets of first timestamp, second timestamp, third timestamp, and fourth timestamp; the second network device timestamp is converted based on the mapping relationship to obtain the mapping value of the second network device timestamp, and the latency between the devices is calculated using the mapping value and the first network device timestamp.

[0048] The mapping relationship between the timestamps of the first network device and the second network device is as follows:

[0049] T' = A * T + OFFSET

[0050] Wherein, T is used to indicate the timestamp of the second network device, T' is used to indicate the mapped timestamp of the first network device, that is, the mapping value of the timestamp of the second network device, A is used to indicate the ratio of the counting frequency of the timestamp of the first network device to that of the timestamp of the second network device, and OFFSET is used to indicate the time deviation of the network device, with the unit being consistent with that of the timestamp of the first network device.

[0051] The parameters A and OFFSET in the mapping relationship between the timestamps of the first network device and the timestamps of the second network device are calculated using the least squares algorithm:

[0052] Obtain N sets of timestamps: first timestamp t1, second timestamp t2, third timestamp t3, and fourth timestamp t4. Calculate parameters A and OFFSET. A and OFFSET satisfy the following relationship with the timestamps:

[0053] t1+t4=A*(t2+t3)+2*OFFSET

[0054] The formula for calculating A is:

[0055]

[0056] The formula for calculating OFFSET is:

[0057]

[0058] in, This represents the average value of (t1+t4) for N sets of timestamps. This represents the average value of (t2+t3) for N sets of timestamps.

[0059] Example 1

[0060] In one embodiment of this application, time synchronization is performed between an FPGA network card and a P4 switch. The first network device is an FPGA network card, and the second network device is a P4 switch. The first network device has the functions of periodically generating request packets, filling the packets with timestamps, parsing the timestamps in the packets, and calculating the timestamp mapping relationship. The second network device has the function of filling the packets with timestamps. The first network device operates at a frequency of 250MHz and the timestamp is a 64-bit tick counter with a counting frequency of 4ns. The second network device operates at a frequency of 1.22GHz and the timestamp format is a 48-bit nanosecond timestamp.

[0061] Figure 2 The diagram illustrates the time synchronization framework of the first network device's FPGA network interface card (NIC), specifically including a timestamp generator, a timer request module, a TX timestamp filling module, an RX timestamp filling module, a timestamp parsing module, a calculation module, and a mapping storage module. The timestamp generator is connected to the TX and RX timestamp filling modules; the timer request module is connected to the TX timestamp filling module; the RX timestamp filling module is connected to the timestamp parsing module; the calculation module is connected to the timestamp parsing module and the mapping storage module; and the mapping storage module is connected to the timestamp parsing module.

[0062] The timestamp generator is used to generate local timestamps. The input is a 250MHz clock, and the output timestamp is generated by a 64-bit counter to represent the number of ticks that have passed in the current FPGA network card. The timestamp is incremented by 1 when the rising edge of each pulse arrives, indicating that the absolute time has passed by 4ns. The timestamp is output to the TX timestamp filling module and the RX timestamp filling module.

[0063] The timed request module allows the user to configure the request message generation period and the number of messages sent in each period. In this embodiment, the module generates 64 request messages every 10ms. When generating the messages, 4 timestamp fields are reserved. After generation, the messages are sent to the TX timestamp filling module.

[0064] Optionally, the timing request module can also be located on the host. The generated request message is sent to the TX timestamp filling module on the FPGA.

[0065] The TX timestamp filling module takes a request message as input, fills the timestamp into the corresponding offset in the message to be sent according to the pre-set first timestamp offset, and outputs a request message containing the first timestamp.

[0066] The TX module is used to send request messages to the second network device.

[0067] The RX module is used to receive response messages from the second network device and send them to the RX timestamp filling module.

[0068] The RX timestamp filling module takes a response message as input, fills the received message with the timestamp according to the pre-set fourth timestamp offset, and outputs a response message containing the fourth timestamp.

[0069] The timestamp parsing module parses the input response message and outputs the parsed first, second, third, and fourth timestamps to the calculation module and the mapping storage module.

[0070] The calculation module is located on the host. It receives the timestamp from the timestamp parsing module, calculates the parameters A and OFFSET of the mapping relationship, and sends the result to the mapping storage module through the PCIe bus after the calculation is completed.

[0071] Alternatively, the computation module can also be located on the FPGA, and after the computation is completed, the result is sent directly to the mapping storage module.

[0072] The mapping storage module receives the A and OFFSET updates from the calculation module, and simultaneously receives the timestamp of the second network device from the timestamp parsing module. Once the timestamp of the second network device is received, the mapping storage module calculates the time of the first network device corresponding to the second network device's timestamp based on the currently stored A and OFFSET.

[0073] like Figure 4 The diagram shows the exchange messages and timestamps between the first network device's FPGA network card and the second network device's P4 switch during time synchronization. Figure 1 The steps for synchronizing the time between two network devices are described in detail.

[0074] Step S0) The first network device sends a request message to the second network device, the request message carrying a first timestamp recorded when the port is exiting;

[0075] Specifically, the timed request module on the FPGA network card or host generates 64 request messages every 10ms. These messages are filled with the current timestamp, i.e. the first timestamp, in the TX timestamp filling module.

[0076] Step S1) The second network device receives the request message and generates a response message carrying the first timestamp, the second timestamp, and the third timestamp;

[0077] Specifically, after receiving the request packet, the P4 switch writes its own data plane timestamp information into the request packet, then generates a response packet and sends it to the FPGA network card. Figure 3 The example demonstrates that the P4 switch can record timestamps at seven locations. In this embodiment, timestamps TS2 and TS5 are obtained at the ingress and egress resolvers and filled into the packet. The P4 switch fills in a 48-bit nanosecond timestamp. Alternatively, timestamps TS3 and TS4 can be obtained. TS4 can be obtained by adding TS3 and the packet queuing time deq_timedelta.

[0078] Step S2) The first network device receives the response message and records the fourth timestamp;

[0079] Specifically, after the FPGA network card receives the response message, the RX timestamp filling module fills the message with the time when the message was received and sends the message to the timestamp parsing module.

[0080] Step S3) Calculate the mapping relationship between the timestamps of the two devices;

[0081] Specifically, the timestamp parsing module on the FPGA network card parses the first, second, third, and fourth timestamps in the response message according to the specified offset and bit width, and transmits them to the calculation module through the PCIe bus. After receiving at least two sets of timestamps, the calculation module performs mapping relationship calculation.

[0082] If the calculation module obtains the number N timestamp groups, it calculates the average of (t1+t4) and the average of (t2+t3) of the N timestamp groups, and then applies the formula:

[0083]

[0084] Calculate A, then use A and the formula:

[0085]

[0086] The offset is calculated, and the result is sent to the mapped memory module via the PCIe bus.

[0087] The second network device timestamp parsed from the FPGA network card is sent to the mapping storage module for conversion. Based on the current values ​​of A and OFFSET in the module, the mapping value T' of the second network device timestamp is obtained using the formula T' = A * T + OFFSET.

[0088] The method proposed in this application can also be used to calculate one-way delay. The FPGA network card parses the second and third timestamps in the packet, sends the two timestamps to the mapping storage module for mapping calculation, and obtains the corresponding mapping value. Therefore, the calculation method of one-way delay of FPGA network card-P4 switch is as follows:

[0089] T'(T = second timestamp) - first timestamp;

[0090] The calculation method for the one-way latency of a P4 switch-FPGA network card is as follows:

[0091] Fourth timestamp - T' (T = third timestamp).

[0092] Example 2

[0093] This application also provides a time synchronization system between network devices, implemented based on the above method. The system includes a first network device and a second network device; wherein...

[0094] A first network device is configured to send a request message to a second network device carrying a first timestamp recorded at the outgoing port; receive a response message from the second network device carrying a first timestamp, a second timestamp, and a third timestamp, and record a fourth timestamp at the incoming port of the response message; obtain a mapping relationship between the timestamps of the first network device and the timestamps of the second network device based on multiple sets of first timestamps, second timestamps, third timestamps, and fourth timestamps; convert the timestamps of the second network device based on the mapping relationship to obtain a mapping value of the timestamps of the second network device; and use the mapping value and the timestamps of the first network device to calculate the latency between the devices.

[0095] The first network device includes:

[0096] A timestamp generator is used to generate local timestamps.

[0097] The timed request module is used to periodically generate request messages and send them to the TX timestamp filling module;

[0098] The TX timestamp filling module is used to fill the timestamp generated by the timestamp generator into the request message to be sent and send it to the TX module.

[0099] The TX module is used to send request messages to the second network device;

[0100] The RX module is used to receive response messages from the second network device and send them to the RX timestamp filling module.

[0101] The RX timestamp filling module is used to fill the response message with the timestamp generated by the timestamp generator and send it to the timestamp parsing module.

[0102] The timestamp parsing module is used to parse the input response message and output the parsed first timestamp, second timestamp, third timestamp, and fourth timestamp to the calculation module and the mapping storage module.

[0103] The calculation module is used to calculate the parameters A and OFFSET of the mapping relationship and send the results to the mapping storage module;

[0104] The mapping storage module is used to calculate the time of the first network device corresponding to the timestamp of the second network device based on A and OFFSET when the timestamp of the second network device is received.

[0105] The second network device is used to receive the request message sent by the first network device, generate a response message with a first timestamp, a second timestamp and a third timestamp, and send it to the first network device.

[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to the embodiments, those skilled in the art should understand that modifications or equivalent substitutions to the technical solutions of this application do not depart from the spirit and scope of the technical solutions of this application, and should all be covered within the scope of the claims of this application.

Claims

1. A method for time synchronization between network devices, involving a first network device and a second network device, comprising: Step S0: The first network device sends a request message to the second network device; The request message carries the first timestamp recorded when the port is exited; Step S1: The second network device receives the request message and generates a response message carrying the first timestamp, the second timestamp, and the third timestamp; The second timestamp is the timestamp of the second network device when the second network device receives the request message, and the third timestamp is the timestamp of the second network device when the second network device sends the response message; Step S2: The first network device receives the response message from the second network device and records the fourth timestamp of the ingress port of the response message; Step S3: The first network device obtains the mapping relationship between the first network device timestamp and the second network device timestamp based on multiple sets of first timestamp, second timestamp, third timestamp, and fourth timestamp; The first network device converts the timestamp of the second network device based on the mapping relationship to obtain a mapping value of the timestamp of the second network device, and uses the mapping value and the timestamp of the first network device to calculate the latency between the devices.

2. The method of time synchronization between network devices according to claim 1, wherein, The mapping relationship between the timestamps of the first network device and the second network device is as follows: T' = A * T + OFFSET Where T represents the timestamp of the second network device; T' represents the mapped timestamp of the first network device, i.e., the mapping value of the timestamp of the second network device; A represents the ratio of the counting frequencies of the timestamp of the first network device to the timestamp of the second network device; OFFSET represents the time deviation of the network device.

3. The method of time synchronization between network devices according to claim 2, wherein, The mapping relationship between the timestamps of the first network device and the second network device is calculated using the least squares algorithm: Obtain N sets of timestamps: first timestamp t1, second timestamp t2, third timestamp t3, and fourth timestamp t4. Calculate A and OFFSET; where A and OFFSET satisfy the following relationship with the timestamps: t1+t4=A*(t2+t3)+2*OFFSET The formula for calculating A is: wherein, represents the average of the (t1 + t4) of the N sets of timestamps; represents the average of the (t2 + t3) of the N sets of timestamps; The formula for calculating OFFSET is:

4. A system for time synchronization between network devices, implemented based on the method of any one of claims 1-3, characterized in that, The system includes a first network device and a second network device; wherein... The first network device is configured to send a request message carrying a first timestamp recorded at the outgoing port to the second network device; receive a response message carrying a first timestamp, a second timestamp, and a third timestamp from the second network device, and record a fourth timestamp at the incoming port of the response message; obtain a mapping relationship between the timestamps of the first network device and the timestamps of the second network device based on multiple sets of first timestamps, second timestamps, third timestamps, and fourth timestamps; convert the timestamps of the second network device based on the mapping relationship to obtain a mapping value of the timestamps of the second network device; and use the mapping value and the timestamps of the first network device to calculate the latency between the devices. The second network device is configured to receive a request message sent by the first network device, generate a response message with a second timestamp and a third timestamp, and send it to the first network device.

5. The time synchronization system between network devices according to claim 4, characterized in that, The first network device includes: A timestamp generator for generating local timestamps; The timed request module is used to periodically generate request messages and send them to the TX timestamp filling module; The TX timestamp filling module is used to fill the timestamp generated by the timestamp generator into the request message to be sent and send it to the TX module. The TX module is used to send request messages to the second network device; The RX module is used to receive response messages from the second network device and send them to the RX timestamp filling module. The RX timestamp filling module is used to fill the response message with the timestamp generated by the timestamp generator and send it to the timestamp parsing module. The timestamp parsing module is used to parse the input response message and output the parsed first timestamp, second timestamp, third timestamp, and fourth timestamp to the calculation module and the mapping storage module. The calculation module is used to calculate the parameters A and OFFSET of the mapping relationship and send the results to the mapping storage module; and The mapping storage module is used to calculate the time of the first network device corresponding to the timestamp of the second network device based on A and OFFSET when the timestamp of the second network device is received.