A rule prefix space based online packet classification method

By adopting an online packet classification method based on rule prefix space, the challenges of high-speed classification and rule updating in existing technologies are solved. By optimizing rule grouping and introducing priority, efficient packet matching and rule updating are achieved, thereby improving the packet switching performance of software-defined network systems.

CN115270955BActive Publication Date: 2025-12-30BEIHANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210878321.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-25
Publication Date
2025-12-30
Estimated Expiration
2042-07-25

AI Technical Summary

Technical Problem

Existing packet classification methods cannot simultaneously achieve high-speed classification and rule updates, resulting in problems such as rule duplication and low packet classification efficiency.

Method used

An online packet classification method based on rule prefix space is adopted. By initializing the rule grouping mapping table and the rule splitting mapping table, priority is used to optimize rule grouping, and rules are added, deleted and matched to reduce the number of rule groups and improve the packet matching rate.

Benefits of technology

While ensuring the performance of rule updates, the packet matching rate was improved, enabling concurrent online rule updates and packet matching, thus optimizing the packet switching performance of the software-defined network system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115270955B_ABST
    Figure CN115270955B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of online packet classification method based on rule prefix space, first initialization rule grouping mapping table and rule split mapping table, respectively for recording rule grouping that rule is assigned to, whether the split of a rule occurs.Record addition and deletion rule, carry out packet classification such as operation can be carried out after the initialization of two mapping tables, when adding rule, scale to rule prefix space, it is added to suitable rule grouping;When deleting rule, it is realized fast processing by the record of two mapping tables.The present application has the advantages that rule prefix space is scaled, and the number of rule grouping is reduced;When selecting rule grouping, optimization is carried out based on priority, so that high priority rule is mainly concentrated in the front rule grouping, while guaranteeing rule update performance, the packet matching rate is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of data packet classification, specifically relating to an online data packet classification method based on a rule prefix space. Background Technology

[0002] The goal of packet classification is to determine which rule a packet matches based on a given set of rules. These rules often consist of multiple fields, such as source IP address, destination IP address, source port, destination port, and protocol number.

[0003] Packet classification is a crucial component of network routing, firewalls, and other services. Traditional packet classification techniques are mostly offline methods, which involve establishing a static data structure to support high-speed packet matching based on a given set of rules. However, with the development of technologies such as Software-Defined Networking (SDN) and Network Functions Virtualization (NFV), new requirements have emerged, such as elastic resource allocation and real-time migration. This necessitates the use of online methods for packet classification, employing a dynamic data structure that allows for rapid rule updates while performing high-speed packet classification.

[0004] Existing packet classification methods can be mainly divided into two categories: decision tree-based classification methods and tuple space-based packet classification methods. Decision tree-based methods divide rules into multiple groups and assign them to different child nodes by uniformly or non-uniformly splitting certain fields in the rules. Decision tree-based methods suffer from rule duplication; that is, when splitting fields, a rule may be assigned to multiple child nodes, which increases memory usage and makes rule updates difficult. Tuple space-based packet classification methods divide the rule set into multiple rule groups based on the matching prefix space of multiple fields in the rules, thus avoiding rule duplication and achieving fast updates. However, during packet matching, tuple space-based methods need to traverse all rule groups. Although there are some optimization methods such as rule group merging and priority-based early termination, the packet classification efficiency remains low due to the large number of groups. Summary of the Invention

[0005] The technical solution of this invention overcomes the shortcomings of existing technologies and provides an online data packet classification method based on rule prefix space. This method solves the problem that current data packet classification methods cannot simultaneously achieve high-speed classification and rule updates, thereby improving the data packet matching rate.

[0006] The specific technical solution of this invention is as follows: an online data packet classification method based on rule prefix space, the method comprising the following steps:

[0007] Step 1: Initialize the rule grouping mapping table and the rule splitting mapping table; the rule grouping mapping table is used to record the rule group to which a rule is assigned; the rule splitting mapping table is used to record whether a rule has been split; use a first-in-first-out request queue to cyclically receive rule addition requests, rule deletion requests, and packet matching requests;

