Flow table matching method, message forwarding device, electronic equipment and medium
By using the hash flow table group method in the high-speed network forwarding chip, a hash flow table that adapts to the changing field combination is solved, and the cost-effective flow table matching effect is achieved.
Patent Information
- Application Number
- CN202510057120.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-03-28
AI Technical Summary
In high-speed network forwarding chips, the flow table matching efficiency and capacity are difficult to meet the requirements, and the high cost and high energy consumption of TCAM have become bottlenecks.
Using the hash flow table group method, the hash flow table is constructed through the CPU module, adapting to the changing field combination, and avoiding the fuzzy matching situation outside the hash flow table to achieve efficient matching of the flow table.
It realizes efficient matching of flow tables, meets the cost-effectiveness requirements of message forwarding chip convection tables, and has large capacity and low cost characteristics.
Smart Images

Figure CN119728544A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of message forwarding, and in particular relates to a flow table matching method, a message forwarding device, an electronic device and a medium. Background Art
[0002] Flow table matching is generally used in network forwarding processing systems or network forwarding chips to find flows (message sequences) in which multiple field items in network messages have specific values and perform specified operations.
[0003] For the network forwarding processing system, because there are multiple devices or hardware and software equipment to work together, the cache space is relatively large and the time for flow table search is relatively ample. Therefore, polling search, binary tree or multi-tree search, integrated hash table multi-field multiple search and other methods can be used.
[0004] For network forwarding chips, the cache space is very limited, and the search time is strictly limited. At the same time, since there are more than a dozen meaningful header fields in IP packets, the total bit length of these fields reaches hundreds of bits, and the flow matching also has fuzzy matching of fields (matching information contains wildcards), various search methods are difficult to meet the efficiency requirements. Therefore, the chip often has to use ternary content addressable memory (TCAM) internally. Relying on the high speed and high flexibility of TCAM, both precise table entries and fuzzy table entries can be stored in TCAM. However, due to the high cost and high energy consumption of TCAM, as the forwarding rate and switching density continue to increase, TCAM often occupies a large amount of storage resources but cannot provide enough table entries. Therefore, how to improve the matching efficiency and capacity of the flow table and reduce the implementation cost of the flow table has become an important issue in high-speed network forwarding chips. Summary of the invention
[0005] The purpose of the present invention is to provide a flow table matching method, a message forwarding device, an electronic device and a medium, which can be used as a low-cost and high-efficiency flow table solution in a high-speed network forwarding chip.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions: In a first aspect, the present invention provides a flow table matching method, the method comprising: Obtain a target message, parse the target message, and obtain multiple fields of the target message; Based on the combinations existing in the pre-constructed original flow table, multiple fields of the target message are combined to obtain multiple first field groups, and hash operations are performed on each first field group at the same time to obtain multiple hash values corresponding to each first field group; the hash value corresponding to the first field group is used as the address, and a table is looked up in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches. If more than one table has a matching table, the table entry with the highest priority is selected from the matching table as the hit table entry according to the pre-defined priorities for different combinations. If there is no matching table, it is determined that the message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table. Therefore, according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table.
[0007] Preferably, the method further comprises: constructing a first-level hash flow table group, comprising: Obtaining an original flow table, wherein the original flow table includes multiple table entries, each table entry includes multiple fields and characteristic values corresponding to each field; Based on the field type of each table item, the fields of the multiple table items are grouped to obtain multiple second field groups, each second field group having table items with the same field combination; Performing a hash operation on the characteristic value of each second field group to obtain a hash value corresponding to each second field group; A hash flow table is constructed according to the hash value and characteristic value corresponding to each second field group to obtain multiple hash flow tables of the first level; Multiple hash flow tables of the first level are combined into a first level hash flow table group.
[0008] Preferably, based on the combinations existing in the pre-constructed original flow table, multiple fields of the target message are sorted to obtain multiple first field groups, including: Obtain table entries of multiple second field groups corresponding to the original flow table; Based on the table entries of each second field group, multiple fields of the target message are sorted to obtain multiple first field groups, and the number of the first field groups is the same as that of the second field groups.
[0009] Preferably, the method further comprises: Encoding the field groups in each first-level hash flow table to obtain a plurality of encoded first-level hash flow table field groups, wherein the field groups in each first-level hash flow table are encoded as mask encoding or number encoding; A priority is assigned to each encoded first-level hash flow table field group to obtain predefined priorities for different combinations.
[0010] In a second aspect, the present invention provides a message forwarding device, the device comprising: a message forwarding chip, the message forwarding chip comprising: a CPU module and a message forwarding module, the CPU module being communicatively connected to the message forwarding module; The CPU module is used to: construct a hash flow table group according to the table items of the original flow table, and send the hash flow table group to the message forwarding module, wherein the hash flow table group includes multiple hash flow tables; The message forwarding module is used to: obtain a target message, parse the target message, and obtain multiple fields of the target message; based on the combinations existing in the pre-constructed original flow table, combine the multiple fields of the target message to obtain multiple first field groups, and simultaneously perform hash operations on each first field group to obtain multiple hash values corresponding to each first field group; use the hash value corresponding to the first field group as the address, and look up the table in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches. If more than one table has a matching table, select the table entry of the matching table with the highest priority in the matching table as the hit table entry according to the pre-defined priorities of different combinations. If there is no matching table, it is determined that the target message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table. Therefore, according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table.
[0011] Preferably, the message forwarding chip further includes: a RAM module, and the hash flow table group is stored in the RAM module.
[0012] Preferably, the message forwarding chip is an integrated circuit ASIC, an FPGA chip loaded with message forwarding function logic, a switching chip or a routing chip.
[0013] In a third aspect, the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned flow table matching method when executing the computer program.
[0014] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned flow table matching method when executed by a processor.
[0015] Beneficial effects: The present invention utilizes the relatively limited number of field combinations in the hash flow table, and the CPU module constructs the hash flow table. The hash flow table can adapt to the changing field combination, and at the same time avoids the fuzzy matching situation outside the hash flow table, thereby overcoming the weakness of the hash table, realizing the matching of the flow table, and meeting the high cost-effectiveness requirement of the message forwarding chip for the flow table; therefore, the hash flow table group of the present invention not only meets the flexibility requirement of the message forwarding chip for the flow table, but also has the characteristics of large capacity and low cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings: Figure 1 It is a flowchart of a flow table matching method provided by an embodiment of the present invention; Figure 2 is a schematic diagram of a raw flow table provided by an embodiment of the present invention; Figure 3 is a schematic diagram of a first hash flow table provided by an embodiment of the present invention; Figure 4 is a schematic diagram of a second hash flow table provided in one embodiment of the present invention; Figure 5 is a schematic diagram of a third hash flow table provided by an embodiment of the present invention; Figure 6 It is a block diagram of a message forwarding device provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0018] Embodiment 1 Figure 1 FIG. 1 is a flow chart of a flow table matching method provided by an embodiment of the present invention. Figure 1 As shown, this embodiment provides a flow table matching method, the method includes steps S10 to S30; before executing steps S10 to S30, it is necessary to build a first-level hash flow table group in advance, therefore, the method includes: building a first-level hash flow table group, including: Step a10: Obtain an original flow table, where the original flow table includes multiple table entries, each of which includes multiple fields and characteristic values corresponding to each field.
[0019] In this embodiment, the structure of the original flow table is as follows: Figure 2 As shown in the figure, there are 8 entries in the original flow table. The fields of each entry include address, source MAC (Media Access Control), source IP (Internet Protocol), destination IP, protocol, source port, destination port, tunnel type and tunnel ID, etc. Each field corresponds to a specific characteristic value. For example, the characteristic value of the source IP field of the first entry is 18.7.9.233; when the characteristic value is "*", it means that the corresponding field is empty.
[0020] Step a20: based on the field type of each table item, the fields of the multiple table items are grouped to obtain multiple second field groups, each second field group having multiple table items with the same field.
[0021] In this embodiment, Figure 2 For example, the destination MAC field and the protocol field in the second table item and the sixth table item have characteristic values and are not empty. In this case, the second table item and the sixth table item are table items with the same fields, and the fields in the second table item and the sixth table item are regarded as a second field group. For another example: the third table item, the seventh table item and the eighth table item have the same fields, and the fields in the third table item, the seventh table item and the eighth table item are regarded as a second field group.
[0022] Step a30: Perform a hash operation on each second field group to obtain a hash stream value corresponding to each second field group.
[0023] In this embodiment, in each second field group, the characteristic values of all fields belonging to the same table entry are concatenated and then used as input of a hash function, and the hash function outputs a hash stream value. Each table entry corresponds to a hash stream value.
[0024] Step a40: construct a hash flow table according to the hash value and characteristic value corresponding to each second field group, and obtain multiple hash flow tables of the first level.
[0025] In this embodiment, the hash flow table is as follows: Figure 3-5 As shown, the hash flow table has a new field, namely, the Hash address. The characteristic value corresponding to the Hash address is the hash flow value corresponding to each table item. The hash flow table is composed of the hash flow value, the fields in the second field group, and the corresponding characteristic values of each table item. One second field group corresponds to one hash flow table.
[0026] Step a50: combining multiple hash flow tables at the first level into a first-level hash flow table group, and combining multiple hash flow tables at the first level together into a first-level hash flow table group.
[0027] After the hash flow table is constructed, steps S10 to S30 are executed as follows: Step S10: Obtain a target message, parse the target message, and obtain multiple fields of the target message; wherein, the parsing of the target message has the following types: Fixed-length parsing: directly cut the field according to the predetermined length; Length field indication analysis: The beginning of the message contains a field indicating the length of the message body; Delimiter delimited parsing: Fields in a message are separated by specific characters; Based on tag-length-value (TLV) parsing: Each field consists of a tag (identifying the field type), a length (field length), and a value.
[0028] Step S20: Based on the combinations existing in the pre-constructed original flow table, multiple fields of the target message are combined to obtain multiple first field groups, and hash operations are performed on each first field group at the same time to obtain the hash value corresponding to each first field group; the hash value corresponding to the first field group is used as the address to look up the table in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches, a matching table entry is obtained. If more than one table has a matching table, the table entry of the matching table with the highest priority is selected from the matching table according to the pre-defined priorities of different combinations as the hit table entry. If there is no matching table, it is determined that the message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table, so according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table; wherein, the second-level flow table can be the original flow table, or it can be constructed based on the original flow table. As a further optimization of this embodiment, before matching, the method also includes: Step b10: encoding the field group in each first-level hash flow table to obtain a plurality of encoded first-level hash flow table field groups, wherein the field group in each first-level hash flow table is encoded as a mask code or a number code; Step b20: Assign a priority to each encoded first-level hash flow table field group to obtain pre-defined priorities for different combinations; wherein the level of priority is related to the user's specific application flow table and can be formulated according to actual needs.
[0029] In this embodiment, the search and matching is performed in descending order of priority, and the successfully matched entry is the matching flow table entry of the target message.
[0030] The present invention utilizes the relatively limited number of field combinations in the hash flow table, and the CPU module constructs the hash flow table. The hash flow table can adapt to the changing field combination, and at the same time avoids fuzzy matching outside the hash flow table, thereby overcoming the weakness of the hash table, realizing the matching of the flow table, and meeting the high cost-effectiveness requirements of the message forwarding chip for the flow table; therefore, the hash flow table group of this embodiment not only meets the flexibility requirements of the message forwarding chip for the flow table, but also has the characteristics of large capacity and low cost.
[0031] Embodiment 2 Figure 6 FIG. 1 is a block diagram of a message forwarding device provided by an embodiment of the present invention. Figure 6 As shown, this embodiment provides a message forwarding device, the device includes: a message forwarding chip, the message forwarding chip includes: a CPU module and a message forwarding module, the CPU module is communicatively connected with the message forwarding module; The CPU module is used for: constructing a hash flow table group according to the table items of the original flow table, and sending the hash flow table group to the message forwarding module, wherein the hash flow table group includes multiple hash flow tables.
[0032] The message forwarding module is used to: obtain a target message, parse the target message, and obtain multiple fields of the target message; based on the combinations existing in the pre-constructed original flow table, combine the multiple fields of the target message to obtain multiple first field groups, and perform hash operations on each first field group to obtain multiple hash values corresponding to each first field group; use the hash value corresponding to the first field group as the address, and look up the table in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches. If more than one table has a matching table, select the table entry of the matching table with the highest priority in the matching table as the hit table entry according to the pre-defined priorities of different combinations. If there is no matching table, it is determined that the message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table. Therefore, according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table.
[0033] In this embodiment, the specific steps of the CPU module constructing the hash flow table group according to the table entries of the original flow table are the same as steps a10 to a40 of the first embodiment, and the steps are not repeated in this embodiment.
[0034] As a further optimization of this embodiment, the message forwarding chip further includes: a RAM (Random Access Memory) module, and the hash flow table group is stored in the RAM module.
[0035] As a further optimization of this embodiment, the message forwarding chip is an integrated circuit ASIC (Application-Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) chip loaded with message forwarding function logic, a switching chip or a routing chip.
[0036] From the perspective of resource occupation, energy consumption, cost, etc., hash tables are always much better than TCAMs. However, the reason why TCAMs are still widely used is that hash tables often cannot provide sufficient flexibility to cope with changing matching field combinations and fuzzy matching situations. Therefore, in this embodiment, the CPU module constructs and processes the flow table by taking advantage of the relatively limited number of field combinations in the hash flow table, adapts the variable field combinations through the hash table group, and avoids fuzzy matching situations outside the hash table, thus overcoming the weaknesses of the hash table, achieving flow table matching, and meeting the high cost-effectiveness requirements of the message forwarding chip for the flow table.
[0037] Embodiment 3 This embodiment further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the flow table matching method in the first embodiment when executing the computer program.
[0038] This embodiment further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the flow table matching method in the first embodiment is implemented.
[0039] The present invention utilizes the fact that the number of field combinations in the hash flow table is relatively limited. The hash flow table can adapt to the changing field combinations, and at the same time avoids fuzzy matching situations outside the hash flow table, thereby overcoming the weaknesses of the hash table, realizing the matching of the flow table, and meeting the high cost-effectiveness requirements of the message forwarding chip for the flow table.
[0040] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0041] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0042] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A flow table matching method, characterized in that: The method comprises: Obtain a target message, parse the target message, and obtain multiple fields of the target message; Based on the combinations existing in the pre-constructed original flow table, multiple fields of the target message are combined to obtain multiple first field groups, and hash operations are performed on each first field group at the same time to obtain multiple hash values corresponding to each first field group; the hash value corresponding to the first field group is used as the address, and a table is looked up in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches. If more than one table has a matching table, the table entry of the matching table with the highest priority is selected from the matching table according to the pre-defined priorities of different combinations as the hit table entry. If there is no match table, it is determined that the target message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table. Therefore, according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table.
2. The flow table matching method according to claim 1, characterized in that: The method further includes: constructing a first-level hash flow table group, including: Obtaining an original flow table, wherein the original flow table includes multiple table entries, each table entry includes multiple fields and characteristic values corresponding to each field; Based on the field type of each table item, the fields of the multiple table items are grouped to obtain multiple second field groups, each second field group having table items with the same field combination; Performing a hash operation on the characteristic value of each second field group to obtain a hash value corresponding to each second field group; A hash flow table is constructed according to the hash value and characteristic value corresponding to each second field group to obtain multiple hash flow tables of the first level; Multiple hash flow tables of the first level are combined into a first level hash flow table group.
3. The flow table matching method according to claim 2, characterized in that: Based on the combinations existing in the pre-built original flow table, multiple fields of the target message are combined to obtain multiple first field groups, including: Obtain table entries of multiple second field groups corresponding to the original flow table; Based on the table entry of each second field group, multiple fields of the target message are combined to obtain multiple first field groups, and the number of the first field groups is the same as that of the second field groups.
4. The flow table matching method according to claim 2, characterized in that: The method further comprises: Encoding the field groups in each first-level hash flow table to obtain a plurality of encoded first-level hash flow table field groups, wherein the field groups in each first-level hash flow table are encoded as mask encoding or number encoding; A priority is assigned to each encoded first-level hash flow table field group to obtain predefined priorities for different combinations.
5. A message forwarding device, characterized in that: The device comprises: a message forwarding chip, the message forwarding chip comprises: a CPU module and a message forwarding module, the CPU module is communicatively connected with the message forwarding module; The CPU module is used to: construct a first-level hash flow table group according to the table items of the original flow table, and send the first-level hash flow table group to the message forwarding module, wherein the first-level hash flow table group includes multiple hash flow tables; The message forwarding module is used to: obtain a target message, parse the target message, and obtain multiple fields of the target message; based on the combinations existing in the pre-constructed original flow table, combine the multiple fields of the target message to obtain multiple first field groups, and simultaneously perform hash operations on each first field group to obtain multiple hash values corresponding to each first field group; use the hash value corresponding to the first field group as the address, and look up the table in the pre-constructed first-level hash flow table group. If the table entry is valid, that is, it matches. If more than one table has a matching table, select the table entry of the matching table with the highest priority in the matching table as the hit table entry according to the pre-defined priorities of different combinations. If there is no matching table, it is determined that the target message is not in the original flow table; the table entry of the first-level hash flow table group also defines at least the index address of the second-level flow table. Therefore, according to the content of the hit table entry, the second-level flow table is looked up as the address to obtain the matching table entry content of the original flow table.
6. The message forwarding device according to claim 5, characterized in that: The message forwarding chip further includes: a RAM module, in which the first-level hash flow table group and the second-level flow table are stored.
7. The message forwarding device according to claim 5, characterized in that: The message forwarding chip is an integrated circuit ASIC, an FPGA chip loaded with message forwarding function logic, a switching chip or a routing chip.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the flow table matching method according to any one of claims 1 to 4 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the flow table matching method described in any one of claims 1 to 4 is implemented.