Method and apparatus for selecting clock source
A method for selecting a clock source includes a first network device that obtains synchronization offset data between the first network device and a second network device through a first port in a clock synchronization failed state. The first network device determines, based on the synchronization offset data, whether to refer to, during clock source selection, clock information received by the first port.
1 . A method implemented by a first network device for selecting a clock source, the method comprising:
receiving, through a first port, a synchronization packet from a second network device, wherein the first port is in a clock synchronization failed state;
determining, based on the synchronization packet, that the port is in a clock synchronization normal state;
receiving, by the first port, clock information after receiving the synchronization packet; and
determining, based on the first port being in the clock synchronization normal state, to refer to the clock information during clock source selection.
2 . The method of claim 1 , wherein a port attribute of the first port comprises tag information, wherein a first value of the tag information indicates that the first port is in the clock synchronization failed state, and wherein the method further comprises setting the tag information to a second value, wherein the second value indicates that the first port is in a clock synchronization normal state.
3 . The method of claim 1 , wherein a state of the first port is a first state, and wherein the method further comprises obtaining synchronization offset data between the first network device and the second network device based on the synchronization packet.
4 . The method of claim 3 , wherein the first state comprises a slave state, a master state, a monitor state, or a passive state.
5 . The method of claim 4 , further comprising setting the state of the first port to the first state.
6 . The method of claim 5 , wherein setting the state of the first port to the first state comprises periodically setting the state of the first port to the first state, wherein the first state comprises the slave state, the monitor state, or the passive state.
7 . The method of claim 4 , further comprising controlling, when the first state is the slave state, a clock of the first network device to not be adjusted based on a clock input signal of the first port.
8 . The method of claim 3 , further comprising obtaining synchronization data between the first network device and the second network device, wherein obtaining the synchronization data comprises:
receiving a Sync packet from the second network device, wherein the Sync packet comprises a first sending time T1 indicating when the Sync packet was sent;
determining a first receiving time T2 at which the Sync packet is received;
sending a delay request (Delay_Req) packet to the second network device at a second sending time T3;
determining T3; and
receiving a delay response (Delay_Resp) packet from the second network device, wherein the Delay_Resp packet comprises a second receiving time T4 based on the Delay_Req packet, and wherein the synchronization data comprises at least one of T1, T2, T3, or T4.
9 . The method of claim 8 , further comprising obtaining synchronization offset data between the first network device and the second network device according to the synchronization data, wherein the synchronization offset data comprises a time offset between the first network device and the second network device.
10 . The method of claim 1 , further comprising obtaining synchronization data between the first network device and the second network device, wherein obtaining the synchronization data comprises:
receiving, through the first port, a first physical clock signal from the second network device; and
obtaining synchronization offset data between the first network device and a second network device by obtaining a frequency offset between the first network device and the second network device based on the first physical clock signal and a second physical clock signal, wherein the second physical clock signal is a local signal of the first network device.
11 . The method of claim 10 , further comprising controlling a clock of the first network device to not be adjusted based on the first physical clock signal.
12 . A first network device comprising:
one or more processors; and
a memory configured to store program instructions, which, when executed by the one or more processors, cause the first network device to:
receive, through a first port, a synchronization packet from a second network device, wherein the first port is in a clock synchronization failed state;
determine, based on the synchronization packet, that the port is in the clock synchronization normal state;
receive, by the first port, clock information after receiving the synchronization packet; and
determine, based on the first port being in the clock synchronization normal state, to refer to the clock information during clock source selection.
13 . The first network device of claim 12 , wherein a port attribute of the first port comprises tag information, wherein a first value of the tag information indicates that the first port is in the clock synchronization failed state; and wherein the program instructions further cause the first network device to set the tag information to a second value, wherein the second value indicates that the first port is in a clock synchronization normal state.
14 . The first network device of claim 12 , wherein a state of the first port is a first state, and wherein the program instructions further cause the first network device to obtain synchronization offset data between the first network device and the second network device based on the synchronization packet.
15 . The first network device of claim 14 , wherein the first state comprises a slave state, a master state, a monitor state, or a passive state.
16 . The first network device of claim 15 , wherein the program instructions further cause the first network device to set the state of the first port to the first state.
17 . The first network device of claim 16 , wherein the program instructions further cause the first network device to periodically set the state of the first port to the first state.
18 . The first network device of claim 15 , wherein the program instructions further cause the first network device to control, when the first state is the slave state, a clock of the first network device to not be adjusted based on a clock input signal of the first port.
19 . The first network device of claim 14 , wherein the program instructions further cause the first network device to obtain synchronization data between the first network device and the second network device, wherein the program instructions to obtain the synchronization data comprises program instructions to:
receive a Sync packet from the second network device, wherein the Sync packet comprises a first sending time T1 indicating when the Sync packet was sent;
determine a first receiving time T2 at which the Sync packet is received;
send a delay request (Delay_Req) packet to the second network device at a second sending time T3;
determine T3; and
receive a delay response (Delay_Resp) packet from the second network device, wherein the Delay_Resp packet comprises a second receiving time T4 based on the Delay_Req packet, and wherein the synchronization data comprises at least one of T1, T2, T3, or T4.
20 . The first network device of claim 14 , wherein the synchronization offset data comprises a time offset between the first network device and the second network device.
21 . The first network device of claim 12 , wherein the program instructions further cause the first network device to:
receive, through the first port, a first physical clock signal from the second network device; and
obtain a frequency offset between the first network device and the second network device based on the first physical clock signal and a second physical clock signal, wherein the second physical clock signal is a local signal of the first network device.
22 . The first network device of claim 21 , wherein the program instructions further cause the first network device to control a clock of the first network device to not be adjusted based on the first physical clock signal.
23 . A computer program product comprising computer-executable instructions that are stored on a non-transitory computer-readable medium and that, when executed by one or more processors, cause a first network device to:
receive, through a first port, a synchronization packet from a second network device, wherein the first port is in a clock synchronization failed state;
determine, based on the synchronization packet, that the port is in the clock synchronization normal state;
receive, by the first port, clock information after receiving the synchronization packet; and
determine, based on the first port being in the clock synchronization normal state, to refer to the clock information during clock source selection.
24 . The computer program product of claim 23 , wherein a port attribute of the first port comprises tag information, wherein a first value of the tag information indicates that the first port is in the clock synchronization failed state, and wherein the computer-executable instructions when executed by the one or more processors further cause the first network device to set the tag information to a second value, wherein the second value indicates that the first port is in a clock synchronization normal state.
25 . The computer program product of claim 23 , wherein a state of the first port is a first state, and wherein the first state comprises a slave state, a master state, a monitor state, or a passive state.
26 . The computer program product of claim 23 , wherein the computer-executable instructions when executed by the one or more processors further cause the first network device to obtain synchronization data between the first network device and the second network device through the synchronization packet, wherein the computer-executable instructions to obtain the synchronization data comprises computer-executable instructions to:
receive a synchronization (Sync) packet from the second network device, wherein the Sync packet comprises a first sending time T1 indicating when the Sync packet was sent;
determine a first receiving time T2 at which the Sync packet is received;
send a delay request (Delay_Req) packet to the second network device at a second sending time T3;
determine T3; and
receive a delay response (Delay_Resp) packet from the second network device, wherein the Delay_Resp packet comprises a second receiving time T4 based on the Delay_Req packet, and wherein the synchronization data comprises at least one of T1, T2, T3, or T4.
27 . The computer program product of claim 26 , wherein the computer-executable instructions when executed by the one or more processors further cause the first network device to obtain synchronization offset data between the first network device and the second network device based on the synchronization data, wherein the synchronization offset data comprises a time offset between the first network device and the second network device.
28 . The method of claim 1 , wherein determining that the first port is in the clock synchronization normal state comprises:
obtaining synchronization offset data between the first network device and the second network device based on the synchronization packet; and
determining that the synchronization offset data is less than an offset threshold.
29 . The first network device of claim 12 , wherein the program instructions further cause the first network device to:
obtain synchronization offset data between the first network device and the second network device based on the synchronization packet; and
determine that the first port is in the clock synchronization normal state when the synchronization offset data is less than an offset threshold.
30 . The computer program product of claim 23 , wherein the computer-executable instructions when executed by the one or more processors further cause the first network device to:
obtain synchronization offset data between the first network device and the second network device based on the synchronization packet; and
determine that the first port is in the clock synchronization normal state when the synchronization offset data is less than an offset threshold.