A rule storage method, device, electronic device and storage medium

By building a rule decision tree and adding the discard rule set to the rule subtree, the problem of matching overhead caused by rule redundancy in the device is solved, and more efficient rule storage and matching is achieved.

CN115834340BActive Publication Date: 2024-09-20NEW H3C SEMICON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211338517.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-28
Publication Date
2024-09-20
Estimated Expiration
2042-10-28

AI Technical Summary

Technical Problem

In devices such as switches and routers, rules in ACLs, flow tables, forwarding tables, or routing tables have a "don't care" status, resulting in rule redundancy and increased rule matching overhead.

Method used

By building a rule decision tree, obtain the discard rule set and add it to the leaf nodes that meet specific backfill conditions in the rule subtree, reduce the number of redundant rules, and store the common rules and remaining rules of each rule subtree in in TCAM.

Benefits of technology

It reduces the overhead of rule matching, reduces the storage requirements of TCAM, and improves the efficiency of rule matching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115834340B
    Figure CN115834340B
Patent Text Reader

Abstract

The embodiment of the present application provides a rule storage method, device, electronic device and storage medium, the method comprising: using the rules included in the global rule set to construct a rule decision tree and obtain a discard rule set; from the rule decision tree, determine multiple rule subtrees, the height of the rule subtree is less than or equal to a preset height threshold; add some rules included in the discard rule set to the leaf nodes that meet the backfill condition in the multiple rule subtrees, the backfill condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the added rule is the same as the value of the bit indicated by the path node of other rules in the leaf node to which the rule is added; determine the common rules of each rule subtree; store the common rules of each rule subtree and the remaining rules in the discard rule set in TCAM. Applying the technical solution provided by the embodiment of the present application can reduce the number of redundant rules and reduce the overhead of rule matching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a rule storage method, device, electronic device and storage medium. Background Art

[0002] In devices with packet classification functions such as switches, routers, and firewalls, data packets are classified and forwarded through the rules in ACL (Access Control List), flow table, forwarding table, or routing table to achieve differentiated services for data packets. ACL, flow table, forwarding table, or routing table is a collection of a series of rules. Electronic devices use decision trees to divide the rules in ACL into multiple rule sets, and then store multiple rule sets in TCAM (Ternary Content Addressable Memory). However, since the rules in ACL, flow table, forwarding table, or routing table have a "don't care" state, a rule may exist in multiple rule sets, resulting in the problem of rule redundancy and increasing the overhead of rule matching. Summary of the invention

[0003] The purpose of the embodiments of the present application is to provide a rule storage method, device, electronic device and storage medium to reduce the number of redundant rules and reduce the overhead of rule matching. The specific technical solution is as follows:

[0004] In a first aspect, an embodiment of the present application provides a rule storage method, the method comprising:

[0005] Using the rules included in the global rule set, a rule decision tree is constructed, and a discard rule set is obtained, wherein in the rule decision tree, the rules included in each subtree under a parent node have the same value at the bit indicated by the parent node and are not wildcards, and the rules included in the rule decision tree and the rules included in the discard rule set constitute the global rule set;

[0006] Determine a plurality of rule subtrees from the rule decision tree, wherein the height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the plurality of rule subtrees are the same as the rules included in the rule decision tree;

[0007] Adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet a backfill condition, wherein the backfill condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added;

[0008] Determine the common rules of each rule subtree;

[0009] The common rules of each rule subtree and the remaining rules in the discard rule set are stored in the TCAM.

[0010] In a second aspect, an embodiment of the present application provides a rule storage device, the device comprising:

[0011] A construction module, used to construct a rule decision tree using the rules included in the global rule set, and obtain a discard rule set, wherein in the rule decision tree, the rules included in each subtree under a parent node have the same value at the bit indicated by the parent node and are not wildcards, and the rules included in the rule decision tree and the rules included in the discard rule set constitute the global rule set;

[0012] A first determining module is used to determine a plurality of rule subtrees from the rule decision tree, wherein the height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the plurality of rule subtrees are the same as the rules included in the rule decision tree;

[0013] An adding module, used for adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet a backfill condition, wherein the backfill condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added;

[0014] A second determination module, used to determine the common rules of each rule subtree;

[0015] The storage module is used to store the common rules of each rule subtree and the remaining rules in the discard rule set in the TCAM.

[0016] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to implement any of the method steps described above.

[0017] In some embodiments, the electronic device further comprises a forwarding chip;

[0018] The processor is further prompted by the machine executable instructions to: implement storing the common rules of each rule subtree in a common rule table in a ternary content addressable memory TCAM, and storing the remaining rules in the discard rule set in a physical table in the TCAM; storing the rules included in each rule subtree in a block rule table in a random access memory RAM; the RAM also stores a main rule table; the block rule table stores a plurality of rules with the same common rules; the main rule table includes at least two fields, a split position set and a base address, the rules in the block rule table belong to a subtree determined by the split position set, the split position set is used to locate the position of the rule corresponding to the key value in the block rule table, the base address is used to locate the block rule table, the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address, and the common rule table and the main rule table have the same index corresponding to the same block rule table;

[0019] The forwarding chip is used to extract a target search key value from a data packet to be classified when the data packet to be classified is received; use the target search key value to match the physical table to obtain a second rule; use the target search key value to match the public rule table to obtain a primary index of the target table item in the main rule table; locate the block rule table based on the base address included in the target table item pointed to by the primary index; determine the secondary index of the first rule in the located block rule table based on the target search key value and the split position set included in the target table item pointed to by the primary index; select a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; and perform packet classification processing on the data packet to be classified according to the selected rule.

[0020] In a fourth aspect, an embodiment of the present application provides a machine-readable storage medium, wherein the machine-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the method steps described above is implemented.

[0021] An embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute any of the rule storage methods described above.

[0022] Beneficial effects of the embodiments of the present application:

[0023] In the technical solution provided by the embodiment of the present application, a rule decision tree is first constructed based on the condition that the rules included in each subtree under a parent node have the same value in the bit indicated by the parent node and are not wildcards. The rules included in different leaf nodes in the rule decision tree do not overlap, that is, there are no redundant rules in the rule decision tree; secondly, the rule decision tree is divided into multiple rule subtrees, and the partial rules included in the discard rule set are added to the leaf nodes that meet the backfill condition in the rule subtree in units of the rule subtree, instead of adding a copy of all the rules included in the discard rule set to each leaf node of the rule decision tree in units of the entire rule decision tree, thereby reducing the number of redundant rules and reducing the expansion of leaf nodes caused by rule duplication; thereafter, the common rules of each rule subtree and the remaining rules in the discard rule set are stored in the TCAM. Since the number of redundant rules in the rule subtree is reduced, the overhead of rule matching is reduced.

[0024] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0026] Figure 1 A structural diagram of a decision tree based on the HiCuts algorithm in the related art;

[0027] Figure 2 A schematic diagram of a first flow chart of a rule storage method provided in an embodiment of the present application;

[0028] Figure 3 A schematic diagram of the first structure of a rule decision tree provided in an embodiment of the present application;

[0029] Figure 4 for Figure 2 A first refinement schematic diagram of step S21;

[0030] Figure 5 for Figure 2 A second refinement schematic diagram of step S21;

[0031] Figure 6 A second structural diagram of a rule decision tree provided in an embodiment of the present application;

[0032] Figure 7 for Figure 2A detailed schematic diagram of step S22;

[0033] Figure 8 A third structural diagram of a rule decision tree provided in an embodiment of the present application;

[0034] Fig. 9 for Figure 2 A detailed schematic diagram of step S23;

[0035] Fig.10 A schematic diagram of a throw rule set backfilled into a rule subtree provided in an embodiment of the present application;

[0036] Fig.11 A schematic diagram of generating common rules of a rule subtree provided in an embodiment of the present application;

[0037] Fig.12 A schematic diagram of the correspondence between the common rule table, the main rule table and the block rule table provided in the embodiment of the present application;

[0038] Fig.13 A schematic diagram of a flow chart of a packet classification method provided in an embodiment of the present application;

[0039] Fig.14 A schematic diagram of a structure of a rule storage device provided in an embodiment of the present application;

[0040] Fig.15 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0041] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.

[0042] The following is an explanation of the terms that appear in the embodiments of the present application.

[0043] Rules: include at least one match field, one action field and priority. The match field can also be called a match domain, and the action field can also be called an action domain. The rules in the rule set are arranged in descending order according to priority.

[0044] Matching field: A field that matches the search key (key value). Electronic devices can classify matching fields according to the objects they target, such as destination IP field, source IP field, destination port field or source port field, etc., where the object targeted by the destination IP field is the destination IP, the object targeted by the source IP field is the source IP, the object targeted by the destination port field is the destination port, and the object targeted by the source port field is the source port. Electronic devices can also classify matching fields according to the type of stored values, such as prefix fields, precise fields, range fields, wildcard fields, etc., where the type of value stored in the prefix field is a prefix value, and the prefix field can also be called a prefix domain; the type of value stored in the precise field is a precise value, and the precise field can also be called a precise domain; the type of value stored in the range field is a range, and the range field can also be called a range domain; the type of value stored in the wildcard field is a wildcard (*), and the wildcard field can also be called a wildcard domain.

[0045] Action field: includes the execution action after the rule is matched, which is used to indicate the next operation on the data packet, such as forwarding the data packet or discarding the data packet.

[0046] In order to limit network traffic, improve network performance, and ensure network security, electronic devices need to provide differentiated services to data packets when transmitting data packets. Electronic devices with packet classification functions such as switches, routers, and firewalls implement this differentiated service based on ACLs, flow tables, forwarding tables, or routing tables, that is, they classify and forward data packets through the rules in ACLs, flow tables, forwarding tables, or routing tables, and provide differentiated services to data packets.

[0047] ACL, flow table, forwarding table or routing table is a collection of a series of rules. Electronic devices control and filter data packets by matching data packets with the rules in ACL, flow table, forwarding table or routing table. Rules are judgment statements that describe the matching conditions of data packets, including the effective time period of the data packet, IP (Internet Protocol) type, source / destination IP address and its wildcard, mask, etc. Electronic devices match data packets based on the rules in ACL, flow table, forwarding table or routing table, and decide on the specific processing method of the data packet, such as forwarding the data packet or discarding the data packet.

