Packet classification method, device, forwarding chip and electronic device

By combining TCAM and RAM in the packet classification method to store public rules and specific rules, the problems of high cost and high power consumption of TCAM are solved, more efficient packet classification processing is achieved, and cost and power consumption are reduced.

CN115714752BActive Publication Date: 2024-10-25NEW H3C SEMICON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211338609.0
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

Technical Problem

Among the existing packet classification methods, the high cost and high power consumption of TCAM result in high packet classification cost and high power consumption, which is difficult to effectively reduce.

Method used

Using a packet classification method that combines TCAM and RAM, by storing public rules in TCAM and specific rules in RAM, TCAM's high search performance is used to exclude most rules, reduce the demand for TCAM capacity, and achieve larger-scale rule search.

Benefits of technology

The cost and power consumption of packet classification are reduced, the efficiency and performance of packet classification are improved, and a smaller-capacity TCAM can be used to achieve larger-scale rule search.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115714752B_ABST
    Figure CN115714752B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a packet classification method, device, forwarding chip and electronic device, which relates to the field of computer technology. The electronic device is provided with TCAM and RAM, a public rule table is stored in the TCAM, and a main rule table and a block rule table are stored in the RAM; a plurality of rules with the same public rule are stored in the block 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, and the base address is used to locate the block rule table; the public rule table stores public rules, and the public rule table and the main rule table have the same index corresponding to the same block rule table; based on the public rule table, the main rule table and the block rule table, the classified data packet is subjected to packet classification processing. The technical solution provided by the embodiment of the present application can solve the problem of high packet classification cost and high power consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a packet classification method, device, forwarding chip and electronic device. 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 pre-defined rule set. Using TCAM (Ternary Content Addressable Memory) to store rule sets and perform rule matching based on content can improve rule matching efficiency and packet classification efficiency, but TCAM is expensive and consumes a lot of power, which makes packet classification costly and consumes a lot of power. Summary of the invention

[0003] The purpose of the embodiments of the present application is to provide a packet classification method, device, forwarding chip and electronic device to solve the problem of high packet classification cost and high power consumption. The specific technical solution is as follows:

[0004] In a first aspect, an embodiment of the present application provides a packet classification method, which is applied to an electronic device with a packet classification function, wherein a TCAM and a RAM (Random-Access Memory) are provided in the electronic device, wherein a public rule table is stored in the TCAM, and a main rule table and a block rule table are stored in the RAM;

[0005] The block rule table stores a plurality of rules having the same common rule;

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

[0007] The common rule table stores common rules, and the common rule table has the same index as the main rule table corresponding to the same block rule table;

[0008] The method comprises:

[0009] Extract target search key values ​​from the data packets to be classified;

[0010] 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;

[0011] Locate the block rule table based on the base address included in the target table entry pointed to by the primary index;

[0012] Determine a secondary index of a first rule in the located block rule table based on the target search key value and a split position set included in the target table entry pointed to by the primary index;

[0013] Based on the first rule pointed to by the secondary index, packet classification processing is performed on the data packet to be classified.

[0014] In some embodiments, the TCAM further stores a physical table, wherein at least one rule is stored in the physical table; and the method further includes:

[0015] Use the target search key value to perform matching in the physical table to obtain a second rule;

[0016] The step of performing packet classification processing on the data packet to be classified based on the first rule pointed to by the secondary index comprises:

[0017] Selecting a rule with the highest priority from the first rule and the second rule pointed to by the secondary index;

[0018] According to the selected rule, the data packet to be classified is subjected to packet classification processing.

[0019] In some embodiments, the step of selecting a rule with the highest priority from the first rule and the second rule pointed to by the secondary index includes:

[0020] Based on the target search key value, respectively verify the first rule and the second rule pointed to by the secondary index;

[0021] From the rules that are verified to match the target search key value, select a rule with the highest priority.

[0022] In some embodiments, the common rule table, the main rule table and the block rule table are generated by:

[0023] Construct a rule decision tree based on the balance bit of each rule in the global rule set, 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;

[0024] Starting from each leaf node of the rule decision tree, traverse upward in breadth-first order to obtain the deepest rule subtree corresponding to each leaf node, wherein the deepest rule subtree is the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth;

[0025] Based on each deepest rule subtree, the common rule table, the main rule table and the block rule table are generated.

[0026] In some embodiments, the step of generating the common rule table, the main rule table and the block rule table based on each deepest rule subtree comprises:

[0027] Based on the rule sets included in each deepest rule subtree, a block rule table is generated respectively;

[0028] Based on the balance bits included in each deepest rule subtree, a split position set is generated respectively;

[0029] Generate the main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table;

[0030] The common rule table is generated based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

[0031] In some embodiments, the step of constructing a rule decision tree based on the balance bit of each rule in the global rule set includes:

[0032] Using a global rule set as a rule set to be split, wherein the global rule set is included in a root node of a rule decision tree;

[0033] Determine the balance position of each rule in the rule set to be split;

[0034] Add the rule whose balance bit value is 0 in the to-be-split rule set to the first side child node, and add the rule whose balance bit value is 1 in the to-be-split rule set to the second side child node;

[0035] For each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and the step of determining the balance position of the rules in the rule set to be split is re-executed until each child node obtained by splitting includes one rule, thereby obtaining the rule decision tree.

[0036] In some embodiments, the method further comprises:

[0037] Divide the rules whose balance bit value is a wildcard in the global rule set into a discard rule set;

[0038] If the number of constructed rule decision trees is less than N, the discard rule set is used as the global rule set, and the step of constructing the rule decision tree based on the balance bits of each rule in the global rule set is re-executed until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of the TCAM.

[0039] In some embodiments, a physical table is further stored in the TCAM, and the method further includes:

[0040] After constructing N rule decision trees, the rules in the current discard rule set are added to the physical table.

[0041] In some embodiments, the rule includes at least one of a prefix class field, a range class field, an exact class field, and a wildcard class field;

[0042] Before constructing the rule decision tree based on the balance position of each rule in the global rule set, the method further includes:

[0043] The following processing is performed on each rule in the global rule set:

[0044] 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;

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

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

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

[0048] In some embodiments, the common rules are generated as follows:

[0049] If the values ​​of one bit of all the rules stored in the block rule table are all 1, then the value of the bit of the common rule corresponding to the block rule table is set to 1;

[0050] If the values ​​of one bit of all the rules stored in the block rule table are all 0, then the value of the bit of the common rule corresponding to the block rule table is set to 0;

[0051] If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

[0052] In a second aspect, an embodiment of the present application provides a packet classification device, which is applied to an electronic device with a packet classification function, wherein a TCAM and a RAM are provided in the electronic device, a public rule table is stored in the TCAM, and a main rule table and a block rule table are stored in the RAM;

[0053] The block rule table stores a plurality of rules having the same common rule;

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

[0055] The common rule table stores common rules, and the common rule table has the same index as the main rule table corresponding to the same block rule table;

[0056] The device comprises:

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

[0058] A first matching module, configured to use the target search key value to perform matching in the common rule table to obtain a primary index of a target entry in the main rule table;

[0059] 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;

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

[0061] The processing module is used to perform packet classification processing on the data packet to be classified based on the first rule pointed to by the secondary index.

[0062] In some embodiments, the TCAM further stores a physical table, wherein at least one rule is stored in the physical table; the device further includes a second matching module;

