Methods, apparatus, storage media and terminals for regular compression storage applicable to TCAM

By combining hash values ​​and hash bits, the rule storage process of TCAM is optimized, solving the problems of low storage efficiency and insufficient space, and achieving efficient rule storage and comparison.

CN114625925BActive Publication Date: 2025-11-14LUOYUAN (SHANGHAI) SEMICON TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210112111.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-28
Publication Date
2025-11-14
Estimated Expiration
2042-01-28

AI Technical Summary

Technical Problem

Existing TCAM solutions are inefficient and have insufficient storage space when storing the same rules. Existing solutions suffer from slow storage speed or a small number of rules that can be stored.

Method used

By calculating the hash value and hash bits of the rule to be stored in TCAM, the location is locked by combining the rule content and preset rules. When there are the same hash values, the rule is compared bit by bit to determine whether they are the same. Hash bits are dynamically generated to optimize the storage location. Storage and deletion operations are performed according to the rule priority.

Benefits of technology

It improves the efficiency of rule storage, reduces the time consumption of storing the same rules, saves storage space, and improves the speed of rule comparison.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114625925B_ABST
    Figure CN114625925B_ABST
Patent Text Reader

Abstract

This invention provides a rule compression storage method, apparatus, storage medium, and terminal suitable for TCAM. The method includes: acquiring a rule to be stored in TCAM, which includes: rule content; calculating its own hash value based on the rule content; acquiring hash bits based on the rule content and preset rules to lock the storage location, and comparing the hash value of the rule to be stored with the hash value of a rule at the storage location; storing the rule to be stored based on the comparison result of the hash values; wherein, in the case of identical hash values, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result. This invention improves the speed of rule comparison, reduces the time consumed in storing identical rules, improves the efficiency of rule storage compression, and saves storage space by combining the hash value of the rule itself with dynamically generated hash bits.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing, and in particular to a regular compression storage method, apparatus, storage medium and terminal suitable for TCAM. Background Technology

[0002] Ternary content addressable memory (TCAM) loads rules to perform content matching, accelerating data classification and filtering. It plays a crucial role in network applications, especially in network filtering and data processing, and is widely used in large network environments or data centers. The rule capacity that TCAM can handle, its data matching speed, and its rule issuance speed are important performance indicators.

[0003] Rules stored in TCAM consist of 0, 1, and the wildcard X. For example, if the rule is 10001X01, the matching data streams are 10001001 and 10001101. The TCAM workflow is as follows: 1. Add rules, rule priorities, and associated data (also called Active Directory); 2. Data matching; 3. When a match is successful, output the associated data corresponding to the rule with the highest priority.

[0004] In TCAM applications, there are situations where the same rules are stored, but these rules are configured with different priorities, each corresponding to its associated data. For a simple example, suppose user A can enjoy 10M, 50M, and 100M broadband services. The rule represents user A's identity, but its priority has four levels: lowest priority is no network service, the next lowest is enjoying 10M bandwidth service, the next highest is enjoying 50M bandwidth service, and the highest priority is enjoying 100M bandwidth service. In this case, four identical rules and their corresponding associated data for different priorities need to be issued. When user A accesses the network, the data stream passes through TCAM, matches user A's identity, successfully matches, and returns the 100M bandwidth service. When user A changes their service plan to enjoy 10M bandwidth service, the highest and next highest priority rules must be deleted so that when user A is matched again, the 10M bandwidth service is returned.

[0005] There are two methods to achieve the above scenario: The first approach involves retaining only one rule at the hardware level, storing the associated data corresponding to its highest priority. At the software level, it's necessary to maintain all priorities and their corresponding associated data for this rule, achieving compressed storage of identical rules. When deleting a rule, the software first determines if the rule to be deleted has the highest priority. If it does, it interacts with the hardware level to delete the rule and its associated data, and then issues the new rule along with its associated data for the next lower priority. The drawback of this first approach is that maintenance at the software level is required every time a rule is added or deleted, resulting in slow matching speeds and a significant reduction in the speed of adding rules.

[0006] The second approach stores all similar rules directly at the hardware level without compression. When data streams match, the hardware returns the associated data corresponding to the highest priority rule. When deleting a rule, that rule and its associated data are deleted directly. The drawback of this second approach is that it can only store a very limited number of identical rules. Summary of the Invention

