Hash index value calculation method and device for longest prefix matching rule

By segmenting binary codes and multi-round hashing operations for the longest prefix matching rule, the problem of low hash index value calculation rate in the existing technology is solved, the index rate and uniform distribution are improved, and the rapidity of massive rules is achieved Storage and access.

CN119254696APending Publication Date: 2025-01-03CORIGINE (NANJING) INC
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411278656.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

The hash index value calculation rate of the existing longest prefix matching rule is low and cannot meet the needs of massive storage management and access. Especially for long-length rules, it takes multiple iterations to obtain hash values ​​that meet the target length, resulting in a relatively high calculation rate. Low.

Method used

By determining the length of the longest prefix matching rule and the target index length, the binary code is segmented, multiple index segment codes are obtained, and the hash is calculated by multiple hashing operations until only one index segment code is obtained. Index value.

Benefits of technology

The uniform distribution degree and calculation rate of hash index values ​​are improved, the index rate of the longest prefix matching rule is enhanced, and the rapid search and access of a large number of rules is achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119254696A_ABST
    Figure CN119254696A_ABST
Patent Text Reader

Abstract

The invention provides a Hash index value calculation method and device for a longest prefix matching rule, and the method comprises the steps: segmenting a binary code of the longest prefix matching rule according to a target index length when the length of the longest prefix matching rule exceeds the target index length, and obtaining a plurality of index segmentation codes which accord with the target index length; according to the method, the index segmentation codes are divided into multiple index segmentation codes, and multiple rounds of hash operation are performed on each index segmentation code until only one index segmentation code is obtained, so that the index segmentation code is taken as the hash index value of the longest prefix matching rule, the uniform distribution degree of the hash index value can be ensured, the calculation rate is effectively improved, and the calculation efficiency is improved. Therefore, the indexing rate of the longest prefix matching rule is improved, the problem that the calculation rate of the Hash index value of the existing longest prefix matching rule is low is effectively solved, and quick search and access of a large number of longest prefix matching rules stored in a plurality of same storage structures can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of storage technology, and in particular to a method and device for calculating a hash index value of a longest prefix matching rule. Background Art

[0002] The Longest Prefix Match (LPM) rule is a search algorithm used to determine the forwarding path of data packets in network routing. The core idea of ​​the Longest Prefix Match (LPM) rule is to find a matching rule with the longest network prefix for a given destination IP address in a set of routing rules. Based on the rapid development of the current network era, each network node has greater requirements for the capacity of the Longest Prefix Match (LPM) rule. In the face of the storage management and access of a large number of Longest Prefix Match (LPM) rules, it is necessary to quickly index the specific location of the Longest Prefix Match (LPM) rule to obtain the result or processing method corresponding to this rule. Therefore, it is particularly important to quickly calculate the index value of the Longest Prefix Match (LPM) rule.

[0003] The hash index of the longest prefix match (LPM) rule is a method of using a hash table to store and search routing rules. The fast access feature of the hash table can be used to map the prefix of the routing rule to the index of the hash table based on the designed hash function. However, the existing method for calculating the hash index value of the longest prefix match (LPM) rule cannot obtain a uniform hash value on the one hand, and the calculation rate is low and time-consuming on the other hand. For example, a hash method for calculating the index of the longest prefix match LPM rule disclosed in the patent (CN112905597B) can solve the discrete degree of the index distribution of variable-length data and reduce hash conflicts. It is suitable for the scene of mixed storage of longest prefix match (LPM) rules of different lengths; however, the technical solution has the problem of high calculation frequency. For the longest prefix match (LPM) rule with a longer length, it is necessary to go through multiple iterations to obtain a hash value that meets the target length. This is more complicated for the search-related hardware implementation, which will make the calculation rate low and time-consuming. Summary of the invention

[0004] In view of the above-mentioned shortcomings of the prior art, the purpose of the present application is to provide a method and device for calculating the hash index value of the longest prefix match rule, so as to solve the problem of low hash index value calculation rate of the existing longest prefix match (LPM) rule.

[0005] To achieve the above-mentioned purpose and other related purposes, the first aspect of the present application provides a method for calculating the hash index value of a longest prefix matching rule, and the method for calculating the hash index value of the longest prefix matching rule includes: determining the length of the longest prefix matching rule and the target index length; when the length of the longest prefix matching rule exceeds the target index length, segmenting the binary code of the longest prefix matching rule according to the target index length to obtain multiple index segment codes that meet the target index length; performing multiple rounds of hash operations on each index segment code until only one index segment code is obtained, and outputting the index segment code as the hash index value of the longest prefix matching rule.

[0006] In some embodiments of the first aspect of the present application, the binary code of the longest prefix matching rule is divided according to the target index length to obtain multiple index segment codes that meet the target index length, including: according to the target index length, the binary code of the longest prefix matching rule is segmented to obtain multiple segment codes; when the length of the last segment code obtained does not meet the target index length, performing a zero-padding operation on the segment code to make it meet the target index length; and using each segment code that meets the target index length as an index segment code.

[0007] In some embodiments of the first aspect of the present application, the method of performing multiple rounds of hash operations on each index segment code until only one index segment code is obtained includes: performing a first round of hash operation on each index segment code obtained by segmenting the binary code of the longest prefix matching rule, reducing the number of index segment codes by one, and obtaining corresponding one or more new index segment codes; determining whether the number of newly obtained index segment codes is unique; if the number is not unique, repeating the above steps, and continuing to perform another round of hash operation on each newly obtained index segment code until only one index segment code is obtained.

[0008] In some embodiments of the first aspect of the present application, a method of performing a round of hash operation on each index segment code includes: performing a bit-by-bit XOR operation on each two adjacent index segment codes in turn to obtain one or more new index segment codes.

[0009] In some embodiments of the first aspect of the present application, the method further includes: when the length of the longest prefix matching rule does not exceed the target index length, outputting the binary code of the longest prefix matching rule as its hash index value.

[0010] To achieve the above-mentioned purpose and other related purposes, the second aspect of the present application provides a hash index value calculation device for a longest prefix matching rule, and the hash index value calculation device for the longest prefix matching rule includes: an LPM rule input module, used to input a longest prefix matching rule and determine the length of the longest prefix matching rule and the target index length; a hash index value calculation module, connected to the LPM rule input module, used to calculate the hash index value of the input longest prefix matching rule when the length of the longest prefix matching rule exceeds the target index length; wherein the hash index value calculation module includes: an LPM rule segmenter, used to divide the binary code of the longest prefix matching rule according to the target index length to obtain multiple index segment codes that meet the target index length; a multi-level index segment hash operator, connected to the LPM rule segmenter, used to perform multiple rounds of hash operation operations on each index segment code until only one index segment code is obtained; a hash index value outputter, connected to the multi-level index segment XOR operator, used to output the obtained unique index segment code as the hash index value of the longest prefix matching rule.

[0011] In some embodiments of the second aspect of the present application, the LPM rule segmenter includes: a rule segmentation unit, used to segment the binary code of the longest prefix matching rule according to the target index length to obtain multiple segment codes; a segment length determination unit, connected to the rule segmentation unit, used to determine whether the length of the last segment code obtained meets the target index length; a segment zero padding unit, connected to the segment length determination unit, used to perform a last-bit zero padding operation on the segment code when the length of the last segment code obtained does not meet the target index length, so that it meets the target index length; an index segment code output unit, connected to the rule segmentation unit and the segment zero padding unit, used to output each segment code that meets the target index length as an index segment code.

[0012] In some embodiments of the second aspect of the present application, the multi-level index segment hash operator includes: a plurality of index segment hash operators connected in sequence, each used to perform a round of hash operation on each index segment code; wherein each index segment hash operator includes: one or more registers and an XOR operator connected to each register.

[0013] In some embodiments of the second aspect of the present application, the multi-level index segment hash operator performs multiple rounds of hash operation operations on each index segment code, including: storing each index segment code obtained by segmenting the segment code of the longest prefix matching rule in sequence in each register of the first-level index segment hash operator; performing a first round of hash operation operations on each index segment code through the XOR operator of the first-level index segment hash operator, reducing the number of index segment codes by one, and obtaining corresponding one or more new index segment codes; judging whether the number of newly obtained index segment codes is unique; if the number is unique, storing the index segment code in the register of the hash index value outputter, and outputting the index segment code as the hash index value of the longest prefix matching rule through the hash index value outputter; if the number is not unique, repeating the above steps, continuing to store each newly obtained index segment code in sequence in the index segment hash operator of the next level, and performing another round of hash operation operations on each index segment code through the XOR operator of the index segment hash operator of this level, until only one index segment code is obtained.

[0014] In some embodiments of the second aspect of the present application, the device also includes: an LPM rule output module, connected to the LPM rule input module, used to output the segmented code of the longest prefix matching rule as its hash index value when the length of the longest prefix matching rule does not exceed the target index length.