[0008] Step 2: Process the rule addition request from Step 1. Add the rule to a rule group. First, select from existing rule groups, using the rule prefix length and the rule group prefix length to determine the feasibility of adding the rule. If it is not feasible, split the rule and use rule priority and rule group priority to assist in selecting a rule group. If the rule still cannot be added, create a new rule group. The prefix length of this rule group is obtained by scaling the rule prefix space.

[0009] Step 3: Process the rule deletion request from Step 1. Delete a rule from the rule group. Based on the rule group mapping table and the rule split mapping table, obtain the rule group information to which the rule was assigned and whether the rule has been split. If the rule has not been split, delete the rule directly from the rule group. Otherwise, based on the rule split information, delete the set of rules formed after splitting from the rule group.

[0010] Step 4: Process the data packet matching request from Step 1. According to the priority order, traverse the existing rule groups, obtain the rules in the rule group that can match the data packet, and record the rule with the highest priority. If the highest priority is greater than the priority of the next rule group to be accessed, terminate the matching operation in advance and return the recorded rule.

[0011] This invention enables rapid classification of data packets and acquisition of the highest priority rule for data packet matching by scaling the rule prefix space and introducing priority optimization rule grouping. At the same time, this invention can perform online rule updates, allowing rule updates and data packet matching to be performed concurrently, thereby improving the availability of data packet matching during rule updates.

[0012] Furthermore, the specific implementation of step 1 is as follows:

[0013] (11) Each entry in the rule grouping mapping table consists of a rule number and a pointer to the rule group. Each new rule is added to the rule grouping mapping table, and each entry in the rule splitting mapping table consists of a rule number and the splitting record for that rule. These two tables are used to quickly locate the rule groups that need to be processed when rules are updated, reducing memory access and computation.

[0014] (12) Requests are received in a loop. There are three types of requests: adding a rule to a rule group, deleting a rule from a rule group, and matching a data packet against a rule. The first two types of requests are triggered by the user. When the network card receives a data packet, the third type of request is triggered. When multiple requests exist at the same time, they are processed using a first-come, first-served approach.

[0015] Furthermore, the specific implementation of step 2 is as follows:

[0016] (21) Parse the rules to obtain the matching field content, rule prefix length, and rule priority; traverse the existing rule groups and, for each rule group, obtain the rule group's used fields, rule group prefix length, and rule group priority;

[0017] (22) Compare the prefix length of the rule with the prefix length of the rule group. If for each field used in the rule group, the prefix length of the rule is greater than or equal to the prefix length of the rule group, and the sum of the differences between the prefix length of the rule and the prefix length of the rule group is less than or equal to the set threshold, then calculate the hash value of the rule under the prefix of the rule group and add the rule to the rule group.

[0018] (23) If the rule is not added to the rule group, then attempt to split the rule: First, calculate the number of bits that the rule needs to be split, that is, for each field used in the rule group, calculate the difference between the prefix length of the rule group and the prefix length of the rule, and take the sum of the differences that are greater than 0 as the number of bits that the rule needs to be split, and calculate the rule split score F = α(-2 k +b)-β(max(pP,0)), where α, b, and β are pre-defined parameters, n is a power of 2 used to limit rule splitting; α is an integer between 1 and 5; β is a decimal between 0 and 1; k is the number of bits the rule needs to split; p is the priority of the rule; and P is the priority of rule grouping.

[0019] (24) If F>0, then split the rule into 2 k For each rule, add a record to the rule splitting mapping table, add all rules to the rule group in turn, and modify the rule group mapping table; if F≤0, then create a new rule group: sample based on the rule prefix space, select the sample value that differs the most from the existing rule group as the prefix length of the new rule group, and add the rule to the new rule group;

[0020] (25) If the rule priority is greater than or equal to the priority of the rule group to which the rule is added, then all rule groups are reordered according to priority.

[0021] The specific implementation of step 3 is as follows:

[0022] (31) Query the rule group to which the rule is assigned in the rule grouping mapping table, query the split record of the rule in the rule splitting mapping table, and delete the record related to the rule from both tables;

[0023] (32) If the rule is not split, then delete the rule from the rule group; if the rule is split, then perform a rule deletion operation for each sub-rule in the split record.

[0024] The specific implementation of step 4 is as follows:

[0025] (41) Traverse the existing rule groups in order of priority, obtain the field information used by the rule groups, calculate the hash value of the data packet on these fields, find the corresponding rule chain through the hash table maintained by the rule groups, and obtain the highest priority rule matched.

