Address matching method and apparatus, storage medium, and program product

By introducing heuristic information into the binary search tree, the problem of low routing efficiency is solved, and more efficient routing lookup and prefix update are achieved, making it suitable for scenarios with strong network dynamics.

CN117478594BActive Publication Date: 2026-07-10HUAWEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2022-07-21
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

In existing technologies, the route lookup process requires traversing a large number of nodes, resulting in low route lookup efficiency and making it difficult to meet the high-speed forwarding requirements of the forwarding platform.

Method used

By introducing heuristic information into the binary search tree and recording the heuristic information nodes for each prefix tag, the search range is narrowed, the number of node traversals is reduced, and the efficiency of route lookup is improved.

Benefits of technology

By using heuristic information to narrow down the search scope, reduce the number of node traversals, improve route lookup efficiency, support fast prefix updates, and adapt to scenarios with highly dynamic networks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117478594B_ABST
    Figure CN117478594B_ABST
Patent Text Reader

Abstract

The application discloses an address matching method and device, a storage medium and a program product, and belongs to the technical field of communication. In the method, the address to be matched is matched with a hash table corresponding to a first node in a binary search tree. If the address matches a target prefix mark in the hash table corresponding to the first node, heuristic information corresponding to the target prefix mark is obtained. The heuristic information refers to information associated with at least one heuristic information node. The at least one heuristic information node is a node corresponding to a hash table in which a prefix of the target prefix mark is projected. A longest prefix matched with the address is found based on the heuristic information corresponding to the target prefix mark. Since the target prefix mark corresponds to heuristic information, the search range can be reduced based on the heuristic information, and it is not necessary to traverse all nodes on a right subtree of a node corresponding to the hash table in which the target prefix mark is located. Therefore, the number of traversed nodes can be reduced, and the routing search efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to an address matching method, apparatus, storage medium, and program product. Background Technology

[0002] To improve packet forwarding efficiency, forwarding devices such as routers are configured with a forwarding information base (FIB). The FIB includes multiple prefixes and forwarding rules corresponding to each prefix. When a forwarding device receives a packet, it parses the packet's destination address, searches the FIB for the longest prefix that matches the destination address, and forwards the packet based on the forwarding rules corresponding to the longest matching prefix. This process is also known as the route lookup process.

[0003] In the aforementioned route lookup process, to improve efficiency, a binary search tree can be maintained for all prefixes in the FIB. This binary search tree includes multiple nodes, each representing a prefix length, and each prefix length corresponds to a hash table used to store multiple prefixes of the corresponding prefix length. To further improve efficiency, prefixes in the hash table of each node can be projected onto nodes with shorter prefix lengths, and the prefix tag corresponding to that prefix is ​​stored in the hash table of the projected node. For example, if nodes are named according to the prefix length they represent, then the hash table corresponding to node 3 stores prefixes of length 3, and the hash table corresponding to node 5 stores prefixes of length 5. If a prefix in node 5 is projected onto node 3, then the hash table corresponding to node 3 also stores the prefix tag corresponding to that prefix. This prefix tag can be understood as the portion obtained by truncating the first few bits of the prefix to a length of 3. Since the prefix length of nodes in the right subtree of any node in a binary search tree is always greater than the prefix length of the node itself, and the prefix length of nodes in the left subtree of any node is always less than the prefix length of the node, if a prefix tag exists in the hash table corresponding to that node, then that prefix tag is the prefix tag obtained by projecting the prefix from the hash table corresponding to the node in the right subtree of that node. In this scenario, when matching the destination address, if the destination address matches the prefix tag in the hash table corresponding to a certain node, then the hash tables corresponding to each node in the right subtree of that node in the binary search tree are traversed to find the longest prefix that matches the destination address.

[0004] The above route lookup process requires traversing a large number of nodes, resulting in low route lookup efficiency. Summary of the Invention

[0005] This application provides an address matching method, apparatus, storage medium, and program product, which can improve route lookup efficiency. The technical solution is as follows:

[0006] Firstly, an address matching method is provided. In this method, the address to be matched and a binary search tree are determined. The binary search tree includes multiple nodes, each node indicating a prefix length, and each prefix length corresponds to a hash table. Each hash table stores at least one prefix of the corresponding prefix length, or at least one prefix and at least one prefix tag. Each prefix tag is obtained by projecting the prefixes in other hash tables according to the prefix length corresponding to the hash table containing the prefix tag.

[0007] The address is matched against the hash table of the first node in a binary search tree. If the address matches the target prefix tag in the hash table of the first node, the heuristic information corresponding to the target prefix tag is obtained. This heuristic information refers to information associated with at least one heuristic information node, which is the node corresponding to the hash table of the prefix of the target prefix tag obtained by projection. The longest prefix matching the address is found based on the heuristic information corresponding to the target prefix tag.

[0008] In this embodiment, when it is determined that the address to be matched matches a certain prefix tag, since the prefix tag also corresponds to heuristic information, and the heuristic information is used to record information associated with the heuristic information node, the search range can be narrowed based on the heuristic information, avoiding the need to traverse all nodes in the right subtree of the node corresponding to the hash table where the prefix tag is located. Therefore, the address matching method provided in this embodiment can reduce the number of nodes traversed, thereby improving the routing lookup efficiency.

[0009] Based on the method provided in the first aspect, in some possible implementations, the heuristic information includes the prefix length indicated by each heuristic information node in at least one heuristic information node. In this scenario, the process of finding the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag can be as follows: based on the prefix length indicated by each heuristic information node in at least one heuristic information node, find the longest prefix matching the address from the binary search tree.

[0010] By directly recording the prefix length indicated by each heuristic information node in the heuristic information, each heuristic information node can be directly determined based on the recorded prefix length during route lookup, thereby quickly finding the longest prefix matching the address from the binary search tree.

[0011] Based on the method provided in the first aspect, in some possible implementations, the process of finding the longest prefix matching the address from the binary search tree based on the prefix length indicated by each heuristic information node in at least one heuristic information node can be as follows: based on the prefix length indicated by each heuristic information node in at least one heuristic information node, determine the common nearest ancestor node of at least one heuristic information node, which is the root node of the smallest subtree containing all heuristic information nodes in the binary search tree; and find the longest prefix matching the address from the subtree rooted at the common nearest ancestor node in the binary search tree.

[0012] After determining each heuristic information node based on the prefix length recorded in the heuristic information, the routing search range can be narrowed down to the subtree rooted at the common nearest ancestor node in the binary search tree, thereby reducing the routing search range and improving routing search efficiency.

[0013] Based on the method provided in the first aspect, in some possible implementations, the heuristic information includes a heuristic search path, which includes at least one binary decision node arranged in sequence. The at least one binary decision node is a node on a binary search tree, and the heuristic search path is a path capable of traversing at least one heuristic information node. In this scenario, the process of finding the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag is as follows: Following the order of at least one binary decision node in the heuristic search path, traverse at least one binary decision node sequentially to find the longest prefix matching the address from the hash table corresponding to the at least one binary decision node.

[0014] Optionally, in this embodiment of the application, a heuristic lookup path that can traverse at least one heuristic information node can also be recorded in the heuristic information, so that during routing lookup, the longest prefix matching the address can be quickly found directly through the heuristic lookup path, further improving the routing lookup efficiency.

[0015] Based on the method provided in the first aspect, in some possible implementations, at least one binary decision node is a node in the subtree of the binary search tree with the common nearest ancestor node as the root node, and the common nearest ancestor node is the root node of the smallest subtree of the binary search tree that contains all heuristic information nodes.

[0016] The heuristic search path can be located on the subtree rooted at the common nearest ancestor node in the binary search tree, thereby narrowing the route search range and improving the route search efficiency.

[0017] Based on the method provided in the first aspect, in some possible implementations, the heuristic search path can be predetermined through the following steps: Specifically, the common nearest ancestor node of at least one heuristic information node is determined, and the common nearest ancestor node is identified as a binary decision node; some heuristic information nodes located in the left subtree of the common nearest ancestor node are determined, and some heuristic information nodes are updated to at least one heuristic information node; the operation of determining the common nearest ancestor node of at least one heuristic information node is returned, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree; the determined binary decision nodes are sequentially configured as the respective binary decision nodes in the heuristic path.

[0018] The heuristic search path determined by the above method can traverse all heuristic information nodes in at least one heuristic information node, thereby improving search accuracy while narrowing the search range.

[0019] Based on the method provided in the first aspect, in some possible implementations, the heuristic search path can also be pre-determined through the following steps: Specifically, determine the common nearest ancestor node of at least one heuristic information node; if the common nearest ancestor node is one of at least one heuristic information node, then determine the common nearest ancestor node as a binary judgment node; if the common nearest ancestor node is not one of at least one heuristic information node, then update the heuristic information node located in the right subtree of the common nearest ancestor node to at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node is one of at least one heuristic information node, and determine the most recently determined common nearest ancestor node as a binary judgment node, or, until the most recently determined common nearest ancestor node is determined to be one of at least one heuristic information node, or, until the most recently determined common nearest ancestor node is determined to be a binary judgment node, or, until the most recently determined common nearest ancestor node is determined to be a heuristic information node, then ... heuristic information node, then the most recently determined common nearest ancestor node is determined to be a binary judgment node, or, until the most recently determined common nearest ancestor node is determined to be a heuristic information node, then the most recently determined common nearest ance The most recently determined common lowest ancestor node has no right subtree or no heuristic information node in its right subtree, and the most recently determined common lowest ancestor node is not one of at least one heuristic information node; for each determined common lowest ancestor node, if there is a heuristic information node in the left subtree of the common lowest ancestor node, update the heuristic information node in the left subtree to at least one heuristic information node, and return to perform the operation of determining the common lowest ancestor node of at least one heuristic information node, until the most recently determined common lowest ancestor node has no left subtree or no heuristic information node in its left subtree; the determined binary judgment nodes are configured sequentially as the binary judgment nodes in the heuristic path.

[0020] The heuristic search path determined by the above method has the following characteristics: the binary search decision nodes that are ranked higher are closer to the right side of the binary search tree than the binary search decision nodes that are ranked lower. Since the prefix length of the nodes closer to the right in the binary search tree is larger, when searching for the longest prefix matching the address using this heuristic search path, it can quickly lock the heuristic information node with the larger prefix length for matching, further improving the routing lookup efficiency.

[0021] Based on the method provided in the first aspect, in some possible implementations, the process of matching the address with the hash table corresponding to the first node among multiple nodes can be as follows: determine an initial path, which includes the root node of the binary search tree and the consecutive left child nodes located in the left subtree of the root node; take each node in the initial path as the first node in turn, and perform the operation of matching the address with the hash table corresponding to the first node among multiple nodes.

[0022] During the route lookup process, the initial path as described above can be predetermined. Then, for each node in the initial path, the address matching method provided in this application embodiment is executed to find the longest prefix that matches the address, so as to ensure that every possible longest prefix is ​​traversed, thereby improving the accuracy of the route lookup.

[0023] Based on the method provided in the first aspect, in some possible implementations, for any hash table, if the hash table stores prefix tags, the hash table is also used to store the longest matching prefix (BMP) of the prefix tags. Additionally, each prefix in the hash table corresponding to any node in the binary search tree corresponds to an associated prefix tag list (AML), where each prefix's AML includes at least one prefix tag, and the BMP of the prefix tags in each prefix's AML is the corresponding prefix.

