IP (Internet Protocol) route searching method, device, equipment and medium
By using the hash function to generate the hash table of the routing table, and hash mapping and length descending matching, the shortcomings of the existing IP routing search methods in terms of search speed and hardware cost are solved, and a fast routing search and a low-cost large-capacity lookup table system are realized.
Patent Information
- Application Number
- CN202510055266.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-05-06
AI Technical Summary
Existing IP routing search methods have shortcomings in finding speed and hardware cost, cannot meet the needs of fast routing search, and rely on expensive TCAM and SRAM devices.
The hash function is used to generate a hash table of the routing table and record all existing mask values. When searching for IP addresses, the IP address and mask IP are mapped through the hash function to obtain the hash address, and use this as the matching field to match the mask IP in descending order of length.
It improves the speed of IP routing search and reduces hardware costs, and can use FPGA internal memory resources to achieve a low-cost large-capacity lookup table system.
Smart Images

Figure CN119945976A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of digital information transmission technology, and in particular, relates to an IP routing search method, device, equipment and medium. Background Art
[0002] LPM (Longest Prefix Match) represents a principle commonly used in IP routing lookups, namely, exact matching.
[0003] The Chinese invention patent application number 201711382380.X discloses a method and system for implementing the longest mask match. This prior art expands the matching content of the TCAM memory on the SRAM through the mapping relationship of the Bitmap attribute table. With the mapping of the base address output by the TCAM plus the offset of the Bitmap search on the SRAM, the same IP address with different masks can store multiple groups of IP routes with different masks on the same SRAM address. During the search process, it is necessary to match all masked IP routes one by one and output the IP route with the longest mask length.
[0004] The mapping relationship of the Bitmap attribute table is used to re-mark the existing routing table. When the IP address cannot be accurately matched, the low-order bits of the Bitmap attribute table are automatically scanned to determine whether the existing routing table has a suitable mask. Mask matching can be performed, and this is repeated until all existing routing tables are traversed. The principle of this operation is to first perform an accurate match, and then perform a mask match with a lower matching bit number. If the match is successful, it is output, and the IP route matching with the longest mask can be completed.
[0005] The above prior art has the following defects:
[0006] (1) Since the routing lookup address is divided into two parts, the first part is searched by TCAM, and the second part is searched by the Bitmap attribute table and SRAM memory. The second search part depends on the output result of the first search part, and it is inevitable that parallel search cannot be performed, which reduces the search speed and may not meet the search performance required for fast routing.
[0007] (2) This method relies on relatively expensive devices such as TCAM and SRAM. TCAM hardware has small capacity, consumes large power when the circuit is working, and is expensive per bit. Therefore, it is not suitable to use TCAM to store large lookup tables. Summary of the invention
[0008] The purpose of this application is to overcome the defects of the prior art and provide an IP routing search method, device, equipment and medium, aiming to improve the search speed of the longest mask match and reduce hardware costs.
[0009] The purpose of this application is achieved through the following technical solutions:
[0010] An IP routing search method, the method comprising:
[0011] Generate a hash table of the routing table according to the hash function rules and record all existing mask values;
[0012] When performing an IP address search, all masked IPs containing the same IP field are derived based on all existing mask values;
[0013] The IP address and the mask IP are simultaneously mapped by a hash function to obtain a corresponding hash address;
[0014] Using the hash address as the matching domain, perform IP matching on the masked IP in descending order of length, and output the matching result when the match is successful.
[0015] Further, the hash lookup table for generating the routing table according to the hash function rule includes:
[0016] Perform hash mapping on the IP address portion of the routing table to obtain a corresponding hash table.
[0017] Furthermore, the method further comprises:
[0018] After deriving all masked IPs containing the same IP field, they are sorted in descending order by mask length.
[0019] On the other hand, the present invention also provides an IP routing search device, the device comprising:
[0020] A hash table generation module, wherein the hash table generation module generates a hash table of the routing table according to the hash function rule and records all existing mask values;
[0021] A mask IP derivation module, wherein when performing an IP address search, the mask IP derivation module derives all mask IPs containing the same IP field according to all existing mask values;
[0022] A matching domain establishment module, wherein the matching domain establishment module simultaneously maps the IP address and the mask IP through a hash function to obtain a corresponding hash address;
[0023] The IP matching module uses the hash address as a matching domain, performs IP matching on the masked IP in descending order of length, and outputs a matching result when the match is successful.
[0024] On the other hand, the present invention further provides a computer device, comprising a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded and executed by the processor to implement any one of the above-mentioned IP routing lookup methods.
[0025] On the other hand, the present invention further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is loaded and executed by a processor to implement any one of the above-mentioned IP routing search methods.
[0026] The beneficial effects of this application are:
[0027] Compared with the prior art, the present application can realize fast routing lookup and can use the internal memory resources of FPGA to realize a low-cost large-capacity lookup table system. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a flowchart of the IP routing search method according to an embodiment of the present application;
[0029] Figure 2 This is a schematic diagram of hash mapping in an embodiment of the present application;
[0030] Figure 3 This is a schematic diagram of a query that supports the longest mask match in an embodiment of the present application;
[0031] Figure 4 This is a schematic diagram of a parallel query that supports the longest mask match in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0033] Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making any creative work shall fall within the scope of protection of this application.
[0034] The existing routing lookup methods have the disadvantages of insufficient lookup speed and high hardware implementation cost.
[0035] In order to solve the above technical problems, the present application proposes the following embodiments of an IP routing lookup method, device, equipment and medium.
[0036] Reference Figure 1 ,like Figure 1 The figure is a flowchart of an IP routing search method according to an embodiment of the present application, and the method comprises the following steps:
[0037] Step 1: Generate a hash table of the routing table according to the hash function rules and record all existing mask values.
[0038] The hash table is a lookup table generated by the routing table according to the hash function rules. In this embodiment, the IP address of the routing table contains a mask, and only the IP address part is hashed to obtain the hash address. Figure 2 ,like Figure 2 Shown is a schematic diagram of hash mapping according to an embodiment of the present application.
[0039] Step 2: When searching for an IP address, derive all masked IPs containing the same IP field based on all existing mask values.
[0040] When generating the hash table, all existing mask values are recorded. The mask values may be 16, 17, 23, 24, 28, etc. The mask indicates the bits that need to be concerned. The larger the mask, the more accurate the routing.
[0041] When searching for IP addresses, the IP address is derived according to all existing mask values. For example, if the IP address is 192.168.10.2 and all existing mask values are 28, 24, 23, 17, and 16, five groups of mask IP addresses are derived, namely 192.168.10.0 / 28, 192.168.10.0 / 24, 192.168.10.0 / 23, 192.168.0.0 / 17, and 192.168.0.0 / 16. The number after " / " is the mask, and the number of bits of all IP addresses that are not of concern is set to 0.
[0042] These 5 groups of IP addresses, plus the original 192.168.10.2, make a total of 6 groups of IP addresses. Excluding the same IP addresses, there are 3 groups left: 192.168.10.2, 192.168.10.0, and 192.168.0.0. All IPs need to be arranged in the order of the longest mask.
[0043] Step 3: Map the IP address and mask IP through the hash function at the same time to obtain the corresponding hash address.
[0044] The original IP address and all derived different IP addresses are mapped through the hash function at the same time to obtain the corresponding hash address.
[0045] The mapping process is similar to the process of generating a hash table.
[0046] Step 4: Use the hash address obtained in step 3 as the matching domain, and perform IP matching on the masked IP in descending order of length. When the match is successful, output the matching result.
[0047] The IP matching process needs to comply with the longest mask matching rule, that is, the longest mask IP is matched first, followed by the second longest mask match, and so on, until all derived IPs are matched.
[0048] During the matching process, if the longest IP is matched successfully, the matching stops and the matching result is output. If it fails, the second longest mask is matched, and so on.
[0049] For example, to find the IP address 192.168.10.2, all mask values are 28, 24, 23, 17, 16.
[0050] If the hash address of 192.168.10.2 / 32 does not exist in the hash table, but the hash address of 192.168.0.0 / 17 exists,
[0051] The hash address corresponding to the IP address 192.168.10.2 with the longest mask of 32 is hash_addr_1;
[0052] The IP address 192.168.10.0 with the second-longest mask 28, 24, 23 has the corresponding hash address hash_addr_2;
[0053] The IP address with the shortest mask of 17 and 16 is 192.168.0.0, and the corresponding hash address is hash_addr3;
[0054] First, the matching domain of the hash_addr_1 address is matched, and the result is a match failure. Then, the matching domain of the hash_addr_2 address is matched, and the result is a match failure. Finally, the matching domain of the hash_addr_3 address is matched, and the result is a match success.
[0055] Finally, the matching results are output and subsequent forwarding or other operations specified by the routing table are performed.
[0056] Take the search for the IP address 192.168.10.2, where all mask values are 28, 24, 23, 17, and 16, as an example, and output the operations corresponding to the matching domain of the hash_addr_3 address.
[0057] In the above five steps, there may be multiple identical hash tables. Parallel table lookups for the same IP and different masks can improve the table lookup speed.
[0058] For example, to find the IP address 192.168.10.2, all mask values are 28, 24, 23, 17, 16.
[0059] Five identical hash tables can be designed according to the maximum mask value, where 192.168.10.2 derives three groups of IP addresses, and three hash tables will be used for parallel lookup:
[0060] Hash table 1: Find the hash address hash_addr_1 corresponding to the IP address 192.168.10.2 with the longest mask of 32.
[0061] Hash table 2: Find the hash address hash_addr_2 corresponding to the IP address 192.168.10.0 with the second-long mask 28, 24, 23.
[0062] Hash table 3: Find the hash address hash_addr_3 corresponding to the IP address 192.168.0.0 with the shortest mask 17, 16.
[0063] All matching results are output at the same time, with hash table 1 having the highest output priority, hash table 2 having the second highest output priority, and hash table 3 having the lowest output priority.
[0064] Compared with the prior art, this embodiment can realize fast routing lookup, and can use the internal memory resources of FPGA to realize a low-cost large-capacity lookup table system. The following Table 1 is a comparison between the IP routing method provided by this embodiment and the traditional method:
[0065] Table 1 Effect comparison table
[0066]
[0067] An implementation method of the IP route search method provided in this embodiment is as follows:
[0068] The search results show that the IP address is 192.168.10.2, and all mask values are 28, 24, 23, 17, and 16. In the routing table, there is no entry for 192.168.10.2 / 32, but there is an entry for 192.168.0.0 / 17.
[0069] In the hash table, the hash address of 192.168.10.2 / 32 does not exist, but the hash address of 192.168.0.0 / 17 exists.
[0070] Reference Figure 3 ,like Figure 3 The figure shows a schematic diagram of a query that supports the longest mask match in this embodiment of the present application.
[0071] The hash address corresponding to the IP address 192.168.10.2 with the longest mask of 32 is hash_addr_1.
[0072] The IP address 192.168.10.0 with the second-long mask 28, 24, 23 has the corresponding hash address hash_addr_2.
[0073] The IP address with the shortest mask 17, 16 is 192.168.0.0, and the corresponding hash address is hash_addr3.
[0074] First, the matching domain of the hash_addr_1 address is matched, and the result is a match failure. Then, the matching domain of the hash_addr_2 address is matched, and the result is a match failure. Finally, the matching domain of the hash_addr_3 address is matched, and the result is a match success.
[0075] Another implementation method of the IP route search method provided in this embodiment is as follows:
[0076] The search results show that the IP address is 192.168.10.2, and all mask values are 28, 24, 23, 17, and 16. In the routing table, there is no entry for 192.168.10.2 / 32, but there is an entry for 192.168.0.0 / 17.
[0077] In the hash table, the hash address of 192.168.10.2 / 32 does not exist, but the hash address of 192.168.0.0 / 17 exists.
[0078] Reference Figure 4 ,like Figure 4 The figure shows a schematic diagram of a parallel lookup supporting the longest mask match according to an embodiment of the present application.
[0079] Five identical hash tables can be designed according to the maximum mask value, where 192.168.10.2 derives three groups of IP addresses, and three hash tables will be used for parallel lookup:
[0080] Hash table 1: Find the hash address hash_addr_1 corresponding to the IP address 192.168.10.2 with the longest mask of 32;
[0081] Hash table 2: Find the hash address hash_addr_2 corresponding to the IP address 192.168.10.0 with the second-long mask 28, 24, 23;
[0082] Hash table 3: Find the hash address hash_addr_3 corresponding to the IP address 192.168.0.0 with the shortest mask 17, 16;
[0083] All matching results are output at the same time, with hash table 1 having the highest output priority, hash table 2 having the second highest output priority, and hash table 3 having the lowest output priority.
[0084] This preferred embodiment provides a computer device, which can implement the steps in any embodiment of the IP routing search method provided in the embodiments of the present application. Therefore, the beneficial effects of the IP routing search method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0085] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps of any embodiment of the IP route lookup method provided in the embodiment of the present invention.
[0086] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0087] Since the instructions stored in the storage medium can execute the steps in any IP routing search method embodiment provided in the embodiments of the present invention, the beneficial effects that can be achieved by any IP routing search method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0088] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. An IP routing search method, characterized in that: The method comprises: Generate a hash table of the routing table according to the hash function rules and record all existing mask values; When performing an IP address search, all masked IPs containing the same IP field are derived based on all existing mask values; The IP address and the mask IP are simultaneously mapped by a hash function to obtain a corresponding hash address; Using the hash address as the matching domain, perform IP matching on the masked IP in descending order of length, and output the matching result when the match is successful.
2. The IP routing search method according to claim 1, wherein: The hash lookup table for generating a routing table according to the hash function rule includes: Perform hash mapping on the IP address portion of the routing table to obtain a corresponding hash table.
3. The IP routing search method according to claim 1, wherein: The method further comprises: After deriving all masked IPs containing the same IP field, they are sorted in descending order by mask length.
4. An IP routing search device, characterized in that: The device comprises: A hash table generation module, wherein the hash table generation module generates a hash table of the routing table according to the hash function rule and records all existing mask values; A mask IP derivation module, wherein when performing an IP address search, the mask IP derivation module derives all mask IPs containing the same IP field according to all existing mask values; A matching domain establishment module, wherein the matching domain establishment module simultaneously maps the IP address and the mask IP through a hash function to obtain a corresponding hash address; The IP matching module uses the hash address as a matching domain, performs IP matching on the masked IP in descending order of length, and outputs a matching result when the match is successful.
5. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the IP routing search method according to any one of claims 1 to 3.
6. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, which is loaded and executed by a processor to implement the IP routing search method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Methods and systems for achieving longest mask matching
CN108075979B