Loop detection method and apparatus, and storage medium

CN122933476APending Publication Date: 2026-10-16深圳市三旺通信股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611295559.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-25
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0005]本申请的主要目的在于提供一种环路检测方法、装置及存储介质,旨在解决传统的环路检测方式存在环路检测效率低下、检测准确性不高、额外占用业务带宽以及环路检测滞后等问题

Benefits of technology

[0018] One or more technical solutions proposed in this application have at least the following technical effects: By embedding a first device identifier and a first message serial number in the first preamble of the first service message, when the first device receives the first service message including the first preamble sent by the second device, loop detection is achieved through the first device identifier and the first message serial number in the first preamble; thus, compared with the loop detection method based on STP/RSTP ring network protocol, which requires changing the specified port according to the network topology and re-converging after each topology change, this application does not require building a forwarding tree. Even when the network topology changes, loop detection can be achieved using only the preamble, avoiding millisecond or even second-level convergence delays. The loop detection method is simple in steps, achieves microsecond-level real-time loop identification, and improves loop detection efficiency. Meanwhile, based on loop detection using device identifiers and message serial numbers, compared to loop detection using sequence numbers, this application can accurately distinguish the device source of service messages through device identifiers, accurately determine whether received service messages are duplicated, avoid the problems of false deduplication or missed loop detection in multi-device forwarding scenarios, and improve the accuracy of loop detection. At the same time, the detection information of this application is device identifier and message serial number, which is directly embedded in the preamble of the service message itself. There is no need to send separate heartbeat messages or probe messages, which does not occupy service bandwidth, and can accurately identify whether real-time service messages are looped. While ensuring the real-time performance of loop detection, it also avoids the bandwidth overhead caused by additional probe messages occupying network resources, reducing the network load required for loop detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122933476A_ABST
    Figure CN122933476A_ABST
Patent Text Reader

Abstract

The application discloses a loop detection method and device and a storage medium, and relates to the field of communication, and comprises the following steps: when a first service packet sent by a second device is received, a first preamble in the first service packet is acquired, the first preamble comprises a first two-tuple, and the first two-tuple comprises a first device identifier and a first message serial number; a historical two-tuple stored in the first device is acquired, and the historical two-tuple is compared with the first two-tuple; and when a target historical two-tuple matching the first two-tuple exists, it is determined that the first device forms a loop in a ring network. According to the application, the device identifier and the message serial number are embedded in the preamble of the service packet, the loop detection is realized through comparison of the preambles, the loop detection efficiency, the detection accuracy and the detection real-time performance are improved, and no extra bandwidth is occupied.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communications, and in particular to loop detection methods, apparatus and storage media. Background Technology

[0002] Industrial TSN (Time-Sensitive Networking) networks, smart substations, rail transit vehicle networks, and underground industrial ring networks commonly adopt a ring network topology architecture with multi-node cascading and dual-path redundancy. These networks are highly susceptible to loop problems such as link loopback, abnormal device forwarding, duplicate forwarding on dual paths, and packet loop duplication, which can lead to network storms, service jitter, control message corruption, and equipment downtime. Therefore, loop detection of the network environment is necessary.

[0003] Traditional loop detection methods include three types. One method uses the traditional STP (spanning tree protocol) or RSTP (rapid spanning tree protocol) ring network protocol for loop detection. The basic idea is to use switches as nodes to generate a loop-free forwarding tree within the ring network. All data packets are transmitted only along the path indicated by the forwarding tree, thus avoiding broadcast storms. This forwarding tree is rooted at a specific switch, which generates configuration messages through an algorithm and sends them level by level. Non-root switch switches receive the configuration messages, complete their own configurations, and continue forwarding, eventually forming the forwarding tree. If a switch receives configuration messages from the same forwarding tree from two or more ports, a loop is determined to exist. However, this method has a slow convergence speed, making it difficult to meet the stringent latency requirements of microsecond-level services in industrial TSN networks, resulting in low loop detection efficiency. Another approach is loop detection based on IEEE 802.1CB FRER (Frame Replication and Elimination for Redundancy) redundancy deduplication technology. The basic idea is to assign a 24-bit numeric sequence number to each service data packet. When a packet with a duplicate sequence number is received, it is considered a loop copy and discarded. However, this method cannot distinguish the source of the packet's forwarding device. In multi-device forwarding scenarios, sequence number wrapping can easily lead to false deduplication or missed loop detection, resulting in poor accuracy. Yet another approach relies on individual heartbeat packets for detection. The basic idea is that if a sent heartbeat packet is received back from another port on the same device, a loop is considered to exist on that port, and the port is automatically closed to block the storm. However, this method not only requires additional service bandwidth but also cannot identify whether real-time service packets are experiencing loop copying issues. Therefore, traditional loop detection methods suffer from low efficiency, low accuracy, additional service bandwidth consumption, and loop detection lag.

[0004] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention

[0005] The main purpose of this application is to provide a loop detection method, device and storage medium, which aims to solve the problems of low loop detection efficiency, low detection accuracy, additional consumption of service bandwidth and loop detection lag in traditional loop detection methods.