[0048] In order to increase the matching speed between data packets and rules, electronic devices store the rules in TCAM. TCAM is a high-speed search hardware, in which each bit has three states: '0', '1' and 'don't care', and can perform exact match search and fuzzy match search at the same time. However, TCAM also has disadvantages such as small capacity and high cost. In order to store a large number of complex rules in a limited TCAM, electronic devices use decision trees to optimize rule storage. When storing rules, electronic devices first use decision trees to index the rules. The specific rules are the leaf nodes of the decision tree, which are stored in RAM (Random Access Memory), and the established index is stored in TCAM. When searching for rules, the electronic device first queries the index of the rule in TCAM, and then searches the RAM for the specific hit rule. The above index is the storage location of the rule.

[0049] Decision tree is a basic classification method that splits a rule set into two parts by adding constraints, thereby dividing a complex rule set into multiple simple rule sets. However, due to the "don't care" state in the rules, a rule may exist in multiple rule sets. This rule redundancy reduces the speed of rule matching.

[0050] Take the decision tree based on the HiCuts algorithm as an example. The HiCuts algorithm is a single-dimensional cutting decision tree algorithm. When the electronic device runs the HiCuts algorithm, it will first set a threshold binth, which is used to determine whether the node of the decision tree is a leaf node; when the number of rules contained in the node is greater than binth, the electronic device selects a constraint condition and splits the node including the rule set into several equal parts as the child nodes of the node as much as possible. Among them, for the rules with the constraint condition of "don't care", the electronic device will place a copy of the rule in each child node; then the cutting is cyclical until the number of rules contained in all child nodes is less than binth, at which time the child nodes containing less than binth are leaf nodes of the decision tree.

[0051] For example, Figure 1In the decision tree based on the HiCuts algorithm shown, the electronic device sets binth=4; at the root node, the electronic device uses constraint x to divide rules R1-R6 into 4 nodes, and rules R3, R4 and R6 "don't care" about constraint x, then rules R3, R4 and R6 are inserted into each child node (nodes 1-4) of the root node, wherein the number of rules in nodes 1-3 is less than or equal to 4, therefore, nodes 1-3 serve as leaf nodes; the number of rules included in node 4 is 5, 5>4, the electronic device uses constraint y to divide the rules included in node 4 into 2 nodes, rules R3, R4 and R6 "don't care" about constraint y, then rules R3, R4 and R6 are inserted into each child node (i.e., nodes 5-6) of node 4, and the number of rules in nodes 5-6 is less than or equal to 4, therefore, nodes 5-6 serve as leaf nodes.

[0052] Through the above Figure 1 As can be seen from the decision tree shown, due to the "don't care" state in the rule, one rule is copied to multiple leaf nodes, which in turn causes the expansion of leaf nodes and increases the overhead when matching specific rules.

[0053] In order to reduce the expansion of leaf nodes caused by rule duplication, that is, to reduce the number of redundant rules and reduce the overhead when matching specific rules, an embodiment of the present application provides a rule storage method, which can be applied to electronic devices such as switches, routers or firewalls. For ease of understanding, the following description is based on electronic devices as the execution subject, which does not serve as a limitation.

[0054] In the rule storage method provided in the embodiment of the present application, the electronic device first constructs a rule decision tree based on the condition that the rules included in each subtree under a parent node have the same value of the bit indicated by the parent node and are not wildcards, and the rules included in different leaf nodes in the rule decision tree do not overlap, that is, there are no redundant rules in the rule decision tree; thirdly, the electronic device divides the rule decision tree into multiple rule subtrees, and adds part of the rules included in the discard rule set to the leaf nodes that meet the backfill condition in the rule subtree in units of the rule subtree, instead of adding a copy of all the rules included in the discard rule set to each leaf node of the rule decision tree in units of the entire rule decision tree, thereby reducing the number of redundant rules and reducing the expansion of leaf nodes caused by rule duplication; thereafter, the electronic device stores the common rules of each rule subtree and the remaining rules in the discard rule set in the TCAM.

[0055] The electronic device only fills a part of the rules in the discard rule set into the leaf nodes of the rule subtree, and directly stores the part of the rules that are not filled into the leaf nodes in the discard rule set in the TCAM. In this way, the number of redundant rules in the rule subtree can be reduced, and the storage space of the TCAM can be utilized to the maximum extent. While improving the utilization rate of the TCAM, the overhead of rule matching based on the rule subtree is reduced.

[0056] In the embodiment of the present application, the rule search process is the process of matching the data packet with the matching field of each rule. The matching fields of typical rules are shown in Table 1, such as the IP length, input logical interface identifier, message summary identifier, VPN (Virtual Private Network) identifier, source IP address, etc. of rules 1-3. The matching field of each rule can be regarded as a bit string, and each bit may be '0', '1' or '*', representing deny, allow and don't care, respectively, and * is a wildcard.

[0057] Table 1

[0058] rule IP length Input logical interface identifier Message summary identifier VPN Logo Source IP address <![CDATA[R1]]> * 0 1 * * <![CDATA[R2]]> * 1 1 1 * <![CDATA[R3]]> * 1 1 0 *

[0059] In the embodiment of the present application, the rule may include one or more matching fields in the range class field, the prefix class field, the exact class field and the wildcard class field, such as the rules R1-R2 shown in Table 1. N .

[0060] Table 2

[0061] rule Source IP Destination IP Source Port Destination Port Transport Protocol action <![CDATA[R1]]> 10.0.8.3 / 24 10.1.6.20 / 16 * 22 TCP accept <![CDATA[R2]]> 10.0.3.8 / 24 * 80 0~1024 TCP reject <![CDATA[R3]]> 10.1.0.0 / 16 10.1.8.15 / 24 0~1024 0~2048 UDP accept … … … … … … … <![CDATA[R N ]]> * * * * * reject

[0062] In Table 2, the fields storing prefix values ​​10.0.8.3 / 24, 10.1.6.20 / 16, 10.1.0.0 / 16, and 10.1.8.15 / 24 are prefix fields; the fields storing ranges 0 to 1024 and 0 to 2048 are range fields; the fields storing exact values ​​22 and 80 are exact fields; and the fields storing the wildcard * are wildcard fields.

[0063] In the embodiment of the present application, before executing the rule storage method provided in the embodiment of the present application, the electronic device may perform the following processing on each rule in the rule set:

[0064] For the prefix class field included in the rule, the value of the highest bit of the prefix length is set to the prefix value, and the values ​​of the other bits are set to wildcards. For example, in rule R2 shown in Table 2, the prefix length of the source IP field is 24, and the prefix value is 10.0.3.8. In the source IP field, the values ​​of the 24 highest bits are set to the prefix value, that is, 10.0.3, and the values ​​of the other bits are set to *, as shown in Table 3. At this time, in rule R2, the source IP can be expressed as 10.0.3.*, which is expressed in binary as: 00001010.0000 0000.000 0011.********.

[0065] Table 3

[0066] rule Source IP Destination IP Source Port Destination Port Transport Protocol action <![CDATA[R2]]> 10.0.3.* * 80 0~1024 TCP reject

[0067] For the range-type field included in the rule, the range of the range-type field is split into multiple continuous and uninterrupted sub-ranges, and the value of each bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range. Each sub-range can be equivalently represented as a prefix value, and the value set of all sub-ranges is exactly the same as the original range value set. For example, for the range [2, 5], the range can be divided into the following two sub-ranges: [2, 3], [4, 5]. The sub-range [2, 3] can be equivalently represented by the binary prefix value 001*, and the sub-range [4, 5] can be equivalently represented by the binary prefix value 010*. Among them, * is a wildcard, and the bit of * can be 0 or 1.

[0068] For the precise class field included in the rule, the value of each bit in the precise class field is set to the precise value. For example, in rule R2 shown in Table 3, the source port field is the precise class field, and the value of each bit in the source port field is set to the precise value, that is, 80. At this time, in rule R2, the source port can be represented as 80, which is represented in binary as: 0101 0000.

[0069] For the wildcard class field included in the rule, the value of each bit in the wildcard class field is set to *. For example, in rule R2 shown in Table 3, the destination IP field is a wildcard class field, and the value of each bit in the destination IP field is set to *.

[0070] In an embodiment of the present application, the electronic device can directly set the range class field, prefix class field, exact class field and wildcard class field in the rule according to the above provisions.

[0071] In the embodiment of the present application, in order to facilitate TCAM storage, the electronic device can convert the rules into the form of key (key value) and mask (mask), and use key and mask to represent the rules. The key value (value) is used to indicate the specific value of the key, and the mask indicates whether the corresponding bit in the key is concerned, 1 means concerned, and 0 means not concerned.

[0072] For example, the electronic device may convert the rule into the form of key and mask according to the following conversion method:

[0073] For the prefix class field, the prefix length is L, the key is the prefix value, the first L bits of the mask are 1, and the remaining bits are 0. For example, if the source IP is 10.1.0.0 / 16, the converted key is hexadecimal 0x0A010000, and the mask is hexadecimal 0xFFFF0000;

[0074] For range fields, the range of the range field is divided into several continuous and uninterrupted sub-ranges, so that each sub-range can be equivalently represented as a prefix, and the value set of all sub-ranges is exactly the same as the original range value set;

[0075] For precise fields, the key is the exact value and the mask is all 1;

[0076] For wildcard fields, key and mask are both 0.

[0077] For the value of any bit I of rule R, the relationship between key and mask is as follows:

[0078] R[I]=0, means mask[I]=1, key[I]=0;

[0079] R[I]=1, means mask[I]=1, key[I]=1;

[0080] R[I]=* means mask[I]=0, key[I]=0 or key[I]=1.

[0081] The following is a detailed description of the rule storage method provided in the embodiment of the present application through specific examples.

[0082] See also Figure 2 , Figure 2 A first flow chart of a rule storage method provided in an embodiment of the present application, the method comprising the following steps:

[0083] Step S21, using the rules included in the global rule set, construct a rule decision tree and obtain a discard rule set.

[0084] In the rule decision tree, each subtree under a parent node includes rules with the same value at the bit indicated by the parent node and is not a wildcard, and the rules included in the rule decision tree and the rules included in the discard rule set constitute a global rule set. Under this condition, the rules included in different leaf nodes in the rule decision tree do not overlap.