[0026] (42) Record the highest priority of the matching rule. If the priority is lower than the priority of the next rule group, continue to traverse the next rule group. If the priority is higher than the priority of the next rule group, terminate the matching early and return the number of the highest priority rule currently recorded.

[0027] The beneficial effects of this invention compared to the prior art are as follows:

[0028] (1) By scaling the rule prefix space, the number of rule groups is reduced; by introducing priority to optimize rule grouping, high-priority rules are mainly concentrated in the earlier rule groups, thus enabling the matching to end earlier when matching data packets. This improves the data packet matching rate while ensuring rule update performance.

[0029] (2) This invention can be used to optimize the packet classification algorithm of software-defined network systems (OvS, VPP), and can perform online rule updates while performing high-speed packet matching, thereby improving the packet switching performance of software-defined network systems.

[0030] This invention enables rapid classification of data packets and acquisition of the highest priority rule for data packet matching by scaling the rule prefix space and introducing priority optimization rule grouping. At the same time, this invention can perform online rule updates, allowing rule updates and data packet matching to be performed concurrently, thereby improving the availability of data packet matching during rule updates. Attached Figure Description

[0031] Figure 1 This is the overall flowchart of the method;

[0032] Figure 2 It involves adding a flowchart to the rules;

[0033] Figure 3 This is a flowchart of the rule deletion process;

[0034] Figure 4 This is a flowchart of the data packet matching process;

[0035] Figure 5 It compares the data packet matching time;

[0036] Figure 6 It compares the rule update time. Detailed Implementation

[0037] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the protection scope of the present invention.

[0038] Table 1. Example of Rules

[0039]

[0040]

[0041] like Figure 1 As shown, the present invention provides an online packet classification method based on a rule prefix space, comprising:

[0042] Step 1: Create a rule grouping mapping table and a rule splitting mapping table, and receive requests in a loop;

[0043] 11) Create the rule grouping mapping table. Each entry in the table consists of a rule number and a pointer to a rule group. The rule grouping mapping table is initialized to empty. Each time a rule is added, a record is added to the rule grouping mapping table, so that the rule group that needs to be processed can be quickly found when the rule is updated.

[0044] 12) Create the rule splitting mapping table. Each entry in the table consists of the rule number and the splitting record of the rule. The rule splitting mapping table is initialized to empty. Each time a split rule is added, a record is added to the rule splitting mapping table, thereby reducing redundant calculations when deleting split rules.

[0045] 13) Rule grouping mapping table and rule splitting mapping table: A rule group can be quickly indexed by the rule number. The rule group is a data structure used to store rules. Each rule group needs to specify the rule fields it uses and the prefix length of these fields when it is created. Each rule group maintains a hash table, where the key is the hash value of the specified field of the rule and the value is the rule linked list. The rule linked list is initialized to empty and is used to store specific rule information.

[0046] 14) Use a first-in, first-out (FIFO) request queue to receive requests cyclically. Requests are divided into three types: adding a rule to a rule group, deleting a rule from a rule group, and performing rule matching on a data packet. The first two types of requests are triggered by the user, and the third type is triggered when the network card receives a data packet. When multiple requests exist simultaneously, a first-come, first-served (FIFO) approach is used. When the request to be processed is adding a rule to a rule group, proceed to step 2; when the request to be processed is deleting a rule from a rule group, proceed to step 3; when the request to be processed is performing rule matching on a data packet, proceed to step 4.

[0047] Step 2: Add a rule to the rule group. This involves creating a new rule group or selecting an existing rule group, adding the rule to the rule chain list corresponding to the rule group, and making corresponding record modifications in the rule group mapping table and rule splitting mapping table.

[0048] Specifically, it includes the following steps:

[0049] 21) Parse the rule and obtain the content of the rule matching field S = (s1, s2, ..., s... n The prefix length of the rule is l = (l1, l2, ..., ln). n ) and rule priority (p);

[0050] 22) Iterate through the existing rule groups and obtain the field information used by the rule group: I = (i1, i2, ..., i... m That is, using m (m≤n) fields, i m (i m ∈{1,2……n}) is the index of the m-th field used in the rule matching field, and the rule grouping prefix length L=(L1,L2……L m ), l is the prefix length of the rule, given when a rule is set manually; L is the prefix length of the rule group, given when a group is created; the priority P of the rule group is the highest priority of all rules in the rule group;

[0051] 23) Compare the prefix length l of the rule with the prefix length L of the rule group. If the following two formulas are satisfied, proceed to step 24); otherwise, proceed to step 25.

[0052] l i ≥L i For each field used in rule grouping, the prefix length of the rule is greater than or equal to the prefix length of the rule group;

[0053] ∑ i∈I l i -L i ≤thresh: For each field used in rule grouping, calculate the difference between the prefix length of the rule and the prefix length of the rule group, sum the differences, and the result is less than or equal to the set threshold thresh;

[0054] 24) Calculate the hash value of the rule. The rule has multiple fields, but only the field used for rule grouping (I = (i1, i2, ..., i...)) is used. m Only fields with the specified number i participate in the hash value calculation, and each field is truncated according to the prefix length of the grouping rules (e.g., for field i). m fields, For the content of this field, L m To determine the prefix length of this field in the rule grouping, use L for this field. m Cut off, get The final hash value is Based on the hash value, find the corresponding rule chain from the hash table maintained by the rule group, add the rule to the rule chain, and add the record of the rule to the rule group mapping table, then proceed to step 28);

[0055] 25) Use the following formula to calculate whether to perform rule splitting, where α, b, and β are pre-set parameters. b is a power of 2 to limit rule splitting; α is a small integer; β is a decimal between 0 and 1; k is the number of bits to be split in the rule; p is the rule priority; and P is the priority of the rule group. By performing rule splitting, high-priority rules can be added to high-priority rule groups, thereby improving the subsequent packet classification rate.

[0056] k=∑ i∈I max(L i -l i For each field used in the rule grouping, calculate the difference between the prefix length of the rule group and the prefix length of the rule, and take the larger value compared to 0. k is the sum of these larger values.

[0057] F=α(-2 k+b)-β(max(pP,0))

[0058] F represents the score for splitting the rule. When F>0, go to step 26); otherwise, check the traversal of all currently existing rule groups: if the traversal is complete, go to step 27); otherwise, go to step 22 to continue the traversal operation.

[0059] 26) Split the rule into 2 k Add a record to the rule splitting mapping table, add all rules to the rule grouping in turn, modify the rule grouping mapping table, and go to step 28);

[0060] 27) Create a new rule group, with the prefix length of the current rule being l = (l1, l2, ..., ln). n ), l n The prefix length of the nth field is represented by the sampling interval [RL1,RL2] of the prefix length grouped according to the following formula.

[0061] RL1=l; RL2=(max(l1-2,0),max(l2-2,0),…,max(l n -2,0));

[0062] The candidate group prefix length R is obtained by sampling within the sampling interval. The selected rule group prefix length is calculated according to the following formula: Where n is the number of established rule groups, L i The prefix length of the i-th rule group that has been established;

[0063]

[0064] Finally, create a new rule group, add the rule to the group, and add the record of the rule to the rule group mapping table;

[0065] 28) Reorder all rule groups according to priority, end step 2, and go to step 14) to process the next request.

[0066] Step 3: Delete a rule from a rule group. First, find the rule group where the rule belongs, then calculate the hash value, find the corresponding rule list based on the hash table maintained by the rule group, and delete the rule from the rule list.

[0067] Specifically, it includes the following steps:

[0068] 31) Obtain the rule group to which the rule is mapped from the rule grouping mapping table, and delete the record from the table;

[0069] 32) Access the rule splitting mapping table. If the rule has not been split, calculate the hash value of the rule, delete the rule from the rule group, and go to step 34); otherwise, go to step 33.

[0070] 33) Read a set of rules formed after the rule is split from the rule splitting mapping table, traverse each rule, calculate the hash value of the rule, delete the rule from the rule group, and delete the record from the rule splitting mapping table;

[0071] 34) If the deleted rule is the highest priority rule in the rule group, reorder all rule groups according to the highest priority; end step 3 and go to step 14) to process the next request;

[0072] Step 4: To perform rule matching on a data packet, the rule groups need to be accessed sequentially according to their priority to obtain the number of the highest priority rule that matches the data packet.

[0073] The processing of each rule group specifically includes the following steps:

[0074] 41) Obtain the field information used by the rule group, calculate the hash value of the data packet on these fields, find the corresponding rule chain through the hash table maintained by the rule group, traverse the rule chain to obtain the highest priority matching rule;

[0075] 42) Record the highest priority of all matching rules. If the priority is lower than the priority of the next rule group, go to step 41); if the priority is higher than the priority of the next rule group, terminate the matching early, return the highest priority rule currently recorded, end step 4, go to step 14), and process the next request.

[0076] This invention enables rapid classification of data packets and identification of the highest priority rule for packet matching by scaling the rule prefix space, introducing priority optimization for rule grouping, and guiding the addition of rules to appropriate rule groups. Simultaneously, this invention allows for online rule updates, enabling concurrent rule updates and data packet matching, thus improving the availability of data packet matching during rule updates.

[0077] The following will provide a more detailed explanation with specific examples.

[0078] like Figure 1 As shown, this invention provides an online packet classification method based on a rule prefix space. In this implementation, the rules shown in Table 1 are used to fully describe the entire process of the method. Specifically, it includes the following:

[0079] 1. Create rule grouping mapping tables and rule splitting mapping tables, and receive requests in a loop, specifically including:

[0080] 11) Create a rule grouping mapping table: This table stores the mapping information from the rule's ID to the group the rule belongs to. The table is initialized to empty; each time a rule is added, a record is added to the table, allowing for quick location of the rule group to be processed when rules are updated.

[0081] 12) Create a rule splitting mapping table: This table maps rule IDs to rule splitting records and stores detailed information about a rule being split into multiple rules. The table is initialized empty; each time a split rule is added, a new record is added to the table, thus reducing redundant calculations when deleting split rules.

[0082] 13) Receive requests in a loop: When the request to be processed is to add a rule to a rule group, proceed to step 2; when the request to be processed is to delete a rule from a rule group, proceed to step 3; when the request to be processed is to perform rule matching on a data packet, proceed to step 4. When multiple requests exist simultaneously, they are processed using a first-come, first-served approach.

[0083] 2. Add a rule to the rule group. Figure 2 This demonstrates the entire rule-adding process, which includes the following steps:

[0084] 21) Parse the rule and obtain the content of its matching field S = (s1, s2, ..., s... n ), the length of the regular prefix l = (l1, l2, ... l) n The priority of the rule (p). Taking rule R5 as an example, its parsing result is as follows: S corresponds to a quadruple (source IP address, destination IP address, source port, destination port), where the source port is represented by 16 bits, and its range is (0000 0100 00001111-0000 0111 1111 1111). Its first 6 bits are fixed. In order to use prefix expression, it can be shortened to (0000 0100 0000 0000-0000 0111 1111 1111), and the prefix length is 6.

[0085] S=(s1,s2......s4)=(10.218.234.1,10.4.241.0,4.0,0.0)

[0086] l=(l1,l2......l4)=(24,31,6,0)

[0087] 22) Traverse the existing rule groups, assuming the field information used to obtain the group is I = (i1, i2) = (1, 2), the prefix length of the rule group is L = (L1, L2) = (16, 16), and the priority of the rule group (P, whose value is the highest priority of all rules in the rule group):

[0088] 23) Compare the prefix length l of the rule with the prefix length L of the rule group. If, for each field used in the rule group, the prefix length of the rule is greater than or equal to the prefix length of the rule group, and for each field used in the rule group, the sum of the differences between the prefix length of the rule and the prefix length of the rule group is less than 16, then proceed to step 24); otherwise, proceed to step 25.

[0089] 24) Calculate The hash function used here is Cuckoo Hash. Based on the hash value, the corresponding rule list is found in the hash table maintained by the rule group, the rule is added to the rule list, and the record of that rule is added to the rule group mapping table. Proceed to step 28.

[0090] 25) Calculate whether rule splitting can be performed using the following formula, where α = β = 1, n = 8 are preset parameters, k is the number of bits to be split for the current rule, p is the rule priority, and P is the priority of the rule group. If F > 0, proceed to step 26); otherwise, check the traversal status of all currently existing rule groups: if the traversal is complete, proceed to step 27); otherwise, proceed to step 22) to continue the traversal operation.

