CN110601786B - Time synchronization method, relay equipment and device - Google Patents

Time synchronization method, relay equipment and device Download PDF

Info

Publication number
CN110601786B
CN110601786B CN201910904570.6A CN201910904570A CN110601786B CN 110601786 B CN110601786 B CN 110601786B CN 201910904570 A CN201910904570 A CN 201910904570A CN 110601786 B CN110601786 B CN 110601786B
Authority
CN
China
Prior art keywords
time
time synchronization
ntp server
ntp
request message
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910904570.6A
Other languages
Chinese (zh)
Other versions
CN110601786A (en
Inventor
王芳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Raisecom Technology Co Ltd
Original Assignee
Raisecom Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Raisecom Technology Co Ltd filed Critical Raisecom Technology Co Ltd
Priority to CN201910904570.6A priority Critical patent/CN110601786B/en
Publication of CN110601786A publication Critical patent/CN110601786A/en
Application granted granted Critical
Publication of CN110601786B publication Critical patent/CN110601786B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0658Clock or time synchronisation among packet nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0658Clock or time synchronisation among packet nodes
    • H04J3/0661Clock or time synchronisation among packet nodes using timestamps
    • H04J3/0667Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The application discloses a time synchronization method, relay equipment and a device, wherein the method comprises the following steps: the method comprises the steps that the relay equipment is connected with at least two NTP servers, the at least two NTP servers comprise a first NTP server, and after the relay equipment detects that the first NTP server is in a fault state and at least one NTP server in the at least two NTP servers is in a normal state, the working mode of the relay equipment is switched from a transparent transmission mode to a forwarding mode; the relay device in the forwarding mode receives a first time synchronization request message sent by a first NTP client to a first NTP server, determines a first target NTP server according to locally stored average round-trip delay related to the first NTP server, sends the first time synchronization request message to the first target NTP server, and sends a received first time synchronization response sent by the first target NTP server to the first NTP client.

Description

Time synchronization method, relay equipment and device
Technical Field
The present application relates to the field of communications technologies, and in particular, to a time synchronization method, a relay device, and an apparatus.
Background
Network Time Protocol (NTP) is a Time synchronization service Protocol, and aims to provide uniform Time synchronization service for devices running on a Network. When the NTP server is in a normal state, normal NTP message interaction is carried out between the NTP client and the NTP server, the relay equipment is transparent to the two types of equipment, namely the NTP client equipment and the NTP server equipment do not sense the existence of the relay equipment, and the mode of the relay equipment is a transparent transmission mode at the moment.
When an NTP server fails or a link between the NTP server and relay equipment fails, NTP synchronization between the NTP client and the NTP server is overtime, and time cannot be synchronized. For periodically synchronized devices, there may be a synchronization failure, but for devices that restart and do not have a Real Time Clock (RTC) mechanism of their own, the Time synchronization service is not available.
Under the conditions that an NTP server fails or a link between the NTP server and relay equipment fails and time synchronization service is unavailable, an NTP client can perform time synchronization conversation only after waiting for the recovery of the fault of the NTP server or the recovery of the link between the NTP server and the relay equipment to complete the time synchronization of the NTP client; however, during a fault period, the NTP client which is restarted and does not have an RTC mechanism cannot perform time synchronization, so that the performance of the NTP client is affected, and the reliability of the time synchronization service is reduced.
Disclosure of Invention
The embodiment of the application provides a time synchronization method, relay equipment and a device, which are used for improving the reliability of time synchronization service.
In a first aspect, a time synchronization method is provided, where the time synchronization method is applied to a relay device, where the relay device establishes a connection with at least two network time protocol NTP servers, where the at least two NTP servers include a first NTP server, and the method includes:
after the relay device detects that the first NTP server is in a fault state and at least one NTP server in the at least two NTP servers is in a normal state, the working mode of the relay device is switched from a transparent transmission mode to a forwarding mode;
the relay equipment in the forwarding mode receives a first time synchronization request message sent by a first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
determining, by the relay device in a forwarding mode, a first target NTP server based on locally stored average round trip delay for the at least one NTP server; wherein, the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment;
the relay device in the forwarding mode sends the first time synchronization request message to the first target NTP server;
the relay device in the forwarding mode receives a first time synchronization response message sent by the first target NTP server, and sends the first time synchronization response message to the first NTP client; wherein the first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
Optionally, the sending, by the relay device in the forwarding mode, the first time synchronization request message to the first target NTP server includes:
the relay device in the forwarding mode modifies a destination address in the first time synchronization request message into an address of the first target NTP server, and sends the modified first time synchronization request message to the first target NTP server;
the sending, by the relay device in the forwarding mode, the first time synchronization response message received by the relay device in the forwarding mode carries a source address, where the source address is an address of the first target NTP server, and the sending, by the relay device in the forwarding mode, the first time synchronization response message to the first NTP client includes:
and the relay equipment in the forwarding mode modifies the source address in the first time synchronization response message into the address of the first NTP server and sends the modified first time synchronization response message to the first NTP client.
Optionally, the method further comprises:
after the relay equipment detects that all the NTP servers in the at least two NTP servers are in a fault state, the working mode of the relay equipment is switched from a transparent transmission mode to a relay service mode;
the relay equipment in a relay service mode receives a first time synchronization request message sent by the first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
the relay device in relay service mode determines a first time and a second time according to locally stored time information about a first NTP server, the time information including at least a system time, an average response delay, and an average round trip delay; wherein the first time is a timestamp indicating that the first NTP server received the first time synchronization request message, and the second time is a timestamp indicating that the first NTP server sent a first time synchronization response message; the average response time delay is the average time length of a response time synchronization request message of an NTP server in a normal state;
the relay device in the relay service mode sends a first time synchronization response message to the first NTP client, where the first time synchronization response message carries the first time and the second time.
Optionally, the operation mode of the relay device further includes a client mode, and the method further includes:
and after the relay equipment in the client mode detects that the first NTP server and the first NTP client finish a time synchronization session, the working mode of the relay equipment is switched to a transparent transmission mode from the client mode.
Optionally, before the relay device in the client mode detects that the first NTP server and the first NTP client complete a time synchronization session, the method further includes:
the relay equipment in the client mode continuously sends a second time synchronization request message to the first NTP server for N times according to a first set frequency, wherein the second time synchronization request message carries a timestamp of the second time synchronization request message sent by the relay equipment; n is an integer greater than 1;
the relay equipment in the client mode determines N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the second time synchronization response message carries a timestamp of the second time synchronization request message sent by the relay device, and the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the second time synchronization response message sent by the first NTP server;
and in the client mode, the relay equipment performs average operation on the N round-trip time delays to obtain initial average round-trip time delays and records the initial average round-trip time delays, and performs average operation on the N response time delays to obtain initial average response time delays and records the initial average response time delays.
Optionally, after the working mode of the relay device is switched from the client mode to the transparent transmission mode, the method further includes:
the relay equipment in the transparent transmission mode sends a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message;
the relay equipment in the transparent transmission mode receives a third time synchronization response message sent by the first NTP server; wherein the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message;
and the relay equipment in the transparent transmission mode updates the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the relay equipment for receiving the third time synchronization response message.
Optionally, the locally stored time information includes an initial average round trip delay and an initial average response delay;
the updating, by the relay device in the transparent transmission mode, the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message, and the timestamp at which the relay device receives the third time synchronization response message includes:
the relay equipment in the transparent transmission mode carries out summation operation on the first time length and the second time length to obtain round-trip time delay, and carries out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time duration is a difference value between a timestamp of the first NTP server receiving the third time synchronization request message and a timestamp of the relay device sending the third time synchronization request message, and the second time duration is a difference value between a timestamp of the relay device receiving the third time synchronization response message and a timestamp of the first NTP server sending the third time synchronization response message;
and in the transparent transmission mode, the relay equipment performs average calculation on the difference value between the timestamp of the first NTP server receiving the third time synchronization request message and the timestamp of the first NTP server sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
Optionally, the time information locally stored by the relay device specifically includes a system time, an average round trip delay, and an average response delay;
the relay device in the relay service mode determining a first time and a second time according to locally stored time information, including:
the relay equipment in a relay service mode carries out summation operation on the system time and one half of the average round-trip delay to obtain the first time;
and the relay equipment in the relay service mode carries out summation operation on the system time, the average response time delay and one half of the average round trip time delay to obtain the second time.
Optionally, the method further comprises:
the relay equipment sends a fault detection request message to the first NTP server according to a third set frequency; the failure detection request message is used for determining the state of the first NTP server; the states include a fault state and a normal state;
if the relay equipment receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state;
and if the relay equipment does not receive the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a fault state.
Optionally, after marking that the first NTP server is in a normal state, the method further comprises:
switching the working mode of the relay equipment from a forwarding mode to a transparent transmission mode; alternatively, the first and second electrodes may be,
and switching the working mode of the relay equipment from a relay service mode to a transparent transmission mode.
Optionally, the method further comprises:
and the relay equipment sends a fourth time synchronization request message to a second target NTP server according to a fourth set frequency, the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored by the relay equipment.
In a second aspect, a relay device is provided, where the relay device establishes a connection with at least two network time protocol NTP servers, where the at least two NTP servers include a first NTP server, and the relay device includes:
the mode switching module is used for switching the working mode from the transparent transmission mode to the forwarding mode after the detection module detects that the first NTP server is in a fault state and at least one NTP server in the at least two NTP servers is in a normal state;
the forwarding module is used for receiving a first time synchronization request message sent by a first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server; determining a first target NTP server based on locally stored average round trip delay for the at least one NTP server; wherein, the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment; sending the first time synchronization request message to the first target NTP server; receiving a first time synchronization response message sent by the first target NTP server, and sending the first time synchronization response message to the first NTP client; wherein the first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
Optionally, the forwarding module is specifically configured to:
modifying the destination address in the first time synchronization request message into the address of the first target NTP server, and sending the modified first time synchronization request message to the first target NTP server;
the first time synchronization response message received by the relay device in the forwarding mode carries a source address, where the source address is an address of the first target NTP server, and the forwarding module is specifically configured to:
and modifying the source address in the first time synchronization response message into the address of the first NTP server, and sending the modified first time synchronization response message to the first NTP client.
Optionally, the mode switching module is further configured to:
after the detection module detects that all the NTP servers in the at least two NTP servers are in a fault state, the working mode of the relay equipment is switched from a transparent transmission mode to a relay service mode;
the relay device further includes a relay service module, where the relay service module is specifically configured to:
receiving a first time synchronization request message sent by the first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
determining a first time and a second time based on locally stored time information about a first NTP server, the time information including at least a system time, an average response delay, and an average round trip delay; wherein the first time is a timestamp indicating that the first NTP server received the first time synchronization request message, and the second time is a timestamp indicating that the first NTP server sent a first time synchronization response message; the average response time delay is the average time length of a response time synchronization request message of an NTP server in a normal state;
and sending a first time synchronization response message to the first NTP client, wherein the first time synchronization response message carries the first time and the second time.
Optionally, the working modes of the relay device further include a client mode, and the mode switching module is further configured to:
and after the detection module detects that the first NTP server and the first NTP client finish a time synchronization session, switching the working mode of the relay equipment from a client mode to a transparent transmission mode.
Optionally, the relay device further comprises a client module;
the client module is specifically configured to:
sending a second time synchronization request message to the first NTP server according to a first set frequency for N times continuously, wherein the second time synchronization request message carries a timestamp for sending the second time synchronization request message by the relay equipment; n is an integer greater than 1;
determining N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the second time synchronization response message carries a timestamp of the second time synchronization request message sent by the relay device, and the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the second time synchronization response message sent by the first NTP server;
and carrying out average operation on the N round-trip time delays to obtain initial average round-trip time delay and recording the initial average round-trip time delay, and carrying out average operation on the N response time delays to obtain initial average response time delay and recording the initial average response time delay.
Optionally, the relay device further includes an unvarnished transmission module, and after the working mode of the relay device is switched from the client mode to the unvarnished transmission mode, the unvarnished transmission module is specifically configured to:
sending a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message;
receiving a third time synchronization response message sent by the first NTP server; wherein the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message;
and updating the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the third time synchronization response message received by the relay equipment.
Optionally, the locally stored time information includes an initial average round trip delay and an initial average response delay;
the transparent transmission module is specifically used for:
summing the first time length and the second time length to obtain round-trip time delay, and carrying out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time duration is a difference value between a timestamp of the first NTP server receiving the third time synchronization request message and a timestamp of the relay device sending the third time synchronization request message, and the second time duration is a difference value between a timestamp of the relay device receiving the third time synchronization response message and a timestamp of the first NTP server sending the third time synchronization response message;
and averagely calculating the difference between the timestamp of the first NTP server receiving the third time synchronization request message and the timestamp of the first NTP server sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
Optionally, the time information locally stored by the relay device includes a system time, an average round trip delay, and an average response delay;
the relay service module is specifically configured to:
summing the system time and one half of the average round-trip delay to obtain the first time;
and summing the average response time delay and one half of the average round trip time delay of the system time to obtain the second time.
Optionally, the detection module is further configured to:
sending a fault detection request message to the first NTP server according to a third set frequency; the failure detection request message is used for determining the state of the first NTP server; the states include a fault state and a normal state;
if the relay equipment receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state;
and if the relay equipment does not receive the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a fault state.
Optionally, the mode switching module is further configured to:
switching the working mode of the relay equipment from a forwarding mode to a transparent transmission mode; alternatively, the first and second electrodes may be,
and switching the working mode of the relay equipment from a relay service mode to a transparent transmission mode.
Optionally, the forwarding module or the relay service module is specifically configured to:
and sending a fourth time synchronization request message to the second target NTP server according to a fourth set frequency, wherein the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored in the relay device.
In a third aspect, a communication apparatus is provided, including: a processor, a memory, and a transceiver;
the memory to store computer instructions;
the processor configured to execute the computer instructions to implement the method according to any one of the first aspect.
In a fourth aspect, there is provided a computer readable storage medium storing computer instructions which, when executed by a processor, implement the method of any one of the first aspects.
In an embodiment of the present application, a relay device establishes a connection with at least two NTP servers, where the at least two NTP servers include a first NTP server, and when the relay device detects that the first NTP server is in a failure state, and at least one of the at least two NTP servers is in a normal state, a working mode of the relay device is switched from a transparent transmission mode to a forwarding mode; the method comprises the steps that relay equipment in a forwarding mode receives a first time synchronization request message sent to a first NTP server by a first NTP client; in response, the relay device in the forwarding mode determines a first target NTP server based on the locally stored average round-trip delay associated with the at least one NTP server, sends a first time synchronization request message to the first target NTP server, receives a first time synchronization response message sent by the first target NTP server, and sends the first time synchronization response to the first NTP client, so that the first NTP client completes time synchronization. Therefore, when the NTP server is in a fault state, the relay equipment under the forwarding model responds to the time synchronization request message sent by the NTP client hung under the NTP server and sends the time synchronization request message to other NTP servers in a normal state, so that the NTP client completes time synchronization, time synchronization can be carried out without waiting for the fault recovery of the NTP server, and the reliability of time synchronization service is improved.
Drawings
Fig. 1 is a schematic structural diagram of a time synchronization service system according to an embodiment of the present application;
fig. 2 is a schematic diagram illustrating switching of an operation mode of a relay device according to an embodiment of the present application;
fig. 3 is a schematic flowchart of a time synchronization method according to an embodiment of the present application;
fig. 4 is a schematic flowchart of a time synchronization method according to an embodiment of the present application;
fig. 5 is a flowchart illustrating switching of an operating mode of a relay device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a relay device according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a communication device according to an embodiment of the present application.
Detailed Description
It should be noted that "first", "second", "third", and "fourth" in the embodiments of the present application are used for distinguishing similar objects, and are not necessarily used for describing a specific order or sequence order.
The following detailed description of embodiments of the present application will be made with reference to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present application, are given by way of illustration and explanation only, and are not intended to limit the present application.
When an NTP server fails or a link between the NTP server and relay equipment fails, an NTP client can perform time synchronization conversation to complete time synchronization after the NTP server failure is recovered or the link between the NTP server and the relay equipment is recovered; during the fault period, the time synchronization service is unavailable for the NTP client which is restarted and does not have the RTC mechanism, the NTP client cannot perform time synchronization, the performance of the NTP client is affected, and the reliability of the time synchronization service is reduced.
In order to solve the above problem, an embodiment of the present application provides a time synchronization service system.
Referring to fig. 1, a schematic structural diagram of a time synchronization service system is provided for the embodiment of the present application.
As shown, the time synchronization service system includes a first NTP server 101, a second NTP server 102, a third NTP server 103, a relay device 104, a first NTP client 105, a second NTP client 106, and a third NTP client 107.
The first NTP server 101 is configured to implement time synchronization between the relay device 104 and the first NTP client 105; specifically, a time synchronization request message is received from the relay device 104, the first NTP client 105, and a time synchronization response message is returned to the relay device 104 and the first NTP client 105 in response to the time synchronization request message.
A second NTP server 102, configured to implement time synchronization between the relay device 104 and the second NTP client 106; a third NTP server 103 configured to implement time synchronization between the relay device 104 and the third NTP client 107; the specific implementation process is similar to the implementation process of the first NTP server 101, and is not described herein again.
A relay device 104 configured to select an NTP server for synchronizing local system time, send a time synchronization request message to the selected NTP server, and receive a time synchronization response message returned from the selected NTP server, so as to synchronize local system time; wherein, the selected NTP server is one of the first NTP server 101, the second NTP server 102, and the third NTP server 103 which is in a normal state; for receiving a time synchronization request message from the first NTP client 105, sending the time synchronization request message to the first NTP server 101, receiving a time synchronization response message returned by the first NTP server 101 in response to the time synchronization request message, and sending the time synchronization response message to the first NTP client 105; for receiving a time synchronization request message from the second NTP client 106, sending the time synchronization request message to the second NTP server 102, receiving a time synchronization response message returned by the second NTP server 102 in response to the time synchronization request message, and sending the time synchronization response message to the second NTP client 106; for receiving a time synchronization request message from the third NTP client 107, sending the time synchronization request message to the third NTP server 103, receiving a time synchronization response message returned by the third NTP server 103 in response to the time synchronization request message, and sending the time synchronization response message to the third NTP client 107.
The time synchronization request message is an NTP request message, and the time synchronization response message is an NTP response message.
The relay device 104 provides four modes of operation: client mode, transparent transmission mode, forwarding mode and relay service mode.
It should be noted that the operation mode of the relay device 104 is specific to a particular NTP server, that is, the operation mode of the relay device 104 may be different for different NTP servers; for example, for the first NTP server 101, the operation mode of the relay device 104 is transparent transmission mode, and for the second NTP server 102, the operation mode of the relay device 104 is forwarding mode.
Next, based on the time synchronization service system shown in fig. 1, the operation mode switching of the relay device with respect to the first NTP server 101 will be described.
Referring to fig. 2, a schematic diagram of switching operation modes of a relay device according to an embodiment of the present application is shown.
As shown in the figure, the operation mode of the relay device 104 may be switched from the client mode 201 to the transparent transmission mode 202, from the transparent transmission mode 202 to the forwarding mode 203 or the relay service mode 204, from the relay service mode 204 or the forwarding mode 203 to the transparent transmission mode 202, from the relay service mode 204 to the forwarding mode 203, and from the forwarding mode 203 to the relay service mode 204.
In client mode 201, the relay device 104 has not hung the first NTP client 105, i.e., the relay device 104 has not detected that the first NTP server 101 and the first NTP client 105 completed a time synchronization session, the relay device 104 is in client mode for the first NTP server 101.
Specifically, in the initial stage, the relay device 104 in the client mode continuously sends a time synchronization request message to the first NTP server 101 at a high frequency (a first set frequency, such as 1 time/second) N times to acquire an initial average round trip delay and an initial average response delay; n is an integer greater than 1.
In a specific implementation, the relay device 104 needs to select one of the 3 NTP servers (i.e., the first NTP server 101, the second NTP server 102, and the third NTP server 103) to perform local system time synchronization; specifically, the relay device 104 sends time synchronization request messages to the 3 NTP servers respectively according to a protocol standard flow, and the relay device 104 calculates parameters such as link delay (i.e., transmission delay) and response delay respectively according to time synchronization response messages returned from the 3 NTP servers, and then selects an optimal NTP server as the NTP server for synchronizing the local system time of the relay device 104 according to the parameters such as link delay and response delay. Of course, the specific selection algorithm of the optimal NTP server may also be any one of other prior arts, and this is not particularly limited in this embodiment of the present invention.
Taking the NTP server where the relay device 104 performs local system time synchronization as the first NTP server 101 as an example, after N corresponding time synchronization response messages are continuously received, the relay device 104 in the client mode sends a time synchronization request message to the first NTP server 101 according to a low frequency (a fourth set frequency) to poll the NTP server mechanism state to synchronize the system time. Preferably, the fourth set frequency is 64-1Time synchronization request messages are sent to the NTP server every second, i.e., every 64 seconds.
In an implementation scenario, if the relay device 104 selects another NTP server to provide the local system time synchronization service, as long as the selected NTP server is in a normal state and the acquisition of the initial average round trip delay and the initial average response delay is completed, the relay device 104 sends a time synchronization request message to the selected NTP server at a low frequency (a fourth set frequency) to synchronize the local system time.
Since the relay device 104 has a relay function, in a high frequency stage, the relay device 104 calculates N round-trip delays from the first NTP server 101 to the relay device 104 according to the N time synchronization request messages, the time synchronization response messages, and the timestamp of each time synchronization response message received by the relay device 104, and performs an average operation on the N round-trip delays to obtain an initial average round-trip delay, which is denoted as t _ rtt _ avg 1. The relay device 104 calculates response delays of the N first NTP servers 101 in response to the time synchronization request messages according to the time stamps in the N time synchronization request messages and the time synchronization response messages, and performs an average operation on the N response delays to obtain an initial average response delay, which is denoted as t _ proc _ avg 1. And recording the calculated initial average round trip delay and initial average response delay into a register.
Specifically, the relay device 104 sends a time synchronization request message to the first NTP server 101, where the time synchronization request message carries a timestamp of the time synchronization request message sent by the relay device 104, the relay device 104 receives a time synchronization response message sent by the first NTP server 101, and the time synchronization response message carries a timestamp of the time synchronization request message sent by the relay device 104, a timestamp of the time synchronization request message received by the first NTP server 101, and a timestamp of the time synchronization response message sent by the first NTP server 101. The round trip delay, response delay associated with the first NTP server 101, the difference between the system time of the relay device 104 and the system time of the first NTP server 101, and the synchronized system time of the relay device 104 are calculated as follows.
t_rtt=(T2-T1)+(T4-T3) (1)
t_proc=T3-T2 (2)
t_del=[(T2-T1)+(T3-T4)]/2 (3)
t_base=t_sys+t_rtt+t_del (4)
Wherein t _ rtt is a round-trip delay, which represents the transmission duration of the time synchronization request message and the time synchronization response message between the relay device 104 and the first NTP server 101; t _ proc is response delay, which represents the duration of the first NTP server 101 responding to the time synchronization request message; t1 denotes a time stamp of the time synchronization request message transmitted by the relay apparatus 104; t2 denotes a time stamp at which the first NTP server 101 receives the time synchronization request message; t3 denotes a time stamp at which the first NTP server 101 transmits the time synchronization response message; t4 denotes a time stamp at which the relay apparatus 104 receives the time synchronization response message; t _ del represents a difference between the system time of the relay device 104 and the system time of the first NTP server 101, t _ sys represents an initialized system time of the relay device 104 (or a current system time, i.e., a system time synchronized by another NTP server), and t _ base represents a system time synchronized by the relay device 104.
It should be noted that, in the state of low-frequency polling the first NTP server 101, the time synchronization response message returned by the first NTP server 104 and received by the relay device 104 is only used for synchronizing the system time of the relay device 104, and does not participate in the calculation of t _ rtt and t _ proc.
In the transparent transmission mode 202, a new first NTP client 105 is added to the network and hung down to the relay device 104, and the first NTP server 101 connected to the relay device 104 is configured to provide time synchronization service for the first NTP client 105, and the first NTP client 105 performs time synchronization with the first NTP server 101 through the relay device 104. After the relay device 104 in the client mode detects that the first NTP server 101 and the first NTP client 105 complete a time synchronization session, the working mode of the relay device 104 is switched from the client mode 201 to the transparent transmission mode 202.
The judgment process that the NTP server and the NTP client finish one time of time synchronization session is as follows: when an NTP client sends a time synchronization request message to an NTP server, the relay equipment detects that the type of the received message is a time synchronization request message through a message identification mechanism, records the IP address of the NTP client, the IP address of the NTP server and the message type, and records the message type into a database of the system, wherein the identification mechanism is matched with an NTP protocol port number (user datagram protocol 123) and an NTP protocol type (NTP request message); the intermediate device forwards the time synchronization request message to the NTP server; when the NTP server returns a time synchronization response message, the relay equipment detects the time synchronization response message through a message identification mechanism, if the time synchronization response message is consistent with the IP address of the NTP client recorded in a database of the system and the IP address of the NTP server, and the message type is a response message, the time synchronization session between the NTP client and the server is recorded, wherein the identification mechanism is matched with an NTP protocol port number (user datagram protocol 123) and the NTP protocol type (NTP response message); and then the relay equipment forwards the response message to the NTP client.
The relay device 104 determines whether a time synchronization session is completed between the first NTP client 105 and the first NTP server 101 according to the above determination process, and in the case of yes, the relay device 104 immediately enters the transparent transmission mode 202 from the client mode 201.
In one aspect, the relay device 104 in the pass-through mode only forwards messages from the first NTP server 101 and the first NTP client 105 to complete the interaction between the first NTP server 101 and the first NTP client 105, the relay device 104 is transparent to the first NTP server 101 and the first NTP client 105, and the first NTP server 101 and the first NTP client 105 are unaware of the existence of the relay device 104.
On the one hand, the relay device 104 in the transparent transmission mode sends a time synchronization request message to the first NTP server 101 according to the intermediate frequency (second set frequency), receives a time synchronization response message returned by the first NTP server 101, and calculates the round-trip delay and the response delay of the transmission of the synchronization request message according to the foregoing formulas (1) and (2), so as to update the locally stored average round-trip delay and average response delay related to the first NTP server 101. Preferably, the second set frequency is 8-1Time synchronization request messages are sent to the NTP server every second, i.e., every 8 seconds.
Specifically, taking the first time synchronization request message sent by the relay device 104 after entering the transparent transmission mode as an example, the relay device 104 in the transparent transmission mode updates the locally stored average round trip delay and average response delay related to the first NTP server 101 according to the following formulas.
t_rtt_avg2=(t_rtt_avg1+t_rtt_x)/2 (5)
t_proc_avg2=(t_proc_avg1+t_proc_x)/2 (6)
Wherein t _ rtt _ avg2 is the updated average round-trip delay, and t _ proc _ avg2 is the updated average response delay; t _ rtt _ avg1 is the initial average round trip delay, t _ proc _ avg1 is the initial average response delay; t _ rtt _ x is the round trip delay calculated this time, and t _ proc _ x is the response delay calculated this time.
After t _ rtt _ avg2 and t _ proc _ avg2 are obtained through calculation, the transparent transmission state is realizedAccording to a second set frequency (which may be set to 8)-1Times/second), updating according to the average round-trip delay and the average response delay stored locally at present, and the round-trip delay and the response delay obtained by calculation.
In one aspect, because the first NTP server 101 is selected as the NTP server for updating the local system time of the relay device 104, when the relay device 104 is in the pass-through mode, the relay device 104 still needs to follow a low frequency (a fourth set frequency, such as 64) in the form of an NTP client-1Sub/sec) sends a time synchronization request message to the first NTP server 101 to synchronously update the system time.
On the other hand, after the relay device 104 enters the transparent transmission mode, it follows a third set frequency (the third set frequency may be set to 8)-1Sub/second) to the first NTP server 101, the failure detection request message (NTP request message) is used to determine the state of the first NTP server 101, including a failed state and a normal state.
Specifically, the status determination process of the NTP server is as follows: when the relay device does not receive the fault detection response message sent by the NTP server within a set time (for example, within 3 seconds), it is determined that a timeout event occurs; if the relay device does not receive the fault detection response message returned by the NTP server for a set number of times (for example, 3 times) continuously, judging that the NTP server has a fault or a link between the NTP server and the relay device has a fault, and marking that the NTP server is in a fault state. The set time length may be determined by a person skilled in the art according to the length of a link between the relay device and the NTP server, the message congestion condition, and the like.
In an implementation scenario, the second setting frequency is equal to the third setting frequency, that is, the time synchronization request message for updating the average round-trip delay and the average response delay and the fault detection request message for determining the state of the NTP server may be sent to the NTP server by using the same NTP message. Of course, the message may also be sent to the NTP server in different frequency and different message forms, which is not limited in this application.
After determining that the first NTP server 101 is in the failure state, the forwarding mode 203 further determines, by the relay device 104, states of other NTP servers connected to the relay device, that is, states of the second NTP server 102 and the third NTP server 103, and when determining that at least one of the other NTP servers (the second NTP server 102 and the third NTP server 103) is in the normal state, the relay device 104 immediately switches from the transparent transmission mode 202 to the forwarding mode 203.
On one hand, after receiving the time synchronization request message sent from the first NTP client 105 to the first NTP server 101, the relay device 104 in the forwarding mode determines a first target NTP server, which is one of the determined other NTP servers in a normal state, forwards the time synchronization request message to the first target NTP server, and sends the received time synchronization response message to the first NTP client 105, so that the first NTP client 105 completes the process.
Specifically, the determination process of the first target NTP server is as follows: when the relay equipment determines that only one NTP server in a plurality of currently connected NTP servers is in a normal state, the relay equipment directly determines that the only NTP server in the normal state is a target NTP server; when the relay device determines that at least two NTP servers among a plurality of currently connected NTP servers are in a normal state, the relay device determines the first target NTP server in three ways:
the first method is as follows: querying locally stored average round-trip delay of each NTP server of the at least two NTP servers (i.e., average round-trip delay of the second NTP server 102 and average round-trip delay of the third NTP server 103), and selecting the NTP server with the shortest average round-trip delay as a first target NTP server; alternatively, the locally stored initial average round trip delay of each of the at least two NTP servers (i.e., the initial average round trip delay of the second NTP server 102 and the initial average round trip delay of the third NTP server 103) is queried, and the NTP server with the shortest initial average round trip delay is selected as the first target NTP server.
The second method comprises the following steps: the method comprises the steps of inquiring a first NTP server stored locally and the average round-trip delay of each NTP server in the at least two NTP servers (namely the average round-trip delay of the second NTP server 102 and the average round-trip delay of the third NTP server 103), carrying out difference operation on the average round-trip delay of the first NTP server and the average round-trip delay of each NTP server in the at least two NTP servers, selecting the NTP server corresponding to the average round-trip delay difference with the minimum absolute value as the first target NTP server, in other words, selecting the NTP server corresponding to the average round-trip delay closest to the average round-trip delay of the first NTP server as the first target NTP server.
The third method comprises the following steps: an NTP server that provides system time synchronization services for the relay device is selected as a first target NTP server. In the above-described embodiment of the present application, the first NTP server 101 is selected as the NTP server for updating the local system time of the relay device 104, and in this case, the first target NTP server is the second target NTP server selected by the relay device 104 according to the set selection rule.
On the one hand, since the first NTP server 101 is selected as the NTP server for updating the local system time of the relay device 104, after the relay device is switched from the transparent transmission mode 202 to the forwarding mode 203, the relay device 104 in the forwarding mode selects a second target NTP server from the at least two NTP servers according to the set selection rule, where the second target NTP server is used for providing the synchronization service of the local system time for the relay device 104. Thereafter, relay device 104 follows the low frequency (64)-1Sub/second) sends a time synchronization request message to the second target server to update the local system time of the relay device 104.
It should be noted that, the set selection rule may be an NTP server that sequences and records the initial average round-trip delay between each NTP server and the intermediate device, and selects an NTP server in which the initial average round-trip delay is the smallest and which is in a normal state as the relay device to perform system time synchronization; further, after the selected NTP server is marked as a fault state, querying the sorted initial average round-trip delay, and selecting the NTP server with the minimum initial average round-trip delay and in a normal state as the NTP server for performing system time synchronization on subsequent relay equipment; of course, the set selection rule may be other existing selection rules, which is not limited in the present application.
On the other hand, the relay device 104 in the forwarding mode continues to transmit the failure detection request message to the first NTP server 101 identified as the failed state at the third set frequency, so as to continue to detect whether the failure of the first NTP server 101 is recovered or whether the link failure is resolved between the first NTP server 101 and the relay device 104.
Specifically, the failure recovery determination process is as follows: the relay equipment judges whether a fault detection response message is received every time, and the overtime is set duration; if the failure detection response message is received for the continuously set number of times, it is determined that the failure of the NTP service has recovered or that the failure of the link between the NTP server and the relay device has recovered, and it is marked that the NTP server is in a normal state.
Further, after the relay device 104 determines that the first NTP server 101 is in the normal state, the operation mode of the relay device 104 is immediately switched from the forwarding mode 203 to the transparent transmission mode 202.
After determining that the first NTP server 101 is in the failure state, the relay device 104 further determines the states of the other NTP servers connected to the relay device 104, that is, the states of the second NTP server 102 and the third NTP server 103, and when determining that the other NTP servers (the second NTP server 102 and the third NTP server 103) are in the failure state, the relay device 104 immediately switches from the transparent transmission mode 202 to the relay service mode 204.
On one hand, the relay device 104 in the relay service mode receives a time synchronization request message sent from the first NTP client 105 to the first NTP server 101, and the relay device 104 in the relay service mode simulates the first NTP server 101 to return a time synchronization response message to the first NTP client 105, so as to assist the first NTP client 105 in completing time synchronization.
On the other hand, the relay device 104 in the relay service mode continues to transmit the failure detection request message to the first NTP server 101 identified as the failed state at the third set frequency, so as to continue to detect whether the failure of the first NTP server 101 is recovered or whether the link failure is resolved between the first NTP server 101 and the relay device 104.
Further, when the relay device 104 determines that the first NTP server 101 is in the normal state, the operation mode of the relay device 104 is immediately switched from the relay service mode 204 to the transparent transmission mode 202.
In some embodiments, the relay device 104 in the forwarding mode detects that the first NTP server 101 is still in the failed state, and the relay device 104 switches from the forwarding mode 203 to the relay service mode 204 immediately after all other NTP servers connected to the relay device 104 are in the failed state.
In other embodiments, the relay device 104 in the relay service mode detects that the first NTP server 101 is still in the failure state, and the relay device 104 switches from the relay service mode 204 to the forwarding mode 203 immediately after at least one of the other NTP servers connected to the relay device 104 is in the normal state.
It should be noted that the above-mentioned operation mode switching is applied to each NTP server connected to the relay device, and the operation in the corresponding operation mode is completed for each NTP server relay device.
For example, if the first NTP server 101 is in the forwarding mode 203 and the selected target NTP server is the second NTP server 102, the operation mode of the relay device 104 is the transparent transmission mode for the second NTP server 102.
For example, the relay device 104 transmits the failure detection request message to the first NTP server 101 at the third set frequency, and also transmits the failure detection request message to the second NTP server 102 and the third NTP server 103 at the third set frequency.
For another example, when the relay device 104 is in the transparent transmission mode 202 for the first NTP server 101 and the relay device 104 is also in the transparent transmission mode 202 for the second NTP server 102, the relay device 104 sends a time synchronization request message to the first NTP server 101 at the second set frequency to update the locally stored average round trip delay and average response delay associated with the first NTP server 101, and the relay device 104 also sends a time synchronization request message to the second NTP server 102 at the second set frequency to update the locally stored average round trip delay and average response delay associated with the second NTP server 102.
When a first NTP server is in a failure state, an embodiment of the present application provides a time synchronization method, in which at least two NTP servers are connected to a relay device, where the at least two NTP servers include the first NTP server, a working mode of the relay device of the first NTP server is a forwarding mode, and a relay device in the forwarding mode cooperates with an NTP client to complete time synchronization.
Referring to fig. 3, a schematic flow chart of a time synchronization method according to an embodiment of the present application is shown.
As shown, the method flow includes:
s301: when the relay device detects that the first NTP server is in a fault state, and at least one NTP server in the at least two NTP servers is in a normal state, the working mode of the relay device is switched from a transparent transmission mode to a forwarding mode.
Specifically, the relay device sends a fault detection request message to the first NTP server according to a third set frequency, and if the relay device does not receive a fault detection response message sent by the first NTP server within a set time length for a continuously set number of times, the relay device marks that the first NTP server is in a fault state; after the relay device determines that the first NTP server is marked as a fault state and further determines that at least one NTP server in other NTP servers connected with the relay device is marked as a normal state, the working mode of the relay device is immediately switched from a transparent transmission mode to a forwarding mode.
In some embodiments, the operational modes of the relay device further include a client mode; after the relay device in the client mode detects that the first NTP server and the first NTP client finish a time synchronization session, the working mode of the relay device is switched from the client mode to the transparent transmission mode.
In some embodiments, before the relay device in client mode detects that the first NTP server and the first NTP client complete a time synchronization session, further comprising: the relay equipment in the client mode continuously sends a second time synchronization request message to the first NTP server for N times according to the first set frequency, wherein the second time synchronization request message carries a timestamp for sending the second time synchronization request message by the relay equipment; the relay equipment in the client mode determines N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the first NTP server sending the second time synchronization response message; and the relay equipment in the client mode performs average operation on the N round-trip time delays to obtain and record initial average round-trip time delays, and performs average operation on the N response time delays to obtain and record initial average response time delays.
In other embodiments, after the operation mode of the relay device is switched from the client mode to the transparent transmission mode, the method further includes: the relay equipment in the transparent transmission mode sends a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message; the relay equipment in the transparent transmission mode receives a third time synchronization response message sent by the first NTP server; the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message; and the relay equipment in the transparent transmission mode updates the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the relay equipment for receiving the third time synchronization response message.
In other embodiments, the locally stored time information includes an initial average round trip delay and an initial average response delay; the method for updating the locally stored average round-trip delay and average response delay by the relay device in the transparent transmission mode according to the locally stored time information, the third time synchronization response message and the timestamp of the third time synchronization response message received by the relay device includes: the relay equipment in the transparent transmission mode carries out summation operation on the first time length and the second time length to obtain round-trip time delay, and carries out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time length is a difference value between a timestamp of the first NTP server for receiving the third time synchronization request message and a timestamp of the relay equipment for sending the third time synchronization request message, and the second time length is a difference value between a timestamp of the relay equipment for receiving the third time synchronization response message and a timestamp of the first NTP server for sending the third time synchronization response message; and the relay equipment in the transparent transmission mode averagely calculates the difference between the timestamp of the first NTP server for receiving the third time synchronization request message and the timestamp of the first NTP server for sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
S302: the method comprises the steps that a relay device in a forwarding mode receives a first time synchronization request message sent by a first NTP client, wherein a destination address carried by the first time synchronization request message is the address of a first NTP server.
After the working mode of the relay device is switched to the forwarding mode, the relay device in the forwarding mode receives a first time synchronization request message sent from a first NTP client, where a destination address carried in the first time synchronization request message is an address of a first NTP server, that is, the first time synchronization request message is sent to the first NTP server by the NTP client.
In a specific implementation, the relay device in the forwarding mode receives a first time synchronization request message from a first NTP client, and records a source address (i.e., an IP address of the first NTP client) and a destination address (i.e., an IP address of a first NTP server) carried in the first time synchronization request message in a forwarding table of the system.
S303: a relay device in a forwarding mode determines a first target NTP server based on locally stored average round trip delays for at least one NTP server.
Specifically, the relay device in the forwarding mode selects one NTP server from at least one NTP server in a normal state as a first target NTP server in response to a first time synchronization request message from an NTP client; when the at least one NTP server includes only one NTP server, the relay device in the forwarding mode determines that the one NTP server is the first target NTP server; when the at least one NTP server includes more than one NTP server, the relay device in the forwarding mode selects the first target NTP server in any one of the three manners; the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay device. The relay device sends a time synchronization request message to an NTP server, and after receiving a time synchronization response message returned by the NTP server for the time synchronization request message, the relay device obtains a round-trip delay of the NTP server according to a timestamp in the time synchronization response message and the receiving time of the time synchronization response message. Averaging the multiple round-trip delays of the NTP server to obtain the average round-trip delay of the NTP server.
At this time, for the first target NTP server, the operation mode of the relay device is the transparent transmission mode.
The process of acquiring the average round-trip delay of the at least one NTP server is the same as the process of acquiring the average round-trip delay of the first NTP server, and is not described herein again.
S304: the relay device in the forwarding mode sends a first time synchronization request message to the first target NTP server.
Optionally, after determining the first target NTP server, the relay device in the forwarding mode modifies a destination address carried in the first time synchronization request message to an address of the first target NTP server, and modifies the modified first time synchronization request message.
In specific implementation, since the first NTP server is marked as a failure state, after the first target NTP server is selected by the relay device in the forwarding mode, the destination address in the first time synchronization request message is modified into the address of the first target NTP server, and the address is recorded in a forwarding table of the system, and an identification position in the forwarding table is set to 1, so as to indicate that the modified first time synchronization request message is a time synchronization request message obtained after the forwarding mode.
S305: the relay device in the forwarding mode receives a first time synchronization response message sent by the first target NTP server, and sends the first time synchronization response message to the first NTP client.
The first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
Optionally, the first target NTP server sends, in response to receiving the modified first time synchronization request message, a first time synchronization response message to the relay device, where the first time synchronization response message carries a timestamp of the first target NTP server receiving the modified first time synchronization request message, and the first target NTP server sends the timestamp and a source address of the first time synchronization response message, where the source address is an address of the first target NTP server; after receiving the first time synchronization response message, the relay device in the forwarding mode modifies the source address carried in the first time synchronization response message into the address of the first NTP server, and sends the modified first time synchronization response message to the NTP client, so that the NTP client completes time synchronization according to the modified first time synchronization response message.
In specific implementation, after receiving a first time synchronization response message, a relay device in a forwarding mode recognizes that a destination address of the first time synchronization response message is an address of a first NTP client, and a first NTP server providing a time synchronization service for the first NTP client is in a fault state, determines that the first time synchronization response message is a time synchronization response message obtained after the forwarding mode by searching a forwarding table of a system, modifies a source address in the first time synchronization response message into the address of the first NTP server, sends the modified first time synchronization response message to the first NTP client, and sets an identification position in the forwarding table to 0.
In the flow shown in figure 3, for the first NTP server, the relay device is in a forwarding mode; for the first target NTP server, the relay device is in the transparent transmission mode, so that the first target NTP server can respond to not only the time synchronization request message from the NTP client hung down by the first NTP server, but also the time synchronization request message from the NTP client hung down by itself.
In some embodiments, the relay device in the forwarding mode sends a failure detection request message to the first NTP server according to a third set frequency; if the relay equipment in the forwarding mode receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state; and the working mode of the relay equipment is switched from the forwarding mode to the transparent transmission mode.
In other embodiments, the relay device sends a fourth time synchronization request message to the second target NTP server according to a fourth set frequency, the second target NTP server is an NTP server selected by the relay device from at least one NTP server according to the set selection rule, the fourth time synchronization request message is used to update the system time locally stored by the relay device, and the second target NTP server provides a system time synchronization service for the relay device.
In an embodiment of the present application, a relay device establishes a connection with at least two NTP servers, where the at least two NTP servers include a first NTP server, and when the relay device detects that the first NTP server is in a failure state, and at least one of the at least two NTP servers is in a normal state, a working mode of the relay device is switched from a transparent transmission mode to a forwarding mode; the method comprises the steps that relay equipment in a forwarding mode receives a first time synchronization request message sent to a first NTP server by a first NTP client; in response, the relay device in the forwarding mode determines a first target NTP server based on the locally stored average round-trip delay associated with the at least one NTP server, sends a first time synchronization request message to the first target NTP server, receives a first time synchronization response message sent by the first target NTP server, and sends the first time synchronization response message to the first NTP client, so that the first NTP client completes time synchronization.
Therefore, when the NTP server is in a fault state, the relay equipment under the forwarding model responds to the time synchronization request message sent by the NTP client hung under the NTP server and sends the time synchronization request message to other NTP servers in a normal state, so that the NTP client completes time synchronization, time synchronization can be carried out without waiting for the fault recovery of the NTP server, and the reliability of time synchronization service is improved.
When a first NTP server is in a failure state, an embodiment of the present application provides a time synchronization method, in which at least two NTP servers are connected to a relay device, where the at least two NTP servers include the first NTP server, a working mode of the relay device of the first NTP server is a relay service mode, and a relay device in the relay service mode cooperates with an NTP client to complete time synchronization.
Referring to fig. 4, a schematic flow chart of a time synchronization method according to an embodiment of the present application is shown.
As shown, the time synchronization method includes.
S401: after the relay device detects that all the NTP servers in the at least two NTP servers are in the fault state, the working mode of the relay device is switched from the transparent transmission mode to the relay service mode.
Specifically, the relay device sends a fault detection request message to at least two connected NTP servers according to a third set frequency, and if the relay device does not receive a fault detection response message sent by any NTP server of the at least two NTP servers within a set time length for a continuously set number of times, marks that the at least two NTP servers are both in a fault state; after the relay device detects that the at least two NTP servers are in the fault state, the working mode of the relay device is immediately switched from the transparent transmission mode to the relay service mode.
S402: the method comprises the steps that a relay device in a relay service mode receives a first time synchronization request message sent by a first NTP client, wherein a destination address carried by the first time synchronization request message is the address of a first NTP server.
A relay device in relay service mode receives a first time synchronization request message sent by a first NTP client to a first NTP server.
S403: the relay device in the relay service mode determines the first time and the second time based on locally stored time information about the first NTP server.
Wherein, the first time is used for indicating a timestamp of the first time request message received by the first NTP server, and the second time is used for indicating a timestamp of the first time response message sent by the first NTP server; the time information at least comprises system time, average response time delay and average round trip time delay; the average round-trip delay is the average transmission delay of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment; the average response time delay is the average time delay of an NTP server for responding time synchronization request messages, namely, an NTP server receives a time synchronization request message from the relay equipment, as a response, after the NTP server returns the time synchronization response message to the relay equipment, the relay equipment can obtain a response time delay of the NTP server according to a timestamp of the time synchronization request message received by the NTP server and a timestamp of the time synchronization response message sent by the NTP server, and a plurality of response time delays of the NTP server are averaged to obtain the average response time delay of the NTP server.
In specific implementation, when the locally stored time information is system time, average round-trip delay and average response time delay, the relay device in the relay service mode performs summation operation on the system time and one half of the average round-trip delay to obtain first time; and the relay equipment in the relay service mode carries out summation operation on the system time, the average response time delay and one half of the average round trip time delay to obtain a second time.
Specifically, the first time and the second time are obtained according to the following formulas.
T21=t_base+t_rtt_avg/2 (7)
T31=t_base+t_rtt_avg/2+t_proc_avg (8)
Wherein, T21Indicating a first time, T31Representing a second time; t _ base represents the system time; t _ rtt _ avg represents the average round trip delay, and t _ proc _ avg represents the average response delay.
The time information locally stored by the relay device is obtained when the relay device is in the client mode and when the relay device is in the transparent transmission mode.
In some embodiments, in the initial stage, the relay device does not have a first NTP client off-hook, and for the first NTP server, the working mode of the relay device is the client mode; the relay equipment in the client mode continuously sends a second time synchronization request message to the first NTP server for N times according to the first set frequency, wherein the second time synchronization request message carries a timestamp for sending the second time synchronization request message by the relay equipment; the relay equipment in the client mode determines N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the first NTP server sending the second time synchronization response message; and the relay equipment in the client mode performs average operation on the N round-trip time delays to obtain and record initial average round-trip time delays, and performs average operation on the N response time delays to obtain and record initial average response time delays.
In some embodiments, the operating mode of the relay device is switched from the client mode to the transparent transmission mode; the relay equipment in the transparent transmission mode sends a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message; the relay equipment in the transparent transmission mode receives a third time synchronization response message sent by the first NTP server; the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message; and the relay equipment in the transparent transmission mode updates the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the relay equipment for receiving the third time synchronization response message.
In other embodiments, the locally stored time information includes an initial average round trip delay and an initial average response delay; the method for updating the locally stored average round-trip delay and average response delay by the relay device in the transparent transmission mode according to the locally stored time information, the third time synchronization response message and the timestamp of the third time synchronization response message received by the relay device includes: the relay equipment in the transparent transmission mode carries out summation operation on the first time length and the second time length to obtain round-trip time delay, and carries out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time length is a difference value between a timestamp of the first NTP server for receiving the third time synchronization request message and a timestamp of the relay equipment for sending the third time synchronization request message, and the second time length is a difference value between a timestamp of the relay equipment for receiving the third time synchronization response message and a timestamp of the first NTP server for sending the third time synchronization response message; and the relay equipment in the transparent transmission mode averagely calculates the difference between the timestamp of the first NTP server for receiving the third time synchronization request message and the timestamp of the first NTP server for sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
S404: the relay equipment in the relay service mode sends a first time synchronization response message to the first NTP client, wherein the first time synchronization response message carries a first time and a second time.
The relay equipment in the relay service mode carries the calculated first time and second time in a first time synchronization response message and sends the first time and second time to the first NTP client so that the first NTP client completes time synchronization operation according to the first time and the second time; wherein, the source IP address in the first time synchronization response message is the IP address of the NTP server, and the destination IP address is the IP address of the NTP client.
Further, the relay device in the relay service mode still sends a fault detection request message to the first NTP server currently marked as a fault state according to a third set frequency; and if the number of times of the continuous equipment of the relay equipment in the relay service mode receives the fault detection response message sent by the first NTP server within a set time length, marking that the first NTP server is in a normal state, and switching the working mode of the relay equipment from the relay service mode to a transparent transmission mode.
In some embodiments, the fourth set frequency is lower than the second set frequency, and the second set frequency is lower than the first set frequency; that is, in the initial stage, the relay device in the client mode is at a higher frequency (first set frequency, e.g., 1)-1Time/second) to continuously generate N times of time synchronization request messages to the first NTP server so as to quickly and accurately acquire time synchronization response messages returned by the first NTP server, acquire system time synchronized according to the first NTP server and acquire initial average round-trip delay and initial average response delay; if the first NTP server is selected as the NTP server for the relay device to synchronize the system time, after the initial stage, the relay device (client mode or transparent mode) will be at a lower frequency (a fourth set frequency, such as 64 f) as long as the first NTP server is marked as normal, due to the relay device's own holding capacity and to reduce the link bandwidth load-1Sub/sec) to a first NTPThe server sends a time synchronization request message to acquire a time synchronization response message returned by the first NTP server to complete the synchronization of the local system time; in pass-through mode, the repeater operates at medium frequency (second set frequency, e.g. 8)-1Time/second) to obtain a time synchronization response message returned by the first NTP server, and complete updating of the locally stored average round-trip delay and average response delay, so that the locally stored average round-trip delay and average response delay are updated in a medium-frequency manner, and the updating of the average round-trip delay and average response delay can be completed in the sending period of the first NTP client.
In some embodiments, the second set frequency is equal to the third set frequency, i.e., the relay device is at a medium frequency (e.g., 8)-1Time/second) sending a fault detection request message to the first NTP server to determine the state of the first NTP server; therefore, the relay equipment can judge the state of the first NTP server in the sending period of the first NTP client and complete the switching of the working modes according to the state of the first NTP server, even if the first NTP server fails or a link between the first NTP server and the relay equipment fails, the relay equipment is switched to a forwarding mode or a relay service mode before the next sending period of the first NTP client, the time delay is reduced, and the reliability of time synchronization service is improved.
It should be noted that the time synchronization method provided in the embodiment of the present application is also applicable to a scenario in which one NTP server corresponds to multiple NTP clients. When a plurality of NTP clients are hung on the relay device, if the NTP server fails or a link between the NTP server and the relay device fails, the relay device enters a forwarding mode or a relay service mode, and when at least one of the plurality of NTP clients hung on the relay device sends a time synchronization request message to the relay device, the NTP client in the relay service mode assists the NTP client in completing time synchronization according to the flow shown in fig. 3 or fig. 4.
In the above embodiment of the present application, the relay device establishes a connection with at least two NTP servers, where the at least two NTP servers include a first NTP server, and after the relay device detects that the at least two NTP servers are both in a failure state, the working mode of the relay device is switched from the transparent transmission mode to the relay service mode; a relay device in a relay service mode receives a first time synchronization request message sent to a first NTP server by a first NTP client; in response, the relay device in relay service mode determines a first time and a second time based on locally stored time information about the first NTP server, the first time being indicative of a timestamp at which the first NTP server receives the first time synchronization request message, the second time being indicative of a timestamp at which the first NTP server sends the first time synchronization response message, the relay device in relay service mode sending the first time synchronization response message carrying the first time and the second time to the first NTP client such that the first NTP client completes time synchronization based on the first time and the second time.
The relay device in the relay service mode determines a first time of a time stamp for instructing the NTP server to receive the time synchronization request message and a second time of the time stamp for instructing the NTP server to transmit the time synchronization response message according to the locally stored time information related to the NTP server; therefore, even though all NTP servers connected with the relay equipment are in a fault state, the time synchronization of the hanging NTP client can be completed, and the reliability of the time synchronization service is improved.
The following fault detection request message is taken as NTP request message, N takes value of 15, and high frequency is 1-Second/second, medium frequency 8-1Second/second, low frequency of 64-1For example, the second/second is used to describe the switching process of the working mode of the relay device in detail for the first NTP server.
Referring to fig. 5, a flowchart of switching an operating mode of a relay device according to an embodiment of the present application is provided.
As shown, the handover procedure includes:
s501: in an initial phase, a relay device in client mode determines an initial average round trip delay and an initial average response delay.
Specifically, in the initial stage, the relay device does not hang the NTP client, the working mode of the relay device is the client mode, and the relay device in the client mode is according to 1-1And continuously sending 15 NTP request messages to the first NTP server at the frequency of time/second, determining 15 groups of round-trip time delays and response time delays according to the received 15 NTP response messages and formulas (1) and (2), and further carrying out average operation to obtain initial average round-trip time delay and initial average response time delay.
Further, the first NTP server is selected as the NTP server providing the system time synchronization service for the relay device. Then after the initial phase the relay device in client mode follows 64-1And transmitting the NTP request message to the first NTP server at the frequency of time/second so as to complete the synchronization of the system time of the relay equipment.
S502: and after detecting that the first NTP server and the first NTP client finish a time synchronization session, switching the working mode of the relay equipment from a client mode to a transparent transmission mode.
S503: the relay device in the transparent transmission mode is according to 8-1And transmitting an NTP request message to the first NTP server at the frequency of the second/second so as to detect the state of the first NTP server and update the average round-trip delay and the average response delay stored locally.
Specifically, after the relay device enters the transparent transmission mode, 8 is used-1And the frequency of the second time/second is used for sending an NTP request message to the NTP server to update the average round-trip delay and the average response delay which are stored locally according to the formulas (5) and (6).
Optionally, the first NTP server is selected as the NTP server providing the system time synchronization service for the relay device, and the relay device in the transparent transmission mode is further according to 64-1The frequency of time/second sends NTP request message to NTP server to synchronize system time.
S504: the relay equipment judges whether the first NTP server is in a fault state or not; if yes, executing S505; in the case of no, S503 is executed.
S505: the relay equipment judges whether at least one NTP server in other connected NTP servers is in a normal state; in case of yes, S506 is executed; in the case of no, S509 is executed.
S506: the working mode of the relay equipment is switched from the transparent transmission mode to the forwarding mode.
S507: the relay equipment in the forwarding mode receives an NTP request message from a first NTP client, determines a first target NTP server, and forwards the NTP request message to the first target NTP server so that the first NTP client completes time synchronization.
Optionally, if the first NTP server is selected to provide the system time synchronization service for the relay device in the initial stage, the relay device in the forwarding mode further needs to select a second target NTP server according to a set selection rule to provide the system time synchronization service for the relay device.
S508: relay device in Forwarding mode is according to 8-1And transmitting an NTP request message to the first NTP server at the frequency of time/second so as to detect the state of the first NTP server.
The relay device also has the following 8 while performing S508-1And transmitting an NTP request message to at least one NTP server at the frequency of time/second, and immediately switching the working mode of the relay equipment from a forwarding mode to a relay service mode aiming at the first NTP server after detecting that the at least one NTP server is in a fault state.
S509: and the working mode of the relay equipment is switched from the transparent transmission mode to the relay service mode.
S510: the relay equipment in the relay service mode receives an NTP request message from a first NTP client and determines a first time and a second time so that the first NTP client completes time synchronization.
S511: relay device in relay service mode is according to 8-1And transmitting an NTP request message to the first NTP server at the frequency of time/second so as to detect the state of the first NTP server.
The relay device also has a protocol 8 while performing S511-1And transmitting NTP request messages to other NTP servers at the frequency of time/second, and immediately switching the working mode of the relay equipment from the relay service mode to the forwarding mode for the first NTP server after detecting that at least one of the other NTP servers is in a normal state.
S512: the relay equipment judges whether the first NTP server is in a normal state or not; in case of yes, S513 is performed; in the case of no, the steps shown in S507-S508 are performed or the steps shown in S510-S511 are performed.
S513: the working mode of the relay equipment is switched from a forwarding mode or a relay service mode to a transparent transmission mode.
After S513, the relay service mode in the transparent transmission mode performs the steps shown in S503 to S504.
Based on the same technical concept, embodiments of the present application further provide a relay device, where the communication device may implement the flows performed in fig. 3 to fig. 5 in the foregoing embodiments.
Fig. 6 is a schematic structural diagram of a relay device according to an embodiment of the present application.
As shown, the relay device includes a detection module 601, a mode switching module 602, and a forwarding module 603.
Wherein, the relay device establishes connection with at least two network time protocol NTP servers, the at least two NTP servers include a first NTP server, the relay device includes:
a mode switching module 602, configured to switch a working mode from a transparent transmission mode to a forwarding mode when the detecting module 601 detects that the first NTP server is in a failure state and at least one NTP server of the at least two NTP servers is in a normal state;
a forwarding module 603, configured to receive a first time synchronization request message sent by a first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server; determining a first target NTP server based on locally stored average round trip delay for the at least one NTP server; wherein, the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment; sending the first time synchronization request message to the first target NTP server; receiving a first time synchronization response message sent by the first target NTP server, and sending the first time synchronization response message to the first NTP client; wherein the first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
Optionally, the forwarding module 603 is specifically configured to:
modifying the destination address in the first time synchronization request message into the address of the first target NTP server, and sending the modified first time synchronization request message to the first target NTP server;
the first time synchronization response message received by the relay device in the forwarding mode carries a source address, where the source address is an address of the first target NTP server, and the forwarding module is specifically configured to:
and modifying the source address in the first time synchronization response message into the address of the first NTP server, and sending the modified first time synchronization response message to the first NTP client.
Optionally, the mode switching module 602 is further configured to:
after the detection module 601 detects that all NTP servers in the at least two NTP servers are in a failure state, switching the working mode of the relay device from a transparent transmission mode to a relay service mode;
the relay device further includes a relay service module 604, where the relay service module 604 is specifically configured to:
receiving a first time synchronization request message sent by the first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
determining a first time and a second time based on locally stored time information about a first NTP server, the time information including at least a system time, an average response delay, and an average round trip delay; wherein the first time is a timestamp indicating that the first NTP server received the first time synchronization request message, and the second time is a timestamp indicating that the first NTP server sent a first time synchronization response message; the average response time delay is the average time length of a response time synchronization request message of an NTP server in a normal state;
and sending a first time synchronization response message to the first NTP client, wherein the first time synchronization response message carries the first time and the second time.
Optionally, the operation modes of the relay device further include a client mode, and the mode switching module 602 is further configured to:
after the detection module 601 detects that the first NTP server and the first NTP client complete one time of time synchronization session, the working mode of the relay device is switched from the client mode to the transparent transmission mode.
Optionally, the relay device further comprises a client module 605;
the client module 605 is specifically configured to:
sending a second time synchronization request message to the first NTP server according to a first set frequency for N times continuously, wherein the second time synchronization request message carries a timestamp for sending the second time synchronization request message by the relay equipment; n is an integer greater than 1;
determining N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the second time synchronization response message carries a timestamp of the second time synchronization request message sent by the relay device, and the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the second time synchronization response message sent by the first NTP server;
and carrying out average operation on the N round-trip time delays to obtain initial average round-trip time delay and recording the initial average round-trip time delay, and carrying out average operation on the N response time delays to obtain initial average response time delay and recording the initial average response time delay.
Optionally, the relay device further includes an unvarnished transmission module 606, and after the working mode of the relay device is switched from the client mode to the unvarnished transmission mode, the unvarnished transmission module 606 is specifically configured to:
sending a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message;
receiving a third time synchronization response message sent by the first NTP server; wherein the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message;
and updating the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the third time synchronization response message received by the relay equipment.
Optionally, the locally stored time information includes an initial average round trip delay and an initial average response delay;
the transparent transmission module 606 is specifically configured to:
summing the first time length and the second time length to obtain round-trip time delay, and carrying out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time duration is a difference value between a timestamp of the first NTP server receiving the third time synchronization request message and a timestamp of the relay device sending the third time synchronization request message, and the second time duration is a difference value between a timestamp of the relay device receiving the third time synchronization response message and a timestamp of the first NTP server sending the third time synchronization response message;
and averagely calculating the difference between the timestamp of the first NTP server receiving the third time synchronization request message and the timestamp of the first NTP server sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
Optionally, the time information locally stored by the relay device includes a system time, an average round trip delay, and an average response delay;
the relay service module 604 is specifically configured to:
summing the system time and one half of the average round-trip delay to obtain the first time;
and summing the average response time delay and one half of the average round trip time delay of the system time to obtain the second time.
Optionally, the detecting module 601 is further configured to:
sending a fault detection request message to the first NTP server according to a third set frequency; the failure detection request message is used for determining the state of the first NTP server; the states include a fault state and a normal state;
if the relay equipment receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state;
and if the relay equipment does not receive the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a fault state.
Optionally, the mode switching module 602 is further configured to:
switching the working mode of the relay equipment from a forwarding mode to a transparent transmission mode; alternatively, the first and second electrodes may be,
and switching the working mode of the relay equipment from a relay service mode to a transparent transmission mode.
Optionally, the forwarding module or the relay service module 604 is specifically configured to:
and sending a fourth time synchronization request message to the second target NTP server according to a fourth set frequency, wherein the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored in the relay device.
Based on the same technical concept, the embodiment of the present application further provides a communication device, which can implement the processes performed in fig. 3 to 5 in the foregoing embodiments.
Referring to fig. 7, which is a schematic structural diagram of a communication device according to an embodiment of the present disclosure, as shown in the figure, the base station may include: a processor 701, a memory 702, a transceiver 703, and a bus interface 704.
The processor 701 is responsible for managing the bus architecture and general processing, and the memory 702 may store data used by the processor 701 in performing operations. The transceiver 703 is used for receiving and transmitting data under the control of the processor 701.
The bus architecture may include any number of interconnected buses and bridges, with one or more processors, represented by processor 701, and various circuits, represented by memory 702, being linked together. The bus architecture may also link together various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. The bus interface provides an interface. The processor 701 is responsible for managing the bus architecture and general processing, and the memory 702 may store data used by the processor 701 in performing operations.
The processes disclosed in the embodiments of the present application may be applied to the processor 701, or implemented by the processor 701. In implementation, the steps of the signal processing flow may be implemented by integrated logic circuits of hardware or instructions in the form of software in the processor 701. The processor 701 may be a general purpose processor, a digital signal processor, an application specific integrated circuit, a field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or the like that may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of a method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware processor, or may be implemented by a combination of hardware and software modules in a processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 702, and the processor 701 reads the information in the memory 702 and completes the steps of the signal processing flow in combination with the hardware thereof.
In the embodiment of the present application, for concepts, explanations, detailed descriptions, and other steps related to the technical solutions provided in the embodiment of the present application, which are related to the relay device 600 and the communication apparatus 700, please refer to the descriptions of the foregoing methods or the other embodiments about these contents, and no further description is given here.
It should be noted that the processor referred to in the embodiments of the present application may be a Central Processing Unit (CPU), a general purpose processor, a Digital Signal Processor (DSP), an application-specific integrated circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic devices, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. A processor may also be a combination of computing functions, e.g., comprising one or more microprocessors, a DSP and a microprocessor, or the like. Wherein the memory may be integrated in the processor or may be provided separately from the processor.
Based on the same technical concept, the embodiment of the application also provides a computer readable storage medium. The computer-readable storage medium stores computer-executable instructions for causing a computer to perform the processes performed in fig. 3-5.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, 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 means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (25)