[0015] As described above, the present application provides a method and device for calculating the hash index value of the longest prefix matching rule, by segmenting the binary code of the longest prefix matching rule according to the target index length when the length of the longest prefix matching rule exceeds the target index length, and obtaining multiple index segmentation codes that meet the target index length; and by performing multiple rounds of hash operations on each index segmentation code until only one index segmentation code is obtained, so that the index segmentation code can be used as the hash index value of the longest prefix matching rule. The present application has the following beneficial effects: the present application can not only ensure the uniform distribution of its hash index value, but also effectively improve the calculation rate, thereby improving the index rate of the longest prefix matching rule, effectively solving the problem of low calculation rate of the hash index value of the existing longest prefix matching rule, and can realize fast search and access to a large number of longest prefix matching rules stored in multiple identical storage structures. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 Shown is a schematic diagram of a process for calculating a hash index value of a longest prefix matching rule in one embodiment of the present application.

[0017] Figure 2 Shown is a schematic diagram of a flow chart of calculating a hash index value when the length of the longest prefix matching rule exceeds the target index length in one embodiment of the present application.

[0018] Figure 3A Shown is a schematic diagram of dividing the longest prefix matching rule mask when the length of the longest prefix matching rule exceeds the target index length in a specific embodiment of the present application.

[0019] Figure 3B It is a schematic diagram showing the execution of multiple rounds of hash operations when the length of the longest prefix matching rule exceeds the target index length in a specific embodiment of the present application.

[0020] Figure 4 Shown is a structural schematic diagram of a hash index value calculation device for a longest prefix matching rule in an embodiment of the present application.

[0021] Figure 5 Shown is a structural diagram of a hash index value calculation module in a specific embodiment of the present application. DETAILED DESCRIPTION

[0022] 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.

[0023] The technical solutions of the embodiments of the present application can be applied to various communication systems, such as: Long Term Evolution (LTE) system, LTE frequency division duplex (FDD) system, future fifth generation (5G) communication system, new radio access technology (NR), LTE time division duplex (TDD), Worldwide Interoperability for Microwave Access (WiMAX), Universal Mobile Telecommunication System (UMTS), and vehicle-to-XV2X. Among them, V2X can include vehicle to network (V2N), vehicle to vehicle (V2V), vehicle to infrastructure (V2I), vehicle to pedestrian (V2P), Long Term Evolution-Vehicle (LTE-V), Internet of Vehicles, machine type communication (MTC), Internet of Things (IoT), Long Term Evolution-Machine (LTE-M), machine to machine (M2M), etc.

[0024] In order to solve the problems in the above-mentioned background technology, the present invention provides a method and device for calculating the hash index value of the longest prefix matching rule, aiming to solve the problem of low hash index value calculation rate of the LPM rule in the prior art. At the same time, in order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution in the embodiment of the present invention is further described in detail through the following embodiments and in combination with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the invention.

[0025] The longest prefix match (LPM) algorithm is a key technology used for route lookup in network devices (such as routers). The core goal is to find the longest network prefix match in the routing table based on the destination IP address of the data packet. The specific steps include: converting the destination IP address into binary form; for each rule in the routing table, determining its mask length, where the mask length defines the number of bits in the IP address used for matching; extracting the corresponding prefix from the destination IP address based on the mask length of the rule; comparing the prefix extracted from the destination IP address with the prefix of each rule in the routing table, starting from the highest bit, until an unmatched bit is found; among all matching rules, selecting the rule with the longest prefix.

[0026] The routing table contains a series of routing rules, each of which includes at least the IP address of the destination network, the network mask, and the next hop address and other attribute information. Routing rules are usually represented as binary codes of indefinite length. In some implementations, it is necessary to convert the binary code of each routing rule into a numerical index to achieve the purpose of storing and searching for the longest prefix match (LPM) rule. The hash index of the longest prefix match (LPM) rule is a method of using a hash table to store and search for routing rules. The fast access feature of the hash table can be utilized, and the prefix of the routing rule can be mapped to the index of the hash table based on the designed hash function. However, the existing method for calculating the hash index value of the longest prefix match (LPM) rule cannot obtain a uniform hash value on the one hand, and the calculation rate is low and time-consuming on the other hand, which cannot adapt to the storage management and access of a large number of longest prefix match (LPM) rules.