[0006] To achieve the above objectives, this application proposes a loop detection method applied to a first device in a ring network, wherein the ring network includes multiple devices connected based on a ring topology, and the ring network includes a first device and a second device. The loop detection method comprises the following steps: When a first service message sent by the second device is received, a first preamble in the first service message is obtained. The first preamble includes a first tuple, and the first tuple includes a first device identifier and a first message serial number. Obtain the historical tuple cached in the first device, and compare the historical tuple with the first tuple; When a target historical tuple that matches the first tuple exists, it is determined that the first device forms a loop in the ring network.

[0007] For example, the step of obtaining the historical tuple cached in the first device and comparing the historical tuple with the first tuple includes: Obtain the preset device identifier and preset message serial number from the historical tuple, wherein the preset device identifier includes the first preset device identifier corresponding to the first device; When the first device identifier matches the first preset device identifier, the first historical tuple corresponding to the first preset device identifier is obtained; Compare the first preset message serial number of the first historical tuple with the first message serial number; When a first target preset message sequence number exists that matches the first message sequence number, the first historical tuple corresponding to the first target preset message sequence number is taken as the target historical tuple.

[0008] For example, after the step of obtaining the preset device identifier and preset message serial number from the historical tuple, the method further includes: When the first device identifier does not match the first preset device identifier, a second historical tuple other than the first historical tuple is determined from the historical tuples; Compare each second history tuple with the first tuple; The second historical tuple that matches the first tuple is taken as the target historical tuple.

[0009] For example, after determining that the first device forms a loop in the ring network when a target historical tuple matching the first tuple exists, the method further includes: Discard the first service message.

[0010] For example, after the step of obtaining the historical tuple pre-cached in the first device and comparing the historical tuple with the first tuple, the method further includes: If no target historical tuple matches the first tuple, it is determined that the first device has not formed a loop in the ring network; The target device corresponding to the first service message is determined, and the first service message is sent to the target device.

[0011] For example, before the step of determining the target device corresponding to the first service message and sending the first service message to the target device, the method further includes: The first tuple is cached in the first device.

[0012] For example, the loop detection method further includes: Get the cached time corresponding to the historical tuple cached in the first device; The historical tuples that have been cached for longer than the preset aging time are cleared.

[0013] For example, the loop detection method further includes: In response to a service message sending request, obtain the first preset device identifier corresponding to the first device; The second preamble corresponding to the service message to be sent is generated based on the first preset device identifier and the second message serial number corresponding to the service message to be sent. The second preamble and the service message to be sent are combined to generate the second service message; The second service message is sent to the second target device so that the second target device can perform loop detection operation based on the second preamble.

[0014] In addition, to achieve the above objectives, this application also proposes a loop detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the loop detection method described above.

[0015] In addition, to achieve the above objectives, this application also proposes a loop detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the loop detection method described above.

[0016] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the loop detection method described above.

[0017] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the loop detection method described above.

[0018] One or more technical solutions proposed in this application have at least the following technical effects: By embedding a first device identifier and a first message serial number in the first preamble of the first service message, when the first device receives the first service message including the first preamble sent by the second device, loop detection is achieved through the first device identifier and the first message serial number in the first preamble; thus, compared with the loop detection method based on STP / RSTP ring network protocol, which requires changing the specified port according to the network topology and re-converging after each topology change, this application does not require building a forwarding tree. Even when the network topology changes, loop detection can be achieved using only the preamble, avoiding millisecond or even second-level convergence delays. The loop detection method is simple in steps, achieves microsecond-level real-time loop identification, and improves loop detection efficiency. Meanwhile, based on loop detection using device identifiers and message serial numbers, compared to loop detection using sequence numbers, this application can accurately distinguish the device source of service messages through device identifiers, accurately determine whether received service messages are duplicated, avoid the problems of false deduplication or missed loop detection in multi-device forwarding scenarios, and improve the accuracy of loop detection. At the same time, the detection information of this application is device identifier and message serial number, which is directly embedded in the preamble of the service message itself. There is no need to send separate heartbeat messages or probe messages, which does not occupy service bandwidth, and can accurately identify whether real-time service messages are looped. While ensuring the real-time performance of loop detection, it also avoids the bandwidth overhead caused by additional probe messages occupying network resources, reducing the network load required for loop detection. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

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

[0021] Figure 1 This is a flowchart illustrating the first embodiment of the loop detection method of this application; Figure 2 A schematic diagram of a ring network provided in the first embodiment of the loop detection method of this application; Figure 3 This is an example diagram of the data structure of the service message in the first embodiment of the loop detection method of this application; Figure 4 This is a flowchart illustrating the first embodiment of the loop detection method of this application; Figure 5 This is a flowchart illustrating the first embodiment of the loop detection method of this application; Figure 6 This is a detailed flowchart of step S20 in the second embodiment of the loop detection method of this application; Figure 7 This is a schematic diagram of the first device forming a self-loop in a ring network in the second embodiment of the loop detection method of this application; Figure 8 This is a schematic diagram of the first device forming a self-loop in a ring network in the second embodiment of the loop detection method of this application; Figure 9 This is a detailed flowchart of step S20 in the second embodiment of the loop detection method of this application; Figure 10 This is a schematic diagram of a repeating loop formed in a ring network in the second embodiment of the loop detection method of this application; Figure 11 This is a schematic diagram of the device structure of the hardware operating environment involved in the loop detection method in the embodiments of this application.

