A method for implementing a decision tree based on bitmap

By using bitmap bitmap bitmap marking in the decision tree and deleting empty nodes and the same nodes, the decision tree structure is optimized, and the problem of waste of RAM resources in the existing technology is solved, achieving more efficient resource utilization.

CN113723549BActive Publication Date: 2024-11-22BEIJING ZUOJIANG TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111039665.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-06
Publication Date
2024-11-22
Estimated Expiration
2041-09-06

AI Technical Summary

Technical Problem

In the existing decision tree implementation, the existence of empty nodes and the same nodes leads to wasting RAM resources, affecting system efficiency.

Method used

The decision tree implementation method based on bitmap is adopted, and empty nodes and the same nodes are marked and deleted through empty_bitmap and equal_bitmap bitmap to optimize the decision tree structure, and the optimized decision tree search process is designed.

Benefits of technology

It significantly reduces the use of RAM resources on the FPGA chip by decision tree nodes and improves resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113723549B_ABST
    Figure CN113723549B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for implementing a decision tree based on a bitmap, and belongs to the field of communication technology. The present invention adds key information such as a bitmap to each node in the decision tree, deletes empty nodes and identical subnodes in the decision tree based on the key information, and designs a decision tree search process based on the optimized decision tree. After the empty nodes and identical nodes are optimized, the number of decision tree nodes is significantly reduced. By comparing the tree building data before and after the empty nodes and identical subnodes are deleted by using a bitmap, it is found that the scheme significantly reduces the FPGA on-chip RAM resources occupied by the decision tree nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of communication technology, and in particular relates to a method for realizing a decision tree based on bitmap. Background Art

[0002] The packet classification algorithm is a commonly used algorithm in the network. Its purpose is to classify packets into different types according to the header information carried by the packet, which is generally the five domains of DIP, SIP, SP, DP, and Protocol. In SDN, there are more domains, such as 11, so that they can be processed differently. Common applications include: access control lists, firewalls, and flow-based billing statistics. There are different applications in core network devices and edge network devices. Decision tree is a commonly used algorithm among many packet classification algorithms.

[0003] The key point of packet classification through decision tree is the creation of decision tree. The establishment of decision tree is to divide the rules of parent node to multiple child nodes as evenly as possible according to the characteristics of rule set. The root node has all the rules in the rule set, and after the division of multi-level tree nodes, the leaf node only contains less than the specified number of rules. In this way, a large rule set is divided into multiple small rule sets, and then the network packet is searched in the specified small rule set. When searching for network packets, the lower nodes are searched from the root node according to the information when the decision tree is established, until the leaf node, and then the search is performed in the small rule set contained in the leaf node.

[0004] In a common decision tree implementation, since each rule represents a larger or smaller scope, when dividing the rule from the parent node to the child node, the same rule may be divided into multiple child nodes; or the scope represented by the rule itself is very small, but multiple rules overlap with each other, resulting in multiple rules cannot be effectively divided into different nodes after the multi-level tree node division; these two situations are collectively referred to as rule replication in this patent. Rule replication may cause the same rules to be included in brother nodes, forming the same subtree after level-by-level division. Since a decision tree contains tens of thousands or even hundreds of thousands of nodes, the same subtree will cause serious waste of RAM resources.

[0005] Figure 1 For example, the following fields represent the source IP address value / source IP mask, destination IP address value / destination IP mask, source port number range, destination port number range, and protocol number value / protocol number mask value. Each rule represents a range, and the rule with a smaller mask represents a larger range.

[0006] In the process of creating a decision tree, for each parent node, the division dimension and the number of division bits are first obtained heuristically based on the features contained in the parent node, and the number of child nodes it has can be calculated based on the division dimension and the number of division bits. Then, after the rules are divided from the parent node to the child nodes, some child nodes may not have rules, which are called empty nodes in this embodiment. Empty nodes do not store valid information and waste RAM resources. At the same time, multiple child nodes may contain the same rules, which are called the same nodes in this embodiment. The same nodes contain redundant information and also waste RAM resources. Summary of the invention