[0027] In a patent (CN112905597B) previously provided by the applicant, a hash method for calculating the longest prefix match LPM rule index is provided. Although it can solve the discrete degree of index distribution of variable-length data and reduce hash conflicts, it is suitable for scenarios where longest prefix match (LPM) rules of different lengths are mixed and stored; however, the technical solution has the problem of high calculation frequency. For the longest prefix match (LPM) rule with a longer length, multiple iterations are required to obtain a hash value that meets the target length, which is more complicated for search-related hardware implementation, and will result in a lower calculation rate and a longer time consumption. The present invention provides an optimization solution for the problem of low calculation rate in the technical solution.

[0028] like Figure 1 As shown, a flow chart of a method for calculating a hash index value of a longest prefix matching rule in an embodiment of the present invention is shown. The method for calculating a hash index value of a longest prefix matching rule in this embodiment mainly includes the following steps.

[0029] Step S1: Determine the length of the longest prefix match (LPM) rule and the target index length.

[0030] In one embodiment, the method for determining the target index length includes: if the bit width of the storage module for storing the longest prefix match (LPM) rule is w and the depth is 2 l , then the target index length is l. The length of the longest prefix match (LPM) rule is determined to be L.

[0031] Step S2: When the length of the longest prefix match (LPM) rule exceeds the target index length, the binary code of the longest prefix match (LPM) rule is segmented according to the target index length to obtain multiple index segment codes that meet the target index length; multiple rounds of hash operations are performed on each index segment code until only one index segment code is obtained, and the index segment code is output as the hash index value of the longest prefix match (LPM) rule.

[0032] In one embodiment, if Figure 2 As shown, the step S2 specifically includes the following steps.

[0033] Step S21: segmenting the binary code of the longest prefix match (LPM) rule according to the target index length to obtain a plurality of segment codes.

[0034] Step S22: when the length of the last segment code obtained does not meet the target index length, a zero padding operation is performed on the segment code to make it meet the target index length.

[0035] Step S23: taking each segment code that meets the target index length as an index segment code.

[0036] Step S24: performing a first round of hash operation on each index segment code obtained by segmenting the binary code according to the longest prefix match (LPM) rule, reducing the number of index segment codes by one, and obtaining one or more corresponding new index segment codes.

[0037] Step S25: Determine whether the newly obtained index segment code quantity is unique.

[0038] Step S26: If the number is not unique, repeat the above steps and continue to perform another round of hash operation on each newly obtained index segment code until only one index segment code is obtained.

[0039] Step S27: If the number is unique, the index segment code is output as the hash index value of the longest prefix match (LPM) rule.

[0040] In order to better illustrate the process of calculating the hash index value of the longest prefix match (LPM) rule in step 2, the present invention provides an example for illustration.

[0041] Examples include Figure 3A as well as Figure 3B As shown, a longest prefix match (LPM) rule with a length L of 19 is given as 00111010 0010 1111011, and a target index length l is given as 4. At this time, L≥l is satisfied. The process of calculating the hash index value of the longest prefix match (LPM) rule is as follows.

[0042] Step 1: Segment the binary code of the longest prefix match (LPM) rule into n segments according to the target index length l, where n = L / l = 19 / 4 = 5, that is, the longest prefix match (LPM) rule can be divided into 5 segments, and each segment code is recorded as l0, l1, l2, l3, l4. Specifically, l0 = 0011, l1 = 1010, l2 = 0010, l3 = 1111 and l4 = 011.

[0043] Step 2: Since the length of the last segment code l4=011 obtained is 3, which does not meet the target index length l of 4, the segment code is padded with zeros to convert l4 to 0110, thereby obtaining 5 index segment codes that meet the target index length l: l0=0011, l1=1010, l2=0010, l3=1111 and l4=0110.

[0044] Step 3: Perform the first round of hash operation on the obtained 5 index segment codes, that is, perform bit-by-bit XOR operation on every two adjacent index segment codes in turn, so as to obtain 4 new index segment codes.

[0045] Specific as Figure 3B As shown, l0=l0^l1=0011^1010=1001, l1=l1^l2=1010^0010=

[0046] 1000, l2=l2^l3=0010^1111=1101, l3=l3^l4=1111^0110=1001.

[0047] Step 4: Since the number of newly obtained index segment codes is greater than 1, the second round of hash operation is continued to be performed on each newly obtained index segment code, and then every two adjacent index segment codes are subjected to bit-by-bit XOR operation in turn, thereby obtaining 3 new index segment codes.

[0048] Specific as Figure 3B As shown, l0=l0^l1=1001^1000=0001, l1=l1^l2=1000^1101=0101, l2=l2^l3=1101^1001=0100.

[0049] Step 5: Since the number of newly obtained index segment codes is greater than 1, the third round of hash operation is continued to be performed on each newly obtained index segment code, and then every two adjacent index segment codes are subjected to bit-by-bit XOR operation in turn, thereby obtaining 2 new index segment codes.

[0050] Specific as Figure 3B As shown, l0=l0^l1=0001^0101=0100, l1=l1^l2=0101^0100=0001.

[0051] Step 6: Since the number of newly obtained index segment codes is greater than 1, the fourth round of hash operation is continued to be performed on each newly obtained index segment code, and the two adjacent index segment codes are subjected to bit-by-bit XOR operation to obtain the only remaining single index segment code, which is output as the hash index value (idx) of the longest prefix match (LPM) rule.

[0052] Specific as Figure 3B As shown, l0=l0^l1=0100^0001=0101=idx.

[0053] Therefore, after four rounds of calculation, the hash index value of the longest prefix match (LPM) rule 00111010 00101111011 with a length L of 19 is 0101.

[0054] The purpose of the design of the present application in this embodiment is to optimize the calculation method of the hash index value of the longest prefix match (LPM) rule, which not only ensures the uniform distribution of its hash index value, but also effectively improves the calculation rate, thereby improving the indexing rate of the longest prefix match (LPM) rule.

[0055] For example, in the above example, to calculate the longest prefix match (LPM) rule with a length L of 19 as a hash index value of length 4, 4 rounds of hash operations are required. According to a hash method for calculating the longest prefix match LPM rule index disclosed in the previous patent of the applicant (CN112905597B): when the length L of the longest prefix match (LPM) rule exceeds the length n of the storage unit, the first n bits are used as the reference, and an OR operation is performed bit by bit backward, and the cycle is repeated until the hash value of the specified length of the longest prefix match (LPM) rule is calculated; the longest prefix match (LPM) rule with a mask length L of 19 is calculated as a hash index value of length 4. It takes 15 rounds of hash operations. In comparison, the calculation rate and index rate of the present invention are significantly improved, which effectively solves the problem of low calculation rate of hash index values ​​of the existing longest prefix match (LPM) rule.

[0056] Step S3: When the length of the longest prefix match (LPM) rule does not exceed the target index length, output the prefix of the longest prefix match (LPM) rule as its hash index value.

[0057] For example, given a longest prefix match (LPM) rule with a length L of 12 as 1001 00001111, and given a target index length l of 14. At this time, L < l is satisfied. Therefore, the hash index value of this longest prefix match (LPM) rule is 1001 0000 1111.

[0058] In the embodiments of the present application, terms such as "first" and "second" are used to distinguish identical or similar items with basically the same functions and effects. For example, the first XX and the second XX are only used to distinguish different XX, and do not limit their sequence. Those skilled in the art can understand that terms such as "first" and "second" do not limit the quantity and execution order, and "first", "second", etc. do not necessarily mean different.

[0059] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" represent examples, illustrations or explanations. Any embodiment or design solution described as "exemplary" or "for example" in the present application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific manner.

[0060] In the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after. "At least one (item)" or its similar expression refers to any combination of these items, including any combination of single item (item) or plural items (items). For example, at least one (item) of a, b or c can represent: a, b, c, a - b, a - c, b - c or a - b - c, where a, b, c can be single or multiple.

[0061] As Figure 4 shown, a schematic structural diagram of a hash index value calculation device for the longest prefix match rule in the embodiments of the present invention is shown. The hash index value calculation device for the longest prefix match rule includes: an LPM rule input module 1, a hash index value calculation module 2, and an LPM rule output module 3.

[0062] The LPM rule input module 1 is used to input the longest prefix matching rule and determine the length of the longest prefix matching rule and the target index length.

[0063] The hash index value calculation module 2 is connected to the LPM rule input module 1 and is used to calculate the hash index value of the input longest prefix matching rule when the length of the longest prefix matching rule exceeds the target index length.

[0064] The hash index value calculation module 2 includes: an LPM rule segmenter 21 , a multi-level index segmentation hash operator 22 and a hash index value outputter 23 .

[0065] The LPM rule segmenter 21 is used to divide the binary code of the longest prefix matching rule according to the target index length to obtain a plurality of index segment codes that meet the target index length.