[0007] In view of the shortcomings of the prior art described above, the purpose of this invention is to provide a rule-based compressed storage method, apparatus, storage medium and terminal suitable for TCAM, so as to solve the technical problems of low rule storage efficiency and insufficient storage space in the prior art.

[0008] To achieve the above and other related objectives, a first aspect of the present invention provides a rule compression storage method applicable to TCAM, comprising: obtaining a rule to be stored in TCAM, which includes: rule content; calculating and obtaining its own hash value based on the rule content; obtaining hash bits based on the rule content and a preset rule to lock the storage location, and comparing the own hash value of the rule to be stored with the own hash value of the rule at the storage location; storing the rule to be stored based on the comparison result of the own hash value; wherein, in the case of the same hash value, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result.

[0009] In some embodiments of the first aspect of the present invention, the rule to be stored includes a rule priority; storing the rule to be stored based on the judgment result includes: when two rules are determined to be the same, comparing the rule priorities of the two identical rules; when the priority of the rule to be stored is higher, deleting the rule in the hardware that is consistent with the rule to be stored and its associated data, and saving the rule to be stored and its associated data when there is space in the storage location.

[0010] In some embodiments of the first aspect of the present invention, the method includes: maintaining, at the software level, the priorities of the same rules and their associated data, when the priority of the rule to be stored is not higher than that of another rule being compared.

[0011] In some embodiments of the first aspect of the present invention, the rule content is composed of 0, 1 and wildcards, and the step of calculating and obtaining a hash value based on the rule content includes: obtaining the number of bits of the hash value based on the number of storable rules at the storage location and a set number of rule bits; calculating bit by bit based on the rule content, and iteratively calculating the hash value using the set number of rule bits and the number of hash value as judgment conditions.

[0012] In some embodiments of the first aspect of the present invention, storing the rules to be stored based on the comparison result of the hash values ​​includes: determining whether there is space available for storage at the storage location if there are no identical hash values; determining whether the number of bits of the hash bit has reached the upper limit if there is no space at the storage location; designating the hash bit as a first hash bit; adding a new hash bit to obtain a second hash bit if the number of bits of the first hash bit has not reached the upper limit; and redistributing the rules at the storage location based on the second hash bit.

[0013] In some embodiments of the first aspect of the present invention, the storage location of the rule to be stored is locked based on the second hash bit of the rule to be stored, and the rule to be stored and its associated data are saved if there is space in the storage location.

[0014] In some embodiments of the first aspect of the present invention, the rule content consists of 0, 1 and wildcards, and the preset rule of the hash bit includes: selecting the position with fewer wildcards and a uniform distribution of the number of 0 and 1 as the hash bit based on the rule content of the stored rules.

[0015] To achieve the above and other related objectives, a second aspect of the present invention provides a rule compression storage device suitable for TCAM, comprising: a rule acquisition module for acquiring rules to be stored in TCAM, the rules comprising: rule content; a hash value calculation module for calculating its own hash value based on the rule content; a first comparison module for acquiring hash bits based on the rule content and a preset rule to lock the storage location, and comparing the hash value of the rule to be stored with the hash value of the rule at the storage location; and a second comparison module for storing the rule to be stored based on the comparison result of the hash values; wherein, in the case of identical hash values, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result.

[0016] To achieve the above and other related objectives, a third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the rule-based compressed storage method applicable to TCAM.

[0017] To achieve the above and other related objectives, a fourth aspect of the present invention provides an electronic terminal, comprising: a processor and a memory; the memory for storing a computer program, and the processor for executing the computer program stored in the memory to cause the terminal to execute the rule-based compressed storage method applicable to TCAM.

[0018] As described above, the rule compression storage method, apparatus, storage medium and terminal proposed in this invention for TCAM have the following beneficial effects: by combining its own hash value and dynamically generated hash bits, the speed of rule comparison is improved, the time consumed in storing the same rule is reduced, the efficiency of rule storage compression is improved, and storage space is saved. Attached Figure Description

[0019] Figure 1 The diagram shown is a flowchart illustrating a rule-based compressed storage method applicable to TCAM in one embodiment of the present invention.

[0020] Figure 2 The diagram shown is a flowchart illustrating a compressed storage method based on the same rules of dynamic hash bits according to an embodiment of the present invention.