[0024] In this scenario, in this method, in response to the prefix update operation, the BMP of each prefix tag in the AML corresponding to the prefix to be updated is updated based on the AML corresponding to the prefix to be updated.

[0025] Since the hash table also stores the BMP for each prefix tag, adding or deleting a prefix in the FIB may affect the BMP of the prefix tags projected onto it, requiring updates to the BMPs of each prefix tag. In this embodiment, to reduce the workload of BMP update operations triggered during prefix updates, each node in the binary search tree has an associated prefix tag list AML in its hash table for each prefix. Each prefix's AML includes at least one prefix tag, and the BMP of each prefix tag in the AML is the corresponding prefix. Thus, when updating a prefix, the AML corresponding to that prefix can determine which prefix tags' BMPs need updating, avoiding the need to update the global prefix tag BMPs and improving update efficiency.

[0026] Based on the method provided in the first aspect, in some possible implementations, the prefix update operation includes a prefix insertion operation, and the prefix to be updated includes the first prefix to be inserted. In this scenario, the implementation process of updating the BMP of each prefix tag in the AML corresponding to the prefix to be updated is as follows: determine the length of the first prefix, obtain the first prefix length, and insert the first prefix into the hash table corresponding to the first prefix length; determine the second prefix from the binary search tree, the second prefix being the longest prefix that matches the first prefix and has a length less than the first prefix length; obtain the AML of the second prefix, obtain the second AML; determine some prefix tags in the second AML as prefix tags in the AML of the first prefix, obtain the first AML, and update the BMP of each prefix tag in the first AML from the second prefix to the first prefix.

[0027] When a prefix is ​​inserted, some prefix tags' BMPs may become part of the newly inserted prefix. All potentially affected prefix tags must reside in the AML of the longest matching prefix (assuming it exists) that is no longer than the inserted prefix. Therefore, when inserting the first prefix, the longest prefix with a length less than the first prefix and matching it can be determined from the binary search tree to obtain the second prefix. Then, from the AML of the second prefix, it can be determined which prefix tags' BMPs will be updated to the first prefix, thus obtaining the AML of the first prefix.

[0028] Based on the method provided in the first aspect, in some possible implementations, the partial prefix tag in the second AML is a prefix tag that satisfies the following conditions: the length of the partial prefix tag is greater than or equal to the length of the first prefix, and the prefix of the partial prefix tag is the first prefix.

[0029] By using the above method, when inserting the first prefix, the longest prefix that is shorter than the length of the first prefix and matches the first prefix can be quickly determined from the binary search tree, which is the second prefix.

[0030] Based on the method provided in the first aspect, in some possible implementations, the first prefix is ​​projected onto the second node on the binary search tree to obtain the first prefix tag, and the first prefix tag is added to the hash table corresponding to the second node; the BMP of the first prefix tag is determined to obtain the first BMP; and the first prefix tag is added to the AML of the first BMP.

[0031] Since a new prefix is ​​inserted, and this inserted prefix needs to be projected onto other nodes, in this embodiment, after inserting the first prefix, the first prefix is ​​also projected onto the second node in the binary search tree to obtain a first prefix tag, and the first prefix tag is added to the hash table corresponding to the second node; the BMP of the first prefix tag is determined to obtain the first BMP; the first prefix tag is added to the AML of the first BMP to achieve updates to other AMLs.

[0032] Based on the method provided in the first aspect, in some possible implementations, after projecting the first prefix onto the second node on the binary search tree to obtain the first prefix label, the method can also determine and store the heuristic information corresponding to the first prefix label.

[0033] The above approach facilitates the subsequent execution of the address matching scheme provided in this application embodiment based on the heuristic information corresponding to the first prefix tag.

[0034] Based on the method provided in the first aspect, in some possible implementations, the prefix update operation includes a prefix deletion operation, and the prefix to be updated includes a third prefix to be deleted. In this scenario, the implementation process of updating the BMP of each prefix tag in the AML corresponding to the prefix to be updated is as follows: determine the length of the third prefix, obtain the third prefix length, and delete the third prefix from the hash table corresponding to the third prefix length; obtain the AML of the third prefix, obtain the third AML; redetermine the BMP of each prefix tag in the third AML, and add each prefix tag in the third AML to the AML of the redetermined BMP; delete the third AML.

[0035] When a prefix is ​​deleted, the BMP needs to be recalculated for all prefix tags that use the deleted prefix as the BMP, and all potentially affected prefix tags must be in the AML of the deleted prefix. Based on this, when deleting a third prefix, the BMP of each prefix tag in the AML of the third prefix needs to be recalculated, and each prefix tag in the third AML needs to be added to the AML of the recalculated BMP.

[0036] Based on the method provided in the first aspect, in some possible implementations, the method can also determine the prefix label of the third node projected onto the binary search tree to obtain the third prefix label; if there are no other prefixes projected onto the third prefix label, the third prefix label and the corresponding heuristic information are deleted; if there are other prefixes projected onto the third prefix label, the heuristic information corresponding to the third prefix label is updated.

[0037] After deleting the third prefix, the heuristic information of the prefix labels projected before the third prefix needs to be updated. Based on the above method, the heuristic information of the prefix labels projected before the third prefix can be updated.

[0038] Secondly, an address matching apparatus is provided, which has the function of implementing the address matching method described in the first aspect. The address matching apparatus includes at least one module for implementing the address matching method provided in the first aspect.

[0039] Thirdly, an address matching apparatus is provided, comprising a processor configured to execute a program or instructions to cause the address matching apparatus to perform any of the methods described in the first aspect and its possible implementations. In some embodiments, the address matching apparatus further comprises a memory for storing the program or instructions; in some embodiments, the memory is also used to store data related to implementing the address matching method provided in the first aspect. The address matching apparatus may further comprise a communication bus for establishing a connection between the processor and the memory.

[0040] Fourthly, a computer-readable storage medium is provided, wherein a program or instructions are stored therein, which, when executed on a computer, cause the computer to perform the address matching method described in the first aspect.

[0041] Fifthly, a computer program product comprising a program or instructions is provided, which, when executed on a computer, causes the computer to perform the address matching method described in the first aspect.

[0042] The technical effects achieved by the second, third, fourth, and fifth aspects mentioned above are similar to those achieved by the corresponding technical means in the first aspect, and will not be repeated here. Attached Figure Description

[0043] Figure 1 This is a schematic diagram of a FIB and a binary search tree provided in an embodiment of this application;

[0044] Figure 2This is a schematic diagram of the architecture of an address matching system provided in an embodiment of this application;

[0045] Figure 3 This is a flowchart of an address matching method provided in an embodiment of this application;

[0046] Figure 4 This is a schematic diagram of a binary search tree and heuristic information provided in an embodiment of this application;

[0047] Figure 5 This is a schematic diagram of another binary search tree and heuristic information provided in an embodiment of this application;

[0048] Figure 6 This is a schematic diagram of another binary search tree and heuristic information provided in an embodiment of this application;

[0049] Figure 7 This is a schematic diagram of another binary search tree and heuristic information provided in an embodiment of this application;

[0050] Figure 8 This is a schematic diagram of a BMP update process provided in an embodiment of this application;

[0051] Figure 9 This is a schematic diagram illustrating the addition of a prefix according to an embodiment of this application;

[0052] Figure 10 This is a schematic diagram illustrating a prefix deletion method provided in an embodiment of this application;

[0053] Figure 11 This is a schematic diagram of an address matching device provided in an embodiment of this application;

[0054] Figure 12 This is a schematic diagram of the structure of a network device provided in an embodiment of this application. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0056] It should be understood that "multiple" as mentioned herein refers to two or more. In the description of this application, unless otherwise stated, " / " signifies "or," for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, to facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first," "second," etc., are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and that "first," "second," etc., are not necessarily different. The "longest matching prefix" and "best matching prefix (BMP)" referred to in this application have the same meaning and can be used interchangeably.

[0057] Before providing a detailed explanation of the embodiments of this application, let's first introduce the application scenarios of these embodiments.

[0058] Route lookup is a core operation of forwarding devices such as routers in a network. The process by which a forwarding device performs a route lookup largely determines its cost and performance. Specifically, route lookup refers to the process of finding, given the destination address of a message (i.e., a data packet), such as the destination network protocol (IP) address, in the forwarding information base (FIB) to find the forwarding rule (such as next-hop information) corresponding to the longest prefix matching that destination address, and then processing the message according to that forwarding rule.

[0059] To simplify the subsequent discussion, this embodiment uses a 0 / 1 string ending with an asterisk to represent a prefix, where the total number of 0s and 1s in the 0 / 1 string represents the length of the prefix. For example, if a FIB contains three prefixes: P1 = 101*, P2 = 1010*, and P3 = 10101*, then the length of prefix P1 is 3, the length of prefix P2 is 4, and the length of prefix P3 is 5. Assuming the first 8 bits of the destination address to be searched are 10100000, then the destination address can match prefixes P1 and P2. Since the length of P2 is longer than the length of P1, according to the longest prefix matching principle, the result of this route lookup is the forwarding rule corresponding to prefix P2.

[0060] To improve routing lookup efficiency, all prefixes in the FIB are grouped by length, with each group containing prefixes of equal length. Each group's prefixes are maintained using a hash table, meaning each hash table corresponds to a prefix length. When looking up an address, all hash tables are probed, and the match in the hash table with the longest corresponding prefix length is selected as the final routing result. For ease of explanation later, the process of matching an address against all prefixes and prefix tags in a hash table is called a hash probe.

[0061] In addition, to reduce the number of hash probes and thus speed up the route lookup process, all hash tables are organized into a binary search tree according to their corresponding prefix lengths. Each node in the binary search tree indicates a prefix length, and each prefix length indicated by a node corresponds to a hash table.

[0062] For ease of explanation, the node indicating the prefix length N will be called node N. For example... Figure 1 As shown, the FIB includes 7 prefixes, with lengths ranging from 1 to 7. Therefore, 7 hash tables are configured for the FIB, each storing a prefix with a length equal to the corresponding prefix length.

[0063] like Figure 1 As shown, these 7 hash tables are maintained using a binary search tree of height 4. The binary search tree consists of 7 nodes, numbered 1 to 7, each indicating a prefix length of 1 to 7. Each node corresponds to a hash table used to store prefixes of length 1 to 7 indicated by that node. Figure 1 As shown, the hash table corresponding to node 3 is used to store prefix C: 010*, node 2 is used to store prefix B: 01*, node 1 is used to store prefix A: 1*, node 7 is used to store prefix G: 1111111*, node 5 is used to store prefix E: 01000*, node 4 is used to store prefix D: 1011*, and node 6 is used to store prefix F: 101111*.

[0064] The binary search tree has the following properties: For any node in the binary search tree, when that node is the root node, if its left subtree is not empty, then the value of all nodes in the left subtree is less than the value of the root node. If its right subtree is not empty, then the value of all nodes in the right subtree is greater than the value of the root node. In this embodiment, the value of each node is also the prefix length indicated by each node.

[0065] Based on the properties of binary search trees, the structure of the binary search trees corresponding to nodes 1 to 7 is as follows: Figure 1 As shown. In Figure 1In the binary search tree shown, node 3 is the root node, nodes 2 and 1 are located in the left subtree of node 3, and nodes 4 to 7 are located in the right subtree of node 3. The structure of other branches in the binary search tree can be understood similarly, and will not be described in detail here.

[0066] Furthermore, to ensure the correctness of the binary search, a "projection" operation can be performed in a "right-biased order" to generate prefix markers. For example, "projecting" node N to node M (N>M) means: taking the first M bits of all prefixes in the hash table with prefix length N and inserting them as prefix markers into the hash table with prefix length M. "Right-biased order" means that all nodes project to the node closest to them whose right subtree contains them. Thus, once the binary search tree structure is fixed, each node has a unique projection node. And when a prefix in the hash table corresponding to a node is projected to another projection node, the generated prefix marker can then be used as a prefix of that projection node to continue projecting to other projection nodes.

[0067] Therefore, in the embodiments of this application, the hash table corresponding to a certain node stores at least one prefix, or may also store at least one prefix tag, which is a tag generated when the prefix in the hash table corresponding to other nodes is projected onto the node.

[0068] Furthermore, for a hash table corresponding to a node, the prefix marker stored in that hash table might be the same as a prefix stored in the same hash table. In this case, to save storage space, the hash table only stores that prefix marker and labels it with a mixed prefix marker, indicating that the prefix marker is both a projection of a prefix from another hash table and an original prefix in this hash table. Conversely, if the prefix marker is only a projection of a prefix from another hash table, then it is labeled with a pure prefix marker.

[0069] like Figure 1 As shown, the prefix F in the hash table corresponding to node 6 needs to be projected onto node 5, leaving a prefix marker M3. Prefix marker M3 consists of the first 5 bits of prefix F, 10111. Prefix marker M3 can then be projected onto node 3, leaving a prefix marker M2, which consists of the first 3 bits of prefix marker M3, 101.

[0070] After storing the prefix tags in the hash table, during route lookup on the binary search tree, starting from the root node, if no prefix or prefix tag is found in the hash table corresponding to the root node, the search proceeds to the left subtree of the root node. If a prefix tag is found in the hash table corresponding to the root node, the search continues to the right subtree. The matching ends when a prefix is ​​found in the hash table corresponding to the root node.

[0071] Additionally, when a pure prefix tag is matched, if probing the right subtree also fails, it's necessary to return to the node containing the pure prefix tag and continue probing the left subtree—that is, backtracking. To avoid backtracking during the probing process, the best matching prefix (BMP) shorter than the original FIB is maintained for each prefix tag; that is, each prefix tag corresponds to one BMP. Thus, when a prefix tag is matched, its BMP is first used as the current search result. If no match is found in the right subtree of the node containing the prefix tag, then the prefix tag's BMP is used as the final search result. If a match is found in the right subtree of the node containing the prefix tag, then the search result is updated.

[0072] by Figure 1 For example, the BMPs of prefix markers M1 and M2 are both prefix A, while the BMP of prefix marker M3 is prefix D. However, the above scheme requires a large number of hash probes and has a high average number of memory accesses in IPv6 scenarios, making it difficult to meet the high-speed forwarding requirements of forwarding platforms. In addition, the above method does not involve how to update the prefix, making it unsuitable for scenarios with high network dynamics.

[0073] Based on this, this application provides an address matching method. This method, on the one hand, can extract finer-grained pointing information to help forwarding devices plan route lookup paths, thereby reducing the number of hash probes in the route lookup process and improving route lookup performance. On the other hand, it utilizes the association relationship between prefix tags and their BMP on the binary search tree to design a dynamic maintenance mechanism for the BMP of prefix tags with limited influence domains, thus supporting rapid incremental updates. Details will be described in subsequent embodiments and will not be elaborated here.

[0074] The address matching system, address matching method, and related apparatus provided in the embodiments of this application will be explained in detail below.

[0075] Figure 2 This is a schematic diagram of the architecture of a network system provided in an embodiment of this application. Figure 2As shown, the system includes a first network device 10 and a second network device 20. The first network device 10 and the second network device 20 are connected via a wired or wireless connection for communication. In some embodiments, the first network device 10 and the second network device 20 may also communicate without a wired connection. Figure 2 It is not a network but a direct communication connection.

[0076] The first network device 10 is used to send a message to the second network device 20. The second network device 20 is used to receive the message, and based on the destination address of the message, find the longest prefix in its local FIB that matches the destination address to determine the forwarding rules for the message, and then continue to forward the message based on the determined forwarding rules.

[0077] In some embodiments, such as Figure 2 As shown, the second network device 20 is equipped with a FIB lookup module. This FIB lookup module is used to find the longest prefix matching the destination address based on the method provided in this application embodiment, in order to solve the performance bottleneck problem of address matching in scenarios such as IPv6. This FIB module can also support dynamic incremental updates of prefixes in the FIB, avoiding the low efficiency of dynamic incremental updates. Detailed technical implementation methods will be described in subsequent embodiments and will not be elaborated here.

[0078] Furthermore, the first network device 10 and / or the second network device 20 can be network devices such as routers, switches, and firewalls. This application does not limit this aspect.

[0079] It should be noted that the above example illustrates the application scenario of the address matching method provided in this application embodiment using route lookup as an example. Optionally, the address matching method provided in this application embodiment can also be applied to other scenarios that require address matching, which will not be illustrated here.

[0080] Figure 3 This is a flowchart of an address matching method provided in an embodiment of this application. This method can be applied to... Figure 2 Any network device in the architecture shown. For example... Figure 3 As shown, the method includes the following steps.

[0081] Step 301: The network device determines the address to be matched and the binary search tree. The binary search tree includes multiple nodes, each node indicating a prefix length, and each prefix length corresponds to a hash table. Each hash table is used to store at least one prefix with a length of the corresponding prefix length, or at least one prefix and at least one prefix tag. Each prefix tag is obtained by projecting the prefixes in other hash tables according to the prefix length corresponding to the hash table where the corresponding prefix tag is located.

[0082] In step 301, the address to be matched can be, for example, the destination address of a packet received by the network device. Additionally, the binary search tree is based on the network device's local FIB configuration; for details on binary search trees, please refer to [link / reference needed]. Figure 1 The relevant content will not be repeated here.

[0083] The process for generating prefix tags can also be found by referring to [the documentation / reference]. Figure 1 The relevant content will not be repeated here.

[0084] Step 302: Match the address with the hash table corresponding to the first node among the multiple nodes. The first node can be any one of these multiple nodes.

[0085] Specifically, matching the address with the hash table corresponding to the first node among multiple nodes involves: extracting the first few bits of the address according to the prefix length indicated by the first node to obtain a bit sequence of length equal to the prefix length; traversing all prefixes in the hash table corresponding to the first node; if the hash table corresponding to the first node also includes prefix tags, then traversing all prefix tags in that hash table is also necessary; during the traversal, if a prefix or prefix tag is the same as the bit sequence, then it is determined that the address matches that prefix or prefix tag, the matched prefix is ​​called the target prefix, and the matched prefix tag is called the target prefix tag.

[0086] If a target prefix is ​​matched, that target prefix is ​​used as the prefix that matches the address, and the search process ends. If a target prefix marker is matched, the search needs to continue based on step 303 below.

[0087] Furthermore, the first node can be, for example, the root node in a binary search tree. Alternatively, the first node can also be any node that needs to be searched during the address matching process.

[0088] Step 303: If the address matches the target prefix tag in the hash table corresponding to the first node, then obtain the heuristic information corresponding to the target prefix tag. The heuristic information refers to the information associated with at least one heuristic information node, which is the node corresponding to the hash table where the prefix of the target prefix tag is projected.

[0089] In this embodiment, to improve routing lookup efficiency, heuristic information is maintained for each prefix tag. This heuristic information records the information of the node corresponding to the hash table of the prefix projected onto that prefix tag. Thus, during subsequent routing lookups, if the address to be matched matches a prefix tag in the hash table corresponding to a node, it is not necessary to traverse every node in the right subtree of that node to find the longest prefix matching that address. Instead, the search range is narrowed down directly based on the heuristic information, and the longest prefix matching that address is found within the narrowed search range. This reduces the number of hash probes and improves routing lookup efficiency.

[0090] The heuristic information can be stored in a hash table containing the prefix tag, so that when a prefix tag is matched in the hash table, the heuristic information of that prefix tag can be quickly retrieved. Optionally, the heuristic information can also be stored in other ways, which is not limited in this embodiment.

[0091] Step 304: Find the longest prefix that matches the address based on the heuristic information corresponding to the target prefix tag.

[0092] As can be seen from step 303, this heuristic information can narrow down the route lookup range, thereby reducing the number of hash probes and improving route lookup efficiency.

[0093] The implementation process of step 304 is related to the specific content of the heuristic information. For ease of explanation, the implementation method of the heuristic information will be described in detail here first. The heuristic information provided in the embodiments of this application may include the following two implementation methods.

[0094] (1) Heuristic information includes the prefix length indicated by each heuristic information node in at least one heuristic information node.

[0095] For example, for Figure 1 The binary search tree shown has a prefix label M3, which is the prefix label obtained by projecting the prefix F from the hash table corresponding to node 6. Therefore, as shown... Figure 4 As shown, the heuristic information corresponding to the prefix marker M3 includes 6. This value 6 is used to indicate that the heuristic information node is the node with a prefix length of 6 indicated in the binary search tree, that is, node 6. Figure 4 Heuristic information (HI) is recorded as HI.

[0096] For example, in Figure 4 In the hash table, prefix marker M2 is the prefix marker obtained by projecting prefix D from the hash table corresponding to node 4 and prefix F from the hash table corresponding to node 6. Therefore, as shown in the original text... Figure 4As shown, the heuristic information (HI) corresponding to the prefix marker M2 includes 4 and 6. These values ​​4 and 6 are used to indicate that the heuristic information nodes are nodes in the binary search tree with prefix lengths of 4 and 6 respectively, namely nodes 4 and 6.

[0097] For example, in Figure 4 In the hash table corresponding to node 7, the prefix label M1 is the prefix label obtained by projecting the prefix G from the hash table. Therefore, as shown in the original text... Figure 4 As shown, the heuristic information (HI) corresponding to the prefix marker M1 includes 7. This value 7 is used to indicate that the heuristic information node is the node with a prefix length of 7 indicated in the binary search tree, that is, node 7.

[0098] In this scenario, the process of finding the longest prefix that matches the address based on the heuristic information corresponding to the target prefix tag in step 304 can be as follows: based on the prefix length indicated by each heuristic information node in at least one heuristic information node, find the longest prefix that matches the address from the binary search tree.

[0099] By directly recording the prefix length indicated by each heuristic information node in the heuristic information, each heuristic information node can be directly determined based on the recorded prefix length during route lookup, thereby quickly finding the longest prefix matching the address from the binary search tree.

[0100] Specifically, in some embodiments, the process of finding the longest prefix matching the address from the binary search tree based on the prefix length indicated by each heuristic information node in at least one heuristic information node can be as follows: based on the prefix length indicated by each heuristic information node in at least one heuristic information node, determine the common nearest ancestor node of at least one heuristic information node, the common nearest ancestor node being the root node of the smallest subtree containing all heuristic information nodes in the binary search tree, and find the longest prefix matching the address from the subtree rooted at the common nearest ancestor node in the binary search tree.