[0022] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0023] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0024] In this application, the loop detection method can be performed by a loop detection device. This embodiment provides a loop detection device, which can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or loop detection device capable of performing the above functions.

[0025] In related technologies, traditional loop detection methods include three types. One type uses the traditional STP (spanning tree protocol) / RSTP (rapid spanning tree protocol) ring network protocol for loop detection. The basic idea is to use switches as nodes to generate a loop-free forwarding tree in the ring network. All data packets are transmitted only along the path indicated by the forwarding tree, thus avoiding broadcast storms. This forwarding tree is rooted at a switch, which generates configuration messages through an algorithm and sends them level by level. Non-root node switches receive the configuration messages, complete their own configurations, and continue forwarding, eventually forming the forwarding tree. If a switch receives configuration messages from the same forwarding tree from two or more ports, a loop is determined to exist. However, this method has a slow convergence speed, making it difficult to meet the stringent latency requirements of microsecond-level services in industrial TSN networks, resulting in low loop detection efficiency. Another approach is loop detection based on IEEE 802.1CB FRER (Frame Replication and Elimination for Redundancy) redundancy deduplication technology. The basic idea is to assign a 24-bit numeric sequence number to each service data packet. When a packet with a duplicate sequence number is received, it is considered a loop copy and discarded. However, this method cannot distinguish the source of the packet's forwarding device. In multi-device forwarding scenarios, sequence number wrapping can easily lead to false deduplication or missed loop detection, resulting in poor accuracy. Yet another approach relies on individual heartbeat packets for detection. The basic idea is that if a sent heartbeat packet is received back from another port on the same device, a loop is considered to exist on that port, and the port is automatically closed to block the storm. However, this method not only requires additional service bandwidth but also cannot identify whether real-time service packets are experiencing loop copying issues. Therefore, traditional loop detection methods suffer from low efficiency, low accuracy, additional service bandwidth consumption, and loop detection lag.

[0026] This application provides a solution that embeds a first device identifier and a first message serial number into a first preamble in a first service message. When the first device receives a first service message including the first preamble from a second device, loop detection is achieved using the first device identifier and the first message serial number in the first preamble. Compared to loop detection methods based on STP / RSTP ring network protocols, which require changes to specified ports based on the network topology and re-convergence after each topology change, this application eliminates the need to construct a forwarding tree. Even when the network topology changes, loop detection can be achieved using only the preamble, avoiding millisecond-level or even second-level convergence delays. The loop detection method is simple, achieving microsecond-level real-time loop identification and improving loop detection efficiency. Meanwhile, based on loop detection using device identifiers and message serial numbers, compared to loop detection using sequence numbers, this application can accurately distinguish the device source of service messages through device identifiers, accurately determine whether received service messages are duplicated, avoid the problems of false deduplication or missed loop detection in multi-device forwarding scenarios, and improve the accuracy of loop detection. At the same time, the detection information of this application is device identifier and message serial number, which is directly embedded in the preamble of the service message itself. There is no need to send separate heartbeat messages or probe messages, which does not occupy service bandwidth, and can accurately identify whether real-time service messages are looped. While ensuring the real-time performance of loop detection, it also avoids the bandwidth overhead caused by additional probe messages occupying network resources, reducing the network load required for loop detection.

[0027] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0028] First Embodiment Reference Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the loop detection method, which includes steps S10 to S30: Step S10: When the first service message sent by the second device is received, the first preamble in the first service message is obtained. The first preamble includes a first tuple, and the first tuple includes a first device identifier and a first message serial number. Step S20: Obtain the historical tuple cached in the first device, and compare the historical tuple with the first tuple; Step S30: When a target historical tuple that matches the first tuple exists, it is determined that the first device forms a loop in the ring network.

[0029] It's important to note that a network loop, also known as a network loop, is a concept in computer networks that refers to the phenomenon where data packets are transmitted in a loop within the network and fail to reach their destination. This situation typically leads to degraded network performance and may even cause network paralysis. Loops can be divided into two types: physical loops and logical loops. Physical loops are usually caused by misconfigurations of network devices or connecting lines. For example, if two switches are connected via multiple paths, a physical loop may be formed. Logical loops, on the other hand, are caused by incorrect routing table configurations or routing protocol failures. When a router's routing table contains incorrect paths pointing to unreachable networks, data packets will be transmitted in a loop between routers, failing to reach their final destination.

[0030] In this embodiment, the first device applied to the ring network can be an industrial TSN (Time-Sensitive Networking) network, a smart substation, a rail transit vehicle network, an underground industrial ring network, etc. The first device is a switching device in the ring network, which consists of multiple devices connected end-to-end via Ethernet links to form a closed ring topology. Each device in the ring network can be a switching device or a terminal device. The switching device can be a switch, router, gateway, optical line terminal (OLT), access point (AP), or other types of devices, used to forward or process service packets from the terminal devices, and also used to generate service packets and forward or process the generated service packets. The terminal device can be a sensor, programmable logic controller (PLC), industrial camera, data acquisition terminal, human-machine interface, or other types of industrial equipment, used to generate service packets and send them to the ring network, and / or receive service packets from the ring network. For example, refer to... Figure 2 , Figure 2 A schematic diagram of a ring network is shown.

