(19)
(11)EP 3 664 375 A1

(12)EUROPEAN PATENT APPLICATION
published in accordance with Art. 153(4) EPC

(43)Date of publication:
10.06.2020 Bulletin 2020/24

(21)Application number: 17922213.8

(22)Date of filing:  23.08.2017
(51)Int. Cl.: 
H04L 12/26  (2006.01)
(86)International application number:
PCT/CN2017/098685
(87)International publication number:
WO 2019/036943 (28.02.2019 Gazette  2019/09)
(84)Designated Contracting States:
AL AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV MC MK MT NL NO PL PT RO RS SE SI SK SM TR
Designated Extension States:
BA ME
Designated Validation States:
MA MD

(71)Applicant: Huawei Technologies Co., Ltd.
Longgang Shenzhen, Guangdong 518129 (CN)

(72)Inventors:
  • WANG, Jinhui
    Shenzhen Guangdong 518129 (CN)
  • CHEN, Liqing
    Shenzhen Guangdong 518129 (CN)
  • NIU, Hongwei
    Shenzhen Guangdong 518129 (CN)
  • QI, Yunlei
    Shenzhen Guangdong 518129 (CN)

(74)Representative: Gill Jennings & Every LLP 
The Broadgate Tower 20 Primrose Street
London EC2A 2ES
London EC2A 2ES (GB)

  


(54)PACKET PROCESSING METHOD AND NETWORK DEVICE


(57) This application provides a packet processing method and a network device. The method includes: receiving a first packet by using a first receiving interface of a media conversion module of a first network device, where the first packet includes a first alignment marker AM; sending a second packet by using a first sending interface of the media conversion module, where the second packet includes the first AM, and the second packet is the first packet processed by the media conversion module; and calculating a time interval T1 between a time at which the media conversion module receives the first packet and a time at which the media conversion module sends the second packet, where the T1 is used to compensate for a first timestamp at which the first network device receives or sends the third packet. According to the method and the network device in the embodiments of this application, a delay of processing a packet by the media conversion module can be accurately determined, and synchronization performance of a 1588 protocol is further improved.




Description

TECHNICAL FIELD



[0001] This application relates to the network communications field, and in particular, to a packet processing method and a network device in the network communications field.

BACKGROUND



[0002] In an existing communications device, most solutions for performing time synchronization between devices are implemented according to a precision time protocol (Precision Time Protocol, PTP) standard of a network measurement and control system proposed by the Institute of Electrical and Electronics Engineers (Institute of Electrical and Electronics Engineers, IEEE), and the standard is also referred to as an IEEE 1588 protocol.

[0003] A core idea of the IEEE 1588 protocol is to use a master-slave clock mode. During synchronization, a master device periodically issues PTP packets, a slave device receives timestamp information sent by the master device. A master-slave line time delay and a master-slave time offset are calculated based on the timestamp information, and a local time is adjusted by using the time offset, so that a slave device time is kept consistent with a master device time, to implement time synchronization.

[0004] The IEEE 1588 protocol requires that a delay between a stamping point and a physical layer medium (for example, an optical fiber) be stable and that there be no asymmetric delay change. However, in an existing network system, there is an asymmetric link delay, and a key to resolve an asymmetric delay problem is how to obtain the delay. In a plurality of current clock synchronization systems, a delay in a PHY chip is largely considered. However, internal processing, such as first in first out (First-In-First-Out, FIFO), also exists between the stamping point and an egress of a media conversion module, and a delay of the internal processing is uncertain. An existing solution is to estimate a delay of the media conversion module based on internal circuit processing. In this solution, the obtained delay may be inaccurate, resulting in relatively low synchronization performance of the 1588 protocol.

SUMMARY



[0005] This application provides a packet processing method and a network device, so as to accurately determine a delay of processing a packet by a media conversion module, and help improve synchronization performance of a 1588 protocol.

[0006] According to a first aspect, a method for measuring a delay is provided, and the method includes: receiving, by a first network device, a first packet by using a first receiving interface of a media conversion module of the first network device, where the first packet includes a first alignment marker AM; sending, by the first network device, a second packet by using a first sending interface of the media conversion module, where the second packet includes the first AM, and the second packet is the first packet processed by the media conversion module; calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM; and receiving, by the first network device, a third packet by using the first receiving interface, and sending, by using the first sending interface, the third packet processed by the media conversion module, where the first network device uses the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.

[0007] A time interval of a packet before and after the packet passes through the media conversion module is recorded, and the time interval is used to correct a timestamp of sending or receiving the packet. This can accurately determine a delay of the packet through internal processing of the media conversion module, and further improve synchronization performance of a 1588 protocol.

[0008] Optionally, the third packet is a packet received after the first network device receives the first packet by using the first receiving interface.

[0009] Optionally, the third packet may also be the first packet.

[0010] Optionally, the step of calculating the T1 may be performed only once, and the calculated T1 is stored in the first network device. When the third packet needs to be sent or received, the T1 is directly used to compensate for a timestamp at which the third packet is sent or received. In other words, the T1 may be used for a plurality of times for subsequent packets.

[0011] Optionally, the media conversion module may be an optical module.

[0012] With reference to the first aspect, in some implementations of the first aspect, the method further includes: receiving, by the first network device, a fourth packet by using a second receiving interface of the media conversion module, where the fourth packet includes a second AM; sending, by the first network device, a fifth packet by using a second sending interface of the media conversion module, where the fifth packet includes the second AM, and the fifth packet is the fourth packet processed by the media conversion module; calculating, by the first network device, a time interval T2 between a time at which the media conversion module receives the fourth packet including the second AM and a time at which the media conversion module sends the fifth packet including the second AM; and receiving, by the first network device, a sixth packet by using the second receiving interface, and sending, by using the second sending interface, the sixth packet processed by the media conversion module, where a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet, and the first network device uses the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.

[0013] Optionally, the sixth packet is a packet received after the first network device receives the fourth packet by using the second receiving interface.

[0014] Optionally, the sixth packet may also be the fourth packet.

[0015] In the foregoing method, a delay of internal processing of the media conversion module is used to compensate for timestamps in both the receiving direction and the sending direction. This can further improve the synchronization performance of the 1588 protocol.

[0016] Optionally, the receiving interface and the sending interface in this application may be multiplexed; to be specific, it may be understood that the first receiving interface may be the second sending interface, and the first sending interface may be the second receiving interface.