[0063] The second matching module is used to use the target search key value to perform matching in the physical table to obtain a second rule;

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

[0065] In some embodiments, the processing module is specifically used to verify the first rule and the second rule pointed to by the secondary index respectively based on the target search key value; and select the rule with the highest priority from the rules determined by the verification that match the target search key value.

[0066] In some embodiments, the apparatus further comprises a first generating module, configured to generate the common rule table, the main rule table and the block rule table, comprising:

[0067] A construction submodule, for constructing a rule decision tree based on the balance bit of each rule in the global 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;

[0068] A traversal submodule, used to traverse upward from each leaf node of the rule decision tree in a breadth-first manner to obtain the deepest rule subtree corresponding to each leaf node, wherein the deepest rule subtree is the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth;

[0069] A generating submodule is used to generate the common rule table, the main rule table and the block rule table based on each deepest rule subtree.

[0070] In some embodiments, the generating submodule is specifically used for:

[0071] Based on the rule sets included in each deepest rule subtree, a block rule table is generated respectively;

[0072] Based on the balance bits included in each deepest rule subtree, a split position set is generated respectively;

[0073] Generate the main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table;

[0074] The common rule table is generated based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

[0075] In some embodiments, the building block is specifically used to:

[0076] Using a global rule set as a rule set to be split, wherein the global rule set is included in a root node of a rule decision tree;

[0077] Determine the balance position of each rule in the rule set to be split;

[0078] Add the rule whose balance bit value is 0 in the to-be-split rule set to the first side child node, and add the rule whose balance bit value is 1 in the to-be-split rule set to the second side child node;

[0079] For each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and the step of determining the balance position of the rules in the rule set to be split is re-executed until each child node obtained by splitting includes one rule, thereby obtaining the rule decision tree.

[0080] In some embodiments, the first generation module further includes a division submodule;

[0081] The division submodule is used to divide the rules whose balance bit value in the global rule set is a wildcard into a discard rule set;

[0082] The construction submodule is also used to, if the number of constructed rule decision trees is less than N, use the discard rule set as the global rule set, and re-execute the step of constructing the rule decision tree based on the balance bits of each rule in the global rule set until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of the TCAM.

[0083] In some embodiments, a physical table is also stored in the TCAM, and the first generation module further includes an adding submodule;

[0084] The adding submodule is used to add the rules in the current discarding rule set to the physical table after constructing N rule decision trees.

[0085] In some embodiments, the rule includes at least one of a prefix class field, a range class field, an exact class field, and a wildcard class field;

[0086] The device further includes: a setting module, configured to perform the following processing on each rule in the global rule set before constructing the rule decision tree based on the balance position of each rule in the global rule set:

[0087] 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;

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

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

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

[0091] In some embodiments, the apparatus further includes a second generating module, configured to generate the common rule, specifically configured to:

[0092] If the values ​​of one bit of all the rules stored in the block rule table are all 1, then the value of the bit of the common rule corresponding to the block rule table is set to 1;

[0093] If the values ​​of one bit of all the rules stored in the block rule table are all 0, then the value of the bit of the common rule corresponding to the block rule table is set to 0;

[0094] If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

[0095] In a third aspect, an embodiment of the present application further provides a forwarding chip, which is used to execute any of the above-mentioned packet classification method steps.

[0096] In a fourth aspect, an embodiment of the present application further provides an electronic device with a packet classification function, comprising a processor and a forwarding chip provided in the third aspect; the processor constructs a common rule table in the TCAM and a main rule table and a block rule table in the RAM based on a global rule set; the forwarding chip executes any of the above-mentioned packet classification method steps based on the common rule table, the main rule table and the block rule table.

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

[0098] In the technical solution provided in the embodiment of the present application, a TCAM and a RAM are provided in an electronic device with a packet classification function. The electronic device stores common rules of multiple rules in the TCAM and stores specific rules in the RAM, which can reduce the demand for TCAM capacity. The electronic device uses the common rules stored in the TCAM with higher search performance to exclude most of the rules; subsequently, the remaining rules after exclusion in the RAM are used 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.

[0099] 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

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

[0101] Figure 1 A schematic diagram of a structure of an electronic device in the related art;

[0102] Figure 2 A flowchart of a rule search method in the related art;

[0103] Figure 3 A schematic diagram of a first flow chart of a packet classification method provided in an embodiment of the present application;

[0104] Figure 4 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;

[0105] Figure 5a A first schematic diagram of the data structure of a check block provided in an embodiment of the present application;

[0106] Figure 5b A second schematic diagram of the data structure of the check block provided in an embodiment of the present application;

[0107] Figure 5c A third schematic diagram of the data structure of the check block provided in the embodiment of the present application;

[0108] Figure 6 A schematic diagram of valid data and unimportant data in a check block provided in an embodiment of the present application;

[0109] Figure 7 A second flow chart of the packet classification method provided in the embodiment of the present application;

[0110] Figure 8 A schematic diagram of a flow chart of rule search provided in an embodiment of the present application;

[0111] Fig. 9 A schematic diagram of generating a common rule provided in an embodiment of the present application;

[0112] Fig.10 A first flow chart of a method for generating a common rule table, a main rule table and a block rule table provided in an embodiment of the present application;

[0113] Fig.11A schematic diagram of a rule set provided in an embodiment of the present application;

[0114] Fig.12 A schematic diagram of a rule decision tree provided in an embodiment of the present application;

[0115] Fig.13 is a detailed schematic diagram of step S1001;

[0116] Fig.14 A first flow chart of a method for generating a common rule table, a main rule table and a block rule table provided in an embodiment of the present application;

[0117] Fig.15 A schematic diagram of the first structure of the packet classification device provided in the embodiment of the present application;

[0118] Fig.16 A second structural diagram of the packet classification device provided in an embodiment of the present application;

[0119] Fig.17 A schematic diagram of the structure of an electronic device with a packet classification function provided in an embodiment of the present application. DETAILED DESCRIPTION

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

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

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

[0123] Packet classification is a method of finding the best matching rule in a rule set for each arriving data packet according to a predefined rule set. A rule set is composed of multiple rules, and each rule consists of three parts: the first part is the judgment predicate expression (Predicate) corresponding to the packet header, referred to as expression, which can be a prefix, range, exact value, and wildcard (*). The first part is the matching domain of the rule. According to the type of value in the first part, such as prefix, range, exact value, and wildcard, the matching domain can include prefix domain (also called prefix class field), exact value domain (also called exact class field), range domain (also called range class field), wildcard domain (also called wildcard class field), etc.; the second part is the execution action (Action) after the rule is matched, that is, the action domain of the rule, which is used to indicate the next operation on the data packet, such as forwarding the data packet or discarding the data packet; the third part is the rule priority (Priority), and the rules in the rule set are arranged in descending order according to priority.

[0124] A packet classifier is provided in an electronic device having a packet classification function, such as Figure 1 As shown, the packet classifier integrates the packet classification processing operations performed by the processor and the forwarding engine, as well as the rule set required for the packet classification processing operations. The processor and the forwarding engine perform packet classification processing based on the rule set stored in the packet classifier and the information in the data packet header. Figure 1 In the example, the rule set may be a set of rules including a matching domain and an action domain stored in a table such as an ACL (Access Control Lists), a flow table, a forwarding table, and a routing table.

[0125] TCAM is a customized memory. Traditional RAM memory searches for the content of a storage unit according to a given address, while TCAM determines whether there is a storage unit that matches the content among all storage units according to the given content. TCAM is developed on the basis of CAM (Content Addressable Memory). Unlike the bit unit in CAM that only supports two states, "0" or "1", TCAM also has a "don't care" state, so it is called "three-state". It realizes "three-state" through masking. It is this third state feature of TCAM that enables it to perform both exact match search and fuzzy match search. The rules in the TCAM table entry are stored in order from high to low priority. All data in the entire table entry space are queried at the same time. The search speed is not affected by the size of the data in the table entry space, and one search is completed in each clock cycle.

[0126] The prefix class field, exact class field, range class field and wildcard class field in the matching domain of the rule can be directly converted into the form of key value and mask. 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 indicates concern, and 0 indicates no concern. Among them, the conversion of the range class field is relatively complex. The range class field needs to be divided into several continuous and uninterrupted sub-ranges, so that each sub-range can be equivalently represented as a prefix, and the value set of all sub-ranges is exactly the same as the original range class field value set. In this way, each sub-range can independently constitute a rule completely represented by key and mask, and directly stored in TCAM. For example, for the range class field [2, 5], the range class field 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 001*, and the sub-range [4, 5] can be equivalently represented by the binary prefix 010*. Among them, * is a wildcard, and the bit of * can be 0 or 1.

[0127] For a range class field with a bit width of W, at most 2W-2 encoding prefixes are required for equivalent representation. The number of prefixes 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.

[0128] The rule matching method combining key and mask is suitable for TCAM storage. After each field of each rule is converted into the form of key and mask, it is organized into a complete key and mask in the agreed order and directly stored in TCAM; when searching for rules, the fields of the received data packet are organized into a search key in the agreed order, and the search key is input into TCAM for search, and the result can be directly obtained. Figure 2 In the search process shown in the figure, the value of the search key is matched with the N rules stored in the TCAM, and the corresponding matching result is output to the priority encoder through the matching line corresponding to each rule; the priority encoder selects the rule with the highest priority from the matched rules, encodes and outputs the index, obtains the output result from the RAM (Random Access Memory) through the index, that is, the action corresponding to the rule, and processes the data packet according to the obtained action, such as forwarding the data packet or discarding the data packet.

[0129] By using TCAM, electronic devices can quickly find the required rules, improve rule matching efficiency, and improve packet classification efficiency. However, as a customized memory, TCAM is expensive, has small capacity, and high power consumption, which to a certain extent increases the cost and power consumption of packet classification.

[0130] In order to solve the above-mentioned problem of high packet classification cost and high power consumption, an embodiment of the present application provides a packet classification method, which is applied to an electronic device with a packet classification function, and the electronic device can be an electronic device such as a switch, a router, a firewall, etc. For ease of understanding, the electronic device with a packet classification function is referred to as an electronic device below.

[0131] In the packet classification method provided in the embodiment of the present application, a TCAM and a RAM are provided in the electronic device, and 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. In actual measurement, the packet classification method provided in the embodiment of the present application can use a 2K*40B (bit) TCAM to implement 32K*40B rule storage, while if the TCAM is used to directly store 32K*40B rules, a 32K*40B TCAM space is required. In addition, in the packet classification method provided in the embodiment of the present application, the electronic device uses the common rules stored in the TCAM with higher search performance to exclude most of the rules; and subsequently uses the remaining rules after exclusion in the RAM to perform packet classification processing on the data packets to be classified. Compared with the method of implementing packet classification by purely using TCAM to store rules, the packet classification method provided in the embodiment of the present application combines TCAM and RAM to complete packet classification processing, and can use a smaller TCAM capacity to implement larger-scale rule search, saving the cost and power consumption of packet classification.

[0132] In addition, after the electronic device finds the required public rules from the public rule table in the TCAM, it accesses the corresponding main rule table in the RAM, and then accesses the corresponding block rule table. Taking the number of public rule tables as N as an example, the number of main rule tables is also N, and the number of times the electronic device accesses the RAM is at worst 2N times, that is, the number of memory accesses is at worst 2N times, and the number of memory accesses will not change with the change of rule specifications; while the number of memory accesses for pure software algorithms to search for rules often increases with the increase of rules and matching domains. In the process of rule search, memory access is often the most time-consuming, so compared with pure software algorithms, the technical solution provided in the embodiment of the present application can provide higher search performance.

[0133] The following describes in detail the packet classification method provided in the embodiment of the present application through specific examples.

[0134] See also Figure 3 , Figure 3 The first flow chart of the packet classification method provided in the embodiment of the present application is applied to an electronic device with a packet classification function. The electronic device is provided with a TCAM and a RAM, a public rule table is stored in the TCAM, and a main rule table and a block rule table are stored in the RAM; a plurality of rules with the same public rule are stored in the block 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 rule table stores public rules, and the index of the public rule table and the main rule table corresponding to the same block rule table is the same.

[0135] 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: Figure 4 As shown in the figure, the index is used to indicate the position of the entry in the table.

[0136] 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 Figure 4In the embodiment of the present application, multiple rules in a block rule table constitute a rule block.

[0137] A TCAM table has a corresponding master rule table stored in RAM, such as Figure 4 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 Figure 4 The primary index in .

[0138] The multiple rules included in a rule block constitute a block rule table and are stored in RAM, such as Figure 4 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 Figure 4 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 Figure 4 The sub-index in .

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

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

[0141] Table 1

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

[0143] In Table 1, 10.0.8.3 / 24, 10.1.6.20 / 16, 10.1.0.0 / 16, and 10.1.8.15 / 24 are prefix values, belonging to the prefix field; 0-1024 and 0-2048 are range fields; 22 and 80 are exact values, belonging to the exact field; and * is a wildcard, belonging to the wildcard field.

[0144] In the embodiment of the present application, 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 other bits are set to wildcards. For example, in rule R2 shown in Table 1, the source IP is 10.0.3.8 / 24, which belongs to the prefix class field, and its prefix length is 24, and the prefix value is 10.0.3. Then, in the prefix class field of the source IP included in the rule, the values ​​of the 24 highest bits are set to the prefix value (i.e., 10.0.3), and the values ​​of other bits are set to *. At this time, in rule R2, the source IP can be expressed as 10.0.3.*, which is expressed in binary as: 0000 1010.0000 0000.0000011.********, as shown in Table 2.

[0145] Table 2

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

[0147] For the range type field included in the rule, the range type field is divided into multiple continuous and uninterrupted sub-ranges, and the value of the bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range. The specific equivalent representation method can be found in the description in the above-mentioned related technology, which will not be repeated here.

[0148] 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 1, the source port is the precise value 80, which belongs to the precise class field. Therefore, in the precise class field of the source port included in the rule, the value of each bit is set to 80. At this time, in rule R2, the source port can be represented as 80, which is represented in binary as: 0101 0000.

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

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

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

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

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

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

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

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

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

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

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

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

[0161] Based on the above rules, as well as the common rule table stored in the TCAM and the main rule table and block rule table stored in the RAM, Figure 3 As shown, the packet classification method provided in the embodiment of the present application includes the following steps:

[0162] Step S301: extracting target search key values ​​from the data packet to be classified.

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