[0007] 1. Technical issues to be resolved

[0008] The technical problem to be solved by the present invention is how to provide a method for implementing a decision tree based on a bitmap to solve the problem of wasting RAM resources due to empty nodes and identical nodes.

[0009] (II) Technical solution

[0010] In order to solve the above technical problems, the present invention proposes a method for implementing a decision tree based on a bitmap, where each node in the decision tree includes at least the following key information:

[0011] empty_bitmap: bitmap of empty nodes;

[0012] first_equal_idx: the index of the first child node among all identical child nodes;

[0013] equal_bitmap: bitmap of the same child nodes;

[0014] filter_num: the number of rules contained in this node;

[0015] filter_list: the rule list of this node, which stores all the rules of this node. Each list node contains the specific information of the rule.

[0016] children_ptr: a pointer to the memory of child nodes. Multiple child nodes of a parent node are stored in a continuous memory block, and children_ptr points to the first address of the memory block.

[0017] child_num: number of child nodes;

[0018] The method comprises the following steps:

[0019] S1. Determine which child nodes are empty nodes; traverse the child nodes according to the children_ptr and child_num fields of the parent node, and determine whether the filter_num field of the child node is zero; if it is zero, the current child node is an empty node, set idx to the index value of the current child node, and set the idx-th bit of the empty_bitmap field to 1; otherwise, the current child node is a non-empty node, and set the idx-th bit of the empty_bitmap field to 0;

[0020] S2. Determine which child nodes are the same node, and traverse the child nodes according to the children_ptr and child_num fields of the parent node; the specific rule information contained in the child node can be known according to the filter_num and filter_list fields of the child node, and by comparing the rules of the child nodes in pairs, it can be known which child nodes contain the same rules; assign the smallest child node index value of all the same nodes to the first_equal_idx field, and set the bits of the equal_bitmap field corresponding to the index values ​​of other same nodes to 1;

[0021] S3. Delete all empty nodes; for identical nodes, keep the node with the smallest index value and delete the rest of the identical nodes.

[0022] Furthermore, each node in the decision tree also includes the following key information:

[0023] Current node tree height tree_height: indicates the number of tree layers from the root node to the current node;

[0024] The partition dimension of the current node cut_dim: a total of 5 bits, from bit 0 to bit 4, respectively, representing the five dimensions of protocol number, destination port number, source port number, destination IP address, and source IP address. When a bit of cut_dim is 1, it means that the corresponding dimension is used as the partition dimension;

[0025] The number of bits used by the current node as the partitioning bits in the specified partitioning dimension cut_num[5]: represented by an array containing 5 elements, from cut_num[0] to cut_num[4], which represent the number of partitioning bits in the five dimensions of protocol number, destination port number, source port number, destination IP address and source IP address respectively;

[0026] The sum of the number of partition bits of each node on the path from the root node to the parent node of the current node is called the cumulative number of partition bits of the current node, represented by accu_cut_num[5]. From accu_cut_num[0] to accu_cut_num[4], they represent the cumulative number of partition bits of the five dimensions of protocol number, destination port number, source port number, destination IP address and source IP address respectively.

[0027] isleaf: Whether the current node is a leaf node. The initial value of this field is 0. When the value of this field is 1, it means that the current node is a leaf node.

[0028] Furthermore, the method for calculating the number of child nodes is as follows: the sum of the number of partition bits corresponding to the partition dimension is calculated, cut_num_sum, and the number of child nodes child_num is: 2 to the power of cut_num_sum.

[0029] Furthermore, the method for obtaining the partitioning dimension is as follows: the different numbers of rules contained in the current node in each dimension are saved in the array diff_num[5] respectively, the average value avg_num of the five members of diff_num[5] is calculated, and the dimension in which diff_num[i] is greater than avg_num is used as the partitioning dimension.

[0030] Furthermore, at most three partitioning dimensions are selected.

[0031] Furthermore, the method for obtaining the number of partition bits is as follows: try different numbers of partition bits, divide the parent node rule into multiple child nodes, calculate the standard deviation of the number of child node rules as a basis for reflecting the average degree of rule division, and take the partition bit with the highest average degree of rule division as the final number of partition bits.

[0032] Furthermore, when the parent node only uses one dimension i as the division dimension, the number of division bits is cut_num[i], and the cumulative number of division bits is accu_cut_num[i]; when a rule r of the parent node needs to be divided into child nodes, the value of the rule in dimension i from the accu_cut_num[i]th bit to the accu_cut_num[i]+cut_num[i]-1th bit is obtained, and this value is the child node index value idx, indicating that the rule r will be divided into the idxth child node of the parent node. When the mask value mask of dimension i is less than accu_cut_num[i]+cut_num[i], that is, the mask bit to the accu_cut_num[i]+cut_num[i]th bit of dimension i are wildcards, so the rule r will be divided into multiple child nodes.

[0033] Further, when using two dimensions i and j as the partitioning dimensions, obtain the value IDXi of the partitioning dimension i from the accu_cut_num[i]-th bit to the (accu_cut_num[i]+cut_num[i]-1)-th bit; obtain the value IDXj of the partitioning dimension j from the accu_cut_num[j]-th bit to the (accu_cut_num[j]+cut_num[j]-1)-th bit; after shifting IDXj to the left by cut_num[i] bits, perform a bitwise OR operation with IDXi to obtain the index value idx, which is the index of the child node, indicating that rule r will be partitioned to the idx-th child node of the parent node. Also due to mask wildcards, rule r may be partitioned to multiple child nodes.

[0034] A decision tree search method for an implementation method based on a decision tree according to the present invention, the method includes:

[0035] Extract the five-tuple information from the data packet to be searched, including: source IP address, destination IP address, source port number, destination port number, and protocol number;

[0036] The decision tree search starts from the root node and then searches layer by layer down to the lower-level nodes. The search steps are as follows:

[0037] step1: Calculate the index of the child node: cld_idx according to the content of the data packet header and the information cut_dim, cut_num, accu_cut_num saved in the parent node;

[0038] step2: Each bit of the empty_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means the corresponding child node is an empty node. If the value of ((1<<cld_idx)&empty_bitmap) is non-zero, it means the value of the cld_idx-th bit of the empty_bitmap field is 1, that is, the cld_idx-th child node is an empty node. At this time, execute step11 and output the matching result as not hitting any rules; otherwise, execute step3;

[0039] step3: Each bit of the equal_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means the corresponding child node is one of the multiple identical nodes. If the value of ((1<<cld_idx)&equal_bitmap) is non-zero, it means the value of the cld_idx-th bit of the equal_bitmap field is 1, that is, the cld_idx-th child node is one of the multiple identical nodes. At this time, execute step4; otherwise, execute step5;

[0040] Step 4: Update the index value cld_idx of the child node to first_equal_idx, that is, cld_idx = first_equal_idx;

[0041] Step 5: Traverse each bit of the empty_bitmap field, calculate the number of bits with a value of 1 between the 0th bit and the cld_idxth bit, record it as empty_num, which indicates how many child nodes are empty nodes before the cld_idxth child node; continue to execute step 6;

[0042] Step 6: Traverse each bit of the equal_bitmap field and calculate the number of bits with a value of 1 between the 0th bit and the cld_idxth bit, recorded as equal_num, which indicates how many child nodes are the same as the cld_idxth child node, and continue to execute step 7;

[0043] step7: Update the child node index value cld_idx: cld_idx = cld_idx-empty_num-equal_num;

[0044] Step 8: The child nodes are stored continuously in the memory. The memory address of the child node is obtained according to the starting address of the child node memory block and the child node index value cld_idx. The isleaf field in the child node is used to determine whether the current node is a leaf node. If not, execute step 10: use the current child node as the new parent node and execute step 1 to step 8 again. Otherwise, execute step 9 to search for a small number of rules in the leaf node in parallel, and output the matching results in step 11.

[0045] Furthermore, the starting address of the child node memory block is stored in the children_ptr field.

[0046] (III) Beneficial effects