1. A time synchronization method applied to a relay device, wherein the relay device establishes a connection with at least two network time protocol NTP servers, and the at least two NTP servers include a first NTP server, and the method includes:
after the relay device detects that the first NTP server is in a fault state and at least one NTP server in the at least two NTP servers is in a normal state, the working mode of the relay device is switched from a transparent transmission mode to a forwarding mode;
the relay equipment in the forwarding mode receives a first time synchronization request message sent by a first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
determining, by the relay device in a forwarding mode, a first target NTP server based on locally stored average round trip delay for the at least one NTP server; wherein, the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment;
the relay device in the forwarding mode sends the first time synchronization request message to the first target NTP server;
the relay device in the forwarding mode receives a first time synchronization response message sent by the first target NTP server, and sends the first time synchronization response message to the first NTP client; wherein the first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
2. The method of claim 1, wherein said relaying device in said forwarding mode sending said first time synchronization request message to said first target NTP server, comprising:
the relay device in the forwarding mode modifies a destination address in the first time synchronization request message into an address of the first target NTP server, and sends the modified first time synchronization request message to the first target NTP server;
the sending, by the relay device in the forwarding mode, the first time synchronization response message received by the relay device in the forwarding mode carries a source address, where the source address is an address of the first target NTP server, and the sending, by the relay device in the forwarding mode, the first time synchronization response message to the first NTP client includes:
and the relay equipment in the forwarding mode modifies the source address in the first time synchronization response message into the address of the first NTP server and sends the modified first time synchronization response message to the first NTP client.
3. The method of claim 1, wherein the method further comprises:
after the relay equipment detects that all the NTP servers in the at least two NTP servers are in a fault state, the working mode of the relay equipment is switched from a transparent transmission mode to a relay service mode;
the relay equipment in a relay service mode receives a first time synchronization request message sent by the first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
the relay device in relay service mode determines a first time and a second time according to locally stored time information about a first NTP server, the time information including at least a system time, an average response delay, and an average round trip delay; wherein the first time is a timestamp indicating that the first NTP server received the first time synchronization request message, and the second time is a timestamp indicating that the first NTP server sent a first time synchronization response message; the average response time delay is the average time length of a response time synchronization request message of an NTP server in a normal state;
the relay device in the relay service mode sends a first time synchronization response message to the first NTP client, where the first time synchronization response message carries the first time and the second time.
4. The method of any one of claims 1-3, wherein the operational mode of the relay device further comprises a client mode, the method further comprising:
and after the relay equipment in the client mode detects that the first NTP server and the first NTP client finish a time synchronization session, the working mode of the relay equipment is switched to a transparent transmission mode from the client mode.
5. The method of claim 4, wherein prior to the relay device in the client mode detecting that the first NTP server and the first NTP client complete a time synchronization session, further comprising:
the relay equipment in the client mode continuously sends a second time synchronization request message to the first NTP server for N times according to a first set frequency, wherein the second time synchronization request message carries a timestamp of the second time synchronization request message sent by the relay equipment; n is an integer greater than 1;
the relay equipment in the client mode determines N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the second time synchronization response message carries a timestamp of the second time synchronization request message sent by the relay device, and the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the second time synchronization response message sent by the first NTP server;
and in the client mode, the relay equipment performs average operation on the N round-trip time delays to obtain initial average round-trip time delays and records the initial average round-trip time delays, and performs average operation on the N response time delays to obtain initial average response time delays and records the initial average response time delays.
6. The method of claim 4, wherein after the operating mode of the relay device is switched from the client mode to the transparent transmission mode, the method further comprises:
the relay equipment in the transparent transmission mode sends a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message;
the relay equipment in the transparent transmission mode receives a third time synchronization response message sent by the first NTP server; wherein the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message;
and the relay equipment in the transparent transmission mode updates the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the relay equipment for receiving the third time synchronization response message.
7. The method of claim 6, wherein the locally stored time information comprises an initial average round trip delay and an initial average response delay;
the updating, by the relay device in the transparent transmission mode, the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message, and the timestamp at which the relay device receives the third time synchronization response message includes:
the relay equipment in the transparent transmission mode carries out summation operation on the first time length and the second time length to obtain round-trip time delay, and carries out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time duration is a difference value between a timestamp of the first NTP server receiving the third time synchronization request message and a timestamp of the relay device sending the third time synchronization request message, and the second time duration is a difference value between a timestamp of the relay device receiving the third time synchronization response message and a timestamp of the first NTP server sending the third time synchronization response message;
and in the transparent transmission mode, the relay equipment performs average calculation on the difference value between the timestamp of the first NTP server receiving the third time synchronization request message and the timestamp of the first NTP server sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
8. The method according to claim 3, wherein the time information locally stored by the relay device specifically includes a system time, an average round trip delay, and an average response delay;
the relay device in the relay service mode determining a first time and a second time according to locally stored time information, including:
the relay equipment in a relay service mode carries out summation operation on the system time and one half of the average round-trip delay to obtain the first time;
and the relay equipment in the relay service mode carries out summation operation on the system time, the average response time delay and one half of the average round trip time delay to obtain the second time.
9. The method of any one of claims 1-3, further comprising:
the relay equipment sends a fault detection request message to the first NTP server according to a third set frequency; the failure detection request message is used for determining the state of the first NTP server; the states include a fault state and a normal state;
if the relay equipment receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state;
and if the relay equipment does not receive the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a fault state.
10. The method of claim 9, wherein after marking the first NTP server as normal, the method further comprises:
switching the working mode of the relay equipment from a forwarding mode to a transparent transmission mode; alternatively, the first and second electrodes may be,
and switching the working mode of the relay equipment from a relay service mode to a transparent transmission mode.
11. The method of any one of claims 1-3, further comprising:
and the relay equipment sends a fourth time synchronization request message to a second target NTP server according to a fourth set frequency, the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored by the relay equipment.
12. A relay device that establishes connections with at least two network time protocol, NTP, servers, including a first NTP server, the relay device comprising:
the mode switching module is used for switching the working mode from the transparent transmission mode to the forwarding mode after the detection module detects that the first NTP server is in a fault state and at least one NTP server in the at least two NTP servers is in a normal state;
the forwarding module is used for receiving a first time synchronization request message sent by a first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server; determining a first target NTP server based on locally stored average round trip delay for the at least one NTP server; wherein, the average round-trip delay of the NTP server is the average transmission duration of the time synchronization request message and the time synchronization response message between the NTP server and the relay equipment; sending the first time synchronization request message to the first target NTP server; receiving a first time synchronization response message sent by the first target NTP server, and sending the first time synchronization response message to the first NTP client; wherein the first time synchronization response message carries a timestamp of the first target NTP server receiving the first time synchronization request message, and a timestamp of the first target NTP server sending the first time synchronization response message.
13. The relay device of claim 12, wherein the forwarding module is specifically configured to:
modifying the destination address in the first time synchronization request message into the address of the first target NTP server, and sending the modified first time synchronization request message to the first target NTP server;
the first time synchronization response message received by the relay device in the forwarding mode carries a source address, where the source address is an address of the first target NTP server, and the forwarding module is specifically configured to:
and modifying the source address in the first time synchronization response message into the address of the first NTP server, and sending the modified first time synchronization response message to the first NTP client.
14. The relay device of claim 12, wherein the mode switching module is further configured to:
after the detection module detects that all the NTP servers in the at least two NTP servers are in a fault state, the working mode of the relay equipment is switched from a transparent transmission mode to a relay service mode;
the relay device further includes a relay service module, where the relay service module is specifically configured to:
receiving a first time synchronization request message sent by the first NTP client; wherein, the destination address carried by the first time synchronization request message is the address of the first NTP server;
determining a first time and a second time based on locally stored time information about a first NTP server, the time information including at least a system time, an average response delay, and an average round trip delay; wherein the first time is a timestamp indicating that the first NTP server received the first time synchronization request message, and the second time is a timestamp indicating that the first NTP server sent a first time synchronization response message; the average response time delay is the average time length of a response time synchronization request message of an NTP server in a normal state;
and sending a first time synchronization response message to the first NTP client, wherein the first time synchronization response message carries the first time and the second time.
15. The relay device of any of claims 12-14, wherein the operational mode of the relay device further comprises a client mode, the mode switching module further to
And after the detection module detects that the first NTP server and the first NTP client finish a time synchronization session, switching the working mode of the relay equipment from a client mode to a transparent transmission mode.
16. The relay device of claim 15, wherein the relay device further comprises a client module;
the client module is specifically configured to:
sending a second time synchronization request message to the first NTP server according to a first set frequency for N times continuously, wherein the second time synchronization request message carries a timestamp for sending the second time synchronization request message by the relay equipment; n is an integer greater than 1;
determining N round-trip delays and N response delays according to a second time response message returned by the first NTP server each time and a timestamp of receiving the second time synchronization response message each time; the second time synchronization response message carries a timestamp of the second time synchronization request message sent by the relay device, and the first NTP server receives the timestamp of the second time synchronization request message and the timestamp of the second time synchronization response message sent by the first NTP server;
and carrying out average operation on the N round-trip time delays to obtain initial average round-trip time delay and recording the initial average round-trip time delay, and carrying out average operation on the N response time delays to obtain initial average response time delay and recording the initial average response time delay.
17. The relay device of claim 15, wherein the relay device further comprises an unvarnished transmission module, and after the operating mode of the relay device is switched from the client mode to the unvarnished transmission mode, the unvarnished transmission module is specifically configured to:
sending a third time synchronization request message to the first NTP server according to a second set frequency; the third time synchronization request message carries a timestamp for the relay device to send the third time synchronization request message;
receiving a third time synchronization response message sent by the first NTP server; wherein the third time synchronization response message carries a timestamp of the third time synchronization request message sent by the relay device, the first NTP server receives the timestamp of the third time synchronization request message, and the first NTP server sends the third time synchronization response message;
and updating the locally stored average round-trip delay and average response delay according to the locally stored time information, the third time synchronization response message and the timestamp of the third time synchronization response message received by the relay equipment.
18. The relay device of claim 17, wherein the locally stored time information comprises an initial average round trip delay and an initial average response delay;
the transparent transmission module is specifically used for:
summing the first time length and the second time length to obtain round-trip time delay, and carrying out average calculation on the obtained round-trip time delay and the initial average round-trip time delay to obtain and record updated average round-trip time delay; the first time duration is a difference value between a timestamp of the first NTP server receiving the third time synchronization request message and a timestamp of the relay device sending the third time synchronization request message, and the second time duration is a difference value between a timestamp of the relay device receiving the third time synchronization response message and a timestamp of the first NTP server sending the third time synchronization response message;
and averagely calculating the difference between the timestamp of the first NTP server receiving the third time synchronization request message and the timestamp of the first NTP server sending the third time synchronization response message and the initial average response time delay to obtain and record the updated average response time delay.
19. The relay device of claim 14, wherein the time information stored locally by the relay device includes a system time, an average round trip delay, and an average response delay;
the relay service module is specifically configured to:
summing the system time and one half of the average round-trip delay to obtain the first time;
and summing the average response time delay and one half of the average round trip time delay of the system time to obtain the second time.
20. The relay device of any one of claims 12-14, wherein the detection module is further to:
sending a fault detection request message to the first NTP server according to a third set frequency; the failure detection request message is used for determining the state of the first NTP server; the states include a fault state and a normal state;
if the relay equipment receives the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a normal state;
and if the relay equipment does not receive the fault detection response message sent by the first NTP server within the set time length for the continuous set times, marking that the first NTP server is in a fault state.
21. The relay device of claim 20, wherein the mode switching module is further configured to:
switching the working mode of the relay equipment from a forwarding mode to a transparent transmission mode; alternatively, the first and second electrodes may be,
and switching the working mode of the relay equipment from a relay service mode to a transparent transmission mode.
22. The relay device according to claim 12 or 13, wherein the forwarding module is specifically configured to:
and sending a fourth time synchronization request message to a second target NTP server according to a fourth set frequency, wherein the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored by the relay device.
23. The relay device of claim 14, wherein the relay service module is specifically configured to:
and sending a fourth time synchronization request message to a second target NTP server according to a fourth set frequency, wherein the second target NTP server is an NTP server selected from the at least one NTP server according to a set selection rule, and the fourth time synchronization request message is used for updating the system time locally stored by the relay device.
24. A communications apparatus, comprising: a processor, a memory, and a transceiver;
the memory to store computer instructions;
the processor for executing the computer instructions to implement the method of any one of claims 1 to 11.
25. A computer-readable storage medium, characterized in that the storage medium stores computer instructions which, when executed by a processor, implement the method of any of claims 1 to 11.
CN201910904570.6A 2019-09-24 2019-09-24 Time synchronization method, relay equipment and device Active CN110601786B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910904570.6A CN110601786B (en) 2019-09-24 2019-09-24 Time synchronization method, relay equipment and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910904570.6A CN110601786B (en) 2019-09-24 2019-09-24 Time synchronization method, relay equipment and device

