Method and device for generating pre-screened character string in regular expression rule
By generating non-deterministic finite state automata and counting the number of occurrences of candidate strings to determine pre-screened strings, regular expression matching is optimized, solving the problem of low regular expression matching performance in high-traffic environments, and improving the efficiency of aggregation and distribution equipment. processing efficiency.
Patent Information
- Application Number
- CN202410863733.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-29
- Publication Date
- 2024-10-11
AI Technical Summary
In a high-traffic environment, when regular expressions are matched in the aggregation and distribution equipment, the performance decreases because the pre-screened strings are the same and cannot meet the needs of processing large-traffic packets.
By generating non-deterministic finite state automata for regular expression rules, candidate strings are determined, and the number of occurrences of each candidate string in the global linked list array is counted, the pre-screened string is determined based on the minimum number of occurrences, and the pre-screened string is optimized extraction method.
Significantly improves the efficiency of regular expression matching, is suitable for aggregation and distribution equipment in high-traffic environments, and solves the problem of performance degradation when the pre-screened strings are the same.
Smart Images

Figure CN118761384A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer information processing, and in particular to a method and device for generating a pre-screened character string in a regular expression rule. Background Art
[0002] Convergence and diversion equipment is a network device used in specific scenarios. It is usually connected to the network in bypass mode. The Internet packets split or mirrored from the switches / routers of the Internet backbone network are sent to the device, which performs preliminary analysis and processing according to the specified rules and forwards them to the specified back-end business system for further analysis. Convergence and diversion equipment is usually deployed in the operator backbone network and above. The traffic received by a single device is usually above 100Gbps, and currently can reach the level of 10Tbps, and will grow rapidly in the foreseeable future. Therefore, the diversion rule module of the convergence and diversion equipment needs to achieve ultra-large traffic message matching and processing (modification, forwarding, copying, discarding, statistics, etc.) with extremely low latency. Ordinary switches mainly rely on the switching chip ACL to match and process messages. Although the processing performance can reach the line speed level, the number of ACL rules is limited by the brand and model of the switching chip. Currently, high-end switching chips only reach the level of 10K. The back-end business system in a large-traffic environment requires the number of diversion rules of the convergence and diversion equipment to start from 100,000 and reach hundreds of millions, which the switching chip cannot meet. Therefore, the convergence and diversion equipment often uses programmable chips (such as FPGA, NP, etc.) on the board to implement the diversion rule module. The programmable chip can customize the supported functions according to the needs, and can use its own resources to implement the large-capacity diversion rule module. The number of rules can reach hundreds of millions, and it can also ensure line speed forwarding. However, some complex functions (such as message replication, message deduplication, etc.) will also affect the processing performance of the programmable chip.
[0003] A regular expression is a widely used computer text pattern that is used to describe text with specific characteristics or regularities. A regular expression uses a single string to describe and match a series of strings that match a certain syntactic rule. It is usually used to retrieve and replace text that meets a certain pattern (rule). The grammatical rules of regular expressions are universal and can be referenced by various computer programming languages. For example, the regular expression "[a-zA-Z0-9]+" means matching at least one uppercase English letter, lowercase English letter, or number 0 to 9 in the string, and "^abc(def|ghi)jkl" means matching a string that starts with abc, followed by def or ghi, and then jkl (it doesn't matter what characters are after jkl).
[0004] In some usage scenarios of aggregation and distribution devices, it is necessary to match the message data in the network traffic according to regular expressions and extract the messages containing character strings that conform to a specific format for further analysis and processing.
[0005] The above information disclosed in the Background section is only for enhancement of understanding of the background of the present application and therefore it may contain information that does not constitute the prior art that is already known to a person of ordinary skill in the art. Summary of the invention
[0006] In view of this, the present application provides a method and device for generating pre-screened strings in regular expression rules, which can solve the problem of performance degradation when the pre-screened strings are the same in the prior art, significantly improve the efficiency of regular expression matching, and is suitable for convergence and diversion equipment in high-traffic environments.
[0007] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0008] According to one aspect of the present application, a method for generating a pre-screened string in a regular expression rule is proposed, the method comprising: generating a corresponding non-deterministic finite state automaton for the regular expression rule; determining a candidate string for the regular expression rule based on the non-deterministic finite state automaton; counting the number of times each candidate string appears in a global linked list array; and determining a pre-screened string corresponding to the regular expression rule based on the candidate string with the minimum number of occurrences in each regular expression rule.
[0009] In an exemplary embodiment of the present application, it also includes: associating the pre-screened string with its corresponding regular expression and sending it to the convergence and diversion device; the convergence and diversion device matches and distributes the message based on the pre-screened string.
[0010] In an exemplary embodiment of the present application, the pre-screened character string and its corresponding regular expression are associated, including: generating a full-inclusive floating feature code rule through the pre-screened character, the identifier of the regular expression, and the key path identifier; and associating the full-inclusive floating feature code rule with the regular expression.
[0011] In an exemplary embodiment of the present application, a corresponding non-deterministic finite state automaton is generated for a regular expression rule, including: obtaining a regular expression rule; performing a legality check on each rule in the regular expression rule; after the legality check passes, generating a non-deterministic finite state automaton for the regular expression rule.
[0012] In an exemplary embodiment of the present application, determining the candidate strings of the regular expression rules based on a non-deterministic finite state automaton includes: traversing the non-deterministic finite state automaton of each of the regular expression rules; extracting the candidate strings corresponding to each of the regular expression rules; and storing the candidate strings in a global linked list array.
[0013] In an exemplary embodiment of the present application, the number of times each candidate string appears in the global linked list array is counted, including: setting the initial value of the number of occurrences of each candidate string to 1; comparing all candidate strings pairwise; and counting the number of times each candidate string appears in the global linked list array based on the comparison results.
[0014] In an exemplary embodiment of the present application, all candidate character strings are compared pairwise, including: comparing the lengths of the candidate character strings; for candidate characters of different lengths, determining whether the shorter candidate character is contained by the longer one, if so, the number of occurrences of the shorter candidate character is increased; and comparing the string spellings of candidate character strings of the same length.
[0015] In an exemplary embodiment of the present application, all candidate character strings are compared in pairs, including: truncating candidate character strings exceeding a preset length; and comparing the truncated candidate character strings in a random or traversal manner.
[0016] In an exemplary embodiment of the present application, a pre-screened string corresponding to a regular expression rule is determined based on the candidate string with the minimum number of occurrences in each regular expression rule, including: counting the number of occurrences of all candidate strings on each key path in each regular expression rule; and taking the string with the minimum number of occurrences on each key path in each regular expression rule as the pre-screened string on the key path.
[0017] According to one aspect of the present application, a device for generating pre-screened strings in regular expression rules is proposed, and the device includes: a conversion module, which is used to generate a corresponding non-deterministic finite state automaton for the regular expression rule; a candidate module, which is used to determine the candidate strings of the regular expression rule based on the non-deterministic finite state automaton; a statistical module, which is used to count the number of times each of the candidate strings appears in a global linked list array; and a character module, which is used to determine the pre-screened string corresponding to the regular expression rule based on the candidate string with the minimum number of occurrences in each regular expression rule.
[0018] According to one aspect of the present application, an electronic device is proposed, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.
[0019] According to one aspect of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described above is implemented.
[0020] According to the method and device for generating pre-screened strings in regular expression rules of the present application, a corresponding non-deterministic finite state automaton is generated for the regular expression rule; the candidate strings of the regular expression rule are determined based on the non-deterministic finite state automaton; the number of times each candidate string appears in a global linked list array is counted; and the pre-screened string corresponding to the regular expression rule is determined based on the candidate string with the minimum number of appearances in each regular expression rule. This method can solve the problem of performance degradation when the pre-screened strings are the same in the prior art, significantly improve the efficiency of regular expression matching, and is suitable for convergence and diversion equipment in high-traffic environments.
[0021] It should be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The above and other objects, features and advantages of the present application will become more apparent by describing in detail the exemplary embodiments thereof with reference to the accompanying drawings. The accompanying drawings described below are only some embodiments of the present application, and it is clear to a person skilled in the art that other accompanying drawings can be obtained from these accompanying drawings without creative effort.
[0023] Figure 1 It is a schematic diagram of a method for generating a pre-screened character string in a regular expression rule in the prior art.
[0024] Figure 2 The present invention is a flowchart of a method for generating a pre-screened character string in a regular expression rule according to an exemplary embodiment.
[0025] Figure 3 The present invention is a flowchart of a method for generating a pre-screened character string in a regular expression rule according to another exemplary embodiment.
[0026] Figure 4 The present invention is a flowchart of a method for generating a pre-screened character string in a regular expression rule according to another exemplary embodiment.
[0027] Figure 5 The present invention is a block diagram of a device for generating a pre-screened character string in a regular expression rule according to an exemplary embodiment.
[0028] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment.
[0029] Figure 7 It is a block diagram of a computer-readable medium according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this application will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0031] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0033] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0034] It should be understood that although the terms first, second, third, etc. may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another component. Therefore, the first component discussed below can be referred to as the second component without departing from the teachings of the concepts of the present application. As used herein, the term "and / or" includes any one of the associated listed items and all combinations of one or more.
[0035] Those skilled in the art will appreciate that the drawings are merely schematic diagrams of example embodiments, and the modules or processes in the drawings are not necessarily necessary for implementing the present application, and therefore cannot be used to limit the scope of protection of the present application.
[0036] The flowchart diagram of the existing scheme is as follows Figure 1As shown in the figure, in order to check whether there are messages with data features that meet the specific regular expression in the network traffic, the convergence and diversion device sends the regular expression rule to the rule query engine of the programmable chip. If the payload part of each received message is simply extracted and matched with the regular expression in the regular expression rule, the performance will be very low. For example, the regular expression "[abc](def|ghi)jkl" will check byte by byte in the string to be queried whether it belongs to one of the three characters "abc". If so, check whether the next 3 bytes are "def" or "ghi". If so, check whether the next 3 bytes are "jkl". For the convergence and diversion device diversion board that needs to process up to 10Gb of traffic per second or even more, this query algorithm cannot meet the requirements at all.
[0037] Therefore, when regular expressions are actually used for string matching, a state machine is introduced to write the program. By converting a specific regular expression into a non-deterministic finite state automaton (NFA), the string to be queried is then input into the state machine, and the output result will be a match or a mismatch. The specific algorithm is fully described in the public network and will not be repeated here.
[0038] Since the table lookup solution generated after the state machine conversion is still not efficient enough, the existing solution is optimized from the perspective of reducing the possible matching regular expression rules. The idea is that if a message cannot match the substring that must appear in all the strings corresponding to a regular expression, then the message cannot match this regular expression. Therefore, combined with the advantages of the full-package floating rule, the regular expression rules are pre-screened and matched. The method is to extract a common substring from each regular expression. This substring is a common subset of all possible strings represented by the regular expression; if this substring does not exist, it can also be a union of multiple substrings that together constitute a common subset. For example, the common subset of "[abc](def|ghi)jkl" can be "jkl", and the common subset of "[abc](def|ghi)" is "def" and "ghi" (these two substrings together constitute a common subset).
[0039] In the specific implementation scheme, after converting the regular expression into a non-deterministic finite state automaton (NFA), its finite critical path can be determined. The critical path is traversed and searched, and for each critical path, the longest string among the continuous substrings contained therein is found and set as the pre-screened substring of the critical path.
[0040] Each pre-screening substring (i.e., common subset string) of each rule is configured as a signature code to a full-package floating signature code rule. The messages matched by these full-package floating signature code rules are sent to the regular expression state machine query table as suspected matching results for query. The query table adopts a structure similar to a hash table, and the hash key value is calculated through the pre-screening substring. The regular expression rules with the same pre-screening substring are hung on the same linked list. This greatly reduces the number of messages to be queried in the state machine, thereby greatly improving the matching efficiency of the regular expression rules.
[0041] To reduce the false hit rate of pre-screening, the pre-screening string should be as long as possible. Therefore, in the process of converting the regular expression into a state machine, the longest one among multiple common subsets of the regular expression is extracted. If there are multiple common subsets with the same length, one is randomly selected (usually the first one from the front to the back).
[0042] However, in some scenarios, the pre-screened strings extracted by multiple regular expressions may be the same. In this case, the regular expression state machine query hash table degenerates into a single linked list, and the pre-screened hit message must continue to search all corresponding regular expression rules, which will seriously affect the rule search performance.
[0043] That is, in a specific application scenario, the pre-screened string extracted by multiple regular expression rules is the same string, resulting in a serious degradation of rule search performance. For example, 2,000 regular expression rules in the form of "asdgk(sf|g7)vb..lj?bc[0-9]XXXX" (where "XXXX" represents random changes) are configured. Since the longest substring in the key path is "asdgk", "asdgk" in each regular expression rule will be selected as the pre-screened substring, causing all packets with the "asdgk" string in the payload to check these 2,000 regular expression rules, and the search performance will become extremely low.
[0044] In order to solve the technical difficulties in the prior art, this application proposes a method for generating pre-screened strings in regular expression rules, which takes all regular expressions of the entire machine into consideration globally, and regards the common substrings extracted from all regular expressions as equal and sorts them by frequency of occurrence. Then, the extraction method of the pre-screened strings is optimized. The content of this application is described in detail below with the help of specific embodiments.
[0045] Figure 2 The flowchart of a method for generating a pre-screened string in a regular expression rule according to an exemplary embodiment is shown. The method 20 for generating a pre-screened string in a regular expression rule at least includes steps S202 to S208.
[0046] like Figure 2As shown, in S202, a corresponding non-deterministic finite state automaton is generated for the regular expression rule. For example, a regular expression rule can be obtained; each rule in the regular expression rule is subjected to a legality check; after the legality check passes, a non-deterministic finite state automaton (NFA) of the regular expression rule is generated.
[0047] First, the regular expression to be configured is checked for legality. After the check is passed, the subsequent processing step of the preferred pre-screening string is performed. Among them, NFA is a data structure that describes the matching behavior of the regular expression and can be used for string matching in the subsequent steps.
[0048] In S204, candidate strings of the regular expression rule are determined based on the non-deterministic finite state automaton. For example, the non-deterministic finite state automaton of each regular expression rule is traversed; the candidate strings corresponding to each regular expression rule are extracted; and the candidate strings are stored in a global linked list array.
[0049] In S206, the number of times each candidate string appears in the global linked list array is counted. For example, the initial value of the number of times each candidate string appears is set to 1; all candidate strings are compared in pairs; and the number of times each candidate string appears in the global linked list array is counted according to the comparison result.
[0050] More specifically, all candidate character strings are compared pairwise, and a character string exceeding MAX_LITERAL_LENGTH (indicating the maximum length of the feature code supported by the full-package floating feature code rule) bytes is considered to be MAX_LITERAL_LENGTH bytes, and only MAX_LITERAL_LENGTH bytes are taken according to a certain algorithm (the specific implementation scheme is described separately); the comparison method is to compare whether the string contents are the same when the lengths are the same (pay attention to uppercase and lowercase letters), and if they are equal, the number of occurrences is increased by 1, and if the lengths are different, check whether the shorter one is included in the longer one, and if so, the number of occurrences of the shorter one is increased by 1.
[0051] In S208, the pre-screened string corresponding to each regular expression rule is determined based on the candidate string with the minimum number of occurrences in each regular expression rule. For example, the number of occurrences of all candidate strings on each key path in each regular expression rule is counted; and the string with the minimum number of occurrences on each key path in each regular expression rule is used as the pre-screened string on the key path.
[0052] In one embodiment, it also includes: associating the pre-screened string with its corresponding regular expression and sending it to the convergence and diversion device; the convergence and diversion device matches and distributes the message based on the pre-screened string. The convergence and diversion device can use these rules to efficiently match and distribute the incoming message. More specifically, a full-packet floating feature code rule is generated through the pre-screened character, the identifier of the regular expression, and the key path identifier; the full-packet floating feature code rule is associated with the regular expression.
[0053] In certain usage scenarios of the aggregation and distribution devices, for example, the message data in the network traffic can be matched according to regular expressions, and the messages containing character strings conforming to a specific format can be extracted for further analysis and processing.
[0054] According to the method for generating pre-screened strings in regular expression rules of the present application, a corresponding non-deterministic finite state automaton is generated for the regular expression rule; the candidate strings of the regular expression rule are determined based on the non-deterministic finite state automaton; the number of times each candidate string appears in a global linked list array is counted; and the pre-screened string corresponding to the regular expression rule is determined based on the candidate string with the minimum number of appearances in each regular expression rule. This method can solve the problem of performance degradation when the pre-screened strings are the same in the prior art, significantly improve the efficiency of regular expression matching, and is suitable for convergence and diversion devices in high-traffic environments.
[0055] It should be clearly understood that the present application describes how to form and use specific examples, but the principles of the present application are not limited to any details of these examples. On the contrary, based on the teaching of the content disclosed in the present application, these principles can be applied to many other embodiments.
[0056] Figure 3 The present invention is a flowchart of a method for generating a pre-screened character string in a regular expression rule according to another exemplary embodiment. Figure 3 The process 30 shown is a detailed description of the process of this application in an actual application scenario.
[0057] like Figure 3 As shown, in S302, the user interface configures multiple regular expression rules.
[0058] In S304, all rules are checked for validity.
[0059] In S306, the user interface reports an error and the process ends.
[0060] In S308, a validity check is performed on each rule.
[0061] In S310 , an NFA is generated for the regular expression of each rule.
[0062] In S312, each critical path of the NFA of each rule is traversed to find all candidate strings and record them in a separate global linked list array.
[0063] In S314, the number of times each candidate string in the global linked list array appears in the entire global linked list array is counted. All regular expression rules are globally analyzed, and each regular expression rule is sorted according to the frequency of occurrence of its common substring in all common substrings, and the common substring with the lowest frequency of occurrence of each regular expression rule is selected as the pre-screened substring.
[0064] More specifically, when there is a candidate string whose length exceeds the maximum signature length MAX_LITERAL_LENGTH supported by the full-package floating signature rule, a substring with a length of MAX_LITERAL_LENGTH is selected by one of the two schemes, random and traversal, based on the number of trial comparisons of the traversal algorithm, so as to achieve a pre-screening string selection result with higher search performance.
[0065] In S316, the candidate character string with the smallest number of occurrences in each key path of each regular expression rule is counted and used as the pre-screened character string on the key path.
[0066] In S318, a corresponding full-package floating feature code rule is generated according to the regular expression rule identifier, the key path identifier, and the pre-screened character string, and is issued and associated with the regular expression.
[0067] In S320, the user interface prompts that the configuration is successful.
[0068] The present application globally considers all common substrings of all regular expression rules in the device, selects the common substring with the lowest frequency of occurrence in each regular expression rule as its pre-screening substring, thereby minimizing the number of regular expression rules corresponding to each pre-screening substring, thereby maximizing the efficiency of pre-screening matching and improving the overall search performance of regular expression rules.
[0069] It is worth mentioning that a pre-screened substring can also be selected from multiple common substrings of a regular expression using a random algorithm, so that the probability of multiple regular expressions selecting the same pre-screened substring will be reduced. For example, assuming that each regular expression has three optional common substrings, the random selection of pre-screened substrings will reduce the average possible number of the same common substrings they select to 1 / 3 of the original. However, this can only optimize the rule search performance to a certain extent, and the result is uncertain, which is not as good as the technical solution of the present invention in solving this problem more thoroughly.
[0070] In the prior art, the method for selecting pre-screened DPI strings is to select fixed strings on the key path generated during the parsing of the original string of each regular expression rule as candidate strings, and select the longest string on each key path as the pre-screened string (several key paths generate several pre-screened strings, and the global "|" will cause a single regular rule to generate multiple pre-screened strings, such as "(abc|def|ghi)[0-3]j" will generate 3 pre-screened strings). The basic idea of the solution is to select the candidate pre-screened DPI string generated by the parsing of the original string of each regular expression rule with the lowest number of occurrences among all the candidate strings of the regular rules (if the number of occurrences of multiple strings in the same rule is the lowest, select the longest one). That is:
[0071] First, traverse all key paths and save all candidate continuous strings temp_literal whose string length is not less than MIN_LITERAL_LENETH (indicating the minimum length of the pre-screened DPI string) into a global linked list array. The length of the linked list array is the capacity of the regular rule. Each array element stores the relevant information of each regular rule, including the rule ID, the index generated by the table below the single regular content, and the literal linked list head; the literal linked list stores the above literal according to the rule ID, and the fields include the regular expression rule ID, the content and length of the candidate string, vertex (key path number), and the number of occurrences. In the compilation process reg_exp_compile_all for state machine conversion of all regular expression rules, after all regular expression rules are compiled, the number of occurrences of the candidate string in the nodes in the above linked list is counted (the statistical algorithm is listed separately below), and the number of occurrences is recorded in the corresponding node field. Then, with the rule ID and vertex as the primary key, select the node with the lowest number of occurrences in each primary key. If multiple nodes have the same number of occurrences, take the longest one; if there are still multiple nodes with the same number of occurrences, select one randomly. The selected node is the final selected pre-screened DPI string for each critical path of each rule.
[0072] In this application, if Figure 4 As shown, Figure 4 The present invention is a flowchart of a method for generating a pre-screened character string in a regular expression rule according to another exemplary embodiment. Figure 4 The process 40 shown is for Figure 2 A detailed description of S206 "Counting the number of times each candidate string appears in the global linked list array" in the process shown.
[0073] In S402 , the initial value of the number of occurrences of each candidate character string is set to 1.
[0074] In S404, all candidate character strings are compared in pairs. For example, the lengths of the candidate character strings are compared; for candidate characters of different lengths, it is determined whether the shorter candidate character is included in the longer one, and if so, the number of occurrences of the shorter candidate character is increased by 1; and the spellings of candidate character strings of the same length are compared.
[0075] All candidate strings are compared pairwise, and strings exceeding MAX_LITERAL_LENGTH (indicating the maximum length of the signature supported by the full-package floating signature rule) bytes are considered to be MAX_LITERAL_LENGTH bytes, and only MAX_LITERAL_LENGTH bytes are taken according to a certain algorithm (the specific implementation scheme is described separately); the comparison method is to compare whether the string contents are the same when the lengths are the same (pay attention to uppercase and lowercase), if they are equal, the number of occurrences is increased by 1, and if the lengths are different, check whether the shorter one is included in the longer one, if so, the number of occurrences of the shorter one is increased by 1.
[0076] All candidate strings are compared pairwise, and strings exceeding MAX_LITERAL_LENGTH (indicating the maximum length of the signature supported by the full-package floating signature rule) bytes are considered to be MAX_LITERAL_LENGTH bytes, and only MAX_LITERAL_LENGTH bytes are taken according to a certain algorithm (the specific implementation scheme is described separately); the comparison method is to compare whether the string contents are the same when the lengths are the same (pay attention to uppercase and lowercase), if they are equal, the number of occurrences is increased by 1, and if the lengths are different, check whether the shorter one is included in the longer one, if so, the number of occurrences of the shorter one is increased by 1.
[0077] It is worth mentioning that the candidate strings in this application are different from ordinary strings in C language in that '\0' does not only appear at the end, but may also appear at the beginning and in the middle, and the length of the string is based on a separate string length field, rather than ending with '\0'. Therefore, string functions such as strcpy, strstr, strchr, strlen, etc. in the C language standard library cannot be used.
[0078] When the length of the candidate character string exceeds MAX_LITERAL_LENGTH bytes, in order to comply with the feature code length limit of the full-package floating feature code rule, only MAX_LITERAL_LENGTH bytes are taken as the pre-screening character string.
[0079] More specifically, the candidate character strings exceeding a preset length may be truncated; and the truncated candidate character strings may be compared in a random or traversal manner.
[0080] In order to minimize the overall occurrence frequency of the intercepted string, there are two options:
[0081] Random: Let the length of the candidate string be LEN (LEN>MAX_LITERAL_LENGTH), take a random starting position from the 0th to the LEN-MAX_LITERAL_LENGTHth, and take MAX_LITERAL_LENGTH bytes continuously from this byte as the candidate string participating in the frequency comparison.
[0082] Traversal: Let the length of candidate string 1 exceeding MAX_LITERAL_LENGTH be LEN1, then there are LEN1-MAX_LITERAL_LENGTH ways to extract a substring of MAX_LITERAL_LENGTH byte length from it; let the length of candidate string 2 exceeding MAX_LITERAL_LENGTH be LEN2, then there are LEN2-MAX_LITERAL_LENGTH ways to extract a substring of MAX_LITERAL_LENGTH byte length from it; and so on, let the length of candidate string 3 exceeding MAX_LITERAL_LENGTH be LENn, then there are LENn-MAX_LITERAL_LENGTH ways to extract a substring of MAX_LITERAL_LENGTH byte length from it. A trial comparison is performed for each of the above value situations, for a total of M = (LEN1-MAX_LITERAL_LENGTH)(LEN2-MAX_LITERAL_LENGTH) ... (LENn-MAX_LITERAL_LENGTH) trial comparisons; the sum of the number of occurrences of the pre-screened string for each key path of each rule in each trial comparison is recorded, and the smallest one is taken (if there are multiple smallest ones, one is randomly selected) as the final selected pre-screened string result.
[0083] The traversal scheme is theoretically more accurate and can produce fewer false hits, but it may cause a large number of operations, affecting the efficiency of the rule configuration process. Preferably, after calculating the above M value, a threshold judgment can be made on the value. For example, when the M value exceeds 100, the above random seed scheme is adopted; otherwise, the traversal scheme is adopted.
[0084] In S406, the number of times each candidate character string appears in the global linked list array is counted according to the comparison result.
[0085] Those skilled in the art will appreciate that all or part of the steps for implementing the above embodiments are implemented as a computer program executed by a CPU. When the computer program is executed by the CPU, the above functions defined by the above method provided in the present application are executed. The program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.
[0086] In addition, it should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present application, and are not intended to be limiting. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0087] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0088] Figure 5 FIG. 1 is a block diagram of a device for generating a pre-screened string in a regular expression rule according to an exemplary embodiment. Figure 5 As shown, the pre-screening character string generation device 50 in the regular expression rule includes: a conversion module 502 , a candidate module 504 , a statistics module 506 , and a character module 508 .
[0089] The conversion module 502 is used to generate a corresponding non-deterministic finite state automaton for the regular expression rule; the conversion module 502 is also used to obtain the regular expression rule; perform a legality check on each rule in the regular expression rule; after the legality check passes, generate a non-deterministic finite state automaton for the regular expression rule.
[0090] The candidate module 504 is used to determine the candidate string of the regular expression rule based on the non-deterministic finite state automaton; the candidate module 504 is also used to traverse the non-deterministic finite state automaton of each regular expression rule; extract the candidate string corresponding to each regular expression rule; and store the candidate string in a global linked list array.
[0091] The statistical module 506 is used to count the number of times each candidate string appears in the global linked list array; the statistical module 506 is also used to set the initial value of the number of times each candidate string appears to be 1; compare all candidate strings in pairs; and count the number of times each candidate string appears in the global linked list array based on the comparison results.
[0092] The character module 508 is used to determine the pre-screened string corresponding to each regular expression rule based on the candidate string with the minimum number of occurrences in each regular expression rule. The character module 508 is also used to count the number of occurrences of all candidate strings on each key path in each regular expression rule; and to use the string with the minimum number of occurrences on each key path in each regular expression rule as the pre-screened string on the key path.
[0093] According to the pre-screened string generation device in the regular expression rule of the present application, a corresponding non-deterministic finite state automaton is generated for the regular expression rule; the candidate string of the regular expression rule is determined based on the non-deterministic finite state automaton; the number of times each of the candidate strings appears in the global linked list array is counted; and the pre-screened string corresponding to the regular expression rule is determined based on the candidate string with the minimum number of appearances in each regular expression rule. This method can solve the problem of performance degradation when the pre-screened strings are the same in the prior art, significantly improve the efficiency of regular expression matching, and is suitable for convergence and diversion equipment in high-traffic environments.
[0094] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment.
[0095] Refer to the following Figure 6 The electronic device 600 according to this embodiment of the present application is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0096] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610), a display unit 640, etc.
[0097] The storage unit stores a program code, which can be executed by the processing unit 610, so that the processing unit 610 performs the steps described in this specification according to various exemplary embodiments of the present application. For example, the processing unit 610 can perform the following steps: Figure 2 , Figure 3 , Figure 4 Follow the steps shown in .
[0098] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0099] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include the implementation of a network environment.
[0100] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0101] The electronic device 600 may also communicate with one or more external devices 600' (e.g., keyboards, pointing devices, Bluetooth devices, etc.) to enable a user to communicate with the electronic device 600, and / or any device (e.g., routers, modems, etc.) that the electronic device 600 can communicate with one or more other computing devices. Such communication may be performed via an input / output (I / O) interface 650. In addition, the electronic device 600 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 660. The network adapter 660 may communicate with other modules of the electronic device 600 via a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0102] Through the above description of the implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by combining software with necessary hardware. Figure 7 As shown, the technical solution according to the implementation mode of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the above method according to the implementation mode of the present application.
[0103] The software product may be any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0104] The computer readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by an instruction execution system, an apparatus, or a device or used in combination with it. The program code contained on the readable storage medium may be transmitted with any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.
[0105] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0106] The computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the computer-readable medium implements the following functions: generating a corresponding non-deterministic finite state automaton for a regular expression rule; determining a candidate string for the regular expression rule based on the non-deterministic finite state automaton; counting the number of times each candidate string appears in a global linked list array; and determining a pre-screened string corresponding to the regular expression rule based on the candidate string with the minimum number of occurrences in each regular expression rule.
[0107] Those skilled in the art will appreciate that the above modules can be distributed in the device according to the description of the embodiment, or can be changed accordingly and only used in one or more devices different from the embodiment. The modules of the above embodiments can be combined into one module, or further divided into multiple sub-modules.
[0108] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiment of the present application.
[0109] The exemplary embodiments of the present application are specifically shown and described above. It should be understood that the present application is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present application is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.
Claims
1. A method for generating a pre-screened string in a regular expression rule, characterized in that: include: Generate corresponding non-deterministic finite state automata for regular expression rules; Determining a candidate string of the regular expression rule based on a non-deterministic finite state automaton; Count the number of times each candidate string appears in the global linked list array; The pre-screened character string corresponding to each regular expression rule is determined based on the candidate character string with the minimum number of occurrences in each regular expression rule.
2. The method according to claim 1, characterized in that Also includes: Associating the pre-screened string with its corresponding regular expression and sending it to the aggregation and distribution device; The convergence and distribution device matches and distributes the messages based on the pre-screened character string.
3. The method according to claim 2, characterized in that Associating the pre-screened string with its corresponding regular expression, including: Generate a full-package floating feature code rule through the pre-screened characters, the identifier of the regular expression, and the key path identifier; The full-package floating feature code rule is associated with the regular expression.
4. The method according to claim 1, characterized in that Generates corresponding non-deterministic finite state automata for regular expression rules, including: Get regular expression rules; Performing a validity check on each rule in the regular expression rule; After the legality check passes, a non-deterministic finite state automaton of the regular expression rule is generated.
5. The method according to claim 1, characterized in that Determining a candidate string of the regular expression rule based on a non-deterministic finite state automaton includes: A non-deterministic finite state automaton traversing each of the regular expression rules; Extracting candidate strings corresponding to each of the regular expression rules; The candidate character strings are stored in a global linked list array.
6. The method according to claim 1, characterized in that Count the number of times each candidate string appears in the global linked list array, including: Set the initial value of the number of occurrences of each candidate string to 1; Compare all candidate strings pairwise; The number of times each candidate string appears in the global linked list array is counted according to the comparison result.
7. The method according to claim 6, characterized in that All candidate strings are compared pairwise, including: Compare the lengths of the candidate strings; Compare the lengths of the candidate strings; for candidate strings of different lengths, determine whether the shorter candidate string is contained in the longer candidate string, if so, the number of occurrences of the shorter candidate string increases; Compare the spellings of candidate strings of the same length.
8. The method according to claim 6, characterized in that All candidate strings are compared pairwise, including: Truncate candidate character strings that exceed a preset length; The candidate strings after truncating are compared in a random or traversal manner.
9. The method according to claim 1, characterized in that Determining a pre-screened string corresponding to each regular expression rule based on a candidate string with a minimum number of occurrences in each regular expression rule includes: Count the number of occurrences of all candidate strings on each key path in each regular expression rule; The string with the minimum number of occurrences on each key path in each regular expression rule is used as the pre-screened string on the key path.
10. A device for generating a pre-screened character string in a regular expression rule, characterized in that: include: A conversion module, used for generating corresponding non-deterministic finite state automata for regular expression rules; A candidate module, used for determining a candidate string of the regular expression rule based on a non-deterministic finite state automaton; A statistics module, used to count the number of times each candidate string appears in the global linked list array; The character module is used to determine the pre-screened character string corresponding to each regular expression rule based on the candidate character string with the minimum number of occurrences in the regular expression rule.
