Time synchronization method and apparatus for network device and readable storage medium

By mirroring and redirecting messages between network devices and communication terminals, the date field in data packets is captured and parsed, and the time of the network devices is automatically updated. This solves the problem of low time synchronization efficiency in existing technologies and achieves efficient and accurate time synchronization.

CN122137849APending Publication Date: 2026-06-02BOWEI TECHNOLOGY COMPANY LIMITED

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BOWEI TECHNOLOGY COMPANY LIMITED
Filing Date
2026-02-28
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing network equipment has low time synchronization efficiency and cannot support Layer 3 routing forwarding, resulting in inaccurate time synchronization.

Method used

By implementing message mirroring and message redirection during data communication between network devices and communication terminals, the system captures data packets sent by the communication terminal and parses the date field to update the network device's time.

Benefits of technology

It enables automatic time synchronization of network devices, improves the efficiency and accuracy of time synchronization, reduces hardware deployment costs, and ensures the operational stability of the devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122137849A_ABST
    Figure CN122137849A_ABST
Patent Text Reader

Abstract

This application discloses a time synchronization method, apparatus, and readable storage medium for network devices, relating to the field of time synchronization technology. The time synchronization method for network devices includes: determining message mirroring and message redirection between the network device and the communication terminal when the network device is communicating with a communication terminal; controlling the network device to receive M data packets sent by the communication terminal, where M is an integer greater than 0, based on the message mirroring and redirection; determining N date fields corresponding to the network device, where N is a positive integer less than or equal to M, based on the M data packets; and updating the time of the network device based on the N date fields. This application achieves automatic time synchronization of network devices, improving the time synchronization efficiency of network devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of time synchronization technology, and in particular to a time synchronization method, apparatus and readable storage medium for a network device. Background Technology

[0002] Currently, network devices access the internet via Layer 2 and do not support Layer 3 routing and forwarding, thus preventing the use of protocols to obtain accurate time. Therefore, existing network device time synchronization methods suffer from technical problems such as low time synchronization efficiency. Summary of the Invention

[0003] This application provides a time synchronization method, apparatus, and readable storage medium for network devices, which addresses the technical problem of low time synchronization efficiency in the prior art.

[0004] A first aspect of this application provides a time synchronization method for a network device, comprising:

[0005] When network devices and communication terminals communicate with each other, message mirroring and message redirection between the network devices and communication terminals are determined. Based on message mirroring and message redirection, control the network device to receive M data packets sent by the communication terminal, where M is an integer greater than 0; Based on M data packets, determine N date fields corresponding to the network device, where N is a positive integer less than or equal to M; Update the network device's time based on N date fields.

[0006] The time synchronization method for network devices in this embodiment controls the network device to capture data packets sent by the communication terminal in real time during data communication between the network device and the communication terminal, ensuring the real-time performance of the data packets. It also parses the date field from the data packets, ensuring the real-time performance and accuracy of the date field.

[0007] Based on a real-time date field, the system time of network devices can be automatically updated, achieving automatic time synchronization and improving the efficiency of network device time synchronization. Simultaneously, based on an accurate date field, the accuracy of network device time synchronization can be guaranteed.

[0008] This embodiment enables automatic time synchronization of network devices without requiring hardware modifications, reducing hardware deployment costs. Furthermore, the network device only needs to capture a small number of data packets to synchronize its system time, avoiding increased processing resources and ensuring operational stability.

[0009] A second aspect of this application provides a time synchronization apparatus for a network device, the apparatus comprising: The first processing unit is used to determine message mirroring and message redirection between the network device and the communication terminal when the network device and the communication terminal are communicating data. The second processing unit is used to control the network device to receive M data packets sent by the communication terminal based on packet mirroring and packet redirection, where M is an integer greater than 0; The third processing unit is used to determine N date fields corresponding to the network device based on M data packets, where N is a positive integer less than or equal to M; The fourth processing unit is used to update the network device's time based on N date fields.

[0010] In this embodiment, the time synchronization device of the network device controls the network device to capture data packets sent by the communication terminal in real time during data communication between the network device and the communication terminal, ensuring the real-time performance of the data packets. It also parses the date field from the data packets, ensuring the real-time performance and accuracy of the date field.