Publications (2)

Publication Number Publication Date
CN110601786A CN110601786A (en) 2019-12-20
CN110601786B true CN110601786B (en) 2020-12-22

Family

ID=68862702

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910904570.6A Active CN110601786B (en) 2019-09-24 2019-09-24 Time synchronization method, relay equipment and device

Country Status (1)

Country Link
CN (1) CN110601786B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114697320A (en) * 2020-12-31 2022-07-01 联想企业解决方案(新加坡)有限公司 Edge server and edge server system
CN114553354A (en) * 2021-12-16 2022-05-27 深圳市太铭科技有限公司 Method for keeping clock synchronization of NTP (network time protocol) server

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101094237A (en) * 2007-07-30 2007-12-26 中兴通讯股份有限公司 Method for sharing in load among net elements in IP multimedia sub system
EP2353333B1 (en) * 2008-11-04 2016-09-14 Telefonaktiebolaget LM Ericsson (publ) System and method of downlinking data to an unsynchronized user equipment in a telecommunications network
CN106331202A (en) * 2015-06-30 2017-01-11 中兴通讯股份有限公司 Dynamic host configuration protocol (DHCP) server management method and device
CN107809784A (en) * 2017-10-10 2018-03-16 上海交通大学 The chance method for routing of live video stream is transmitted in multi-hop wireless network

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101146337B (en) * 2006-09-15 2011-04-20 华为技术有限公司 Random access method and system for new access nodes

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101094237A (en) * 2007-07-30 2007-12-26 中兴通讯股份有限公司 Method for sharing in load among net elements in IP multimedia sub system
EP2353333B1 (en) * 2008-11-04 2016-09-14 Telefonaktiebolaget LM Ericsson (publ) System and method of downlinking data to an unsynchronized user equipment in a telecommunications network
CN106331202A (en) * 2015-06-30 2017-01-11 中兴通讯股份有限公司 Dynamic host configuration protocol (DHCP) server management method and device
CN107809784A (en) * 2017-10-10 2018-03-16 上海交通大学 The chance method for routing of live video stream is transmitted in multi-hop wireless network