[0031] Optionally, the ring network includes a first device and a second device, which are arranged adjacent to each other in the ring network. The first device can be used to receive service packets sent by the second device and can also send service packets to the second device. The second device can be used to receive service packets sent by the first device and can also send service packets to the first device. The first device is a switching device, that is, the switching device acts as the execution entity for loop detection, performing loop detection on the received service packets. The first device can be an interactive device or a terminal device. The second device is a device in the ring network that sends service packets to the first device. The second device can be a switching device or a terminal device, and this application does not limit it in this way.

[0032] Optionally, the service message is an Ethernet data frame transmitted in a ring network, including but not limited to industrial control data, sensor-collected data, video stream data, and audio stream data sent by terminal devices, as well as network management messages, clock synchronization messages, and protocol interaction messages generated by switching devices. It should be noted that the service message is different from an independent heartbeat detection message or probe message; it carries the effective data payload of the upper-layer service itself.

[0033] Optionally, the service message is a standard Ethernet frame structure. A standard Ethernet frame includes fields such as a preamble, destination MAC address (DMAC), source MAC address (SMAC), Virtual Local Area Network tag (VLAN tag), EtherType / Length, payload, padding, and Frame Check Sequence (FCS), as shown in the reference. Figure 3 , Figure 3 A sample diagram illustrating the data structure of a business message is shown.

[0034] It should be noted that the preamble in a standard Ethernet frame is an 8-byte fixed code. The preamble contains a blank preamble reserved area, which is a customizable extended reserved bit. This allows for the embedding of custom extended fields to carry additional detection information without modifying the standard Ethernet frame structure. Based on this, this application utilizes the preamble reserved area to embed the device identifier and the message serial number as detection information within the preamble. This allows the service message to carry the detection information required for loop detection while simultaneously carrying upper-layer service data. Since the device identifier and the message serial number are located within the preamble, they do not occupy the data load of the service message and do not modify standard fields such as the destination MAC address, source MAC address, virtual LAN tag, and frame check sequence number. Therefore, the service message is fully compatible with the existing Ethernet protocol stack and does not affect the normal processing flow of upper-layer services.

[0035] Optionally, the preamble consists of a reserved field, a device identifier field, a message sequence number field, and a frame start delimiter. Each service message frame corresponds to a unique preamble. The reserved field, device identifier field, and message sequence number field are located before the frame start delimiter. The reserved field occupies 3 bytes, with a default value of 55h 55h 55h. The device identifier field occupies 2 bytes and carries the device identifier of the source device sending the service message. The source device is the device that generates the service message; it can be an switching device or a terminal device. In a ring network, each switching device or terminal device corresponds to a unique device identifier. The message sequence number field occupies 2 bytes and carries the message sequence number assigned by the source device to the generated service message. The message sequence number within a single device is strictly incremented and used to identify each service message sent from the source device. Each time a device generates and sends a message frame, the message sequence number counter automatically increments by 1 and then cycles back to zero. The frame start delimiter occupies 1 byte, with a default value of D5h, and is used to identify the end of the preamble and the beginning of the frame data.

[0036] Optionally, the device identifier field is filled with a device identifier, the value range of which is 0 to 65534, where 5555h is a reserved value and is not used as a device identifier. The message serial number field has a value range of 0 to 65535, where 5555h is a reserved value and is not used as a message serial number. Optionally, the reserved field, the device identifier field, and the message serial number field together constitute the content filled in the custom extension area in the preamble, and this custom extension area is located before the frame start delimiter.

[0037] It should be noted that, for ease of explanation, this application treats the device identifier and message serial number in the same preamble as a set of tuples; each time a device in a ring network generates a service message, it caches the tuples in the generated service message as historical tuples in the device for subsequent tuple comparison; each time a device receives a new service message, it caches the tuples of the received service message as historical tuples in the device for subsequent tuple comparison, and the new service message is the first service message received by the device.

[0038] In this embodiment, the first device, located adjacent to a second device in a ring network, can send its own generated service packets to the second device, forward received service packets to the second device, receive service packets generated by the second device, and receive service packets forwarded by the second device. Optionally, after receiving a first service packet sent by the second device, the first device parses the first service packet, obtains a first preamble, and extracts a first tuple from the first preamble. The first tuple includes a first device identifier and a first message serial number. The first device identifier represents the device identifier of the source device that generated the first service packet. When the source device is a device other than the first device, the first device identifier is the device identifier of that other device; when the source device is the first device, the first device identifier is the device identifier of the first device. The first message serial number represents the generation order of the first service packet generated by the source device.

[0039] Optionally, after extracting the first tuple, a historical tuple cached in the first device is obtained, and the first tuple is compared with the historical tuples. If a target historical tuple matching the first tuple exists in the historical tuples, it is determined that the first device forms a loop in the ring network. The historical tuples cached by the first device include tuples extracted from the preamble of a service message when the first device first receives a service message sent by another device; and tuples extracted from a service message when the first device generates a service message. Each set of historical tuples corresponds to one frame of service message; the first device caches at least one set of historical tuples. It should be noted that the historical tuples are those cached for a preset aging time. When a historical tuple is not matched within the preset aging time, it is cleared from the cache.