[0011] Based on a real-time date field, the system time of network devices can be automatically updated, achieving automatic time synchronization and improving the efficiency of network device time synchronization. Simultaneously, based on an accurate date field, the accuracy of network device time synchronization can be guaranteed.

[0012] This embodiment enables automatic time synchronization of network devices without requiring hardware modifications, reducing hardware deployment costs. Furthermore, the network device only needs to capture a small number of data packets to synchronize its system time, avoiding increased processing resources and ensuring operational stability.

[0013] A third aspect of this application provides another time synchronization apparatus for a network device, including a processor and a memory. The memory stores a computer program, which, when executed by the processor, implements the steps of the time synchronization method for the network device as described in any of the above embodiments. Therefore, this time synchronization apparatus for the network device possesses all the beneficial effects of the time synchronization method for the network device in any of the above embodiments, and will not be elaborated further here.

[0014] A fourth aspect of this application provides a readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the time synchronization method of the network device as described in any of the above embodiments. Therefore, this readable storage medium possesses all the beneficial effects of the time synchronization method of the network device in any of the above embodiments, which will not be elaborated further here. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 A flowchart illustrating a time synchronization method for a network device provided in an embodiment of this application; Figure 2 Functional block diagram of the time synchronization device for a network device provided in the embodiments of this application; Figure 3 A structural block diagram of the time synchronization device for a network device provided in an embodiment of this application. Detailed Implementation

[0017] To better understand the technical solutions provided in the embodiments of this specification, the technical solutions of the embodiments of this specification will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of this specification and the specific features in the embodiments are detailed descriptions of the technical solutions of the embodiments of this specification, rather than limitations on the technical solutions of this specification. In the absence of conflict, the embodiments of this specification and the technical features in the embodiments can be combined with each other.

[0018] In this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element. The term "two or more" includes two or more cases.

[0019] In some embodiments, such as Figure 1 As shown, an embodiment of this application provides a time synchronization method for a network device, including: Step S101: When the network device and the communication terminal are communicating via data, determine the message mirroring and message redirection between the network device and the communication terminal. Step S102: Based on message mirroring and message redirection, control the network device to receive M data packets sent by the communication terminal; Step S103: Based on the M data packets, determine the N date fields corresponding to the network device; Step S104: Update the network device's time based on N date fields.

[0020] In this embodiment, a time synchronization method for network devices is proposed to synchronize the system time of network devices. The network devices are optical network terminal devices designed for individual home users in fiber-to-the-home scenarios, mainly used to realize the access and transmission of broadband, voice and video signals.

[0021] For example, a network device can be a specific optical network terminal (also known as an "optical modem") in a home, which connects to home appliances that need to be connected to the internet to enable the home appliances to access the internet.

[0022] Controlling network devices and communication terminals to connect to the network enables data communication between them, where the communication terminal is the terminal that needs to be connected to the network.

[0023] For example, the communication terminal can specifically be a fixed terminal such as a computer.

[0024] For example, the communication terminal can specifically be a mobile terminal such as a mobile phone or tablet.

[0025] When network devices and communication terminals communicate, packet mirroring and packet redirection are determined between them. Packet mirroring is defined as: copying a packet from a specified interface or service flow and sending it to the monitoring port, while the original packet continues to be forwarded normally. Packet redirection is defined as: forcibly changing the forwarding path of a packet flow that meets specific conditions and sending it to a specified interface, next-hop device, or CPU for processing.

[0026] For example, the characteristics of message mirroring include: It does not affect the original data path; it only performs a "copy" operation.

[0027] It is commonly used in scenarios such as network traffic analysis, intrusion detection, and performance monitoring.

[0028] It has minimal impact on system performance and is suitable for long-term operation.

[0029] For example, the characteristics of message redirection include: Changing the forwarding path of the original message is a "rerouting" behavior.

[0030] It can be used in scenarios such as policy routing, firewall traffic redirection, and load balancing.

[0031] It has a higher priority than ordinary routing tables, enabling fine-grained traffic scheduling.

[0032] Based on message mirroring and message redirection, the network device is controlled to receive M data packets sent by the communication terminal, where M is an integer greater than 0, and the data packets are the messages sent by the communication terminal.

[0033] For example, a data message can specifically be an HTTP (Hypertext Transfer Protocol) message. An HTTP message is the basic data unit for communication between a client and a server via the HTTP protocol, and it is mainly divided into two types: request messages and response messages. Its structure is clear, its format is uniform, and it is easy to parse and debug.

[0034] For example, the time synchronization program in the network device includes thread 1, which is responsible for setting up message mirroring and message redirection, and reducing CPU resource consumption by capturing a small number of Layer 2 HTTP messages.

[0035] For example, M data packets can specifically be 50 HTTP packets. Thread 1 sets the mark value of the 50 HTTP packets on the Layer 2 WAN side interface to X and mirrors them to the br-lan interface. It also sets iptables rules to redirect the HTTP packets with the mark value of X to the time synchronization program.

[0036] For example, the time synchronization program in the network device includes thread 2, a dedicated thread responsible for receiving HTTP messages. Thread 2 improves the message receiving speed and the accuracy of timestamp recording, preventing message delays from affecting time precision. Thread 2 sequentially stores the received HTTP messages and the current timestamp into queue 1. If 50 HTTP messages have been received, then threads 1 and 2 exit. Based on M data packets, determine N date fields corresponding to the network device, where N is a positive integer less than or equal to M, and the date field is the field in the data packet that contains date data.

[0037] For example, a date field can be specifically a date field.

[0038] For example, if string recognition processing is required for M data messages, N date fields can be obtained.

[0039] For example, a date field may include data such as a specific date and a specific time.

[0040] Update the network device's time based on N date fields to ensure the accuracy of the network device's time.

[0041] For example, the system time of a network device can be updated in real time based on N date fields, ensuring the accuracy of the network device's system time. With an accurate system time, the accuracy of the data recorded in the network device's logs can be guaranteed. Therefore, in the event of a problem with the network device, accurate logs can be used to locate the problem, improving the efficiency of network device maintenance.

[0042] The time synchronization method for network devices in this embodiment controls the network device to capture data packets sent by the communication terminal in real time during data communication between the network device and the communication terminal, ensuring the real-time performance of the data packets. It also parses the date field from the data packets, ensuring the real-time performance and accuracy of the date field.

[0043] Based on a real-time date field, the system time of network devices can be automatically updated, achieving automatic time synchronization and improving the efficiency of network device time synchronization. Simultaneously, based on an accurate date field, the accuracy of network device time synchronization can be guaranteed.

[0044] This embodiment enables automatic time synchronization of network devices without requiring hardware modifications, reducing hardware deployment costs. Furthermore, the network device only needs to capture a small number of data packets to synchronize its system time, avoiding increased processing resources and ensuring operational stability.

[0045] In some embodiments, this application provides a time synchronization method for a network device, which determines N date fields corresponding to the network device based on M data packets, including: Classify the M data packets by type to obtain P response packets from the M data packets, where P is an integer less than or equal to M and greater than or equal to N; Data is read and processed from P response messages to obtain N date fields.

[0046] In this embodiment, M data packets are classified to obtain P response packets from the M data packets, where P is an integer less than or equal to M and greater than or equal to N, and the response packet is a data packet containing response data.

[0047] For example, data packets may include response packets and request packets.

[0048] Data is read and processed from P response messages to obtain N date fields.

[0049] For example, the time synchronization program in the network device includes thread 3. Thread 3 reads HTTP messages and timestamps from queue 1, checks whether it is an HTTP response message, whether it contains a date field, and whether the source port is port 80. The source IP address, date value, and timestamp of the HTTP message that meets the conditions are stored as a record in queue 2. Before storing in queue 2, in order to ensure the diversity of time sources and improve the accuracy of time synchronization, it is necessary to check whether there is a record with the same source IP address that has been stored. If so, the record is discarded.

[0050] In some embodiments, this application provides a time synchronization method for a network device, which updates the time of the network device based on N date fields, including: Perform data filtering on N date fields to obtain Q valid date fields from the N date fields, where Q is a positive integer less than or equal to N; Update the network device's time based on Q valid date fields.

[0051] Perform data filtering on N date fields to obtain Q valid date fields from the N date fields, where Q is a positive integer less than or equal to N. In this embodiment, data filtering is performed on N date fields to obtain Q valid date fields from the N date fields, where Q is a positive integer less than or equal to N, and the valid date fields are the valid data in the date fields.

[0052] For example, N date fields include valid date fields and invalid date fields. By filtering out the invalid date fields, Q valid date fields can be obtained from the N date fields.

[0053] Update the network device's time based on Q valid date fields.

[0054] For example, the time synchronization program in the network device includes thread 4, which is responsible for eliminating erroneous date interference and selecting accurate dates, thus obtaining Q valid date fields.

[0055] In some embodiments, this application provides a time synchronization method for a network device, which updates the time of the network device based on Q valid date fields, including: Set the date field with the smallest time among the Q valid date fields as the base date field; Determine the time difference between the other Q-1 valid date fields and the base date field to obtain Q-1 time differences that correspond one-to-one with the Q-1 valid date fields; By comparing Q-1 time differences, the target date field among Q-1 valid date fields is determined; Update the network device's time based on the target date field.

[0056] In this embodiment, the date field with the smallest time among the Q valid date fields is set as the base date field, where the base date field is the smallest time among the Q valid date fields.

[0057] For example, Q valid date fields can be specifically 20 valid date fields.

[0058] The 20 valid date fields are as follows: [sip1,date1,timestamp1]; [sip2,date2,timestamp2]; [sip3,date3,timestamp3]; ... [sip20,date20,timestamp20].

[0059] Determine the time difference between the other Q-1 valid date fields and the base date field to obtain Q-1 time differences that correspond one-to-one with the Q-1 valid date fields, where the time difference is the time difference between the valid date field and the base date field.

[0060] By comparing Q-1 time differences, the target date field is determined among Q-1 valid date fields, where the target date field is the optimal date field among the Q-1 valid date fields.

[0061] Update the network device's time based on the target date field.

[0062] For example, the time difference between the first and second valid date fields is calculated. Date1 is then calibrated to the same time as Date2, which is date1 plus the difference between the timestamps of the two valid date fields. Then, date2 is subtracted from the calibrated date1 time to obtain the time difference between the two valid date fields. If both times are accurate, the time difference should be 0. If one date is inaccurate, the absolute value of the time difference should be greater than 0. Based on this principle, the larger the sum of the time differences between a valid date field and the other valid date fields, the more inaccurate the date of that valid date field is. Therefore, the valid date field with the smallest sum of its time differences should be selected as the reference for synchronizing the system time.

[0063] Calculate the time difference between the first and second valid date fields: sip1_sip2=|date2-(date1+(timestamp2-timestamp1))|; Calculate the time difference between the first and third valid date fields: sip1_sip3=|date3-(date1+(timestamp3-timestamp1))|; And so on, calculate the time difference between the first valid date field and the twentieth valid date field: sip1_sip20=|date20-(date1+(timestamp20-timestamp1))|.

[0064] In some embodiments, this application provides a time synchronization method for a network device, which determines a target date field among Q-1 valid date fields by comparing Q-1 time differences, including: Determine the minimum of Q-1 time differences to obtain the target time difference; The valid date field corresponding to the target time difference is determined as the target date field.

[0065] In this embodiment, the minimum of Q-1 time differences is determined to obtain the target time difference, wherein the target time difference is the minimum of the Q-1 time differences.

[0066] The valid date field corresponding to the target time difference is determined as the target date field.

[0067] For example, the target time difference being the smallest time difference indicates that the target date field is the most accurate and timely date field.

[0068] In some embodiments, this application provides a time synchronization method for a network device, which updates the time of the network device according to a target date field, including: Generate the time setting value corresponding to the network device based on the target date field; Set the network device's time to the set time value to update the network device's time.

[0069] In this embodiment, a time setting value corresponding to the network device is generated based on the target date field, wherein the time setting value is the time value that needs to be set.

[0070] For example, converting the data type of the target date field to a time data type can yield a time setting value.

[0071] Set the network device's time to a preset value to update the network device's time and ensure its accuracy.