[0085] In an embodiment of the present application, the electronic device uses all rules with matching fields and action fields as a global rule set, which is a collection of all rules for packet classification pre-stored in the electronic device, such as the rules in the above-mentioned ACL, flow table, forwarding table or routing table. The rule decision tree includes multiple nodes, each non-leaf node includes: the bit position classified into one or more subtrees, the rules and quantity thrown into the discard rule set, and other information; each leaf node includes one or more rules.

[0086] In the rule decision tree, one parent node includes one or more subtrees, and each subtree includes one or more rules. All rules included in a subtree have the same value of the bit indicated by the corresponding parent node, and are not *, such as all 1 or all 0. In this case, in the rule decision tree, the rules included in different leaf nodes do not overlap, so there are no redundant rules in the rule decision tree. For rules that do not care about the value of the bit indicated by the node, that is, the rule whose value of the bit indicated by the node is *, the electronic device adds such rules to the discard rule set. After the rule decision tree is constructed, the rules included in the rule decision tree and the rules included in the discard rule set constitute a global rule set.

[0087] The specific method of constructing a rule decision tree and obtaining a discard rule set will be described in detail later. This section will introduce it in detail.

[0088] Step S22, determining a plurality of rule subtrees from the rule decision tree.

[0089] The height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the multiple rule subtrees are the same as the rules included in the rule decision tree.

[0090] In the embodiment of the present application, the rule decision tree includes multiple rule subtrees, that is, the rules included in the rule decision tree are divided into multiple rule subtrees. The height of the rule subtree represents the maximum number of levels of nodes included in the rule subtree. Assume that, Figure 1 The decision tree shown is a rule subtree, which includes nodes of three levels, namely the root node of the first level, nodes 1-4 of the second level, and nodes 5-6 of the third level. Therefore, the maximum number of levels of the rule subtree is 3, that is, the height of the rule subtree is 3.

[0091] A height threshold of a rule subtree is preset in the electronic device, and a preset height threshold is set. The preset height threshold can be set according to actual needs. For example, when the TCAM capacity is large, the preset height threshold can be set to a smaller value, such as 2, 3, etc., so that each rule subtree includes fewer rules. When determining that a data packet matches the rule of a certain rule subtree, the matching rule can be quickly determined from fewer rules, thereby improving the efficiency of rule matching. For another example, when the TCAM capacity is small, the preset height threshold can be set to a larger value, such as 5, 6, etc., so that each rule subtree includes more rules, so that the TCAM can store the common rules of all rule subtrees, achieve matching of all rules, and ensure the integrity of the matching.

[0092] Step S23: adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet the backfill condition.

[0093] Among them, the backfill conditions include: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added.

[0094] In the embodiment of the present application, for each rule, if the value of the rule is * at the position indicated by each path node from a leaf node to the root node, or the value of the rule is the same as the value of other rules in the leaf node, then the leaf node is a leaf node that meets the backfill condition, and the electronic device can add the rule to the leaf node. This process can be called rule backfilling.

[0095] For example, Figure 3 The rule decision tree shown, Figure 3 Only one rule subtree included in the rule decision tree, namely rule subtree 1, is shown. The rule decision tree may also include other rule subtrees, which is not limited thereto. Figure 3 In the example, the leaf nodes of rule subtree 1 include rules R1 and R2, P0, P1 and P2 are the bits indicated by the nodes, and P0 is the bit indicated by the root node of the rule decision tree. R1 and R2 have the same values ​​at P0, P1 and P2. For example, the values ​​of R1 and R2 at P0 and P1 are both 0, and the values ​​at P2 are both 1. The electronic device obtains rule R3 from the discard rule set. If R3 meets any of the following conditions, R3 is added to the leaf nodes where rules R1 and R2 are located. The specific conditions are:

[0096] 1) The value at P0 and P1 is 0, and the value at P2 is 1;

[0097] 2) The value at P0 is *, the value at P1 is 0, and the value at P2 is 1;

[0098] 3) The value at P0 is 0, the value at P1 is *, and the value at P2 is 1;

[0099] 4) The value at P0 and P1 is 0, and the value at P2 is *;

[0100] 5) The value at P0 and P1 is *, and the value at P2 is 1;

[0101] 6) The value at P0 and P2 is *, and the value at P1 is 0;

[0102] 7) The values ​​at P1 and P2 are *, and the value at P0 is 0;

[0103] 8) The values ​​of P0, P1 and P2 are all *.

[0104] In the embodiment of the present application, the backfill condition may also include: the number of rules included in the leaf node is less than or equal to the fourth preset number threshold. The fourth preset number threshold represents the maximum number of rules allowed to be stored in the leaf node. The fourth preset number threshold can be set according to actual needs. In order to improve the efficiency of rule matching, the fourth preset number threshold should not be too large to avoid wasting too much time when comparing the rules contained in the leaf node one by one after the leaf node is found. The backfill condition may also include other information, which is not limited.

[0105] In the embodiment of the present application, after some rules included in the discard rule set are added to multiple rule subtrees, the sum of the number of remaining rules and the number of multiple rule subtrees is less than or equal to the capacity of the TCAM. For example, the capacity of the TCAM is C, the number of rule subtrees is M, and the number of rules included in the discard rule set after backfilling is T', M+T'≤C. In order to make full use of the efficient search performance of TCAM and improve the efficiency of rule matching, M+T'=C. At this time, the number of rules backfilled to the rule subtree in the discard rule set is R=T+MC, where T is the number of rules included in the discard rule set before backfilling.

[0106] In the embodiment of the present application, the rule decision tree is stored in a RAM pre-allocated for the rule decision tree. After some rules included in the discard rule set are added to multiple rule subtrees, if the RAM allocated for the rule decision tree is full, and the sum of the number of rules remaining in the discard rule set and the number of multiple rule subtrees is greater than the capacity of the TCAM, the electronic device can write the remaining part of the rules in the discard rule set into the TCAM according to the write strategy, and the sum of the rules written into the TCAM and the number of multiple rule subtrees is equal to the capacity of the TCAM; for the rules in the discard rule set that are not written into the TCAM, the electronic device can discard these rules.

[0107] The write strategy can be set according to actual needs. For example, the write strategy can be any of the following:

[0108] 1. Select rules according to the order of writing the discard rule set, and write the selected rules into the TCAM.

[0109] 2. Randomly select a rule and write the selected rule into TCAM.

[0110] Step S24, determining the common rules of each rule subtree.

[0111] In the embodiment of the present application, the common rules of a rule subtree can be understood as the common rules of all rules in the rule subtree. After the electronic device backfills part of the rules in the discarded rule set into the rule subtree, for each rule subtree, the electronic device determines the common rules of the rule subtree.

[0112] Step S25: store the common rules of each rule subtree and the remaining rules in the discard rule set in the TCAM.

[0113] For each rule subtree, the electronic device stores the common rules of the rule subtree in the TCAM, and also stores the remaining rules in the discard rule set in the TCAM.

[0114] In the technical solution provided in the embodiment of the present application, the electronic device compresses the global rule set and stores the common rules of the rule subtree in the TCAM instead of storing all the rules in the TCAM, thereby reducing the demand for TCAM capacity and reducing the cost of rule storage.

[0115] In addition, the electronic device only fills a part of the rules in the discard rule set into the leaf nodes of the rule subtree, and directly stores the part of the rules in the discard rule set that are not filled into the leaf nodes in the TCAM. In this way, the number of redundant rules in the rule subtree can be reduced, and the storage space of the TCAM can be utilized to the maximum extent. While improving the utilization rate of the TCAM, the overhead of rule matching based on the rule subtree is reduced.

[0116] In some embodiments, Figure 4 As shown, the above step S21 may include steps S41 to S44.

[0117] Step S41, taking the global rule set as the rule set to be split, taking the node in the rule decision tree containing the rule set to be split as the target node, and the global rule set is contained in the root node of the rule decision tree.

[0118] In the embodiment of the present application, when initially constructing a rule decision tree, the electronic device uses the global rule set as the rule set to be split. When subsequently splitting, all rules included in a subtree constitute the rule set to be split. The node in the rule decision tree that contains the rule set to be split is the target node. When initially constructing the rule decision tree, the root node of the rule decision tree is the target node.

[0119] Step S42, determining the target bit for rule splitting in the rule set to be split, as the bit indicated by the target node.

[0120] In the embodiment of the present application, the electronic device may adopt different splitting methods to determine the target bit to split the rule set to be split into one or more rule sets. The splitting methods may include but are not limited to random splitting methods, balanced splitting methods, and unbalanced splitting methods.

[0121] When the random splitting method is adopted, the electronic device can randomly select a bit as the target bit for regular splitting, that is, the target bit is a random bit.

[0122] When the balanced splitting method is adopted, the electronic device selects the bit with the smallest number of rules whose value is * in the rule set to be split. If there is only one bit with the smallest number of rules whose value is *, this bit is used as the target bit; if there are multiple bits with the smallest number of rules whose value is *, the bit with the smallest difference between the number of rules whose value is 0 and the number of rules whose value is 1 is selected from these multiple bits as the target bit, that is, the target bit is the bit with the smallest number of rules whose value is * and the smallest difference between the number of rules whose value is 0 and the number of rules whose value is 1.

[0123] As shown in Table 1, at the bit positions where the input logical interface identifier and the message summary identifier are located, the number of rules with a value of * is both 0, which is the smallest. At the bit position where the input logical interface identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is 2-1=1. At the bit position where the message summary identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is 3-0=3, 3>1. It can be seen that at the bit position where the input logical interface identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is the smallest. Therefore, the electronic device can determine that the bit position where the input logical interface identifier is located is the target bit position.

[0124] By using a balanced split method to split the rule set, the number of rules included in each leaf node of the final rule decision tree can be balanced. When searching for rules, it is necessary to match the search key with the rules in the leaf node one by one. Based on this, using a balanced split method can balance the time consumed by searching for rules, thereby achieving a balanced computing resource.