[0047] The present invention proposes a method for implementing a decision tree based on bitmap. The present invention adds key information such as bitmap to each node in the decision tree, deletes empty nodes and identical subnodes in the decision tree based on the key information, and designs a decision tree search process based on the optimized decision tree. After the empty nodes and identical nodes are optimized, the number of decision tree nodes is significantly reduced. By comparing the tree building data before and after using bitmap to delete empty nodes and identical subnodes, it is found that the scheme significantly reduces the FPGA on-chip RAM resources occupied by the decision tree nodes. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 For example,

[0049] Figure 2 The memory layout of the parent node and child nodes;

[0050] Figure 3 This is an example of an empty node;

[0051] Figure 4 For the same node example;

[0052] Figure 5 Optimized memory layout for empty nodes and identical nodes;

[0053] Figure 6 To find the flow chart. DETAILED DESCRIPTION

[0054] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0055] This embodiment marks empty nodes and redundant identical nodes through bitmap and then directly deletes these nodes, thus saving RAM resources.

[0056] Each node in the decision tree includes the following key information:

[0057] 1) Current node tree height tree_height: indicates the number of layers from the root node to the current node. The root node has a tree height of 0, the root node's child node has a tree height of 1, the grandchild node has a tree height of 2, and so on.

[0058] 2) The current node's partition dimension cut_dim: a total of 5 bits, from bit 0 to bit 4, representing the five dimensions of protocol number, destination port number, source port number, destination IP address, and source IP address. When a bit of cut_dim is 1, it means that the corresponding dimension is used as the partition dimension.

[0059] Method for obtaining partitioning dimensions: save the different numbers of rules contained in the current node in each dimension in the array diff_num[5], calculate the average value avg_num of the five members of diff_num[5], and use the dimension where diff_num[i] is greater than avg_num as the partitioning dimension. A maximum of three dimensions can be selected.

[0060] 3) The number of bits used by the current node as the partitioning bits in the specified partitioning dimension cut_num[5]: represented by an array containing 5 elements. From cut_num[0] to cut_num[4], they represent the number of partitioning bits in the five dimensions of protocol number, destination port number, source port number, destination IP address and source IP address.

[0061] Method for obtaining the number of division bits: try different numbers of division bits, divide the parent node rule into multiple child nodes, calculate the standard deviation of the number of child node rules as the basis for reflecting the average degree of rule division. The division bit with the highest average degree of rule division is taken as the final number of division bits.

[0062] 4) The sum of the number of partition bits of each node on the path from the root node to the parent node of the current node is called the cumulative number of partition bits of the current node, represented by accu_cut_num[5]. From accu_cut_num[0] to accu_cut_num[4], they represent the cumulative number of partition bits of the five dimensions of protocol number, destination port number, source port number, destination IP address, and source IP address.

[0063] 5)empty_bitmap: bitmap of empty node.

[0064] 6)first_equal_idx: The index of the first child node among all identical child nodes.

[0065] 7) equal_bitmap: bitmap of identical child nodes (except the first identical node).

[0066] 8)filter_num: The number of rules contained in this node.

[0067] 9)filter_list: The rule list of this node, which stores all the rules of this node. Each list node contains the specific information of the rule.

[0068] 10) Pointer children_ptr pointing to child node memory: Multiple child nodes of a parent node are stored in a continuous memory block, and children_ptr points to the first address of the memory block.

[0069] 11) Number of child nodes child_num: After determining the partition dimension cut_dim and the number of partition bits cut_num[5], the number of child nodes is also determined.

[0070] The method for calculating the number of child nodes is as follows: calculate the sum of the number of partition bits corresponding to the partition dimension, cut_num_sum. The number of child nodes, child_num, is 2 raised to the power of cut_num_sum. The memory layout of the parent node and the child node is as follows: Figure 2 As shown in the figure, the index of child nodes starts from 0, and the index value of child node n in the figure is child_num–1.

[0071] 12)isleaf: Whether the current node is a leaf node. The initial value of this field is 0. When the value of this field is 1, it means that the current node is a leaf node.

[0072] Method for dividing parent node rules into child nodes:

[0073] 1) When the parent node uses only one dimension i as the partitioning dimension, the number of partitioning bits is cut_num[i], and the cumulative number of partitioning bits is accu_cut_num[i]. When a rule r of the parent node needs to be partitioned to a child node, the value of the rule in the dimension i from the accu_cut_num[i]th bit to the accu_cut_num[i]+cut_num[i]-1th bit is obtained (note: the highest bit is recorded as the 0th bit, the second highest bit is recorded as the 1st bit, and so on). This value is the child node index value idx, indicating that the rule r will be partitioned to the idxth child node of the parent node. When the mask value mask of dimension i is less than accu_cut_num[i]+cut_num[i], that is, the mask bit to the accu_cut_num[i]+cut_num[i]th bit of dimension i is wildcarded, so the rule r will be partitioned to multiple child nodes.

[0074] 2) When the parent node uses multiple dimensions as partitioning dimensions, the processing method is similar to that when only one dimension is used. For the convenience of description, it is assumed here that two dimensions i and j are used as partitioning dimensions. Get the value IDXi of the partitioning dimension i from the accu_cut_num[i]th bit to the accu_cut_num[i]+cut_num[i]-1th bit; get the value IDXj of the partitioning dimension j from the accu_cut_num[j]th bit to the accu_cut_num[j]+cut_num[j]-1th bit. After shifting IDXj left by cut_num[i] bits, perform a bitwise OR operation with IDXi to obtain the index value idx, which is the index of the child node, indicating that the rule r will be divided into the idxth child node of the parent node. Similarly, due to the wildcard mask, the rule r may be divided into multiple child nodes. The case of using 3 dimensions as partitioning dimensions is similar to the case of using 2 dimensions, and will not be repeated here.

[0075] 3) For other rules in the parent node, the same processing method as rule r is adopted and they are divided into child nodes in turn.

[0076] When creating a decision tree, after dividing the parent node rules into child nodes, assign values ​​to empty_bitmap and equal_bitmap according to the rules in the child nodes:

[0077] S1. Determine which child nodes are empty nodes. Figure 3As shown, according to the children_ptr and child_num fields of the parent node, traverse the child nodes to determine whether the filter_num field of the child node is zero; if it is zero, the current child node (let idx be the index value of the current child node, that is, the nth child node of its parent node) is an empty node, and the idx-th bit of the empty_bitmap field is set to 1; otherwise, the current child node is a non-empty node, and the idx-th bit of the empty_bitmap field is set to 0.

[0078] like Figure 3 As shown, after traversing the child nodes, it is found that child nodes 1, 3, and 6 do not contain rules and are empty nodes. Therefore, the 1st, 3rd, and 6th bits of the empty_bitmap field are assigned a value of 1.

[0079] S2. Determine which child nodes are the same node. Figure 4 As shown, according to the children_ptr and child_num fields of the parent node, the child nodes are traversed; according to the filter_num and filter_list fields of the child nodes, the specific rule information contained in the child nodes can be known, and by comparing the rules of the child nodes in pairs, it can be known which child nodes contain the same rules.

[0080] like Figure 4 As shown in the figure, if we traverse the child nodes and compare their rule information, we find that the rules contained in child nodes 2, 4, 5, and 7 are the same; among all the same nodes, the smallest child node index value is assigned to the first_equal_idx field. Figure 4 The first_equal_idx field is assigned a value of 2. Then the bits of the equal_bitmap field corresponding to the index values ​​of other identical nodes are set to 1. Figure 4 The 4th, 5th and 7th bits of the equal_bitmap field are set to 1.

[0081] S3, delete all empty nodes; for Figure 3 For example, child nodes 1, 3, and 6 are deleted. For identical nodes, the node with the smallest index value is retained, and the remaining identical nodes are deleted; Figure 4 For example, child node 2 is retained, and child nodes 4, 5, and 7 are deleted.

[0082] go through Figure 3 and Figure 4 After the empty nodes and the same nodes are optimized, the new parent-child node memory layout is as follows Figure 5 As shown, the number of decision tree nodes is significantly reduced, and the problem of excessive RAM resource consumption is significantly improved.