[0072] In some embodiments, this application provides a time synchronization method for a network device. After controlling the network device to receive M data packets sent by a communication terminal, the method is as follows: Determine the number of date fields in M ​​data messages; If the number of date fields is less than N, control the network device to re-receive data packets sent by the communication terminal.

[0073] In this embodiment, the number of date fields in M ​​data packets is determined. If the number of date fields is less than N, it indicates that the number of date fields is insufficient, and the date fields need to be recaptured to meet the time synchronization requirements. The network device is then controlled to re-receive data packets sent by the communication terminal.

[0074] For example, after processing all messages in queue 1, check if there are more than 20 records in queue 2. If there are, start thread 4 and exit thread 3; otherwise, restart thread 1 and continue collecting HTTP messages.

[0075] In some embodiments, such as Figure 2 As shown, an embodiment of this application provides a time synchronization device 200 for a network device, comprising: The first processing unit 202 is used to determine message mirroring and message redirection between the network device and the communication terminal when the network device and the communication terminal are communicating data. The second processing unit 204 is used to control the network device to receive M data packets sent by the communication terminal based on packet mirroring and packet redirection, where M is an integer greater than 0. The third processing unit 206 is used to determine N date fields corresponding to the network device based on M data packets, where N is a positive integer less than or equal to M; The fourth processing unit 208 is used to update the time of the network device based on N date fields.

[0076] In this embodiment, the time synchronization device 200 of the network device controls the network device to capture data packets sent by the communication terminal in real time during data communication between the network device and the communication terminal, ensuring the real-time performance of the data packets. It also parses the date field from the data packets, ensuring the real-time performance and accuracy of the date field.

[0077] Based on a real-time date field, the system time of network devices can be automatically updated, achieving automatic time synchronization and improving the efficiency of network device time synchronization. Simultaneously, based on an accurate date field, the accuracy of network device time synchronization can be guaranteed.

[0078] This embodiment enables automatic time synchronization of network devices without requiring hardware modifications, reducing hardware deployment costs. Furthermore, the network device only needs to capture a small number of data packets to synchronize its system time, avoiding increased processing resources and ensuring operational stability.

[0079] In some embodiments of this application, a time synchronization device 200 for a network device is provided, wherein the third processing unit 206 is further configured to: Classify the M data packets by type to obtain P response packets from the M data packets, where P is an integer less than or equal to M and greater than or equal to N; Data is read and processed from P response messages to obtain N date fields.

[0080] In some embodiments of this application, a time synchronization device 200 for a network device is provided, wherein the fourth processing unit 208 is further configured to: Perform data filtering on N date fields to obtain Q valid date fields from the N date fields, where Q is a positive integer less than or equal to N; Update the network device's time based on Q valid date fields.

[0081] In some embodiments of this application, a time synchronization device 200 for a network device is provided, wherein the fourth processing unit 208 is further configured to: Set the date field with the smallest time among the Q valid date fields as the base date field; Determine the time difference between the other Q-1 valid date fields and the base date field to obtain Q-1 time differences that correspond one-to-one with the Q-1 valid date fields; By comparing Q-1 time differences, the target date field among Q-1 valid date fields is determined; Update the network device's time based on the target date field.

[0082] In some embodiments of this application, a time synchronization device 200 for a network device is provided, wherein the fourth processing unit 208 is further configured to: Determine the minimum of Q-1 time differences to obtain the target time difference; The valid date field corresponding to the target time difference is determined as the target date field.

[0083] In some embodiments of this application, a time synchronization device 200 for a network device is provided, wherein the fourth processing unit 208 is further configured to: Generate the time setting value corresponding to the network device based on the target date field; Set the network device's time to the set time value to update the network device's time.

[0084] In some embodiments of this application, a time synchronization device 200 for a network device is provided, further comprising a fifth processing unit, the fifth processing unit being configured to: Determine the number of date fields in M ​​data messages; If the number of date fields is less than N, control the network device to re-receive data packets sent by the communication terminal.

[0085] In some embodiments, such as Figure 3 As shown, a time synchronization device 300 for a network device is proposed. The time synchronization device 300 includes a processor 302 and a memory 304. The memory 304 stores a computer program, which, when executed by the processor 302, implements the steps of the time synchronization method for the network device as described in any of the above embodiments. Therefore, the time synchronization device 300 possesses all the beneficial effects of the time synchronization method for the network device in any of the above embodiments, which will not be elaborated further here.

[0086] In some embodiments, a readable storage medium is provided on which a program is stored, which, when executed by a processor, implements the steps of the time synchronization method of the network device as described in any of the above embodiments, and thus has all the beneficial technical effects of the time synchronization method of the network device in any of the above embodiments.

[0087] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0088] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-readable program code.

[0089] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0090] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0091] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0092] This application also provides a computer program product, which includes computer software instructions that, when executed on a processing device, cause the processing device to execute a process of a time synchronization method for a network device.

[0093] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0094] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0095] In the several embodiments provided in this application, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.

[0096] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0097] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0098] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0099] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

[0100] Although preferred embodiments have been described in this specification, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this specification.

[0101] Obviously, those skilled in the art can make various modifications and variations to this specification without departing from its spirit and scope. Therefore, if such modifications and variations fall within the scope of the claims and their equivalents, this specification is also intended to include such modifications and variations.

Claims

1. A time synchronization method for network devices, characterized in that, The method includes: When the network device and the communication terminal are communicating, message mirroring and message redirection between the network device and the communication terminal are determined. Based on the message mirroring and the message redirection, the network device is controlled to receive M data packets sent by the communication terminal, where M is an integer greater than 0; Based on the M data packets, determine the N date fields corresponding to the network device, where N is a positive integer less than or equal to M; Update the time of the network device based on the N date fields.

2. The method according to claim 1, characterized in that, The step of determining the N date fields corresponding to the network device based on the M data packets includes: The M data packets are classified by type to obtain P response packets from the M data packets, where P is an integer less than or equal to M and greater than or equal to N; Data reading and processing are performed on P response messages to obtain N date fields.

3. The method according to claim 1, characterized in that, The step of updating the network device's time based on the N date fields includes: Data filtering is performed on the N date fields to obtain Q valid date fields from the N date fields, where Q is a positive integer less than or equal to N; Update the time of the network device based on the Q valid date fields.

4. The method according to claim 3, characterized in that, The step of updating the network device's time based on the Q valid date fields includes: Set the date field with the smallest time among the Q valid date fields as the base date field; Determine the time difference between the other Q-1 valid date fields and the base date field to obtain Q-1 time differences that correspond one-to-one with the Q-1 valid date fields; By comparing Q-1 of the time differences, the target date field among the Q-1 valid date fields is determined; Update the network device's time based on the target date field.

5. The method according to claim 4, characterized in that, The step of determining the target date field among the Q-1 valid date fields by comparing Q-1 time differences includes: Determine the minimum of Q-1 time differences to obtain the target time difference; The effective date field corresponding to the target time difference is determined as the target date field.

6. The method according to claim 4, characterized in that, The step of updating the network device's time based on the target date field includes: Based on the target date field, generate the time setting value corresponding to the network device; Set the time of the network device to a set time value to update the time of the network device.

7. The method according to any one of claims 1 to 6, characterized in that, After the network device receives M data packets sent by the communication terminal, the method is as follows: Determine the number of date fields in the M data packets; If the number of date fields is less than N, control the network device to re-receive the data packets sent by the communication terminal.

8. A time synchronization device for a network device, characterized in that, The device includes: The first processing unit is configured to determine message mirroring and message redirection between the network device and the communication terminal when the network device and the communication terminal are communicating data. The second processing unit is configured to control the network device to receive M data packets sent by the communication terminal based on the packet mirroring and the packet redirection, where M is an integer greater than 0; The third processing unit is used to determine N date fields corresponding to the network device based on the M data packets, where N is a positive integer less than or equal to M; The fourth processing unit is used to update the time of the network device based on the N date fields.

9. A time synchronization device for a network device, characterized in that, include: processor; A memory, in which programs or instructions are stored, wherein a processor, when executing programs or instructions in the memory, implements the steps of the time synchronization method of the network device as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that, A program or instruction is stored on a readable storage medium, which, when executed by a processor, implements the steps of the time synchronization method of the network device as described in any one of claims 1 to 7.