CN111597407A - Keyword matching method, device, equipment and storage medium based on TCAM - Google Patents

Keyword matching method, device, equipment and storage medium based on TCAM Download PDF

Info

Publication number
CN111597407A
CN111597407A CN202010269547.7A CN202010269547A CN111597407A CN 111597407 A CN111597407 A CN 111597407A CN 202010269547 A CN202010269547 A CN 202010269547A CN 111597407 A CN111597407 A CN 111597407A
Authority
CN
China
Prior art keywords
keyword
matching
matched
tcam
length
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010269547.7A
Other languages
Chinese (zh)
Inventor
刘春晓
郑展伟
房超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baizhuo Network Technology Co ltd
Original Assignee
Beijing Baizhuo Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baizhuo Network Technology Co ltd filed Critical Beijing Baizhuo Network Technology Co ltd
Priority to CN202010269547.7A priority Critical patent/CN111597407A/en
Publication of CN111597407A publication Critical patent/CN111597407A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • G06F16/90339Query processing by using parallel associative memories or content-addressable memories
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • G06F16/90344Query processing by using string matching techniques

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a keyword matching method, a keyword matching device, keyword matching equipment and a keyword matching storage medium based on TCAM, wherein the method comprises the following steps: acquiring the length of a keyword to be matched; comparing the length of the keyword to be matched with the size of a preset value; when the length of the keyword to be matched is larger than the preset value, matching the keyword according to a first issued matching rule; and when the length of the keyword to be matched is smaller than the preset value, matching the keyword according to a second issued matching rule. The invention can improve the searching efficiency without occupying more TCAM space and can not generate matching errors.

Description