[0125] When the unbalanced splitting method is adopted, the electronic device selects the bit with the smallest number of rules whose value is * in the rule set to be split. If there is only one bit with the smallest number of rules whose value is *, this bit is used as the target bit. If there are multiple bits with the smallest number of rules whose value is *, the bit with the largest difference between the number of rules whose value is 0 and the number of rules whose value is 1 is selected from these multiple bits as the target bit, that is, the target bit is the bit with the smallest number of rules whose value is * and the largest difference between the number of rules whose value is 0 and the number of rules whose value is 1.

[0126] As shown in Table 1, at the bit position where the input logical interface identifier and the message summary identifier are located, the number of rules with a value of * is 0, which is the smallest, and at the bit position where the input logical interface identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is 2-1=1, and at the bit position where the message summary identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is 3-0=3, 3>1. It can be seen that at the bit position where the message summary identifier is located, the difference between the number of rules with a value of 0 and the number of rules with a value of 1 is the largest. Therefore, the electronic device can determine that the bit position where the message summary identifier is located is the target bit position.

[0127] The rule set is split in an unbalanced splitting manner. After the rule decision tree is built, a node may have only one child node. Based on this, when some rules included in the discarded rule set are filled into the rule decision tree, the number of nodes to add rules can be reduced, the expansion of leaf nodes caused by rule duplication is reduced, and the overhead when matching specific rules is reduced.

[0128] Step S43, add the rule whose target bit value is 1 in the rule set to be split to the first side child node of the target node, add the rule whose target bit value is 0 in the rule set to be split to the second side child node of the target node, and add the rule whose target bit value in the rule set to be split is a wildcard in the rule decision tree to the discard rule set.

[0129] In an embodiment of the present application, the first side is the left side and the second side is the right side, and accordingly, the first side child node is the left node and the second side child node is the right node; or, the first side is the right side and the second side is the left side, and accordingly, the first side child node is the right node and the second side child node is the left node.

[0130] After determining the rule set to be split, the target node and the target bit, the electronic device adds the rule whose target bit value is 1 to the first side child node of the target node, adds the rule whose target bit value is 0 to the second side child node of the target node, and discards the rule whose target bit value is * from the rule set to be split and adds it to the discard rule set.

[0131] Taking the first side as the right side and the second side as the left side as an example, as shown in Table 1 above, the electronic device determines that the bit where the VPN identifier is located is the target bit, and adds rule R3 with a value of 0 for the bit where the VPN identifier is located to the left child node of the target node, and adds rule R2 with a value of 1 for the bit where the VPN identifier is located to the right child node of the target node; rule R1 with a value of * for the bit where the VPN identifier is located is thrown out from the set of rules to be split and added to the discarded rule set.

[0132] Step S44, taking the rule set included in the child node whose number of rules is greater than or equal to the first preset number threshold as the new rule set to be split, and taking the node in the rule decision tree containing the rule set to be split as the new target node, and re-execute step S42 until the number of rules included in the child node is less than the first preset number threshold.

[0133] In the embodiment of the present application, the first preset quantity threshold can be set according to actual needs, for example, the first preset quantity threshold can be 2, 3 or 4.

[0134] In step S43, the electronic device splits the rule set to be split into two rule sets, namely, the rule set included in the first side subnode and the rule set included in the second side subnode. For each subnode obtained in step S43, the electronic device can determine whether the number of rules included in the subnode is greater than or equal to the first preset number threshold; if so, the rule set included in the subnode is used as the new rule set to be split, and the subnode (i.e., the node in the rule decision tree that contains the rule set to be split) is used as the new target node, and step S42 is re-executed to continue splitting the rule set included in the subnode; if not, the splitting of the rule set included in the subnode is terminated.

[0135] In the embodiment of the present application, the electronic device cyclically executes the above steps S42-S44 to complete the construction of the rule decision tree and obtain the constructed rule decision tree.

[0136] In the technical solution provided in the embodiment of the present application, the electronic device can select the corresponding splitting method according to different needs, such as random splitting method, balanced splitting method or unbalanced splitting method, to meet different needs, such as the time balance consumed by the above-mentioned search rules to achieve the demand for balanced computing resources, as well as the above-mentioned reduction of leaf node expansion caused by rule duplication, and the reduction of overhead when matching specific rules.

[0137] In some embodiments, the electronic device can adopt the above-mentioned multiple splitting methods to complete the construction of the rule decision tree. For example, the electronic device can adopt the balanced splitting method and the unbalanced splitting method to complete the construction of the rule decision tree. In this case, Figure 5 As shown, the above step S21 may include steps S51 to S58.

[0138] Step S51, taking the global rule set as the rule set to be split, taking the node in the rule decision tree that includes the rule set to be split as the first target node, and the global rule set is included in the root node of the rule decision tree.

[0139] Step S52, determine the first target bit for rule splitting in the rule set to be split, as the bit indicated by the first target node, the first target bit is the bit with the smallest number of rules with wildcard values ​​and the largest difference between the number of rules with 0 values ​​and the number of rules with 1 values.

[0140] Step S53, add the rule whose first target bit value is 1 in the rule set to be split to the first side child node of the first target node, add the rule whose first target bit value is 0 in the rule set to be split to the second side child node of the target node, and add the rule whose first target bit value is a wildcard in the rule set to be split to the discard rule set.

[0141] Step S54, taking the rule set included in the child node whose number of rules is greater than or equal to the second preset number threshold as the new rule set to be split, and taking the node in the rule decision tree containing the rule set to be split as the new first target node, and re-execute step S52 until the number of rules included in the child node is less than the second preset number threshold.

[0142] The second preset quantity threshold can be set according to actual needs, for example, the second preset quantity threshold can be 2, 3 or 4.

[0143] Step S55: taking the rule set included in the child node whose number of rules is less than the second preset number threshold as a new rule set to be split, and taking the node in the rule decision tree including the rule set to be split as the second target node.

[0144] Step S56, determine the second target bit for splitting the rules in the rule set to be split, as the bit indicated by the second target node, the second target bit is the bit with the smallest number of rules whose values ​​are wildcards, and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1.

[0145] Step S57, add the rule whose second target bit value is 1 in the rule set to be split to the first side node of the second target node, add the rule whose second target bit value is 0 in the rule set to be split to the second side node of the target node, and add the rule whose second target bit value is a wildcard in the rule set to be split to the discard rule set.

[0146] Step S58, taking the rule set included in the child node whose number of rules is greater than or equal to the third preset number threshold as the new rule set to be split, and taking the node in the rule decision tree containing the rule set to be split as the new second target node, and re-execute step S56 until the number of rules included in the child node is less than the third preset number threshold.

[0147] The third preset quantity threshold can be set according to actual needs, for example, the third preset quantity threshold can be 2, 3 or 4.

[0148] The description of the above steps S51-S58 is similar to that of the above steps S41-S44, and please refer to the relevant description of steps S41-S44 for details.

[0149] The electronic device completes the construction of the rule decision tree by executing the above steps S51 to S58. Figure 6 The construction process of the rule decision tree shown. Figure 6 In Th max Represents the second preset quantity threshold, Th leaf The electronic device sets the type of the root node to head, and performs an unbalanced split on the global rule set according to the above steps S51-S54 until the number of rules included in the node is less than Th max , and the number of rules is less than Th max The type of the node is set to MAX; then, the electronic device performs balanced splitting of the rule set included in the node whose node type is MAX according to the above steps S55-S58 until the number of rules in the node is less than Th leaf , and the number of rules is less than Th leaf At this point, the electronic device has completed the construction of the rule decision tree, and the rules thrown out at each node constitute a discard rule set.

[0150] Here, the node type is set only to facilitate the distinction between the two splitting stages of unbalanced splitting and balanced splitting, and does not play a limiting role.

[0151] In the technical solution provided in the embodiment of the present application, the electronic device first adopts an unbalanced splitting method to split the rule set, and then adopts a balanced splitting method to split the rule set, so as to complete the construction of the rule decision tree, which satisfies the time balance consumed in searching for rules and achieves the demand of balanced computing resources, and also meets the demand of reducing the expansion of leaf nodes caused by rule duplication and reducing the overhead when matching specific rules.

[0152] In some embodiments, Figure 7 As shown, the above step S22 may include steps S71 to S73.

[0153] Step S71, starting from the root node of the rule decision tree, traverse the nodes downward.

[0154] Step S72, if the height from the traversed node to the leaf node is greater than the preset height threshold, continue to execute the step of traversing the nodes downward until the height from the traversed node to the leaf node is less than or equal to the preset height threshold.

[0155] Step S73: the subtree starting from the node reached when the downward traversal of nodes ends is used as a regular subtree.

[0156] In the embodiment of the present application, starting from the root node of the rule decision tree, traversing the nodes downward, the electronic device determines whether the height from the current node traversed to the leaf node is greater than the preset height threshold; if so, that is, greater than the preset height threshold, then continue to traverse the nodes downward from the node, and continue to determine whether the height from the current node traversed to the leaf node is greater than the preset height threshold; if not, that is, less than or equal to the preset height threshold, then end the downward traversal of the nodes, and use the subtree starting from the node as the rule subtree. Based on this, the electronic device can divide a rule decision tree into multiple rule subtrees to facilitate the backfilling of subsequent rules.

[0157] For example Figure 8 The rule decision tree shown, Figure 8 In Th min The electronic device sets the root node type to head, and detects whether the height from the traversed node to the leaf node is greater than Th according to the above steps S71-S73. min , the height from the traversed node to the leaf node is less than or equal to Th min When traversing, the type of the node is set to MIN, and the subtree starting from the MIN node is a regular subtree.

[0158] Here, setting the node type is only for the convenience of distinguishing the nodes of the rule subtree and does not play a limiting role.

[0159] In the embodiment of the present application, the electronic device may also use other methods to divide a rule decision tree into multiple rule subtrees. For example, the electronic device starts from the leaf node of the rule decision tree and traverses the nodes upward; if the height from the traversed node to the leaf node is less than the preset height threshold, the step of traversing the nodes upward continues until the height from the traversed node to the leaf node is greater than or equal to the preset height threshold; the subtree starting from the node traversed at the end of the upward traversal of the nodes is the rule subtree. Here, a leaf node exists in a rule subtree.

[0160] In some embodiments, Fig. 9 As shown, the above step S23 may include steps S91 to S93.

[0161] Step S91: for each rule subtree, determine the number of leaf nodes that meet the backfill condition and correspond to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule.