[0040] It should be noted that the target device identifier in the target history tuple is the same as the first device identifier in the first tuple, and the target message sequence number in the target history tuple is the same as the first message sequence number in the first tuple. When a target history tuple matching the first tuple exists, and it is determined that the first tuple corresponding to the first service message has been cached in the first device, then it is determined that the first service message was generated by the first device and the first device cached the first tuple in itself, and / or the first device has received the first service message and has cached the first tuple corresponding to the first service message in itself.

[0041] In one embodiment, when the first service message is generated by the first device and the first device caches the first tuple within itself, the first service message received from the second device is a duplicate message. Therefore, it is determined that the first device has formed a loop in the ring network. Herein, a loop is used to characterize that the first service message sent from the first device returns to the first device after being forwarded by other devices in the ring network, that is, the first service message returns to the source device after going around the ring network along a closed path.

[0042] In another embodiment, if the first device has received the first service message and has cached the first tuple corresponding to the first service message in the first device itself, then it is determined that the first service message received from the second device is a duplicate message, then it is determined that the first device has a duplicate loop in the ring network, and then it is determined that the first device has formed a loop in the ring network; wherein, the duplicate loop is used to characterize the transmission path of the first service message generated by other devices besides the first device along different paths in the ring network, and the first device arrives at the first device from different transmission paths, that is, the first service message has received the same first service message successively on two or more paths in the ring network.

[0043] In an alternative embodiment, refer to Figure 4 After determining that the first device forms a loop in the ring network, step S40 is included: Step S40: Discard the first service message.

[0044] Understandably, if it is determined that the first service message was generated by the first device itself, and / or if it is determined that the first service message received at this time is a duplicate message when the first device has already received the first service message, then a loop is formed. In this case, the first service message is directly discarded to block the loop storm and prevent the first service message from being forwarded indefinitely in the ring network. This is to prevent the network bandwidth from being exhausted, the device processing resources from being over-occupied, and the transmission of normal service messages from being blocked, thus ensuring the stable operation of the ring network.

[0045] Optionally, after confirming the existence of a loop in the ring network, an alarm message is output to allow administrators to troubleshoot the loop fault; alternatively, the port corresponding to the loop can be shut down. The alarm message includes the first device identifier of the first device experiencing the loop, port information, and a timestamp indicating that the loop was detected, enabling administrators to quickly locate the loop and perform corresponding troubleshooting operations. Shutting down the port corresponding to the loop involves disabling the port on the first device that receives the first service packet, thus physically blocking the loop path and preventing the loop storm from spreading. It should be noted that after the port is shut down, the first device will no longer forward or receive any service packets through the closed port.

[0046] In another alternative implementation, refer to Figure 5 After step S20, the method further includes: Step S50: If there is no target historical tuple that matches the first tuple, determine that the first device has not formed a loop in the ring network. Step S60: Determine the first target device corresponding to the first service message, and send the first service message to the first target device.

[0047] In an optional embodiment, if it is determined that there is no target historical tuple matching the first tuple, and the first service message is determined to be a normal service message and not a duplicate message, then it is determined that the first service message was not generated and sent by the first device, and / or if it is determined that the first device received the first service message for the first time, then it is determined that the first device has not formed a loop in the ring network.

[0048] Optionally, when it is determined that there is no loop in the ring network, the first service packet is forwarded or uploaded normally. When it is determined that the first service packet is a forwarded packet, the first target device is determined according to the first destination MAC address in the first service packet, the target port corresponding to the first target device is determined, and the first service packet is sent to the first target device through the target port.

[0049] It should be noted that, when it is determined that no target historical tuple matches the first tuple, before sending the first service message to the first target device, the following is executed: The first tuple is cached in the first device.

[0050] Optionally, when it is determined that no target historical tuple matches the first tuple, it is determined that the first device has received the first service message for the first time. The first tuple corresponding to the first service message is cached in the first device, and after caching is completed, step S60 is executed. It should be noted that receiving the first service message for the first time means that the first device has not received any service messages containing the same first tuple. In this case, the first service message is identified as a normal service message, and the first tuple is stored in the cache of the first device as a basis for loop determination of subsequent received messages. In this way, before the first service message is sent or forwarded, the first tuple in the first service message is cached in the first device, so that when a service message containing the same first tuple is received later, the first device can find the matching target historical tuple in the cache, thereby identifying the subsequent message as a duplicate message and discarding it.

[0051] It is understandable that if caching is performed after forwarding or uploading is completed, duplicate packets may arrive at the first device from the second device via other ports of the first device within the time window before the caching operation is completed, and may be mistakenly identified as normal service packets and forwarded or uploaded, resulting in misprocessing of duplicate packets. This application avoids uploading or forwarding duplicate packets as normal service packets by placing the caching operation before the forwarding or uploading operation, thus ensuring the accuracy and real-time performance of loop detection and improving the accuracy and reliability of service packet uploading / forwarding.

[0052] It should be noted that, to avoid cache overflow, this application embodiment sets up a cache aging mechanism. Specifically, the loop detection method further includes: Get the cached time corresponding to the historical tuple cached in the first device; The historical tuples that have been cached for longer than the preset aging time are cleared.

[0053] The cached time is the time interval from the time the historical tuple was stored in the first device to the current time. The preset aging time is a pre-set aging threshold. When the cached time of the historical tuple exceeds the preset aging time, the first device deletes the historical tuple from the cache.