[0021] Figure 3 The diagram shown is a flowchart illustrating a method for calculating a self-hash value according to an embodiment of the present invention.

[0022] Figure 4 The diagram shown is an example of a method for calculating a self-hash value in one embodiment of the present invention.

[0023] Figure 5 The diagram shown is a flowchart illustrating a method for compressing and storing TCAM according to the same rules, as described in an embodiment of the present invention.

[0024] Figure 6 The diagram shown is a structural schematic of a regular compressed storage device suitable for TCAM according to an embodiment of the present invention.

[0025] Figure 7 The diagram shown is a structural schematic of an electronic terminal according to an embodiment of the present invention. Detailed Implementation

[0026] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.

[0027] It should be noted that in the following description, reference is made to the accompanying drawings, which illustrate several embodiments of the invention. It should be understood that other embodiments may also be used, and operational changes may be made without departing from the spirit and scope of the invention. The following detailed description should not be considered limiting, and the scope of the embodiments of the invention is defined only by the claims of the published patents. The terminology used herein is for describing particular embodiments only and is not intended to limit the invention.

[0028] Furthermore, as used herein, the singular forms “a,” “an,” and “the” are intended to include the plural forms as well, unless the context indicates otherwise. It should be further understood that the terms “comprising,” “including,” indicate the presence of the stated feature, operation, element, component, item, kind, and / or group, but do not preclude the presence, occurrence, or addition of one or more other features, operations, elements, components, items, kinds, and / or groups. The terms “or” and “and / or” as used herein are interpreted as inclusive, or mean any one or any combination thereof. Thus, “A, B, or C” or “A, B, and / or C” means “any one of: A; B; C; A and B; A and C; B and C; A, B, and C.” Exceptions to this definition arise only when combinations of elements, functions, or operations are inherently mutually exclusive in some manner.

[0029] This invention provides a rule compression storage method, apparatus, storage medium, and terminal suitable for TCAM, to solve the technical problems of low rule storage efficiency and insufficient storage space in the prior art. The rules referred to in the embodiments of this invention are all ACL rules (Access Control Lists).

[0030] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining the present invention and are not intended to limit the present invention.

[0031] Example 1

[0032] like Figure 1As shown in the figure, this invention proposes a flowchart of a rule-based compressed storage method suitable for TCAM. The rule-based compressed storage method specifically includes the following steps:

[0033] Step S11. Obtain the TCAM rules to be stored, which include: rule content. In some examples, the rules to be stored also include rule ID, rule priority, its own hash value, etc.

[0034] Step S12. Calculate and obtain its own hash value based on the rule content. The rule content consists of 0, 1 and wildcards. Calculating and obtaining the hash value based on the rule content includes: obtaining the number of bits in the hash value based on the number of storable rules at the storage location and the set number of rule bits; calculating bit by bit based on the rule content, and iteratively calculating the hash value using the set number of rule bits and the number of hash value bits as judgment conditions.

[0035] Step S13. Obtain hash bits based on the rule content and preset rules to lock the storage location, and compare the hash value of the rule to be stored with the hash value of the rule at the storage location. The rule content consists of 0, 1 and wildcards, and the preset rules for the hash bits include: based on the rule content of the stored rules, selecting the location with fewer wildcards and a uniform distribution of 0 and 1 as the hash bits.

[0036] Step S14. Store the rule to be stored based on the comparison result of the hash value; wherein, in the case of the same hash value, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result.

[0037] In a preferred embodiment of this example, storing the rule to be stored based on the comparison result of the hash value includes: if no identical hash value exists, determining whether there is space available at the storage location; if there is no space at the storage location, determining whether the number of bits in the hash bit has reached its upper limit; designating the hash bit as a first hash bit; if the number of bits in the first hash bit has not reached its upper limit, adding a new hash bit to obtain a second hash bit; redistributing the rule at the storage location based on the second hash bit. The storage location is locked based on the second hash bit of the rule to be stored, and the rule to be stored and its associated data are saved if there is space at that storage location.

