Algorithm for realizing TCAM (Ternary Content Addressable Memory) priority matching based on linked list
By adopting linked list resource management algorithm in TCAM, the problems of traditional TCAM tables in multi-priority control are solved, priority matching and flexible resource management in a single table are realized, business needs of complex applications are met, and TCAM is improved flexibility and resource utilization efficiency.
Patent Information
- Application Number
- CN202310711645.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-15
- Publication Date
- 2024-12-17
AI Technical Summary
The orderly addition and deletion methods of traditional TCAM tables cannot meet the multi-priority needs in complex applications, especially in terms of priority control within a single table.
Using a linked list-based resource management algorithm, the TCAM chip is divided into multiple tables, each rule type allocates a specific resource pool, and priority matching is achieved through the linked list structure, and the final hit result is determined through the grouping number and storage location.
Multi-priority control in a single table is realized, the business needs of complex applications are met, the flexibility and convenience of TCAM are deeply explored, and the available and used TCAM resource pool space is quickly presented.
Smart Images

Figure CN119155245A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to network communication technology, and in particular to an algorithm for realizing TCAM priority matching based on a linked list. Background Art
[0002] With the increase in the data interface rate of network devices, the traditional software routing search mechanism can no longer meet the requirements. The common hardware solution at present is to use TCAM to achieve high-speed routing search. TCAM is a three-state content addressable memory, mainly used to search ACL, routing, etc. It is developed on the basis of CAM. A TCAM chip can be logically divided into different blocks, and each block can place a table of rules. For example, based on the TCAM support for masked ipv4 five-tuple rules (source IP, destination IP, source port, destination port, protocol), masked ipv6 five-tuple rules, tcp-flag and frame length rules, and feature code rules (binary data) matching in the splitter device, the TCAM chip is divided into 4 tables. In order to improve the search efficiency, TCAM is designed so that all entries in a single table can be accessed in parallel, and the first search hit result is returned, and the first hit is added first.
[0003] However, current TCAM-based applications are becoming more and more complex, especially the demand for priority control within a single table. The traditional TCAM table's sequential addition and deletion method can no longer meet the business's needs for multiple priorities. To solve the above problems, how to implement priority demarcation based on different groups is a difficult problem. Summary of the invention
[0004] To solve the above problems, the present invention proposes an algorithm for implementing TCAM priority matching based on a linked list, realizing TCAM table structure resource management, and finally realizing multi-priority division matching requirements. The specific steps are as follows: Step 1: Identify the multi-priority business scenarios, that is, how many types of rules need to be matched, how many rules of each type are needed, and how many priority levels need to be implemented under each type. Suppose a scenario is as follows: support 100,000 IPv4 quintuples with masks, support 100,000 IPv6 quintuples with masks, support 1,000 tcp-flag and frame length rules, support 1,000 feature code rules (binary data), each type of rule needs to implement 32 groups, and if there are multiple hits under a type of rule, the rule with the smallest group number is the final hit result; if there are multiple hits under the same group number under a type of rule, the one before the storage position is the final hit result.
[0005] Step 2: The system control plane initializes the TCAM chip table structure and divides the TCAM into 4 tables, each of which is used for different types of rules. The subsequent steps take the IPV4 five-tuple type with mask as an example. The control methods of the other three types of rules are similar. The total number of rules of this type is 100,000, so the management control plane pre-applies for a pool of 100,000 resource structures. Each resource structure member consists of a four-byte prev pointer, a four-byte next pointer, and a four-byte tcamindex. The tcamindex of the resource structure is assigned in increments of 1, that is, the tcamindex of the first resource structure is 1, and the tcamindex of the last resource structure is 100,000. The prev pointer and next pointer of each resource structure are initialized to null pointers.
[0006] Step 3: Create 32 group resource head pointers tail_service
[32] for the control linked lists, and complete the free resource pool distribution based on the rule capacity required for each group of the same type. The total capacity of the masked IPV4 five-tuple rule for all groups does not exceed 100,000. For example, in a certain scenario, the capacity of the masked IPV4 five-tuple type under group 0 is less than 500, the capacity of the masked IPV4 five-tuple type under group 1 is less than 600, and the capacity of the masked IPV4 five-tuple type under group 4 is less than 700. The remaining groups are not allocated the capacity of this type of rule. Then tail_service[0] points to the resource structure with tcamindex of 1, the prev pointer of the resource structure with tcamindex of 1 points to a null pointer, and the next pointer points to the resource structure with tcamindex of 2; the prev pointer of the resource structure with tcamindex of 2 points to the resource structure with tcamindex of 1, and the next pointer points to the resource structure with tcamindex of 3, and so on. The prev pointer of the resource structure with tcamindex of 499 points to the resource structure with tcamindex of 498, and the next pointer points to the resource structure with tcamindex of 500. The prev pointer of the resource structure with tcamindex of 500 points to the resource structure with tcamindex of 499, and the next pointer points to a null pointer. tail_service[1] points to the resource structure with tcamindex 501. The prev pointer of the resource structure with tcamindex 501 points to a null pointer, and the next pointer points to the resource structure with tcamindex 502. The prev pointer of the resource structure with tcamindex 502 points to the resource structure with tcamindex 501, and the next pointer points to the resource structure with tcamindex 503. Similarly, the prev pointer of the resource structure with tcamindex 1099 points to the resource structure with tcamindex 1098, and the next pointer points to the resource structure with tcamindex 1100. The prev pointer of the resource structure with tcamindex 1100 points to the resource structure with tcamindex 1099, and the next pointer points to a null pointer. tail_service[3] is allocated in the same way as above. After the allocation is completed, the resource structures with tcamindex greater than 1800 are all unused. The prev pointer of such resource structures points to a null pointer, and the next pointer also points to a null pointer. In addition, except for group 0, group 1, and group 4, the remaining groups do not have this type of regular capacity allocation, that is, the idle resource head pointers tail_service[num] of these groups all point to null pointers.
[0007] Step 4: When adding a masked IPV4 five-tuple rule type, the group number to which the rule belongs is known, and the free resource header pointer of the group is queried. If the free resource header pointer points to a null pointer, it indicates that the resources allocated to the group number have been used up or there are no allocated resources, and an error is returned that the rule is full; if the free resource header pointer points to a non-null pointer, the resource structure is taken out of the group's linked list, and the next pointer of the structure resource is assigned to the tail_service[num] of the group. The prev and next of the structure resource pools both point to null pointers. The tcamindex value of this structure resource is the actual location of the masked IPV4 five-tuple rule loaded on the tcam chip. The chip driver interface is called to complete the loading, and tcamindex is assigned to the storage location of the rule for easy use when deleting the rule.
[0008] Step 5: When deleting the IPV4 five-tuple rule type with mask, resources need to be released and recycled. The storage location tcamindex has been assigned when the rule is added. If tail_service[num] (num is the group number - 1) of the group to which the deleted rule belongs points to a null pointer, then tail_service[num] points to the structure resource of the tcamindex value, and prev and next of the structure resource assigned the tcamindex value both point to null pointers; if tail_service[num] of the group points to a non-null pointer, then the prev of the structure resource pointed to by tail_service[num] points to the structure resource of the tcamindex recycled this time, the prev pointer of the structure resource of the tcamindex recycled this time points to null, and next points to the structure resource pointed to by tail_service[num]. Tail_service[num] points to the tcamindex structure resource recycled this time again.
[0009] Step 6: If the rule capacity of each group needs to be reallocated, it is necessary to jump to step 2 to reinitialize the group resource head pointers and related resources of the 32 control linked lists. According to this algorithm, the priority matching requirement can be achieved when the TCAM table is looked up.
[0010] Step 7: After completing the storage of the rule structure in TCAM according to the above steps, when the data plane data reaches the device, the device extracts the key of the corresponding table structure and queries TCAM to obtain the rule matching results based on multiple priorities. According to the results, the traffic forwarding control of the data plane can be realized.
[0011] The technical solution of the present invention is based on the inventive method of using a link management resource pool in TCAM. While ensuring functional completeness, compared with the prior art, its significant beneficial effects are: 1. Priority is set based on different groups, and priority control is realized within a single table. It can meet the needs of many complex applications based on TCAM, solve the business scenario requirements of flexible setting of multi-service priorities within a single table structure of TCAM, and deeply explore the flexibility and convenience of TCAM.
[0012] 2. Conveniently and quickly present the available and utilized TCAM resource pool space. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The drawings are not intended to be drawn to scale. In the drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For clarity, not every component is labeled in every figure. Embodiments of various aspects of the present invention will now be described by way of example and with reference to the accompanying drawings, in which: Figure 1 The present invention provides a resource pool management flow chart of an algorithm for implementing TCAM priority matching based on a linked list. DETAILED DESCRIPTION
[0014] In order to make the purpose and technical solution of the present disclosure more clearly understood, the present disclosure is further elaborated in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0015] like Figure 1 As shown, the specific steps are as follows: Step 1: Identify the multi-priority business scenarios, that is, how many types of rules need to be matched, how many rules of each type are needed, and how many priority levels need to be implemented under each type. Suppose a scenario is as follows: support 100,000 IPv4 quintuples with masks, support 100,000 IPv6 quintuples with masks, support 1,000 tcp-flag and frame length rules, support 1,000 feature code rules (binary data), each type of rule needs to implement 32 groups, and if there are multiple hits under a type of rule, the rule with the smallest group number is the final hit result; if there are multiple hits under the same group number under a type of rule, the one before the storage position is the final hit result.
[0016] Step 2: The system control plane initializes the TCAM chip table structure and divides the TCAM into 4 tables, each of which is used for different types of rules. The subsequent steps take the IPV4 five-tuple type with mask as an example. The control methods of the other three types of rules are similar. The total number of rules of this type is 100,000, so the management control plane pre-applies for a pool of 100,000 resource structures. Each resource structure member consists of a four-byte prev pointer, a four-byte next pointer, and a four-byte tcamindex. The tcamindex of the resource structure is assigned in increments of 1, that is, the tcamindex of the first resource structure is 1, and the tcamindex of the last resource structure is 100,000. The prev pointer and next pointer of each resource structure are initialized to null pointers.
[0017] Step 3: Create 32 group resource head pointers tail_service
[32] for the control linked lists, and complete the free resource pool distribution based on the rule capacity required for each group of the same type. The total capacity of the masked IPV4 five-tuple rule for all groups does not exceed 100,000. For example, in a certain scenario, the capacity of the masked IPV4 five-tuple type under group 0 is less than 500, the capacity of the masked IPV4 five-tuple type under group 1 is less than 600, and the capacity of the masked IPV4 five-tuple type under group 4 is less than 700. The remaining groups are not allocated the capacity of this type of rule. Then tail_service[0] points to the resource structure with tcamindex of 1, the prev pointer of the resource structure with tcamindex of 1 points to a null pointer, and the next pointer points to the resource structure with tcamindex of 2; the prev pointer of the resource structure with tcamindex of 2 points to the resource structure with tcamindex of 1, and the next pointer points to the resource structure with tcamindex of 3, and so on. The prev pointer of the resource structure with tcamindex of 499 points to the resource structure with tcamindex of 498, and the next pointer points to the resource structure with tcamindex of 500. The prev pointer of the resource structure with tcamindex of 500 points to the resource structure with tcamindex of 499, and the next pointer points to a null pointer. tail_service[1] points to the resource structure with tcamindex 501. The prev pointer of the resource structure with tcamindex 501 points to a null pointer, and the next pointer points to the resource structure with tcamindex 502. The prev pointer of the resource structure with tcamindex 502 points to the resource structure with tcamindex 501, and the next pointer points to the resource structure with tcamindex 503. Similarly, the prev pointer of the resource structure with tcamindex 1099 points to the resource structure with tcamindex 1098, and the next pointer points to the resource structure with tcamindex 1100. The prev pointer of the resource structure with tcamindex 1100 points to the resource structure with tcamindex 1099, and the next pointer points to a null pointer. tail_service[3] is allocated in the same way as above. After the allocation is completed, the resource structures with tcamindex greater than 1800 are all unused. The prev pointer of such resource structures points to a null pointer, and the next pointer also points to a null pointer. In addition, except for group 0, group 1, and group 4, the remaining groups do not have this type of regular capacity allocation, that is, the idle resource head pointers tail_service[num] of these groups all point to null pointers.
[0018] Step 4: When adding a masked IPV4 five-tuple rule type, the group number to which the rule belongs is known, and the free resource header pointer of the group is queried. If the free resource header pointer points to a null pointer, it indicates that the resources allocated to the group number have been used up or there are no allocated resources, and an error is returned that the rule is full; if the free resource header pointer points to a non-null pointer, the resource structure is taken out of the group's linked list, and the next pointer of the structure resource is assigned to the tail_service[num] of the group. The prev and next of the structure resource pools both point to null pointers. The tcamindex value of this structure resource is the actual location of the masked IPV4 five-tuple rule loaded on the tcam chip. The chip driver interface is called to complete the loading, and tcamindex is assigned to the storage location of the rule for easy use when deleting the rule.
[0019] Step 5: When deleting the IPV4 five-tuple rule type with mask, resources need to be released and recycled. The storage location tcamindex has been assigned when the rule is added. If tail_service[num] (num is the group number - 1) of the group to which the deleted rule belongs points to a null pointer, then tail_service[num] points to the structure resource of the tcamindex value, and prev and next of the structure resource assigned the tcamindex value both point to null pointers; if tail_service[num] of the group points to a non-null pointer, then the prev of the structure resource pointed to by tail_service[num] points to the structure resource of the tcamindex recycled this time, the prev pointer of the structure resource of the tcamindex recycled this time points to null, and next points to the structure resource pointed to by tail_service[num]. Tail_service[num] points to the tcamindex structure resource recycled this time again.
[0020] Step 6: If the rule capacity of each group needs to be reallocated, it is necessary to jump to step 2 to reinitialize the group resource head pointers and related resources of the 32 control linked lists. According to this algorithm, the priority matching requirement can be achieved when the TCAM table is looked up.
[0021] Step 7: After completing the storage of the rule structure in TCAM according to the above steps, when the data plane data reaches the device, the device extracts the key of the corresponding table structure and queries TCAM to obtain the rule matching results based on multiple priorities. According to the results, the traffic forwarding control of the data plane can be realized.
[0022] Various aspects of the present invention are described in this disclosure with reference to the accompanying drawings, in which many illustrative embodiments are shown. The embodiments of the present disclosure are not necessarily defined to include all aspects of the present invention. It should be understood that the various concepts and embodiments introduced above, as well as those described in more detail below, can be implemented in any of many ways, because the concepts and embodiments disclosed by the present invention are not limited to any implementation. In addition, some aspects disclosed by the present invention can be used alone, or in any appropriate combination with other aspects disclosed by the present invention.
[0023] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
Claims
1. An algorithm for implementing TCAM priority matching based on a linked list, characterized in that: The specific steps of the method are as follows: Step 1: Identify the multi-priority business scenarios, that is, how many types of rule matches need to be implemented, how many rules of each type are needed, and how many levels of priority principles need to be implemented under each type. Suppose a scenario is as follows: support 100,000 IPv4 quintuples with masks, support 100,000 IPv6 quintuples with masks, support 1,000 tcp-flag and frame length rules, support 1,000 feature code rules (binary data), and each type of rule needs to implement 32 groups. If there are multiple hits under the same type of rule, the rule with the smallest group number is the final hit result; if there are multiple hits under the same group number under the same type of rule, the one before the storage position is the final hit result; Step 2: The system control plane initializes the TCAM chip table structure and divides the TCAM into four tables, each of which is used for different types of rules. The subsequent steps take the IPV4 five-tuple type with mask as an example. The control methods of the other three types of rules are similar. The total number of rules of this type is 100,000, so the management control plane pre-applies for a pool of 100,000 resource structures. Each resource structure member consists of a four-byte prev pointer, a four-byte next pointer, and a four-byte tcamindex. The tcamindex of the resource structure is assigned in increments of 1, that is, the tcamindex of the first resource structure is 1, and the tcamindex of the last resource structure is 100,000. The prev pointer and next pointer of each resource structure are initialized to null pointers. Step 3: Create 32 group resource head pointers tail_service[32] of the control linked list, and complete the free resource pool distribution based on the rule capacity required for each group of the same type. The total capacity of the masked IPV4 five-tuple rule of all groups does not exceed 100,000. For example, in a certain scenario, the capacity of the masked IPV4 five-tuple type under group 0 is less than 500, the capacity of the masked IPV4 five-tuple type under group 1 is less than 600, and the capacity of the masked IPV4 five-tuple type under group 4 is less than 700. The remaining groups are not allocated the capacity of this type of rule. Then tail_service[0] points to the resource structure with tcamindex of 1, t The prev pointer of the resource structure with tcamindex of 1 points to a null pointer, and the next pointer points to the resource structure with tcamindex of 2; the prev pointer of the resource structure with tcamindex of 2 points to the resource structure with tcamindex of 1, and the next pointer points to the resource structure with tcamindex of 3, and so on. The prev pointer of the resource structure with tcamindex of 499 points to the resource structure with tcamindex of 498, and the next pointer points to the resource structure with tcamindex of 500. The prev pointer of the resource structure with tcamindex of 500 points to the resource structure with tcamindex of 499. tail_service[1] points to the resource structure with tcamindex 501, the prev pointer of the resource structure with tcamindex 501 points to the null pointer, and the next pointer points to the resource structure with tcamindex 502; the prev pointer of the resource structure with tcamindex 502 points to the resource structure with tcamindex 501, and the next pointer points to the resource structure with tcamindex 503, and so on. The prev pointer of the resource structure with tcamindex 1099 points to the resource structure with tcamindex 1098, and the next pointer points to To the resource structure with tcamindex of 1100, the prev pointer of the resource structure with tcamindex of 1100 points to the resource structure with tcamindex of 1099, and the next pointer points to a null pointer; tail_service[3] is allocated in the same way as above. After the allocation is completed, all resource structures with tcamindex greater than 1800 are unused. The prev pointer of this type of resource structure points to a null pointer, and the next pointer also points to a null pointer; in addition to group 0, group 1, and group 4, the other groups do not have this type of regular capacity allocation, that is, the idle resource head pointers tail_service[num] of these groups all point to null pointers; Step 4: When adding a masked IPV4 five-tuple rule type, the group number to which the rule belongs is known, and the free resource header pointer of the group is queried. If the free resource header pointer points to a null pointer, it indicates that the resources allocated to the group number have been used up or there are no allocated resources, and an error message is returned indicating that the rule is full; if the free resource header pointer points to a non-null pointer, the resource structure is taken out of the group's linked list, and the next pointer of the structure resource is assigned to the tail_service[num] of the group. The prev and next of the structure resource pools both point to null pointers. The tcamindex value of this structure resource is the actual location of the masked IPV4 five-tuple rule loaded on the tcam chip. The chip driver interface is called to complete the loading, and tcamindex is assigned to the storage location of the rule for easy use when deleting the rule; Step 5: When deleting the IPV4 five-tuple rule type with mask, resources need to be released and recycled. The storage location tcamindex has been assigned when the rule is added. If tail_service[num] (num is the group number - 1) of the group to which the deleted rule belongs points to a null pointer, then tail_service[num] points to the structure resource of the tcamindex value, and prev and next of the structure resource assigned the tcamindex value both point to null pointers; if tail_service[num] of the group points to a non-null pointer, then the prev of the structure resource pointed to by tail_service[num] points to the structure resource of the tcamindex recycled this time, the prev pointer of the structure resource of the tcamindex recycled this time points to null, and next points to the structure resource pointed to by tail_service[num], and tail_service[num] points to the tcamindex structure resource recycled this time again; Step 6: If the rule capacity of each group needs to be reallocated, it is necessary to jump to step 2 to reinitialize the group resource head pointers and related resources of the 32 control linked lists. According to this algorithm, the priority matching requirement can be achieved when the TCAM table is looked up; Step 7: After completing the storage of the rule structure in TCAM according to the above steps, when the data plane data reaches the device, the device extracts the key of the corresponding table structure and queries TCAM to obtain the rule matching results based on multiple priorities. According to the results, the traffic forwarding control of the data plane can be realized.