[0066] In a specific embodiment, the LPM rule segmenter 21 includes: a rule segmentation unit, a segment length determination unit, a segment zero padding unit, and an index segment code output unit. The rule segmentation unit is used to segment the binary code of the longest prefix matching rule according to the target index length to obtain multiple segment codes; the segment length determination unit is connected to the rule segmentation unit and is used to determine whether the length of the last segment code obtained meets the target index length; the segment zero padding unit is connected to the segment length determination unit and is used to perform a last-bit zero padding operation on the segment code to make it meet the target index length when the length of the last segment code obtained does not meet the target index length; the index segment code output unit is connected to the rule segmentation unit and the segment zero padding unit and is used to output each segment code that meets the target index length as an index segment code.

[0067] In order to better explain the working mode of the LPM rule segmenter 21, the present invention provides an example for illustration. Figure 3A As shown, a longest prefix match (LPM) rule of length L of 19 is 00111010 00101111011 input into the LPM rule input module 1, and the target index length l is given as 4. At this time, L≥l is satisfied. The binary code of the longest prefix match (LPM) rule is segmented by the LPM rule segmenter 21 in the hash index value calculation module 2, and a process of obtaining multiple index segment codes that meet the target index length l of 4 is as follows.

[0068] ① The binary code of the longest prefix match (LPM) rule is segmented into n segments according to the target index length l by the rule segmentation unit, wherein n=L / l=19 / 4=5, that is, the binary code of the longest prefix match (LPM) rule can be divided into 5 segments, and each segment code is recorded as l0, l1, l2, l3, l4. Specifically, l0=0011, l1=1010, l2=0010, l3=1111 and l4=011.

[0069] ② The length of the last segment code l4=011 obtained by the segment length determination unit is 3, which does not meet the target index length l of 4, so the segment code is subjected to the end zero padding operation through the segment zero padding unit to convert l4 into 0110 to meet the target index length, and is sent to the index segment code output unit as an index segment code, while other segment codes that have met the target index length are sent to the index segment code output unit as index segment codes through the rule segmentation unit.

[0070] ③ This time, a total of 5 index segment codes are obtained: l0=0011, l1=1010, l2=0010, l3=1111 and l4=0110.

[0071] The multi-level index segmentation hash operator 22 is connected to the LPM rule segmenter 21 and is used to perform multiple rounds of hash operations on each index segmentation code until only one index segmentation code is obtained.

[0072] The hash index value outputter 23 is connected to the multi-level index segment XOR operator 22, and is used to output the obtained single index segment code as the hash index value of the longest prefix matching rule.

[0073] In a specific embodiment, if Figure 5 As shown, the multi-level index segment hash operator 22 includes: a plurality of index segment hash operators connected in sequence, each for performing a round of hash operation on each index segment code. Each index segment hash operator includes: one or more registers and an XOR operator connected to each register.

[0074] In this embodiment, the multi-level index segment hash operator performs multiple rounds of hash operation operations on each index segment code, including: storing each index segment code obtained by segmenting the binary code of the longest prefix matching rule in order in each register of the first-level index segment hash operator; performing a first round of hash operation operations on each index segment code through the XOR operator of the first-level index segment hash operator, so that the number of index segment codes is reduced by one, and obtaining corresponding one or more new index segment codes; judging whether the number of newly obtained index segment codes is unique; if the number is unique, storing the index segment code in the register of the hash index value outputter, and outputting the index segment code as the hash index value of the longest prefix matching rule through the hash index value outputter; if the number is not unique, repeating the above steps, continuing to store each newly obtained index segment code in order in the index segment hash operator of the next level, and performing another round of hash operation operations on each index segment code through the XOR operator of the index segment hash operator of this level, until only one index segment code is obtained.

[0075] Taking the above example as an example, the longest prefix match (LPM) rule 0011 1010 0010 1111011 with a length L of 19 is segmented according to the target index length l of 4 through the LPM rule segmenter 21, and 5 index segment codes l0=0011, l1=1010, l2=0010, l3=1111 and l4=0110 are obtained. The hash index values ​​can then be calculated through 4 index segment hash calculators. Among them, the first-level index segment hash operator stores l0=0011, l1=1010, l2=0010, l3=1111 and l4=0110 in 5 registers in sequence, and performs bit-by-bit XOR operation on every two adjacent index segment codes in turn through the corresponding XOR operator, and stores the newly obtained 4 index segment codes l0=1001, l1=1000, l2=1101 and l3=1001 in 4 registers of the second-level index segment hash operator; the second-level index segment hash operator obtains the 4 index segment codes stored in its register, and continues to perform bit-by-bit XOR operation on every two adjacent index segment codes in turn through the corresponding XOR operator, and stores the newly obtained 3 index segment codes l0=0001, l1=010 1 and l2=0100 are stored in three registers of the third-level index segment hash operator; the third-level index segment hash operator obtains the three index segment codes stored in its register, and continues to perform bit-by-bit XOR operations on every two adjacent index segment codes in sequence through the corresponding XOR operator, and stores the newly obtained two index segment codes l0=0100 and l1=0001 in the two registers of the fourth-level index segment hash operator; the fourth-level index segment hash operator obtains the two index segment codes stored in its register, and continues to perform bit-by-bit XOR operations on every two adjacent index segment codes in sequence through the corresponding XOR operator, and sends the newly obtained unique index segment code l0=0101 to the hash index value outputter 23 to be stored in the register therein.