Also Published As

Publication number Publication date
CN110601786A (en) 2019-12-20

Similar Documents

Publication Publication Date Title
CN110492967B (en) Time synchronization method, relay equipment and device
US9876596B2 (en) Method and device for detecting fault in synchronization link
CN110971698B (en) Data forwarding system, method and device
CN106330475B (en) Method and device for managing main and standby nodes in communication system and high-availability cluster
US20160197719A1 (en) Time Synchronization Method and Device
JP2012209791A (en) Network node, time synchronization method, and network system
CN110601786B (en) Time synchronization method, relay equipment and device
CN109495345B (en) BFD processing method and network equipment
EP1601124B1 (en) Method and apparatus synchronizing clocks of network nodes
CN101145896B (en) Control system and method for clock synchronization between control stations
CN113746733A (en) Table item synchronization method, gateway equipment, networking system and storage medium
CN101262369A (en) Master/slave realization method for dispatching server and dispatching server
CN105024798A (en) Method and device for time synchronization
CN100484142C (en) Method and device for correting time of customer end through network time protocol
CN110098884B (en) Method and apparatus for determining an anomalous clock
CN102158335B (en) Method and device for processing time synchronization port
US20200213878A1 (en) Method and apparatus for controlling network sensors
CN107819591B (en) Data synchronization method, device, system and network equipment
EP3232646A1 (en) Apparatus for relaying data transmission in scada system
WO2015096432A1 (en) Method and system for controlling network topology structure
CN111181678B (en) Time synchronization method applied to time-triggered FC network
CN114553354A (en) Method for keeping clock synchronization of NTP (network time protocol) server
KR101973264B1 (en) Clocks timing fault recovery method and apparatus in precision time protocol system
CN105592133A (en) Data migration method and device
JP2020188401A (en) Clock synchronization program, clock synchronization method, communication device, and communication system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant