Time Synchronization Method, Device and System

By determining the device identity when the target network device is powered on, and obtaining clock level information and hop information when receiving the target synchronization message, and directly using the target synchronization message to transmit these information, the problem of complex logic of the time synchronization method in the prior art is solved, and the effect of simplifying processing logic and improving efficiency is achieved.

CN115694702BActive Publication Date: 2025-06-27MAXIO TECHNOLOGY (HANGZHOU) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211085529.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-06
Publication Date
2025-06-27
Estimated Expiration
2042-09-06

AI Technical Summary

Technical Problem

In the prior art, the time synchronization method requires a large number of packet types and packets, resulting in complex time synchronization processing logic.

Method used

By determining the device identity when the target network device is powered on, and obtaining the clock level information and hop information in the message header when the target synchronization message is received, the target synchronization message is directly used to transmit this information, reducing the message type and number and simplifying the processing logic.

Benefits of technology

Reduces the type and number of messages, simplifies the logic of time synchronization processing, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115694702B_ABST
    Figure CN115694702B_ABST
Patent Text Reader

Abstract

The present application discloses a time synchronization method, apparatus and system, belonging to the field of communications. The time synchronization method provided by the present application includes: when a target network device is powered on, determining the device identity of the target network device; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device or a slave clock device; when the device identity of the target network device is a master clock candidate device or a slave clock device, receiving a target synchronization message; when the target synchronization message is received, obtaining the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through; and performing time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of communications, and particularly relates to a time synchronization method, apparatus, and system. Background Art

[0002] In a communication network, time synchronization between various network devices can be achieved through the IEEE1588v2 protocol. The BMC (best master clock) algorithm defined by this protocol is described in detail in the IEEE1588v2 protocol. This BMC algorithm can be used to determine the best master clock device from various network devices in the communication network, so as to subsequently achieve time synchronization between various network devices based on the best master clock.

[0003] However, in the related art, the standard BMC algorithm uses packets of the announce message type to transmit clock information, and network devices perform BMC processing based on the clock information in the received announce message type packets. After the best master clock device is determined by the BMC algorithm, packets of another message type are also used for time synchronization and delay measurement of network devices to achieve time synchronization between various network devices in the communication network. The packet types and the number of packets required for the entire time synchronization method are relatively large, resulting in a relatively complex time synchronization processing logic. Summary of the Invention

[0004] The objective of the embodiments of this application is to provide a time synchronization method, apparatus, and system, which can solve the problem that the packet types and the number of packets required for the time synchronization method in the related art are relatively large, resulting in a relatively complex time synchronization processing logic.

[0005] In a first aspect, the embodiments of this application provide a time synchronization method, which is applied to a target network device and includes:

[0006] When the target network device is powered on, determine the device identity of the target network device; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device;

[0007] When the device identity of the target network device is a master clock candidate device or a slave clock device, receive a target synchronization packet;

[0008] When the target synchronization packet is received, obtain the clock level information and hop count information carried in the packet header of the target synchronization packet, where the hop count information indicates the number of hops that the target synchronization packet has passed through;

[0009] Perform time synchronization according to the clock level information and the hop count information carried in the packet header of the target synchronization packet.

[0010] In a second aspect, an embodiment of the present application provides a time synchronization device, including: a determination module, a reception module, an acquisition module, and a time synchronization module.

[0011] The determination module is configured to determine the device identity of the target network device when the target network device is powered on; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device.

[0012] The reception module is configured to receive a target synchronization message when the device identity of the target network device is a master clock candidate device or a slave clock device.

[0013] The acquisition module is configured to, when receiving the target synchronization message, acquire the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has passed through.

[0014] The time synchronization module is configured to perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.

[0015] In a third aspect, an embodiment of the present application provides a time synchronization system, including: a highest-level master clock device, a master clock candidate device, and a slave clock device.

[0016] The highest-level master clock device is configured to: generate a target synchronization message, where the target synchronization message carries the clock level information and hop count information of the highest-level master clock device, and the hop count information indicates the number of hops that the target synchronization message has passed through; send the target synchronization message.

[0017] The master clock candidate device is configured to: when receiving the target synchronization message, acquire the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has passed through; perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.

[0018] The master clock candidate device is further configured to send a first synchronization message when the target synchronization message is not received, where the first synchronization message carries the clock level information of the master clock candidate device and first hop count information, and the first hop count information indicates the number of hops that the first synchronization message has passed through.

[0019] The slave clock device is used to obtain the clock level information and hop count information carried in the header of the target synchronization message when receiving the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through; and perform time synchronization according to the clock level information and the hop count information carried in the header of the target synchronization message.

[0020] In an embodiment of the present application, when the target network device is powered on, the device identity of the target network device is determined; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device; when the device identity of the target network device is a master clock candidate device or a slave clock device, a target synchronization message is received; when the target synchronization message is received, the clock level information and hop count information carried in the header of the target synchronization message are obtained, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through; and time synchronization is performed according to the clock level information and the hop count information carried in the header of the target synchronization message. In this way, the clock level information and the hop count information are encoded in the header of the target synchronization message, and the target synchronization message is used to transmit the clock level information and the hop count information, without separately using another message to transmit the clock level information and the hop count information, reducing the message types and the number of messages, and simplifying the logic of time synchronization processing. Description of the Drawings

[0021] Figure 1 is a schematic flowchart of a time synchronization method provided by an embodiment of the present application;

[0022] Figure 2 is a schematic flowchart of steps for determining the device identity of a target network device provided by an embodiment of the present application;

[0023] Figure 3 is a schematic flowchart of another time synchronization method provided by an embodiment of the present application;

[0024] Figure 4 is a schematic flowchart of another time synchronization method provided by an embodiment of the present application;

[0025] Figure 5 is a schematic flowchart of steps for determining the first target port of a target network device provided by an embodiment of the present application;

[0026] Figure 6 is a schematic flowchart of another time synchronization method provided by an embodiment of the present application;

[0027] Figure 7 is a schematic structural diagram of a time synchronization system provided by an embodiment of the present application;

[0028] Figure 8 It is a schematic flowchart of another time synchronization method provided by an embodiment of the present application;

[0029] Figure 9 It is a schematic diagram of the synchronization message transmission path among each clock node in a time synchronization method provided by an embodiment of the present application;

[0030] Figure 10 It is a schematic diagram of the synchronization message transmission path among each clock node in another time synchronization method provided by an embodiment of the present application;

[0031] Figure 11 It is a schematic structural diagram of a time synchronization device provided by an embodiment of the present application. Detailed implementation manners

[0032] Next, the technical solutions in the embodiments of the present application will be clearly described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art belong to the scope protected by the present application.

[0033] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. generally belong to the same category, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / " generally indicates an "or" relationship between the associated objects before and after.

[0034] Next, the time synchronization method provided by the embodiments of the present application will be described in detail in conjunction with the accompanying drawings through specific embodiments and their application scenarios.

