A method, device, electronic device and storage medium for expanding scope in a rule
By determining and splitting LCPs in rules in electronic devices, rule expansion is reduced, and multiple ranges of public information are used for expansion, solving the problems of rule expansion and high TCAM costs, improving search performance and saving TCAM resources.
Patent Information
- Application Number
- CN202211337643.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2042-10-28
AI Technical Summary
In electronic devices such as switches and routers, equivalent expansion of range fields in rules leads to rule expansion, affects search performance, and causes high TCAM storage costs and power consumption.
By determining the LCP for each range of matching fields, and splitting and adjusting based on the LCP, rule bloat is reduced, expanded using common information from multiple ranges, and stored in a smaller TCAM capacity.
It improves the search performance of packet classification, reduces the usage of TCAM, and saves cost and power consumption.
Smart Images

Figure CN115913963B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for expanding the scope of a rule. Background Art
[0002] In electronic devices with packet classification functions such as switches, routers, and firewalls, data packets need to be classified and forwarded through table entry lookup. Packet classification is a method of finding the best matching rule in a rule set for each arriving data packet based on a predefined rule set. Among them, a rule set is composed of multiple rules, and the rules are composed of matching fields described by expressions such as prefixes, ranges, exact values, and wildcards. The range implementation of the range class field in the rule is relatively complex and requires equivalent expansion, which will cause the expansion of the rules and affect the search performance. In addition, storing the rule set in TCAM (Ternary Content Addressable Memory) and matching rules based on content can improve the efficiency of rule matching, but TCAM has a high cost and consumes a lot of power. The expansion of rules requires a larger capacity TCAM, and the cost and power consumption will increase accordingly. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a method, device, electronic device and storage medium for expanding the scope in a rule, so as to reduce the rule expansion coefficient caused by the scope expansion, improve the search performance and save the cost and power consumption of TCAM.
[0004] The specific technical solutions are as follows:
[0005] In a first aspect of an embodiment of the present application, a method for expanding a scope in a rule is provided, the method comprising:
[0006] When all rules in the rule set do not overlap in the range of the specified matching field, determine the LCP (Longest Common Prefix) of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field;
[0007] Detecting whether there is an intersection between the ranges indicated by the at least one LCP obtained;
[0008] If there is an intersection, determining a target LCP in the at least one determined LCP, wherein the range indicated by the target LCP includes the range indicated by the other LCPs;
[0009] Based on the highest wildcard bit in the target LCP, the target LCP is split into two LCPs, and based on the multiple LCPs obtained after the splitting, the step of detecting whether there is an intersection in the range indicated by the at least one LCP obtained is re-executed; the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP;
[0010] If there is no intersection, the minimum value of the range indicated by the at least one LCP obtained is adjusted to the minimum value of the range of the specified matching field, and the maximum value of the range indicated by the at least one LCP obtained is adjusted to the maximum value of the range of the specified matching field.
[0011] In some embodiments, the method further comprises:
[0012] When all the rules in the rule set intersect within the range of the specified matching field, determining the balance bit of each rule in the rule set, wherein the balance bit is the bit with the smallest difference between the number of rules with a value of 0 and the number of rules with a value of 1;
[0013] The rules whose balance bit value is 0 are divided into one rule set, and the rules whose balance bit value is 1 are divided into another rule set;
[0014] For each rule set obtained by splitting, if all the rules in the rule set intersect within the scope of the specified matching field, the step of determining the balance bit of each rule in the rule set is re-executed until all the rules in the rule set obtained by splitting do not intersect within the scope of the specified matching field.
[0015] 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;
[0016] Before determining the balance position of each rule in the rule set, the method further includes:
[0017] The following processing is performed on each rule in the rule set:
[0018] 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;
[0019] For the range-type fields included in this rule, set the value of each bit to a wildcard character;
[0020] For the exact class fields included in the rule, set the value of each bit to the exact value;
[0021] For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.
[0022] In some embodiments, the step of determining the LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field includes:
[0023] For each range of the specified matching field, determine the highest bit with different values in the maximum value and the minimum value of the range; set the value of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range as wildcards to obtain the LCP of the range.
[0024] In some embodiments, the step of splitting the target LCP into two LCPs based on the highest wildcard bit in the target LCP includes:
[0025] The value of the highest wildcard bit in the target LCP is set to 0, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 1, to obtain a splitting maximum value;
[0026] The value of the highest wildcard bit in the target LCP is set to 1, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 0, so as to obtain a minimum split value;
[0027] A new LCP is generated based on the minimum value of the range determining the target LCP and the split maximum value, and another new LCP is generated based on the maximum value of the range determining the target LCP and the split minimum value.
[0028] In some embodiments, the method further comprises:
[0029] After the range is expanded, based on the LCP corresponding to each expanded range, the rules whose designated matching fields are the expanded multiple ranges are end-split and added to the decision tree, where one leaf node of the decision tree includes one rule.
[0030] In some embodiments, the step of performing end splitting on the multiple ranges obtained by the expansion based on the LCP corresponding to each range obtained by the expansion and adding the multiple ranges to the decision tree includes:
[0031] Starting from the highest bit with different values in the LCP corresponding to each range obtained by expansion, traverse each bit and add the rules of the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value.
[0032] In some embodiments, after the scope expansion is completed, the method further includes:
[0033] The rules corresponding to each range obtained by expansion are stored in a block rule table in a RAM (Dynamic Random Access Memory), wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, wherein 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, and 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 is stored in the common rule table in the TCAM, and the common rule table has the same index as the main rule table corresponding to the same block rule table;
[0034] When receiving a data packet to be classified, extracting a target search key value from the data packet to be classified;
[0035] 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;
[0036] Locate the block rule table based on the base address included in the target table entry pointed to by the primary index;
[0037] Determine a secondary index of a target 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;
[0038] Based on the target rule pointed to by the secondary index, packet classification processing is performed on the data packet to be classified.
[0039] In a second aspect of an embodiment of the present application, a scope expansion device in a rule is provided, the device comprising:
[0040] A first determination module, configured to determine the LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field when all rules in the rule set do not overlap in the range of the specified matching field;
[0041] A detection module, used to detect whether there is an intersection between the ranges indicated by the at least one LCP obtained;
[0042] A second determination module is configured to determine a target LCP from the at least one determined LCP if the detection result of the detection module is yes, wherein the range indicated by the target LCP includes the range indicated by other LCPs;
[0043] a splitting module, configured to split the target LCP into two LCPs based on the highest wildcard bit in the target LCP, and re-trigger the detection module to detect whether there is an intersection in the range indicated by at least one LCP obtained based on the multiple LCPs obtained after the splitting; the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP;
[0044] An adjustment module is used to adjust the minimum value of the range indicated by at least one LCP obtained to the minimum value of the range of the specified matching field, and to adjust the maximum value of the range indicated by at least one LCP obtained to the maximum value of the range of the specified matching field when the detection result of the detection module is yes.
[0045] In some embodiments, the apparatus further comprises:
[0046] A third determination module is used to determine a balance bit of each rule in the rule set when all rules in the rule set intersect within the range of the specified matching field, wherein the balance bit is a bit in which 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;
[0047] A partitioning module, used for partitioning the rules whose balance bit value is 0 into one rule set, and partitioning the rules whose balance bit value is 1 into another rule set;
[0048] The third determination module is also used to, for each rule set obtained by splitting, if all the rules in the rule set intersect within the range of the specified matching field, re-execute the step of determining the balance bit of each rule in the rule set until all the rules in the rule set obtained by splitting do not intersect within the range of the specified matching field.
[0049] 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;
[0050] The apparatus further includes: a first processing module, configured to perform the following processing on each rule in the rule set before determining the balance position of each rule in the rule set:
[0051] 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;
[0052] For the range-type fields included in this rule, set the value of each bit to a wildcard character;
[0053] For the exact class fields included in the rule, set the value of each bit to the exact value;
[0054] For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.
[0055] In some embodiments, the first determining module is specifically configured to:
[0056] For each range of the specified matching field, determine the highest bit with different values in the maximum value and the minimum value of the range; set the value of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range as wildcards to obtain the LCP of the range.
[0057] In some embodiments, the splitting module is specifically used to:
[0058] The value of the highest wildcard bit in the target LCP is set to 0, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 1, to obtain a splitting maximum value;
[0059] The value of the highest wildcard bit in the target LCP is set to 1, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 0, so as to obtain a minimum split value;
[0060] A new LCP is generated based on the minimum value of the range determining the target LCP and the split maximum value, and another new LCP is generated based on the maximum value of the range determining the target LCP and the split minimum value.
[0061] In some embodiments, the apparatus further comprises:
[0062] The adding module is used to perform end splitting on the rules whose designated matching fields are multiple ranges obtained by expansion based on the LCP corresponding to each range obtained by expansion after the range expansion is completed, and add them to the decision tree, wherein a leaf node of the decision tree includes a rule.
[0063] In some embodiments, the adding module is specifically used to:
[0064] Starting from the highest bit with different values in the LCP corresponding to each range obtained by expansion, traverse each bit and add the rules of the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value.
[0065] In some embodiments, the apparatus further comprises:
[0066] A storage module is used to store the rules corresponding to each range obtained by expansion into a block rule table in a RAM after the range expansion is completed, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, wherein 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 is stored in the common rule table in the TCAM, and the common rule table has the same index as the main rule table corresponding to the same block rule table;
[0067] An extraction module, used for extracting a target search key value from the data packet to be classified when receiving the data packet to be classified;
[0068] A matching module, configured to use the target search key value to perform a match in the common rule table to obtain a primary index of a target entry in the main rule table;
[0069] 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;
[0070] a third determination module, configured to determine a secondary index of a target 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;
[0071] The second processing module is used to perform packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
[0072] In a third aspect of an embodiment of the present application, an electronic device is provided, 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 the scope expansion method steps in any of the above-mentioned rules.
[0073] In some embodiments, the electronic device further comprises a forwarding chip;
[0074] The processor is further prompted by the machine executable instructions to: implement storing the rules corresponding to each range obtained by expansion into a block rule table in the RAM, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; 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 rules are stored in the common rule table in the TCAM, and the common rule table and the main rule table have the same index corresponding to the same block rule table;
[0075] The forwarding chip is used to extract a 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 the public rule table to obtain the 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 target 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; and perform packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
[0076] In a fourth aspect of an embodiment of the present application, a machine-readable storage medium is provided, 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 scope expansion method steps in any of the above-mentioned rules.
[0077] In the technical solution provided by the embodiment of the present application, the LCP of each range of the specified matching field is used to expand multiple ranges at the same time, and the common information of multiple ranges can be effectively utilized. Compared with the related art, only each range is considered separately and a range is equivalently expanded into multiple ranges. In the technical solution provided by the embodiment of the present application, the common information of multiple ranges is fully utilized, and multiple ranges are expanded at the same time, which can reduce the rule expansion coefficient caused by range expansion, thereby improving the search performance. In addition, since the rule expansion coefficient caused by range expansion is reduced, the technical solution provided by the embodiment of the present application can use a smaller TCAM capacity, realize larger-scale rule search, and save TCAM cost and power consumption.
[0078] 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
[0079] 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.
[0080] Figure 1 A first flow chart of a method for expanding a scope in a rule provided in an embodiment of the present application;
[0081] Figure 2 A schematic diagram of the scope expansion provided by the embodiment of the present application;
[0082] Figure 3 A partial flow chart of a method for expanding a scope in a rule provided in an embodiment of the present application;
[0083] Figure 4 A schematic diagram of a rule set provided in an embodiment of the present application;
[0084] Figure 5 A first schematic diagram of a decision tree provided in an embodiment of the present application;
[0085] Figure 6 A detailed schematic diagram of step S11 provided in an embodiment of the present application;
[0086] Figure 7 A schematic diagram of LCP extraction provided in an embodiment of the present application;
[0087] Figure 8 A schematic diagram of step S14 provided in an embodiment of the present application;
[0088] Fig. 9 A schematic diagram of LCP splitting provided in an embodiment of the present application;
[0089] Fig.10 A second flow chart of the scope expansion method in the rule provided in the embodiment of the present application;
[0090] Fig.11 A schematic diagram of terminal splitting provided in an embodiment of the present application;
[0091] Fig.12 A second schematic diagram of a decision tree provided in an embodiment of the present application;
[0092] Fig.13 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;
[0093] Fig.14 A schematic diagram of a flow chart of a packet classification method provided in an embodiment of the present application;
[0094] Fig.15 A schematic diagram of a first structure of a range expansion device in a rule provided in an embodiment of the present application;
[0095] Fig.16 A second structural schematic diagram of a range expansion device in a rule provided in an embodiment of the present application;
[0096] Fig.17 A schematic diagram of a first structure of an electronic device provided in an embodiment of the present application;
[0097] Fig.18 A second structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0098] 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.
[0099] The following is an explanation of the terms that appear in the embodiments of the present application.
[0100] 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.
[0101] Matching field: The field that matches the search key. Electronic devices can classify matching fields according to the objects they target, such as the destination IP field, the source IP field, the destination port field, or the 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 the prefix value, and the prefix field can also be called a prefix domain; the type of value stored in the precise field is the precise value, and the precise field can also be called a precise domain; the type of value stored in the range field is the range, and the range field can also be called a range domain; the type of value stored in the wildcard field is the wildcard (*), and the wildcard field can also be called a wildcard domain.
[0102] 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.
[0103] In electronic devices with packet classification functions such as switches, routers, and firewalls, it is necessary to classify and forward messages through table search. Traditional table search methods such as linear search and hash table search convert the key (key value) into an address and index the content in SRAM (Static Random-Access Memory) or DRAM (Dynamic Random Access Memory) to complete the search. The key value is the value of the keyword composed of the value of the matching field.
[0104] The table entry search for MAC (Media Access Control) address table is generally implemented using the above-mentioned table entry search method based on address index. However, for table entries such as ACL (Access Control Lists), flow tables, forwarding tables, and routing tables, their rules specify that certain fields are not of concern. The key needs to be compared with the rules one by one to filter out the rule that fully matches the concerned fields and has the highest priority. The table entry search method based on the above-mentioned address index obviously cannot meet the matching requirements of such rules, so a more complex packet classification method is introduced.
[0105] Packet classification is a method of finding the best matching rule in a predefined rule set for each arriving data packet. A rule set is composed of multiple rules, and each rule is composed of fields described by different expressions. The expressions can be prefix values, ranges, exact values, and wildcards.
[0106] In the rules, the values of prefix fields, exact fields, and wildcard fields can be directly converted into key and mask forms, which can be directly processed by TCAM or software algorithms. The key 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. However, the range implementation of range fields is more complicated and requires equivalent expansion or separate encoding processing, which will cause the expansion of rules and affect the search performance.
[0107] For example, when performing equivalent expansion on the range of a range-type field, the range needs to be divided into several continuous and uninterrupted sub-ranges, so that 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. In this way, each sub-range can independently constitute a rule that is completely represented by key and mask and directly stored in TCAM. 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.
[0108] For a range class field with a bit width of W, at most 2W-2 coded prefix values are required for equivalent representation. The number of prefix values is called the expansion factor. If there are multiple range class fields in the rule, the total expansion factor needs to be equal to the product of the expansion factors of all range class fields. If two 16-bit range class fields are considered, the expansion factor may reach (2*16-2)*(2*16-2)=900.
[0109] Using TCAM to store rule sets and matching rules based on content can improve rule matching efficiency. However, TCAM is expensive and consumes a lot of power. When the rules expand, a larger TCAM capacity is required to store the expanded rules, and the cost and power consumption will increase accordingly. Therefore, it is necessary to reduce the expansion coefficient caused by the range expansion of the range class field as much as possible.
[0110] In order to reduce the rule expansion coefficient caused by scope expansion, improve search performance, and save TCAM cost and power consumption, the present application provides a scope expansion method in a rule. The method can be applied to electronic devices with packet classification functions such as switches, routers, and firewalls. For ease of description, the following description is based on electronic devices as the execution subject, which does not serve as a limitation.
[0111] 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 .
[0112] Table 1
[0113]
[0114]
[0115] In Table 1, 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.
[0116] In the embodiment of the present application, before executing the scope expansion method provided in the embodiment of the present application, the electronic device may perform the following processing on each rule in the rule set:
[0117] 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 1, 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 2. 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.********.
[0118] Table 2
[0119] rule Source IP Destination IP Source Port Destination Port Transport Protocol action <![CDATA[R2]]> 10.0.3.* * 80 0~1024 TCP reject
[0120] For the range class field included in the rule, the value of each bit in the range class field is set to *. For example, in the rule R2 shown in Table 2, the destination port field is a range class field, and the value of each bit in the destination port field is set to *. At this time, the rule R2 is as shown in Table 3.
[0121] Table 3
[0122] rule Source IP Destination IP Source Port Destination Port Transport Protocol action <![CDATA[R2]]> 10.0.3.* * 80 * TCP reject
[0123] 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.
[0124] 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 *.
[0125] In the 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.
[0126] In the embodiment of the present application, to facilitate TCAM storage, the electronic device may convert the rules into the form of key and mask, and use the key and mask to represent the rules.
[0127] For example, the electronic device may convert the rule into the form of key and mask according to the following conversion method:
[0128] For prefix fields, 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 0x0A010000 in hexadecimal, and the mask is 0xFFFF0000 in hexadecimal. For range fields, the key and mask are all 0. For exact fields, the key is the exact value, and the mask is all 1. For wildcard fields, the key and mask are all 0.
[0129] For the value of any bit I of rule R, the relationship between key and mask is as follows:
[0130] R[I]=0, means mask[I]=1, key[I]=0;
[0131] R[I]=1, means mask[I]=1, key[I]=1;
[0132] R[I]=* means mask[I]=0, key[I]=0 or key[I]=1.
[0133] In the range expansion method provided in the embodiment of the present application, the electronic device uses the LCP of each range of the specified matching field based on the above rules to expand multiple ranges at the same time, which can effectively utilize the common information of multiple ranges. Compared with the related art, only each range is considered separately and a range is equivalently expanded into multiple ranges. In the technical solution provided in the embodiment of the present application, the electronic device makes full use of the common information of multiple ranges and expands multiple ranges at the same time, which can reduce the rule expansion coefficient caused by range expansion, thereby improving the search performance. In addition, since the rule expansion coefficient caused by range expansion is reduced, the technical solution provided in the embodiment of the present application can use a smaller TCAM capacity to achieve larger-scale rule search, saving TCAM cost and power consumption.
[0134] The following is a detailed introduction to the range field expansion method provided in the embodiment of the present application with a specific example.
[0135] See also Figure 1 , Figure 1 A first flow chart of a range class field expansion method provided in an embodiment of the present application, the method comprising the following steps:
[0136] Step S11 : when all rules in the rule set do not overlap in the range of the specified matching field, determine the LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field.
[0137] In an embodiment of the present application, the designated match field may be a match field for any object. For ease of understanding, the match field for an object will be referred to as the match field below. In an embodiment of the present application, the electronic device may use each match field as a designated match field; in order to improve the efficiency of range expansion and thereby improve the search performance of the electronic device, the electronic device may also use the match field that has a range class field in multiple rules in the rule set as a designated match field. As shown in Table 1 above, the source port field of rule R3 is a range class field, and the electronic device may use the source port field as a designated match field.
[0138] A rule set includes multiple rules. A rule may contain one or more range-type fields or may not contain any range-type fields. For a specified matching field, the electronic device detects whether all rules in the rule set have an intersection in the range of the specified matching field. For non-range-type fields, when considering whether the ranges have an intersection, the non-range-type fields may be converted into range form.
[0139] For example, for an exact field, the electronic device may convert the exact value of the exact field into a field from the exact value to the exact value. For example, if the exact value of the exact field is 80, the electronic device may convert 80 into a range of [80,80].
[0140] For the prefix class field, the electronic device may set the value of the *bit in the prefix value of the prefix class field to 0 to obtain the minimum value of the range corresponding to the prefix class field, and set the value of the *bit in the prefix value of the prefix class field to 1 to obtain the maximum value of the range corresponding to the prefix class field; if the prefix value of the prefix class field is 01**, the minimum value of the range corresponding to 01** is 0100, that is, 4, and the maximum value of the range corresponding to 01** is 0111, that is, 7, that is, the electronic device can convert 01** into the range [4,7];
[0141] For a wildcard class field, the electronic device may set all bits of the wildcard class field to 0 to obtain the minimum value of the range corresponding to the wildcard class field, and set all bits of the wildcard class field to 1 to obtain the maximum value of the range corresponding to the wildcard class field. For example, if the wildcard class field includes 4 bits, all bits of the wildcard class field are set to 0 to obtain 0000, that is, 0, and all bits of the wildcard class field are set to 1 to obtain 1111, that is, 15. In other words, the electronic device can convert the wildcard class field **** into the range [0,15].
[0142] For a rule set, if two rules in the rule set intersect in the range of a specified matching field, the electronic device can determine that all rules in the rule set intersect in the range of a specified matching field; if any two rules in the rule set do not intersect in the range of a specified matching field, the electronic device can determine that all rules in the rule set do not intersect in the range of a specified matching field. When all rules in the rule set do not intersect in the range of a specified matching field, for each range of the specified matching field, the electronic device determines the LCP of the range based on the maximum and minimum values of the range. The specific method for determining the LCP will be described in detail later and will not be elaborated here.
[0143] Step S12, detecting whether there is any intersection in the range indicated by the at least one LCP obtained. If there is any intersection, executing step S13; if there is no intersection, executing step S15.
[0144] In the embodiment of the present application, LCP (Longest Common Prefix) is a binary value represented by 0, 1 and *, where the bit of * can be 0 or 1. In this case, LCP can indicate a range. For example, when the LCP is 000001**********, when the bit of * of the LCP is all 0, the minimum value of the range indicated by the LCP is obtained, that is, 1024; when the bit of * of the LCP is all 1, the maximum value of the range class field indicated by the LCP is obtained, that is, 2047. Therefore, the range indicated by the LCP is [1024, 2047].
[0145] In step S11, after the electronic device obtains the LCP of each range of the specified matching field, it can determine the range indicated by each LCP and detect whether the range indicated by the obtained LCP has an intersection. If there is an intersection, it means that the current LCP has redundant content, which is easy to cause rule mismatching. In order to remove the redundant part, the electronic device executes step S13 to split the redundant LCP; if there is no intersection, it means that the current LCP does not have redundant content, and the electronic device executes step S15.
[0146] Step S13: determining a target LCP in the determined at least one LCP, wherein the range indicated by the target LCP includes the range indicated by other LCPs.
[0147] There are two types of relationships between two LCPs: intersection and non-intersection. The intersection relationship can be further divided into: inclusion and inclusion. For example, LCP1 includes LCP2, which means that the range indicated by LCP1 includes the range indicated by LCP2.
[0148] In the embodiment of the present application, when it is detected that the range indicated by the at least one determined LCP is crossed, the electronic device determines from the at least one LCP the LCP whose indicated range includes the range indicated by the other LCP as the target LCP. Here, the other LCP is the LCP in the at least one determined LCP.
[0149] Step S14, based on the highest wildcard bit in the target LCP, split the target LCP into two LCPs, and re-execute step S12 based on the multiple LCPs obtained after the split, and the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP.
[0150] The electronic device determines the highest bit of the * in the target LCP, and based on the highest bit of the *, splits the target LCP into two LCPs, and based on the multiple LCPs obtained after the splitting, re-executes step S12 to detect whether there is any intersection in the range indicated by the obtained LCPs; steps S12-S14 are executed in a loop until there is no intersection in the range indicated by the obtained multiple LCPs.
[0151] For example, LCP1 is 000000000000****, LCP2 is 000000000000110, and the * bits can be 0 or 1, so the range [0, 15] indicated by LCP1 includes the range [12, 13] indicated by LCP2, and [12, 13] is within [0, 15]. Therefore, LCP1 includes LCP2. The electronic device determines LCP1 as the target LCP, determines the highest bit of * in LCP1, and splits LCP1 into two LCPs based on the highest bit of *. For example, the two LCPs obtained by splitting are LCP11 and LCP12, where LCP11 is 0000000000000*** and 0000000000001***.
[0152] In an embodiment of the present application, the union of the ranges indicated by the two LCPs obtained by splitting is greater than or equal to the range of the target LCP, thereby avoiding the problem of rule mismatch caused by the LCP obtained by splitting failing to cover the original range, that is, the range of the specified matching field.
[0153] Step S15: adjusting the minimum value of the range indicated by the at least one LCP obtained to the minimum value of the range of the specified matching field, and adjusting the maximum value of the range indicated by the at least one LCP obtained to the maximum value of the range of the specified matching field.
[0154] In the embodiment of the present application, when there is no intersection in the range indicated by at least one obtained LCP, the electronic device determines the minimum and maximum values of the ranges indicated by all currently obtained LCPs, adjusts the minimum value of the range indicated by the obtained LCP to the minimum value of the range of the specified matching field, and adjusts the maximum value of the range indicated by the obtained LCP to the maximum value of the range of the specified matching field. This restores the range obtained after expansion to the range of the specified matching field, ensuring that the ranges of the two are consistent.
[0155] For example, see Figure 2 A schematic diagram of the range expansion shown. Figure 2 In the example, the ranges of the specified matching fields include [1, 8], [12, 13], and [15, 28]. The minimum value of the multiple ranges is 1, and the maximum value is 28. The ranges indicated by the LCPs corresponding to the multiple ranges are [0, 15], [12, 13], and [0, 31]. The electronic device expands the multiple ranges, that is, splits the LCPs corresponding to the multiple ranges to obtain multiple LCPs without intersection. The ranges indicated by the multiple LCPs include [0, 7], [8, 8], [12, 13], [15, 15], and [16, 31]. The minimum value of the ranges indicated by the multiple LCPs is 0, and the maximum value is 31. The minimum value of the range of the specified matching field is 1, and the maximum value is 28. Therefore, the electronic device adjusts the minimum value 0 of the range indicated by the obtained multiple LCPs to the minimum value 1 of the range of the specified matching field, and adjusts the maximum value 31 of the range indicated by the obtained multiple LCPs to the maximum value 28 of the range of the specified matching field. The restored ranges include: [1, 7], [8, 8], [12, 13], [15, 15] and [16, 28].
[0156] In the technical solution provided by the embodiment of the present application, the electronic device uses the LCP of each range of the specified matching field to expand multiple ranges at the same time, which can effectively utilize the common information of multiple ranges. Compared with the related art, only each range is considered separately and a range is equivalently expanded into multiple ranges. In the technical solution provided by the embodiment of the present application, the common information of multiple ranges is fully utilized and multiple ranges are expanded at the same time, which can reduce the rule expansion coefficient caused by range expansion, thereby improving the search performance. In addition, since the rule expansion coefficient caused by range expansion is reduced, the technical solution provided by the embodiment of the present application can use a smaller TCAM capacity to achieve larger-scale rule search, saving TCAM cost and power consumption.
[0157] In some embodiments, based on Figure 1 The method embodiment shown in the figure, the embodiment of the present application also provides a method for expanding the scope in a rule, such as Figure 3 As shown, Figure 3 A partial flow chart of a method for expanding a scope in a rule provided in an embodiment of the present application, the method may include:
[0158] Step S31, when all rules in the rule set intersect within the range of the specified matching field, determine the balance bit of each rule in the rule set, the balance bit being the bit with the smallest difference between the number of rules with a value of 0 and the number of rules with a value of 1.
[0159] A rule may include a match field and an action field, such as rules in ACL (Access Control Lists), flow tables, forwarding tables, and routing tables. In an embodiment of the present application, the electronic device uses all rules with match fields and action fields as a global rule set. The rule set in the above step S31 can be a global rule set, or it can be a rule set obtained by splitting the global rule set. Considering the entire rule, the electronic device determines the balance bit of the rules in the rule set. At the balance bit, 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.
[0160] For example, a rule set in an electronic device includes Figure 4 The 5 rules R1-R5 shown, from Figure 4 It can be seen that at bit position P2, the number of rules with a value of 0 is 2, the number of rules with a value of 1 is 2, and the difference between the two is 2-2=0. This is the bit position where 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, it can be determined that bit position P2 is a balanced bit position.
[0161] Before executing step S31 to determine the balance bit of each rule in the rule set, in order to ensure the accuracy of rule processing, the electronic device may perform the following processing on each rule in the rule set:
[0162] 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;
[0163] For the range-type fields included in this rule, set the value of each bit to a wildcard character;
[0164] For the exact class fields included in the rule, set the value of each bit to the exact value;
[0165] For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.
[0166] Step S32: divide the rules whose balance bit value is 0 into one rule set, and divide the rules whose balance bit value is 1 into another rule set.
[0167] Still Figure 4 Take this as an example. The electronic device determines that the balance bit is P2, and divides the rules R2 and R5 whose values of the bit P2 are 0 into a rule set 1; and divides the rules R1 and R4 whose values of the bit P2 are 1 into a rule set 2. At this point, the splitting of one rule set into two rule sets is completed.
[0168] In an embodiment of the present application, the electronic device may adopt a decision tree management rule set in the form of a binary tree. For example, the root node of the decision tree includes a global rule set, and the electronic device divides the rules with a balance bit value of 0 into a rule set, and adds the rule set to the first side child node of the decision tree; divides the rules with a balance bit value of 1 into a rule set, and adds the rule set to the second side node of the decision tree. Among them, the above-mentioned first side child is left, and the second side is right, or the first side is a right tree, and the second side is left. The use of a decision tree management rule set in the form of a binary tree makes the technical solution provided in the embodiment of the present application more general and has nothing to do with specific applications.
[0169] In the embodiment of the present application, there is a case where the value of the balance bit is "*", such as Figure 4 In the example, the value of the balance bit P2 of rule R3 is "*". In this case, the electronic device may not process such rules at all, or may add such rules to the discard rule set for subsequent processing. There is no limitation on this.
[0170] Step S33: for each rule set obtained by splitting, if all rules in the rule set have an intersection in the range of the specified matching field, step S31 is re-executed until all rules in the rule set obtained by splitting have no intersection in the range of the specified matching field. Figure 1 Steps S11-S15 are shown.
[0171] In the embodiment of the present application, the electronic device executes steps S31-S33 in a loop, and the condition for the end of the loop is: all rules in the split rule set do not intersect in the range of the specified matching field. A decision tree in the form of a binary tree is used to manage the rule set, and multiple ranges that do not intersect are the leaf nodes of the decision tree. Figure 5 As shown, Figure 5 A leaf node of the decision tree is shown in FIG. 1 , in which the ranges [1, 8], [12, 13] and [15, 28] of rules R0, R1 and R2 do not intersect. Figure 5 P0 and P1 represent the balance bit.
[0172] By applying the technology provided in the embodiments of the present application, the electronic device splits the range of the specified matching field so that there is no overlap in the split range, thereby reducing the workload of subsequent LCP generation and the repetition rate of rule storage based on LCP, and improving the efficiency of subsequent rule matching.
[0173] In some embodiments, in the above step S11, the step of determining the LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field may include steps S61 and S62, such as Figure 6 As shown:
[0174] Step S61, for each range of the specified matching field, determining the highest bit of the maximum value and the lowest value of the range that have different values;
[0175] In an embodiment of the present application, for each range of the specified matching field, the electronic device converts the maximum value and the minimum value of the range into binary values respectively, and can traverse each bit from the highest bit to the lowest bit to determine the highest bit with different values.
[0176] In the embodiment of the present application, for each range of the specified matching field, the electronic device converts the maximum value and the minimum value of the range into binary values respectively, and then divides the binary values corresponding to the maximum value and the minimum value into multiple segments, and detects whether the binary values of each segment are completely the same. If they are not the same, the electronic device uses the highest bit in the different one or more segments of binary values as the highest bit in the maximum value and the minimum value that have different values.
[0177] In the embodiment of the present application, the electronic device may also use other methods to determine the highest bit position where the maximum value and the minimum value have different values, and this is not limited.
[0178] Step S62: for each range of each designated matching field, the values of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range are set as wildcards to obtain the LCP of the range.
[0179] For example, the electronic device obtains a range of the specified matching field [1528, 2022], the maximum value of the range is 2022, the minimum value of the range is 1528, and the binary values of 1528 and 2022 can be found in Figure 7 shown. Figure 7In the binary values shown, the leftmost is the highest and the rightmost is the lowest. In the binary values of 1528 and 2022, the highest bit with different values is P0. Based on the minimum value 1528 in the range [1528, 2022], the electronic device sets the values of bit P0 and bits lower than bit P0 in the minimum value 1528 to *, and obtains LCP_1 in the range [1528, 2022].
[0180] When all *bits in LCP_1 are 0, the electronic device obtains the minimum value of the range indicated by LCP_1, that is, 1024. When all *bits in LCP_1 are 1, the electronic device obtains the maximum value of the range indicated by LCP_1, that is, 2047.
[0181] In some embodiments, steps S61 and S62 may be implemented as follows: for each range of a specified matching field, the electronic device traverses each bit position I from the highest bit position of the maximum value and the minimum value of the range to the lowest bit position; if the maximum value [I] = the minimum value [I], then LCP[I] = the maximum value [I] = the minimum value [I]; starting from the bit position where the first maximum value [I] is not equal to the minimum value [I], all subsequent bit positions LCP[I] = *.
[0182] By applying the technical solution provided in the embodiments of the present application, the electronic device uses one LCP to represent a range, which reduces the expansion coefficient of the range, facilitates TCAM to support range search, improves the search performance as a whole, and saves TCAM cost and power consumption.
[0183] In some embodiments, the step of splitting the target LCP into two LCPs based on the highest wildcard bit in the target LCP in step S14 may include step S81, step S82 and step S83. Figure 8 As shown:
[0184] Step S81, setting the value of the highest wildcard bit in the target LCP to 0, and setting the values of other wildcard bits in the target LCP except the highest wildcard bit to 1, to obtain the maximum value of splitting;
[0185] Step S82, setting the value of the highest wildcard bit in the target LCP to 1, and setting the values of other wildcard bits in the target LCP except the highest wildcard bit to 0, to obtain the minimum splitting value;
[0186] In the embodiment of the present application, the execution order of step S81 and step S82 is not limited.
[0187] Step S83, generating a new LCP according to the minimum value of the range of the target LCP and the split maximum value, and generating another new LCP according to the maximum value of the range of the target LCP and the split minimum value.
[0188] For example, the electronic device obtains a range of the specified matching field [1528, 2022], the maximum value 1 of the range is 2022, the minimum value 1 of the range is 1528, and the binary values of 1528 and 2022 can be found in Fig. 9 shown. Fig. 9 In the binary values shown, the leftmost is the highest and the rightmost is the lowest. In the binary values of 1528 and 2022, the highest bit with different values is P0. Based on the minimum value 1528 in the range [1528, 2022], the electronic device sets the values of bit P0 and bits lower than bit P0 in the minimum value 1528 to *, and obtains LCP1 in the range [1528, 2022], as shown in Fig. 9 shown.
[0189] Fig. 9 In , the electronic device can traverse each bit position I of LCP1 from the highest bit position to the lowest bit position of LCP1, and find the first bit position P0 that makes LCP[1] = *, that is, the highest wildcard position P0. The electronic device sets the value of bit position P0 to 0 and the values of other wildcard positions to 1, and obtains the maximum value of splitting, that is, Fig. 9 The maximum value in is 2; set the value of bit P0 to 1 and the values of other wildcard bits to 0 to obtain the minimum value of splitting, that is Fig. 9 The minimum value is 2. Electronic devices can be Figure 6 In the method shown, according to the minimum value 1 and the maximum value 2, the bit position P1 is determined, and then the new LCP2 is determined. The range indicated by LCP2 is 1528 to 1535; according to the minimum value 2 and the maximum value 1, the bit position P2 is determined, and then the new LCP3 is determined. The range indicated by LCP3 is 1536 to 2047. Here, the method of determining LCP2 and LCP3 can be referred to Figure 6 The description of part is not repeated here.
[0190] By applying the technical solution provided in the embodiments of the present application, when the target LCP contains other LCPs, the electronic device splits the target LCP into multiple LCPs, which can narrow the coverage of the range indicated by the LCP, reduce the repetition rate of rule storage based on LCP, improve the efficiency of subsequent rule matching, and improve the accuracy of rule matching.
[0191] In some embodiments, the present application also provides a method for expanding the scope in a rule, such as Fig.10 As shown, Fig.10A second flow chart of a method for expanding the scope in a rule provided in an embodiment of the present application, the method may include steps S101-S106, wherein steps S101-S105 are the same as the above steps S11-S15.
[0192] Step S106, based on the LCP corresponding to each expanded range, the rules whose designated matching fields are multiple expanded ranges are subjected to end splitting and added to the decision tree, wherein one leaf node of the decision tree includes one rule.
[0193] In some embodiments, step S105 may be: starting from the highest bit with different values in the LCP corresponding to each range obtained by the expansion, traverse each bit, and add the rules belonging to the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value. For example, if the bit is 1 and corresponds to the right subtree, and the bit is 0 and corresponds to the left subtree, the electronic device may add the rules belonging to the range with the bit being 1 to the right subtree, and add the rules belonging to the range with the bit being 0 to the left subtree.
[0194] In the embodiment of the present application, the electronic device may also use other methods to implement end splitting, as long as a leaf node of the decision tree includes a rule.
[0195] In the technical solution provided by the embodiment of the present application, multiple bits can be obtained in the range for terminal splitting, reducing the number of rules in the leaf node. In addition, when performing packet classification to obtain rules, the electronic device verifies the obtained rules to determine whether the obtained rules completely match the key of the data packet. At this time, the electronic device needs to verify all the rules in the leaf node. In the embodiment of the present application, after the terminal splitting, the number of rules in the leaf node is 1, which greatly improves the verification rate of the rules and improves the search performance.
[0196] Combine the following Figure 5 , Figure 2 , Fig.11 Schematic diagram of terminal cleavage shown, and Fig.12 The decision tree diagram shown in the figure is used to explain in detail the range expansion method provided in the embodiment of the present application. In the embodiment of the present application, the range with the value of bit position 1 is added to the right subtree, and the range with the value of bit position 0 is added to the left subtree as an example for explanation.
[0197] The electronic device splits the rule set, and a leaf node obtained includes multiple rules that specify the matching fields as non-overlapping ranges, such as Figure 5 The specified matching fields shown are rules R0-R2 with ranges [1, 8], [12, 13], and [15, 28] respectively.
[0198] 1) Electronic devices are based on the binary system of 1, 8, 12, 13, 15 and 28. Figure 6 The method shown in Figure 2 extracts LCPs in three ranges and obtains the LCP set as Figure 2 As shown, including [0, 15], [12, 13] and [0, 31].
[0199] To facilitate determination of the relationship between the ranges indicated by the LCPs, the electronic device may sort the extracted LCPs in ascending order of starting values, analyze pairwise adjacent LCPs, determine the relationship between the ranges indicated by pairwise adjacent LCPs, and then split the LCPs.
[0200] 2) In the LCP set obtained in step 1), [0, 15] contains [12, 13], so the electronic device can be Figure 8 The method shown splits [0, 15] to obtain [0, 7] and [8, 8]. At this time, [8, 8] does not intersect with [12, 13].
[0201] 3) In the LCP set obtained in steps 1) and 2), [12, 13] is included in [0, 31]. Therefore, the electronic device can be Figure 8 The method shown splits [0, 31] to obtain [15, 15] and [16, 31].
[0202] 4) The electronic device restores the obtained LCP to the original range, such as: the minimum value of the first LCP generated by splitting becomes the minimum value of the original range, the maximum value of the last LCP becomes the maximum value of the original range, and the rest remain unchanged. This completes the processing of a child node on the decision tree, and the obtained range is as follows Figure 2 The range in the middle restores multiple ranges in a row. After the same process is performed on all child nodes of the decision tree, the processing of the global rule set is completed.
[0203] 5) The electronic device performs end splitting on the obtained multiple ranges. For example, Fig.11 As shown, multiple bits P2-P5 are determined:
[0204] a) Split at bit position P2: [16, 28] has a value of 1 at bit position P2, and the values of other ranges at bit position P2 are 0. Then the electronic device adds the rules belonging to [16, 28] to the right subtree, and the rules belonging to other ranges to the left subtree;
[0205] b) Split at bit position P3: Except for [16, 28], the value of [1, 7] at bit position P3 is 0, and the value of other ranges at bit position P3 is 1. Then the electronic device adds the rules belonging to [1, 7] to the left subtree, and the rules belonging to other ranges to the right subtree;
[0206] c) Split at bit position P4: Except for [16, 28] and [1, 7], the value of [8, 8] at bit position P4 is 0, and the value of other ranges at bit position P4 is 1, then the electronic device adds the rules belonging to [8, 8] to the left subtree, and the rules belonging to other ranges to the right subtree;
[0207] d) Split at bit position P5: Except for [16, 28], [1, 7] and [8, 8], the value of [12, 13] at bit position P5 is 0, and the value of [15, 15] at bit position P5 is 1. The electronic device adds the rule belonging to [12, 13] to the left subtree, and adds the rule belonging to [15, 15] to the right subtree.
[0208] At this point, a leaf node includes a rule, the end split is completed, and the resulting decision tree is as follows Fig.12 As shown, Fig.12 In , each range represents the rules included in a leaf node, and P1-P5 represent the bits included in a node.
[0209] In the technical solution provided by the embodiment of the present application, multiple bits can be obtained in the range, and the end splitting can be performed, thereby reducing the number of rules in the leaf node. In addition, when the packet classification is performed to obtain the rules, the electronic device verifies the obtained rules to determine whether the obtained rules completely match the key of the data packet. At this time, the electronic device needs to verify all the rules in the leaf node. In the embodiment of the present application, after the end splitting, the number of rules in the leaf node is 1, which greatly improves the verification rate of the rules and improves the search performance.
[0210] In addition, by using the LCP of each range of the specified matching field and expanding multiple ranges at the same time, the common information of multiple ranges can be effectively utilized. Compared with the related art, only each range is considered separately and one range is equivalently expanded into multiple ranges. In the technical solution provided by the embodiment of the present application, the common information of multiple ranges is fully utilized and multiple ranges are expanded at the same time, which can reduce the rule expansion coefficient caused by range expansion, thereby improving the search performance. In addition, since the rule expansion coefficient caused by range expansion is reduced, the technical solution provided by the embodiment of the present application can use a smaller TCAM capacity to achieve larger-scale rule search, saving TCAM cost and power consumption.
[0211] After the expansion of the range is completed, the electronic device performs packet classification processing based on the expanded range. In some embodiments, before performing packet classification processing, the electronic device can store the rules corresponding to each expanded range into a block rule table in the RAM, and the block rule table stores multiple rules with the same common rules, and the common rules are determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, and 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, and the base address is used to locate the block rule table. The value of the non-wildcard bit in the public 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 public rules are stored in the public rule table in the TCAM, and the public rule table and the main rule table have the same index corresponding to the same block rule table.
[0212] 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.13 As shown in the figure, the index is used to indicate the position of the entry in the table.
[0213] 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.13 In the embodiment of the present application, multiple rules in a block rule table constitute a rule block.
[0214] A TCAM table has a corresponding master rule table stored in RAM, such as Fig.13 L0-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.13 The primary index in .
[0215] The multiple rules included in a rule block constitute a block rule table and are stored in RAM, such as Fig.13 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.13 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.13 The sub-index in .
[0216] The above-mentioned common rule table, main rule table and block rule table can be collectively referred to as an algorithm table.
[0217] Based on the above common rule table, main rule table and block rule table, when receiving a data packet to be classified, the electronic device performs packet classification processing, such as Fig.14 As shown, the following steps are included:
[0218] Step S141, extracting a target search key value from the data packet to be classified;
[0219] 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.
[0220] Step S142, using 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;
[0221] 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.
[0222] Step S143, locating the block rule table based on the base address included in the target table entry pointed to by the primary index;
[0223] 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.
[0224] Step S144, determining the secondary index of the target 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;
[0225] As described in step S143, 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 bit values form 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 target rule, which does not serve as a limitation.
[0226] The execution order of step S143 and step S144 is not limited in the embodiment of the present application.
[0227] Step S145, performing packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
[0228] The electronic device reads the target rule corresponding to the secondary index in the block rule table located in step S143, and performs packet classification processing on the data packet to be classified according to the action field in the target rule, such as forwarding the data packet to be classified, or discarding the data packet to be classified.
[0229] 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.
[0230] Based on the same inventive concept, corresponding to the above-mentioned scope expansion method embodiment in the rule, the embodiment of the present application also provides a scope expansion device in the rule, see Fig.15 , Fig.15 A schematic diagram of a structure of a scope expansion device in a rule provided in an embodiment of the present application, the device comprising:
[0231] A first determination module 151, configured to determine the LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field when all rules in the rule set do not overlap in the range of the specified matching field;
[0232] A detection module 152, configured to detect whether a range indicated by the at least one LCP obtained has an intersection;
[0233] A second determination module 153 is configured to determine a target LCP from the at least one determined LCP if the detection result of the detection module 152 is yes, and the range indicated by the target LCP includes the range indicated by other LCPs;
[0234] The splitting module 154 is used to split the target LCP into two LCPs based on the highest wildcard bit in the target LCP, and re-trigger the detection module 152 to detect whether there is an intersection in the range indicated by the at least one LCP obtained based on the multiple LCPs obtained after the split; the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP;
[0235] The adjustment module 155 is used to adjust the minimum value of the range indicated by the at least one LCP obtained to the minimum value of the range of the specified matching field, and adjust the maximum value of the range indicated by the at least one LCP obtained to the maximum value of the range of the specified matching field when the detection result of the detection module 152 is yes.
[0236] In some embodiments, Fig.16 As shown, the scope expansion device in the above rule may also include:
[0237] A third determination module 156 is used to determine the balance bit of each rule in the rule set when all the rules in the rule set intersect in the range of the specified matching field, where the balance bit is the bit with the smallest difference between the number of rules with a value of 0 and the number of rules with a value of 1;
[0238] A partitioning module 157, configured to partition the rules whose balance bit value is 0 into one rule set, and partition the rules whose balance bit value is 1 into another rule set;
[0239] The third determination module 156 is also used to, for each rule set obtained by splitting, if all the rules in the rule set intersect in the range of the specified matching field, re-execute the step of determining the balance bit of each rule in the rule set until all the rules in the rule set obtained by splitting do not intersect in the range of the specified matching field.
[0240] 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;
[0241] The scope expansion device in the above rule may further include: a first processing module, configured to perform the following processing on each rule in the rule set before determining the balance position of each rule in the rule set:
[0242] 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;
[0243] For the range-type fields included in this rule, set the value of each bit to a wildcard character;
[0244] For the exact class fields included in the rule, set the value of each bit to the exact value;
[0245] For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.
[0246] In some embodiments, the first determining module 151 may be specifically configured to:
[0247] For each range of the specified matching field, determine the highest bit whose values are different in the maximum value and the minimum value of the range; set the value of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range as wildcards to obtain the LCP of the range.
[0248] In some embodiments, the splitting module 154 may be specifically configured to:
[0249] The value of the highest wildcard bit in the target LCP is set to 0, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 1 to obtain the maximum value of the split;
[0250] The value of the highest wildcard bit in the target LCP is set to 1, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 0 to obtain the minimum split value;
[0251] A new LCP is generated based on the minimum value of the range that determines the target LCP and the split maximum value, and another new LCP is generated based on the maximum value of the range that determines the target LCP and the split minimum value.
[0252] In some embodiments, the scope expansion means in the above rule may further include:
[0253] A module is added, which is used to perform end splitting on the rules whose designated matching fields are multiple ranges obtained by expansion based on the LCP corresponding to each range obtained by expansion after the range expansion is completed, and add them to the decision tree, wherein a leaf node of the decision tree includes a rule.
[0254] In some embodiments, the add module can be specifically used to:
[0255] Starting from the highest bit with different values in the LCP corresponding to each range obtained by expansion, traverse each bit and add the rules of the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value.
[0256] In some embodiments, the scope expansion means in the above rule may further include:
[0257] A storage module is used for storing the rules corresponding to each range obtained by expansion into a block rule table in a random access memory RAM after the range expansion is completed, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, wherein 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 the rules in the block rule table pointed to by the base address; the common rules are stored in a common rule table in a ternary content addressable memory TCAM, and the common rule table and the main rule table have the same index corresponding to the same block rule table;
[0258] An extraction module, used for extracting a target search key value from the data packet to be classified when receiving the data packet to be classified;
[0259] A matching module, used to match the target lookup key value in the common rule table to obtain the primary index of the target table item in the main rule table;
[0260] 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;
[0261] A third determination module, configured to determine a secondary index of a target 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;
[0262] The second processing module is used to perform packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
[0263] In the technical solution provided by the embodiment of the present application, the LCP of each range of the specified matching field is used to expand multiple ranges at the same time, and the common information of multiple ranges can be effectively utilized. Compared with the related art, only each range is considered separately and a range is equivalently expanded into multiple ranges. In the technical solution provided by the embodiment of the present application, the common information of multiple ranges is fully utilized, and multiple ranges are expanded at the same time, which can reduce the rule expansion coefficient caused by range expansion, thereby improving the search performance. In addition, since the rule expansion coefficient caused by range expansion is reduced, the technical solution provided by the embodiment of the present application can use a smaller TCAM capacity, realize larger-scale rule search, and save TCAM cost and power consumption.
[0264] The present application also provides an electronic device, such as Fig.17 As shown, it includes a processor 171 and a machine-readable storage medium 172; the machine-readable storage medium 172 stores machine-executable instructions that can be executed by the processor 171, and the processor 171 is prompted by the machine-executable instructions to implement the scope expansion method steps in any of the above-mentioned rules.
[0265] 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.
[0266] 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.
[0267] In some embodiments, Fig.18 As shown, the electronic device may further include a forwarding chip 173;
[0268] The processor 171 is further prompted by the machine executable instructions to: implement storing the rules corresponding to each range obtained by the expansion into a block rule table in the RAM, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; 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 rules are stored in the common rule table in the TCAM, and the common rule table and the main rule table have the same index corresponding to the same block rule table;
[0269] The forwarding chip 173 is used to extract a 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 public rule table to obtain the 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 target 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; and perform packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
[0270] In another embodiment provided by the present application, a machine-readable storage medium is also provided, in which machine-executable instructions that can be executed by the processor are contained, and the processor is prompted by the machine-executable instructions to implement any of the above-mentioned range class field expansion method steps.
[0271] 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 range class field expansion method steps.
[0272] 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 loading and executing computer program instructions 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 hard disk SolidState Disk (SSD)), etc.
[0273] 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.
[0274] 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, machine-readable 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.
[0275] 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 scope expansion method in a rule, It is characterized in that The method comprises: When all rules in the rule set do not overlap in the range of the specified matching field, determine the longest common prefix LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field; Detecting whether there is an intersection between the ranges indicated by the at least one LCP obtained; If there is an intersection, determining a target LCP in the at least one determined LCP, wherein the range indicated by the target LCP includes the range indicated by the other LCPs; Based on the highest wildcard bit in the target LCP, the target LCP is split into two LCPs, and based on the multiple LCPs obtained after the splitting, the step of detecting whether there is an intersection in the range indicated by the at least one LCP obtained is re-executed; the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP; If there is no intersection, adjusting the minimum value of the range indicated by the at least one LCP obtained to the minimum value of the range of the specified matching field, and adjusting the maximum value of the range indicated by the at least one LCP obtained to the maximum value of the range of the specified matching field; The step of splitting the target LCP into two LCPs based on the highest wildcard bit in the target LCP comprises: The value of the highest wildcard bit in the target LCP is set to 0, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 1, to obtain a splitting maximum value; Setting the value of the highest wildcard bit in the target LCP to 1, and setting the values of other wildcard bits in the target LCP except the highest wildcard bit to 0, to obtain a minimum split value; A new LCP is generated based on the minimum value of the range determining the target LCP and the split maximum value, and another new LCP is generated based on the maximum value of the range determining the target LCP and the split minimum value.
2. The method according to claim 1, It is characterized in that The method further comprises: When all the rules in the rule set intersect within the range of the specified matching field, determining the balance bit of each rule in the rule set, wherein the balance bit is the bit with the smallest difference between the number of rules with a value of 0 and the number of rules with a value of 1; The rules whose balance bit value is 0 are divided into one rule set, and the rules whose balance bit value is 1 are divided into another rule set; For each rule set obtained by splitting, if all the rules in the rule set intersect within the scope of the specified matching field, the step of determining the balance bit of each rule in the rule set is re-executed until all the rules in the rule set obtained by splitting do not intersect within the scope of the specified matching field.
3. The method according to claim 2, It is 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 determining the balance position of each rule in the rule set, the method further includes: The following processing is performed on each rule in the 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 fields included in this rule, set the value of each bit to a wildcard character; 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.
4. The method according to claim 1, It is characterized in that The step of determining the longest common prefix LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field comprises: For each range of the designated matching field, determine the highest bit with different values in the maximum value and the minimum value of the range; set the value of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range as wildcards to obtain the longest common prefix LCP of the range.
5. The method according to claim 1, It is characterized in that The method further comprises: After the range is expanded, based on the LCP corresponding to each expanded range, the rules whose designated matching fields are the expanded multiple ranges are end-split and added to the decision tree, where one leaf node of the decision tree includes one rule.
6. The method according to claim 5, It is characterized in that The step of performing end splitting on the multiple ranges obtained by the expansion based on the LCP corresponding to each range obtained by the expansion and adding the ranges to the decision tree comprises: Starting from the highest bit with different values in the LCP corresponding to each range obtained by expansion, traverse each bit and add the rules of the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value.
7. The method according to any one of claims 1 to 6, It is characterized in that After the scope expansion is completed, the method further includes: The rules corresponding to each range obtained by expansion are stored in a block rule table in a random access memory RAM, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, wherein 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, and 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 is stored in a common rule table in a ternary content addressable memory TCAM, and the common rule table has the same index as the main rule table 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 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 target 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; Based on the target rule pointed to by the secondary index, packet classification processing is performed on the data packet to be classified.
8. A range expansion device in a rule, It is characterized in that The device comprises: A first determination module, configured to determine the longest common prefix LCP of each range of the specified matching field according to the maximum value and the minimum value of each range of the specified matching field when all rules in the rule set do not intersect in the range of the specified matching field; A detection module, used to detect whether there is an intersection between the ranges indicated by the at least one LCP obtained; A second determination module is configured to determine a target LCP from the at least one determined LCP if the detection result of the detection module is yes, wherein the range indicated by the target LCP includes the range indicated by other LCPs; a splitting module, configured to split the target LCP into two LCPs based on the highest wildcard bit in the target LCP, and re-trigger the detection module to detect whether there is an intersection in the range indicated by at least one LCP obtained based on the multiple LCPs obtained after the splitting; the union of the ranges indicated by the two LCPs is greater than or equal to the range of the target LCP; an adjustment module, configured to, when the detection result of the detection module is yes, adjust the minimum value of the range indicated by the at least one LCP obtained to the minimum value of the range of the specified matching field, and adjust the maximum value of the range indicated by the at least one LCP obtained to the maximum value of the range of the specified matching field; The splitting module is specifically used for: The value of the highest wildcard bit in the target LCP is set to 0, and the values of other wildcard bits in the target LCP except the highest wildcard bit are set to 1, to obtain a splitting maximum value; Setting the value of the highest wildcard bit in the target LCP to 1, and setting the values of other wildcard bits in the target LCP except the highest wildcard bit to 0, to obtain a minimum split value; A new LCP is generated based on the minimum value of the range determining the target LCP and the split maximum value, and another new LCP is generated based on the maximum value of the range determining the target LCP and the split minimum value.
9. The device according to claim 8, It is characterized in that The device also includes: A third determination module is used to determine a balance bit of each rule in the rule set when all rules in the rule set intersect within the range of the specified matching field, wherein the balance bit is a bit in which 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; A partitioning module, used for partitioning the rules whose balance bit value is 0 into one rule set, and partitioning the rules whose balance bit value is 1 into another rule set; The third determination module is also used to, for each rule set obtained by splitting, if all the rules in the rule set intersect within the range of the specified matching field, re-execute the step of determining the balance bit of each rule in the rule set until all the rules in the rule set obtained by splitting do not intersect within the range of the specified matching field.
10. The device according to claim 9, It is 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 apparatus further includes: a first processing module, configured to perform the following processing on each rule in the rule set before determining the balance position of each rule in the 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 fields included in this rule, set the value of each bit to a wildcard character; 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.
11. The device according to claim 8, It is characterized in that The first determining module is specifically configured to: For each range of the designated matching field, determine the highest bit with different values in the maximum value and the minimum value of the range; set the value of the highest bit and other bits lower than the highest bit in the maximum value or the minimum value of the range as wildcards to obtain the longest common prefix LCP of the range.
12. The device according to claim 8, It is characterized in that The device also includes: The adding module is used to perform end splitting on the rules whose designated matching fields are multiple ranges obtained by expansion based on the LCP corresponding to each range obtained by expansion after the range expansion is completed, and add them to the decision tree, wherein a leaf node of the decision tree includes a rule.
13. The device according to claim 12, It is characterized in that The adding module is specifically used for: Starting from the highest bit with different values in the LCP corresponding to each range obtained by expansion, traverse each bit and add the rules of the range of different values at each bit to the subtree of the decision tree on one side corresponding to the value.
14. The device according to any one of claims 8 to 13, It is characterized in that The device also includes: A storage module is used for storing the rules corresponding to each range obtained by the expansion into a block rule table in a random access memory RAM after the expansion of the range is completed, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; the main rule table includes at least two fields, a split position set and a base address, wherein 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 is stored in a common rule table in a ternary content addressable memory TCAM, and the common rule table has the same index as the main rule table corresponding to the same block rule table; An extraction module, used for extracting a target search key value from the data packet to be classified when receiving the data packet to be classified; A 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 a target 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 second processing module is used to perform packet classification processing on the data packet to be classified based on the target rule pointed to by the secondary index.
15. An electronic device, It is 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 6.
16. The electronic device according to claim 15, It is 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 rules corresponding to each range obtained by the expansion into a block rule table in a random access memory RAM, wherein the block rule table stores a plurality of rules having the same common rule, and the common rule is determined based on the LCP corresponding to each range; the RAM also stores a main rule table; 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 public 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 public rules are stored in the public rule table in the ternary content addressable memory TCAM. The public 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 perform a match in the common rule table to obtain a primary index of the target entry in the main rule table; Based on the base address included in the target table entry pointed to by the primary 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 primary index, the secondary index of the target rule in the located block rule table is determined; based on the target rule pointed to by the secondary index, packet classification processing is performed on the data packet to be classified.
17. A machine-readable storage medium, It is characterized in that The machine-readable storage medium stores machine-executable instructions that can be executed by a processor, and the processor is prompted by the machine-executable instructions to implement the method steps described in any one of claims 1-6.