[0162] The backfill overhead indicates the number of leaf nodes that need to add a copy of the rule when the rule is inserted back into the rule subtree. For each rule subtree, for each rule included in the discard rule set, the electronic device determines the leaf nodes corresponding to the rule in the rule subtree that meet the backfill condition, and counts the number of leaf nodes that meet the backfill condition as the backfill overhead corresponding to the rule.

[0163] In some embodiments, the electronic device may traverse downward from the root node of the rule decision tree to the leaf node, and based on the information recorded in each node, such as the bit indicated by the node and the rule thrown at the node, determine the leaf node corresponding to each rule that meets the backfill condition, determine which rule subtree the rule can be backfilled to, and then determine the backfill overhead corresponding to the rule. In the embodiment of the present application, the rules backfilled to the same rule subtree are recorded as a thrown rule set, such as Fig.10 As shown, there are n rule subtrees corresponding to n throwing rule sets.

[0164] In other embodiments, the electronic device may determine the throwing position of each rule based on the information recorded by each node, such as the bit position indicated by the node and the rule thrown at the node, and traverse downward from the node at the throwing position of the rule decision tree to the leaf node, and determine the leaf node corresponding to each rule that meets the backfill condition based on the information recorded by each node, such as the bit position indicated by the node and the rule thrown at the node, determine which rule subtree the rule can be backfilled to, and then determine the backfill overhead corresponding to the rule.

[0165] For each rule, after determining the rule subtree to which the rule can be backfilled, the electronic device calculates the number of leaf nodes corresponding to the rule in the rule subtree that meet the backfill condition as the backfill cost.

[0166] Step S92, determining a target rule with the smallest backfill cost and a target rule subtree with the smallest backfill cost corresponding to the target rule.

[0167] Step S93, adding the target rule to the leaf nodes that meet the backfill condition in the target rule subtree, and returning to execute step S91.

[0168] After determining the backfill overhead of each rule in each rule subtree, the electronic device determines the rule with the smallest backfill overhead as the target rule, and the target rule subtree with the smallest backfill overhead corresponding to the target rule; for the target rule subtree corresponding to the target rule when the backfill overhead is the smallest, the electronic device adds the target rule to the leaf node that meets the backfill condition in the target rule subtree. After that, the electronic device executes step S91 to recalculate the backfill overhead. Steps S91-S93 are executed in a loop until the number of backfill rules meets the requirement, such as the number of rules backfilled to the rule subtree in the discarded rule set reaches T+MC, where T is the number of rules included in the discarded rule set before backfilling, C is the capacity of TCAM, and M is the number of rule subtrees.

[0169] In an embodiment of the present application, the electronic device calculates the backfill overhead and backfills the rules to the leaf nodes in the rule subtree with the smallest backfill overhead. This allows the rules to be filled in the leaf nodes with the least backfill overhead, reduces the expansion of leaf nodes caused by rule duplication, and reduces the overhead when matching specific rules.

[0170] In some embodiments, the above step S24 may be: for each bit of all rules in each rule subtree:

[0171] If the value of a bit of all rules included in each rule subtree is 1, the value of the bit of the common rule of the rule subtree is set to 1;

[0172] If the values ​​of one bit of all rules included in each rule subtree are all 0, the value of this bit of the common rules of the rule subtree is set to 0;

[0173] If the values ​​of one bit of all class rules included in each rule subtree are not all 1, and / or the values ​​of one bit of all rules included in each rule subtree are not all 0, the value of the bit of the public rules of the rule subtree is set to a wildcard.

[0174] For example Fig.11 A schematic diagram of the generation of common rules for the rule subtree shown. Fig.11 A rule subtree includes 4 rules, namely rules 0-3. Fig.11 In the example, at bit position P0, the values ​​of rules 0-3 are all 0, then the electronic device sets the value of bit position P0 of the public rule to 0; at bit position P1, the values ​​of rules 0-3 are all 1, then the electronic device sets the value of bit position P1 of the public rule to 1; at other bit positions, if rules 0-3 do not satisfy the above two conditions, then the electronic device sets the values ​​of these bits of the public rule to *.

[0175] In the embodiment of the present application, the bit width of the common rule is the same as the bit width of the rule, and when all bits of the common rule are set, the common rule is generated and stored in the TCAM.

[0176] In the technical solution provided in the embodiment of the present application, the electronic device extracts the common rules of all rules in each rule subtree, that is, one common rule can represent multiple rules, and stores the common rules in the TCAM, thereby reducing the demand for TCAM capacity. A smaller capacity TCAM can be used to achieve larger-scale rule search, saving the cost and power consumption of packet classification.

[0177] In addition, in the technical solution provided in the embodiment of the present application, the electronic device uses the above method to extract the common bits of all rules in the rule subtree as the common rules of the rule subtree, which can ensure that the rules that cannot match the common rules will not appear in the corresponding rule subtree, thereby reducing the possibility of false positives.

[0178] In some embodiments, for each block rule table, the electronic device can determine the bits that are 1 or 0 in all the rules in the block rule table; if the number of bits that are 1 or 0 is greater than a preset value, then randomly select a bit of the preset value from the bits that are 1 or 0; for each selected bit, if the bit in all rules is 1, then the value of the bit in the public rule corresponding to the block rule table is set to 1; if the bit in all rules is 0, then the value of the bit in the public rule corresponding to the block rule table is set to 0; except for the selected bit, the values ​​of other bits of the public rules corresponding to the block rule table are all set to *. In this case, the bits of concern in the public rules are reduced, which helps to compress the TCAM and further reduce the need for TCAM capacity. The size of the preset value can be set according to actual needs.

[0179] In an embodiment of the present application, after backfilling some rules in the discard rule set into the rule subtree, the electronic device stores the common rules of each rule subtree and the remaining rules in the discard rule set in the TCAM, and the specific rules included in each rule subtree are stored in the RAM.

[0180] In the technical solution provided by the embodiment of the present application, the electronic device compresses the rules and stores a large number of rules in TCAM and RAM. In addition, by dividing the rule subtree, backfilling overhead calculation, rule backfilling, etc., as many rules as possible are stored in TCAM, which improves the speed of rule matching, reduces the duplication rate of rules when constructing the rule decision tree, and effectively solves the contradiction between effective TCAM capacity and high-speed search requirements.

[0181] Based on the remaining rules in the discard rule set stored in the above TCAM, the electronic device performs packet classification processing. In some embodiments, before performing packet classification processing, the electronic device executes the above step S25. In one example, the above step S25 can be: storing the common rules of each rule subtree in the common rule table in the TCAM, and storing the remaining rules in the discard rule set in the physical table in the TCAM. In addition, before performing packet classification processing, the electronic device can store the rules included in each rule subtree in the block rule table in the RAM; the RAM also stores a main rule table; the block rule table stores multiple rules with the same common rules; the main rule table includes at least two fields, a split position set and a base address, the rules in the block rule table belong to a subtree determined by the split position set, the split position set is used to locate the position of the rule corresponding to the key value in the block rule table, the base address is used to locate the block rule table, the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address, and the common rule table and the main rule table have the same index corresponding to the same block rule table.

[0182] In the embodiment of the present application, one or more public rule tables, one or more main rule tables, and one or more block rule tables may be stored in the electronic device. The public rule table and the main rule table correspond one to one. For the table items of the public rule table and the table items of the main rule table with the same index, both correspond to the same block rule table. One table item in the main rule table corresponds to one block rule table. When the main rule table includes multiple table items, the main rule table corresponds to multiple block rule tables. Taking a public rule table and a main rule table as an example, the correspondence between the public rule table, the main rule table, and the block rule table is as follows: Fig.12 As shown in the figure, the index is used to indicate the position of the entry in the table.

[0183] The common rule table is established in TCAM, which can also be called TCAM table. An entry in the TCAM table is a common rule of multiple rules in a block rule table, such as Fig.12 In the embodiment of the present application, multiple rules in a block rule table constitute a rule block.

[0184] A TCAM table has a corresponding master rule table stored in RAM, such as Fig.12L0-Ln in the main rule table. The main rule table can be a linear table or other forms of tables supported by RAM. The main rule table can also be called a main table. A table entry in the main table stores the split position set (split bits) of a rule block and the base address of the subordinate table. Here, the subordinate table is the block rule table storing the rule block. The offset of each rule block corresponding table entry in the main table is the same as the offset of the rule block corresponding table entry in the TCAM table. The offset here is the index, such as Fig.12 The primary index in .

[0185] The multiple rules included in a rule block constitute a block rule table and are stored in RAM, such as Fig.12 Rules 0-3 in constitute a rule block, which is stored in block rule table 0 in RAM. The block rule table can be a linear table or other form of table supported by RAM. The block rule table can also be called a block table, such as Fig.12 Block table 0 and Block table n in the main table. The base address and split position set of a block table are stored in a table entry in the main table. The split position set consists of multiple bits. Assuming that the number of bits included in the split position set is S, the size of the Block table is 2 to the power of S, that is, the Block table includes 2 to the power of S rules. For example, S=2, 2 to the power of 2=4, then the Block table includes 4 rules. When the electronic device obtains the split position set of a rule block, it extracts the value of each rule in the rule block in these S bits to form the offset of each rule. The offset is the index of the rule in the block table, such as Fig.12 The sub-index in .

[0186] The above-mentioned common rule table, main rule table and block rule table can be collectively referred to as an algorithm table.

[0187] Based on the above common rule table, main rule table, block rule table and physical table, when receiving a data packet to be classified, the electronic device performs packet classification processing, such as Fig.13 As shown, the following steps are included:

[0188] Step S131, extracting a target search key value from the data packet to be classified.

[0189] In the embodiment of the present application, the electronic device receives a data packet input by a user or a data packet input by another device to the electronic device, and the data packet received by the electronic device is the data packet to be classified. After the electronic device obtains the data packet to be classified, it can extract the key information constituting the key from the header of the data packet to be classified, and use the extracted key information to form a search key, that is, a target search key.

[0190] Step S132, use the target search key value to match in the physical table to obtain the second rule.

[0191] In the embodiment of the present application, after obtaining the target search key, the electronic device uses the target search key to match in the physical table to obtain a matching rule. In the embodiment of the present application, the target search key matches a rule in the physical table, which can be understood as: the target search key has the same value as the rule in the same bit position, or the value of the rule in the same bit position is *.