[0035] Figure 1 It is a schematic flowchart of a time synchronization method provided by an embodiment of the present application.

[0036] As Figure 1 shown, the time synchronization method provided by the embodiments of the present application, which is applied to a target network device, may include:

[0037] Step 110: When the target network device is powered on, determine the device identity of the target network device; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device;

[0038] Step 120: When the device identity of the target network device is a primary clock candidate device or a slave clock device, receive a target synchronization message.

[0039] Step 130: When the target synchronization message is received, obtain the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through.

[0040] Step 140: Perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.

[0041] In Step 110, when the hardware of the target network device is powered on, the device identity of the target network device can be determined. The time synchronization method applied to the target network device is different according to different device identities of the target network device. Among them, the device identity generally includes a highest-level primary clock device, a primary clock candidate device, or a slave clock device. The highest-level primary clock device generally sends synchronization messages to slave clock nodes as the primary clock node; the slave clock device generally receives synchronization messages sent by the primary clock node as the slave clock node; the primary clock candidate device can be used as the primary clock node or the slave clock node. When the highest-level primary clock device fails, the primary clock candidate device can send synchronization messages to slave clock nodes as the primary clock node; when the highest-level primary clock device is normal, the primary clock candidate device can receive synchronization messages sent by the primary clock node as the slave clock node.

[0042] In Step 120 and Step 130, the target synchronization message can be the sync type message information defined by the standard, or other types of message information, which is not specifically limited in this application.

[0043] It can be understood that in the related art, the standard BMC best master clock algorithm generally uses announce type messages to transmit clock information, and nodes perform best master clock processing according to the clock information in the received announce message type. For example, in the related art, separate messages (such as announce type messages) are used to transmit clock level information and hop count information. However, in the embodiments of this application, the clock level information and hop count information are directly encoded into the message header of the target synchronization message (such as the sync type message), and the target synchronization message is used to transmit the clock level information and hop count information, without the need to use a separate announce message to transmit the clock level information and hop count information, reducing the message type and the number of messages, and simplifying the logic of time synchronization processing.

[0044] In step 140, the priority of the clock level information is higher than that of the hop count information. For example, according to the clock level information and the hop count information carried in the header of the target synchronization message, the clock node with the highest clock level or the clock node with the lowest clock level can be used as the master clock to achieve time synchronization of each clock node in the local area network. Under the condition that the clock levels are the same, the clock node with the largest hop count information or the clock node with the smallest hop count information is used as the master clock to achieve time synchronization of each clock node in the local area network.

[0045] According to the time synchronization method provided by the embodiments of the present application, when receiving a target synchronization message, the clock level information and the hop count information carried in the header of the target synchronization message are obtained, and the hop count information indicates the number of hops that the target synchronization message has passed through; time synchronization is performed according to the clock level information and the hop count information carried in the header of the target synchronization message. In this way, the clock level information and the hop count information are incorporated into the header of the target synchronization message, and the target synchronization message is used to transmit the clock level information and the hop count information, without separately using another message to transmit the clock level information and the hop count information, reducing the type and number of messages and simplifying the logic of time synchronization processing.

[0046] In a specific embodiment, in order to avoid affecting other standard information carried in the target synchronization message, the header of the target synchronization message may include a first reserved field and a second reserved field, the clock level information is located in the first reserved field, and the hop count information is located in the second reserved field.

[0047] For example, the target synchronization message may be a sync message (a type of event synchronization information). The common header of the target synchronization message includes multiple reserved fields, and this solution uses the reserved fields to transmit the clock level information and the hop count information. Specifically, a reserved field can be redefined as the sCLKClass field to serve as the first reserved field for transmitting the clock level information; another reserved field can be redefined as the steps field to serve as the second reserved field for transmitting the hop count information. The following takes Table 1 and Table 2 as examples for specific description.

[0048]

[0049]

[0050] Table 1

[0051] Among them, Table 1 is the common header of the sync message defined by the IEEE 1588V2 standard. Among them, Octets represents the number of octets occupied by the field. In the common header of the sync message, the upper four bits of the second octet are the reserved field, the sixth octet is the reserved field, and the seventeenth to twentieth octets are the reserved fields.

[0052]

[0053] Table 2

[0054] Among them, Table 2 is a common header of a sync message defined in this application. Among them, the upper four bits of the second octet are defined as the sCLKClass field, which is the first reserved field for transmitting clock level information; the sixth octet is defined as the steps field, which is the second reserved field for transmitting hop count information.

[0055] Thus, the first reserved field is located in the upper four bits of the second octet in the header of the target synchronization message, and the second reserved field is located in the sixth octet in the header of the target synchronization message.

[0056] Of course, in practical applications, since in the common header of the sync message defined by the IEEE 1588V2 standard, the upper four bits of the second octet, the sixth octet, and the seventeenth to twentieth octets are all reserved fields. This application can arbitrarily select two reserved fields from the three reserved fields and redefine them as the first reserved field and the second reserved field. For example, in the common header of the sync message defined in this application, the first reserved field can also be located in the sixth octet or the seventeenth to twentieth octets, and the second reserved field can also be located in the upper four bits of the second octet or the seventeenth to twentieth octets. This application does not make specific restrictions on this.

[0057] In this way, the reserved fields in the header of the target synchronization message can be flexibly used to transmit clock level information and hop count information without affecting the standard functions of the target synchronization message.

[0058] In a specific embodiment, in order to quickly determine the device identity of the target network device, as Figure 2 shown, in step 110 above, when the target network device is powered on, determining the device identity of the target network device may specifically include:

[0059] Step 1101: When the target network device is powered on, obtain the clock encoding of the target network device;

[0060] Step 1102: Determine the device identity of the target network device based on the clock encoding, where the device identity includes a highest-level master clock device, a master clock candidate device, or a slave clock device; among them, the clock encodings corresponding to the highest-level master clock device, the master clock candidate device, and the slave clock device are all different.

[0061] In the embodiments of the present application, in order to shorten the time required to determine the device identity of the target network device, the clock encoding of the target network device can be determined based on the power-on state of the target network device when the hardware of the target network device is powered on.

[0062] It can be understood that in the related art, complex BMC algorithms often require the participation of the CPU. After the CPU is powered on, from booting the operating system, importing application software, and finally the BMC algorithm runs, at least several seconds have passed.

[0063] However, in the embodiments of the present application, the clock encoding of the target network device can be directly determined according to the power-on state of the target network device, shortening the time required to determine the device identity of the target network device. The following is a specific description.

[0064] In practical applications, a clock encoding detection component can be set on the target network device; in step 1101 above, when the target network device is powered on, obtaining the clock encoding of the target network device can specifically include:

[0065] When the target network device is powered on, determine the power-on state of the clock encoding detection component;

[0066] Determine the clock encoding of the target network device according to the power-on state of the clock encoding detection component.

[0067] Among them, the corresponding relationship between the power-on state of the clock encoding detection component when the hardware of the target network device is powered on and the clock encoding of the target network device can be preset in advance. When the target network device is powered on, detect the power-on state of the clock encoding detection component; determine the clock encoding of the target network device through the power-on state of the clock encoding detection component and the preset corresponding relationship between the power-on state of the clock encoding detection component and the clock encoding of the target network device.

[0068] Among them, the correspondence between the clock encoding of the target network device and the clock level of the target network device can be preset. After obtaining the clock encoding of the target network device, the clock level of the target network device is determined according to the clock encoding of the target network device and the correspondence between the clock encoding of the target network device and the clock level of the target network device. Furthermore, the device identity of the target network device can be determined according to the clock level of the target network device. Among them, the clock level of the slave clock device < the clock level of the primary clock candidate device < the clock level of the highest-level primary clock device. The clock level of the slave clock device is the lowest, and the clock level of the highest-level primary clock device is the highest.

[0069] Alternatively, the correspondence between the clock encoding of the target network device and the device identity of the target network device can be preset. After obtaining the clock encoding of the target network device, the device identity of the target network device is determined according to the clock encoding of the target network device and the correspondence between the clock encoding of the target network device and the device identity of the target network device.

[0070] In this way, when the target network device is powered on, the device identity of the target network device is directly determined by the clock encoding corresponding to the power-on state of the clock encoding detection component, without determining the device identity of the target network device by the target network device receiving and sending messages, which improves the efficiency of determining the device identity of the target network device.

[0071] Moreover, the clock encoding detection component can include at least one of the following: a chip, an input module, and an output module. Among them, the clock encoding detection component can be a chip, an input module, or an output module originally existing in the target network device. In this application, the clock encoding of the target network device can be determined by reusing the chip, input module, or output module originally existing in the target network device; there is no need to add new hardware to the target network device as the clock encoding detection component, so that the target network device can determine the clock encoding of the target network device through the power-on state of the originally existing chip, input module, or output module.

[0072] For example, in the embodiment of the present application, a first pin Pin1 and a second pin Pin2 are provided on the clock encoding detection component of the target network device; in step 1101 above, when the target network device is powered on, obtaining the clock encoding of the target network device may specifically include:

[0073] When the target network device is powered on, determine the pin encoding of the first pin and the pin encoding of the second pin;

[0074] Combine the pin encoding of the first pin and the pin encoding of the second pin to obtain the clock encoding of the target network device.

[0075] Among them, the first pin has a first state, a second state, and a third state, and the second pin has a first state, a second state, and a third state; each of the first state, the second state, and the third state corresponds to a pin code, and different states correspond to different pin codes;

[0076] The first state is the pull-up state, the second state is the non-pull state, and the third state is the pull-down state. Each state corresponds to two binary digits, and the clock code of the target network device is four binary digits. The following takes Table 3 as an example for illustration.

[0077] Table 3 is a configuration table of the hardware power-on state and device identity of a target network device.

[0078]

[0079] Table 3

[0080] As shown in Table 3, the pin code of the pull-up state of the first pin Pin1 is 11, the pin code of the pull-down state is 10, and the pin code of the non-pull state is 00. The pin code of the pull-up state of the second pin Pin2 is 11, the pin code of the pull-down state is 10, and the pin code of the non-pull state is 00.

[0081] In Table 3, the clock code of the target network device can be obtained by combining the pin code of the first pin and the pin code of the second pin. Among them, the combination method can be to directly piece together the pin code of the first pin (corresponding to two binary digits) and the pin code of the second pin (corresponding to two binary digits) to obtain four binary digits as the clock code of the target network device.

[0082] Of course, the above coding method is only an example and does not mean a limitation. The pin code of the first pin is not limited to two binary digits, and can also be three binary digits, four binary digits, etc.; the pin code of the second pin is not limited to two binary digits, and can also be three binary digits, four binary digits, etc.; the clock code of the target network device is not limited to four binary digits, and can also be five binary digits, six binary digits, etc.; the combination method of the pin code of the first pin and the pin code of the second pin is not limited to direct piecing together, and can also be arithmetic operations such as addition and subtraction. This application does not make specific limitations.

[0083] In this way, by detecting the states of the first pin and the second pin set on the target network device when the target network device is powered on, the pin code of the first pin and the pin code of the second pin can be determined, so as to quickly determine the clock code of the target network device.

[0084] Of course, in the embodiments of the present application, the power-on state of the clock encoding detection component can be represented not only by the pin states of the two pins set on the clock encoding detection component mentioned above, but also by other states such as the voltage state, temperature state, and pressure state of other components in the clock encoding detection component. The present application does not make specific limitations here.

[0085] As mentioned above, the device identity of the target network device is determined. In the embodiments of the present application, different device identities of the target network device result in different clock synchronization methods executed by the target network device. Among them, the device identity of the target network device may include a primary clock candidate device, a slave clock device, or a highest-level primary clock device. Moreover, the primary clock candidate device can be used as the primary clock node or the slave clock node under different circumstances, the slave clock device can be used as the slave clock node, and the highest-level primary clock device can be used as the primary clock node. Examples are given below respectively.

[0086] The first case: The target network device is a primary clock candidate device, and the primary clock candidate device is used as the primary clock node.

[0087] As Figure 3 shown, when the target network device is a primary clock candidate device and the primary clock candidate device is used as the primary clock node, the time synchronization method provided by the embodiments of the present application is applied to the primary clock candidate device, and the method may include:

[0088] Step 310: When the target network device is powered on, determine the device identity of the target network device; the device identity of the target network device is a primary clock candidate device;

[0089] Step 320: When the device identity of the target network device is a primary clock candidate device, receive a target synchronization message;

[0090] Step 330: Determine whether the target network device has received the target synchronization message;

[0091] Step 340: When the target synchronization message has not been received, send a first synchronization message, where the first synchronization message carries the clock level information and the first hop count information of the target network device, and the first hop count information indicates the number of hops passed by the first synchronization message.

[0092] Among them, the first synchronization message can be a synchronization message generated by the target network device. The first hop count information indicating the number of hops passed by the first synchronization message is generally 0.

[0093] Step 350: When the target synchronization message has been received, obtain the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops passed by the target synchronization message;

[0094] Step 360: When receiving the target synchronization message, compare the clock level information carried in the message header of the target synchronization message with the local clock level information;

[0095] Step 370: When the local clock level information is higher than the clock level information, send a first synchronization message, where the first synchronization message carries the clock level information of the target network device and the first hop count information, and the first hop count information indicates the number of hops through which the first synchronization message is transmitted.

[0096] Among them, the first synchronization message may be a synchronization message generated by the target network device, and the specific content of the first synchronization message in Step 370 may be the same as that of the first synchronization message in Step 340. The first hop count information indicates that the number of hops through which the first synchronization message is transmitted is generally 0.

[0097] Among them, the above Step 310 may refer to the specific content of Step 110; the above Step 320 may refer to the specific content of Step 120, and the above Step 350 may refer to the specific content of Step 130; the above Step 360 and the above Step 370 may be sub-steps of Step 140.

[0098] Among them, when the target network device is the master clock candidate device: when the target synchronization message is not received, the target network device may act as the master clock, generate the first synchronization message and send the first synchronization message to the slave clock. When the target synchronization message is received, if the local clock level information of the target network device is higher than the clock level information carried in the received target synchronization message, the target network device may act as the master clock, generate the first synchronization message and send the first synchronization message to the slave clock.

[0099] In this way, after determining the device identity of the target network device, when the target network device is the master clock candidate device, and when the target network device does not receive the target synchronization message or the local clock level information is higher than the clock level information carried in the received target synchronization message when the target synchronization message is received, the target network device may be used as the master clock, and the first synchronization message is sent to the slave clock node network-connected to the target network device to achieve time synchronization of the local area network.

[0100] The second case: the target network device is the master clock candidate device and the master clock candidate device acts as the slave clock node; or, the target network device is the slave clock device.

[0101] In the embodiments of the present application, the number of target synchronization messages may be multiple.

[0102] Such as Figure 4As shown, when the target network device is the master clock candidate device, the time synchronization method provided by the embodiments of the present application may include:

[0103] Step 410: When the target network device is powered on, determine the device identity of the target network device; the device identity of the target network device is the master clock candidate device or the slave clock device;

[0104] Step 420: Receive multiple target synchronization messages through each port of the target network device;

[0105] Step 430: When a target synchronization message is received, obtain the clock level information and hop count information carried in the message header of the target synchronization message, and the hop count information indicates the number of hops that the target synchronization message has passed through;

[0106] Step 440: When the target network device is the master clock candidate device and the local clock level information of the target network device is not higher than the clock level information carried in the target synchronization message, or when the target network device is the slave clock device, based on the clock level information and hop count information carried in the message headers of the respective target synchronization messages in the multiple target synchronization messages, determine the first target port of the target network device;

[0107] Among them, the first target port may be a slave port (i.e., a Slave port).

[0108] Step 450: Based on the first target port of the target network device, determine the second target port of the target network device;

[0109] Among them, the second target port may be a master port (i.e., a Master port).

[0110] Step 460: Send a second synchronization message through the second target port, where the second synchronization message carries target clock level information and second hop count information, and the value of the second hop count information is equal to the target hop count information plus one; among them, the target clock level information is the clock level information carried in the message header of the specified message, the target hop count information is the hop count information carried in the message header of the specified message, and the specified message is the target synchronization message with the highest clock level information carried in the message headers of the respective target synchronization messages in the multiple target synchronization messages.

[0111] Among them, the specific content of the above step 410 may refer to the specific content of step 110; the above step 420 may be a sub-step of step 120, and the above step 430 may refer to the specific content of step 130; the above steps 440, 450, and 460 may be sub-steps of step 140.

[0112] It can be understood that in step 460, when there is a specified message among multiple target synchronization messages, the target hop count information is the hop count information carried in the message header of this specified message; when there are multiple specified messages among multiple target synchronization messages, the target hop count information is the lowest hop count among the hop count information carried in the message headers of multiple specified messages.

[0113] In this way, when the target network device is a primary clock candidate device and the local clock level information of the target network device is not higher than the clock level information carried in the target synchronization message, or when the target network device is a slave clock device, the target network device can be used as a slave clock node and send a second synchronization message through the second target port to achieve time synchronization of the local area network.

[0114] In the embodiment of the present application, during the process of determining the first target port of the target network device, the priority of the clock level information is higher than the priority of the hop count information. As Figure 5 shown, the above step 440 may specifically include:

[0115] Step 4401: Determine the highest clock level among the clock level information carried in the message headers of each target synchronization message;

[0116] Step 4402: When there is a target synchronization message whose message header carries the highest clock level among the multiple target synchronization messages, determine the port that receives the target synchronization message carrying the highest clock level as the first target port of the target network device;

[0117] Step 4403: When there are multiple target synchronization messages whose message headers all carry the highest clock level among the multiple target synchronization messages, determine the lowest hop count among the hop count information carried in the message headers of each target synchronization message; when there is a unique target synchronization message with the lowest hop count among the multiple target synchronization messages carrying the highest clock level, determine the port that receives the target synchronization message carrying the highest clock level and the lowest hop count as the first target port of the target network device.

[0118] In this way, during the process of determining the first target port of the target network device based on the clock level information and hop count information carried in the message headers of each target synchronization message among multiple target synchronization messages, the priority of the clock level information is higher than the priority of the hop count information. The first target port of the target network device can be determined preferentially according to the clock level carried in the target synchronization message. Under the condition of the same clock level, the first target port of the target network device is determined according to the hop count information carried in the target synchronization message.

[0119] In addition, in the embodiments of the present application, during the process of determining the first target port of the target network device, the first target port of the target network device can also be determined by the port number. Among them, the priority of the clock level information is higher than the priority of the hop count information which is higher than the priority of the port number.

[0120] As Figure 5 shown, the above step 440 may specifically further include:

[0121] Step 4404: When there are multiple target synchronization messages in the multiple target synchronization messages and both the highest clock level and the lowest hop count are carried in the message headers of the multiple target synchronization messages, determine the multiple port numbers of the target synchronization messages that receive the highest clock level and the lowest hop count;

[0122] Step 4405: Determine the port with the smallest or largest number value among the multiple port numbers as the first target port of the target network device.

[0123] In this way, during the process of determining the first target port of the target network device based on the clock level information and hop count information carried in the message headers of each target synchronization message among the multiple target synchronization messages and the multiple port numbers of the received target synchronization messages, the priority of the clock level information is higher than the priority of the hop count information which is higher than the priority of the port number. Under the same conditions of the clock level and hop count information, the first target port of the target network device is determined according to the port number carried in the received target synchronization message.

[0124] In addition, after determining the first target port, other ports of the target network device are in a passive state. In the case of a failure of the first target port, a new first target port can also be determined from the passive ports to implement the protection switching function.

[0125] The third case: The target network device is the highest-level master clock device.

[0126] As Figure 6 shown, the embodiments of the present application provide a time synchronization method applied to the highest-level master clock device, which may further include:

[0127] Step 610: When the device identity of the target network device is the highest-level master clock device, generate a target synchronization message, and the target synchronization message carries the clock level information and hop count information of the target network device, and the hop count information indicates the number of hops that the target synchronization message is transmitted through;

[0128] Step 620: Send the target synchronization message.

[0129] In step 610, the hop count information indicates that the number of hops that the target synchronization message is transmitted through is generally 0.

[0130] In step 620, the highest-level master clock device may send a target synchronization message to other master clock candidate devices or slave clock devices in the time synchronization system, enabling the master clock candidate devices or slave clock devices to receive the target synchronization message and perform time synchronization. In this way, when the device identity of the target network device is the highest-level master clock device, the target synchronization message is used to transmit the clock level information and hop count information, eliminating the need to separately use the announce message to transmit the clock level information and hop count information, reducing the number of message types and messages, and simplifying the logic of time synchronization processing.

[0131] In practical applications, the above-mentioned highest-level master clock device, master clock candidate device, and slave clock device may be different clock nodes in the same time synchronization system.

[0132] As Figure 7 shown, an embodiment of the present application provides a time synchronization system, including: a highest-level master clock device 701, a master clock candidate device 702, and a slave clock device 703.

[0133] As Figure 7 shown, the highest-level master clock device 701 may communicate with the master clock candidate device 702 and the slave clock device 703; the master clock candidate device 702 may communicate with the highest-level master clock device 701 and the slave clock device 703; the slave clock device 703 may communicate with the highest-level master clock device 701, the master clock candidate device 702, or other slave clock devices.

[0134] Of course, the communication connection manner between the highest-level master clock device 701, the master clock candidate device 702, and the slave clock device 703 in the time synchronization system is not limited to Figure 7 the manner shown, and may also be other manners, which are not specifically limited in this application.

[0135] Among them, the highest-level master clock device 701 is used to: generate a target synchronization message, where the target synchronization message carries the clock level information and hop count information of the highest-level master clock device, and the hop count information indicates the number of hops that the target synchronization message has passed through; send the target synchronization message;

[0136] The master clock candidate device 702 is used to: when receiving the target synchronization message, obtain the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has passed through; perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message;

[0137] The master clock candidate device 702 is also used to send a first synchronization message when the target synchronization message is not received. The first synchronization message carries the clock level information of the master clock candidate device and the first hop count information, and the first hop count information indicates the number of hops through which the first synchronization message is transmitted.

[0138] The slave clock device 703 is used to obtain the clock level information and hop count information carried in the message header of the target synchronization message when the target synchronization message is received. The hop count information indicates the number of hops through which the target synchronization message is transmitted; and perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.

[0139] In this way, in the time synchronization system, the target synchronization message is used to transmit the clock level information and hop count information between each clock node, eliminating the need to separately use the announce message to transmit the clock level information and hop count information, reducing the number of message types and messages, and simplifying the logic of time synchronization processing. The following is an example of the time synchronization method for a single clock node in the time synchronization system.

[0140] As Figure 8 shown, for a single clock node in the time synchronization system, an embodiment of the present application provides a time synchronization method, which may include:

[0141] Step 810: After the clock node is powered on, obtain the local clock level of the clock node according to the hardware state of the clock node, and determine the device identity of the clock node; wherein, the device identity of the clock node includes: the highest-level master clock device, the master clock candidate device, or the slave clock device.

[0142] Among them, in the time synchronization system, in order to maintain strong robustness of the time synchronization system, there are at least two communication paths reachable between two clock nodes. In the case where one path fails in the two communication paths, the clock node can quickly switch to the other path for communication.

[0143] Among them, in the time synchronization system, in order to maintain strong robustness of the time synchronization system, the clock nodes in the time synchronization system may include master clock candidate devices. In the case where the highest-level master clock device fails, the master clock candidate device can act as the master clock node. In other words, the master clock candidate device can be used as the master clock node to send synchronization messages to the slave clock nodes.

[0144] In step 810, if it is determined that the clock node is the highest-level master clock device, step 820 can be executed.

[0145] In step 810, if it is determined that the clock node is the master clock candidate device, step 830 can be executed.

[0146] In step 810, if it is determined that the clock node is a slave clock device, steps 860 and 870 can be executed.

[0147] Step 820: When the clock node is the highest-level master clock device, generate a synchronization message and send the synchronization message, where the synchronization message carries the synchronization information (sCLKClass, steps) of the local clock; among them, sCLKClass is the highest clock level code 0XF, and steps is 0.

[0148] Step 830: When the clock node is a master clock candidate device, after power-on, detect whether the clock node receives a synchronization message (sCLKClass, steps) sent by other nodes.

[0149] In step 830, in order to reduce the convergence time of time synchronization to eliminate unnecessary oscillations, embodiments of the present application can specify that the local clock level code values set by two or more master clock candidate devices are different.

[0150] In step 830, if the clock node does not receive a synchronization message, the clock node is taken as the master clock, and step 840 can be executed.

[0151] In step 830, if the clock node receives a synchronization message, step 850 can be executed.

[0152] Step 840: Generate a synchronization message and send the synchronization message, where the synchronization message carries the synchronization information (sCLKClass, steps) of the local clock. Among them, sCLKClass is the local clock level code, and steps is 0.

[0153] Step 850: Compare the size of the local sCLKClass and the sCLKClass value in the received synchronization message to determine whether the clock node itself is the master clock or the slave clock.

[0154] In step 850, when the clock node is a master clock candidate device, if the local sCLKClass value is less than the sCLKClass value in the received synchronization message, the clock node can be taken as the slave clock. And steps 860 and 870 are executed in sequence.

[0155] In step 850, when the clock node is a master clock candidate device, if the local sCLKClass value is higher than the sCLKClass value in the received synchronization message, the clock node can be taken as the master clock, and step 840 can be executed.

[0156] Step 860: Receive the synchronization message (sCLKClass, steps) sent by other nodes, and determine the slave port and master port of the clock node.

[0157] Step 870: Further send the synchronization message (sCLKClass, steps + 1) to other nodes through the master port.

[0158] The following is an example in combination with the specific application scenarios of each clock node in the local area network.

[0159] Such as Figure 9 and Figure 10 As shown, the clock of node N1 is designed as the highest-level clock (clock level is 0XF), the clock of node N6 is designed as the master clock candidate (clock level is 0XE), and the clocks of the remaining nodes are designed as slave clocks (clock level is 0X8). Using the method described in this application, the paths of the synchronization message information received and sent by all clock nodes at last are as shown by the dotted line in Figure 9 The dash-dotted line represents the synchronization information (sCLKClass, steps) adopted by the receiving party, and the dotted line represents the synchronization information (sCLKClass, steps) discarded by the receiving party.

[0160] Such as Figure 9 As shown, when the clock of node N1 is normal, the clock of node N1 is the highest-level master clock device. After node N1 is powered on, it will not accept the synchronization information sent by other nodes in the network. The local information of node N1 sent to N2 / N3 / N6 is (0XF, 0). After N2 / N3 / N6 receive it, they compare the local clock level sCLKClass value, which is lower than the received sCLKClass value (i.e., 0XF). N2 / N3 / N6 transfer (0XF, 1) to other ports, indicating that one hop has been experienced during the synchronization information transfer process. Node N4 will receive (0XF, 1) from N6 and N2. At this time, the port number of N4 will be added to the selection condition of the slave port. The P1 port number of N4 is small, so the P1 port of N4 is selected as the slave port. Further analysis shows that node N5 receives the synchronization information sent by node N6; node N7 receives the synchronization information sent by node N6.

[0161] Such as Figure 10 As shown, when node N1 fails, all slave clock nodes are waiting for the port to receive new synchronization information. In this example, node N6 is the master clock candidate device. When node N6 times out without receiving the synchronization information from node N1, node N6 acts as the master clock and actively generates a synchronization message to send the synchronization information to other clock nodes.

[0162] In addition, if there are multiple ports on the slave node that can receive the synchronization information of the master clock, a slave port for receiving the synchronization information of the master clock will be selected according to a preset rule. Other ports may enter the passive state. When the slave port cannot receive the synchronization information of the master clock normally, a port can be selected from the passive ports as a new slave port to implement the function of protection switching.

[0163] It should be noted that for the time synchronization method provided in the embodiments of the present application, the execution entity can be a time synchronization device, or a control module in the time synchronization device for executing the time synchronization method. In the embodiments of the present application, the case where the time synchronization device executes the time synchronization method is taken as an example to illustrate the time synchronization device provided in the embodiments of the present application.

[0164] Figure 11 It is a schematic structural diagram of a time synchronization device provided in the embodiments of the present application.

[0165] As Figure 11 shown, the time synchronization device 1100 provided in the embodiments of the present application may include:

[0166] a determination module 1101, a reception module 1102, an acquisition module 1103, and a time synchronization module 1104,

[0167] The determination module 1101 is configured to determine the device identity of the target network device when the target network device is powered on; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device;

[0168] The reception module 1102 is configured to receive a target synchronization message when the device identity of the target network device is a master clock candidate device or a slave clock device;

[0169] The acquisition module 1103 is configured to, when receiving a target synchronization message, acquire the clock level information and hop count information carried in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has passed through;

[0170] The time synchronization module 1104 is configured to perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message.

[0171] In the time synchronization device provided by the embodiment of the present application, the determination module is used to determine the device identity of the target network device when the target network device is powered on; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device; the receiving module is used to receive a target synchronization message when the device identity of the target network device is a master clock candidate device or a slave clock device; the obtaining module is used to obtain the clock level information and hop count information carried in the message header of the target synchronization message when the target synchronization message is received, and the hop count information indicates the number of hops that the target synchronization message has passed through; the time synchronization module is used to perform time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message. In this way, the clock level information and the hop count information are incorporated into the message header of the target synchronization message, and the target synchronization message is used to transmit the clock level information and the hop count information, without using separate messages to transmit the clock level information and the hop count information, reducing the message types and the number of messages, and simplifying the logic of time synchronization processing.

[0172] Optionally, in the time synchronization device provided by the embodiment of the present application, the message header of the target synchronization message includes a first reserved field and a second reserved field, the clock level information is located in the first reserved field, and the hop count information is located in the second reserved field.

[0173] Among them, the first reserved field is located in the high four bits of the second octet in the message header of the target synchronization message, and the second reserved field is located in the sixth octet in the message header of the target synchronization message;

[0174] Among them, the target synchronization message is a sync message.

[0175] In this way, the reserved fields in the message header of the target synchronization message can be flexibly used to transmit the clock level information and the hop count information without affecting the standard functions of the target synchronization message.

[0176] Optionally, in the time synchronization device provided by the embodiment of the present application, the determination module specifically includes:

[0177] A clock code obtaining module, which is used to obtain the clock code of the target network device when the target network device is powered on;

[0178] A device identity determination module, which is used to determine the device identity of the target network device based on the clock code, and the device identity includes a highest-level master clock device, a master clock candidate device, or a slave clock device;

[0179] Among them, the clock codes corresponding to the highest-level master clock device, the clock codes corresponding to the master clock candidate devices, and the clock codes corresponding to the slave clock devices are all different.

[0180] A clock code detection component is provided on the target network device; the clock code acquisition module is specifically configured to:

[0181] When the target network device is powered on, determine the power-on state of the clock code detection component;

[0182] According to the power-on state of the clock code detection component, determine the clock code of the target network device.

[0183] In this way, when the target network device is powered on hardware, the device identity of the target network device is directly determined by the clock code corresponding to the power-on state of the clock code detection component, without determining the device identity of the target network device by the target network device sending and receiving packets, improving the efficiency of determining the device identity of the target network device.

[0184] Optionally, in the time synchronization device provided in the embodiments of the present application, a first pin and a second pin are provided on the clock code detection component of the target network device;

[0185] The clock code acquisition module specifically includes:

[0186] A pin code acquisition module, configured to determine the pin code of the first pin and the pin code of the second pin when the target network device is powered on;

[0187] A clock code determination module, configured to combine the pin code of the first pin and the pin code of the second pin to obtain the clock code of the target network device.

[0188] Among them, the first pin has a first state, a second state, and a third state, and the second pin has a first state, a second state, and a third state; each of the first state, the second state, and the third state corresponds to a pin code, and different states correspond to different pin codes.

[0189] Among them, the first state is the pull-up state, the second state is the non-pull state, and the third state is the pull-down state. Each state corresponds to two binary bits, and the clock code of the target network device is four binary bits.

[0190] In this way, by detecting the states of the first pin and the second pin provided on the target network device when the target network device is powered on hardware, the pin code of the first pin and the pin code of the second pin can be determined, so as to quickly determine the clock code of the target network device.

[0191] Optionally, in the time synchronization device provided in the embodiments of the present application, the target network device is a primary clock candidate device, and the time synchronization device further includes:

[0192] A first sending module, configured to send a first synchronization message when the target synchronization message is not received, where the first synchronization message carries the clock level information of the target network device and the first hop count information, and the first hop count information indicates the number of hops passed by the first synchronization message.

[0193] In this way, after determining the device identity of the target network device, when the target network device is a primary clock candidate device and the target network device does not receive the target synchronization message, the target network device can be used as the primary clock to send a first synchronization message to the slave clock nodes network - connected to the target network device, so as to achieve time synchronization of the local area network.

[0194] Optionally, in the time synchronization device provided in the embodiments of the present application, the target network device is a primary clock candidate device, and the time synchronization module includes a comparison module and a second sending module;

[0195] The comparison module is configured to compare the clock level information carried in the message header of the target synchronization message with the local clock level information;

[0196] The second sending module is configured to send a first synchronization message when the local clock level information is higher than the clock level information, where the first synchronization message carries the clock level information of the target network device and the first hop count information, and the first hop count information indicates the number of hops passed by the first synchronization message.