[0054] Optionally, when a historical tuple cached in the first device is matched, the cached time of the matched historical tuple is cleared to zero. In one embodiment, when a target historical tuple that matches the first tuple is determined, the cached time of the target historical tuple is cleared to zero.

[0055] It is understandable that when a historical tuple is matched by a tuple in a currently transmitted service packet, it indicates that the service packet containing the historical tuple is still being transmitted in the ring network at the current moment, and there is a possibility that it may arrive at the first device repeatedly. Therefore, the historical tuple still has value for subsequent loop detection. This embodiment extends the lifespan of the historical tuple in the cache by resetting its cached time to zero, preventing the historical tuple from being mistakenly cleared and causing missed detection of duplicate packets while the service packet containing it is still being transmitted in the ring network. Optionally, for historical tuples that have not been matched for a long time, the corresponding service packet is unlikely to continue being transmitted in the ring network. Clearing such timed-out historical tuples can free up cache space without affecting the accuracy of loop detection. Thus, this embodiment balances the utilization rate of cache space and the accuracy of loop detection by setting a cache aging mechanism and a cache time-resetting mechanism.

[0056] In this embodiment, by setting a cache aging mechanism, the first device can promptly clear historical tuples that have not been matched for a long time, releasing cache space and avoiding cache overflow problems caused by the continuous accumulation of cached tuples. Simultaneously, since the service packets corresponding to expired historical tuples have exceeded their normal preset aging time in the ring network, even if subsequent packets containing the same tuple are received, they should be considered new normal packets rather than duplicate packets. Therefore, clearing expired historical tuples will not affect the accuracy of loop detection.

[0057] Optionally, the loop detection method further includes: In response to a service message sending request, obtain the first preset device identifier corresponding to the first device; The second preamble corresponding to the service message to be sent is generated based on the first preset device identifier and the second message serial number corresponding to the service message to be sent. The second preamble and the service message to be sent are combined to generate the second service message; The second service message is sent to the second target device so that the second target device can perform loop detection operation based on the second preamble.

[0058] In one embodiment, when the upper-layer protocol stack of the first device generates service data to be sent, a service message sending request is triggered. The first device responds to the service message sending request to generate a second service message to be sent. Specifically, the first device obtains a first preset device identifier corresponding to the first device, which is the device identifier of the first device, and obtains the current count value of the message serial number counter from the message serial number counter of the first device, and uses the current count value as the second message serial number corresponding to the service message to be sent; then, the first preset device identifier and the second message serial number are used as a second tuple, and the second tuple is filled into the device identifier field filling area and the message serial number field filling area of ​​the second preamble, respectively, to generate the second preamble; wherein, after generating the second preamble, the first device automatically increments its local message serial number counter by one for the allocation of the message serial number of the next service message to be sent. Furthermore, after generating the second preamble, the second preamble and the current service message to be sent are combined to generate the second service message, and the second target device corresponding to the second service message is determined. The second target device can be a second device or another device adjacent to the first device, and the second service message is sent to the second target device.

[0059] In this process, after the second target device receives the second service message, it performs a loop detection operation based on the second preamble in the second service message. Specifically, the second target device obtains the second tuple from the second preamble and compares it with historical tuples cached in the second target device to determine whether the second service message is a duplicate message, thereby determining whether a loop exists in the ring network. It should be noted that the specific implementation of the loop detection operation performed by the second target device on the second service message is consistent with the specific implementation of the loop detection operation performed by the first device. The second target device extracts the second tuple from the second preamble, which includes the second device identifier and the second message serial number; it compares the second tuple with each historical tuple cached locally in the second target device; if a matching target historical tuple exists, it is determined that a loop exists in the ring network, and the second service message is discarded; if no matching target historical tuple exists, it is determined that no loop exists in the ring network, the second tuple is cached locally in the second target device, and the second service message is forwarded or uploaded for processing.

[0060] In this embodiment, by using the first tuple as detection information and embedding it directly into the first preamble, the frame payload is not occupied, the standard Ethernet frame header is not modified, and it is fully compatible with the existing TSN protocol. Furthermore, there is no need to generate additional heartbeat messages, reducing the bandwidth and resource consumption of heartbeat messages in the ring network. Loop detection is achieved while transmitting service messages, improving the real-time performance of loop detection. When the first device receives a first service message sent by the second device, it parses the first service message, obtains the first preamble, and extracts the first tuple from the first preamble. This first tuple is used as detection information for loop detection. The first tuple is compared with historical tuples cached in the first device to determine if a target historical tuple matching the first tuple exists. If a target historical tuple matching the first tuple is found, the first service message is determined to be a duplicate message, thus indicating that the first device has formed a loop in the ring network. The currently transmitted first service message is then discarded and not forwarded. Loop detection is achieved through the preamble in the service message. Compared to STP / RSTP-based loop detection methods, which require specifying port changes and re-convergence after topology changes, the loop detection method in this application is simpler and requires fewer steps, improving loop detection efficiency. Meanwhile, this application, by embedding the device identifier in the preamble, can distinguish the source device corresponding to the service message when a loop is detected, thus solving the problem of incorrect deduplication or missed loop detection caused by the inability to distinguish the source of the forwarding device, and improving the accuracy of loop detection.