Keyword matching method, device, equipment and storage medium based on TCAM
Technical Field
The present disclosure relates to the field of communications technologies, and in particular, to a keyword matching method, apparatus, device, and storage medium based on TCAM.
Background
At present, the pattern matching algorithm of the high-speed network data processing device is mostly implemented based on a hardware TCAM (ternary content addressable memory), which is developed from the CAM. The general CAM memory has only two states of each bit, namely ' 0 ' or ' 1 ', and the TCAM has three states of each bit, except ' 0 ' and ' 1 ', and also has a ' don't care ' state, so the state is called ' tri-state ', and the state is realized by mask, and the third state characteristic of the TCAM enables the state to carry out exact match search and fuzzy match search, while the CAM has no third state, so the state can only carry out exact match search.
The TCAM is a ternary content addressable memory capable of performing parallel search on stored content and giving a result in a short determination time, and supports matching different key word lengths of 10, 20, 40, 80, and the like, however, in the related art, the matching key word length supported by the TCAM does not exceed 80 bytes, and for the case that the matching key word existing in the existing network data processing device exceeds 80 bytes, a technical scheme that not only can ensure high matching efficiency but also can ensure a low matching error rate is not available.
Disclosure of Invention
An object of an embodiment of the present specification is to provide a keyword matching method, apparatus, device and storage medium based on a TCAM, so as to improve search efficiency without occupying more TCAM space and avoid matching errors.
In order to achieve the above object, in one aspect, an embodiment of the present specification provides a keyword matching method based on a TCAM, including:
acquiring the length of a keyword to be matched;
comparing the length of the keyword to be matched with the size of a preset value;
when the length of the keyword to be matched is larger than the preset value, matching the keyword according to a first issued matching rule;
and when the length of the keyword to be matched is smaller than the preset value, matching the keyword according to a second issued matching rule.
On the other hand, an embodiment of the present specification further provides a keyword matching apparatus based on a TCAM, including:
the keyword length acquisition module is used for acquiring the length of the keyword to be matched;
the keyword length comparison module is used for comparing the length of the keyword to be matched with the size of a preset value;
the first matching rule execution module is used for matching the keywords according to the issued first matching rule when the length of the keyword to be matched is larger than the preset value;
and the second matching rule execution module is used for matching the keywords according to the issued second matching rule when the length of the keyword to be matched is smaller than the preset value.
In another aspect, an embodiment of the present specification further provides an electronic device, including:
memory for storing computer software program
And the processor is used for realizing the steps of the TCAM-based keyword matching method in the embodiment of the invention when the computer software program is operated.
In another aspect, an embodiment of the present specification further provides a computer readable storage medium, on which a computer software program is stored, where the computer software program is executed to implement the steps of the TCAM-based keyword matching method in the embodiment of the present invention.
As can be seen from the technical solutions provided in the embodiments of the present specification, the embodiments of the present specification implement, by classifying the matching rules of the keywords, that is, classifying the two situations that the length of the keyword to be matched is not greater than the maximum keyword length of the TCAM and is greater than the maximum keyword length of the TCAM, and adding a flag bit for whether to perform the query of the remaining bytes in the hit return content, the search efficiency is improved without occupying more TCAM space, and no matching error occurs.
Drawings
FIG. 1 is a flow diagram of a TCAM-based keyword matching method in accordance with some embodiments of the present disclosure.
Fig. 2 is a block diagram of a TCAM-based keyword matching apparatus according to some embodiments of the present disclosure.
Fig. 3 is a schematic diagram illustrating rule issuing of a TCAM-based keyword matching method according to some embodiments of the present disclosure.
Fig. 4 is a matching diagram of a TCAM-based keyword matching method according to some embodiments of the present disclosure.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all of the embodiments. All other embodiments obtained by a person skilled in the art based on the embodiments in the present specification without any inventive step should fall within the scope of protection of the present specification.
As shown in fig. 1, some embodiments of the present specification provide a TCAM-based keyword matching method, which includes the following steps:
acquiring the length of a keyword to be matched;
comparing the length of the keyword to be matched with the size of a preset value;
when the length of the keyword to be matched is larger than the preset value, matching the keyword according to a first matching rule issued;
and when the length of the keyword to be matched is smaller than the preset value, matching the keyword according to the issued second matching rule.
In some embodiments of the present specification, the first matching rule includes splitting keywords to be matched into a first keyword to be matched and a second keyword to be matched, where the first keyword to be matched is located before the second keyword to be matched and has a length equal to a preset value; issuing a first keyword to be matched to a first TCAM table; recording first hit return content, wherein the first hit return content comprises a first zone bit and a position code of a first TCAM table, and the zone bit is used for indicating that a second keyword to be matched needs to be issued to a second TCAM table for matching; combining the second keyword to be matched, the zone bit and the position code into a third keyword to be matched; issuing a third keyword to be matched to a second TCAM table; and returning the matching result of the first matching rule.
In some embodiments of the present specification, the preset value is 80, that is, it is determined whether the keyword to be matched exceeds 80 bytes, and then the corresponding keyword matching mode is selected according to the determination result.
In an actual application environment, such as an application scenario of network data traffic processing, for example, with reference to fig. 3 and 4, we define the first TCAM table as TCAM table 1, the second TCAM table as TCAM table 2, and the preset value is 80, then the keyword matching process may specifically be performed according to the following steps:
a keyword matching rule issuing stage:
step 1: judging the length M of the keyword, if M < > is 80, executing the step 2, otherwise executing the step 3;
step 2: issuing the first 80-byte keyword content and acquiring hit return content to the TCAM table 1, accommodating a flag bit in the hit return (the flag bit indicates that the TCAM table 2 does not need to be matched), and executing the step 5;
and step 3: issuing the first 80-byte keyword content to the TCAM table 1 and acquiring hit return content, wherein the hit return content comprises a flag bit (the flag bit indicates that the TCAM table 2 needs to be matched) and a position code of the TCAM table 1;
and 4, step 4: issuing keywords formed by combining the residual keywords and the position codes acquired in the step 3 to a TCAM table 2 and acquiring a hit return result;
and 5: completing the issuing of the keyword matching rule;
keyword matching stage (matching according to the issued keyword matching rules):
step 6: obtaining key word content, taking the first 80 byte group matching key word, matching TCAM table 1, executing step 7 by hit, otherwise executing step 9 by key word matching failure
And 7: recording hit return contents; judging whether to inquire the TCAM table 2 or not through the zone bit, if so, executing step 8, otherwise, successfully executing step 9 if the keyword matching is successful
And 8: taking the rest keywords and the position code group matching keywords in the returned result of the step 7, matching with the TCAM table 2, successfully matching the hit keywords, or else, failing to match the keywords;
and step 9: return keyword matching result
By classifying the keyword rules of the issued TCAM, sending the keywords into the TCAM table 1 and the TCAM table 2 in two parts and increasing the query flag bit of whether to carry out the residual byte or not by hitting the return content, the number of table lookup is reduced by judging the flag bit of the content of the TCAM table 1, in addition, the keyword content is also encoded by the TCAM position of the residual byte and the previous content to match the TCAM table 2, the technical effects of improving the lookup efficiency and avoiding the matching error under the condition of not occupying more TCAM space are realized.
As shown in fig. 2, some embodiments of the present specification further provide a TCAM-based keyword matching apparatus, including:
a keyword length obtaining module 201, configured to obtain a length of a keyword to be matched;
a keyword length comparison module 202, configured to compare the length of the keyword to be matched with a preset value;
the first matching rule execution module 203 is configured to, when the length of the keyword to be matched is greater than a preset value, match the keyword according to the issued first matching rule;
and a second matching rule executing module 204, configured to, when the length of the keyword to be matched is smaller than the preset value, perform matching on the keyword according to the issued second matching rule.
In some embodiments of the present description, there is also provided an electronic device comprising: a memory for storing a computer software program; and a processor, configured to implement the steps of the TCAM-based keyword matching method in the embodiment of the present specification when running the computer software program.
In some embodiments of the present specification, there is further provided a computer readable storage medium having stored thereon a computer software program, which when executed, may implement the steps of the TCAM-based keyword matching method in the embodiments of the present specification.
When the computer program runs, the keyword matching method based on the TCAM can be realized, and the technical effects of reducing the matching error rate and improving the matching efficiency are achieved.
While the process flows described above include operations that occur in a particular order, it should be appreciated that the processes may include more or less operations that are performed sequentially or in parallel (e.g., using parallel processors or a multi-threaded environment). The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory. The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium. Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein. This description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices. The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the method embodiment, since it is substantially similar to the apparatus embodiment, the description is simple, and the relevant points can be referred to the partial description of the apparatus embodiment. The above description is only an example of the present specification, and is not intended to limit the present specification. Various modifications and alterations to this description will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification should be included in the scope of the claims of the present specification.