[0197] In this way, after determining the device identity of the target network device, when the target network device is a primary clock candidate device and the local clock level information is higher than the clock level information carried in the received target synchronization message when the target network device receives the target synchronization message, the target network device can be used as the primary clock to send a first synchronization message to the slave clock nodes network - connected to the target network device, so as to achieve time synchronization of the local area network.

[0198] Optionally, in the time synchronization device provided in the embodiments of the present application, the number of the target synchronization messages is multiple;

[0199] The receiving module is specifically configured to receive multiple target synchronization messages through each port of the target network device;

[0200] The time synchronization module further includes:

[0201] The first port determination module is configured to determine a first target port of the target network device based on the clock level information and hop count information carried in the packet headers of the respective target synchronization packets among the multiple target synchronization packets when the target network device is a master clock candidate device and the local clock level information of the target network device is not higher than the clock level information carried in the target synchronization packet, or when the target network device is a slave clock device;

[0202] The second port determination module is configured to determine a second target port of the target network device based on the first target port of the target network device;

[0203] The sending module is configured to send a second synchronization packet through the second target port, where the second synchronization packet carries target clock level information and a second hop count information, and the value of the second hop count information is equal to the target hop count information plus one;

[0204] Wherein, the target clock level information is the clock level information carried in the packet header of a specified packet, the target hop count information is the hop count information carried in the packet header of the specified packet, and the specified packet is the target synchronization packet with the highest clock level information carried in the packet headers of the respective target synchronization packets among the multiple target synchronization packets.

[0205] In this way, when the target network device is a master clock candidate device and the local clock level information of the target network device is not higher than the clock level information carried in the target synchronization packet, or when the target network device is a slave clock device, the target network device can act as a slave clock and send a second synchronization packet through the second target port to achieve time synchronization in the local area network.

[0206] Optionally, in the time synchronization device provided in the embodiments of the present application, the first port determination module is specifically configured to:

[0207] Determine the highest clock level among the clock level information carried in the packet headers of the respective target synchronization packets;

[0208] When there is a target synchronization packet among the multiple target synchronization packets whose packet header carries the highest clock level, determine the port that receives the target synchronization packet carrying the highest clock level as the first target port of the target network device;

[0209] When the highest clock level is carried in the headers of multiple target synchronization messages among the multiple target synchronization messages, determine the lowest hop count in the hop count information carried in the headers of each target synchronization message; when there is a unique target synchronization message carrying the lowest hop count among the multiple target synchronization messages carrying the highest clock level, determine the port that receives the target synchronization message carrying the highest clock level and the lowest hop count as the first target port of the target network device.

[0210] In this way, in the process of determining the first target port of the target network device based on the clock level information and hop count information carried in the headers of each target synchronization message among the multiple target synchronization messages, the priority of the clock level information is higher than that of the hop count information. The first target port of the target network device can be determined preferentially according to the clock level carried in the target synchronization message. Under the condition of the same clock level, the first target port of the target network device is determined according to the hop count information carried in the target synchronization message.

[0211] Optionally, in the time synchronization device provided in the embodiments of the present application, the first port determination module is specifically configured to:

[0212] When there are multiple target synchronization messages among the multiple target synchronization messages whose headers carry both the highest clock level and the lowest hop count, determine the multiple port numbers of the ports that receive the target synchronization messages carrying the highest clock level and the lowest hop count;

[0213] Determine the port with the smallest or largest number value among the multiple port numbers as the first target port of the target network device.

[0214] In this way, in the process of determining the first target port of the target network device based on the clock level information, hop count information carried in the headers of each target synchronization message among the multiple target synchronization messages and the multiple port numbers of the received target synchronization messages, the priority of the clock level information is higher than that of the hop count information which is higher than that of the port number. Under the condition of the same clock level and hop count information, the first target port of the target network device is determined according to the port number carried in the received target synchronization message.

[0215] Optionally, in the time synchronization device provided in the embodiments of the present application, the time synchronization device further includes:

[0216] A generation module, configured to generate a target synchronization message when the device identity of the target network device is the highest-level master clock device, where the target synchronization message carries the clock level information and hop count information of the target network device, and the hop count information indicates the number of hops that the target synchronization message is transmitted through;

[0217] A sending module, configured to send the target synchronization message.

[0218] In this way, when the device identity of the target network device is the highest-level master clock device, the target synchronization message is used to transmit the clock level information and hop count information, without separately using the announce message to transmit the clock level information and hop count information, reducing the message types and the number of messages, and simplifying the logic of time synchronization processing.

[0219] The time synchronization device in the embodiments of the present application may be a device, or a component, an integrated circuit, or a chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device may be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device may be a server, a Network Attached Storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.

[0220] The time synchronization device in the embodiments of the present application may be a device with an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.

[0221] The time synchronization device provided in the embodiments of the present application can implement each process implemented in the above method embodiments. To avoid repetition, it will not be described in detail here.

[0222] Optionally, the embodiments of the present application further provide an electronic device, including a processor, a memory, and a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, it implements each process in the above method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described in detail here.

[0223] It should be noted that the electronic device in the embodiments of the present application includes the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0224] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described in detail here.

[0225] Wherein, the processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.