[0164] For example, the key information is a quintuple, namely the source IP, destination IP, source port, destination port and transmission protocol, and the search key consists of a quintuple; if the electronic device extracts the source IP as 10.1.0.0, the destination IP as 20.1.0.1, the source port as 8080, the destination port as 8081, and the transmission protocol as TCP (Transmission Control Protocol), then an example of the electronic device's search key composition can be 10.1.0.0-8080-20.1.0.1-8081-TCP.

[0165] In an embodiment of the present application, the order of the fields in the search key is not limited, as long as the order of the fields in the search key is consistent with the order of the fields in the rule. For example, the rule includes four fields: source IP, destination IP, source port, and destination port. The order of these four fields is: source IP→destination IP→source port→destination port; then the order of the fields in the search key is also: source IP→destination IP→source port→destination port.

[0166] Step S302: Use the target search key value to perform a match in the public rule table to obtain the primary index of the target entry in the main rule table.

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

[0168] Step S303: locate the block rule table based on the base address included in the target table entry pointed to by the primary index.

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

[0170] Step S304: Determine the secondary index of the first rule in the located block rule table based on the target search key value and the split position set included in the target table entry pointed to by the primary index.

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

[0172] The execution order of step S303 and step S304 is not limited in the embodiment of the present application.

[0173] Step S305: classify the data packet to be classified based on the first rule pointed to by the secondary index.

[0174] The electronic device reads the first rule corresponding to the secondary index in the block rule table located in step S303, and performs packet classification processing on the data packet to be classified according to the action field in the first rule, such as forwarding the data packet to be classified, or discarding the data packet to be classified.

[0175] In an embodiment of the present application, N TCAM tables may be stored in the electronic device, where N is greater than or equal to 1. For each TCAM table, the electronic device may obtain a first rule based on the TCAM table, the main table corresponding to the TCAM table, and the Block table corresponding to the TCAM table. In this way, the electronic device may obtain at most N first rules for the N TCAM tables.

[0176] In this case, the electronic device can select a first rule with the highest priority from the N rules obtained to perform packet classification processing on the data packet to be classified. In the embodiment of the present application, the electronic device can also select a rule from the N rules obtained in other ways to perform packet classification processing on the data packet to be classified, which is not limited to this.

[0177] In some embodiments, to ensure the accuracy of packet classification processing, after obtaining a first rule from the Block table, the electronic device verifies the first rule and the target search key; if the verification result indicates that the first rule and the target search key match, the packet classification processing is performed on the data packet to be classified according to the first rule obtained from the block table. When multiple first rules are obtained, the electronic device selects the rule with the highest priority from the N first rules whose verification results indicate that they match the target search key, and then performs packet classification processing on the data packet to be classified. If the verification result indicates that the first rule and the target search key do not match, the electronic device refuses to use the first rule and performs packet classification processing on the data packet to be classified.

[0178] In an embodiment of the present application, the electronic device performs an integrity check or a locality check on the first rule and the target search key.

[0179] During the integrity check, the block rule table fully stores the matching domain of each rule, that is, the key and mask of each rule are fully stored; the electronic device compares each bit of the target search key, the key of the first rule, and the mask, and determines whether the first rule and the target search key match based on the comparison result. Here, the first rule and the target search key match when each bit of the first rule and the target search key meets any of the following conditions:

[0180] Case 1: Same bit, mask of the first rule = 0;

[0181] Case 2: Same bit, mask of the first rule = 1, key of the first rule = 0, target search key = 0;

[0182] Case 3: Same bit position, mask of the first rule = 1, key of the first rule = 1, target search key = 1.

[0183] Otherwise, if any bit does not satisfy any of the above conditions, the first rule and the target search key do not match.

[0184] During locality verification, the block rule table compresses and stores the matching domain of each rule, that is, compresses and stores the key and mask of each rule. For example, a rule in the block rule table is compressed into at least one check block. The types of check blocks include mask type and non-mask type. The check block of mask type includes key and mask. The check block of non-mask type includes key with continuous effective bits, and the effective bit is the bit with mask as 1.

[0185] For different types of checksum data structures, see Figure 5a-5c shown. Figure 5aThe data structure of the check block of the mask type has a length of 32 bits, of which 2-0 bits store the code of the check block type, 15-3 bits store the mask, 28-16 bits store the key, and 31-29 bits store the offset of the starting bit of the key within a byte of the rule to which it belongs.

[0186] Figure 5b It is a data structure of a non-mask type check block. The length of the check block is 32 bits, of which 2-0 bits store the code of the check block type, and 31-3 bits store the key. The key is the data that matches the target search key. The key can occupy the entire 31-3 bits or only a part of it. That is, the maximum length of the key stored in 31-3 bits is 29 bits. Figure 5b The longest matching data in .

[0187] To distinguish valid data from unimportant data in the check block, the key is stored in the high bit of the check block, and the low bit not occupied by the key is filled with unimportant data. The value of a bit adjacent to the valid data in the unimportant data is set to 0, and the values ​​of other bits in the unimportant data are set to 1, such as Figure 6 shown.

[0188] Figure 5c It is another data structure of non-mask type check block. The length of the check block is 32 bits, of which 2-0 bits store the code of the check block type, 28-3 bits store the key, and 31-29 bits store the offset of the starting bit of the key within a byte of the rule to which it belongs. Among them, the key is the data that matches the target search key, and the key can occupy the entire 28-3 bits, such as Figure 5c The longest matching data in the 28-3 bit can also occupy only part of it, that is, the maximum length of the key stored in 28-3 bits is 26 bits. For the storage method of data in 28-3 bits, see Figure 6 shown.

[0189] In the embodiment of the present application, for a non-mask type check block, all its bits can also be used to store keys, that is, a 32-bit key is stored in a 32-bit check block, and this is not limited.

[0190] Based on the above check blocks, for each check block included in the first rule, the electronic device determines the length of the data to be matched according to the type of the check block; according to the starting bit of the data included in the check block, starting from the same starting bit in the target search key, extracts the data to be matched according to the length of the data to be matched, and matches the data to be matched with the data included in the check block; if the target search key matches all the check blocks in the rule to be matched successfully, it is determined that the target search key matches the first rule; otherwise, it is determined that the target search key does not match the first rule. Among them, the length of the data to be matched is the length of the key stored in the check block. Different types of check blocks have different lengths of stored keys. Therefore, the electronic device determines the length of the data to be matched according to the type of the check block to correctly extract the data to be matched from the target search key and accurately complete the matching of the data to be matched with the data included in the check block.

[0191] During locality verification, for a mask-type check block, the check block and the data to be matched match when each bit of the check block and the data to be matched meets any of the following conditions:

[0192] Case 1: Same bit, check block mask = 0;

[0193] Case 2: Same bit, check block mask = 1, check block key = 0, data to be matched = 0;

[0194] Case 3: Same bit, mask of check block = 1, key of check block = 1, and that of the data to be matched = 1.

[0195] Otherwise, if any bit does not satisfy any of the above conditions, the check block and the data to be matched do not match, and the target search key does not match the first rule.

[0196] For a non-mask check block, the check block and the data to be matched match when each bit of the check block and the data to be matched meets any of the following conditions:

[0197] Case 1: Same bit, key of check block = 0, key of data to be matched = 0;

[0198] Case 2: Same bit, key of check block = 1, key of data to be matched = 1.

[0199] Otherwise, if any bit does not satisfy any of the above conditions, the check block and the data to be matched do not match, and the target search key does not match the first rule.

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

[0201] In some embodiments, a physical table is also stored in the TCAM, and at least one rule is stored in the physical table. Through the physical table, the electronic device can store redundant rules in the physical table, so that the electronic device can match the target search key with all the rules in the electronic device to obtain the rule that truly matches the target search key. The above redundant rules are rules other than the rules included in the block rule table, that is, rules that cannot form a rule block with the rules in the block rule table.

[0202] based on Figure 3 The embodiment shown in the figure, and the physical table stored in the above TCAM, the embodiment of the present application also provides a packet classification method, such as Figure 7 As shown, Figure 7 A second flow chart of a packet classification method provided in an embodiment of the present application is provided. The method is applied to an electronic device. The packet classification method may include steps S701-S707.

[0203] Step S701, extracting a target search key value from the data packet to be classified. Step S701 is the same as step S301.

[0204] Step S702: Use the target search key value to perform a match in the physical table to obtain a second rule.

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

[0206] Step S703, use the target search key value to perform a match in the public rule table to obtain the primary index of the target entry in the main rule table. Step S703 is the same as step S302.

[0207] The embodiment of the present application does not limit the execution order of step S702 and step S703.

[0208] Step S704: Locate the block rule table based on the base address included in the target table entry pointed to by the primary index. Step S704 is the same as step S303.

[0209] Step S705, based on the target search key value and the split position set included in the target table entry pointed to by the primary index, determine the secondary index of the first rule in the located block rule table. Step S705 is the same as step S304.

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

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

[0212] In some embodiments, the above step S706 may be: based on the target search key value, respectively verify the first rule and the second rule pointed to by the secondary index; and select the rule with the highest priority from the rules that match the target search key value determined by the verification. The verification here may be an integrity check or a locality check. For the specific verification process, please refer to the relevant description of the above step S305.

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

[0214] Step S707: classify the data packets to be classified according to the selected rules.

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

[0216] In the technical solution provided by the embodiment of the present application, 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. In addition, the electronic device directly stores a part of the rules in the TCAM physical table, and the electronic device uses the common rule table and the physical table to complete the search for matching rules from all rules, which saves the cost and power consumption of packet classification and improves the integrity of rule search during packet classification.

[0217] Combine the following Figure 8 The rule search process shown is a detailed description of the packet classification method provided in the embodiment of the present application.

[0218] The TCAM in the electronic device stores N TCAM tables, such as Figure 8 The TCAM tables 1-N shown in FIG. 1 also store a physical table in the TCAM; the RAM stores N main tables, such as Figure 8 The main tables 1-N shown in FIG. 1 correspond to the N TCAM tables one by one. The RAM also stores multiple Block tables, such as Figure 8 The Block tables 1-X, ..., block tables NX are shown, where x = 1, 2, ..., n, and one main table corresponds to n Block tables.

[0219] The electronic device extracts the search key from the acquired data packet, uses the search key to match in the TCAM table 1-N, and obtains the corresponding index 1-N; respectively searches for the table entries corresponding to the indexes 1-N from the main table 1-N, and obtains the base address and split position set of the Bock table from the table entries corresponding to the indexes 1-N; based on the split position set, the electronic device can determine the offset of the required rule in the Block table, and the base address and offset of the Block table constitute the address of the rule, such as Figure 8 The electronic device uses the addresses 1-N to obtain rules from the Block table 1-X, ..., Bock table NX, respectively, such as Figure 8 Results 1-N are shown. One result consists of one rule.

[0220] In addition, the electronic device uses the lookup key to match in the physical table and obtains a rule such as Figure 8 The result N+1 is shown.

[0221] The electronic device selects the result with the highest priority from the N+1 results, such as Figure 8 The electronic device performs packet classification processing on the data packets according to the best result.

[0222] In some embodiments, for each block rule table, the common rules corresponding to the block rule table may be generated in the following manner:

[0223] If the values ​​of one bit of all rules stored in the block rule table are all 1, then the value of the bit of the common rule corresponding to the block rule table is set to 1;

[0224] If the values ​​of one bit of all rules stored in the block rule table are all 0, then the value of the bit of the public rule corresponding to the block rule table is set to 0;

[0225] If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

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

[0227] In the embodiment of the present application, the bit width of the common rule is the same as the bit width of the rule. When all the bits of the common rule are set, the common rule is generated. The generated common rule is stored in the TCAM, and a corresponding main rule table entry and a block rule table storing all rules corresponding to the common rule are established in the RAM. For specific storage rules, please refer to the above Figure 3 Part of the description.

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

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

[0230] In some embodiments, the present application also provides a method for generating a common rule table, a main rule table, and a block rule table, such as Fig.10 As shown, Fig.10 A first flow chart of a method for generating a common rule table, a main rule table, and a block rule table provided in an embodiment of the present application, the method may include the following steps:

[0231] Step S1001, constructing a rule decision tree based on the balance bit of each rule in the global rule set, 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.

[0232] A rule may include a matching domain and an action domain, such as rules in ACL (Access Control Lists), flow tables, forwarding tables, and routing tables. In the embodiment of the present application, the electronic device uses all rules with matching domains and action domains as a global rule set, and considering the entire rule, the electronic device determines the balance bit of the rules in the global rule set, and 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.

[0233] For example, the rule set in the electronic device includes Fig.11 The five rules R1-R5 shown are from Fig.11 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.

[0234] The electronic device constructs a rule decision tree based on the balance position of each rule in the global rule set. Among them, the rule decision tree can be implemented by a decision tree in the form of a binary tree. The rule decision tree in the form of a binary tree is used to manage the rule set, so that the technical solution provided by the embodiment of the present application is more general and has nothing to do with specific applications. In the embodiment of the present application, the electronic device can also use other forms of rule decision trees, which are not limited to this.

[0235] Before executing step S1001, in order to ensure the accuracy of rule processing, the electronic device may perform the following processing on each rule in the global rule set:

[0236] 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;

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

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

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

[0240] Step S1002, starting from each leaf node of the rule decision tree, traverse upward in breadth-first order to obtain the deepest rule subtree corresponding to each leaf node, the deepest rule subtree being the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth.

[0241] A maximum number of split bits is preset in the electronic device, that is, a preset split bit depth, which is the maximum number of bits included in the split position set. The size of the preset number can be set according to actual needs.

[0242] After a rule decision tree is constructed, for each leaf node of the rule decision tree, the electronic device traverses upward from the leaf node in a breadth-first manner. When traversing to a node of the rule decision tree, this node is used as the root node to form a subtree; if the electronic device determines that the subtree is the deepest subtree whose number of balance bits is less than or equal to the preset split bit depth, the subtree is used as the deepest rule subtree and the upward traversal is stopped; otherwise, this node is used as the starting point to continue the upward traversal.

[0243] When all leaf nodes of the rule decision tree belong to a deepest rule subtree respectively, the electronic device stops executing the above step S1002.

[0244] Step S1003: Generate a common rule table, a main rule table and a block rule table based on each deepest rule subtree.

[0245] In the embodiment of the present application, after the electronic device executes step S1002, it obtains one or more deepest rule subtrees, and generates a block rule table based on the rule set included in each deepest rule subtree; generates a split position set based on the balance bit included in each deepest rule subtree; generates a main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table; generates a common rule table based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

[0246] Among them, all the rules included in a deepest rule subtree constitute a block rule table, that is, a rule block. For a deepest rule subtree, the electronic device generates a block rule table from the rule set included in the deepest rule subtree; generates a split position set from the balance bits included in other nodes except the root node of the deepest rule subtree; generates an entry in the main rule table from the split position set corresponding to the deepest rule subtree and the base address of the block rule table; generates an entry in the public rule table from the common rules of the rule set included in the deepest rule subtree, and the index of the entry in the public rule table corresponding to the deepest rule subtree is the same as the index of the entry in the main rule table corresponding to the deepest rule subtree. A main rule table is generated from the entries in the main rule table corresponding to all the deepest rule subtrees included in a rule decision tree; a public rule table is generated from the entries in the public rule table corresponding to all the deepest rule subtrees included in a rule decision tree.

[0247] For example, the default split bit depth is 3, such as Fig.12The rule decision tree shown in the figure, where R0-R3 represent the rules included in the leaf nodes, and P0-P6 represent the balance bits included in the nodes. The electronic device traverses upward from the leaf node R0 in a breadth-first manner, traverses to the node P2, and takes P2 as the root node to form a subtree. The subtree includes rules R0 and R1. The number of balance bits included in the subtree is 0, 0<3. Continuing to take node P2 as the starting point, continue to traverse upward to bit position P1, and take P1 as the root node to form a subtree. The balance bits included in the subtree are: P2 and P3, and the corresponding rules are: rules R0-R3. At this time, the number of balance bits included in the subtree is 2, 2<3. If the node P1 is taken as the starting point, the subtree is continued. Continue to traverse upward, the number of balancing bits included in the formed subtree must be greater than 3. Therefore, the subtree formed with node P1 as the root node is the deepest rule subtree with the number of balancing bits not greater than 3. The split position set of the deepest rule subtree is {P2, P3}, and the rules R0-R3 are stored in a block rule table 1. Based on the split position set {P2, P3} and the base address of the block rule table 1, an entry 1 in the main rule table is generated; based on the index of the entry 1 in the main rule table and the common rules of the rules R0-R3, an entry 2 in the common rule table is generated.

[0248] In the embodiment of the present application, the electronic device uses the above steps S1001-S1003 to generate and determine the common rule table, the main rule table and the block rule table. In order to avoid the problem of repeated storage of rules, a balance bit is recorded only once in all the split positions of a rule decision tree. In this way, the capacity of TCAM and RAM can be effectively utilized, saving costs.

[0249] In the technical solution provided by the embodiment of the present application, the electronic device can extract more common information of the rules by using the rule decision tree, thereby saving costs, reducing the difficulty of finding the rules, and improving the search efficiency.

[0250] In some embodiments, Fig.13 As shown, the above step S1001 can be refined into the following steps:

[0251] Step S1301: Use the global rule set as the rule set to be split, and the global rule set is included in the root node of the rule decision tree.

[0252] Step S1302, determining the balance bit of each rule in the rule set to be split. The method of determining the balance bit in step S1302 can refer to the relevant description of step S1001.

[0253] Step S1303: add the rule whose balance bit value is 0 in the to-be-split rule set to the first side child node, and add the rule whose balance bit value is 1 in the to-be-split rule set to the second side child node.

[0254] Taking the rule decision tree in the form of a binary tree as an example, the first side is left and the second side is right, or the first side is right and the second side is left. Taking the first side as left and the second side as right as an example, combined with Fig.11 Take this as an example. The electronic device determines that the balance bit is P2, divides the rules R2 and R5 with the value of the bit P2 as 0 into a rule set 1, and adds the rule set 1 to the left child node of the rule decision tree; divides the rules R1 and R4 with the value of the bit P2 as 1 into a rule set 2, and adds the rule set 2 to the right child node of the rule decision tree. At this point, the splitting of one rule set into two rule sets is completed.

[0255] In the embodiment of the present application, there is a case where the value of the balance bit is "*", such as Fig.11 In the example, the value of the balance bit P2 of rule R3 is "*". In this case, the electronic device does not process such rules at all, and such rules can also be added to the discard rule set for subsequent processing. There is no limitation on this.

[0256] Step S1304: for each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and step S1302 is re-executed until each child node obtained by splitting includes one rule, thereby obtaining a rule decision tree.

[0257] In the embodiment of the present application, the electronic device executes steps S1302-S1304 in a loop, and the condition for the loop to end is: the child node obtained by splitting includes a rule. A rule decision tree in the form of a binary tree is used to manage the rule set, and a leaf node of the rule decision tree includes a rule. Fig.12 The structure of a rule decision tree is shown, and each of the four leaf nodes R0-R3 of the rule decision tree includes only one rule.

[0258] In the embodiment of the present application, the electronic device uses the above steps S1301-S1304 to construct a rule decision tree, and then the rule decision tree can generate a common rule table, a main rule table and multiple block rule tables. In the technical solution provided by the embodiment of the present application, the electronic device can extract more common information of the rules by using the rule decision tree, while saving costs, reducing the difficulty of finding rules and improving the search efficiency.

[0259] In some embodiments, the electronic device may also evenly divide the global rule set into multiple rule sets, each rule set includes multiple rules stored as a block rule table, and extract the common rules of this block rule table and the corresponding split position set to generate the corresponding common rule table and main rule table.

[0260] In some embodiments, in order to improve the accuracy of packet classification, based on the above Fig.10 The embodiment shown in the embodiment of the present application also provides a method for generating a common rule table, a main rule table and a block rule table, such as Fig.14 As shown, Fig.14 A second flow chart of a method for generating a common rule table, a main rule table, and a block rule table provided in an embodiment of the present application, the method may include the following steps:

[0261] Step S1401: construct a rule decision tree based on the balance bit of each rule in the global rule set, 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. This is the same as the above step S1001.

[0262] Step S1402, starting from each leaf node of the rule decision tree, traverse upward in breadth-first order to obtain the deepest rule subtree corresponding to each leaf node, the deepest rule subtree being the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth. This is the same as the above step S1002.

[0263] Step S1403: Generate a common rule table, a main rule table and a block rule table based on each deepest rule subtree, which is the same as the above step S1003.

[0264] Step S1404: divide the rules whose balance bit values ​​in the global rule set are wildcards into a discard rule set.

[0265] Step S1405, if the number of constructed rule decision trees is less than N, the discard rule set is used as the global rule set, and step S1401 is re-executed until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of TCAM.

[0266] In the embodiment of the present application, each time a rule decision tree is generated, a discard rule set is generated based on the rule whose balance bit value is *. The electronic device re-splits the discard rule set to construct a new rule decision tree. In this way, the electronic device can store N public rule tables in the TCAM and search for rules of N rule decision trees at the same time, thereby improving the efficiency of rule search.

[0267] In the embodiment of the present application, in order to improve the search efficiency as much as possible, N=C-1, where C represents the maximum concurrent number of TCAM.

[0268] In some embodiments, after constructing N rule decision trees, the electronic device adds the rules in the current discard rule set to the physical table.

[0269] In this way, the subsequent electronic device can complete the search for all rules, ensuring the integrity of the rule search, thereby improving the accuracy of the found rules and the accuracy of the packet classification processing.