[0038] In a preferred embodiment of this example, the rule to be stored includes a rule priority. Storing the rule based on the judgment result includes: if two rules are determined to be the same, comparing the rule priorities of the two identical rules; if the rule to be stored has a higher priority, deleting the rule in the hardware that is identical to the rule to be stored and its associated data, and saving the rule to be stored and its associated data if there is space in the storage location. If the priority of the rule to be stored is not higher than the other rule being compared, the software layer maintains the priorities of the same rules and their associated data. It should be noted that the deletion of rules in this embodiment is a hardware-level deletion; all identical rules are saved at the software level, facilitating the issuance of the next highest priority rule to the hardware through the software layer after the higher priority rule and its associated data are deleted from the hardware layer.

[0039] In some examples, for software TCAM that implements a three-state TCAM using a two-state approach, it consists of several storage modules, each with the same number of storage rows. The application scenario is mostly a dynamic rule insertion mode, requiring the dynamic addition of hash bits to index the storage row where the rule is located. Therefore, the selection of hash bits should be based on already stored rules, choosing positions with as few wildcards as possible and with a relatively even distribution of 0s and 1s. When storing rules, the selected hash bits must be used as the basis for distributing the rules and locking the storage row position.

[0040] Based on the above principle for selecting hash bits, the process for issuing deduplication rules is as follows: In a storage module, retrieve existing hash bits; calculate the hash value of the rule to be inserted; check if there is still space in the storage row pointed to by the hash value. If the storage row pointed to by the hash value is not full, save the rule and its associated data, return success and exit; if the storage row pointed to by the hash value is full, determine whether a new hash bit can be added; if a new hash bit can be added, add the new hash bit, redistribute the rules in the storage module, and re-obtain the hash bits of the rule to be inserted; if the number of hash bits has reached the upper limit and no new hash bits can be added, return failure and exit.

[0041] The above method improves the speed of rule comparison by combining self-hash and dynamically generated hash bits, thereby reducing the time consumed by storing the same rules and effectively making up for the defects of compressing the same rules.

[0042] For ease of understanding of the present invention, as follows Figure 2 As shown in the figure, this invention proposes a flowchart of a compressed storage method based on the same rules of dynamic hash bits, which includes the following steps:

[0043] Step 21: In a storage module, obtain the hash bits of the storage module.

[0044] Step 22: Calculate the hash value based on the storage rules according to the hash bits.

[0045] Step 23: Check all rules in the storage row pointed to by the hash value and compare them bit by bit to see if they match the rule. If they do not match, proceed to step 24; otherwise, proceed to step 25.

[0046] Step 24: Check if the space for the row to be stored is full. If the row has no space left, proceed to step 26. Otherwise, save the rule to be inserted and its associated data, and then proceed to step 27.

[0047] Step 25: If the rule has a high priority, delete the old rule that is consistent with the rule and its associated data, and proceed to step 24; otherwise, proceed to step 27.

[0048] Step 26: Determine whether the hash bits of the storage module have reached the upper limit. If not, proceed to step 28; otherwise, return failure.

[0049] Step 27: Maintain the various priorities of the same rule and their corresponding associated data at the software level, and return success.

[0050] Step 28: Based on all the rules in the storage module and the rules to be inserted, add new hash bits, redistribute all the hash bits to the original rule positions, and lock the new storage row to be inserted corresponding to the rule to be inserted, then proceed to step 24.

[0051] It is worth mentioning that the self-hash value calculation method proposed in this invention makes full use of the rule content, treats the wildcard X as an independent element, and makes it equivalent to 0 and 1 (ternary) to calculate its own hash value, which serves as the attribute information of each rule.

[0052] like Figure 3 As shown in the diagram, this invention proposes a flowchart for calculating a self-hash value. Specifically, the self-hash algorithm assumes that the storage space can store M rules, the number of bits for each rule is k, and the number of bits for its self-hash is n. Therefore, it must satisfy 3... (n-1) ≤M≤3 n The size of n is determined by the conditions.

[0053] right Figure 3 The calculation method shown is illustrated with an example, such as... Figure 4As shown, if there is a rule of 101110X11X1100X1, when M=16, n=3. According to the above hash calculation principle, the first time, taking the 0th to 2nd digit "101" gives hash=10; the second time, taking the 3rd to 5th digit "110" gives hash=22; the third time, taking the 6th to 8th digit "X11" gives hash=44. Since hash>3... 3 -1, then hash = 44 - (3 3 -1) = 18; Fourth time, take the 9th to 11th positions "X11" to get hash = 40. Since hash > 3 3 -1, then hash = 40 - (3 3 -1) = 14; the fifth time, take the 12th to 14th bits "00X" to get hash = 16; the sixth time, take the 15th bit "1" to get hash = 17. Finally, we can get its own hash value as 17.