[0076] Therefore, when calculating hash index values ​​for 5 index segment codes, 4 index segment hash operators are required to perform 4 rounds of hash operations respectively. Among them, the first-level index segment hash operator requires at most 5 registers. When calculating hash index values ​​for n index segment codes, n-1 index segment hash operators are required to perform n-1 rounds of hash operations, among which the first-level index segment hash operator requires at most n registers. It should be noted that n=L / l. Therefore, the number of index segment hash operators and the number of registers in the hash index value calculation device of the longest prefix match rule limit the length and calculation times of the longest prefix match (LPM) rule that can be calculated. The specific number can be set according to demand, and the present invention does not limit it.

[0077] The LPM rule output module 3 is connected to the LPM rule input module 1, and is used to output the binary code of the longest prefix matching rule as its hash index value when the length of the longest prefix matching rule does not exceed the target index length.

[0078] It should be understood that the specific process of each module executing the above corresponding steps has been described in detail in the above method embodiment, and for the sake of brevity, it will not be repeated here.

[0079] It should also be understood that the division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional module in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0080] The terms "component", "module", "system", etc. used in this specification are used to represent computer-related entities, hardware, firmware, a combination of hardware and software, software, or software in execution. For example, a component can be, but is not limited to, a process running on a processor, a processor, an object, an executable file, an execution thread, a program and / or a computer. By way of illustration, both applications running on a computing device and a computing device can be components. One or more components may reside in a process and / or an execution thread, and a component may be located on a computer and / or distributed between two or more computers. In addition, these components may be executed from various computer-readable media having various data structures stored thereon. Components may, for example, communicate through local and / or remote processes according to signals having one or more data packets (e.g., data from two components interacting with another component between a local system, a distributed system and / or a network, such as the Internet interacting with other systems through signals).

[0081] Those of ordinary skill in the art will appreciate that the various illustrative logical blocks and steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0082] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0083] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0084] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0085] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0086] In the above embodiments, the functions of each functional unit can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions (programs). When loading and executing computer program instructions (programs) on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. Computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media integrations. Available media may be magnetic media (e.g., floppy disks, hard disks, tapes), optical media (e.g., high-density digital video discs (DVDs), or semiconductor media (e.g., solid state disks (SSDs), etc.).

[0087] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.

[0088] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0089] In summary, the present application provides a method and device for calculating the hash index value of the longest prefix matching rule, by segmenting the binary code of the longest prefix matching rule according to the target index length when the length of the longest prefix matching rule exceeds the target index length, and obtaining multiple index segment codes that meet the target index length; and by performing multiple rounds of hash operations on each index segment code until only one index segment code is obtained, so that the index segment code can be used as the hash index value of the longest prefix matching rule. The present application has the following beneficial effects: the present application can not only ensure the uniform distribution of its hash index value, but also effectively improve the calculation rate, thereby improving the index rate of the longest prefix matching rule, and effectively solve the problem of low hash index value calculation rate of the existing longest prefix matching rule, and can realize fast search and access to a large number of longest prefix matching rules stored in multiple identical storage structures.

[0090] Therefore, the present application effectively overcomes various shortcomings in the prior art and has high industrial utilization value.

[0091] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.

Claims

1. A method for calculating a hash index value of a longest prefix matching rule, characterized in that: include: Determine the length of the longest prefix matching rule and the target index length; When the length of the longest prefix matching rule exceeds the target index length, the binary code of the longest prefix matching rule is segmented according to the target index length to obtain multiple index segment codes that meet the target index length; Multiple rounds of hash operations are performed on each index segment code until only one index segment code is obtained, and the index segment code is output as the hash index value of the longest prefix matching rule.