[0101] After determining each heuristic information node based on the prefix length recorded in the heuristic information, the routing search range can be narrowed down to the subtree rooted at the common nearest ancestor node in the binary search tree, thereby reducing the routing search range and improving routing search efficiency.

[0102] For example, the implementation of finding the longest prefix matching the address from the subtree rooted at the common nearest ancestor node in the binary search tree can be as follows: starting from the root node of the subtree rooted at the common nearest ancestor node, that is, starting from the common nearest ancestor node, traverse all nodes in the subtree, treat each node as a binary search node, and search for the longest prefix matching the address from the hash table corresponding to the binary search node.

[0103] For example, for Figure 4 In the binary search tree shown, if the destination address is 10111111, then after matching the destination address with the hash table corresponding to node 3, the destination address matches the prefix marker M2. The heuristic information (HI) corresponding to the prefix marker M2 includes 4 and 6, determining that the common nearest ancestor of nodes 4 and 6 is node 5. Therefore, traversing the hash tables corresponding to all nodes in the subtree rooted at node 5 (i.e., traversing the hash tables corresponding to nodes 5, 4, and 6 respectively) will find the longest prefix matching the destination address 10111111. Through this operation, finding the longest prefix matching the destination address 10111111 requires four hash lookups: searching the hash tables corresponding to nodes 3, 5, 4, and 6 respectively.

[0104] For example, to further reduce the number of hash probes, the implementation of finding a prefix matching the address from the subtree rooted at the common nearest ancestor node can be as follows: Use the common nearest ancestor node of at least one heuristic information node as a binary search node, and search for a prefix matching the address in the hash table corresponding to the binary search node. If no prefix matching the address is found in the hash table corresponding to the binary search node, and there are still some heuristic information nodes in the left subtree of the common nearest ancestor node, update some of the heuristic information nodes to at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of at least one heuristic information node, until a prefix matching the address is found. The found prefix is ​​taken as the longest prefix matching the address.

[0105] The heuristic search path determined by the above method can traverse all heuristic information nodes in at least one heuristic information node, thereby improving search accuracy while narrowing the search range.

[0106] For example, for Figure 4In the binary search tree shown, if the destination address is 10111111, then after matching the destination address with the hash table corresponding to node 3, the destination address matches the prefix marker M2. The heuristic information (HI) corresponding to prefix marker M2 includes 4 and 6, determining that the common lowest ancestor of nodes 4 and 6 is node 5. Therefore, after matching the destination address with the hash table corresponding to node 5, the destination address matches the prefix marker M3. The heuristic information (HI) corresponding to prefix marker M3 includes 6, determining that the common lowest ancestor of node 6 is still node 6. Therefore, after matching the destination address with the hash table corresponding to node 6, the prefix F is matched, thus determining that the longest prefix matching the destination address is prefix F. Through this operation, finding the longest prefix matching the destination address 10111111 only requires three hash lookups: searching the hash tables corresponding to nodes 3, 5, and 6 respectively.

[0107] For example, if the destination address is 1011011, after matching the destination address with the hash table corresponding to node 3, the destination address matches the prefix marker M2. The heuristic information (HI) corresponding to prefix marker M2 includes 4 and 6, determining that the common nearest ancestor of nodes 4 and 6 is node 5. Therefore, after matching the destination address with the hash table corresponding to node 5, the destination address does not match any prefix or prefix marker. However, the left subtree of the common nearest ancestor node (node ​​5) still contains heuristic information node 4, and the common nearest ancestor of node 4 is node 4 itself. Therefore, the destination address is matched with the hash table corresponding to node 4, and the destination address matches the prefix D in the hash table corresponding to node 4, thus determining that the longest prefix matching the destination address is prefix D. Through this operation, finding the longest prefix matching the destination address 1011011 only requires three hash lookups: searching the hash tables corresponding to nodes 3, 5, and 4 respectively.

[0108] As another example, in order to further reduce the number of searches, the implementation of finding a prefix that matches the address from the subtree rooted at the common nearest ancestor node can be as follows: after determining the common nearest ancestor node of at least one heuristic information node, determine whether the common nearest ancestor node of at least one heuristic information node is a heuristic information node.

[0109] If the common nearest ancestor (CLA) of at least one heuristic information node is one of at least one heuristic information nodes, then the CLA of at least one heuristic information node is used as a binary search node, and a prefix matching the address is searched in the hash table corresponding to the binary search node. If the CLA is not one of at least one heuristic information node, then the heuristic information nodes in the right subtree of the CLA are updated to at least one heuristic information node, and the operation of determining the CLA of at least one heuristic information node is returned until the most recently determined CLA is one of at least one heuristic information node, and the most recently determined CLA is used as a binary search node, and a prefix matching the address is searched in the hash table corresponding to the binary search node. Alternatively, the process continues until the most recently determined CLA has no right subtree or no heuristic information node in the right subtree, and the most recently determined CLA is not a heuristic information node.

[0110] For each common nearest ancestor node determined above, if a heuristic information node exists in the left subtree of the common nearest ancestor node, then update the heuristic information node in the left subtree to at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree. The finally found prefix is ​​taken as the longest prefix matching the address.

[0111] When traversing the heuristic information nodes using the above method, the heuristic information nodes closest to the right side of the binary search tree can be traversed first. Since the prefix length of nodes closer to the right in the binary search tree is larger, when searching for the longest prefix matching the address using this heuristic search path, the heuristic information node with the larger prefix length can be quickly identified for matching, further reducing search efficiency.

[0112] For example, for Figure 4In the binary search tree shown, if the destination address is 10111111, then after matching the destination address with the hash table corresponding to node 3, the destination address matches the prefix marker M2. The heuristic information (HI) corresponding to prefix marker M2 includes 4 and 6. The common nearest ancestor of nodes 4 and 6 is determined to be node 5. At this point, it is necessary to determine whether node 5 is one of the heuristic information nodes. Since node 5 is neither heuristic information node 4 nor 6, the heuristic information node located in the right subtree of node 5 is determined, resulting in node 6. The common nearest ancestor of node 6 is node 6 itself, and node 6 is itself a heuristic information node. Therefore, node 6 is used as a binary search node. After matching the destination address with the hash table corresponding to node 6, the prefix F is matched, thus determining the longest prefix matching the destination address as prefix F. Through this operation, finding the longest prefix matching the destination address only requires two hash lookups: one for searching the hash tables corresponding to nodes 3 and the other for searching the hash tables corresponding to nodes 6.

[0113] For example, if the destination address is 1011011, after matching this address with the hash table corresponding to node 3, the destination address matches the prefix marker M2. The heuristic information (HI) corresponding to prefix marker M2 includes 4 and 6. The common nearest ancestor of nodes 4 and 6 is determined to be node 5. At this point, it is necessary to determine whether node 5 is one of the heuristic information nodes. Since node 5 is neither heuristic information node 4 nor 6, the heuristic information node located in the right subtree of node 5 is determined, resulting in node 6. The common nearest ancestor of node 6 is node 6 itself, and node 6 is itself a heuristic information node. Therefore, node 6 is used as a binary search node. After matching the destination address with the hash table corresponding to node 6, no prefix match is found.

[0114] The above process identifies the common lowest ancestor (CRA) node twice, at nodes 5 and 6. Node 6 has no left subtree, while node 5 has a left subtree containing the heuristic information node 4. Therefore, we continue to determine the CRA of node 4 in the left subtree of node 5. This CRA is node 4, which itself is a heuristic information node. Node 4 is then used as a binary search node. After matching the destination address with the hash table corresponding to node 4, the prefix D is matched, thus determining the longest prefix matching the destination address as prefix D. Through this operation, finding the longest prefix matching the destination address 1011011 requires only three hash lookups: searching the hash tables corresponding to nodes 3, 5, and 4.

[0115] Optionally, in other embodiments, the process of finding the longest prefix matching the address from the binary search tree based on the prefix length indicated by each heuristic information node in at least one heuristic information node can be as follows: directly traverse the hash table corresponding to each prefix length in the heuristic information based on the prefix length indicated by each heuristic information node in at least one heuristic information node to find the longest prefix matching the address. The traversal order is not limited in this embodiment.

[0116] (2) Heuristic information includes heuristic search paths.

[0117] In the scenario where the heuristic information is implemented as described in (1), after determining at least one common nearest ancestor node, the network device traverses the subtree of the common nearest ancestor node according to certain logic to find a prefix that matches the address. Furthermore, in order to improve the routing lookup efficiency, the heuristic information may also include a heuristic search path (HSP), which includes at least one binary decision node arranged in order. This at least one binary decision node is a node on the binary search tree, and the heuristic search path is a path that can traverse at least one heuristic information node.

[0118] Thus, the process by which a network device searches for the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag can be as follows: following the order of at least one binary search node in the heuristic search path, traverse at least one binary search node sequentially to find the longest prefix matching the address from the hash table corresponding to at least one binary search node. This eliminates the need for the network device to temporarily determine how to traverse each node; it can directly traverse according to the heuristic search path, saving the network device's computational time and thus improving its search efficiency.

[0119] To narrow down the route search, we can traverse the subtree rooted at the common lowest ancestor node. In this scenario, at least one binary decision node in the heuristic search path (HSP) is a node in the subtree rooted at the common lowest ancestor node. The common lowest ancestor node is the root node of the smallest subtree in the binary search tree that contains all heuristic information nodes.

[0120] In this case, the network device can predetermine the heuristic lookup path using the following two implementation methods and store the heuristic lookup path in a hash table. The specific storage method is not limited in this embodiment.

[0121] In some embodiments, the network device may determine the heuristic search path by: determining the common nearest ancestor (CRA) node of at least one heuristic information node; defining the CRA node as a binary decision node, where the CRA node is the root node of the smallest subtree in the binary search tree containing at least one heuristic information node; determining a subset of heuristic information nodes located in the left subtree of the CRA node, updating the subset of heuristic information nodes to at least one heuristic information node, and returning to the operation of determining the CRA node of at least one heuristic information node, until the most recently determined CRA node has no left subtree or no heuristic information node in its left subtree. The determined binary decision nodes are then sequentially configured as the respective binary decision nodes in the heuristic path.

[0122] The order of the binary search decision nodes in the heuristic path is the same as the order in which the binary search decision nodes are determined. That is, the first binary search decision node is located earlier in the heuristic search path.

[0123] For example, for Figure 4 The binary search tree shown has the following heuristic information nodes for prefix label M2: nodes 4 and 6. The common nearest ancestor of nodes 4 and 6 is determined to be node 5. Therefore, node 5 is selected as the first binary search node in the heuristic search path. The heuristic information nodes in the left subtree of the common nearest ancestor node (node ​​5) are then determined, resulting in node 4. The common nearest ancestor of node 4 is determined to be node 4 itself. Therefore, node 4 is selected as the second binary search node in the heuristic search path. Since node 4 has no right subtree, the path calculation process terminates. Thus, the resulting heuristic search path is as follows: Figure 4 As shown, HSP: 5→4.