[0054] Furthermore, such as Figure 5 As shown in the figure, this invention proposes another method for compressing and storing data according to the same rules for TCAM, which includes the following steps:

[0055] Step 51: Calculate the hash of the rule to be inserted and save the hash value as its own attribute.

[0056] Step 52: Obtain the hash bit of the storage module to be inserted, and lock the storage row to be inserted based on the hash bit.

[0057] Step 53: Compare the hash of the rule to be inserted with the hash of all rules in the storage row to be inserted. If they are the same, proceed to step 54; otherwise, proceed to step 55.

[0058] Step 54: Compare two rules with the same hash bit by bit. If they are completely identical, proceed to step 56; otherwise, proceed to step 55.

[0059] Step 55: Is there space available to store the row to be inserted? If there is space, save the rule to be inserted and its associated data, and proceed to step 58; otherwise, proceed to step 59.

[0060] Step 56: Compare the priorities of the two rules. If the rule to be inserted has a higher priority, proceed to step 57; otherwise, proceed to step 58.

[0061] Step 57: Delete the rule that matches the rule to be inserted and its associated data, then proceed to step 55.

[0062] Step 58: The software maintains various priorities of the same rule and their corresponding associated data, and returns a success message.

[0063] Step 59: Determine whether the hash bits of the storage module have reached the upper limit. If not, proceed to step 60; otherwise, return failure.

[0064] Step 60: Based on all the rules in the storage module and the rule to be inserted, add new hash bits, redistribute all the hash bits to the original rule positions, lock the new storage row to be inserted corresponding to the rule to be inserted, and proceed to step 55.

[0065] Figure 5 The compressed storage method shown can be illustrated by examples, as shown in Tables 1 to 5 below. Table 1 is the rule list, Table 2 is the first storage state table, Table 3 is the second storage state table, Table 4 is the third storage state table, and Table 5 is the fourth storage state table.

[0066] Specifically, when inserting rules 1 to 4, their own hashes are first calculated to check if they match the hashes of existing rules. Their hashes are 17, 15, 12, and 11, respectively. Since the hash bits have not yet been selected and only occupy the 00 storage row, they are directly stored in the storage row with address 00, as shown in Table 2.

[0067] When rule 5 is inserted, its hash value is 4, which is inconsistent with the hash values ​​of previously saved rules, and there is no remaining space for storage. Therefore, the first hash bit needs to be selected to reclaim a storage row and distribute the rules. Based on the hash bit selection principle, the first hash bit is selected, which is the 0th position of the rule. According to this hash bit, storage rows 00 and 01 are occupied. Rules 1 and 3 are distributed to storage row 01, and rules 2 and 34 are distributed to storage row 00. The value of rule 5 on this hash bit is "X", so rule 5 must be stored in both storage rows 00 and 01, as shown in Table 3.

[0068] Table 1. List of Rules

[0069]

[0070]

[0071] When storing rule 6, its hash is calculated to be 17, and its corresponding hash bit value is "1". This is compared with the hashes of all rules in storage row 01, and it is found to be equal to the hash of rule 1. Therefore, the two rules are compared bit by bit, and they are found to be identical. Then, their priorities are compared; rule 6 has a higher priority than rule 1. Therefore, rule 1 is deleted, and rule 6 is stored. The software maintains the two priorities and their associated data for this rule. When inserting rule 7, its hash is calculated to be 7, and its corresponding hash bit value is "0". Since it is different from the hashes of all rules in storage row 00, it is directly saved to storage row 00. When inserting rule 8, its hash is calculated to be 14, and its corresponding hash bit value is "1". Since it is different from the hashes of all rules in storage row 01, it is directly saved to storage row 01. The current rule distribution is shown in Table 4.

[0072] When inserting rule 9, its own hash is calculated to be 21, and its corresponding hash bit value is "1". This is different from the hashes of all rules in storage row 01, and there is no remaining space for storage. Therefore, a second hash bit needs to be selected to reclaim a storage row and distribute the rule. Based on the hash bit selection principle, the second hash bit is selected, which is the 7th position of the rule. According to the 0th and 7th hash bits, storage rows 00, 01, 10, and 11 are occupied. The hash bit values ​​of rules 2 and 4 are "0X", stored in storage rows 00 and 01. The hash bit values ​​of rules 3 and 8 are "10", stored in storage rows 00 and 01. The hash bit value of rule 5 is "X0", stored in storage rows 00 and 10. The hash bit value of rule 6 is "11", stored in storage row 11. The hash bit value of rule 7 is "01", stored in storage row 01. The hash bit value of rule 9 is "1X". There is still space available in storage rows 10 and 11, so they can be stored directly.

[0073] When inserting rule a, its own hash is calculated to be 14, and its corresponding hash bit value is "10". This is compared with the hashes of all rules in the 10-store row, and it is found to be equal to the hash of rule 8. Therefore, the two rules are compared bit by bit, and they are found to be identical. Then, their priorities are compared; rule 8 has a higher priority than rule a. Therefore, only the software maintains the two priorities and their associated data for this rule, without performing an insertion operation. When inserting rule b, its own hash is calculated to be 7, and its corresponding hash bit value is "01". This is compared with the hashes of all rules in the 01-store row, and it is found to be equal to the hash of rule 7. Therefore, the two rules are compared bit by bit, and they are found to be identical. Then, their priorities are compared; rule b has a higher priority than rule 7. Therefore, rule 7 is deleted, and rule b is stored. The software maintains the two priorities and their associated data for this rule. When inserting rule c, its own hash is calculated to be 0, and the value of its corresponding hash bit is "00". Since it is different from the own hash of all rules in storage row 00, it is directly saved to storage row 00. The final rule distribution of the storage module is shown in Table 5.

[0074] It should be noted that the number of hash bits is determined by the storage capacity of the storage module. If the storage module can store 32K rules, totaling 128 storage rows, then 8 hash bits are required. The above example is merely an illustration of rule distribution in an application scenario and does not impose a limit on the number of hash bits.

[0075] In some embodiments, the method can be applied to a controller, such as an ARM (Advanced RISC Machines) controller, an FPGA (Field Programmable Gate Array) controller, a SoC (System on Chip) controller, a DSP (Digital Signal Processing) controller, or an MCU (Microcontroller Unit) controller, etc. In some embodiments, the method can also be applied to a computer including components such as memory, a memory controller, one or more processing units (CPUs), peripheral interfaces, RF circuitry, audio circuitry, speakers, microphones, input / output (I / O) subsystems, displays, other output or control devices, and external ports; the computer includes, but is not limited to, personal computers such as desktop computers, laptops, tablets, smartphones, smart TVs, and personal digital assistants (PDAs). In other embodiments, the method can also be applied to a server, which can be deployed on one or more physical servers based on factors such as function and load, or can be composed of distributed or centralized server clusters.

[0076] Example 2

[0077] like Figure 6 As shown in the figure, this embodiment of the invention proposes a structural schematic diagram of a rule compression storage device suitable for TCAM, which includes: a rule acquisition module 61 for acquiring rules to be stored in TCAM, which includes: rule content; a hash value calculation module 62 for calculating its own hash value based on the rule content; a first comparison module 63 for acquiring hash bits based on the rule content and a preset rule to lock the storage location, and comparing the hash value of the rule to be stored with the hash value of the rule at the storage location; and a second comparison module 64 for storing the rule to be stored based on the comparison result of the hash value; wherein, in the case of the same hash value, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result.

[0078] It should be noted that the modules provided in this embodiment are similar to the methods and implementation methods provided above, and therefore will not be repeated. It should also be understood that the division of the various modules in the above device is merely a logical functional division; in actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can all be implemented in software through processing element calls; they can all be implemented in hardware; or some modules can be implemented in software through processing element calls, while others are implemented in hardware. For example, the first comparison module 63 can be a separately established processing element, or it can be integrated into a chip in the above device. Alternatively, it can be stored as program code in the memory of the above device, and its function can be called and executed by a processing element of the above device. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element mentioned here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0079] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more digital signal processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together to form a system-on-a-chip (SOC).

[0080] Example 3