[0270] Corresponding to the above-mentioned packet classification method, the embodiment of the present application also provides a packet classification device, such as Fig.15 As shown, the device is applied to an electronic device with a packet classification function, wherein a TCAM and a RAM are provided in the electronic device, a public rule table is stored in the TCAM, and a main rule table and a block rule table are stored in the RAM;

[0271] A plurality of rules having the same common rule are stored in the block rule table;

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

[0273] The common rule table stores common rules, and the common rule table has the same index as the main rule table corresponding to the same block rule table;

[0274] The above-mentioned packet classification device comprises:

[0275] An extraction module 151 is used to extract a target search key value from a data packet to be classified;

[0276] A first matching module 152, 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 primary rule table;

[0277] A positioning module 153, configured to locate the block rule table based on a base address included in a target table entry pointed to by a primary index;

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

[0279] The processing module 155 is used to perform packet classification processing on the data packet to be classified based on the first rule pointed to by the secondary index.

[0280] In some embodiments, a physical table is also stored in the TCAM, and at least one rule is stored in the physical table; Fig.16 As shown, the above-mentioned packet classification device may further include a second matching module 156;

[0281] A second matching module 156, configured to use the target lookup key value to perform matching in the physical table to obtain a second rule;

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

[0283] In some embodiments, the processing module 155 can be specifically used to verify the first rule and the second rule pointed to by the secondary index based on the target search key value; and select the rule with the highest priority from the rules that match the target search key value determined by the verification.

[0284] In some embodiments, the packet classification device may further include a first generating module, which is used to generate a common rule table, a main rule table and a block rule table, including:

[0285] A construction submodule is used to construct a rule decision tree based on the balance bit of each rule in the global rule set, 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;

[0286] A traversal submodule is used to traverse upward from each leaf node of the rule decision tree in a breadth-first manner to obtain the deepest rule subtree corresponding to each leaf node, wherein the deepest rule subtree is the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth;

[0287] The generation submodule is used to generate a common rule table, a main rule table and a block rule table based on each deepest rule subtree.

[0288] In some embodiments, the generating submodule may be specifically used for:

[0289] Based on the rule sets included in each deepest rule subtree, a block rule table is generated respectively;

[0290] Based on the balance bits included in each deepest rule subtree, a split position set is generated respectively;

[0291] Generate a main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table;

[0292] A common rule table is generated based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

[0293] In some embodiments, the construction submodule may be specifically used to:

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

[0295] Determine the balance position of each rule in the rule set to be split;

[0296] Add the rule whose balance bit value is 0 in the rule set to be split to the first side child node, and add the rule whose balance bit value is 1 in the rule set to be split to the second side child node;

[0297] For each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and the step of determining the balance position of the rules in the rule set to be split is re-executed until each child node obtained by splitting includes one rule, thereby obtaining a rule decision tree.

[0298] In some embodiments, the first generation module may further include a division submodule;

[0299] A partitioning submodule, used for partitioning the rules whose balance bit value is a wildcard in the global rule set into a discarding rule set;

[0300] The construction submodule is also used to discard the rule set as the global rule set if the number of constructed rule decision trees is less than N, and re-execute the step of constructing the rule decision tree based on the balance bit of each rule in the global rule set until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of TCAM.

[0301] In some embodiments, a physical table is also stored in the TCAM, and the first generation module may further include an adding submodule;

[0302] Add a submodule to add the rules in the current discard rule set to the physical table after building N rule decision trees.

[0303] In some embodiments, the rule may include at least one of a prefix class field, a range class field, an exact class field, and a wildcard class field;

[0304] The packet classification device may further include: a setting module, which is used to perform the following processing on each rule in the global rule set before constructing a rule decision tree based on the balance bit of each rule in the global rule set:

[0305] 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;

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

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

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

[0309] In some embodiments, the packet classification device may further include a second generation module for generating common rules, which may be specifically used for:

[0310] If the values ​​of one bit of all rules stored in the block rule table are 1, the value of the bit of the common rule corresponding to the block rule table is set to 1;

[0311] If the values ​​of one bit of all rules stored in the block rule table are all 0, then the value of the bit of the common rule corresponding to the block rule table is set to 0;

[0312] If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

[0313] In the technical solution provided 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; subsequently, the remaining rules after exclusion in the RAM are used 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.

[0314] The present application also provides a forwarding chip, which is used to perform the above Figure 3-14 Any of the steps of the packet classification method described above.

[0315] The present application also provides an electronic device with a packet classification function, such as Fig.17 As shown, it includes a processor 171 and a forwarding chip 172; the processor 171 builds a common rule table in the TCAM and a main rule table and a block rule table in the RAM based on the global rule set; the forwarding chip 172 executes any of the above-mentioned packet classification method steps based on the common rule table, the main rule table and the block rule table.

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

[0317] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

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

[0319] 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 and electronic device 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.

[0320] 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 packet classification method, characterized in that: Applicable to an electronic device with a packet classification function, wherein the electronic device is provided with a ternary content addressable memory TCAM and a random access memory RAM, wherein the TCAM stores a public rule table, and the RAM stores a main rule table and a block rule table; The block rule table stores a plurality of rules having the same common rule; The main rule table includes at least two fields: a split position set and a base address. The rules in the block rule table belong to a subtree determined by the split position set. The split position set is used to locate the position of the rule corresponding to the key value in the block rule table. The base address is used to locate the block rule table. The value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address. The common rule table stores common rules, and the common rule table has the same index as the main rule table corresponding to the same block rule table; The method comprises: Extract target search key values ​​from the data packets 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 first rule in the located block rule table based on the target search key value and a split position set included in the target table entry pointed to by the primary index; Based on the first rule pointed to by the secondary index, packet classification processing is performed on the data packet to be classified.

2. The method according to claim 1, characterized in that The TCAM also stores a physical table, wherein at least one rule is stored in the physical table; the method further includes: Use the target search key value to perform matching in the physical table to obtain a second rule; The step of performing packet classification processing on the data packet to be classified based on the first rule pointed to by the secondary index comprises: Selecting a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; According to the selected rule, the data packet to be classified is subjected to packet classification processing.

3. The method according to claim 2, characterized in that The step of selecting a rule with the highest priority from the first rule and the second rule pointed to by the secondary index comprises: Based on the target search key value, respectively verify the first rule and the second rule pointed to by the secondary index; From the rules that are verified to match the target search key value, select a rule with the highest priority.

4. The method according to claim 1, characterized in that: The common rule table, main rule table and block rule table are generated in the following manner: Construct a rule decision tree based on the balance bit of each rule in the global rule set, 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; Starting from each leaf node of the rule decision tree, traverse upward in breadth-first order to obtain the deepest rule subtree corresponding to each leaf node, wherein the deepest rule subtree is the deepest rule subtree among the rule subtrees whose number of balance bits is less than or equal to the preset splitting bit depth; Based on each deepest rule subtree, the common rule table, the main rule table and the block rule table are generated.

5. The method according to claim 4, characterized in that The step of generating the common rule table, the main rule table and the block rule table based on each deepest rule subtree comprises: Based on the rule sets included in each deepest rule subtree, a block rule table is generated respectively; Based on the balance bits included in each deepest rule subtree, a split position set is generated respectively; Generate the main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table; The common rule table is generated based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