[0192] Step S133, use the target search key value to perform a match in the common rule table to obtain the primary index of the target entry in the main rule table.

[0193] After obtaining the target search key, the electronic device uses the target search key to match in the public rule table, and obtains the index of the table entry where the matched public rule is located. The index is the index of the target table entry in the main rule table. In the embodiment of the present application, the index of the target table entry in the main rule table is called the main index. In the embodiment of the present application, the target search key matches the public rule, which can be understood as: the target search key has the same value as the public rule in the same bit position, or the public rule has the same value as * in the same bit position.

[0194] Step S134, locating the block rule table based on the base address included in the target table entry pointed to by the primary index;

[0195] The public rule table corresponds to the main rule table one by one, and the index of the public rule table and the main rule table corresponding to the same block rule table is the same. After obtaining the main index from the TCAM, the electronic device reads the target table entry corresponding to the main index in the main rule table, obtains the base address and split position set of the block rule table, and then locates the block rule table at the read base address.

[0196] Step S135 , determining the secondary index of the first rule in the located block rule table based on the target search key value and the split position set included in the target table entry pointed to by the primary index.

[0197] As described in step S134, the electronic device reads the target table entry corresponding to the main index in the main rule table, and can obtain the base address and split position set of the block rule table. The electronic device extracts the value of each bit indicated by the read target split position set from the target search key, and the extracted values ​​of each bit constitute a secondary index, which is the offset of the matched rule in the located block rule table. For the sake of distinction and understanding, the matched rule in the located block rule table is called the first rule, which does not serve as a limitation.

[0198] The execution order of step S134 and step S135 is not limited in the embodiment of the present application.

[0199] Step S136: Select a rule with the highest priority from the first rule and the second rule pointed to by the secondary index.

[0200] In the embodiment of the present application, after obtaining the first rule and the second rule, the electronic device selects a rule with the highest priority from the first rule and the second rule. The number of the first rule can be one or more.

[0201] In some embodiments, the above step S146 may be: based on the target search key value, respectively verify the first rule and the second rule pointed to by the secondary index; and select the rule with the highest priority from the rules that match the target search key value determined by the verification. The verification here may be an integrity check or a locality check, which is not limited.

[0202] In an embodiment of the present application, after the electronic device finds a rule that matches the target search key from the common rule table, the main rule table, the block rule table and the physical table, it verifies each rule found with the target search key respectively, ensuring that the rule and the target search key match, thereby improving the accuracy of packet classification processing for the classified data packets.

[0203] Step S137, classifying the data packets to be classified according to the selected rules.

[0204] For example, if the action of the selected rule is forwarding, the electronic device forwards the data packet to be classified; or, if the action of the selected rule is discarding, the electronic device discards the data packet to be classified; or, if the action of the selected rule is deep packet inspection, the electronic device performs deep packet inspection on the data packet to be classified, and based on the inspection result, processes the data packet to be classified, such as forwarding or discarding.

[0205] In the embodiment of the present application, a TCAM and a RAM are provided in the electronic device. The electronic device stores the common rules of multiple rules in the TCAM and stores the specific rules in the RAM, which can reduce the demand for the TCAM capacity. The electronic device uses the common rules stored in the TCAM with higher search performance to exclude most of the rules; and then uses the remaining rules after exclusion in the RAM to perform packet classification processing on the data packets to be classified. Compared with the packet classification method that purely uses TCAM, the technical solution provided in the embodiment of the present application combines TCAM and RAM to complete packet classification processing, and can use a smaller capacity TCAM to achieve larger-scale rule search, saving the cost and power consumption of packet classification.

[0206] Corresponding to the above rule storage method, the present application embodiment also provides a rule storage device, such as Fig.14 As shown, the device comprises:

[0207] A construction module 141 is used to construct a rule decision tree using the rules included in the global rule set, and obtain a discard rule set, wherein in the rule decision tree, the rules included in each subtree under a parent node have the same value at the bit indicated by the parent node and are not wildcards, and the rules included in the rule decision tree and the rules included in the discard rule set constitute a global rule set;

[0208] A first determining module 142 is used to determine a plurality of rule subtrees from the rule decision tree, wherein the height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the plurality of rule subtrees are the same as the rules included in the rule decision tree;

[0209] The adding module 143 is used to add some rules included in the discarding rule set to leaf nodes in the multiple rule subtrees that meet the backfilling condition, and the backfilling condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added;

[0210] A second determination module 144, configured to determine a common rule for each rule subtree;

[0211] The storage module 145 is used to store the common rules of each rule subtree and the remaining rules in the discard rule set in a ternary content addressable memory TCAM.

[0212] In some embodiments, the construction module 141 may be specifically used to:

[0213] The global rule set is used as the rule set to be split, the node in the rule decision tree that contains the rule set to be split is used as the target node, and the global rule set is included in the root node of the rule decision tree;

[0214] Determine the target bit for rule splitting in the rule set to be split, as the bit indicated by the target node;

[0215] Add the rule whose target bit value is 1 in the to-be-split rule set to the first side child node of the target node, add the rule whose target bit value is 0 in the to-be-split rule set to the second side child node of the target node, and add the rule whose target bit value is a wildcard in the to-be-split rule set to the discard rule set;

[0216] The rule set included in the child node whose number of rules is greater than or equal to the first preset number threshold is taken as the new rule set to be split, and the node containing the rule set to be split in the rule decision tree is taken as the new target node, and the step of determining the target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the target node until the number of rules included in the child node is less than the first preset number threshold.

[0217] In some embodiments, the target bit is the bit with the smallest number of rules whose values ​​are wildcards and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; or

[0218] The target bit is the bit with the smallest number of rules whose values ​​are wildcards and the largest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1.

[0219] In some embodiments, the construction module 141 may be specifically used to:

[0220] The global rule set is used as the rule set to be split, the node in the rule decision tree that contains the rule set to be split is used as the first target node, and the global rule set is contained in the root node of the rule decision tree;

[0221] Determine the first target bit for rule splitting in the rule set to be split, as the bit indicated by the first target node, the first target bit is the bit with the smallest number of rules with wildcard values ​​and the largest difference between the number of rules with 0 values ​​and the number of rules with 1 values;

[0222] Add the rule whose first target bit value is 1 in the rule set to be split to the first side child node of the first target node, add the rule whose first target bit value is 0 in the rule set to be split to the second side child node of the target node, and add the rule whose first target bit value is a wildcard in the rule set to be split to the discard rule set;

[0223] The rule set included in the child node whose number of rules is greater than or equal to the second preset number threshold is used as a new rule set to be split, and the node in the rule decision tree that includes the rule set to be split is used as a new first target node, and the step of determining the first target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the first target node until the number of rules included in the child node is less than the second preset number threshold;

[0224] The rule set included in the sub-node whose number of rules is less than the second preset number threshold is used as a new rule set to be split, and the node including the rule set to be split in the rule decision tree is used as the second target node;

[0225] Determine the second target bit for rule splitting in the rule set to be split, as the bit indicated by the second target node, the second target bit is the bit with the smallest number of rules whose values ​​are wildcards, and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1;

[0226] Add the rule whose second target bit value is 1 in the rule set to be split to the first side node of the second target node, add the rule whose second target bit value is 0 in the rule set to be split to the second side node of the target node, and add the rule whose second target bit value is a wildcard in the rule set to be split to the discard rule set;

[0227] The rule set included in the child node whose number of rules is greater than or equal to the third preset number threshold is taken as the new rule set to be split, and the node containing the rule set to be split in the rule decision tree is taken as the new second target node, and the step of determining the second target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the second target node until the number of rules included in the child node is less than the third preset number threshold.

[0228] In some embodiments, the first determining module 142 may be specifically configured to:

[0229] Starting from the root node of the rule decision tree, traverse the nodes downward;

[0230] If the height from the traversed node to the leaf node is greater than the preset height threshold, continue to perform the step of traversing the node downward until the height from the traversed node to the leaf node is less than or equal to the preset height threshold;

[0231] The subtree starting from the node reached at the end of the downward traversal is regarded as a regular subtree.

[0232] In some embodiments, the adding module 143 may be specifically used to:

[0233] For each rule subtree, determine the number of leaf nodes that meet the backfill condition and correspond to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule;

[0234] Determine the target rule with the smallest backfill cost and the target rule subtree with the smallest backfill cost corresponding to the target rule;

[0235] Add the target rule to the leaf nodes that meet the backfill condition in the target rule subtree;

[0236] Return to the step of executing, for each rule subtree, determining the number of leaf nodes that meet the backfill condition and correspond to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule.

[0237] In some embodiments, the backfill condition further includes: the number of rules included in the leaf node is less than or equal to a fourth preset number threshold; and / or,

[0238] After some rules included in the discard rule set are added to the multiple rule subtrees, the sum of the number of remaining rules and the number of the multiple rule subtrees is less than or equal to the capacity of the TCAM.

[0239] In some embodiments, the second determining module 144 may be specifically configured to:

[0240] If the value of a bit of all rules included in each rule subtree is 1, the value of the bit of the common rule of the rule subtree is set to 1;

[0241] If the values ​​of one bit of all rules included in each rule subtree are all 0, the value of this bit of the common rules of the rule subtree is set to 0;

[0242] If the values ​​of one bit of all class rules included in each rule subtree are not all 1, and / or the values ​​of one bit of all rules included in each rule subtree are not all 0, the value of the bit of the public rules of the rule subtree is set to a wildcard.

[0243] In some embodiments, the rule includes at least one matching field among a prefix class field, a range class field, an exact class field, and a wildcard class field; the rule storage device may further include a processing module for performing the following processing on each rule in the global rule set before constructing a rule decision tree using the rules included in the global rule set:

[0244] For the prefix class field included in the rule, the value of the highest bit of the prefix length is set to the prefix value, and the values ​​of the other bits are set to wildcards;

[0245] For the range type field included in the rule, the range type field is split into multiple sub-ranges, and the value of the bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range;

[0246] For the exact class fields included in the rule, set the value of each bit to the exact value;

[0247] For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.

[0248] In some embodiments, the storage module 145 may be specifically configured to store the common rules of each rule subtree in a common rule table in the TCAM, and store the remaining rules in the discard rule set in a physical table in the TCAM;