[0083] Due to the introduction of the empty node and identical node optimizations, the decision tree lookup module has changed. The following, in combination with Figure 6 the lookup flowchart shown, will be described in detail step by step:

[0084] 1) Data packet header: Extract the five-tuple information from the data packet to be looked up, including: source IP address, destination IP address, source port number, destination port number, and protocol number.

[0085] 2) The decision tree lookup starts from the root node and then looks up layer by layer to the lower-level nodes. When looking up for the first time, Figure 6 the parent node shown in is the root node. When this lookup process is recursively executed later, the parent node will be updated in step10.

[0086] 3) Step1: Calculate the index of the child node: cld_idx based on the content of the data packet header and the information (cut_dim, cut_num, accu_cut_num) saved in the parent node.

[0087] An example to illustrate the calculation method of cld_idx: The five-tuple of the data packet to be looked up is shown in Table 1. The values of the key fields for rule division in the node are shown in Table 2. The calculation steps are shown in Table 3.

[0088] Table 1 Example of the five-tuple of the data packet header

[0089] Packet Fields Decimal hexadecimal Binary Source IP 192.168.10.35 0xc0a80a23 11000000101010000000101000100011 Destination IP 10.10.5.83 0x0a0a0553 1010000010100000010101010011 Source Port 14531 0x38c3 11100011000011 Destination Port 8080 0x1f90 1111110010000 Protocol Number 6 0x06 00000110

[0090] Table 2 Example of the values of the division rule fields in the node

[0091]

[0092] Table 3 Calculation steps of cld_idx

[0093]

[0094] 4) Step2: Each bit of the empty_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means the corresponding child node is an empty node. If the value of ((1<<cld_idx)&empty_bitmap) is non-zero, it means the value of the cld_idx-th bit of the empty_bitmap field is 1, that is, it means the cld_idx-th child node is an empty node. At this time, execute step11 and output that the matching result is that no rule is hit; otherwise, execute step3.

[0095] 5) Step 3: Each bit of the equal_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means that the corresponding child node is one of multiple identical nodes. If the value of ((1<<cld_idx)&equal_bitmap) is non-zero, it means that the cld_idx-th bit of the equal_bitmap field is 1, that is, the cld_idx-th child node is one of multiple identical nodes. At this time, execute Step 4; otherwise, execute Step 5.

[0096] 6) Step 4: As known from the above, only the node with the smallest index value among multiple identical nodes is retained (its index value is saved in the first_equal_idx field), and the remaining nodes have been deleted. Therefore, it is necessary to update the index value cld_idx of the lower-level child node to first_equal_idx, that is, cld_idx = first_equal_idx.

[0097] 7) Step 5: Traverse each bit of the empty_bitmap field, calculate the number of bits with a value of 1 between the 0-th bit and the cld_idx-th bit, and record it as empty_num. It represents how many child nodes before the cld_idx-th child node are empty nodes. Then continue to execute Step 6.

[0098] 8) Step 6: Traverse each bit of the equal_bitmap field, calculate the number of bits with a value of 1 between the 0-th bit and the cld_idx-th bit, and record it as equal_num. It represents how many child nodes before the cld_idx-th child node are identical nodes. Then continue to execute Step 7.

[0099] 9) Step 7: Update the child node index value cld_idx: cld_idx = cld_idx - empty_num - equal_num. Since the empty nodes and identical nodes before the original cld_idx have been deleted, cld_idx needs to subtract the number of deleted nodes.

[0100] 10) Step 8: The child nodes are continuously stored in memory. According to the starting address of the child node memory block (saved in the children_ptr field) and the child node index value (saved in the cld_idx), the memory address of the child node can be obtained. Determine whether the current node is a leaf node according to the isleaf field in the child node. If not, execute Step 10: Use the current child node as the new parent node and execute Steps 1 to 8 again; otherwise, execute Step 9, parallelly search for a small number of rules in the leaf nodes, and the rule examples are as Figure 1 shown, and output the matching result in Step 11.

[0101] By comparing the tree building data before and after using bitmap to delete empty nodes and identical child nodes, it is found that this scheme significantly reduces the FPGA on-chip RAM resources occupied by decision tree nodes.

[0102] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for implementing a decision tree based on bitmap. It is characterized in that Each node in the decision tree includes at least the following key information: empty_bitmap: bitmap of empty nodes; first_equal_idx: the index of the first child node among all identical child nodes; equal_bitmap: bitmap of the same child nodes; filter_num: the number of rules contained in this node; filter_list: the rule list of this node, which stores all the rules of this node. Each list node contains the specific information of the rule. children_ptr: a pointer to the memory of child nodes. Multiple child nodes of a parent node are stored in a continuous memory block, and children_ptr points to the first address of the memory block. chi ld_num: number of child nodes; The method comprises the following steps: S1. Determine which child nodes are empty nodes; according to the child_ptr and child_num fields of the parent node, traverse the child nodes and determine whether the filter_num field of the child node is zero; if it is zero, the current child node is an empty node, set idx to the index value of the current child node, and set the idx bit of the empty_bitmap field to 1; Otherwise, if the current child node is a non-empty node, the idx-th bit of the empty_bitmap field is set to 0; S2. Determine which child nodes are the same node, and traverse the child nodes according to the child_ptr and child_num fields of the parent node; the specific rule information contained in the child node can be known according to the filter_num and filter_list fields of the child node, and by comparing the rules of the child nodes in pairs, it can be known which child nodes contain the same rules; assign the smallest child node index value of all the same nodes to the first_equal_idx field, and set the bits of the equal_bitmap field corresponding to the index values ​​of other same nodes to 1; S3. Delete all empty nodes; for identical nodes, keep the node with the smallest index value and delete the rest of the identical nodes; in, Each node in the decision tree also includes the following key information: Current node tree height tree_height: indicates the number of tree layers from the root node to the current node; The partition dimension of the current node cut_dim: a total of 5 bits, from bit 0 to bit 4, respectively, representing the five dimensions of protocol number, destination port number, source port number, destination IP address, and source IP address. When a bit of cut_dim is 1, it means that the corresponding dimension is used as the partition dimension; The number of bits used by the current node as the partitioning bits in the specified partitioning dimension cut_num[5]: represented by an array containing 5 elements, from cut_num[0] to cut_num[4], which represent the number of partitioning bits in the five dimensions of protocol number, destination port number, source port number, destination IP address and source IP address respectively; The sum of the number of partition bits of each node on the path from the root node to the parent node of the current node is called the cumulative number of partition bits of the current node, represented by accu_cut_num[5]. From accu_cut_num[0] to accu_cut_num[4], they represent the cumulative number of partition bits of the five dimensions of protocol number, destination port number, source port number, destination IP address and source IP address respectively. isleaf: Whether the current node is a leaf node. The initial value of this field is 0. When the value of this field is 1, it means that the current node is a leaf node.

2. The method for implementing a bitmap-based decision tree as claimed in claim 1, It is characterized in that The method for calculating the number of child nodes is as follows: the sum of the number of partition bits corresponding to the partition dimension is calculated, and the number of child nodes chi ld_num is: 2 to the power of cut_num_sum.

3. The method for implementing a bitmap-based decision tree as claimed in claim 1, It is characterized in that Method for obtaining partitioning dimensions: save the different numbers of rules contained in the current node in each dimension in the array diff_num[5], calculate the average value avg_num of the five members of diff_num[5], and use the dimension where diff_num[i] is greater than avg_num as the partitioning dimension.

4. The method for implementing a bitmap-based decision tree as claimed in claim 3, It is characterized in that Select up to three partitioning dimensions.

5. The method for implementing a bitmap-based decision tree as claimed in claim 1, It is characterized in that Method for obtaining the number of partition bits: try different numbers of partition bits, divide the parent node rule into multiple child nodes, calculate the standard deviation of the number of child node rules as the basis for reflecting the average degree of rule partition, and take the partition bit with the highest average degree of rule partition as the final number of partition bits.

