Deterministic finite automaton compression method, device, equipment and storage medium
By constructing the failure path and default path of the deterministic finite automaton, compressing the DFA and generating a TCAM table, the problem of low DFA compression ratio in the existing technology is solved, and more efficient DFA compression and TCAM storage optimization are achieved.
Patent Information
- Application Number
- CN202210918797.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-01
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-08-01
AI Technical Summary
In the prior art, the TCAM-based DFA compression method has a low compression ratio because the DFA state encoding length is equal to the longest character string length.
By constructing a deterministic finite automaton and utilizing the invalidation path and default path of its state, the DFA is compressed to generate a TCAM table. The invalidation path is used for state encoding and migration edge fusion to generate TCAM table entries.
The compression ratio and storage economy of DFA are improved, and the DFA compression time and TCAM storage overhead are reduced.
Smart Images

Figure CN115149962B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a deterministic finite automaton compression method, apparatus, device, and storage medium. Background Art
[0002] String matching algorithms are core functions of content-based network applications such as firewalls, intrusion detection and prevention, and application-layer protocol identification. Deterministic finite automata (DFAs) are typically used to represent a given set of characteristic string rules. To improve string matching performance, DFAs are compressed using TCAM.
[0003] Currently, the main TCAM-based DFA compression method is the compact DFA method, which uses a DFA state encoding algorithm based on a common suffix tree and a DFA transition edge fusion algorithm. However, the DFA state encoding length is the length of the longest string, resulting in a low DFA compression ratio. Summary of the Invention
[0004] In view of this, the present application provides a deterministic finite automaton compression method, apparatus, device and storage medium, aiming to improve the compression ratio of DFA.
[0005] To achieve the above objectives, the present application provides a deterministic finite automaton compression method, the method comprising:
[0006] Read characteristic characters from the characteristic character string set;
[0007] Based on the characteristic characters, a deterministic finite automaton is constructed;
[0008] Based on the failure path and the default path of the state of the deterministic finite automaton, the deterministic finite automaton is compressed to obtain a TCAM table; the TCAM table is used for string matching.
[0009] Exemplarily, compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table includes:
[0010] Based on the failure path of the state of the deterministic finite automaton, the state of the deterministic finite automaton is encoded to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton;
[0011] Based on the source code, destination code and default path of each state, the transition edge of the deterministic finite automaton is compressed to obtain a table entry in the TCAM table.
[0012] Exemplarily, the state encoding of the deterministic finite automaton based on the failure path of the state of the deterministic finite automaton to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton includes:
[0013] Determining a default transition edge for each state based on a failure path of the state of the deterministic finite automaton;
[0014] Constructing a coding tree with each state as a state node and the default transition edge as an edge;
[0015] Based on the coding tree, a source code and a destination code corresponding to each state are calculated.
[0016] Exemplarily, the determining the default transition edge of each state based on the failure path of the state of the deterministic finite automaton includes:
[0017] Traversing each state and calculating the weight of the traversed state and multiple failure states; the failure state is the state on the failure path corresponding to the state; the weight is the number of common transition edges;
[0018] The failure state corresponding to the highest weight is selected as the target failure state;
[0019] A default transition edge is generated between each state and a target failure state corresponding to each state.
[0020] Exemplarily, the calculating, based on the coding tree, the source code and the destination code corresponding to each state includes:
[0021] Based on the coding tree, calculating the mask lengths of multiple state nodes;
[0022] Sort each state node in descending order based on the mask length to obtain a sequence of the state nodes;
[0023] The sequence is traversed to calculate the source code and the destination code corresponding to each state.
[0024] Exemplarily, compressing the transition edge of the deterministic finite automaton based on the source code, destination code, and default path of each state to obtain an entry in the TCAM table includes:
[0025] Based on the default path, generate the reverse default path from the root state node to multiple sub-state nodes;
[0026] Traversing the state nodes, eliminating the common migration edge between the current state node and the state node in the corresponding reverse default path, and obtaining a table entry in the TCAM table; the table entry includes the source code and the destination code.
[0027] Exemplarily, after compressing the deterministic finite automaton based on the failed path and the default path of the state of the deterministic finite automaton to obtain the TCAM table, the method includes:
[0028] Read the input characters in the string to be processed;
[0029] Traversing the entries in the TCAM table, and determining the entry with the highest matching degree with the key value as the target entry;
[0030] The TCAM table is updated based on the target entry.
[0031] Exemplarily, to achieve the above-mentioned purpose, the present application further provides a deterministic finite automaton compression method and apparatus, the deterministic finite automaton compression method and apparatus comprising:
[0032] A first reading module is used to read characteristic characters from a characteristic character string set;
[0033] A construction module, used for constructing a deterministic finite automaton based on the characteristic characters;
[0034] The compression module is used to compress the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table; the TCAM table is used for string matching.
[0035] Illustratively, to achieve the above-mentioned purpose, the present application also provides a deterministic finite automaton compression method device, which includes a memory, a processor, and a deterministic finite automaton compression method program stored on the memory and executable on the processor. When the deterministic finite automaton compression method program is executed by the processor, the steps of the deterministic finite automaton compression method as described above are implemented.
[0036] Illustratively, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a deterministic finite automaton compression method program is stored. When the deterministic finite automaton compression method program is executed by a processor, the steps of the deterministic finite automaton compression method as described above are implemented.
[0037] Compared with the prior art, the compact DFA method is used to compress TCAM based on the DFA state encoding algorithm and the DFA migration edge fusion algorithm of the common suffix tree, but the DFA state encoding length is the longest string length, resulting in a low compression ratio of the DFA. The present application reads feature characters from a feature string set; based on the feature characters, a deterministic finite automaton is constructed; based on the failure path and default path of the state of the deterministic finite automaton, the deterministic finite automaton is compressed to obtain a TCAM table; the TCAM table is used for string matching. The present application compresses the TCAM using the failure path and default path of the state of the deterministic finite automaton, without the need to compress the TCAM through the common suffix tree, and its state encoding length is not limited by the string. Therefore, the present application improves the compression ratio of the DFA. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0040] Figure 1 This is a flow chart of the first embodiment of the deterministic finite automaton compression method of the present application;
[0041] Figure 2 This is the DFA of the string set and its state transition representation of the first embodiment of the deterministic finite automaton compression method of the present application;
[0042] Figure 3 This is a schematic diagram of the DFA state encoding process of the first embodiment of the deterministic finite automaton compression method of the present application;
[0043] Figure 4 This is a schematic diagram of the failed transition edge of the DFA state of the first embodiment of the deterministic finite automaton compression method of the present application;
[0044] Figure 5 This is a schematic diagram of the failure path and default migration edge of the first embodiment of the deterministic finite automaton compression method of the present application;
[0045] Figure 6 This is a schematic diagram of the coding tree of the first embodiment of the deterministic finite automaton compression method of the present application;
[0046] Figure 7Schematic diagram of source and destination encoding of the DFA state of the first embodiment of the deterministic finite automaton compression method of the present application;
[0047] Figure 8 This is a schematic diagram of the TCAM table lookup process of the first embodiment of the deterministic finite automaton compression method of the present application;
[0048] Figure 9 Schematic diagram of the number of TCAM entries before and after coding compression in the second embodiment of the deterministic finite automaton compression method of the present application;
[0049] Figure 10 It is a structural diagram of the hardware operating environment involved in the embodiment of the present application.
[0050] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0051] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0052] This application provides a deterministic finite automaton compression method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the deterministic finite automaton compression method of the present application.
[0053] The present application provides an embodiment of a deterministic finite automaton compression method. It should be noted that although the flowchart shows a logical order, in some cases, the steps shown or described may be performed in a different order than shown. For ease of description, the following description of the steps of the deterministic finite automaton compression method is omitted. The deterministic finite automaton compression method includes:
[0054] Step S10: Read characteristic characters from a characteristic character string set.
[0055] Step S20: constructing a deterministic finite automaton based on the characteristic characters.
[0056] Step S30 : compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table; the TCAM table is used for string matching.
[0057] The specific steps are as follows:
[0058] Step S10: Read characteristic characters from a characteristic character string set.
[0059] In this embodiment, the characteristic string set is a collection of characteristic strings. A characteristic string is a string of characters consisting of numbers, letters, underscores, and the like. Characteristic characters refer to glyph-like units or symbols, including letters, numbers, operators, punctuation marks, and other symbols. Characters are a general term for letters, numbers, and symbols in computers or radio communications, and are the smallest data access unit in a data structure. For example, characteristic characters are a, b, and c; characteristic strings are abc and cab; and the characteristic string set is {cabab, baab, babc, abc}.
[0060] Step S20: constructing a deterministic finite automaton based on the characteristic characters.
[0061] In this embodiment, a deterministic finite automaton is an automaton that implements state transitions. Specifically, given a state belonging to the automaton and a character in the sum of its alphabet, the automaton transitions to the next state according to a preset transition function. This is referred to as a DFA (deterministic finite automation) in the following description.
[0062] Exemplarily, a DFA consists of a state set, a transition edge set, and an alphabet. The state set includes an initial state (source state), an accepting state (destination state), and intermediate states, where the accepting state is the state that matches the feature string. The transition edge is a directed edge that transitions from the source state to the destination state when a character is input. The alphabet is the set of valid characters processed by the DFA.
[0063] For example, for a given set of feature strings, the AC algorithm (Aho-Corasick) is used to construct a DFA and the failure transition edge of each state. Figure 2 The following table shows the DFA and its state transition table for the string set {cabab, baab, babc, abc}. The total number of DFA states is 15 (i.e., states 0, 1, ... 14), the alphabet contains 3 valid characters (i.e., characters a, b, c), and the total number of DFA transition edges is 60. A failed transition edge is a directed edge from a source state to a destination state where the transition fails.
[0064] Step S30 : compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table; the TCAM table is used for string matching.
[0065] In this embodiment, the DFA compression process includes DFA state encoding and DFA transition edge fusion. An invalidation path is constructed for each DFA state using the invalidation transition edges of each DFA state. This path is an invalidation path from that DFA state to the initial state. The default path is the path from the DFA state node to the root state node after constructing the coding tree with the state node as the state node.
[0066] Exemplarily, the compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table includes:
[0067] Step S31 : Based on the failure path of the state of the deterministic finite automaton, the state of the deterministic finite automaton is encoded to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton.
[0068] In this embodiment, the source code is the source state code of the DFA transition edge, and the destination code is the destination state code of the DFA transition edge.
[0069] Specifically, using the invalid migration edge of each DFA state, construct an invalid path for each DFA state, that is, an invalid path from the DFA state to the initial state; using the invalid path of each DFA state, calculate a default migration edge for each DFA state, that is, calculate the number of common migration edges between the DFA state and each state in its invalid path, and select the directed edge with the largest number of common migration edges and the smallest destination state depth as the default migration edge; using the default migration edge of each DFA state, construct a coding tree covering all DFA states, calculate the mask length of each state node in a bottom-up manner, and calculate the source code and destination code of each state node in a top-down manner. Figure 3 As shown in Figure 2, it is the DFA state encoding process.
[0070] Exemplarily, the state encoding of the deterministic finite automaton based on the failure path of the state of the deterministic finite automaton to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton includes:
[0071] Step S311 : determining a default transition edge for each state based on the failure path of the state of the deterministic finite automaton.
[0072] In this embodiment, the default transition edge is the directed edge with the most common transition edges and the smallest destination state depth for each DFA state on the invalidation path. A common transition edge is a transition edge between two DFA states with the same input character and the same destination state.
[0073] Exemplarily, the determining the default transition edge of each state based on the failure path of the state of the deterministic finite automaton includes:
[0074] Step S3111, traverse each state and calculate the weight of the traversed state and multiple failure states; the failure state is the state on the failure path corresponding to the state; the weight is the number of common transition edges.
[0075] In this embodiment, the weight is the number of common transition edges, and the failure state is the destination state on the failure path corresponding to the state. Calculate the weight of the DFA state and each failure state on the failure path. Figure 4 As shown in , there are transition edges and failure transition edges of DFA states, for example, Figure 5 As shown in Figure 1, the failure path 11→14→1→0 in state 11 is composed of three failure transition edges: 11→14, 14→1, and 1→0. The weight of the directed edge 11→14 is 256, the weight of the directed edge 11→1 is 256, and the weight of the directed edge 11→0 is 255.
[0076] Step S3112: Select the failure state corresponding to the highest weight as the target failure state.
[0077] In this embodiment, the weights of the various failure states are compared, and the failure state with the highest weight is selected. Figure 5 As shown, the weights of directed edge 11→14 and directed edge 11→1 are 256, and failure states 14 and 1 are selected. The depth of the target state is then compared to determine the target failure state.
[0078] Step S3113: Generate a default transition edge between each state and the target failure state corresponding to each state.
[0079] In this embodiment, the directed edge with the largest weight and the smallest destination state depth is selected as the default transition edge of the DFA state. Figure 4 As shown, the depth of failed state 14 is 3, the depth of failed state 0 is 0, and the depth of failed state 1 is 1. Therefore, state 11 selects the directed edge 11→1 with the largest weight (i.e., 256) and the smallest destination state depth (i.e., 1) as the default migration edge.
[0080] Step S312: construct a coding tree with each state as a state node and the default transition edge as an edge.
[0081] In this embodiment, the state node is a DFA state node. The state node includes a root state node and a child state node. A coding tree is constructed with the DFA state as the state node and the default transition edge of the DFA state as the edge. Figure 6As shown, a coding tree covering all 15 DFA states is constructed with the initial state 0 as the root node. For example, the default transition edge of state 5 points to state 10, the default transition edge of state 10 points to state 6, and the default transition edge of state 6 points to the initial state 0.
[0082] Step S313: Calculate the source code and destination code corresponding to each state based on the coding tree.
[0083] Exemplarily, the calculating, based on the coding tree, the source code and the destination code corresponding to each state includes:
[0084] Step S3131: Calculate the mask lengths of multiple state nodes based on the coding tree.
[0085] In this embodiment, the mask is a string of binary codes that performs a bitwise AND operation on the target field to mask the current input bits, and the mask length is the number of bits of the masked input bits.
[0086] Specifically, a bottom-up approach is used to calculate the mask length of each state code in the coding tree. Starting from the leaf state node of the coding tree, the mask length of each state code is calculated until the root state node of the coding tree (i.e., the initial state). The leaf state node is a child state node and is the node of the destination state. Figure 6 As shown, states 11, 14, 2, 5, 3, 9, 4, 8, and 12 are leaf nodes, and their mask length is 0, indicating that the source and destination codes of the leaf nodes are exact and identical. The mask lengths of non-leaf nodes in the coding tree are calculated in a bottom-up manner.
[0087]
[0088] Where, mask_lengthj is the mask length of state node j; state node i is the child state node of state node j and its mask length is mask_lengthi; represents the sum of the encoding values of all child state nodes i; 1 represents 1 encoding value of the parent node j. According to the above formula, calculate Figure 6 The mask length of non-leaf nodes, for example, the mask length of state nodes 1 and 13 is 2, the mask length of state nodes 10 and 7 is 1, the mask length of state node 6 is 3, and the mask length of the root state node 0 is 5 (indicating that the coding length of all state nodes in the coding tree is 5 bits).
[0089] Step S3142: sort each state node in descending order based on the mask length to obtain a sequence of the state nodes.
[0090] In this embodiment, before calculating the source code and destination code of the state node, the state nodes of each layer in the coding tree are sorted in descending order according to the mask length. The longer the mask length, the higher the sorting; the shorter the mask length, the lower the sorting. For example, Figure 6 The mask lengths of the first layer state nodes in the descending order are state nodes 6, 1, 7, 2, 8 and 12.
[0091] Step S3133: traverse the sequence and calculate the source code and destination code corresponding to each state.
[0092] In this embodiment, starting from the root state node of the coding tree to the leaf state node, a sequence of each layer is traversed in a top-down manner to calculate the source code and the destination code of each state node in the coding tree.
[0093] Specifically, such as Figure 7 As shown, since the mask length of the root state node 0 is 5, the source code of the root state node 0 is *****, and its destination code is the coverage lower limit value 00000 of the source code; the source code of the first-level state node 6 (mask length is 3) is the mask value 11*** of the coverage upper limit value 11111 of the parent node 0, and its destination code is the coverage lower limit value 11000 of the source code; the source code of the first-level state node 2 (mask length is 2) is the mask value 101** of the remaining coverage upper limit value 10111 of the parent node 0, and its destination code is the coverage lower limit value 10100 of the source code; the source code of the first-level state node 7 (mask length is 1) is the mask value 1001* of the remaining coverage upper limit 10011 of the parent node 0, and its destination code is the coverage lower limit value 10010 of the source code; the first-level state node 2 (mask length is 0 )'s source code is the mask value 10001 of the upper limit 10001 of the remaining coverage range of the parent node 0, and its destination code is the coverage lower limit 10001 of the source code, that is, the source code and destination code of the state node 2 are the same; similarly, the source code and destination code of the first-layer state node 8 (mask length is 0) are both 10000, and the source code and destination code of the state node 12 (mask length is 0) are both 01111; the source code of the second-layer state node 13 (mask length is 2) is the mask value 111** of the coverage upper limit 11111 of the parent node 6, and its destination code is the coverage lower limit 11100 of the source code; the source code of the second-layer state node 10 (mask length is 1) is the mask value 1101* of the remaining coverage upper limit 11011 of the parent node 6, and its destination code is the coverage lower limit 11010 of the source code.
[0094] For example, while outputting the source codes and destination codes of all DFA states, the default path of each state node in the coding tree is output, that is, a default path from the state node to the root state node. Figure 7 As shown, the default path of state 5 is 5→10→6→0.
[0095] In this embodiment, two dependent paths, namely the failure path and the default path of the DFA state, are utilized to efficiently implement DFA state encoding and DFA migration edge fusion. Compared with existing TCAM-based DFA compression methods, the DFA compression algorithm of the present invention reduces DFA compression time. Experimental results on the Snort attack signature string rule set show that in terms of DFA compression time, the DFA compression method of the present invention is reduced to 1 / 9.6 compared to the CompactDFA (Compact Deterministic Finite Automaton) method, 1 / 13362 compared to the CSE (covered state encoding) method, and 1 / 3049 compared to the SSE (Shadow State Encoding) method, greatly improving compression efficiency.
[0096] Exemplarily, after compressing the deterministic finite automaton based on the failed path and the default path of the state of the deterministic finite automaton to obtain the TCAM table, the method includes:
[0097] Step a: read the input characters in the character string to be processed.
[0098] In this embodiment, if Figure 8 FIG. 1 shows a TCAM (ternary content addressable memory) table lookup process, which is to read an input character from a character string to be processed in a data packet.
[0099] Step b: traverse the entries in the TCAM table and determine the entry with the highest matching degree with the key value as the target entry.
[0100] In this embodiment, the key values are the source state and the input character, and the current source state of the TCAM table is the initial state. Using the source state and the input character as key values, the TCAM table is searched for a match with the highest priority TCAM entry (i.e., the smallest index value), and a destination state is output. If the destination state is the accept state, the matching string rule is output.
[0101] Step c: updating the TCAM table based on the target entry.
[0102] In this embodiment, the current source state of the TCAM table is updated to the destination state, and the next input character is read in. The TCAM table is searched using the source state and the input character as key values until the input character string is processed.
[0103] Compared with the prior art, the compact DFA method is used to compress TCAM based on the DFA state encoding algorithm and the DFA migration edge fusion algorithm of the common suffix tree, but the DFA state encoding length is the longest string length, resulting in a low compression ratio of the DFA. The present application reads feature characters from a feature string set; based on the feature characters, a deterministic finite automaton is constructed; based on the failure path and default path of the state of the deterministic finite automaton, the deterministic finite automaton is compressed to obtain a TCAM table; the TCAM table is used for string matching. The present application compresses the TCAM using the failure path and default path of the state of the deterministic finite automaton, without the need to compress the TCAM through the common suffix tree, and its state encoding length is not limited by the string. Therefore, the present application improves the compression ratio of the DFA.
[0104] Exemplarily, based on the first embodiment of the deterministic finite automaton compression method of the present application, a second embodiment is proposed, wherein the method further includes:
[0105] Step S32 : compressing the transition edge of the deterministic finite automaton based on the source code, destination code and default path of each state to obtain a table entry in the TCAM table.
[0106] In this embodiment, the source code, destination code, and default path of the DFA state are used to efficiently fuse and compress multiple DFA migration edges into a TCAM table entry. The TCAM table contains multiple entries. The process includes: using the source code and destination code of each DFA state to replace the source state and destination state of each DFA migration edge; using the default path of each DFA state in the coding tree, that is, a default path from the DFA state to the root state (that is, the initial state), fusing and compressing multiple migration edges with the same input character and the same destination code into a TCAM table entry. A default TCAM table entry is added, that is, the source code is the wildcard **…*, the input character is the wildcard **…*, and the destination code is the destination code 00…0 of the initial state, at the end of the TCAM table.
[0107] Exemplarily, compressing the transition edge of the deterministic finite automaton based on the source code, destination code, and default path of each state to obtain an entry in the TCAM table includes:
[0108] Step S321: Based on the default path, generate a reverse default path corresponding to the root state node to multiple sub-state nodes.
[0109] In this embodiment, the default path is the path from the child state node to the root state node, and the reverse default path is the path from the root state node to the child state node.
[0110] Step S322 , traverse the state nodes, eliminate the common transition edge between the current state node and the state node in the corresponding reverse default path, and obtain a table entry in the TCAM table; the table entry includes the source code and the destination code.
[0111] In this embodiment, starting from the root state node in the coding tree, transition edges with the same input character and destination code between the state node and each state node on its reverse default path are eliminated. A transition edge comparison is performed between state node j and each state node i on its reverse default path in the coding tree, and transition edges with the same input character and destination code as state node j are eliminated. Finally, the remaining transition edges for each state node in the coding tree are stored in a TCAM table in ascending order of source code mask length. That is, the shorter the source code mask length of a transition edge, the higher its priority and the smaller its index value in the TCAM table.
[0112] For example, a default TCAM entry is inserted at the end of the TCAM table. When other transition edges cannot match the source state and input characters, the default TCAM entry outputs the initial state as the destination state. The default TCAM entry has a source code of the wildcard **…*, input characters of the wildcard **…*, and a destination code of the initial state, 00…0. The default TCAM entry has the lowest priority and the highest index value in the TCAM table.
[0113] For example, the compressed TCAM table is output, such as Figure 9 As shown, the TCAM table before compression contains 60 TCAM entries, including 15 DFA states, and the character table contains 3 valid characters and 1 invalid character (i.e., ^[abc], representing characters other than a, b, or c). After compression, the TCAM table contains 15 TCAM entries, each with its source state representing the source code and its destination state representing the destination code. The storage space is reduced to only one-fourth of the original. The DFA compression method of the present invention reduces TCAM storage overhead by 89.4% compared to the CompactDFA method and by 57.9% compared to the CSE method, improving storage efficiency.
[0114] In this embodiment, a conventional TCAM table contains the number of DFA states, all valid characters, one invalid character, and the destination state corresponding to each DFA state number under that character. This table occupies a large amount of storage space, and the large number of DFA transition edges results in high TCAM storage overhead. This application efficiently compresses multiple DFA transition edges into a single TCAM table entry by performing transition edge fusion on the DFA state, thereby constructing a space-efficient compressed TCAM table. This reduces storage space, thereby reducing TCAM storage overhead and improving storage efficiency.
[0115] Exemplarily, the present application further provides a deterministic finite automaton compression method device, the deterministic finite automaton compression method device comprising:
[0116] A first reading module is used to read characteristic characters from a characteristic character string set;
[0117] A construction module, used for constructing a deterministic finite automaton based on the characteristic characters;
[0118] The compression module is used to compress the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table; the TCAM table is used for string matching.
[0119] Exemplarily, the compression module includes:
[0120] an encoding submodule, configured to perform state encoding on the deterministic finite automaton based on failure paths of the states of the deterministic finite automaton, and obtain source codes and destination codes corresponding to a plurality of states of the deterministic finite automaton;
[0121] The compression submodule is used to compress the transition edge of the deterministic finite automaton based on the source code, the destination code and the default path of each state to obtain a table entry in the TCAM table.
[0122] Exemplarily, the encoding submodule includes:
[0123] a determining unit, configured to determine a default transition edge for each state based on a failure path of the state of the deterministic finite automaton;
[0124] A construction unit, configured to construct a coding tree with each state as a state node and the default transition edge as an edge;
[0125] A calculation unit is used to calculate the source code and the destination code corresponding to each state based on the coding tree.
[0126] Exemplarily, the determining unit includes:
[0127] The first traversal subunit is used to traverse each state and calculate the weight of the traversed state and multiple failure states; the failure state is the state on the failure path corresponding to the state; the weight is the number of common transition edges;
[0128] Select a subunit to select the failure state corresponding to the highest weight as the target failure state;
[0129] A generating subunit is configured to generate a default transition edge between each state and a target failure state corresponding to each state.
[0130] Exemplarily, the computing unit includes:
[0131] A calculation subunit, configured to calculate the mask lengths of a plurality of state nodes based on the coding tree;
[0132] a sorting subunit, configured to sort each state node in descending order based on the mask length to obtain a sequence of the state nodes;
[0133] The second traversal subunit is used to traverse the sequence and calculate the source code and the destination code corresponding to each state.
[0134] Exemplarily, the compression submodule,
[0135] A generation unit, configured to generate, based on the default path, a reverse default path from a root state node to a plurality of child state nodes;
[0136] The elimination unit is used to traverse the state nodes, eliminate the common migration edge between the current state node and the state node in the corresponding reverse default path, and obtain a table entry in the TCAM table; the table entry includes the source code and the destination code.
[0137] Exemplarily, the deterministic finite automaton compression method apparatus further includes:
[0138] The second reading module is used to read the input characters in the character string to be processed;
[0139] a traversal module, configured to traverse the entries in the TCAM table and determine the entry with the highest matching degree with the key value as the target entry;
[0140] An updating module is configured to update the TCAM table based on the target entry.
[0141] The specific implementation of the deterministic finite automaton compression method device of the present application is basically the same as the above-mentioned embodiments of the deterministic finite automaton compression method, and will not be repeated here.
[0142] In addition, the present application also provides a deterministic finite automaton compression method and device. Figure 10As shown, Figure 10 It is a structural diagram of the hardware operating environment involved in the embodiment of the present application.
[0143] For example, Figure 10 That is, it is a structural diagram of the hardware operating environment of the deterministic finite automaton compression method device.
[0144] like Figure 10 As shown, the deterministic finite automaton compression method device may include a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, wherein the processor 1001, the communication interface A02 and the memory 1003 communicate with each other through the communication bus 1004, and the memory 1003 is used to store computer programs; the processor 1001 is used to implement the steps of the deterministic finite automaton compression method when executing the program stored in the memory 1003.
[0145] The communication bus 1004 mentioned in the deterministic finite automaton compression method and apparatus described above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 1004 can be divided into an address bus, a data bus, and a control bus. For ease of illustration, the figure shows only one thick line, but this does not mean that there is only one bus or only one type of bus.
[0146] The communication interface 1002 is used for communication between the above-mentioned deterministic finite automaton compression method device and other devices.
[0147] The memory 1003 may include a random access memory (RMD) or a non-volatile memory (NM), such as at least one disk storage. Alternatively, the memory 1003 may be at least one storage device located away from the processor 1001.
[0148] The above-mentioned processor 1001 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0149] The specific implementation of the deterministic finite automaton compression method and device of the present application is basically the same as the above-mentioned embodiments of the deterministic finite automaton compression method, and will not be repeated here.
[0150] In addition, an embodiment of the present application also proposes a computer-readable storage medium, on which a deterministic finite automaton compression method program is stored. When the deterministic finite automaton compression method program is executed by a processor, the steps of the deterministic finite automaton compression method as described above are implemented.
[0151] The specific implementation of the computer-readable storage medium of the present application is basically the same as the embodiments of the above-mentioned deterministic finite automaton compression method, and will not be repeated here.
[0152] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0153] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0154] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, device, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0155] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A deterministic finite automaton compression method, characterized in that: The method comprises: Read characteristic characters from the characteristic character string set; Based on the characteristic characters, a deterministic finite automaton is constructed; Based on the failure paths and default paths of the states of the deterministic finite automaton, the deterministic finite automaton is compressed to obtain a TCAM table; the TCAM table is used for string matching; wherein the DFA compression process includes: DFA state encoding and DFA transition edge fusion, and constructing a failure path for each DFA state through the failure transition edges of each DFA state, that is, a failure path from the DFA state to the initial state. The default path is the path from the DFA state node to the root state node after constructing a coding tree with the DFA state as the state node; The compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table includes: Based on the failure path of the state of the deterministic finite automaton, the state of the deterministic finite automaton is encoded to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton; Compressing the transition edge of the deterministic finite automaton based on the source code, the destination code and the default path of each state to obtain an entry in the TCAM table; The failure path based on the state of the deterministic finite automaton, performing state encoding on the deterministic finite automaton, and obtaining source codes and destination codes corresponding to multiple states of the deterministic finite automaton, includes: Determining a default transition edge for each state based on a failure path of the state of the deterministic finite automaton; Constructing a coding tree with each state as a state node and the default transition edge as an edge; Based on the coding tree, a source code and a destination code corresponding to each state are calculated.
2. The method according to claim 1, wherein The step of determining the default transition edge of each state based on the failure path of the state of the deterministic finite automaton includes: Traversing each state and calculating the weight of the traversed state and multiple failure states; the failure state is the state on the failure path corresponding to the state; the weight is the number of common transition edges; The failure state corresponding to the highest weight is selected as the target failure state; A default transition edge is generated between each state and a target failure state corresponding to each state.
3. The method according to claim 1, wherein The calculating, based on the coding tree, the source code and the destination code corresponding to each state includes: Based on the coding tree, calculating the mask lengths of multiple state nodes; Based on the mask length, sorting each state node in descending order to obtain a sequence of the state nodes; The sequence is traversed to calculate the source code and the destination code corresponding to each state.
4. The method according to claim 1, wherein The method compresses the transition edge of the deterministic finite automaton based on the source code, the destination code, and the default path of each state to obtain an entry in the TCAM table, including: Based on the default path, generate the reverse default path from the root state node to multiple sub-state nodes; Traversing the state nodes, eliminating the common migration edge between the current state node and the state node in the corresponding reverse default path, and obtaining a table entry in the TCAM table; the table entry includes the source code and the destination code.
5. The method according to claim 1, wherein After compressing the deterministic finite automaton based on the failure path and the default path of the state of the deterministic finite automaton to obtain a TCAM table, the method includes: Read the input characters in the string to be processed; Traversing the entries in the TCAM table, and determining the entry with the highest matching degree with the key value as the target entry; The TCAM table is updated based on the target entry.
6. A deterministic finite automaton compression method and device, characterized in that: The device comprises: A first reading module is used to read characteristic characters from a characteristic character string set; A construction module, used for constructing a deterministic finite automaton based on the characteristic characters; A compression module is configured to compress the deterministic finite automaton based on the failure paths and default paths of the states of the deterministic finite automaton to obtain a TCAM table; the TCAM table is used for string matching; wherein the DFA compression process includes: DFA state encoding and DFA transition edge fusion, wherein a failure path is constructed for each DFA state through the failure transition edges of each DFA state, i.e., a failure path from the DFA state to the initial state; the default path is the path from the DFA state node to the root state node after constructing a coding tree with the DFA state as the state node; The compression module is used to implement: Based on the failure path of the state of the deterministic finite automaton, the state of the deterministic finite automaton is encoded to obtain source codes and destination codes corresponding to multiple states of the deterministic finite automaton; Compressing the transition edge of the deterministic finite automaton based on the source code, the destination code and the default path of each state to obtain an entry in the TCAM table; The compression module is also used to implement: Determining a default transition edge for each state based on a failure path of the state of the deterministic finite automaton; Constructing a coding tree with each state as a state node and the default transition edge as an edge; Based on the coding tree, a source code and a destination code corresponding to each state are calculated.
7. A deterministic finite automaton compression method and device, characterized in that: The deterministic finite automaton compression method device includes a memory, a processor, and a deterministic finite automaton compression method program stored on the memory and executable on the processor. When the deterministic finite automaton compression method program is executed by the processor, the steps of the deterministic finite automaton compression method as described in any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a deterministic finite automaton compression method program, which implements the steps of the deterministic finite automaton compression method according to any one of claims 1 to 5 when executed by a processor.
Citation Information
Patent Citations
Regular expression DFA space compression method and system
CN109977275A
Regular expression matching using tcams for network intrusion detection
US20120072380A1