[0124] For example, regarding Figure 5The binary search tree shown has a prefix marker M1 in the hash table corresponding to node 3. The heuristic information nodes corresponding to prefix marker M1 are nodes 4, 5, and 8. The common nearest ancestor of nodes 4, 5, and 8 is determined to be node 6. Therefore, node 6 is the first binary search node in the heuristic search path. The heuristic information nodes in the left subtree of the common nearest ancestor node (i.e., node 6) are determined, resulting in nodes 4 and 5. The common nearest ancestor of nodes 4 and 5 is determined, resulting in node 5. Therefore, node 5 is the second binary search node in the heuristic search path. The heuristic information nodes in the left subtree of this common nearest ancestor node (i.e., node 5) are determined, resulting in node 4. The common nearest ancestor of node 4 is determined, resulting in node 4 itself. Therefore, node 4 is the second binary search node in the heuristic search path. Since node 4 has no right subtree, the path calculation process terminates. Thus, the resulting heuristic search path is as follows: Figure 5 As shown, HSP: 6→5→4.

[0125] In other embodiments, the network device determines the heuristic search path by: determining each binary decision node in the heuristic path through steps one to three below:

[0126] Step 1: Determine the common lowest ancestor (CRA) node of at least one heuristic information node. The CRA is the root node of the smallest subtree in the binary search tree that contains all nodes of at least one heuristic information node. If the CRA is one of at least one heuristic information node, then the CRA is determined as a binary search node. If the CRA is not a heuristic information node, then update the heuristic information nodes in the right subtree of the CRA to at least one heuristic information node, and return to perform the operation of determining the CRA of at least one heuristic information node, until the most recently determined CRA is one of at least one heuristic information node, and the most recently determined CRA is determined as a binary search node, or until the most recently determined CRA has no right subtree or no heuristic information node in the right subtree, and the most recently determined CRA is not a heuristic information node.

[0127] Step Two: For each common nearest ancestor node determined in Step One, if a heuristic information node exists in the left subtree of this common nearest ancestor node, update the heuristic information node in the left subtree to at least one heuristic information node, and return to execute the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree. That is, return to execute Step One.

[0128] Step 3: Configure the determined binary decision nodes sequentially as the binary decision nodes in the heuristic path.

[0129] The order of the binary search nodes in the heuristic path is the same as the order in which the binary search nodes were determined in steps one and two above. That is, the first binary search node determined is located earlier in the heuristic search path.

[0130] In step two, the common nearest ancestor (CRA) nodes determined in step one can be processed in the reverse order of their determination in step one. For example, if the first CRA and the second CRA are determined sequentially in step one, then in step two, step two is performed first on the second CRA, and then on the first CRA. This ensures that nodes with longer prefixes are placed at the beginning of the heuristic search path, allowing for faster matching of the longest prefix for certain addresses, thus further reducing the number of hash probes in some scenarios.

[0131] At this point, at least one binary judgment node in the heuristic search path is at least one heuristic information node, and in the heuristic search path, the prefix length corresponding to the heuristic information node that is ranked earlier is greater than the prefix length corresponding to the heuristic information node that is ranked later.

[0132] For example, for Figure 4 In the binary search tree shown, for prefix label M2, the heuristic information nodes corresponding to prefix label M2 include nodes 4 and 6. The common lowest ancestor node of nodes 4 and 6 is determined to be node 5. At this point, node 5 is not directly used as the first binary search node in the heuristic search path. Instead, it is first determined whether node 5 itself is one of the heuristic information nodes. Since node 5 is not one of the heuristic information nodes, it is not used as the first binary search node in the heuristic search path. Instead, the heuristic information nodes located in the right subtree of node 5 are determined, resulting in node 6. Then, the common lowest ancestor node of node 6 is determined, resulting in node 6 itself. It is then determined whether node 6 is one of the heuristic information nodes. Since node 6 is one of the heuristic information nodes, it is used as the first binary search node in the heuristic search path.

[0133] In the above process, two common nearest ancestor nodes were identified: nodes 5 and 6. Since node 6 has no left subtree, step two is not performed on node 6. Step two is then performed on node 5 to determine the heuristic information node in its left subtree, resulting in node 4. The common nearest ancestor node of node 4, i.e., node 4 itself, is then determined, and it is judged whether node 4 is one of the heuristic information nodes. Since node 4 is one of the heuristic information nodes, it is used as the second binary search node in the heuristic search path. Because node 4 has no right or left subtree, the path calculation process terminates. Thus, the resulting heuristic search path is as follows: Figure 6 As shown, HSP: 6→4.

[0134] For example, regarding Figure 5 The binary search tree shown has a prefix label M1 in the hash table corresponding to node 3. The heuristic information nodes corresponding to prefix label M1 are nodes 4, 5, and 8. The common lowest ancestor of nodes 4, 5, and 8 is determined to be node 6. However, node 6 is not directly used as the first binary search node in the heuristic search path. Instead, it is first determined whether node 6 itself is one of the heuristic information nodes. Since node 6 is not one of the heuristic information nodes, it is not used as the first binary search node in the heuristic search path. Instead, the heuristic information nodes located in the right subtree of node 6 are determined, resulting in node 8. The common lowest ancestor of node 8 is then determined, resulting in node 7. The same process is repeated, determining whether node 7 itself is one of the heuristic information nodes. Since node 7 is not one of the heuristic information nodes, it is not used as the first binary search node in the heuristic search path. Finally, the heuristic information nodes located in the right subtree of node 7 are determined, resulting in node 8. Continue to determine the common nearest ancestor of node 8, thus obtaining node 8 itself. Then, determine whether node 8 is one of the heuristic information nodes. Since node 8 is one of the heuristic information nodes, it is selected as the first binary search node in the heuristic search path.

[0135] The above identifies three common nearest ancestor nodes: nodes 6, 7, and 8. Since nodes 7 and 8 have no left subtree, step two is not performed on them. For node 6, step two is performed: the heuristic information nodes in its left subtree are identified, resulting in nodes 4 and 5. The common nearest ancestor node of nodes 4 and 5 is then identified, resulting in node 5. It is then determined whether node 5 is one of the heuristic information nodes. Since node 5 is one of the heuristic information nodes, it is selected as the second binary search node in the heuristic search path. Because node 5 also has a left subtree, and this left subtree includes the heuristic information node 4, the common nearest ancestor node of node 4 is identified, resulting in node 4 itself. It is then determined whether node 4 is one of the heuristic information nodes. Since node 4 is one of the heuristic information nodes, node 5 is selected as the third binary search node in the heuristic search path. Thus, the resulting heuristic search path is as follows: Figure 7 As shown, HSP: 8→5→4.

[0136] When the heuristic information includes a heuristic search path, the network device only needs to traverse each binary search node in the order indicated by the heuristic search path when searching for the longest prefix that matches the address based on the heuristic information corresponding to the target prefix tag. For the specific implementation method, please refer to the implementation method of heuristic information (1), which will not be repeated here.

[0137] The above-described implementation of determining the heuristic search path is for illustrative purposes. Optionally, in the embodiments of this application, the heuristic search path can also be determined in other ways, which will not be illustrated here.

[0138] Furthermore, the above explanation uses the network device itself to determine the heuristic search path as an example. Alternatively, other devices in the network, such as the management terminal, can determine the heuristic search path and upload it to the network device for its use.

[0139] Alternatively, the heuristic information can be other content, such as the prefix length indicated by the common nearest ancestor node of the heuristic information node, so that the network device can start the search from the common nearest ancestor node to narrow the route search range, thereby reducing the number of hash probes and improving the route search efficiency.

[0140] Furthermore, the route lookup begins from the root node of the binary search tree. Therefore, step 301, which involves matching the address with the hash table corresponding to the first node among the plurality of nodes, can be understood as: determining an initial path, which includes the root node of the binary search tree and the consecutive left child nodes located in the left subtree of the root node; sequentially taking each node in the initial path as the first node, and performing the operation of matching the address with the hash table corresponding to the first node among the plurality of nodes in the binary search tree.

[0141] During the route lookup process, the initial path as described above can be predetermined. Then, for each node in the initial path, the address matching method provided in this application embodiment is executed to find the longest prefix that matches the address, so as to ensure that every possible longest prefix is ​​traversed, thereby improving the accuracy of the route lookup.

[0142] For example, for Figure 4 The binary search tree shown has an initial path of 3→2→1. For a destination address to be matched, the network device first matches the destination address with the hash table corresponding to node 3. If the destination address matches a target prefix marker in the hash table, the BMP of that target prefix marker is used as the search result for the destination address. Then, following the above embodiment, the device continues to search for a prefix that matches the destination address in the right subtree of node 3. If no prefix matching the destination address is found in the right subtree of node 3, the previously determined search result is used as the final search result. If a prefix matching the destination address is finally found in the right subtree of node 3, the previously determined search result is updated.

[0143] If the destination address matches a prefix in the hash table, the prefix is ​​used as the lookup result, and the lookup ends.

[0144] If the destination address does not match any prefix or prefix tag in the hash table, then node 2 in the initial path will continue to be the first node and the above operation will be performed until the longest prefix that matches the destination address is found.

[0145] Optionally, if after traversing to the first node, no longest prefix matching the destination address is found, it is determined that no longest prefix matching the destination address is currently found in the FIB.

[0146] It should be noted that in the embodiments of this application, the target prefix mark can be a pure prefix mark or a mixed prefix mark, and the embodiments of this application do not limit it.

[0147] In summary, in this embodiment, when a network device determines that an address matches a certain prefix tag, since the prefix tag also corresponds to heuristic information, and the heuristic information is used to record information associated with the heuristic information node, the network device can narrow down the search range based on the heuristic information, avoiding the need to traverse all nodes in the right subtree of the node corresponding to the hash table where the prefix tag is located. Therefore, the address matching method provided in this embodiment can reduce the number of hash probes, thereby improving routing lookup efficiency.

[0148] In addition, this application embodiment also provides a prefix update method in FIB, which will be described in detail below.

[0149] As described above, the hash table also stores the BMP for each prefix marker. The function of the BMP is detailed in the aforementioned embodiments and will not be repeated here. Therefore, adding or deleting a prefix in the FIB may affect the BMPs of some prefix markers, requiring updates to the BMPs of each prefix marker. In this embodiment, to reduce the workload of BMP update operations triggered during prefix updates, each prefix in the hash table corresponding to each node in the binary search tree has an associated affected marker list (AML). Each prefix's AML includes at least one prefix marker, and the longest matching prefix BMP of each prefix marker in the AML is the corresponding prefix. Thus, when updating a prefix, the AML corresponding to that prefix can determine which prefix markers' BMPs need updating, avoiding the need to update the global prefix marker BMPs and improving update efficiency.

[0150] The AML corresponding to each prefix can be stored in a hash table. The specific storage method is not limited in this embodiment.

[0151] Figure 8 This application provides a prefix update method, such as... Figure 8 As shown, the prefix update method includes the following steps.

[0152] Step 801: In response to the prefix update operation, update the BMP of each prefix tag in the AML corresponding to the prefix to be updated.

[0153] Since prefix update operations typically include prefix insertion or prefix deletion operations, step 801 will be explained in detail below in two scenarios.

[0154] Scenario 1: The prefix update operation includes the prefix insertion operation, and the prefix to be updated includes the first prefix to be inserted.

[0155] In Scenario 1, the implementation process of step 801 is as follows: determine the length of the first prefix, obtain the first prefix length, and insert the first prefix into the hash table corresponding to the first prefix length; determine the second prefix from the binary search tree, the second prefix is ​​the longest prefix that matches the first prefix and has a length less than the first prefix length; obtain the AML of the second prefix, obtain the second AML; determine some prefix tags in the second AML as prefix tags in the AML of the first prefix, obtain the first AML, and update the BMP of each prefix tag in the first AML to the first prefix.

[0156] When a prefix is ​​inserted, some prefix tags' BMPs may become part of the newly inserted prefix. All potentially affected prefix tags must reside in the AML of the longest matching prefix (assuming it exists) that is no longer than the inserted prefix. Therefore, when inserting the first prefix, the longest prefix with a length less than the first prefix and matching it can be determined from the binary search tree to obtain the second prefix. Then, from the AML of the second prefix, it can be determined which prefix tags' BMPs will be updated to the first prefix, thus obtaining the AML of the first prefix.

[0157] Specifically, when a prefix tag in the second AML meets the following two conditions, its BMP will be updated to the first prefix. At this point, the prefix tag will be removed from the second AML and added to the first AML, meaning that the prefix tag is taken over by the first AML. The following two conditions can also be referred to as takeover conditions.

[0158] The first condition is: the length of the prefix tag in the second AML is greater than or equal to the length of the first prefix. The second condition is: the prefix of the prefix tag in the second AML is the first prefix.

[0159] For example, in Figure 9 In the binary search tree shown, suppose we need to insert a prefix H: 11*. Since the length of prefix H is 2, the first prefix length is 2, so we insert prefix H into the hash table corresponding to node 2. We then search the binary search tree for the longest matching prefix with a length less than prefix H, which is prefix A; therefore, the second prefix is ​​prefix A. For example... Figure 9 As shown, the AML for prefix A includes prefix marker M1 and prefix marker M2. Traversing the two prefix markers in the AML for prefix A, prefix marker M2 satisfies the condition that its length is not shorter than prefix H, but prefix H is not its prefix, therefore it does not meet the takeover condition. Prefix marker M1, however, satisfies both takeover conditions. Therefore, the newly inserted AML for prefix H takes over prefix marker M1 from the AML for prefix A. Thus, the BMP of prefix marker M1 is updated from the second prefix (prefix A) to the first prefix (prefix H). Prefix marker M2 is not taken over by the AML for the first prefix, therefore the BMP of prefix marker M2 remains the second prefix (prefix A).

[0160] Optionally, in the embodiments of this application, each prefix tag in the second AML can be directly traversed, and the BMP of each prefix tag can be re-determined to determine which prefix tags in the second AML will be updated to the first prefix.

[0161] Furthermore, since a new prefix is ​​inserted, and the inserted prefix may need to be projected onto other nodes, in this embodiment of the application, after inserting the first prefix, the first prefix is ​​also projected onto the second node on the binary search tree to obtain the first prefix tag, and the first prefix tag is added to the hash table corresponding to the second node; the BMP of the first prefix tag is determined to obtain the first BMP; and the first prefix tag is added to the AML of the first BMP.

[0162] It should be noted that if the BMP for the first prefix tag is not determined in the binary search tree, the first prefix tag can be added to... Figure 9 In the default AML, in this embodiment, the prefix marker in the default AML is the prefix marker that cannot be found in the binary search tree for a corresponding BMP.

[0163] Furthermore, since the inserted prefix is ​​projected onto the first prefix tag, the heuristic information corresponding to the first prefix tag can also be determined and stored, so that subsequent execution can be performed based on the heuristic information corresponding to the first prefix tag. Figure 3 The address matching scheme in the illustrated embodiment.

[0164] like Figure 9 As shown, since prefix H does not require the insertion of prefix tags into other nodes, the insertion of the new prefix H is completed after the AML of prefix H is determined.

[0165] Scenario 2: The prefix update operation includes the prefix deletion operation, and the prefix to be updated includes the third prefix to be deleted.

[0166] In scenario two, the implementation process of step 801 is as follows: determine the length of the third prefix, obtain the length of the third prefix, delete the third prefix from the hash table corresponding to the length of the third prefix; obtain the AML of the third prefix, obtain the third AML; redetermine the BMP of each prefix tag in the third AML, and add each prefix tag in the third AML to the AML of the redetermined BMP; delete the third AML.

[0167] When a prefix is ​​deleted, the BMP needs to be recalculated for all prefix tags that use the deleted prefix as the BMP, and all potentially affected prefix tags must be in the AML of the deleted prefix. Based on this, when deleting a third prefix, the BMP of each prefix tag in the AML of the third prefix needs to be recalculated, and each prefix tag in the third AML needs to be added to the AML of the recalculated BMP.

[0168] It should be noted that when recalculating the BMP of each prefix tag in the AML of the third prefix after deleting the third prefix, there may be a prefix tag that does not have a BMP in the binary search tree, that is, the recalculated BMP is empty. In this case, the prefix tag can be added to the default AML.

[0169] For example, in Figure 10 In the binary search tree shown, suppose we need to delete prefix A: 1*. Since the length of prefix A is 1, the length of the third prefix is ​​also 1. Based on this, prefix A is deleted from the hash table corresponding to node 1. And as... Figure 10 As shown, the AML of prefix A includes prefix tag M2, so the BMP of prefix tag M2 needs to be recalculated. After deleting prefix A, the prefixes shorter than prefix tag M2 in the binary search tree are prefix B and prefix H. However, prefix B and prefix H do not match the first two bits of prefix tag M2, so the recalculated BMP of prefix tag M2 is empty. At this time, prefix tag M2 can be added to the default AML.

[0170] Furthermore, after deleting the third prefix, the heuristic information of the prefix labels projected before the third prefix needs to be updated. Therefore, in this embodiment, after deleting the third prefix, the prefix label of the third node projected onto the binary search tree can be determined to obtain the third prefix label; if no other prefix or other prefix labels are projected onto the third prefix label, the third prefix label and its corresponding heuristic information are deleted; if other prefixes or other prefix labels are projected onto the third prefix label, the heuristic information corresponding to the third prefix label is updated.

[0171] The heuristic for updating the third prefix tag can be found in [reference needed]. Figure 3 The details of how the heuristic information was determined in the embodiments will not be elaborated here.

[0172] like Figure 10 As shown, since the deleted prefix A has not been inserted into other nodes, the deletion of prefix A is completed after updating the BMP of the prefix tag in the AML of prefix A.

[0173] In summary, in the embodiments of this application, when a network device updates a prefix (e.g., adds or deletes a prefix), it can determine which prefix-marked BMPs will be affected by the prefix update based on the AML corresponding to each prefix, and then update the determined prefix-marked BMPs, thereby improving the efficiency of prefix updates.

[0174] based on Figure 3 and Figure 8 As can be seen from the embodiments shown, the technical effects of the technical solutions provided in this application can be summarized as follows:

[0175] (1) The prefix lookup process is accelerated by recording the length information of the heuristic information nodes corresponding to the prefix tags as heuristic information. The heuristic information can be used in the following ways: Figure 3 The two methods for constructing heuristic search paths described in the embodiments can also be other methods of use, and this application does not limit them.

[0176] (2) By maintaining the AML for each prefix, an efficient prefix update scheme is provided.

[0177] The apparatus involved in the embodiments of this application will be explained below.

[0178] Figure 11 This is a schematic diagram of the structure of an address matching device provided in an embodiment of this application. Figure 11 As shown, the device 1100 includes the following modules.

[0179] The first determining module 1101 is used to determine the address to be matched and the binary search tree. The binary search tree includes multiple nodes, each node indicating a prefix length, and each prefix length corresponds to a hash table. Each hash table is used to store at least one prefix with a length equal to the corresponding prefix length, or at least one prefix and at least one prefix tag. Each prefix tag is obtained by projecting the prefixes in other hash tables according to the prefix length corresponding to the hash table containing the corresponding prefix tag. For specific implementation details, please refer to [reference needed]. Figure 3 Step 301 in the embodiment.

[0180] Matching module 1102 is used to match the address with the hash table corresponding to the first node among multiple nodes, where the first node can be any one of the multiple nodes. For specific implementation details, please refer to [reference needed]. Figure 3 Step 302 in the embodiment.

[0181] The acquisition module 1103 is used to acquire heuristic information corresponding to the target prefix tag if the address matches the target prefix tag in the hash table corresponding to the first node. Heuristic information refers to information associated with at least one heuristic information node, which is the node corresponding to the hash table where the prefix of the projected target prefix tag is located. For specific implementation details, please refer to [reference needed]. Figure 3 Step 303 in the embodiment.

[0182] The lookup module 1104 is used to find the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag. For specific implementation details, please refer to [reference needed]. Figure 3 Step 304 in the embodiment.

[0183] Optionally, the heuristic information includes the prefix length indicated by each heuristic information node in at least one heuristic information node;

[0184] The lookup module 1104 is used for:

[0185] Based on the prefix length indicated by each heuristic information node in at least one heuristic information node, find the longest prefix that matches the address from the binary search tree.

[0186] Optionally, the lookup module 1104 is used for:

[0187] Based on the prefix length indicated by each heuristic information node in at least one heuristic information node, determine the common nearest ancestor node of at least one heuristic information node. The common nearest ancestor node is the root node of the smallest subtree containing all heuristic information nodes in the binary search tree.

[0188] From the subtree rooted at the common nearest ancestor node in the binary search tree, find the longest prefix that matches the address.

[0189] Optionally, the heuristic information includes a heuristic search path, which includes at least one binary decision node arranged in order, the at least one binary decision node being a node on a binary search tree, and the heuristic search path being a path capable of traversing at least one heuristic information node.

[0190] The lookup module 1104 is used for:

[0191] Following the order of at least one binary search node in the heuristic search path, traverse at least one binary search node in turn to find the longest prefix that matches the address from the hash table corresponding to at least one binary search node.

[0192] Optionally, at least one binary decision node is a node in the subtree of the binary search tree with the common nearest ancestor node as its root node, and the common nearest ancestor node is the root node of the smallest subtree of the binary search tree that contains all heuristic information nodes.

[0193] Optionally, the device 1100 further includes:

[0194] The second determining module is used to determine the common nearest ancestor node of at least one heuristic information node, and to determine the common nearest ancestor node as a binary judgment node.

[0195] The third determination module is used to determine some heuristic information nodes located in the left subtree of the common nearest ancestor node, update some heuristic information nodes to at least one heuristic information node, and return to the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree.

[0196] The first configuration module is used to sequentially configure the determined binary search decision nodes as the various binary search decision nodes in the heuristic path.

[0197] Optionally, the device 1100 further includes:

[0198] The fourth determination module is used to determine the common nearest ancestor node of at least one heuristic information node;

[0199] The fifth determination module is used to determine the common nearest ancestor node as a binary judgment node if the common nearest ancestor node is one of at least one heuristic information node, and to update the heuristic information node in the right subtree of the common nearest ancestor node to at least one heuristic information node if the common nearest ancestor node is not one of at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node is one of at least one heuristic information node, and the most recently determined common nearest ancestor node is determined as a binary judgment node, or until the most recently determined common nearest ancestor node has no right subtree or no heuristic information node in the right subtree, and the most recently determined common nearest ancestor node is not one of at least one heuristic information node;

[0200] The sixth determination module is used to update the heuristic information node in the left subtree of the determined common nearest ancestor node to at least one heuristic information node if there is a heuristic information node in the left subtree of the common nearest ancestor node, and return to the operation of determining the common nearest ancestor node of at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree.

[0201] The second configuration module is used to sequentially configure the determined binary search decision nodes as the various binary search decision nodes in the heuristic path.

[0202] Optionally, the matching module is used for:

[0203] Determine the initial path, which includes the root node of the binary search tree and the consecutive left child nodes located in the left subtree of the root node;

[0204] Each node in the initial path is taken as the first node in turn, and the operation of matching the address with the hash table corresponding to the first node among multiple nodes is performed.

[0205] Optionally, for any hash table, if the hash table stores prefix tags, the hash table is also used to store the longest matching prefix BMP of the prefix tags. Each prefix in the hash table corresponding to any node in the binary search tree corresponds to an associated prefix tag list AML. The AML of each prefix includes at least one prefix tag, and the BMP of the prefix tags in the AML of each prefix is ​​the corresponding prefix.

[0206] The device 1100 also includes:

[0207] The first update module, in response to a prefix update operation, updates the BMP of each prefix tag in the AML corresponding to the prefix to be updated. For specific implementation details, please refer to [reference needed]. Figure 8 Step 801 in the embodiment.

[0208] Optionally, the prefix update operation includes a prefix insertion operation, and the prefix to be updated includes the first prefix to be inserted;

[0209] The first update module is used for:

[0210] Determine the length of the first prefix, obtain the first prefix length, and insert the first prefix into the hash table corresponding to the first prefix length;

[0211] The second prefix is ​​determined from the binary search tree. The second prefix is ​​the longest prefix that matches the first prefix and has a length less than the length of the first prefix.

[0212] Get the AML with the second prefix, and obtain the second AML;

[0213] The prefix tags in the second AML are identified as prefix tags in the first prefix AML, thus obtaining the first AML. The BMP of each prefix tag in the first AML is then updated from the second prefix to the first prefix.

[0214] Optionally, some prefix tags in the second AML are prefix tags that satisfy the following conditions:

[0215] The length of a partial prefix tag is greater than or equal to the length of the first prefix, and the prefix of the partial prefix tag is the first prefix.

[0216] Optionally, the device 1100 further includes:

[0217] The projection module is used to project the first prefix onto the second node in the binary search tree to obtain the first prefix label, and add the first prefix label to the hash table corresponding to the second node;

[0218] The seventh determining module is used to determine the BMP of the first prefix tag to obtain the first BMP;

[0219] Add a module to add the first prefix tag in the AML of the first BMP.

[0220] Optionally, the device 1100 further includes:

[0221] The storage module is used to determine and store the heuristic information corresponding to the first prefix tag.

[0222] Optionally, the prefix update operation includes a prefix deletion operation, and the prefix to be updated includes the third prefix to be deleted;

[0223] The first update module is used for:

[0224] Determine the length of the third prefix, obtain the length of the third prefix, and delete the third prefix from the hash table corresponding to the length of the third prefix.

[0225] Get the AML with the third prefix, and obtain the third AML;

[0226] Redetermine the BMP for each prefix tag in the third AML, and add each prefix tag in the third AML to the AML of the redetermined BMP;

[0227] Delete the third AML.

[0228] Optionally, the device 1100 further includes:

[0229] The eighth determination module is used to determine the prefix label of the third node projected onto the binary search tree, and obtain the third prefix label;

[0230] The deletion module is used to delete the third prefix tag and its corresponding heuristic information if no other prefix is ​​projected onto the third prefix tag.

[0231] The second update module is used to update the heuristic information corresponding to the third prefix tag if other prefixes are projected onto the third prefix tag.

[0232] In this embodiment, when it is determined that the address to be matched matches a certain prefix tag, since the prefix tag also corresponds to heuristic information, and the heuristic information is used to record information associated with the heuristic information node, the search range can be narrowed based on the heuristic information, avoiding the need to traverse all nodes in the right subtree of the node corresponding to the hash table where the prefix tag is located. Therefore, the address matching method provided in this embodiment can reduce the number of nodes traversed, thereby improving the routing lookup efficiency.

[0233] It should be noted that the address matching device provided in the above embodiments is only illustrated by the division of the above functional modules during address matching. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the address matching device and the address matching method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.

[0234] Figure 12 This is a schematic diagram of the structure of a network device provided in this application embodiment. Figure 2 The address matching system in the middle can be used Figure 12 This is implemented using the network device shown. See also Figure 12 The network device includes a processor 1201, a communication bus 1202, a memory 1203, and at least one communication interface 1204.

[0235] The processor 1201 may be a general-purpose central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present application.

[0236] The communication bus 1202 is used to transmit information between the aforementioned components.

[0237] The memory 1203 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or it may be an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), a magnetic disk or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. The memory 1203 may exist independently and be connected to the processor 1201 via the communication bus 1202. The memory 1203 may also be integrated with the processor 1201.

[0238] The memory 1203 stores program code for executing the scheme of this application, and its execution is controlled by the processor 1201. The processor 1201 executes the program code stored in the memory 1203. The program code may include one or more software modules. Figure 3 as well as Figure 8 The network device shown can determine the data used for application development through one or more software modules in the program code in the processor 1201 and memory 1203.

[0239] Communication interface 1204 uses any transceiver-like device to communicate with other devices or communication networks, such as wired networks, radio access networks (RAN), wireless local area networks (WLAN), etc.

[0240] In a specific implementation, as one example, a network device may include multiple processors, for example... Figure 12 The processors 1201 and 1205 are shown. Each of these processors may be a single-core processor or a multi-core processor. A processor here may refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).

[0241] In a specific implementation, as one embodiment, the network device may further include an output device 1206 and an input device 1207. The output device 1206 communicates with the processor 1201 and can display information in various ways. For example, the output device 1206 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 1207 communicates with the processor 1201 and can receive user input in various ways. For example, the input device 1207 may be a mouse, keyboard, touchscreen device, or sensing device, etc.

[0242] The network devices mentioned above can be routers or switches or other forwarding devices with network forwarding functions. Examples of each of these devices will not be provided in this application.

[0243] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).

[0244] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0245] The above descriptions are embodiments provided in this application and are not intended to limit the embodiments of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of the embodiments of this application.

Claims

1. An address matching method, characterized in that, include: The address to be matched and the binary search tree are determined. The binary search tree includes multiple nodes, each node indicating a prefix length, and each prefix length corresponds to a hash table. Each hash table is used to store at least one prefix with a length of the corresponding prefix length, or at least one prefix and at least one prefix tag. Each prefix tag is obtained by projecting the prefixes in other hash tables according to the prefix length corresponding to the hash table where the prefix tag is located. For any node in the binary search tree, when any node is taken as the root node, if the left subtree of the root node is not empty, then the prefix length indicated by all nodes in the left subtree is less than the prefix length indicated by the root node. If the right subtree of the root node is not empty, then the prefix length indicated by all nodes in the right subtree is greater than the prefix length indicated by the root node. The address is matched with the hash table corresponding to the first node among the plurality of nodes, where the first node is any one of the plurality of nodes; If the address matches the target prefix tag in the hash table corresponding to the first node, then the heuristic information corresponding to the target prefix tag is obtained. The heuristic information refers to information associated with at least one heuristic information node. The at least one heuristic information node is: the node corresponding to the prefix of the target prefix tag or the hash table where the prefix tag is located, which is projected onto the first node in the right subtree rooted at the first node. Based on the heuristic information corresponding to the target prefix tag, find the longest prefix that matches the address.

2. The method as described in claim 1, characterized in that, The heuristic information includes the prefix length indicated by each of the at least one heuristic information nodes; The step of finding the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag includes: Based on the prefix length indicated by each of the at least one heuristic information nodes, the longest prefix matching the address is found in the binary search tree.

3. The method as described in claim 2, characterized in that, The step of finding the longest prefix matching the address from the binary search tree based on the prefix length indicated by each of the at least one heuristic information nodes includes: Based on the prefix length indicated by each of the at least one heuristic information nodes, the common nearest ancestor node of the at least one heuristic information node is determined, and the common nearest ancestor node is the root node of the smallest subtree containing all heuristic information nodes in the binary search tree. From the subtree rooted at the common nearest ancestor node in the binary search tree, find the longest prefix that matches the address.

4. The method as described in claim 1, characterized in that, The heuristic information includes a heuristic search path, which includes at least one binary decision node arranged in order. The at least one binary decision node is a node on the binary search tree, and the heuristic search path is a path that can traverse the at least one heuristic information node. The step of finding the longest prefix matching the address based on the heuristic information corresponding to the target prefix tag includes: Following the order of the at least one binary decision node in the heuristic search path, the at least one binary decision node is traversed sequentially to find the longest prefix matching the address from the hash table corresponding to the at least one binary decision node.

5. The method as described in claim 4, characterized in that, The at least one binary decision node is a node in the subtree of the binary search tree with the common nearest ancestor node as the root node, and the common nearest ancestor node is the root node of the smallest subtree of the binary search tree that contains all heuristic information nodes.

6. The method as described in claim 4 or 5, characterized in that, The method further includes: Determine the common nearest ancestor node of the at least one heuristic information node, and define the common nearest ancestor node as a binary judgment node; Determine a subset of heuristic information nodes located in the left subtree of the common nearest ancestor node, update the subset of heuristic information nodes to the at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of the at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree; The determined binary decision nodes are sequentially configured as the binary decision nodes in the heuristic search path.

7. The method as described in claim 4 or 5, characterized in that, The method further includes: Determine the common nearest ancestor node of the at least one heuristic information node; If the common nearest ancestor node is one of the at least one heuristic information nodes, then the common nearest ancestor node is determined as a binary decision node. If the common nearest ancestor node is not one of the at least one heuristic information nodes, then the heuristic information nodes in the right subtree of the common nearest ancestor node are updated to the at least one heuristic information node, and the operation of determining the common nearest ancestor node of the at least one heuristic information node is returned until the most recently determined common nearest ancestor node is one of the at least one heuristic information nodes, and the most recently determined common nearest ancestor node is determined as a binary decision node, or until the most recently determined common nearest ancestor node has no right subtree or no heuristic information node in the right subtree, and the most recently determined common nearest ancestor node is not one of the at least one heuristic information node. For each determined common nearest ancestor node, if there is a heuristic information node in the left subtree of the common nearest ancestor node, update the heuristic information node in the left subtree to the at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of the at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree. The determined binary decision nodes are sequentially configured as the binary decision nodes in the heuristic search path.

8. The method according to any one of claims 1-7, characterized in that, The step of matching the address with the hash table corresponding to the first node among the plurality of nodes includes: Determine an initial path, which includes the root node of the binary search tree and the consecutive left child nodes located in the left subtree of the root node; Each node in the initial path is sequentially designated as the first node, and the operation of matching the address with the hash table corresponding to the first node among the plurality of nodes is performed.