[0017] With reference to the first aspect, in some implementations of the first aspect, the calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM includes: recording, by the first network device, a first moment when receiving the first packet by using the first receiving interface and when determining that the first packet includes the first AM; recording, by the first network device, a second moment when sending the second packet by using the first sending interface and when determining that the second packet includes the first AM; and determining, by the first network device, a time interval between the first moment and the second moment as the time interval T1.

[0018] Optionally, the calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM includes: recording moments when the first packet passes through the first receiving interface and the first sending interface of the media conversion module, and determining a time difference between the two recorded moments as the time interval T1.

[0019] Optionally, the determining that the first packet includes the first AM and recording the first moment may also be performed by another control device. Similarly, the determining that the second packet includes the first AM and recording the second moment may also be performed by another control device.

[0020] With reference to the first aspect, in some implementations of the first aspect, the determining, by the first network device, a time interval between the first moment and the second moment as the time interval T1 includes: starting, by the first network device, a counter at the first moment; stopping, by the first network device, the counter at the second moment, and obtaining a count value N, where N is a positive integer, and a clock cycle of the counter is t; and determining N t as the T1.

[0021] Measuring the delay by using the counter is simple and easy to implement. The delay measurement method may be implemented by both hardware and software.

[0022] Optionally, the count value N of the counter may be reported to a central processing unit (Central Processing Unit, CPU), and the CPU calculates the delay T1.

[0023] With reference to the first aspect, in some implementations of the first aspect, the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device sends the third packet includes: using, by the first network device, a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, where the first timestamp is a moment at which the third packet arrives at the first receiving interface.

[0024] With reference to the first aspect, in some implementations of the first aspect, the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device receives the third packet includes: using, by the first network device, a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, where the first timestamp is a moment at which the third packet arrives at the first sending interface.

[0025] With reference to the first aspect, in some implementations of the first aspect, the third packet is a synchronization packet sent by a second network device to the first network device, where the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet. The sixth packet is a delay request packet sent by the first network device to the second network device, where the second network device is a master device of the first network device, and the first network device is a slave device of the second network device. The method further includes: obtaining, by the first network device from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet; and that the first network device uses the T1 to compensate for the first timestamp at which the first network device receives the third packet includes: using, by the first network device, a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, where the first timestamp is a moment at which the synchronization packet arrives at the first sending interface; and that the first network device uses the T2 to compensate for the second timestamp at which the first network device sends the sixth packet includes: using, by the first network device, a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, where the second timestamp is a moment at which the delay request packet arrives at the second receiving interface; and the method further includes: receiving, by the first network device, a delay response packet sent by the second network device, where the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet; obtaining, by the first network device from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and calculating, by the first network device, a time offset between the first network device and the second network device based on the t1, the t2, the t3, and the t4.

[0026] According to a second aspect, a network device is provided, and is configured to perform the method according to any one of the first aspect or the possible implementations of the first aspect. Specifically, the network device includes units that are configured to perform the method according to any one of the first aspect or the possible implementations of the first aspect.

[0027] According to a third aspect, a network device is provided. The network device includes a network interface, a memory, and a processor. The memory is configured to store a computer program. The processor is configured to invoke and run the computer program from the memory, and when the program is run, the processor performs the method according to any one of the first aspect or the possible implementations of the first aspect.

[0028] According to a fourth aspect, a computer storage medium is provided, and is configured to store a computer software instruction used to perform the method according to any one of the first aspect or the possible implementations of the first aspect, and the computer software instruction includes a program designed to perform the foregoing aspects.

[0029] According to a fifth aspect, a computer program product including an instruction is provided. When the computer program product is run on a computer, the computer is enabled to perform the method according to any one of the first aspect or the possible implementations of the first aspect.

BRIEF DESCRIPTION OF DRAWINGS



[0030] 

FIG 1 is a schematic diagram of an IEEE 1588 time synchronization process;

FIG 2 is a possible scenario diagram applied to an embodiment of this application;

FIG. 3 is a schematic block diagram of a packet processing method according to an embodiment of this application;

FIG. 4 is a schematic block diagram of a media conversion module according to an embodiment of this application;

FIG. 5 is a schematic block diagram of a network device according to an embodiment of this application; and

FIG 6 is another schematic block diagram of a network device according to an embodiment of this application.


DESCRIPTION OF EMBODIMENTS



[0031] The following describes the embodiments of the present invention with reference to accompanying drawings.

[0032] In a mobile communications system, to ensure service quality of wireless communications, a communications network and a communications device have a strict requirement for clock synchronization. In particular, with development of a fifth-generation mobile communications technology of the mobile communications network, the mobile communications system also has a stricter requirement for clock synchronization precision. IEEE 1588 was originally generated because precise time control is required in the industrial control field. However, because the IEEE 1588 supports hardware stamping, the IEEE 1588 can obtain high-precision time synchronization of a sub-microsecond us level. In recent years, the IEEE 1588 was introduced into a telecommunications network by the International Telecommunication Union-Telecommunication Standardization Sector (International Telecommunication Union-Telecommunication Sector, ITU-T) to provide precise time synchronization for a time division wireless system such as time division-synchronous code division multiple access (Time Division-Synchronous Code Division Multiple Access, TD-SCDMA), code division multiple access 2000 (Code Division Multiple Access 2000, CDMA 2000), or long term evolution-time division duplex (Long Term Evolution-Time Division Duplex, LTE-TDD).

[0033] With reference to FIG. 1, the following describes in detail a concept, a term, and a requirement of time synchronization, and a technical principle, a networking scenario, and a deployment consideration of the 1588 protocol from a technical perspective.

[0034] FIG. 1 is a schematic diagram of a time synchronization process of an IEEE 1588 protocol. Used packets are a synchronization (Sync) packet, a delay request (Delay_Req) packet, and a delay response (Delay_Resp) packet. A master clock sends a Sync packet to a slave clock at a moment t1, where the Sync packet carries a sending time of a t1 timestamp of the Sync packet. The slave clock receives the Sync packet at a moment t2, generates a t2 timestamp locally, and obtains the t1 timestamp from the Sync packet. The slave clock sends a Delay_Req packet to the master clock at a moment t3, and generates a t3 timestamp locally. The master clock receives the Delay _Req packet at a moment t4, and generates a t4 timestamp locally. Then, the master clock adds the t4 timestamp to the Delay_Resp packet, and returns the Delay _Resp packet including the t4 timestamp to the slave clock. The slave clock receives the Delay _Resp packet, and extracts the t4 timestamp from the packet. In this way, the slave clock obtains four times. A master-slave line Delay and a master-slave time Offset can be calculated from the four timestamps. A line delay from the master clock to the slave clock is set to a delay 1, and a line delay from the slave clock to the master clock is set to a delay 2. A calculation process is as follows:





[0035] It is assumed that Delay 1 = Delay 2 = Delay. The following equations are obtained:





[0036] The slave clock can adjust time of the slave clock based on a calculated offset value, so as to implement synchronization with the master clock. The foregoing calculation is based on an assumption that the link delay from the master clock to the slave clock is equal to the link delay from the slave clock to the master clock.

[0037] FIG. 2 is a schematic diagram of a possible application scenario according to an embodiment of this application. Specifically, FIG. 2 is a partial internal structural diagram of a network device. As shown in FIG. 2, the network device includes an optical module, a PHY chip, a system clock, and a 1588 protocol unit, and delays before and after the optical module are a delay 1 and a delay 2 respectively. The following first describes the modules used in FIG. 2.

[0038] PHY chip (PHY chip): The PHY may be implemented by using a field programmable gate array (field programmable gate array, FPGA) or an application-specific integrated circuit (application specific integrated circuit, ASIC). The PHY may include a serdes, a bit demultiplexer (bit demultiplexer, bit demux) circuit, a first in first out buffer (first in first out buffer, FIFO buffer), a descrambling circuit, and an aggregation circuit. The PHY may be a component in a network interface card (network interface card, NIC), and the NIC may be a line card (line card, LC) or a physical interface card (physical interface card, PIC). The PHY may be connected to a media access controller (media access controller, MAC) by using a media independent interface (media independence interface, MII). The PHY chip may include one PHY or a plurality of PHYs.

[0039] Optical module: In short, the optical module is used for optical-to-electrical conversion. A transmitting interface converts an electrical signal into an optical signal. After the optical signal is transmitted through an optical fiber, a receiving interface converts the optical signal into the electrical signal.

[0040] 1588 protocol unit: 1588 is actually a master-slave synchronization system. In a process of system synchronization, the master clock periodically issues PTP time synchronization and time information, and the slave clock port receives timestamp information sent by the master clock port. The system calculates a master-slave line time delay and a master-slave time offset based on the timestamp information, and adjusts a local time by using the time offset, so that a frequency and a phase of a device time are kept consistent with those of a master device time. The 1588 protocol can simultaneously implement frequency synchronization and phase synchronization.

[0041] System clock: Usually, the system clock is a clock system. The system clock is a circuit that includes an oscillator (a signal source), a timing wake-up device, a frequency divider, and the like. The system clock is a pulse of an entire system. Usually, a processor needs to be driven by the clock to complete instruction execution.

[0042] Usually, a timestamp generated when the network device sends a packet is completed by a service chip next preceding the media conversion module. Similarly, a timestamp generated when the network device receives a packet is completed by a service chip next following the media conversion module. In other words, actually, the timestamp generated when the network device sends the packet does not consider a time during which the packet passes through the media conversion module, and a time of actually sending the packet should be later than the timestamp generated when the packet is sent. The timestamp generated when the network device receives the packet does not consider a time during which the packet passes through the media conversion module. The time of actually receiving the packet should be earlier than the timestamp generated when the packet is received.

[0043] FIG. 3 is a schematic block diagram of a packet processing method 100 according to an embodiment of this application. As shown in FIG. 3, the method 100 may be performed by a control unit in a network device. For example, the control unit may be implemented by a CPU or an FPGA. The method 100 includes the following steps.

S110. A first network device receives a first packet by using a first receiving interface of a media conversion module of the first network device, where the first packet includes a first alignment marker AM

S120. The first network device sends a second packet by using a first sending interface of the media conversion module, where the second packet includes the first AM, and the second packet is the first packet processed by the media conversion module.

S130. The first network device calculates a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM

S140. The first network device receives a third packet by using the first receiving interface, and sends, by using the first sending interface, the third packet processed by the media conversion module.

S150. The first network device uses the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.



[0044] It should be understood that the media conversion module in this embodiment of this application may be a component that converts one type of signal into another type of signal. For example, the media conversion module may be an optical module. In addition to converting an optical signal into an electrical signal, the optical module may further convert the electrical signal into the optical signal. Alternatively, the media conversion module may further be a microwave intermediate radio frequency module or the like. For ease of understanding, the following uses the optical module as an example to describe the technical solutions in this embodiment of this application in detail. However, this embodiment of this application is not limited thereto.

[0045] It should be further understood that, when the T1 is calculated in this embodiment of this application, a data stream may be input into the media conversion module, and the data stream may include a plurality of packets. A person skilled in the art understands that the data stream may be data of a physical layer, and the packet may be data of a MAC layer. The data stream may include a plurality of data blocks, and each data block in the data stream is obtained by performing physical layer encoding on an Ethernet frame stream. An alignment marker (alignment marker, AM) is periodically inserted after the physical layer encoding is performed on the Ethernet frame stream. Such a cycle may be referred to as a data cycle. The AM is also a data block. Inserting the AM into the data stream may mean that the AM is included in a packet. For ease of understanding, the following first describes in detail the data block in the data stream.

[0046] The physical layer encoding may be 8-bit/10-bit encoding, or may be 64-bit/66-bit encoding. When the physical layer encoding is 8-bit/10-bit encoding, a quantity of bits included in one data block is 10. When the physical layer encoding is 64-bit/66-bit encoding, a quantity of bits included in one data block is 66. In the data block of 10 bits, two bits may be a synchronization header. In the data block of 66 bits, two bits may be a synchronization header.

[0047] For example, according to a 100 Gigabit Ethernet (Gigabit Ethernet, GE) standard in an IEEE 802.3ba, data transmitted in one data cycle may be 16384 data blocks. The 16384 data blocks include the AM and 16383 data blocks. The AM is transmitted before the 16383 data blocks. A quantity of bits included in each of the 16384 data blocks is 64. In other words, usually, the data transmitted in one data cycle includes one AM and a plurality of data blocks, and the plurality of data blocks form a data block group. In other words, after the AM is inserted, data blocks other than the AM in the data transmitted in one data cycle are data blocks in the data block group. In the data transmitted in one data cycle, the quantity of bits included in each of the plurality of data blocks is equal to the quantity of bits included in the AM

[0048] Optionally, steps S110, S120, and S130 may be performed only once, and the calculated T1 is stored in the first network device. When the third packet needs to be sent or received, the T1 may be directly used to compensate for the timestamp at which the third packet is sent or received. In other words, steps S140 and S150 may be performed for a plurality of times.

[0049] Optionally, the third packet may be the first packet. In other words, the first network device may compensate, in real time, the timestamp at which the first network device receives or sends the first packet. Specifically, if the first packet is sent by the first network device to a second network device, the first network device may add, to the first packet at the first sending interface of the media conversion module, an interval between the time at which the first packet arrives at the first receiving interface and the time at which the first packet arrives at the first sending interface, so that the second network device can calculate an accurate moment at which the first network device sends the first packet.

[0050] Optionally, the third packet may further be a packet received after the first network device receives the first packet by using the second receiving interface. To be specific, the first network device may calculate a delay in advance, and perform compensation in a subsequent packet. This example is used to describe this application in the following, but this embodiment of this application is not limited thereto.

[0051] Therefore, according to the method for measuring a delay in this embodiment of this application, a time interval before and after a packet passes through the media conversion module is recorded, and the time interval is used to correct a timestamp of sending or receiving a packet. This can accurately determine the delay of the packet through internal processing of the media conversion module, and further improve synchronization performance of a 1588 protocol.

[0052] Optionally, in this embodiment of this application, the calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM includes: recording, by the first network device, a first moment when receiving the first packet by using the first receiving interface and when determining that the first packet includes the first AM; recording, by the first network device, a second moment when sending the second packet by using the first sending interface and when determining that the second packet includes the first AM; and determining, by the first network device, a time interval between the first moment and the second moment as the time interval T1.

[0053] Specifically, the first network device may start a counter at the first moment. The first network device may stop the counter at the second moment, and obtain a count value N, where N is a positive integer, and a clock cycle of the counter is t. Further, the first network device may determine N t as the T1. It should be understood that the clock cycle t of the counter may mean that the count value is increased by 1 at an interval of a time t.

[0054] Measuring the delay by using the counter is simple and easy to implement. The delay measurement method may be implemented by both hardware and software.

[0055] A media conversion module 200 of the network device in FIG. 4 is used as an example to describe the technical solutions in this embodiment of this application in detail. As shown in FIG. 4, the media conversion module 200 includes at least a network interface 210, a service processing unit 220, and a delay measurement unit 230. The media conversion module 200 may be configured to perform some or all of the steps or the procedures of the method 100 for measuring a delay in this embodiment of this application. For example, when a data stream needs to enter the inside of the media conversion module 200, a processing requirement of the service processing unit 220 is that parallel-to-serial conversion of data usually needs to be performed by using the network interface 210. For example, the network interface may be a serdes interface, and the serdes interface may be either a serializer or a deserializer. Parallel-to-serial conversion is a mainstream time division multiplexing (time division multiplexing, TDM) and peer-to-peer (peer-to-peer, P2P) serial communications technology. To be specific, a plurality of low rate parallel signals are converted into high rate serial signals at a transmit end, and high rate serial signals are transmitted through a transmission medium (an optical cable or a copper wire). Finally, the high rate serial signals are converted back into low rate parallel signals at a receive end. The data stream after the parallel-to-serial conversion may be a data stream into which an AM has been inserted. It should be understood that, inserting the AM into the data stream may be performed by the media conversion module 200, or may be performed by a service chip before the data stream flows into the media conversion module 200. This is not limited in this embodiment of this application. Further, a data stream that passes through the network interface 210 may be bypassed to the delay measurement unit 230. The delay measurement unit 230 may identify a specific AM in the data stream. At the same time, the data stream is further processed by the service processing unit 220, and before the data stream flows out of the network interface 210, the data stream is bypassed to the delay measurement unit 230 again, and the specific AM is identified again. At moments at which the delay measurement unit 230 identifies the specific AM twice, the delay measurement unit 230 may respectively generate two pulse signals, and the two pulse signals are recorded as an FP1 and an FP2 respectively. A timer may be started inside the delay measurement unit 230, and the FP1 and the FP2 are used as a start and an end of the timer. A time recorded by the timer at an end moment may be a delay during which the data stream passes through the service processing unit 220. Alternatively, a high-frequency counter may be started inside the delay measurement unit 230. Similarly, the FP1 and the FP2 are used as a start and an end of the counter, and a product of a value recorded by the high-frequency counter at an end moment and a cycle of the high-frequency counter may be used as a delay during which the data stream passes through the service processing unit 220. Finally, the delay measured by the delay measurement unit 230 may be used to correct a timestamp at which the network device receives or sends some packets.

[0056] Optionally, in this embodiment of this application, the method further includes: receiving, by the first network device, a fourth packet by using a second receiving interface of the media conversion module, where the fourth packet includes a second AM; sending, by the first network device, a fifth packet by using a second sending interface of the media conversion module, where the fifth packet includes the second AM, and the fifth packet is the fourth packet processed by the media conversion module; calculating, by the first network device, a time interval T2 between a time at which the media conversion module receives the fourth packet including the second AM and a time at which the media conversion module sends the fifth packet including the second AM; and receiving, by the first network device, a sixth packet by using the second receiving interface, and sending, by using the second sending interface, the sixth packet processed by the media conversion module, where a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet, and the first network device uses the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.

[0057] Similarly, the sixth packet may be the fourth packet, or the sixth packet is a packet received after the first network device receives the fourth packet by using the second receiving interface.

[0058] Specifically, the media conversion module 200 may be a media conversion module of a network device. A delay during which a data stream in either of the receiving direction and the sending direction of the network device passes through the service processing unit 220 in the media conversion module 200 may be measured by using the foregoing method 100. For example, the any direction may be the sending direction or the receiving direction. However, a delay during which a data stream in the other direction passes through the service processing unit in the media conversion module 200 may be measured by using an existing delay measurement method. For example, the delay of the media conversion module may be estimated based on internal circuit processing. In actual application, the method 100 may also be applied in two directions of the network device, to be specific, the method 100 is used in both the receiving direction and the sending direction. This is not limited in this embodiment of this application.

[0059] Optionally, the receiving interface and the sending interface in this embodiment of this application may be multiplexed, to be specific, it may be understood that the first receiving interface may be the second sending interface, and the first sending interface may be the second receiving interface. A delay in one direction may be first measured, and then a delay in the other direction is measured.

[0060] In the foregoing method, a delay of internal processing of the media conversion module is used to compensate for timestamps in both the receiving direction and the sending direction. This can further improve synchronization performance of a 1588 protocol.

[0061] Optionally, in this embodiment of this application, the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device sends the third packet includes: using, by the first network device, a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, where the first timestamp is a moment at which the third packet arrives at the first receiving interface.

[0062] It should be understood that when the first network device sends the packet to the second network device, the packet first needs to be processed by using the service chip in the first network device, and then the processed packet is sent by using the media conversion module. To be specific, in this embodiment of this application, the third packet may be a packet processed by the first service chip.

[0063] Optionally, in this embodiment of this application, the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device receives the third packet includes: using, by the first network device, a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, where the first timestamp is a moment at which the third packet arrives at the first sending interface.

[0064] A 1588 clock synchronization system usually includes a master device and a slave device that exchange a packet. In this case, both the master device and the slave device may include the media conversion module 200. In other words, the foregoing method 100 may be used to correct the timestamps of the receiving direction and the sending direction of the master device. The slave device is used as an example. The slave device may use a sum of the measured T1 and the timestamp of sending a packet as a moment of sending the packet to the master device, and the slave device may also use a difference between the measured T2 and the timestamp of receiving the packet as a moment of receiving the packet sent by the master device. Similarly, when sending the packet to the slave device, the master device may add the measured T1 to the packet so that the slave device may calculate an accurate moment at which the master device sends the packet. In this embodiment of this application, using the method 100 to correct the timestamp for any direction of any device in the 1588 clock synchronization system helps improve the synchronization performance of the 1588 protocol.

[0065] Optionally, in this embodiment of this application, the third packet is a synchronization packet sent by a second network device to the first network device, where the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet. The sixth packet is a delay request packet sent by the first network device to the second network device, where the second network device is a master device of the first network device, and the first network device is a slave device of the second network device. The method further includes: obtaining, by the first network device from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet; and that the first network device uses the T1 to compensate for the first timestamp at which the first network device receives the third packet includes: using, by the first network device, a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, where the first timestamp is a moment at which the synchronization packet arrives at the first sending interface; and that the first network device uses the T2 to compensate for the second timestamp at which the first network device sends the sixth packet includes: using, by the first network device, a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, where the second timestamp is a moment at which the delay request packet arrives at the second receiving interface; and the method further includes: receiving, by the first network device, a delay response packet sent by the second network device, where the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet; obtaining, by the first network device from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and calculating, by the first network device, a time offset between the first network device and the second network device based on the t1, the t2, the t3, and the t4.

[0066] It should be understood that the synchronization packet, the delay request packet, and the delay response packet in this embodiment of this application are the same as a Sync packet, a Delay _Req packet, and a Delay _Resp packet in an existing 1588 protocol clock synchronization system. The three types of packets are all event packets, to be specific, are used to generate and communicate timing packets. For a relationship between packets, refer to FIG. 1 and the description of FIG. 1. For brevity, details are not described herein again.

[0067] It should be further understood that the foregoing packet types are merely used as an example for description, or may also be packets of another type. This is not limited in this embodiment of this application.

[0068] Usually, the foregoing measured delay may be encapsulated in a time correction field in a PTP packet, for example, the time correction field (Correction Field) in a format of the PTP packet.

[0069] The following briefly describes a clock synchronization process by using an example in which the delay measurement method 100 is used for a receiving direction and a sending direction of the master device and the slave device. It is assumed that a timestamp of the Sync packet sent by the master device is t1, a delay in the sending direction measured by the master device by using the delay measurement method 100 is T1, a delay in the receiving direction measured by the slave device by using the delay measurement method 100 is T2, a timestamp at which the slave device receives the Sync packet is t2, a timestamp at which the slave device sends the Delay _Req packet to the master device is t3, a delay in the sending direction measured by the slave device by using the delay measurement method 100 is T3, a delay in the receiving direction measured by the master device by using the delay measurement method 100 is T4, and a timestamp at which the master device receives the Delay Req packet is t4. In this case, the slave device may substitute (t1 + T1), (t2 - T2), (t3 + T3), and (t4 - T4) into the foregoing formula (4) to calculate a time offset between the master device and the slave device.

[0070] Optionally, in this embodiment of this application, the foregoing data cycle of periodically inserting the AM into the data stream may be greater than a delay of processing the data stream by the service processing unit 220. In this way, two AMs identified at an ingress and an egress respectively are necessarily a same AM Alternatively, the data cycle may be less than or equal to the delay of processing the data stream by the service processing unit 220. In this case, the periodically inserted AM may be identified. For example, the AM inserted into a same data stream may be sequentially labelled from 0, 1, .... The two identified AMs need to be the same AM, that is, AMs having a same label. Specifically, the same AM separately identified at the ingress and the egress may be a same bit or byte that separately identifies the same AM at the ingress and the egress, for example, may be a first bit. This is not limited in this embodiment of this application, provided that a same location of the same AM is used.

[0071] Optionally, the delay measurement unit 230 in the media conversion module 200 may also be a control unit outside the media conversion module 200. To be specific, the data stream bypassed from the network interface 210 may be input to a control unit, such as a CPU, outside the media conversion module 200 by using another interface. The CPU records a delay during which the data stream passes through the service processing unit 220.

[0072] FIG. 5 is a schematic block diagram of a network device 300 according to an embodiment of this application. The network device is a first network device. As shown in FIG. 5, the network device 300 includes:

a first receiving unit 310, configured to receive a first packet by using a first receiving interface of a media conversion module of the first network device, where the first packet includes a first alignment marker AM;

a first sending unit 320, configured to send a second packet by using a first sending interface of the media conversion module, where the second packet includes the first AM, and the second packet is the first packet processed by the media conversion module;

a first calculation unit 330, configured to calculate a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM, where

the first receiving unit 310 is further configured to receive a third packet by using the first receiving interface, and

the first sending unit 320 is further configured to send, by using the first sending interface, the third packet processed by the media conversion module; and

a first processing unit 340, configured to use the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.



[0073] Therefore, the network device in this embodiment of this application records a time interval before and after a packet passes through the media conversion module, and uses the time interval to correct a timestamp of sending or receiving the packet. This can accurately determine the delay of the packet through internal processing of the media conversion module, and further improve synchronization performance of a 1588 protocol.

[0074] Optionally, in this embodiment of this application, the network device 300 further includes: a second receiving unit, configured to receive a fourth packet by using a second receiving interface of the media conversion module, where the fourth packet includes a second AM; a second sending unit, configured to send a fifth packet by using a second sending interface of the media conversion module, where the fifth packet includes the second AM, and the fifth packet is the fourth packet processed by the media conversion module; a second calculation unit, configured to calculate a time interval T2 between a time at which the media conversion module receives the fourth packet including the second AM and a time at which the media conversion module sends the fifth packet including the second AM, where the second receiving unit is further configured to receive a sixth packet by using the second receiving interface, the second sending unit is further configured to send, by using the second sending interface, the sixth packet processed by the media conversion module, and a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet; and a second processing unit, configured to use the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.

[0075] Optionally, in this embodiment of this application, the first calculation unit 330 is specifically configured to: record a first moment when receiving the first packet by using the first receiving interface and when determining that the first packet includes the first AM; record a second moment when sending the second packet by using the first sending interface and when determining that the second packet includes the first AM; and determine a time interval between the first moment and the second moment as the time interval T1.

[0076] Optionally, in this embodiment of this application, the first calculation unit 330 is specifically configured to: start a counter at the first moment; stop the counter at the second moment, and obtain a count value N, where N is a positive integer and a clock cycle of the counter is t; and determine N t as the T1.

[0077] Optionally, in this embodiment of this application, the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module. The first compensation unit 340 is specifically configured to: use a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, where the first timestamp is a moment at which the third packet arrives at the first receiving interface.

[0078] Optionally, in this embodiment of this application, the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module. The first compensation unit 340 is specifically configured to: use a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, where the first timestamp is a moment at which the third packet arrives at the first sending interface.

[0079] Optionally, in this embodiment of this application, the third packet is a synchronization packet sent by the second network device to the first network device, where the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet. The sixth packet is a delay request packet sent by the first network device to the second network device, where the second network device is a master device of the first network device, and the first network device is a slave device of the second network device. The network device further includes: a first obtaining unit, configured to obtain, from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet, where the first processing unit 340 is specifically configured to use a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, the first timestamp is a moment at which the synchronization packet arrives at the first sending interface, the second processing unit is specifically configured to use a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, and the second timestamp is a moment at which the delay request packet arrives at the second receiving interface; a third receiving unit, configured to receive a delay response packet sent by the second network device, where the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet; a second obtaining unit, configured to obtain, from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and a third calculation unit, configured to calculate a time offset between the first network device and the second network device based on the t1, the t2, the t3, and t4.

[0080] Optionally, in this embodiment of this application, the media conversion module is an optical module.

[0081] The network device 300 in this embodiment of this application may correspond to the first network device in the method embodiment of this application. In addition, the foregoing and other operations and/or functions of the units in the network device 300 are respectively intended to implement the corresponding procedures of the method 100 in FIG. 3. For brevity, details are not described herein again.

[0082] FIG. 6 is a schematic block diagram of a network device 400 for measuring a delay according to an embodiment of this application. The network device 400 is a first network device. As shown in FIG. 6, the network device 400 includes a network interface 410, a memory 420, and a processor 430. The network interface includes: a receiving interface and/or a sending interface, configured to receive or send a packet. The memory is configured to store an instruction. The processor is configured to: control a first receiving interface of a media conversion module of the first network device to receive a first packet, where the first packet includes a first alignment marker AM; control a first sending interface of the media conversion module to send a second packet, where the second packet includes the first AM, and the second packet is the first packet processed by the media conversion module; calculate a time interval T1 between a time at which the media conversion module receives the first packet including the first AM and a time at which the media conversion module sends the second packet including the first AM; control the network interface to receive a third packet by using the first receiving interface, and control the network interface to send, by using the first sending interface, the third packet processed by the media conversion module; and use the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.

[0083] Therefore, the network device in this embodiment of this application records a time interval before and after a packet passes through the media conversion module, and uses the time interval to correct a timestamp of sending or receiving the packet. This can accurately determine the delay of the packet through internal processing of the media conversion module, and further improve synchronization performance of a 1588 protocol.

[0084] It should be understood that, in this embodiment of this application, the processor 430 may be a CPU. The processor 430 may further be another general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or another programmable logic device, a discrete gate or a transistor logic device, a discrete hardware component, or the like. The general-purpose processor may be a microprocessor, or the processor may be any conventional processor or the like.

[0085] The memory 420 may include a read-only memory and a random access memory, and provide an instruction and data to the processor 430. A part of the memory 420 may further include a non-volatile random access memory. For example, the memory 420 may further store information about a device type.

[0086] In an implementation process, content in the foregoing methods can be implemented by using a hardware integrated logic circuit in the processor 430, or by using instructions in a form of software. The content of the method disclosed with reference to the embodiments of this application may be directly performed by a hardware processor, or may be performed by using a combination of hardware in the processor and a software module. A software module may be located in a mature storage medium in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, or the like. The storage medium is located in the memory 420, and the processor 430 reads information in the memory 420 and completes the content in the foregoing methods in combination with hardware of the processor 430. To avoid repetition, details are not described herein again.

[0087] In a specific implementation, a first calculation unit, a second calculation unit, a third calculation unit, a first processing unit, a second processing unit, a first obtaining unit, and a second obtaining unit in the network device 300 may be implemented by the processor 430 in FIG. 6, and sending units and receiving units in the network device 300 may be implemented by the network interface 410 in FIG. 6.

[0088] A person of ordinary skill in the art may be aware that, in combination with the examples described in the embodiments disclosed in this specification, units and algorithm steps may be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed by hardware or software depends on particular applications and design constraints of the technical solutions. A person skilled in the art may use different methods to implement the described functions for each particular application, but it should not be considered that the implementation goes beyond the scope of the embodiments of this application.

[0089] It may be clearly understood by a person skilled in the art that, for the purpose of convenient and brief description, for a detailed working process of the foregoing system, apparatus, and unit, refer to a corresponding process in the foregoing method embodiments. Details are not described herein again.

[0090] In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the described apparatus embodiment is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented by using some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms.

[0091] The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected depending on actual requirements to achieve the objectives of the solutions of the embodiments.

[0092] In addition, functional units in the embodiments of this application may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.

[0093] When the functions are implemented in the form of a software functional unit and sold or used as an independent product, the functions may be stored in a computer-readable storage medium. Based on such an understanding, the technical solutions of this application essentially, or the part contributing to the prior art, or some of the technical solutions may be implemented in a form of a software product. The computer software product is stored in a storage medium, and includes several instructions for instructing a computer device (which may be a personal computer, a server, or a network device) to perform all or some of the steps of the methods described in the embodiments of this application. The foregoing storage medium includes: any medium that can store program code, such as a USB flash drive, a removable hard disk, a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a magnetic disk, or an optical disc.

[0094] The foregoing descriptions are merely specific implementations of the embodiments of this application, but are not intended to limit the protection scope of the embodiments of this application. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in the embodiments of this application shall fall within the protection scope of the embodiments of this application. Therefore, the protection scope of the embodiments of this application shall be subject to the protection scope of the claims.


Claims

1. A packet processing method, comprising:

receiving, by a first network device, a first packet by using a first receiving interface of a media conversion module of the first network device, wherein the first packet comprises a first alignment marker AM;

sending, by the first network device, a second packet by using a first sending interface of the media conversion module, wherein the second packet comprises the first AM, and the second packet is the first packet processed by the media conversion module;

calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet comprising the first AM and a time at which the media conversion module sends the second packet comprising the first AM; and

receiving, by the first network device, a third packet by using the first receiving interface, and sending, by using the first sending interface, the third packet processed by the media conversion module, wherein

the first network device uses the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.


 
2. The method according to claim 1, wherein the method further comprises:

receiving, by the first network device, a fourth packet by using a second receiving interface of the media conversion module, wherein the fourth packet comprises a second AM;

sending, by the first network device, a fifth packet by using a second sending interface of the media conversion module, wherein the fifth packet comprises the second AM, and the fifth packet is the fourth packet processed by the media conversion module;

calculating, by the first network device, a time interval T2 between a time at which the media conversion module receives the fourth packet comprising the second AM and a time at which the media conversion module sends the fifth packet comprising the second AM; and

receiving, by the first network device, a sixth packet by using the second receiving interface, and sending, by using the second sending interface, the sixth packet processed by the media conversion module, wherein a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet, wherein

the first network device uses the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.


 
3. The method according to claim 1 or 2, wherein the calculating, by the first network device, a time interval T1 between a time at which the media conversion module receives the first packet comprising the first AM and a time at which the media conversion module sends the second packet comprising the first AM comprises:

recording, by the first network device, a first moment when receiving the first packet by using the first receiving interface and when determining that the first packet comprises the first AM;

recording, by the first network device, a second moment when sending the second packet by using the first sending interface and when determining that the second packet comprises the first AM; and

determining, by the first network device, a time interval between the first moment and the second moment as the time interval T1.


 
4. The method according to claim 3, wherein the determining, by the first network device, a time interval between the first moment and the second moment as the time interval T1 comprises:

starting, by the first network device, a counter at the first moment;

stopping, by the first network device, the counter at the second moment, and obtaining a count value N, wherein N is a positive integer, and a clock cycle of the counter is t; and

determining, by the first network device, N t as the T1.


 
5. The method according to any one of claims 1 to 4, wherein the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device sends the third packet comprises:
using, by the first network device, a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, wherein the first timestamp is a moment at which the third packet arrives at the first receiving interface.
 
6. The method according to any one of claims 1 to 4, wherein the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module, and that the first network device uses the T1 to compensate for a first timestamp at which the first network device receives the third packet comprises:
using, by the first network device, a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, wherein the first timestamp is a moment at which the third packet arrives at the first sending interface.
 
7. The method according to claim 2, wherein the third packet is a synchronization packet sent by a second network device to the first network device, the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet, the sixth packet is a delay request packet sent by the first network device to the second network device, the second network device is a master device of the first network device, the first network device is a slave device of the second network device, and the method further comprises:

obtaining, by the first network device from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet; and

that the first network device uses the T1 to compensate for the first timestamp at which the first network device receives the third packet comprises:

using, by the first network device, a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, wherein the first timestamp is a moment at which the synchronization packet arrives at the first sending interface; and

that the first network device uses the T2 to compensate for the second timestamp at which the first network device sends the sixth packet comprises:

using, by the first network device, a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, wherein the second timestamp is a moment at which the delay request packet arrives at the second receiving interface; and

the method further comprises:

receiving, by the first network device, a delay response packet sent by the second network device, wherein the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet;

obtaining, by the first network device from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and

calculating, by the first network device, a time offset between the first network device and the second network device based on the t1, the t2, the t3, and the t4.


 
8. A network device, wherein the network device is a first network device, and the network device comprises:

a first receiving unit, configured to receive a first packet by using a first receiving interface of a media conversion module of the first network device, wherein the first packet comprises a first alignment marker AM;

a first sending unit, configured to send a second packet by using a first sending interface of the media conversion module, wherein the second packet comprises the first AM, and the second packet is the first packet processed by the media conversion module;

a first calculation unit, configured to calculate a time interval T1 between a time at which the media conversion module receives the first packet comprising the first AM and a time at which the media conversion module sends the second packet comprising the first AM, wherein

the first receiving unit is further configured to receive a third packet by using the first receiving interface, and

the first sending unit is further configured to send, by using the first sending interface, the third packet processed by the media conversion module; and

a first processing unit, configured to use the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.


 
9. The network device according to claim 8, wherein the network device further comprises:

a second receiving unit, configured to receive a fourth packet by using a second receiving interface of the media conversion module, wherein the fourth packet comprises a second AM;

a second sending unit, configured to send a fifth packet by using a second sending interface of the media conversion module, wherein the fifth packet comprises the second AM, and the fifth packet is the fourth packet processed by the media conversion module;

a second calculation unit, configured to calculate a time interval T2 between a time at which the media conversion module receives the fourth packet comprising the second AM and a time at which the media conversion module sends the fifth packet comprising the second AM, wherein

the second receiving unit is further configured to receive a sixth packet by using the second receiving interface, and

the second sending unit is further configured to send, by using the second sending interface, the sixth packet processed by the media conversion module, wherein a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet; and

a second processing unit, configured to use the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.


 
10. The network device according to claim 8 or 9, wherein
the first calculation unit is specifically configured to:

record a first moment when receiving the first packet by using the first receiving interface and when determining that the first packet comprises the first AM;

record a second moment when sending the second packet by using the first sending interface and when determining that the second packet comprises the first AM; and

determine a time interval between the first moment and the second moment as the time interval T1.


 
11. The network device according to claim 10, wherein the first calculation unit is specifically configured to:

start a counter at the first moment;

stop the counter at the second moment, and obtain a count value N, wherein N is a positive integer, and a clock cycle of the counter is t; and

determine N t as the T1.


 
12. The network device according to any one of claims 8 to 11, wherein the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module, and the first processing unit is specifically configured to:
use a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, wherein the first timestamp is a moment at which the third packet arrives at the first receiving interface.
 
13. The network device according to any one of claims 8 to 11, wherein the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module, and the first processing unit is specifically configured to:
use a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, wherein the first timestamp is a moment at which the third packet arrives at the first sending interface.
 
14. The network device according to claim 9, wherein the third packet is a synchronization packet sent by a second network device to the first network device, the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet, the sixth packet is a delay request packet sent by the first network device to the second network device, the second network device is a master device of the first network device, the first network device is a slave device of the second network device, and the network device further comprises:

a first obtaining unit, configured to obtain, from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet;

the first processing unit is specifically configured to:

use a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, wherein the first timestamp is a moment at which the synchronization packet arrives at the first sending interface;

the second processing unit is specifically configured to:

use a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, wherein the second timestamp is a moment at which the delay request packet arrives at the second receiving interface;

a third receiving unit, configured to receive a delay response packet sent by the second network device, wherein the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet;

a second obtaining unit, configured to obtain, from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and

a third calculation unit, configured to calculate a time offset between the first network device and the second network device based on the t1, the t2, the t3, and the t4.


 
15. A network device, wherein the network device is a first network device, and the network device comprises a network interface, a memory, and a processor, wherein
the network interface comprises a receiving interface and/or a sending interface, configured to receive and/or send a packet;
the memory is configured to store an instruction; and
the processor is configured to: control a first receiving interface of a media conversion module of the first network device to receive a first packet, wherein the first packet comprises a first alignment marker AM; control a first sending interface of the media conversion module to send a second packet, wherein the second packet comprises the first AM, and the second packet is the first packet processed by the media conversion module; and calculate a time interval T1 between a time at which the media conversion module receives the first packet comprising the first AM and a time at which the media conversion module sends the second packet comprising the first AM; control the network interface to receive a third packet by using the first receiving interface, and control the first sending interface to send the third packet processed by the media conversion module; and use the T1 to compensate for a first timestamp at which the first network device receives or sends the third packet.
 
16. The network device according to claim 15, wherein the processor is further configured to: control a second receiving interface of the media conversion module to receive a fourth packet, wherein the fourth packet comprises a second AM; control a second sending interface of the media conversion module to send a fifth packet, wherein the fifth packet comprises the second AM, and the fifth packet is the fourth packet processed by the media conversion module; calculate a time interval T2 between a time at which the media conversion module receives the fourth packet comprising the second AM and a time at which the media conversion module sends the fifth packet comprising the second AM; control the second receiving interface to receive a sixth packet, and control the second sending interface to send the sixth packet processed by the media conversion module, wherein a receiving direction and a sending direction of the third packet are opposite to those of the sixth packet; and use the T2 to compensate for a second timestamp at which the first network device receives or sends the sixth packet.
 
17. The network device according to claim 15 or 16, wherein the processor is specifically configured to:
record a first moment when controlling the first receiving interface to receive the first packet and when determining that the first packet comprises the first AM; record a second moment when controlling the first sending interface to send the second packet and when determining that the second packet comprises the first AM; and determine a time interval between the first moment and the second moment as the time interval T1.
 
18. The network device according to claim 17, wherein the processor is specifically configured to:

start a counter at the first moment;

stop the counter at the second moment, and obtain a count value N, wherein N is a positive integer, and a clock cycle of the counter is t; and

determine N t as the T1.


 
19. The network device according to any one of claims 15 to 18, wherein the third packet is a packet that is sent by a first service chip of the first network device to a second network device by using the media conversion module, and the processor is specifically configured to:
use a sum of the first timestamp and the T1 as a moment at which the first network device sends the third packet to the second network device, wherein the first timestamp is a moment at which the third packet arrives at the first receiving interface.
 
20. The network device according to any one of claims 15 to 18, wherein the third packet is a packet that is sent by a second network device to a second service chip of the first network device by using the media conversion module, and the processor is specifically configured to:
use a difference between the first timestamp and the T1 as a moment at which the first network device receives the third packet, wherein the first timestamp is a moment at which the third packet arrives at the first sending interface.
 
21. The network device according to claim 16, wherein the third packet is a synchronization packet sent by a second network device to the first network device, the synchronization packet carries a third timestamp at which the second network device sends the synchronization packet, the sixth packet is a delay request packet sent by the first network device to the second network device, the second network device is a master device of the first network device, the first network device is a slave device of the second network device, and the processor is further configured to:

obtain, from the synchronization packet, a moment t1 at which the second network device sends the synchronization packet; and

the processor is specifically configured to:

use a difference between the first timestamp and the T1 as a moment t2 at which the first network device receives the synchronization packet, wherein the first timestamp is a moment at which the synchronization packet arrives at the first sending interface; and

use a sum of the second timestamp and the T2 as a moment t3 at which the first network device sends the delay request packet, wherein the second timestamp is a moment at which the delay request packet arrives at the second receiving interface; and

the processor is further configured to:
control the first receiving interface to receive a delay response packet sent by the second network device, wherein the delay response packet carries a fourth timestamp at which the second network device receives the delay request packet; obtain, from the delay response packet, a moment t4 at which the second network device receives the delay request packet; and calculate a time offset between the first network device and the second network device based on the t1, the t2, the t3, and the t4.


 




Drawing