6. The method according to claim 4, characterized in that The step of constructing a rule decision tree based on the balance position of each rule in the global rule set includes: Using a global rule set as a rule set to be split, wherein the global rule set is included in a root node of a rule decision tree; Determine the balance position of each rule in the rule set to be split; Add the rule whose balance bit value is 0 in the to-be-split rule set to the first side child node, and add the rule whose balance bit value is 1 in the to-be-split rule set to the second side child node; For each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and the step of determining the balance position of the rules in the rule set to be split is re-executed until each child node obtained by splitting includes one rule, thereby obtaining the rule decision tree.

7. The method according to claim 4, characterized in that The method further comprises: Divide the rules whose balance bit value is a wildcard in the global rule set into a discard rule set; If the number of constructed rule decision trees is less than N, the discard rule set is used as the global rule set, and the step of constructing the rule decision tree based on the balance bits of each rule in the global rule set is re-executed until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of the TCAM.

8. The method according to claim 7, characterized in that A physical table is also stored in the TCAM, and the method further includes: After constructing N rule decision trees, the rules in the current discard rule set are added to the physical table.

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

10. The method according to any one of claims 1 to 8, characterized in that: The public rules are generated in the following manner: If the values ​​of one bit of all the rules stored in the block rule table are all 1, then the value of the bit of the common rule corresponding to the block rule table is set to 1; If the values ​​of one bit of all the rules stored in the block rule table are all 0, then the value of the bit of the common rule corresponding to the block rule table is set to 0; If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

11. A packet classification device, characterized in that: Applicable to an electronic device with a packet classification function, wherein the electronic device is provided with a ternary content addressable memory TCAM and a random access memory RAM, wherein the TCAM stores a public rule table, and the RAM stores a main rule table and a block rule table; The block rule table stores a plurality of rules having the same common rule; The main rule table includes at least two fields: a split position set and a base address. The rules in the block rule table belong to a subtree determined by the split position set. The split position set is used to locate the position of the rule corresponding to the key value in the block rule table. The base address is used to locate the block rule table. The value of the non-wildcard bit in the common rule is the same as the value of the same bit of all rules in the block rule table pointed to by the base address. The common rule table stores common rules, and the common rule table has the same index as the main rule table corresponding to the same block rule table; The device comprises: An extraction module, used to extract target search key values ​​from the data packets to be classified; A first matching module, configured to use the target search key value to perform matching in the common rule table to obtain a primary index of a 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 determination module, configured to determine a secondary index of a first rule in a located block rule table based on the target search key value and a split position set included in the target table entry pointed to by the primary index; The processing module is used to perform packet classification processing on the data packet to be classified based on the first rule pointed to by the secondary index.

12. The device according to claim 11, characterized in that The TCAM also stores a physical table, wherein at least one rule is stored in the physical table; the device also includes a second matching module; The second matching module is used to use the target search key value to perform matching in the physical table to obtain a second rule; The processing module is specifically used to select a rule with the highest priority from the first rule and the second rule pointed to by the secondary index; and perform packet classification processing on the data packet to be classified according to the selected rule.

13. The device according to claim 12, characterized in that The processing module is specifically used to verify the first rule and the second rule pointed to by the secondary index respectively based on the target search key value; and select a rule with the highest priority from the rules that match the target search key value determined by the verification.

14. The device according to claim 11, characterized in that The device further includes a first generating module, which is used to generate the common rule table, the main rule table and the block rule table, including: A construction submodule, for constructing a rule decision tree based on the balance bit of each rule in the global 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; A traversal submodule, used to traverse upward from each leaf node of the rule decision tree in a breadth-first manner to obtain the deepest rule subtree corresponding to each leaf node, wherein the deepest rule subtree is the deepest rule subtree among the rule subtrees whose balance bit is less than or equal to the preset split bit depth; A generating submodule is used to generate the common rule table, the main rule table and the block rule table based on each deepest rule subtree.

15. The device according to claim 14, characterized in that The generating submodule is specifically used for: Based on the rule sets included in each deepest rule subtree, a block rule table is generated respectively; Based on the balance bits included in each deepest rule subtree, a split position set is generated respectively; Generate the main rule table based on the split position set corresponding to each deepest rule subtree and the base address of the block rule table; The common rule table is generated based on the table entry index in the main rule table corresponding to each deepest rule subtree and the common rules of the rule set included in each deepest rule subtree.

16. The device according to claim 14, characterized in that The construction submodule is specifically used for: Using a global rule set as a rule set to be split, wherein the global rule set is included in a root node of a rule decision tree; Determine the balance position of each rule in the rule set to be split; Add the rule whose balance bit value is 0 in the to-be-split rule set to the first side child node, and add the rule whose balance bit value is 1 in the to-be-split rule set to the second side child node; For each child node obtained by splitting, if the child node includes multiple rules, the rule set included in the child node is used as the rule set to be split, and the step of determining the balance position of the rules in the rule set to be split is re-executed until each child node obtained by splitting includes one rule, thereby obtaining the rule decision tree.

17. The device according to claim 14, characterized in that The first generation module also includes a division submodule; The division submodule is used to divide the rules whose balance bit value in the global rule set is a wildcard into a discard rule set; The construction submodule is also used to, if the number of constructed rule decision trees is less than N, use the discard rule set as the global rule set, and re-execute the step of constructing the rule decision tree based on the balance bits of each rule in the global rule set until the number of constructed rule decision trees is equal to N, and N is less than the maximum concurrency number of the TCAM.

18. The device according to claim 17, characterized in that The TCAM also stores a physical table, and the first generation module further includes an adding submodule; The adding submodule is used to add the rules in the current discarding rule set to the physical table after constructing N rule decision trees.

19. The device according to any one of claims 14 to 18, characterized in that: The rule includes at least one of a prefix class field, a range class field, an exact class field, and a wildcard class field; The device further includes: a setting module, configured to perform the following processing on each rule in the global rule set before constructing the rule decision tree based on the balance position of each rule in the global rule set: For the prefix class field included in the rule, the value of the highest bit of the prefix length is set to the prefix value, and the values ​​of the other bits are set to wildcards; For the range type field included in the rule, the range type field is split into multiple sub-ranges, and the value of the bit corresponding to each sub-range is set to the equivalent prefix value corresponding to the sub-range; For the exact class fields included in the rule, set the value of each bit to the exact value; For the wildcard class fields included in this rule, set the value of each bit to the wildcard character.

20. The device according to any one of claims 11 to 18, characterized in that The device further includes a second generating module, which is used to generate the common rule, specifically used to: If the values ​​of one bit of all the rules stored in the block rule table are all 1, then the value of the bit of the common rule corresponding to the block rule table is set to 1; If the values ​​of one bit of all the rules stored in the block rule table are all 0, then the value of the bit of the common rule corresponding to the block rule table is set to 0; If the values ​​of one bit of all class rules stored in the block rule table are not all 1, and / or the values ​​of one bit of all rules stored in the block rule table are not all 0, the value of the bit of the public rule corresponding to the block rule table is set to a wildcard.

21. A forwarding chip, characterized in that: The forwarding chip is used to execute the method steps described in any one of claims 1-10.

22. An electronic device with a packet classification function, characterized in that: The method comprises a processor and a forwarding chip as claimed in claim 21; the processor constructs a common rule table in the TCAM and a main rule table and a block rule table in the RAM based on a global rule set; The forwarding chip executes the method steps described in any one of claims 1 to 10 based on the common rule table, the main rule table and the block rule table.