[0091] k=∑ i∈I max(L i -l i ,0), F=α(-2 k +b)-β(max(pP,0))

[0092] 26) Assuming the current rule grouping prefix length is L = (L1, L2) = (25, 32), then we can calculate k = (25 - 24) + (32 - 31) = 2, splitting the rule into 2. 2 =4 rules, as shown in Table 2. Add records to the rule splitting mapping table, add all rules to the rule group in turn, modify the rule grouping mapping table and the rule splitting mapping table, and go to step 28.

[0093] Table 2. Results of R5 Splitting

[0094] rule Source IP address Destination IP address Source port Destination port Priority R5-1 10.218.234.1 / 25 10.4.241.0 / 30 1039:2047 0:65535 5 R5-2 10.218.234.129 / 25 10.4.241.128 / 30 1039:2047 0:65535 5 R5-3 10.218.234.1 / 25 10.4.241.128 / 30 1039:2047 0:65535 5 R5-4 10.218.234.129 / 25 10.4.241.0 / 30 1039:2047 0:65535 5

[0095] 27) Create a new rule group, with the current rule prefix length being l = (l1, l2, ..., ln). nThe sampling interval [RL1, RL2] for the prefix length of the rule-grouped data is calculated using the following formula.

[0096] RL1=l; RL2=(max(l1-2,0),max(l2-2,0),…,max(l n -2,0))

[0097] Taking average sampling as an example, the prefix length R∈{RL1,RL2,(RL1+RL2) / 2} of the candidate rule groups is calculated according to the following formula: Where L i The prefix length for existing rule groups. Finally, create new rule groups, add rules to these groups, and add the records for those rules to the rule group mapping table;

[0098]

[0099] 28) Reorder all rule groups according to priority, end step 2, and proceed to step 13) to process the next request.

[0100] 3. Delete a rule from a rule group, such as... Figure 3 As shown, the specific steps include:

[0101] 31) Obtain the content of the matching field of the rule to be deleted, get the rule group to which the rule is mapped from the rule group mapping table, delete the record from the table, and get the field information and prefix length used by the rule group;

[0102] 32) Access the rule splitting mapping table. If the rule is split, proceed to step 33); otherwise, calculate the hash value of the rule, find the corresponding rule chain, delete the rule from it, and proceed to step 34.

[0103] 33) Read a set of rule split records formed after the rule split from the rule split mapping table, traverse each rule in it, calculate the hash value, delete the rule from the rule group, delete the record from the rule split mapping table, and go to step 34);

[0104] 34) If the deleted rule is the highest priority rule in that rule group, reorder all rule groups according to the highest priority. End step 3 and go to step 13) to process the next request.

[0105] 4. To perform rule matching on a data packet, the rule groups need to be accessed sequentially according to priority. Finally, the number of the highest priority rule that matches the data packet is obtained. The process is as follows: Figure 4 As shown, the specific steps include:

[0106] 41) Obtain the field information used by the rule group, calculate the hash value of the data packet on these fields, find the corresponding rule list through the hash table maintained by the rule group, traverse the rule list, and if a match is found, return the highest priority rule that was matched.

[0107] 42) Record the highest priority of all matching rules. If the priority is lower than the priority of the next rule group, go to step 41); if the priority is higher than the priority of the next rule group, terminate the matching early, return the number of the highest priority rule currently recorded, end step 4, go to step 13), and process the next request.

[0108] This invention was compared with other methods using the open-source test suite ClassBench, specifically the four test suites acl1, acl2, fw1, and ipc1. Figure 5 , Figure 6 As shown, this invention achieves a 10%-40% improvement in data packet matching performance with only a small increase in rule update overhead, thereby improving the data packet matching rate while ensuring rule update performance.

Claims