[0249] The storage module is further used to store the rules included in each rule subtree into a block rule table in the RAM; the RAM also stores a main rule table; the block rule table stores multiple rules with the same common rule; the main rule table includes at least two fields, a split position set and a base address; the rules in the block rule table belong to a subtree determined by the split position set; the split position set is used to locate the position of the rule corresponding to the key value in the block rule table; the base address is used to locate the block rule table; the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address; the common rule table and the main rule table have the same index corresponding to the same block rule table;

[0250] The rule storage device may further include:

[0251] An extraction module, used to extract target search key values ​​from the data packets to be classified;

[0252] A first matching module, used to match the target lookup key value in the physical table to obtain a second rule;

[0253] A second matching module, used to match the target lookup key value in the public rule table to obtain the primary index of the target table item in the main rule table;

[0254] A positioning module, used for locating the block rule table based on a base address included in a target table entry pointed to by a primary index;

[0255] A third determination module, configured to determine a secondary index of the first rule in the located block rule table based on a target search key value and a split position set included in a target table entry pointed to by a primary index;

[0256] The processing module is used to select a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; and perform packet classification processing on the data packet to be classified according to the selected rule.

[0257] In the technical solution provided by the embodiment of the present application, a rule decision tree is first constructed based on the condition that the rules included in each subtree under a parent node have the same value in the bit indicated by the parent node and are not wildcards. The rules included in different leaf nodes in the rule decision tree do not overlap, that is, there are no redundant rules in the rule decision tree; secondly, the rule decision tree is divided into multiple rule subtrees, and the partial rules included in the discard rule set are added to the leaf nodes that meet the backfill condition in the rule subtree in units of the rule subtree, instead of adding a copy of all the rules included in the discard rule set to each leaf node of the rule decision tree in units of the entire rule decision tree, thereby reducing the number of redundant rules and reducing the expansion of leaf nodes caused by rule duplication; thereafter, the common rules of each rule subtree and the remaining rules in the discard rule set are stored in the TCAM. Since the number of redundant rules in the rule subtree is reduced, the overhead of rule matching is reduced.

[0258] Corresponding to the above rule storage method, the embodiment of the present application also provides an electronic device, such as Fig.15 As shown, it includes a processor 151 and a machine-readable storage medium 152, wherein the machine-readable storage medium 152 stores machine-executable instructions that can be executed by the processor 151, and the processor 151 is prompted by the machine-executable instructions to implement any of the above-mentioned rule storage method steps.

[0259] In some embodiments, the electronic device may further include a forwarding chip;

[0260] The processor is also prompted by the machine executable instructions to: implement storing the common rules of each rule subtree in the common rule table in the TCAM, and storing the remaining rules in the discarded rule set in the physical table in the TCAM; storing the rules included in each rule subtree in the block rule table in the RAM; the RAM also stores a main rule table; the block rule table stores multiple rules with the same common rules; the main rule table includes at least two fields, a split position set and a base address, the rules in the block rule table belong to a subtree determined by the split position set, the split position set is used to locate the position of the rule corresponding to the key value in the block rule table, the base address is used to locate the block rule table, the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address, and the index corresponding to the same block rule table in the common rule table and the main rule table is the same;

[0261] A forwarding chip is used to extract a target search key value from a data packet to be classified when receiving the data packet to be classified; use the target search key value to match in a physical table to obtain a second rule; use the target search key value to match in a public rule table to obtain a primary index of a target table item in a main rule table; locate a block rule table based on a base address included in the target table item pointed to by the primary index; determine a secondary index of a first rule in the located block rule table based on a split position set included in the target table item pointed to by the target search key value and the primary index; select a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; and perform packet classification processing on the data packet to be classified according to the selected rule.

[0262] The machine-readable storage medium may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk storage. Optionally, the machine-readable storage medium may also be at least one storage device located away from the aforementioned processor.

[0263] The processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0264] In another embodiment provided in the present application, a machine-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, any of the above rule storage method steps is implemented.

[0265] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned rule storage method steps.

[0266] In the above embodiments, it 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. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, 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 may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0267] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0268] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, storage medium and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0269] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A rule storage method, characterized in that: The method comprises: Using the rules included in the global rule set, a rule decision tree is constructed, and a discard rule set is obtained, wherein in the rule decision tree, the rules included in each subtree under a parent node have the same value at the bit indicated by the parent node and are not wildcards, and the rules included in the rule decision tree and the rules included in the discard rule set constitute the global rule set; Determine a plurality of rule subtrees from the rule decision tree, wherein the height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the plurality of rule subtrees are the same as the rules included in the rule decision tree; Adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet a backfill condition, wherein the backfill condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added; Determine the common rules of each rule subtree; storing the common rules of each rule subtree and the remaining rules in the discard rule set in a ternary content addressable memory TCAM; The step of adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet the backfill condition includes: For each rule subtree, determine the number of leaf nodes that meet the backfill condition and correspond to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule; Determine a target rule with minimum backfill cost and a target rule subtree with minimum backfill cost corresponding to the target rule; Add the target rule to the leaf nodes in the target rule subtree that meet the backfill condition; Return to the step of executing, for each rule subtree, determining the number of leaf nodes satisfying the backfill condition corresponding to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule.

2. The method according to claim 1, characterized in that The step of using the rules included in the global rule set to construct a rule decision tree and obtain a discard rule set includes: Taking the global rule set as the rule set to be split, taking the node in the rule decision tree containing the rule set to be split as the target node, and the global rule set is contained in the root node of the rule decision tree; Determine a target bit for rule splitting in the rule set to be split, as the bit indicated by the target node; Add the rule whose target bit value is 1 in the to-be-split rule set to the first side child node of the target node, add the rule whose target bit value is 0 in the to-be-split rule set to the second side child node of the target node, and add the rule whose target bit value is a wildcard in the to-be-split rule set to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the first preset number threshold is taken as a new rule set to be split, and the node in the rule decision tree that contains the rule set to be split is taken as a new target node, and the step of determining the target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the target node until the number of rules included in the child node is less than the first preset number threshold.

3. The method according to claim 2, characterized in that The target bit is the bit with the smallest number of rules whose values ​​are wildcards and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; or The target bit is the bit with the smallest number of rules whose values ​​are wildcards and the largest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1.

4. The method according to claim 1, characterized in that: The step of using the rules included in the global rule set to construct a rule decision tree and obtain a discard rule set includes: Taking the global rule set as the rule set to be split, taking the node in the rule decision tree containing the rule set to be split as the first target node, and the global rule set is contained in the root node of the rule decision tree; Determine a first target bit for rule splitting in the set of rules to be split, as the bit indicated by the first target node, the first target bit being the bit with the smallest number of rules whose values ​​are wildcards and the largest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; Add the rule whose first target bit value is 1 in the rule set to be split to the first side child node of the first target node, add the rule whose first target bit value is 0 in the rule set to be split to the second side child node of the target node, and add the rule whose first target bit value is a wildcard in the rule set to be split to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the second preset number threshold is used as a new rule set to be split, and the node in the rule decision tree containing the rule set to be split is used as a new first target node, and the step of determining the first target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the first target node, until the number of rules included in the child node is less than the second preset number threshold; Taking the rule set included in the child node whose number of rules is less than the second preset number threshold as a new rule set to be split, and taking the node including the rule set to be split in the rule decision tree as the second target node; Determine a second target bit for rule splitting in the rule set to be split, as the bit indicated by the second target node, the second target bit being the bit with the smallest number of rules whose values ​​are wildcards and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; Add the rule whose second target bit value is 1 in the rule set to be split to the first side node of the second target node, add the rule whose second target bit value is 0 in the rule set to be split to the second side node of the target node, and add the rule whose second target bit value is a wildcard in the rule set to be split to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the third preset number threshold is taken as a new rule set to be split, and the node containing the rule set to be split in the rule decision tree is taken as a new second target node, and the step of determining the second target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the second target node until the number of rules included in the child node is less than the third preset number threshold.

5. The method according to claim 1, characterized in that The step of determining a plurality of rule subtrees from the rule decision tree comprises: Starting from the root node of the rule decision tree, traverse the nodes downward; If the height from the traversed node to the leaf node is greater than the preset height threshold, continue to execute the step of traversing the nodes downward until the height from the traversed node to the leaf node is less than or equal to the preset height threshold; The subtree starting from the node reached at the end of the downward traversal is regarded as a regular subtree.

6. The method according to claim 1, characterized in that The backfill condition also includes: the number of rules included in the leaf node is less than or equal to a fourth preset number threshold; and / or, After some rules included in the discard rule set are added to the multiple rule subtrees, the sum of the number of remaining rules and the number of the multiple rule subtrees is less than or equal to the capacity of the TCAM.

7. The method according to claim 1, characterized in that The step of determining the common rules of each rule subtree comprises: If the value of a bit of all rules included in each rule subtree is 1, the value of the bit of the common rule of the rule subtree is set to 1; If the values ​​of one bit of all rules included in each rule subtree are all 0, the value of this bit of the common rules of the rule subtree is set to 0; If the values ​​of one bit of all class rules included in each rule subtree are not all 1, and / or the values ​​of one bit of all rules included in each rule subtree are not all 0, the value of the bit of the public rules of the rule subtree is set to a wildcard.

8. The method according to any one of claims 1 to 7, characterized in that The rule includes at least one matching field among a prefix class field, a range class field, an exact class field, and a wildcard class field; Before constructing a rule decision tree using the rules included in the global rule set, the method further includes: The following processing is performed on each rule in the global rule set: For the prefix class field included in the rule, the value of the highest bit of the prefix length is set to the prefix value, and the values ​​of the other bits are set to wildcards; For the range type field included in the rule, the range type field is split into multiple sub-ranges, and the value of the bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range; For the exact class fields included in the rule, set the value of each bit to the exact value; For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.