[0081] like Figure 7As shown in the diagram, this embodiment of the invention provides a structural schematic of an electronic terminal. The electronic terminal provided in this embodiment includes: a processor 71, a memory 72, and a communicator 73; the memory 72 is connected to the processor 71 and the communicator 73 via a system bus and completes communication between them; the memory 72 is used to store computer programs; the communicator 73 is used to communicate with other devices; and the processor 71 is used to run the computer program, causing the electronic terminal to execute the various steps of the rule-based compressed storage method applicable to TCAM as described above.

[0082] The system bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., clients, read-write libraries, and read-only libraries). Memory may include Random Access Memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.

[0083] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0084] Example 4

[0085] This invention provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the rule-based compressed storage method applicable to TCAM.

[0086] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented using computer program-related hardware. The aforementioned computer program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0087] In summary, this invention provides a rule compression storage method, apparatus, storage medium, and terminal suitable for TCAM. By combining its own hash value and dynamically generated hash bits, it improves the speed of rule comparison, reduces the time consumed in storing identical rules, increases the efficiency of rule storage compression, and saves storage space. Therefore, this invention effectively overcomes the various shortcomings of the prior art and has high industrial application value.

[0088] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.

Claims

1. A regular compression storage method suitable for TCAM, characterized in that, include: Retrieve the rules to be stored in TCAM, including: rule content; Calculate and obtain its own hash value based on the aforementioned rules; Hash bits are obtained based on the rule content and preset rules to lock the storage location, and the hash value of the rule to be stored is compared with the hash value of the rule at the storage location. The rules to be stored are stored based on the comparison results of their own hash values; wherein, in the case of the same hash value, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rules to be stored are stored based on the determination results. The rule content consists of 0, 1, and wildcards. The step of calculating its own hash value based on the rule content includes: The number of bits in the hash value is obtained based on the number of storable rules at the location to be stored and the set number of rule bits. The calculation is performed bit by bit based on the rule content, and the hash value is obtained by iterative calculation using the set number of rule bits and the number of bits of the hash value as judgment conditions. The rule to be stored includes a rule priority; storing the rule to be stored based on the judgment result includes: when two rules are determined to be the same, comparing the rule priorities of the two identical rules; if the rule to be stored has a higher priority, deleting the rule in the hardware that is consistent with the rule to be stored and its associated data, and saving the rule to be stored and its associated data if there is space in the storage location; The process of storing the rules to be stored based on the comparison result of the hash value includes: if there is no identical hash value, determining whether there is space available for storage at the storage location; if there is no space at the storage location, determining whether the number of bits of the hash bit has reached the upper limit; designating the hash bit as the first hash bit; if the number of bits of the first hash bit has not reached the upper limit, adding a new hash bit to obtain a second hash bit; and redistributing the rules at the storage location based on the second hash bit.

2. The rule-based compressed storage method for TCAM according to claim 1, characterized in that, include: If the priority of the rule to be stored is not higher than that of the other rule being compared, the software layer maintains the priorities of the same rule and their associated data.

3. The rule-based compressed storage method for TCAM according to claim 1, characterized in that, include: The storage location is locked based on the second hash bit of the rule to be stored, and the rule to be stored and its associated data are saved if there is space in that storage location.

4. The rule-based compressed storage method for TCAM according to claim 1, characterized in that, The rule content consists of 0, 1, and wildcards, and the preset rules for the hash bits include: Based on the rule content of the stored rules, the positions with fewer wildcards and a uniform distribution of 0s and 1s are selected as the hash bits.

5. A rule-based compressed storage device suitable for TCAM, implementing the rule-based compressed storage method for TCAM as described in any one of claims 1-4, characterized in that, include: The module for obtaining rules to be stored is used to obtain the rules to be stored in TCAM, which includes: rule content; The hash value calculation module is used to calculate and obtain its own hash value based on the rules. The first comparison module is used to obtain hash bits based on the rule content and preset rules to lock the storage location, and compare the hash value of the rule to be stored with the hash value of the rule at the storage location. The second comparison module is used to store the rule to be stored based on the comparison result of its own hash value; wherein, in the case of the same hash value, the rule content of the two rules is compared bit by bit to determine whether they are the same rule, and the rule to be stored is stored based on the determination result.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the rule-based compressed storage method for TCAM as described in any one of claims 1 to 4.

7. An electronic terminal, characterized in that, include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the terminal to perform the rule-based compressed storage method applicable to TCAM as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data storage method and device

    CN110750508A

  • Flow classification method and device

    CN111817978A