Claims (10)

1. A keyword matching method based on TCAM, the method comprising:
acquiring the length of a keyword to be matched;
comparing the length of the keyword to be matched with the size of a preset value;
when the length of the keyword to be matched is larger than the preset value, matching the keyword according to a first issued matching rule;
and when the length of the keyword to be matched is smaller than the preset value, matching the keyword according to a second issued matching rule.
2. The TCAM-based keyword matching method of claim 1,
the first matching rule may comprise that,
splitting the keywords to be matched into a first keyword to be matched and a second keyword to be matched, wherein the first keyword to be matched is positioned in front of the second keyword to be matched and has the length same as the preset value in size;
issuing the first keyword to be matched to a first TCAM table;
recording first hit return content, wherein the first hit return content comprises a first flag bit and a position code of the first TCAM table, and the flag bit is used for indicating that the second keyword to be matched needs to be issued to a second TCAM table for matching;
combining the second keyword to be matched, the zone bit and the position code into a third keyword to be matched;
issuing the third keyword to be matched to a second TCAM table;
and returning the matching result of the first matching rule.
3. The TCAM-based keyword matching method of claim 1, further comprising:
the second matching rule may comprise a rule that includes,
sending the keywords to be matched to a first TCAM matching table,
recording second hit return content, wherein the second hit return content comprises a second flag bit, and the second flag bit is used for indicating that the keyword to be matched does not need to be issued to a second TCAM table for matching;
and returning the matching result of the second matching rule.
4. The TCAM-based keyword matching method of any one of claims 1-3,
the preset value is 80.
5. A keyword matching apparatus based on TCAM, characterized in that the apparatus comprises
The keyword length acquisition module is used for acquiring the length of the keyword to be matched;
the keyword length comparison module is used for comparing the length of the keyword to be matched with the size of a preset value;
the first matching rule execution module is used for matching the keywords according to the issued first matching rule when the length of the keyword to be matched is larger than the preset value;
and the second matching rule execution module is used for matching the keywords according to the issued second matching rule when the length of the keyword to be matched is smaller than the preset value.
6. The TCAM-based keyword matching apparatus of claim 5, in which the apparatus comprises
The first matching rule execution module is configured to split the keywords to be matched into a first keyword to be matched and a second keyword to be matched, where the first keyword to be matched is located before the second keyword to be matched and has a length equal to the preset value; issuing the first keyword to be matched to a first TCAM table; recording first hit return content, wherein the first hit return content comprises a first flag bit and a position code of the first TCAM table, and the flag bit is used for indicating that the second keyword to be matched needs to be issued to a second TCAM table for matching; combining the second keyword to be matched, the zone bit and the position code into a third keyword to be matched; issuing the third keyword to be matched to a second TCAM table; and returning the matching result of the first matching rule.
7. The TCAM-based keyword matching apparatus of claim 5, in which the apparatus comprises
The second matching rule execution module is used for sending the keywords to be matched to the first TCAM matching table,
recording second hit return content, wherein the second hit return content comprises a second flag bit, and the second flag bit is used for indicating that the keyword to be matched does not need to be issued to a second TCAM table for matching;
and returning the matching result of the second matching rule.
8. The TCAM-based keyword matching apparatus of any one of claims 5-7,
the preset value is 80.
9. An electronic device, comprising
Memory for storing computer software program
A processor for implementing the steps of the TCAM based keyword matching method according to any one of claims 1 to 4 when running the computer software program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer software program, which when executed performs the steps of the TCAM-based keyword matching method according to any one of claims 1 to 4.
CN202010269547.7A 2020-04-08 2020-04-08 Keyword matching method, device, equipment and storage medium based on TCAM Pending CN111597407A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010269547.7A CN111597407A (en) 2020-04-08 2020-04-08 Keyword matching method, device, equipment and storage medium based on TCAM

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010269547.7A CN111597407A (en) 2020-04-08 2020-04-08 Keyword matching method, device, equipment and storage medium based on TCAM