6. The method for implementing a decision tree based on bitmap according to any one of claims 1 to 5, It is characterized in that When the parent node only uses one dimension i as the partition dimension, the number of partition bits is cut_num[i], and the cumulative number of partition bits is accu_cut_num[i]; when a rule r of the parent node needs to be divided into child nodes, the value of the rule in dimension i from the accu_cut_num[i]th bit to the accu_cut_num[i]+cut_num[i]-1th bit is obtained. This value is the child node index value idx, indicating that the rule r will be divided into the idxth child node of the parent node. When the mask value mask of dimension i is less than accu_cut_num[i]+cut_num[i], that is, the mask bit to the accu_cut_num[i]+cut_num[i]th bit of dimension i are wildcards, so the rule r will be divided into multiple child nodes.

7. The method for implementing a decision tree based on bitmap according to any one of claims 1 to 5, It is characterized in that When using two dimensions i and j as the partitioning dimensions, obtain the value IDXi of the partitioning dimension i from the accu_cut_num[i]-th bit to the accu_cut_num[i]+cut_num[i]-1-th bit; obtain the value IDXj of the partitioning dimension j from the accu_cut_num[j]-th bit to the accu_cut_num[j]+cut_num[j]-1-th bit; after shifting IDXj to the left by cut_num[i] bits, perform a bitwise OR operation with IDXi to obtain the index value idx, which is the index of the child node, indicating that rule r will be partitioned to the idx-th child node of the parent node. Also, due to mask wildcards, rule r may be partitioned to multiple child nodes.

8. A decision tree lookup method for an implementation method of a decision tree according to any one of claims 1-7, characterized in that, extract the five-tuple information from the data packet to be looked up, including: source IP address, destination IP address, source port number, destination port number, and protocol number; The decision tree lookup starts from the root node and then looks up layer by layer to the lower-level nodes. The lookup steps are as follows: step1: Calculate the index of the child node: cld_idx according to the content of the data packet header and the information cut_dim, cut_num, accu_cut_num saved in the parent node; step2: Each bit of the empty_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means the corresponding child node is an empty node. If the value of ((1<<cld_idx)&empty_bitmap) is non-zero, it means the value of the cld_idx-th bit of the empty_bitmap field is 1, that is, the cld_idx-th child node is an empty node. At this time, execute step11 and output the matching result as not hitting any rule; otherwise, execute step3; step3: Each bit of the equal_bitmap field corresponds to a child node. If the value of a certain bit is 1, it means the corresponding child node is one of the multiple identical nodes. If the value of ((1<<cld_idx)&equal_bitmap) is non-zero, it means the value of the cld_idx-th bit of the equal_bitmap field is 1, that is, the cld_idx-th child node is one of the multiple identical nodes. At this time, execute step4; otherwise, execute step5; step4: Update the index value cld_idx of the child node to first_equal_idx, that is, cld_idx = first_equal_idx; step5: Traverse each bit of the empty_bitmap field, calculate the number of bits with a value of 1 between the 0-th bit and the cld_idx-th bit, denoted as empty_num, indicating how many child nodes before the cld_idx-th child node are empty nodes; continue to execute step6; Step 6: Traverse each bit of the equal_bitmap field and calculate the number of bits with a value of 1 between the 0th bit and the cld_idxth bit, recorded as equal_num, which indicates how many child nodes are the same as the cld_idxth child node, and continue to execute step 7; step7: Update the child node index value cld_idx: cld_idx = cld_idx-empty_num-equal_num; Step 8: The child nodes are stored continuously in the memory. The memory address of the child node is obtained according to the starting address of the child node memory block and the child node index value cld_idx. The isleaf field in the child node is used to determine whether the current node is a leaf node. If not, execute step 10: use the current child node as the new parent node and execute step 1 to step 8 again. Otherwise, execute step 9 to search for a small number of rules in the leaf node in parallel, and output the matching results in step 11.

9. The method for implementing a bitmap-based decision tree as claimed in claim 8, It is characterized in that The starting address of the child node memory block is stored in the children_ptr field.