1. A method for online packet classification based on rule prefix space, characterized in that: The method comprises the following steps: Step 1: initialize a rule group mapping table and a rule split mapping table; the rule group mapping table is used for recording a rule group to which a rule is assigned; the rule split mapping table is used for recording whether a rule is split; each table entry of the rule group mapping table comprises a rule number and a pointer to a rule group; a record is added in the rule group mapping table for each added rule; each table entry of the rule split mapping table comprises a rule number and split records of the rule; the two tables are used for quickly finding a rule group to be processed when a rule is updated, thereby reducing memory access and calculation; Step 2: use a first-in first-out request queue to cyclically receive requests; the requests are divided into three types, including a rule adding request, a rule deleting request and a packet matching request; the rule adding request is used for adding a rule in a rule group; the rule deleting request is used for deleting a rule from a rule group; the packet matching request is used for performing rule matching on a packet; the first two types of requests are triggered by a user; the third type of request is triggered when a network card receives a packet; when multiple requests exist simultaneously, the requests are processed in a first-come-first-served manner; Step 3: process the rule adding request of step 2, add a rule to a rule group, first select an existing rule group, use a rule prefix length and a rule group prefix length to determine the feasibility of adding the rule; when the rule cannot be added, split the rule, and use a rule priority and a rule group priority to assist in selecting a rule group; if the rule still cannot be added, create a new rule group; the prefix length of the new rule group is obtained by scaling a rule prefix space; Step 4: process the rule deleting request of step 2, delete a rule from a rule group, obtain rule group information to which the rule is assigned and information about whether the rule is split, and delete the records from a rule group mapping table and a rule split mapping table; if the rule is not split, directly delete the rule from the rule group; otherwise, delete a group of rules formed by splitting from the rule group according to the rule split information; Step 5: process the packet matching request of step 2, return a classification result of the packet; according to a priority order, traverse existing rule groups, obtain rules in the rule groups that can match the packet, record a rule with the highest priority, and return the rule as a classification result of the packet if the highest priority is higher than a priority of a rule group to be accessed next.

2. The method for online packet classification based on rule prefix space according to claim 1, characterized in that: The specific implementation in step 3 is as follows: (31) parse a rule to obtain a matching field content, a rule prefix length and a rule priority; traverse existing rule groups, obtain a rule group using field, a rule group prefix length and a rule group priority for each rule group; (32) Compare the prefix length of the rule and the prefix length of the rule group. If the prefix length of the rule is greater than or equal to the prefix length of the rule group for each field used by the rule group, and the sum of the difference between the prefix length of the rule and the prefix length of the rule group is less than or equal to a set threshold, it is feasible to add the rule to the existing rule group, calculate the hash value of the rule under the prefix of the rule group, and add the rule to the rule group. (33) If it is not feasible to add the rule to a rule group, i.e. directly adding the rule to an existing rule group is not feasible, then attempt to split the rule: first calculate the number of bits the rule needs to be split, i.e. for each field used by the rule group, calculate the difference between the prefix length of the rule group and the prefix length of the rule, take the sum of the differences greater than 0 as the number of bits the rule needs to be split, calculate the score of the rule split F = a (-2 k + b) - β (max (p - P, 0)), where a, b, β are pre-set parameters, b takes the exponent of 2, used to limit rule splitting; a takes an integer between 1 and 5; β takes a decimal number between 0 and 1, k is the number of bits the rule needs to be split, p is the priority of the rule, P is the priority of the rule group; (34) If F > 0, i.e. the rule can be added to an existing rule group by rule splitting, split the rule into 2 k If F > 0, i.e. the rule can be added to an existing rule group by rule splitting, split the rule into 2 If F > 0, i.e. the rule can be added to an existing rule group by rule splitting, split the rule into 2 (35) If the rule priority is greater than or equal to the priority of the rule group to which the rule is added, reorder all rule groups according to the priority.

3. The method of claim 1, wherein: The specific implementation in the step 5 is as follows: (51) Traverse the existing rule groups according to the priority order, obtain the field information used by the rule group, calculate the hash value of the data packet on the field, find the corresponding rule linked list through the hash table maintained by the rule group, and obtain the highest priority rule matched; (52) Record the highest priority rule matched, if the highest priority in the matched rule is less than the priority of the next rule group, continue to traverse the next rule group; If the highest priority is greater than the priority of the next rule group, terminate the matching in advance, and return the number of the highest priority rule currently recorded.

Citation Information

Patent Citations

  • TCAM (ternary content addressable memory)-based range matching device and method

    CN102377664A

  • Classification rule processing method, device and matching device based on network packet classification

    CN103841112A