9. The method according to any one of claims 1 to 7, characterized in that: The step of storing the common rules of each rule subtree and the remaining rules in the discard rule set in a ternary content addressable memory TCAM comprises: storing the common rules of each rule subtree in a common rule table in the ternary content addressable memory TCAM, and storing the remaining rules in the discard rule set in a physical table in the TCAM; The method further comprises: The rules included in each rule subtree are stored in a block rule table in a random access memory RAM; the RAM also stores a main rule table; the block rule table stores a plurality of rules having the same common rule; the main rule table includes at least two fields, a split position set and a base address; the rules in the block rule table belong to a subtree determined by the split position set; the split position set is used to locate the position of the rule corresponding to the key value in the block rule table; the base address is used to locate the block rule table; the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address; the common rule table and the main rule table have the same index corresponding to the same block rule table; When receiving a data packet to be classified, extracting a target search key value from the data packet to be classified; Use the target search key value to perform matching in the physical table to obtain a second rule; Use the target search key value to perform a match in the common rule table to obtain a primary index of the target entry in the main rule table; Locate the block rule table based on the base address included in the target table entry pointed to by the primary index; Determine a secondary index of a first rule in the located block rule table based on the target search key value and a split position set included in the target table entry pointed to by the primary index; Selecting a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; According to the selected rule, the data packet to be classified is subjected to packet classification processing.

10. A rule storage device, characterized in that: The device comprises: A construction module, used to construct a rule decision tree using the rules included in the global rule set, and obtain a discard rule set, wherein in the rule decision tree, the rules included in each subtree under a parent node have the same value at the bit indicated by the parent node and are not wildcards, and the rules included in the rule decision tree and the rules included in the discard rule set constitute the global rule set; A first determining module is used to determine a plurality of rule subtrees from the rule decision tree, wherein the height of the rule subtree is less than or equal to a preset height threshold, and the rules included in the plurality of rule subtrees are the same as the rules included in the rule decision tree; An adding module, used for adding some rules included in the discard rule set to leaf nodes in the multiple rule subtrees that meet a backfill condition, wherein the backfill condition includes: the value of the bit indicated by the path node of the added rule is a wildcard, or the value of the bit indicated by the path node of the added rule is the same as that of other rules in the leaf node to which the rule is added, and the path node is a node between the root node of the rule decision tree and the leaf node to which the rule is added; A second determination module, used to determine the common rules of each rule subtree; A storage module, used for storing the common rules of each rule subtree and the remaining rules in the discard rule set in a ternary content addressable memory TCAM; Wherein, the adding module is specifically used for: For each rule subtree, determine the number of leaf nodes that meet the backfill condition and correspond to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule; Determine a target rule with minimum backfill cost and a target rule subtree with minimum backfill cost corresponding to the target rule; Add the target rule to the leaf nodes in the target rule subtree that meet the backfill condition; Return to the step of executing, for each rule subtree, determining the number of leaf nodes satisfying the backfill condition corresponding to each rule included in the discard rule set in the rule subtree as the backfill cost corresponding to each rule.

11. The device according to claim 10, characterized in that The building blocks are specifically used for: Taking the global rule set as the rule set to be split, taking the node in the rule decision tree containing the rule set to be split as the target node, and the global rule set is contained in the root node of the rule decision tree; Determine a target bit for rule splitting in the rule set to be split, as the bit indicated by the target node; Add the rule whose target bit value is 1 in the to-be-split rule set to the first side child node of the target node, add the rule whose target bit value is 0 in the to-be-split rule set to the second side child node of the target node, and add the rule whose target bit value is a wildcard in the to-be-split rule set to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the first preset number threshold is taken as a new rule set to be split, and the node in the rule decision tree that contains the rule set to be split is taken as a new target node, and the step of determining the target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the target node until the number of rules included in the child node is less than the first preset number threshold.

12. The device according to claim 11, characterized in that The target bit is the bit with the smallest number of rules whose values ​​are wildcards and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; or The target bit is the bit with the smallest number of rules whose values ​​are wildcards and the largest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1.

13. The device according to claim 10, characterized in that The building blocks are specifically used for: Taking the global rule set as the rule set to be split, taking the node in the rule decision tree containing the rule set to be split as the first target node, and the global rule set is contained in the root node of the rule decision tree; Determine a first target bit for rule splitting in the set of rules to be split, as the bit indicated by the first target node, the first target bit being the bit with the smallest number of rules whose values ​​are wildcards and the largest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; Add the rule whose first target bit value is 1 in the rule set to be split to the first side child node of the first target node, add the rule whose first target bit value is 0 in the rule set to be split to the second side child node of the target node, and add the rule whose first target bit value is a wildcard in the rule set to be split to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the second preset number threshold is used as a new rule set to be split, and the node in the rule decision tree containing the rule set to be split is used as a new first target node, and the step of determining the first target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the first target node, until the number of rules included in the child node is less than the second preset number threshold; Taking the rule set included in the child node whose number of rules is less than the second preset number threshold as a new rule set to be split, and taking the node including the rule set to be split in the rule decision tree as the second target node; Determine a second target bit for rule splitting in the rule set to be split, as the bit indicated by the second target node, the second target bit being the bit with the smallest number of rules whose values ​​are wildcards and the smallest difference between the number of rules whose values ​​are 0 and the number of rules whose values ​​are 1; Add the rule whose second target bit value is 1 in the rule set to be split to the first side node of the second target node, add the rule whose second target bit value is 0 in the rule set to be split to the second side node of the target node, and add the rule whose second target bit value is a wildcard in the rule set to be split to the discard rule set; The rule set included in the child node whose number of rules is greater than or equal to the third preset number threshold is taken as a new rule set to be split, and the node containing the rule set to be split in the rule decision tree is taken as a new second target node, and the step of determining the second target bit for rule splitting in the rule set to be split is re-executed as the bit indicated by the second target node until the number of rules included in the child node is less than the third preset number threshold.

14. The device according to claim 10, characterized in that The first determining module is specifically configured to: Starting from the root node of the rule decision tree, traverse the nodes downward; If the height from the traversed node to the leaf node is greater than the preset height threshold, continue to execute the step of traversing the nodes downward until the height from the traversed node to the leaf node is less than or equal to the preset height threshold; The subtree starting from the node reached at the end of the downward traversal is regarded as a regular subtree.

15. The device according to claim 11, characterized in that The backfill condition also includes: the number of rules included in the leaf node is less than or equal to a fourth preset number threshold; and / or, After some rules included in the discard rule set are added to the multiple rule subtrees, the sum of the number of remaining rules and the number of the multiple rule subtrees is less than or equal to the capacity of the TCAM.

16. The device according to claim 10, characterized in that The second determining module is specifically used to: If the value of a bit of all rules included in each rule subtree is 1, the value of the bit of the common rule of the rule subtree is set to 1; If the values ​​of one bit of all rules included in each rule subtree are all 0, then the value of this bit of the common rules of the rule subtree is set to 0; If the values ​​of one bit of all class rules included in each rule subtree are not all 1, and / or the values ​​of one bit of all rules included in each rule subtree are not all 0, the value of the bit of the public rules of the rule subtree is set to a wildcard.

17. The device according to any one of claims 10 to 16, characterized in that The rule includes at least one matching field among a prefix class field, a range class field, an exact class field, and a wildcard class field; the device also includes a processing module, which is used to perform the following processing on each rule in the global rule set before constructing a rule decision tree using the rules included in the global rule set: For the prefix class field included in the rule, the value of the highest bit of the prefix length is set to the prefix value, and the values ​​of the other bits are set to wildcards; For the range type field included in the rule, the range type field is split into multiple sub-ranges, and the value of the bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range; For the exact class fields included in the rule, set the value of each bit to the exact value; For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.

18. The device according to any one of claims 10 to 16, characterized in that The storage module is specifically used to store the common rules of each rule subtree in a common rule table in a ternary content addressable memory TCAM, and store the remaining rules in the discard rule set in a physical table in the TCAM; The storage module is further used to store the rules included in each rule subtree into a block rule table in a random access memory RAM; The RAM also stores a main rule table; the block rule table stores a plurality of rules having the same common rule; the main rule table includes at least two fields, a split position set and a base address; the rules in the block rule table belong to a subtree determined by the split position set; the split position set is used to locate the position of the rule corresponding to the key value in the block rule table; the base address is used to locate the block rule table; the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address; the common rule table and the main rule table have the same index corresponding to the same block rule table; The device also includes: An extraction module, used to extract target search key values ​​from the data packets to be classified; A first matching module, configured to use the target search key value to perform matching in the physical table to obtain a second rule; A second matching module, configured to use the target search key value to perform matching in the common rule table to obtain a primary index of the target entry in the main rule table; A positioning module, used for locating the block rule table based on the base address included in the target table entry pointed to by the primary index; a third determination module, configured to determine a secondary index of the first rule in the located block rule table based on the target search key value and a split position set included in the target table entry pointed to by the primary index; The processing module is used to select a rule with the highest priority from the first rule pointed to by the secondary index and the second rule; and perform packet classification processing on the data packet to be classified according to the selected rule.

19. An electronic device, characterized in that: The method comprises a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to implement the method steps described in any one of claims 1 to 8.

20. The electronic device according to claim 19, characterized in that: The electronic device further comprises a forwarding chip; The processor is further prompted by the machine executable instructions to: implement storing the common rules of each rule subtree in a common rule table in a ternary content addressable memory TCAM, and storing the remaining rules in the discard rule set in a physical table in the TCAM; Storing the rules included in each rule subtree into a block rule table in a random access memory RAM; The RAM also stores a main rule table; The block rule table stores a plurality of rules having the same common rule; the main rule table includes at least two fields, a split position set and a base address; the rules in the block rule table belong to a subtree determined by the split position set; the split position set is used to locate the position of the rule corresponding to the key value in the block rule table; the base address is used to locate the block rule table; the value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address; the common rule table and the main rule table have the same index corresponding to the same block rule table; The forwarding chip is used to extract the target search key value from the data packet to be classified when receiving the data packet to be classified; Use the target search key value to match in the physical table to obtain a second rule; use the target search key value to match in the public rule table to obtain a primary index of the target table entry in the main rule table; Based on the base address included in the target table entry pointed to by the main index, the block rule table is located; based on the target search key value and the split position set included in the target table entry pointed to by the main index, the secondary index of the first rule in the located block rule table is determined; from the first rule and the second rule pointed to by the secondary index, the rule with the highest priority is selected; and according to the selected rule, the packet to be classified is subjected to packet classification processing.

21. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 8 are implemented.