[0226] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0227] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal (which may be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application.

[0228] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them fall within the protection scope of the present application.

Claims

1. A time synchronization method, characterized in that, Applied to a target network device, including: When the target network device is powered on, determining the device identity of the target network device through the clock encoding corresponding to the powered-on state of the clock encoding detection component; the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device; When the device identity of the target network device is a master clock candidate device or a slave clock device, receiving a target synchronization message; When the target synchronization message is received, obtaining the clock level information and hop count information carried in the reserved field in the message header of the target synchronization message, where the hop count information indicates the number of hops the target synchronization message has been transmitted through; Performing time synchronization according to the clock level information and the hop count information carried in the reserved field in the message header of the target synchronization message; When the device identity of the target network device is a master clock candidate device and the master clock candidate device does not receive the target synchronization message, the master clock candidate device acts as the master clock, generates a first synchronization message, and sends the first synchronization message.

2. The time synchronization method according to claim 1, wherein The message header of the target synchronization message includes a first reserved field and a second reserved field, the clock level information is located in the first reserved field, and the hop count information is located in the second reserved field; The first reserved field is located in the upper four bits of the second octet in the message header of the target synchronization message, and the second reserved field is located in the sixth octet in the message header of the target synchronization message; Among them, the target synchronization message is a sync message.

3. The time synchronization method according to claim 1, wherein The determining the device identity of the target network device through the clock encoding corresponding to the powered-on state of the clock encoding detection component when the target network device is powered on includes: When the target network device is powered on, obtaining the clock encoding of the target network device; Based on the clock encoding, determining the device identity of the target network device, where the device identity of the target network device includes a highest-level master clock device, a master clock candidate device, or a slave clock device; Among them, the clock encodings corresponding to the highest-level master clock device, the master clock candidate device, and the slave clock device are all different.

4. The time synchronization method according to claim 3, wherein A clock encoding detection component is provided on the target network device; The obtaining the clock encoding of the target network device when the target network device is powered on includes: When the target network device is powered on, determining the powered-on state of the clock encoding detection component; According to the powered-on state of the clock encoding detection component, determining the clock encoding of the target network device.

5. The time synchronization method according to claim 4, wherein A first pin and a second pin are provided on the clock encoding detection component of the target network device; The obtaining the clock encoding of the target network device when the target network device is powered on includes: When the target network device is powered on, determining the pin encoding of the first pin and the pin encoding of the second pin; Combining the pin encoding of the first pin and the pin encoding of the second pin to obtain the clock encoding of the target network device.

6. The time synchronization method according to claim 5, wherein Among them, The first pin has a first state, a second state, and a third state, and the second pin has a first state, a second state, and a third state; each of the first state, the second state, and the third state corresponds to a pin code, and different states correspond to different pin codes; The first state is a pull-up state, the second state is a non-pull state, and the third state is a pull-down state. Each state corresponds to two binary bits, and the clock code of the target network device is four binary bits.

7. The time synchronization method according to claim 1, wherein The first synchronization message carries the clock level information and the first hop count information of the target network device, and the first hop count information indicates the number of hops through which the first synchronization message is transmitted.

8. The time synchronization method according to claim 1, characterized in that, The target network device is a primary clock candidate device. The time synchronization according to the clock level information and the hop count information carried in the reserved field in the message header of the target synchronization message includes: Comparing the clock level information carried in the message header of the target synchronization message with the local clock level information; When the local clock level information is higher than the clock level information, sending a first synchronization message, where the first synchronization message carries the clock level information and the first hop count information of the target network device, and the first hop count information indicates the number of hops through which the first synchronization message is transmitted.

9. The time synchronization method according to claim 1, wherein The number of the target synchronization messages is multiple; Receiving the target synchronization message includes: receiving multiple target synchronization messages through each port of the target network device; When the target network device is a primary clock candidate device and the local clock level information of the target network device is not higher than the clock level information carried in the target synchronization message, or when the target network device is a slave clock device, the time synchronization according to the clock level information and the hop count information carried in the message header of the target synchronization message includes: Determining a first target port of the target network device based on the clock level information and the hop count information carried in the message headers of the respective target synchronization messages among the multiple target synchronization messages; Determining a second target port of the target network device based on the first target port of the target network device; Sending a second synchronization message through the second target port, where the second synchronization message carries target clock level information and a second hop count information, and the second hop count information is equal to the target hop count information plus one; Wherein, the target clock level information is the clock level information carried in the message header of a specified message, the target hop count information is the hop count information carried in the message header of the specified message, and the specified message is the target synchronization message with the highest clock level information carried in the message headers of the respective target synchronization messages among the multiple target synchronization messages.

10. The time synchronization method according to claim 9, wherein The determining a first target port of the target network device based on the clock level information and the hop count information carried in the message headers of the respective target synchronization messages among the multiple target synchronization messages includes: Determining the highest clock level among the clock level information carried in the message headers of the respective target synchronization messages; When there is a target synchronization message among the multiple target synchronization messages whose message header carries the highest clock level, the port that receives the target synchronization message carrying the highest clock level is determined as the first target port of the target network device; When there are multiple target synchronization messages among the multiple target synchronization messages whose message headers all carry the highest clock level, determine the lowest hop count among the hop count information carried in the message headers of each target synchronization message; when there is a unique target synchronization message carrying the lowest hop count among the multiple target synchronization messages carrying the highest clock level, the port that receives the target synchronization message carrying the highest clock level and the lowest hop count is determined as the first target port of the target network device.

11. The time synchronization method according to claim 10, characterized in that, The determining the first target port of the target network device based on the clock level information and hop count information carried in the message headers of each target synchronization message among the multiple target synchronization messages further includes: When there are multiple target synchronization messages among the multiple target synchronization messages whose message headers all carry the highest clock level and the lowest hop count, determine the multiple port numbers of the ports that receive the target synchronization messages carrying the highest clock level and the lowest hop count; Determine the port with the smallest or largest number value among the multiple port numbers as the first target port of the target network device.

12. The time synchronization method according to claim 1, characterized in that When the device identity of the target network device is the highest-level master clock device, the method further includes: Generate a target synchronization message, where the target synchronization message carries the clock level information and hop count information of the target network device, and the hop count information indicates the number of hops that the target synchronization message has passed through; Send the target synchronization message.

13. A time synchronization device, characterized in that, Includes: A determination module, a reception module, an acquisition module, and a time synchronization module, The determination module is used to, when the target network device is powered on, determine the device identity of the target network device through the clock encoding corresponding to the power-on state of the clock encoding detection component; the device identity of the target network device includes the highest-level master clock device, the master clock candidate device, or the slave clock device; The reception module is used to, when the device identity of the target network device is the master clock candidate device or the slave clock device, receive the target synchronization message; The acquisition module is used to, when the target synchronization message is received, acquire the clock level information and hop count information carried in the reserved field of the message header of the target synchronization message, and the hop count information indicates the number of hops that the target synchronization message has passed through; The time synchronization module is used to perform time synchronization according to the clock level information and the hop count information carried in the reserved field of the message header of the target synchronization message; The time synchronization device further includes: a first transmission module, which is used to, when the device identity of the target network device is the master clock candidate device and the master clock candidate device does not receive the target synchronization message, the master clock candidate device acts as the master clock, generate a first synchronization message, and send the first synchronization message.

14. A time synchronization system, characterized in that, Includes: The highest-level master clock device, the master clock candidate device, and the slave clock device; The highest-level master clock device is used for: generating a target synchronization message, where the target synchronization message carries the clock level information and hop count information of the highest-level master clock device, and the hop count information indicates the number of hops that the target synchronization message has been transmitted through; Sending the target synchronization message; The master clock candidate device is used for: when receiving the target synchronization message, obtaining the clock level information and hop count information carried in the reserved field in the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through; Performing time synchronization according to the clock level information and the hop count information carried in the reserved field in the message header of the target synchronization message; The master clock candidate device is further used for, when not receiving the target synchronization message, acting as the master clock, generating a first synchronization message, and sending the first synchronization message, where the first synchronization message carries the clock level information of the master clock candidate device and first hop count information, and the first hop count information indicates the number of hops that the first synchronization message has been transmitted through; The slave clock device is used for, when receiving the target synchronization message, obtaining the clock level information and hop count information carried in the reserved field of the message header of the target synchronization message, where the hop count information indicates the number of hops that the target synchronization message has been transmitted through; Performing time synchronization according to the clock level information and the hop count information carried in the reserved field in the message header of the target synchronization message.

Citation Information

Patent Citations

  • PTP clock synchronization optimization method and application

    CN114362873A