[0061] Second Embodiment Based on the first embodiment, referring to Figure 6 Step S20 includes steps S21 to S24: Step S21: Obtain the preset device identifier and preset message serial number from the historical tuple, wherein the preset device identifier includes the first preset device identifier corresponding to the first device; Step S22: When the first device identifier matches the first preset device identifier, obtain the first historical tuple corresponding to the first preset device identifier; Step S23: Compare the first preset message serial number of the first historical tuple with the first message serial number; Step S24: When there is a first target preset message sequence number that matches the first message sequence number, the first historical tuple corresponding to the first target preset message sequence number is taken as the target historical tuple.

[0062] It should be noted that there are two types of loops: one is a self-loop, where the service message generated by the first device is forwarded by other devices in the ring network and then returns to the first device; the other is a repeated loop, where the same service message generated by other devices arrives at the first device successively through different transmission paths in the ring network.

[0063] In one optional implementation, this application uses a self-loop as an example for explanation and analysis. Specifically, a first preset device identifier corresponding to the first device and a first device identifier of the first service message are obtained. The first preset device identifier is compared with the first device identifier to determine whether the first device identifier is consistent with the first preset device identifier. After determining that the first device identifier matches the first preset device identifier, a first historical tuple containing the first preset device identifier cached in the first device is obtained based on the first preset device identifier, wherein the preset device identifier in the first historical tuple is the first preset device identifier. After determining the first historical tuple, the first preset message serial number in each first historical tuple is obtained. The first preset message serial number in each first historical tuple is compared with the first message serial number in the first service message. It is determined whether there is a first target preset message serial number that matches the first message serial number in each first preset message serial number. The first historical tuple containing the first target preset message serial number is taken as the target historical tuple that matches the first tuple. Thus, it is determined that the comparison result is that there is a target historical tuple that matches the first tuple.

[0064] For example, refer to Figure 7 , Figure 7 This diagram illustrates how the first device forms a self-loop in a ring network. The first service message is sent through PORT 1 of switch device 1 and arrives at switch device 2. After receiving the first service message from switch device 1, switch device 2 sends it out from PORT 2, through switch device 3 and switch device 4, and then back to PORT 3 of switch device 2. After receiving the returned first service message, switch device 2 sends it back to switch device 1 through PORT 1. At this point, switch device 1 has formed a self-loop (DeviceId (first device identifier) ​​+ SeriesNumber (first message serial number) in the first service message = DeviceId (first preset device identifier) ​​+ SeriesNumber (first target preset message serial number) of switch device 1).

[0065] For example, refer to Figure 8 , Figure 8This diagram illustrates how the first device forms a self-loop in a ring network. The first service message is sent to switch 2 via PORT 1 of switch 1. After receiving the first service message from switch 1, switch 2 sends it out from PORT 2, through switch 3, and back to PORT 2 of switch 1. At this point, switch 1 has formed a self-loop (DeviceId (first device identifier) ​​+ SeriesNumber (first message serial number) in the first service message = DeviceId (first preset device identifier) ​​+ SeriesNumber (first destination preset message serial number) of switch 1).

[0066] In one optional implementation, this application uses a repeating loop as an example for illustration and analysis. Specifically, refer to... Figure 9 After step S21, the method further includes steps S25 to S27: Step S25: When the first device identifier does not match the first preset device identifier, determine a second historical tuple other than the first historical tuple from the historical tuples. Step S26: Compare each second history tuple with the first tuple; Step S27: The second historical tuple that matches the first tuple is taken as the target historical tuple.

[0067] In one embodiment, when it is determined that the first device identifier of the first tuple does not match the first preset device identifier of the first device, it is determined that the first service message was not generated and sent by the first device, and then the second historical tuple is obtained from the historical tuple cached by the first device, wherein the second preset device identifier in the second historical tuple is different from the first preset device identifier.

[0068] Optionally, after determining the second historical tuple, the second preset device identifier and the second preset message serial number of each second historical tuple are determined. Each second historical tuple is compared with the first tuple to determine the second historical tuple that matches the first tuple. This second historical tuple is then selected as the target historical tuple. Specifically, the second preset device identifier of the second historical tuple matching the first tuple is the same as the first device identifier, and the second preset message serial number is the same as the first message serial number. After determining the target historical tuple, it is determined that a duplicate loop exists in the ring network, and the first service message is discarded.

[0069] For example, refer to Figure 10 , Figure 10A schematic diagram of a duplicate loop is shown. Switching device 1 receives external service packets or generates its own service packets and sends them out from ports PORT 1 and PORT 2 respectively. The service packet sent from port 1 of switching device 1 passes through switching device 2 and arrives at switching device 4; the service packet from port 2 of switching device 1 passes through switching device 3 and arrives at switching device 4. At this time, switching device 4 receives the first service packet with the same DeviceId and SeriesNumber, and it is determined that switching device 4 has generated a duplicate loop in the ring network.

[0070] In this embodiment, after receiving a first service message, the first device obtains the preset device identifier and preset message serial number of each historical tuple cached locally. It then determines whether the first device identifier of the first tuple matches the first preset device identifier of the first device. When the first device identifier matches the first preset device identifier, by comparing the first message serial number with the first preset message serial number of the existing first historical tuple in the cache, it can accurately identify whether the first service message was sent by the first device and retransmitted back to the first device, thereby determining whether a self-loop exists. When the first device identifier does not match the first preset device identifier, by comparing it with the second historical tuple in the cache, it can accurately identify whether the first service message repeatedly arrives at the first device from different transmission paths, thereby determining whether a duplicate loop exists. Thus, this application uses the first tuple composed of the first device identifier and the first message serial number as the basis for judgment, which can achieve both self-loop detection and duplicate loop detection, ensuring the accuracy of loop detection and avoiding misjudgment or missed detection due to the inability to distinguish the device source.

[0071] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the loop detection method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0072] This application provides a loop detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the loop detection method in Embodiment 1 above.

[0073] The following is for reference. Figure 11The diagram illustrates a structural schematic suitable for implementing the loop detection device in the embodiments of this application. The loop detection device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 11 The loop detection device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of this application.

[0074] like Figure 11 As shown, the loop detection device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the loop detection device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows the loop detection device to communicate wirelessly or wiredly with other devices to exchange data. Although the figures show loop detection devices with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may be implemented alternatively.

[0075] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0076] The loop detection device provided in this application, employing the loop detection method described in the above embodiments, can solve the problems of low loop detection efficiency, low detection accuracy, additional bandwidth consumption, and loop detection lag inherent in traditional loop detection methods. Compared with the prior art, the beneficial effects of the loop detection device provided in this application are the same as those of the loop detection method provided in the above embodiments, and other technical features of this loop detection device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0077] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0078] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0079] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the loop detection method in the above embodiments.

[0080] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0081] The aforementioned computer-readable storage medium may be included in the loop detection device; or it may exist independently and not assembled into the loop detection device.

[0082] The aforementioned computer-readable storage medium carries one or more programs that, when executed by the loop detection device, enable the loop detection device to write computer program code for performing the operations of this application in one or more programming languages ​​or combinations thereof. These programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0083] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0084] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0085] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described loop detection method. This solves the problems of low loop detection efficiency, low detection accuracy, additional bandwidth consumption, and loop detection lag in traditional loop detection methods. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the loop detection method provided in the above embodiments, and will not be repeated here.

[0086] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the loop detection method described above.

[0087] The computer program product provided in this application can solve the problems of low loop detection efficiency, low detection accuracy, additional bandwidth consumption, and loop detection lag in traditional loop detection methods. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the loop detection method provided in the above embodiments, and will not be repeated here.

[0088] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A loop detection method, characterized in that, A first device is applied in a ring network, the ring network comprising multiple devices connected based on a ring topology, the ring network including the first device and a second device, the loop detection method comprising the following steps: When a first service message sent by the second device is received, a first preamble in the first service message is obtained. The first preamble includes a first tuple, and the first tuple includes a first device identifier and a first message serial number. Obtain the historical tuple cached in the first device, and compare the historical tuple with the first tuple; When a target historical tuple that matches the first tuple exists, it is determined that the first device forms a loop in the ring network.

2. The loop detection method as described in claim 1, characterized in that, The step of obtaining the historical tuple cached in the first device and comparing the historical tuple with the first tuple includes: Obtain the preset device identifier and preset message serial number from the historical tuple, wherein the preset device identifier includes the first preset device identifier corresponding to the first device; When the first device identifier matches the first preset device identifier, the first historical tuple corresponding to the first preset device identifier is obtained; Compare the first preset message serial number of the first historical tuple with the first message serial number; When a first target preset message sequence number exists that matches the first message sequence number, the first historical tuple corresponding to the first target preset message sequence number is taken as the target historical tuple.

3. The loop detection method as described in claim 2, characterized in that, After the step of obtaining the preset device identifier and preset message serial number from the historical tuple, the method further includes: When the first device identifier does not match the first preset device identifier, a second historical tuple other than the first historical tuple is determined from the historical tuples; Compare each second history tuple with the first tuple; The second historical tuple that matches the first tuple is taken as the target historical tuple.

4. The loop detection method as described in claim 1, characterized in that, After determining that the first device forms a loop in the ring network when a target historical tuple matching the first tuple exists, the method further includes: Discard the first service message.

5. The loop detection method as described in claim 1, characterized in that, After the step of obtaining the historical tuple pre-cached in the first device and comparing the historical tuple with the first tuple, the method further includes: If no target historical tuple matches the first tuple, it is determined that the first device has not formed a loop in the ring network; The target device corresponding to the first service message is determined, and the first service message is sent to the target device.

6. The loop detection method as described in claim 5, characterized in that, Before the step of determining the target device corresponding to the first service message and sending the first service message to the target device, the method further includes: The first tuple is cached in the first device.

7. The loop detection method as described in claim 1, characterized in that, The loop detection method further includes: Get the cached time corresponding to the historical tuple cached in the first device; The historical tuples that have been cached for longer than the preset aging time are cleared.

8. The loop detection method as described in claim 1, characterized in that, The loop detection method further includes: In response to a service message sending request, obtain the first preset device identifier corresponding to the first device; The second preamble corresponding to the service message to be sent is generated based on the first preset device identifier and the second message serial number corresponding to the service message to be sent. The second preamble and the service message to be sent are combined to generate the second service message; The second service message is sent to the second target device so that the second target device can perform loop detection operation based on the second preamble.

9. A loop detection device, the loop detection device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the loop detection method as described in any one of claims 1 to 8.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the loop detection method as described in any one of claims 1 to 8.