2. The method for calculating the hash index value of the longest prefix matching rule according to claim 1, characterized in that: According to the target index length, the binary code of the longest prefix matching rule is divided to obtain multiple index segment codes that meet the target index length, including: According to the target index length, a plurality of segment codes are obtained for the binary code of the longest prefix matching rule; When the length of the last segment code obtained does not meet the target index length, a zero padding operation is performed on the segment code to make it meet the target index length; Each segment code that meets the target index length is used as the index segment code.

3. The method for calculating the hash index value of the longest prefix matching rule according to claim 1, characterized in that: The method of performing multiple rounds of hash operations on each index segment code until only one index segment code is obtained includes: Performing a first round of hash operation on each index segment code obtained by segmenting the binary code of the longest prefix matching rule, reducing the number of index segment codes by one, and obtaining one or more corresponding new index segment codes; Determine whether the newly obtained index segment code quantity is unique; If the number is not unique, repeat the above steps and continue to perform another round of hash operation on each newly obtained index segment code until only one index segment code is obtained.

4. The method for calculating the hash index value of the longest prefix matching rule according to claim 3, characterized in that: The method of performing a round of hash operation on each index segment code includes: performing a bit-by-bit XOR operation on each two adjacent index segment codes in sequence to obtain one or more new index segment codes.

5. The method for calculating the hash index value of the longest prefix matching rule according to claim 1, characterized in that: The method further comprises: When the length of the longest prefix matching rule does not exceed the target index length, the binary code of the longest prefix matching rule is output as its hash index value.

6. A hash index value calculation device for the longest prefix matching rule, characterized in that: include: An LPM rule input module is used to input a longest prefix matching rule and determine the length of the longest prefix matching rule and the target index length; A hash index value calculation module, connected to the LPM rule input module, used to calculate the hash index value of the input longest prefix matching rule when the length of the longest prefix matching rule exceeds the target index length; Wherein, the hash index value calculation module includes: An LPM rule segmenter is used to segment the binary code of the longest prefix matching rule according to the target index length to obtain multiple index segment codes that meet the target index length; A multi-level index segmentation hash operator, connected to the LPM rule segmenter, for performing multiple rounds of hash operation operations on each index segmentation code until only one index segmentation code is obtained; A hash index value outputter is connected to the multi-level index segment XOR operator and is used to output the obtained single index segment code as the hash index value of the longest prefix matching rule.

7. The hash index value calculation device of the longest prefix matching rule according to claim 6, characterized in that: The LPM rule segmenter includes: A rule segmentation unit, used for segmenting the binary code of the longest prefix matching rule according to the target index length to obtain a plurality of segment codes; A segment length determination unit, connected to the regular segmentation unit, is used to determine whether the length of the last segment code obtained meets the target index length; A segment zero padding unit, connected to the segment length determination unit, is used to perform a zero padding operation on the last bit of the segment code when the length of the last segment code obtained does not meet the target index length, so as to make the segment code meet the target index length; The index segment code output unit is connected to the regular segment unit and the segment zero padding unit, and is used to output each segment code that meets the target index length as an index segment code.

8. The hash index value calculation device of the longest prefix matching rule according to claim 6, characterized in that: The multi-level index segment hash operator comprises: a plurality of index segment hash operators connected in sequence, each for performing a round of hash operation on each index segment code; Each index segment hash operator includes: one or more registers and an XOR operator connected to each register.

9. The hash index value calculation device of the longest prefix matching rule according to claim 8, characterized in that: The method in which the multi-level index segment hash operator performs multiple rounds of hash operations on each index segment code includes: The index segment codes obtained by segmenting the binary code of the longest prefix matching rule are sequentially stored in the registers of the first-level index segment hash operator; Performing a first round of hash operation on each index segment code through an XOR operator of the first-level index segment hash operator, reducing the number of index segment codes by one, and obtaining one or more corresponding new index segment codes; Determine whether the newly obtained index segment code quantity is unique; If the number is unique, the index segment code is stored in the register of the hash index value output device, and the index segment code is output as the hash index value of the longest prefix matching rule through the hash index value output device; If the number is not unique, repeat the above steps, continue to store the newly obtained index segment codes in sequence in the index segment hash operator of the next level, and perform another round of hash operation on each index segment code through the XOR operator of the index segment hash operator of this level until only one index segment code is obtained.

10. The hash index value calculation device of the longest prefix matching rule according to claim 6, characterized in that: The device also includes: an LPM rule output module, connected to the LPM rule input module, and used to output the binary code of the longest prefix matching rule as its hash index value when the length of the longest prefix matching rule does not exceed the target index length.

Citation Information

Cited By

  • Data query method and device, electronic equipment and storage medium

    CN120804149A