9. The method according to any one of claims 1-8, characterized in that, For any hash table, if the hash table stores prefix tags, the hash table is also used to store the longest matching prefix BMP of the prefix tags. Each prefix in the hash table corresponding to any node in the binary search tree corresponds to an associated prefix tag list AML. Each prefix's AML includes at least one prefix tag, and the BMP of the prefix tags in each prefix's AML is the corresponding prefix. The method further includes: In response to the prefix update operation, the BMP of each prefix tag in the AML corresponding to the prefix to be updated is updated based on the AML corresponding to the prefix to be updated.

10. The method as described in claim 9, characterized in that, The prefix update operation includes a prefix insertion operation, and the prefix to be updated includes a first prefix to be inserted. The step of updating the BMP of each prefix tag in the AML corresponding to the prefix to be updated includes: Determine the length of the first prefix, obtain the first prefix length, and insert the first prefix into the hash table corresponding to the first prefix length; The second prefix is ​​determined from the binary search tree. The second prefix is ​​the longest prefix that matches the first prefix and has a length less than the length of the first prefix. Obtain the AML with the second prefix to get the second AML; The prefix tags in the second AML are determined to be the prefix tags in the AML of the first prefix, thus obtaining the first AML. The BMP of each prefix tag in the first AML is updated from the second prefix to the first prefix.

11. The method as described in claim 10, characterized in that, In the second AML, some prefix tags are prefix tags that satisfy the following conditions: The length of the partial prefix marker is greater than or equal to the length of the first prefix, and the prefix of the partial prefix marker is the first prefix.

12. The method as described in claim 10 or 11, characterized in that, The method further includes: Project the first prefix onto the second node in the binary search tree to obtain the first prefix tag, and add the first prefix tag to the hash table corresponding to the second node; Determine the BMP of the first prefix tag to obtain the first BMP; Add the first prefix tag to the AML of the first BMP.

13. The method as described in claim 12, characterized in that, After projecting the first prefix onto the second node of the binary search tree to obtain the first prefix label, the method further includes: Determine and store the heuristic information corresponding to the first prefix tag.

14. The method as described in claim 9, characterized in that, The prefix update operation includes a prefix deletion operation, and the prefix to be updated includes a third prefix to be deleted; The step of updating the BMP of each prefix tag in the AML corresponding to the prefix to be updated includes: Determine the length of the third prefix, obtain the length of the third prefix, and delete the third prefix from the hash table corresponding to the length of the third prefix; Obtain the AML of the third prefix to get the third AML; Redetermine the BMP for each prefix tag in the third AML, and add each prefix tag in the third AML to the AML of the redetermined BMP; Delete the third AML.

15. The method as described in claim 14, characterized in that, The method further includes: Determine the prefix label of the third node projected onto the binary search tree to obtain the third prefix label; If no other prefixes are projected onto the third prefix tag, then the third prefix tag and its corresponding heuristic information are deleted; If other prefixes are projected onto the third prefix tag, then the heuristic information corresponding to the third prefix tag is updated.

16. An address matching device, characterized in that, include: The first determining module is used to determine the address to be matched and the binary search tree. The binary search tree includes multiple nodes, each node indicating a prefix length, and each prefix length corresponds to a hash table. Each hash table is used to store at least one prefix with a length of the corresponding prefix length, or at least one prefix and at least one prefix tag. Each prefix tag is obtained by projecting the prefixes in other hash tables according to the prefix length corresponding to the hash table where the prefix tag is located. For any node in the binary search tree, when any node is taken as the root node, if the left subtree of the root node is not empty, then the prefix length indicated by all nodes in the left subtree is less than the prefix length indicated by the root node. If the right subtree of the root node is not empty, then the prefix length indicated by all nodes in the right subtree is greater than the prefix length indicated by the root node. A matching module is used to match the address with the hash table corresponding to the first node among the plurality of nodes, wherein the first node is any one of the plurality of nodes; The acquisition module is used to acquire heuristic information corresponding to the target prefix mark if the address matches the target prefix mark in the hash table corresponding to the first node. The heuristic information refers to information associated with at least one heuristic information node. The at least one heuristic information node is: the node corresponding to the prefix of the target prefix mark or the hash table where the prefix mark is located, which is obtained by projecting the right subtree rooted at the first node onto the first node. The lookup module is used to find the longest prefix that matches the address based on the heuristic information corresponding to the target prefix tag.

17. The apparatus as claimed in claim 16, characterized in that, The heuristic information includes the prefix length indicated by each of the at least one heuristic information nodes; The search module is used for: Based on the prefix length indicated by each of the at least one heuristic information nodes, the longest prefix matching the address is found in the binary search tree.

18. The apparatus as claimed in claim 17, characterized in that, The search module is used for: Based on the prefix length indicated by each of the at least one heuristic information nodes, the common nearest ancestor node of the at least one heuristic information node is determined, and the common nearest ancestor node is the root node of the smallest subtree containing all heuristic information nodes in the binary search tree. From the subtree rooted at the common nearest ancestor node in the binary search tree, find the longest prefix that matches the address.

19. The apparatus as claimed in claim 16, characterized in that, The heuristic information includes a heuristic search path, which includes at least one binary decision node arranged in order. The at least one binary decision node is a node on the binary search tree, and the heuristic search path is a path that can traverse the at least one heuristic information node. The search module is used for: Following the order of the at least one binary decision node in the heuristic search path, the at least one binary decision node is traversed sequentially to find the longest prefix matching the address from the hash table corresponding to the at least one binary decision node.

20. The apparatus as claimed in claim 19, characterized in that, The at least one binary decision node is a node in the subtree of the binary search tree with the common nearest ancestor node as the root node, and the common nearest ancestor node is the root node of the smallest subtree of the binary search tree that contains all heuristic information nodes.

21. The apparatus as claimed in claim 19 or 20, characterized in that, Also includes: The second determining module is used to determine the common nearest ancestor node of the at least one heuristic information node, and to determine the common nearest ancestor node as a binary judgment node. The third determining module is used to determine a portion of the heuristic information nodes located in the left subtree of the common nearest ancestor node, update the portion of the heuristic information nodes to the at least one heuristic information node, and return to the operation of determining the common nearest ancestor node of the at least one heuristic information node until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree. The first configuration module is used to sequentially configure the determined binary judgment nodes as the various binary judgment nodes in the heuristic search path.

22. The apparatus as claimed in claim 19 or 20, characterized in that, Also includes: The fourth determining module is used to determine the common nearest ancestor node of the at least one heuristic information node; The fifth determining module is used to determine the common nearest ancestor node as a binary judgment node if the common nearest ancestor node is one of the at least one heuristic information nodes; if the common nearest ancestor node is not one of the at least one heuristic information nodes, update the heuristic information nodes in the right subtree of the common nearest ancestor node to the at least one heuristic information node, and return to perform the operation of determining the common nearest ancestor node of the at least one heuristic information node, until the most recently determined common nearest ancestor node is one of the at least one heuristic information node, and the most recently determined common nearest ancestor node is determined as a binary judgment node; or, until the most recently determined common nearest ancestor node has no right subtree or no heuristic information node in the right subtree, and the most recently determined common nearest ancestor node is not one of the at least one heuristic information node. The sixth determining module is used to update the heuristic information node in the left subtree of the determined common nearest ancestor node to the at least one heuristic information node if there is a heuristic information node in the left subtree of the common nearest ancestor node, and return to perform the operation of determining the common nearest ancestor node of the at least one heuristic information node, until the most recently determined common nearest ancestor node has no left subtree or no heuristic information node in the left subtree. The second configuration module is used to sequentially configure the determined binary judgment nodes as the various binary judgment nodes in the heuristic search path.

23. The apparatus according to any one of claims 16-22, characterized in that, The matching module is used for: Determine an initial path, which includes the root node of the binary search tree and the consecutive left child nodes located in the left subtree of the root node; Each node in the initial path is sequentially designated as the first node, and the operation of matching the address with the hash table corresponding to the first node among the plurality of nodes is performed.

24. The apparatus according to any one of claims 16-23, characterized in that, For any hash table, if the hash table stores prefix tags, the hash table is also used to store the longest matching prefix BMP of the prefix tags. Each prefix in the hash table corresponding to any node in the binary search tree corresponds to an associated prefix tag list AML. Each prefix's AML includes at least one prefix tag, and the BMP of the prefix tags in each prefix's AML is the corresponding prefix. The device further includes: The first update module is used to update the BMP of each prefix tag in the AML corresponding to the prefix to be updated, based on the prefix update operation.

25. The apparatus as claimed in claim 24, characterized in that, The prefix update operation includes a prefix insertion operation, and the prefix to be updated includes a first prefix to be inserted. The first update module is used for: Determine the length of the first prefix, obtain the first prefix length, and insert the first prefix into the hash table corresponding to the first prefix length; The second prefix is ​​determined from the binary search tree. The second prefix is ​​the longest prefix that matches the first prefix and has a length less than the length of the first prefix. Obtain the AML with the second prefix to get the second AML; The prefix tags in the second AML are determined to be the prefix tags in the AML of the first prefix, thus obtaining the first AML. The BMP of each prefix tag in the first AML is updated from the second prefix to the first prefix.

26. The apparatus as claimed in claim 25, characterized in that, In the second AML, some prefix tags are prefix tags that satisfy the following conditions: The length of the partial prefix marker is greater than or equal to the length of the first prefix, and the prefix of the partial prefix marker is the first prefix.

27. The apparatus as claimed in claim 25 or 26, characterized in that, Also includes: The projection module is used to project the first prefix onto the second node of the binary search tree to obtain the first prefix tag, and add the first prefix tag to the hash table corresponding to the second node; The seventh determining module is used to determine the BMP of the first prefix tag to obtain the first BMP; Add a module to add the first prefix tag in the AML of the first BMP.

28. The apparatus as claimed in claim 27, characterized in that, Also includes: The storage module is used to determine and store the heuristic information corresponding to the first prefix tag.

29. The apparatus as claimed in claim 24, characterized in that, The prefix update operation includes a prefix deletion operation, and the prefix to be updated includes a third prefix to be deleted; The first update module is used for: Determine the length of the third prefix, obtain the length of the third prefix, and delete the third prefix from the hash table corresponding to the length of the third prefix; Obtain the AML of the third prefix to get the third AML; Redetermine the BMP for each prefix tag in the third AML, and add each prefix tag in the third AML to the AML of the redetermined BMP; Delete the third AML.

30. The apparatus as claimed in claim 29, characterized in that, Also includes: The eighth determining module is used to determine the prefix label of the third node projected onto the binary search tree, thereby obtaining the third prefix label; The deletion module is used to delete the third prefix tag and its corresponding heuristic information if no other prefix is ​​projected onto the third prefix tag. The second update module is used to update the heuristic information corresponding to the third prefix tag if there are other prefixes projected onto the third prefix tag.

31. An address matching device, characterized in that, Includes a processor for executing programs or instructions to cause the address matching device to perform the method according to any one of claims 1-15.

32. The apparatus as claimed in claim 31, characterized in that, It also includes a memory for storing the program or instructions.

33. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program or instructions that, when executed on a computer, cause the computer to perform the method described in any one of claims 1-15.

34. A computer program product, characterized in that, The computer program product comprises a program or instructions that, when run on a computer, cause the computer to perform the method described in any one of claims 1-15.

Citation Information

Patent Citations

  • US20040052251A1