Publications (1)

Publication Number Publication Date
CN111597407A true CN111597407A (en) 2020-08-28

Family

ID=72181903

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010269547.7A Pending CN111597407A (en) 2020-04-08 2020-04-08 Keyword matching method, device, equipment and storage medium based on TCAM

Country Status (1)

Country Link
CN (1) CN111597407A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112667867A (en) * 2020-12-31 2021-04-16 北京卓讯科信技术有限公司 Matching conflict checking method and equipment based on TCAM (ternary content addressable memory) feature code
CN113660165A (en) * 2021-08-09 2021-11-16 国家计算机网络与信息安全管理中心 Mask rule matching method based on TCAM, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030233516A1 (en) * 2002-06-18 2003-12-18 International Business Machines Corporation Method and system for performing range rule testing in a ternary content addressable memory
CN101478447A (en) * 2009-01-08 2009-07-08 中国人民解放军信息工程大学 Method and apparatus for deep packet detection
CN102622434A (en) * 2011-12-31 2012-08-01 成都市华为赛门铁克科技有限公司 Data storage method, data searching method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030233516A1 (en) * 2002-06-18 2003-12-18 International Business Machines Corporation Method and system for performing range rule testing in a ternary content addressable memory
CN101478447A (en) * 2009-01-08 2009-07-08 中国人民解放军信息工程大学 Method and apparatus for deep packet detection
CN102622434A (en) * 2011-12-31 2012-08-01 成都市华为赛门铁克科技有限公司 Data storage method, data searching method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112667867A (en) * 2020-12-31 2021-04-16 北京卓讯科信技术有限公司 Matching conflict checking method and equipment based on TCAM (ternary content addressable memory) feature code
CN112667867B (en) * 2020-12-31 2022-05-10 北京卓讯科信技术有限公司 Matching conflict checking method and equipment based on TCAM (ternary content addressable memory) feature code
CN113660165A (en) * 2021-08-09 2021-11-16 国家计算机网络与信息安全管理中心 Mask rule matching method based on TCAM, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108599973B (en) Log association method, device and equipment
US10776427B2 (en) Efficient conditional state mapping in a pattern matching automaton
US20170032054A1 (en) Improved pattern matching machine with mapping table
CN110992188B (en) Transaction processing method, device and equipment
CN111597407A (en) Keyword matching method, device, equipment and storage medium based on TCAM
CN112380401B (en) Service data checking method and device
CN108616361B (en) Method and device for identifying uniqueness of equipment
US20160335374A1 (en) Improved pattern matching machine
US10339096B2 (en) Efficient pattern matching
CN114564564A (en) Hot word enhancement method, equipment and medium for voice recognition
CN104166649B (en) Caching method and equipment for search engine
CN114626092A (en) Desensitization method, system, device and computer storage medium for multi-field data with incidence relation
US10846598B2 (en) Pattern matching
CN110019295B (en) Database retrieval method, device, system and storage medium
US10535010B2 (en) Pattern matching machine for repeating symbols
CN107562533B (en) Data loading processing method and device
CN113590805A (en) Method and device for searching textile commodity names based on knowledge graph
CN117435640A (en) Method and device for locating similar examples and electronic equipment
CN113535710B (en) Searching method, searching device, terminal equipment and storage medium
CN110221971B (en) Search engine testing method and device, electronic equipment and storage medium
CN113641871B (en) Lock-free hashing method, device, equipment and medium
CN115470306A (en) Index selection method, system and storage medium for relational database
CN117492670A (en) Log printing sequence determining method and device and electronic equipment
CN116089497A (en) Transaction data processing method, device, equipment and readable storage medium
CN115238028A (en) Method and device for matching text data keywords of vehicle user

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination