CN113132261A - Traffic data packet classification method and device and electronic equipment - Google Patents

Traffic data packet classification method and device and electronic equipment Download PDF

Info

Publication number
CN113132261A
CN113132261A CN201911423810.7A CN201911423810A CN113132261A CN 113132261 A CN113132261 A CN 113132261A CN 201911423810 A CN201911423810 A CN 201911423810A CN 113132261 A CN113132261 A CN 113132261A
Authority
CN
China
Prior art keywords
data packet
red
classified
black tree
hash
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.)
Granted
Application number
CN201911423810.7A
Other languages
Chinese (zh)
Other versions
CN113132261B (en
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 Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud 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 Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN201911423810.7A priority Critical patent/CN113132261B/en
Publication of CN113132261A publication Critical patent/CN113132261A/en
Application granted granted Critical
Publication of CN113132261B publication Critical patent/CN113132261B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/24Traffic characterised by specific attributes, e.g. priority or QoS
    • H04L47/2441Traffic characterised by specific attributes, e.g. priority or QoS relying on flow classification, e.g. using integrated services [IntServ]

Abstract

The embodiment of the invention provides a method and a device for classifying traffic data packets and electronic equipment, wherein the method comprises the following steps: receiving a current flow data packet as a data packet to be classified; calculating the address characteristic information of the data packet to be classified by adopting a preset hash algorithm to obtain a hash value of the data packet to be classified; classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified; determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first Hash data packet group based on the address characteristic information of the data packet to be classified; and grouping the first red and black tree data packets corresponding to the current node as a classification result of the data packets to be classified. In the embodiment of the invention, the address characteristic information of the data packet to be classified does not need to be matched with all different address characteristic information, so that the calculated amount in the classification process is reduced.

Description

Traffic data packet classification method and device and electronic equipment
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for classifying traffic packets, and an electronic device.
Background
The packet header of the traffic data packet contains information such as a source IP address (Internet Protocol Addres), a destination IP address, a source port, and a destination port of the data packet, and the traffic data packet classification is a process of dividing different data packets into different classes according to one or more of the above information. For example, the data packets are classified into different categories according to the source IP addresses, and the like.
At present, when classifying traffic data packets, the method mainly adopted is as follows: according to actual needs, one or more of information such as a source IP address, a destination IP address, a source port and a destination port of a data packet are selected as address characteristic information, a characteristic table is constructed, the data packet to be classified is respectively matched with the address characteristic information in the table, and therefore classification of the data packet with different address characteristic information is achieved.
Since the source IP address, the destination IP address, the source port and the destination port of the packet are of a large variety, which results in a large amount of address characteristic information in the characteristic table, when classifying, the packet to be classified needs to be matched with all different address characteristic information, for example, the packet is classified by selecting the source IP address of the packet as the address characteristic information, because the source IP address has a total of 42 (i.e. 2) since the source IP address has a total of 42 (i.e. 2)32) And hundreds of millions of data packets to be classified are matched with the more than 42 hundreds of millions of source IP addresses, so that the calculation amount in the classification process is large, and the resource loss is large.
Disclosure of Invention
Embodiments of the present invention provide a method, an apparatus, and an electronic device for classifying traffic packets, so as to reduce the amount of computation in the process of classifying the traffic packets. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a method for classifying a traffic packet, including:
receiving a current flow data packet as a data packet to be classified;
calculating the address characteristic information of the data packet to be classified by adopting a preset Hash algorithm to obtain a Hash value of the data packet to be classified;
classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified;
determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first Hash data packet group based on the address characteristic information of the data packet to be classified; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
Further, the step of classifying the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified includes:
judging whether hash data packet groups with hash values identical to those of the data packets to be classified exist in the existing hash data packet groups;
if yes, classifying the data packet to be classified into a first hash data packet group with the same hash value as the data packet to be classified;
and if not, newly building a first Hash data packet group with the same Hash value as the data packet to be classified, and classifying the data packet to be classified into the newly built first Hash data packet group.
Further, the step of determining, in a first red-black tree set corresponding to the first hash data packet group, a current node corresponding to the address feature information of the data packet to be classified based on the address feature information of the data packet to be classified includes:
judging whether a first main red-black tree corresponding to the first hash data packet group exists or not;
if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree; if so, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first main red-black tree and is used as a current node;
if the first main red-black tree corresponding to the first hash data packet group does not exist, newly setting a first main red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first main red-black tree.
Further, if the node exists, the step of searching the node corresponding to the address feature information of the to-be-classified data packet in the first main red-black tree includes:
if so, judging whether the first main Reddish Black Tree is in a locked state;
if not, the step of searching the node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree is executed, the first main red-black tree is locked, and the first main red-black tree is unlocked after the current node is determined;
if the first main red-black tree is in a locked state, judging whether a first sub-red-black tree corresponding to the first hash data packet group exists or not; if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, and if the node exists, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree and is used as a current node; if the first sub-red-black tree corresponding to the first hash data packet group does not exist, newly setting a first sub-red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first sub-red-black tree.
Further, the method further comprises:
when the traffic data packet classification result needs to be read, combining the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees to obtain the combined red and black tree data packet group as the traffic data packet classification result;
and reading the classification result of the flow data packet.
Further, the method further comprises:
presetting a first buffer and a second buffer, which are alternately used as a write buffer or a read buffer;
the step of classifying the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified comprises:
classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified in the current write buffer area based on the hash values of the data packets to be classified;
the step of determining whether there is a first main red-black tree set corresponding to the first hash packet includes:
judging whether a first main red-black tree set corresponding to the first hash data packet group exists in the current writing buffer area or not;
the step of newly setting a first main red-black tree corresponding to the first hash packet if there is no first main red-black tree set corresponding to the first hash packet includes:
if a first main red-black tree corresponding to the first hash data packet does not exist in the current writing buffer area, newly setting a first main red-black tree corresponding to the first hash data packet in the current writing buffer area;
the step of determining whether there is a first sub-blacktree corresponding to the first hash packet includes:
judging whether a first sub-red-black tree corresponding to the first Hash data packet group exists in the current writing buffer area or not;
if there is no first sub-red-black tree corresponding to the first hash data packet, newly setting a first sub-red-black tree corresponding to the first hash data packet, including:
if the current writing buffer area does not have a first sub red-black tree corresponding to the first hash data packet group, a first sub red-black tree corresponding to the first hash data packet group is newly arranged in the current writing buffer area;
when a traffic data packet classification result needs to be read, merging red and black tree data packet groups represented by nodes corresponding to the same address characteristic information in all main red and black trees and all sub red and black trees to obtain merged red and black tree data packet groups, wherein the step of taking the merged red and black tree data packet groups as the traffic data packet classification result comprises the following steps:
when the classification result of the flow data packet needs to be read, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area;
and in the switched read buffer area, executing the step of merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees to obtain the merged red and black tree data packet group as the classification result of the traffic data packet.
Further, the step of switching the current write buffer to the read buffer and the current read buffer to the write buffer when the classification result of the traffic data packet needs to be read includes:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
In a second aspect, an embodiment of the present invention provides a traffic packet classification device, including:
a current flow data packet receiving module, configured to receive a current flow data packet as a to-be-classified data packet;
the hash value obtaining module is used for calculating the address characteristic information of the data packet to be classified by adopting a preset hash algorithm to obtain the hash value of the data packet to be classified;
the Hash classification module is used for classifying the data packets to be classified into first Hash data packet groups corresponding to the Hash values of the data packets to be classified based on the Hash values of the data packets to be classified;
a classification result obtaining module, configured to determine, based on the address feature information of the to-be-classified data packet, a current node corresponding to the address feature information of the to-be-classified data packet in a first red-black tree set corresponding to the first hash data packet; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
Further, the hash classification module is specifically configured to: judging whether hash data packet groups with hash values identical to those of the data packets to be classified exist in the existing hash data packet groups; if yes, classifying the data packet to be classified into a first hash data packet group with the same hash value as the data packet to be classified; and if not, newly building a first Hash data packet group with the same Hash value as the data packet to be classified, and classifying the data packet to be classified into the newly built first Hash data packet group.
Further, when the step of determining, by the classification result obtaining module, a current node corresponding to the address feature information of the to-be-classified data packet in a first red-black tree set corresponding to the first hash data packet group based on the address feature information of the to-be-classified data packet is executed, the classification result obtaining module includes: the judgment submodule, the first current node determination submodule and the second current node determination submodule;
the judging submodule is used for judging whether a first main red-black tree which corresponds to the first hash data packet group exists or not; if yes, triggering the first current node determination submodule; if not, triggering the second current node determination submodule;
the first current node determining submodule is used for searching a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree; if so, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first main red-black tree and is used as a current node;
the second current node determining submodule is used for newly setting a first main red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first main red-black tree.
Further, when the step of searching the node corresponding to the address feature information of the to-be-classified data packet in the first main red-black tree is executed, the first current node determining submodule is specifically configured to:
judging whether the first main red-black tree is in a locked state;
if not, executing the step of searching the node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree, and locking the first main red-black tree; after determining the current node, unlocking the first master Reddish Tree;
if the first main red-black tree is in a locked state, judging whether a first sub-red-black tree corresponding to the first hash data packet group exists or not; if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, and if the node exists, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree and is used as a current node; if the first sub-red-black tree corresponding to the first hash data packet group does not exist; newly setting a first sub-red-black tree corresponding to the first hash data packet; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first sub-red-black tree.
Further, the apparatus further comprises: the system comprises a red and black tree data packet grouping and merging module and a classification result reading module;
the red and black tree data packet grouping and merging module is used for merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees when the flow data packet classification result needs to be read, so as to obtain the merged red and black tree data packet group as the flow data packet classification result;
and the classification result reading module is used for reading the classification result of the flow data packet.
Further, the apparatus further comprises:
a buffer setting module for setting a first buffer and a second buffer in advance, the first buffer and the second buffer being alternately used as a write buffer or a read buffer;
the hash classification module is specifically configured to classify the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified in the current write buffer area;
the judging submodule is specifically configured to judge whether a first main red-black tree set corresponding to the first hash data packet exists in the current write buffer;
the second current node determining submodule is specifically configured to newly set a first main red-black tree corresponding to the first hash data packet in the current write buffer when the step of newly setting the first main red-black tree corresponding to the first hash data packet is performed;
when the step of judging whether a first sub-red-black tree corresponding to the first hash data packet group exists is executed by the first current node determination submodule, the first current node determination submodule is specifically used for judging whether a first sub-red-black tree corresponding to the first hash data packet group exists in the current write buffer area;
the first current node determining submodule, when executing the step of newly setting a first sub-red-black tree corresponding to the first hash data packet if the first sub-red-black tree corresponding to the first hash data packet does not exist, is specifically configured to newly set a first sub-red-black tree corresponding to the first hash data packet in the current writing buffer area if the first sub-red-black tree corresponding to the first hash data packet does not exist in the current writing buffer area;
the red and black tree data packet grouping and merging module comprises: the buffer area switching submodule and the red and black tree data packet grouping and merging submodule;
the buffer switching submodule is used for switching the current writing buffer into the reading buffer and switching the current reading buffer into the writing buffer when the flow data packet classification result needs to be read;
and the red and black tree data packet grouping and merging submodule is used for executing the step of merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees in the switched read buffer area to obtain the merged red and black tree data packet group as the classification result of the traffic data packet.
Further, the buffer switching sub-module is specifically configured to:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
In a third aspect, an embodiment of the present invention provides an electronic device, including: the system comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus;
a memory for storing a computer program;
a processor, configured to implement the steps of the traffic packet classification method according to any of the first aspect when executing a program stored in the memory.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the traffic packet classification method according to any one of the first aspect or the second aspect are implemented.
In a fifth aspect, an embodiment of the present invention further provides a computer program product containing instructions, which when run on a computer, causes the computer to perform the steps of the traffic packet classification method according to any one of the first aspect or the second aspect.
The embodiment of the invention provides a method, a device and electronic equipment for classifying traffic data packets, which are used for receiving a current traffic data packet as a data packet to be classified; calculating the address characteristic information of the data packet to be classified by adopting a preset Hash algorithm to obtain a Hash value of the data packet to be classified; classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified; determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first Hash data packet group based on the address characteristic information of the data packet to be classified; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified. In the process, when the data packets to be classified are classified into the corresponding first hash data packet groups based on the hash algorithm, the address characteristic information of the data packets to be classified does not need to be matched with all different address characteristic information, when the current node is determined in the corresponding first red-black tree, the classification result can be obtained only by matching the address characteristic information of the data packets to be classified with the address characteristic information corresponding to each node in the first red-black tree, and the address characteristic information corresponding to each node in the red-black tree is only a small part of all the different address characteristic information.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flow chart of a traffic packet classification method according to an embodiment of the present invention;
fig. 2 is another schematic flow chart of a traffic packet classification method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a traffic packet classification apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to reduce the calculation amount in the process of classifying the traffic data packet, the embodiment of the invention provides a method and a device for classifying the traffic data packet and electronic equipment.
Referring to fig. 1, fig. 1 is a schematic flow chart of a traffic data packet classification method according to an embodiment of the present invention, where the method specifically includes the following steps:
step 101, receiving a current flow data packet as a data packet to be classified.
And 102, calculating the address characteristic information of the data packet to be classified by adopting a preset hash algorithm to obtain the hash value of the data packet to be classified.
The address characteristic information of the data packet to be classified may include one or more of the following information: the source IP address, the destination IP address, the source port, the destination port and the like of the data packet to be classified exist in the packet head of the data packet to be classified, and the address characteristic information can be obtained by analyzing the data packet to be classified.
103, classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified.
Specifically, the address characteristic information of the data packet to be classified may be used as an independent variable, the hash value of the data packet to be classified is obtained through calculation according to a preset hash function, and then the data packet to be classified is classified into the first hash data packet group corresponding to the hash value of the data packet to be classified according to the hash value obtained through calculation.
The number of the hash data packet packets may be one or multiple, specifically, the number of the hash data packet packets is the same as the number of the hash values calculated according to the address feature information of the data packet to be counted.
104, determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first hash data packet group based on the address characteristic information of the data packet to be classified; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one piece of address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as a classification result of the data packets to be classified.
Each hash data packet group is correspondingly provided with one red-black tree, and the number of the hash data packet groups can be multiple, so that the number of the red-black trees can also be multiple.
When the address characteristic information has more types and the hash value is calculated by using the hash algorithm, a collision may occur, that is: the hash values calculated according to different address characteristic information are the same, at the moment, the data to be classified with different address characteristic information are classified into the same hash data packet group, and therefore the classification result is inaccurate.
In the above embodiment of the present invention, when classifying the data packets to be classified into the corresponding first hash data packet groups based on the hash algorithm, it is not necessary to match the address feature information of the data packets to be classified with all the different address feature information, but when determining the current node in the corresponding first red-black tree, it is also only necessary to match the address feature information of the data packets to be classified with the address feature information corresponding to each node in the first red-black tree, and a classification result can be obtained, and the address feature information corresponding to each node in the red-black tree is only a small part of all the different address feature information, so that the amount of calculation in the classification process is reduced.
Referring to fig. 2, fig. 2 is another schematic flow chart of a traffic data packet classification method according to an embodiment of the present invention, where the method specifically includes the following steps:
step 200, presetting a first buffer area and a second buffer area, wherein the first buffer area and the second buffer area are alternately used as a writing buffer area or a reading buffer area.
Step 201, receiving a current traffic data packet as a data packet to be classified.
Step 202, calculating the address characteristic information of the data packet to be classified by adopting a preset hash algorithm to obtain the hash value of the data packet to be classified.
Step 203, classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified in the current write buffer area.
Step 204, judging whether a first main red-black tree set corresponding to the first hash data packet group exists in the current writing buffer area. If so, go to step 205, and if not, go to step 214.
Step 205, determine whether the first major Reddish Black Tree is in a locked state. If not, go to step 206, and if so, go to step 209.
In the embodiment of the present invention, a multithreading parallel processing mode may be adopted to classify the traffic data packet, that is to say: specifically, when a data packet to be classified is obtained, firstly, a thread is determined from all the working threads as a target working thread by a scheduling thread according to the load condition of all the working threads, and is used for classifying the data packet to be classified, wherein the principle of selecting the target working thread may be as follows: when the load of the working thread is smaller than a certain preset load threshold value, the thread can be used as a target working thread; or selecting a work thread with a smaller load as a target work thread according to the magnitude relation of the loads of all the work threads, and the principle of selecting the target work thread is not limited herein.
Since one hash packet corresponds to only one main red-black tree and the traffic packet classification is in a multi-threaded manner, the following may occur: when the worker thread 1 classifies the data packet 1 to be classified into the first hash data packet group corresponding to the hash value of the data packet 1 to be classified, another data packet 2 processed by the worker thread 2 is also classified into the first hash data packet group because the data packet 2 has the same address characteristic information as the data packet 1 to be classified, and the worker thread 2 is performing node search or node creation operation on the first main red-black tree set corresponding to the first hash data packet group, at this time, the worker thread 2 locks the first main red-black tree to prevent the first main red-black tree from being used by other threads. Therefore, if the first main red-black tree set corresponding to the first hash data packet exists in the current write buffer, whether the first main red-black tree is in the locked state can be judged.
And step 206, searching nodes corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree, and locking the first main red-black tree. If so, executing step 207; otherwise, step 208 is performed.
Wherein each node in the first master red-black tree represents a red-black tree packet group, each red-black tree packet group corresponding to an address characteristic information.
And step 207, taking the searched node as the current node, and unlocking the first main Reynouth Tree. Step 215 is then performed.
And 208, newly building a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree as a current node, and unlocking the first main red-black tree. Step 215 is then performed.
If the node corresponding to the address characteristic information of the data packet to be classified is not searched in the first main red-black tree, it indicates that no red-black tree data packet group corresponding to the address characteristic information of the data packet to be classified exists in the first main red-black tree at present, so that a node corresponding to the address characteristic information of the data packet to be classified can be newly established in the first main red-black tree as the current node.
Step 209, determine whether there is a first sub-Reddish Black Tree corresponding to the first Hash packet in the current write buffer. If so, go to step 210, otherwise, go to step 213.
When each working thread is started, a thread buffer corresponding to the thread can be registered in advance in the current write buffer for creating sub-red-black trees corresponding to each hash data packet group. Therefore, the number of the sub red-black trees may be multiple, and in this step, the sub red-black tree created in correspondence with the first hash packet in the thread buffer corresponding to the current thread is used as the first sub red-black tree.
Step 210, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree. If so, go to step 211, otherwise, go to step 212.
Wherein each node in the first sub-red-black tree also represents a red-black tree packet group, and each red-black tree packet group corresponds to one address characteristic information.
And step 211, taking the searched node as the current node. Step 215 is then performed.
Step 212, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree as the current node. Step 215 is then performed.
Similar to step 208, if the node corresponding to the address characteristic information of the data packet to be classified is not found in the first sub-red-black tree, it indicates that there is no red-black tree data packet group corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, so that a node corresponding to the address characteristic information of the classified data packet can be newly established in the first sub-red-black tree as the current node.
Step 213, newly setting a first sub-red-black tree corresponding to the first hash data packet group in the current write buffer, and newly creating a node corresponding to the address feature information of the data packet to be classified as the current node in the newly set first sub-red-black tree. Step 215 is then performed.
Specifically, a first sub-red-black tree corresponding to the first hash data packet may be created in a thread buffer corresponding to the thread in the current write buffer, and a node corresponding to the address feature information of the data packet to be classified is newly created in the newly set first sub-red-black tree as the current node.
Step 214, newly setting a first main red-black tree corresponding to the first hash data packet group in the current write buffer area, locking the newly set first main red-black tree, newly building a node corresponding to the address characteristic information of the data packet to be classified in the newly set first main red-black tree, using the node as the current node, and unlocking the first main red-black tree.
Step 215, grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
Step 216, when the traffic data packet classification result needs to be read, the current write buffer is switched to the read buffer, and the current read buffer is switched to the write buffer.
When the classification result of the traffic data packet needs to be read, the write buffer area and the read buffer area are switched so as not to influence the ongoing and subsequent traffic data packet classification work at the current moment, so that the classification operation can be executed on the data packet to be classified acquired after the switching in the write buffer area after the switching, and the subsequent classification operation can be continued in the buffer area before the switching until the classification result is obtained for the data packet being classified during the switching, thereby improving the efficiency of the traffic data packet classification.
Further, when the classification result of the traffic data packet needs to be read, the current write buffer is switched to the read buffer, and the current read buffer is switched to the write buffer, including:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
And 217, merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees in the switched read buffer area to obtain the merged red and black tree data packet group as a flow data packet classification result.
When the classification result of the traffic data packet needs to be read, after the current write buffer is switched to the read buffer and the current read buffer is switched to the write buffer, it may be determined whether there is any write operation in the write buffer before switching, and when there is no write operation in the write buffer before switching, it indicates that the current classification operation has been completed, and then step 217 may be performed.
Step 218, the traffic packet classification result is read.
For ease of understanding, the above steps are explained below by way of specific examples:
in step 200, the current write buffer is assumed to be the first buffer.
In steps 201-203, assume that the source IP address of the data packet is used as the address characteristic information, and the received data packet to be classified is a data packet string to be classified, the source IP addresses thereof respectively belong to the IP address segment range of 192.168.1.1-192.168.1.15, and for the source IP address: 192.168.1.1 and 192.168.1.2, the hash values calculated by the hash algorithm are the same, and at this time, in the first buffer, the data packets to be classified in the data packet string to be classified are classified into 14 hash data packet packets, wherein one hash data packet corresponds to two different source IP addresses: 192.168.1.1 and 192.168.1.2, the remaining hashed data packet packets each correspond to a source IP address.
In steps 204-217, through node lookup or node creation operations in the main red-black tree or the sub-red-black tree, a plurality of red-black tree data packet packets may be obtained, and when a traffic data packet classification result needs to be read, for example, when a traffic data packet classification result reading instruction is received, red-black tree data packet packets represented by nodes corresponding to the same source IP address in all main red-black trees and all sub-red-black trees may be merged, and finally, 15 red-black tree data packet packets may be obtained, where each red-black tree data packet corresponds to one source IP address.
In the embodiment shown in fig. 2, when classifying the data packets to be classified into the corresponding first hash data packet groups based on the hash algorithm, it is not necessary to match the address feature information of the data packets to be classified with all the different address feature information, but when determining the current node in the corresponding red and black, it is also only necessary to match the address feature information of the data packets to be classified with the address feature information corresponding to each node in the first red and black tree, and the classification result can be obtained, and the address feature information corresponding to each node in the first red and black tree is only a small part of all the different address feature information, so that the calculation amount in the classification process is reduced. Meanwhile, a multi-thread parallel processing mode is adopted, thread buffer areas corresponding to all threads are created, when the first main red-black tree is in a locked state, other working threads do not need to wait for the unlocking of the first main red-black tree and then carry out writing operation in the first main red-black tree, but directly carry out writing operation in the first sub red-black tree in the thread buffer area corresponding to the other working threads, and therefore the classification efficiency of the flow data packets is improved.
Based on the same inventive concept, according to the traffic packet classification method provided in the above embodiment of the present invention, correspondingly, an embodiment of the present invention further provides a traffic packet classification device, a schematic structural diagram of the device is shown in fig. 3, and the device includes:
a current traffic data packet receiving module 301, configured to receive a current traffic data packet as a to-be-classified data packet;
a hash value obtaining module 302, configured to calculate address feature information of the data packet to be classified by using a preset hash algorithm, so as to obtain a hash value of the data packet to be classified;
a hash classification module 303, configured to classify the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified;
a classification result obtaining module 304, configured to determine, based on the address feature information of the to-be-classified data packet, a current node corresponding to the address feature information of the to-be-classified data packet in a first red-black tree set corresponding to the first hash data packet; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
Further, the hash classification module 303 is specifically configured to: judging whether hash data packet groups with hash values identical to those of the data packets to be classified exist in the existing hash data packet groups; if yes, classifying the data packet to be classified into a first hash data packet group with the same hash value as the data packet to be classified; and if not, newly building a first Hash data packet group with the same Hash value as the data packet to be classified, and classifying the data packet to be classified into the newly built first Hash data packet group.
Further, the classification result obtaining module 304, when performing the step of determining, in the first red-black tree set corresponding to the first hash packet, a current node corresponding to the address feature information of the to-be-classified data packet based on the address feature information of the to-be-classified data packet, includes: the judgment submodule, the first current node determination submodule and the second current node determination submodule;
the judging submodule is used for judging whether a first main red-black tree which corresponds to the first hash data packet group exists or not; if yes, triggering the first current node determination submodule; if not, triggering the second current node determination submodule;
the first current node determining submodule is used for searching a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree; if so, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first main red-black tree and is used as a current node;
the second current node determining submodule is used for newly setting a first main red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first main red-black tree.
Further, when the step of searching the node corresponding to the address feature information of the to-be-classified data packet in the first main red-black tree is executed, the first current node determining submodule is specifically configured to:
judging whether the first main red-black tree is in a locked state;
if not, executing the step of searching the node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree, and locking the first main red-black tree; after determining the current node, unlocking the first master Reddish Tree;
if the first main red-black tree is in a locked state, judging whether a first sub-red-black tree corresponding to the first hash data packet group exists or not; if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, and if the node exists, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree and is used as a current node; if the first sub-red-black tree corresponding to the first hash data packet group does not exist; newly setting a first sub-red-black tree corresponding to the first hash data packet; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first sub-red-black tree.
Further, the apparatus further comprises: the system comprises a red and black tree data packet grouping and merging module and a classification result reading module;
the red and black tree data packet grouping and merging module is used for merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees when the flow data packet classification result needs to be read, so as to obtain the merged red and black tree data packet group as the flow data packet classification result;
and the classification result reading module is used for reading the classification result of the flow data packet.
Further, the apparatus further comprises:
a buffer setting module for setting a first buffer and a second buffer in advance, the first buffer and the second buffer being alternately used as a write buffer or a read buffer;
the hash classification module 303 is specifically configured to classify the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified in the current write buffer area;
the judging submodule is specifically configured to judge whether a first main red-black tree set corresponding to the first hash data packet exists in the current write buffer;
the second current node determining submodule is specifically configured to newly set a first main red-black tree corresponding to the first hash data packet in the current write buffer when the step of newly setting the first main red-black tree corresponding to the first hash data packet is performed;
when the step of judging whether a first sub-red-black tree corresponding to the first hash data packet group exists is executed by the first current node determination submodule, the first current node determination submodule is specifically used for judging whether a first sub-red-black tree corresponding to the first hash data packet group exists in the current write buffer area;
the first current node determining submodule, when executing the step of newly setting a first sub-red-black tree corresponding to the first hash data packet if the first sub-red-black tree corresponding to the first hash data packet does not exist, is specifically configured to newly set a first sub-red-black tree corresponding to the first hash data packet in the current writing buffer area if the first sub-red-black tree corresponding to the first hash data packet does not exist in the current writing buffer area;
the red and black tree data packet grouping and merging module comprises: the buffer area switching submodule and the red and black tree data packet grouping and merging submodule;
the buffer switching submodule is used for switching the current writing buffer into the reading buffer and switching the current reading buffer into the writing buffer when the flow data packet classification result needs to be read;
and the red and black tree data packet grouping and merging submodule is used for executing the step of merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees in the switched read buffer area to obtain the merged red and black tree data packet group as the classification result of the traffic data packet.
Further, the buffer switching sub-module is specifically configured to:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
In the embodiment shown in fig. 3, when the hash classification module 303 classifies the data packet to be classified into the corresponding first hash data packet group based on the hash algorithm, it is not necessary to match the address feature information of the data packet to be classified with all the different address feature information, and when the classification result obtaining module 304 determines the current node in the corresponding first red and black, it is also only necessary to match the address feature information of the data packet to be classified with the address feature information corresponding to each node in the first red and black tree, so as to obtain the classification result, and the address feature information corresponding to each node in the first red and black tree is only a small part of all the different address feature information, so that the amount of calculation in the classification process is reduced.
An embodiment of the present invention further provides an electronic device, as shown in fig. 4, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401, when executing the program stored in the memory 403, implements the following steps:
receiving a current flow data packet as a data packet to be classified;
calculating the address characteristic information of the data packet to be classified by adopting a preset Hash algorithm to obtain a Hash value of the data packet to be classified;
classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified;
determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first Hash data packet group based on the address characteristic information of the data packet to be classified; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
Further, other processing flows in the traffic data packet classification method provided in the embodiment of the present invention may also be included, and are not described in detail herein.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer-readable storage medium is further provided, which has instructions stored therein, and when the instructions are executed on a computer, the instructions cause the computer to execute the traffic packet classification method described in any of the above embodiments.
In a further embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the method for traffic packet classification as described in any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, 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, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the device and electronic apparatus embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference may be made to some descriptions of the method embodiments for relevant points.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (16)

1. A traffic data packet classification method is characterized by comprising the following steps:
receiving a current flow data packet as a data packet to be classified;
calculating the address characteristic information of the data packet to be classified by adopting a preset Hash algorithm to obtain a Hash value of the data packet to be classified;
classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified based on the hash values of the data packets to be classified;
determining a current node corresponding to the address characteristic information of the data packet to be classified in a first red-black tree set corresponding to the first Hash data packet group based on the address characteristic information of the data packet to be classified; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
2. The method of claim 1, wherein the step of classifying the data packet to be classified into a first hashed data packet corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified comprises:
judging whether hash data packet groups with hash values identical to those of the data packets to be classified exist in the existing hash data packet groups;
if yes, classifying the data packet to be classified into a first hash data packet group with the same hash value as the data packet to be classified;
and if not, newly building a first Hash data packet group with the same Hash value as the data packet to be classified, and classifying the data packet to be classified into the newly built first Hash data packet group.
3. The method according to claim 1, wherein the step of determining a current node corresponding to the address feature information of the data packet to be classified in a first red-black tree corresponding to the first hashed data packet based on the address feature information of the data packet to be classified comprises:
judging whether a first main red-black tree corresponding to the first hash data packet group exists or not;
if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree; if so, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first main red-black tree and is used as a current node;
if the first main red-black tree corresponding to the first hash data packet group does not exist, newly setting a first main red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first main red-black tree.
4. The method according to claim 3, wherein the step of searching the first main red-black tree for the node corresponding to the address feature information of the to-be-classified data packet, if any, comprises:
if so, judging whether the first main Reddish Black Tree is in a locked state;
if not, the step of searching the node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree is executed, the first main red-black tree is locked, and the first main red-black tree is unlocked after the current node is determined;
if the first main red-black tree is in a locked state, judging whether a first sub-red-black tree corresponding to the first hash data packet group exists or not; if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, and if the node exists, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree and is used as a current node; if the first sub-red-black tree corresponding to the first hash data packet group does not exist, newly setting a first sub-red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first sub-red-black tree.
5. The method of claim 4, further comprising:
when the traffic data packet classification result needs to be read, combining the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees to obtain the combined red and black tree data packet group as the traffic data packet classification result;
and reading the classification result of the flow data packet.
6. The method of claim 5, further comprising:
presetting a first buffer and a second buffer, which are alternately used as a write buffer or a read buffer;
the step of classifying the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified comprises:
classifying the data packets to be classified into first hash data packet groups corresponding to the hash values of the data packets to be classified in the current write buffer area based on the hash values of the data packets to be classified;
the step of determining whether there is a first main red-black tree set corresponding to the first hash packet includes:
judging whether a first main red-black tree set corresponding to the first hash data packet group exists in the current writing buffer area or not;
the step of newly setting a first main red-black tree corresponding to the first hash packet if there is no first main red-black tree set corresponding to the first hash packet includes:
if a first main red-black tree corresponding to the first hash data packet does not exist in the current writing buffer area, newly setting a first main red-black tree corresponding to the first hash data packet in the current writing buffer area;
the step of determining whether there is a first sub-blacktree corresponding to the first hash packet includes:
judging whether a first sub-red-black tree corresponding to the first Hash data packet group exists in the current writing buffer area or not;
if there is no first sub-red-black tree corresponding to the first hash data packet, newly setting a first sub-red-black tree corresponding to the first hash data packet, including:
if the current writing buffer area does not have a first sub red-black tree corresponding to the first hash data packet group, a first sub red-black tree corresponding to the first hash data packet group is newly arranged in the current writing buffer area;
when a traffic data packet classification result needs to be read, merging red and black tree data packet groups represented by nodes corresponding to the same address characteristic information in all main red and black trees and all sub red and black trees to obtain merged red and black tree data packet groups, wherein the step of taking the merged red and black tree data packet groups as the traffic data packet classification result comprises the following steps:
when the classification result of the flow data packet needs to be read, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area;
and in the switched read buffer area, executing the step of merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees to obtain the merged red and black tree data packet group as the classification result of the traffic data packet.
7. The method as claimed in claim 6, wherein the step of switching the current write buffer to the read buffer and the current read buffer to the write buffer when the traffic packet classification result needs to be read comprises:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
8. An apparatus for classifying traffic packets, comprising:
a current flow data packet receiving module, configured to receive a current flow data packet as a to-be-classified data packet;
the hash value obtaining module is used for calculating the address characteristic information of the data packet to be classified by adopting a preset hash algorithm to obtain the hash value of the data packet to be classified;
the Hash classification module is used for classifying the data packets to be classified into first Hash data packet groups corresponding to the Hash values of the data packets to be classified based on the Hash values of the data packets to be classified;
a classification result obtaining module, configured to determine, based on the address feature information of the to-be-classified data packet, a current node corresponding to the address feature information of the to-be-classified data packet in a first red-black tree set corresponding to the first hash data packet; each node in the first red-black tree represents a red-black tree data packet group, and each red-black tree data packet group corresponds to one address characteristic information; and grouping the first red and black tree data packets corresponding to the current node as the classification result of the data packets to be classified.
9. The apparatus of claim 8,
the hash classification module is specifically configured to: judging whether hash data packet groups with hash values identical to those of the data packets to be classified exist in the existing hash data packet groups; if yes, classifying the data packet to be classified into a first hash data packet group with the same hash value as the data packet to be classified; and if not, newly building a first Hash data packet group with the same Hash value as the data packet to be classified, and classifying the data packet to be classified into the newly built first Hash data packet group.
10. The apparatus of claim 8,
the classification result obtaining module, when executing the step of determining a current node corresponding to the address feature information of the to-be-classified data packet in a first red-black tree set corresponding to the first hash data packet group based on the address feature information of the to-be-classified data packet, includes: the judgment submodule, the first current node determination submodule and the second current node determination submodule;
the judging submodule is used for judging whether a first main red-black tree which corresponds to the first hash data packet group exists or not; if yes, triggering the first current node determination submodule; if not, triggering the second current node determination submodule;
the first current node determining submodule is used for searching a node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree; if so, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first main red-black tree and is used as a current node;
the second current node determining submodule is used for newly setting a first main red-black tree corresponding to the first hash data packet group; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first main red-black tree.
11. The apparatus of claim 10,
when the step of searching for the node corresponding to the address feature information of the to-be-classified data packet in the first main red-black tree is executed, the first current node determining submodule is specifically configured to:
judging whether the first main red-black tree is in a locked state;
if not, executing the step of searching the node corresponding to the address characteristic information of the data packet to be classified in the first main red-black tree, and locking the first main red-black tree; after determining the current node, unlocking the first master Reddish Tree;
if the first main red-black tree is in a locked state, judging whether a first sub-red-black tree corresponding to the first hash data packet group exists or not; if the node exists, searching a node corresponding to the address characteristic information of the data packet to be classified in the first sub-red-black tree, and if the node exists, taking the searched node as the current node; if the node is not found, a node corresponding to the address characteristic information of the data packet to be classified is newly established in the first sub-red-black tree and is used as a current node; if the first sub-red-black tree corresponding to the first hash data packet group does not exist; newly setting a first sub-red-black tree corresponding to the first hash data packet; and newly building a node corresponding to the address characteristic information of the data packet to be classified as the current node in the newly-set first sub-red-black tree.
12. The apparatus of claim 11, further comprising: the system comprises a red and black tree data packet grouping and merging module and a classification result reading module;
the red and black tree data packet grouping and merging module is used for merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees when the flow data packet classification result needs to be read, so as to obtain the merged red and black tree data packet group as the flow data packet classification result;
and the classification result reading module is used for reading the classification result of the flow data packet.
13. The apparatus of claim 12, further comprising:
a buffer setting module for setting a first buffer and a second buffer in advance, the first buffer and the second buffer being alternately used as a write buffer or a read buffer;
the hash classification module is specifically configured to classify the data packet to be classified into a first hash data packet group corresponding to the hash value of the data packet to be classified based on the hash value of the data packet to be classified in the current write buffer area;
the judging submodule is specifically configured to judge whether a first main red-black tree set corresponding to the first hash data packet exists in the current write buffer;
the second current node determining submodule is specifically configured to newly set a first main red-black tree corresponding to the first hash data packet in the current write buffer when the step of newly setting the first main red-black tree corresponding to the first hash data packet is performed;
when the step of judging whether a first sub-red-black tree corresponding to the first hash data packet group exists is executed by the first current node determination submodule, the first current node determination submodule is specifically used for judging whether a first sub-red-black tree corresponding to the first hash data packet group exists in the current write buffer area;
the first current node determining submodule, when executing the step of newly setting a first sub-red-black tree corresponding to the first hash data packet if the first sub-red-black tree corresponding to the first hash data packet does not exist, is specifically configured to newly set a first sub-red-black tree corresponding to the first hash data packet in the current writing buffer area if the first sub-red-black tree corresponding to the first hash data packet does not exist in the current writing buffer area;
the red and black tree data packet grouping and merging module comprises: the buffer area switching submodule and the red and black tree data packet grouping and merging submodule;
the buffer switching submodule is used for switching the current writing buffer into the reading buffer and switching the current reading buffer into the writing buffer when the flow data packet classification result needs to be read;
and the red and black tree data packet grouping and merging submodule is used for executing the step of merging the red and black tree data packet groups represented by the nodes corresponding to the same address characteristic information in all the main red and black trees and all the sub red and black trees in the switched read buffer area to obtain the merged red and black tree data packet group as the classification result of the traffic data packet.
14. The apparatus of claim 13, wherein the buffer switching submodule is specifically configured to:
when receiving a command for reading the classification result of the flow data packet, switching the current write buffer area into a read buffer area, and switching the current read buffer area into a write buffer area;
alternatively, the first and second electrodes may be,
and when the preset flow data packet classification result reading period is reached, switching the current writing buffer area into a reading buffer area, and switching the current reading buffer area into a writing buffer area.
15. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 7 when executing a program stored in the memory.
16. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 7.
CN201911423810.7A 2019-12-31 2019-12-31 Traffic data packet classification method and device and electronic equipment Active CN113132261B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911423810.7A CN113132261B (en) 2019-12-31 2019-12-31 Traffic data packet classification method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911423810.7A CN113132261B (en) 2019-12-31 2019-12-31 Traffic data packet classification method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN113132261A true CN113132261A (en) 2021-07-16
CN113132261B CN113132261B (en) 2023-01-03

Family

ID=76769889

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911423810.7A Active CN113132261B (en) 2019-12-31 2019-12-31 Traffic data packet classification method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN113132261B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113518130A (en) * 2021-08-19 2021-10-19 北京航空航天大学 Packet burst load balancing method and system based on multi-core processor

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103746919A (en) * 2014-01-14 2014-04-23 浪潮电子信息产业股份有限公司 Method for quickly classifying network packets through combining multi-way decision tree and Hash tables
CN106293585A (en) * 2012-04-17 2017-01-04 青岛海信移动通信技术股份有限公司 A kind of method for caching and processing shown for mobile terminal and device
CN106452856A (en) * 2016-09-28 2017-02-22 杭州鸿雁智能科技有限公司 Traffic flow statistics method and device, and wireless access equipment with traffic flow statistics function
CN106789727A (en) * 2016-12-27 2017-05-31 锐捷网络股份有限公司 Packet classification method and device
WO2018068524A1 (en) * 2016-10-12 2018-04-19 深圳市中兴微电子技术有限公司 Routing-table establishment and ip routing lookup method, device, and storage medium
CN110290117A (en) * 2019-06-06 2019-09-27 新华三信息安全技术有限公司 A kind of method and device of Match IP Address

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106293585A (en) * 2012-04-17 2017-01-04 青岛海信移动通信技术股份有限公司 A kind of method for caching and processing shown for mobile terminal and device
CN103746919A (en) * 2014-01-14 2014-04-23 浪潮电子信息产业股份有限公司 Method for quickly classifying network packets through combining multi-way decision tree and Hash tables
CN106452856A (en) * 2016-09-28 2017-02-22 杭州鸿雁智能科技有限公司 Traffic flow statistics method and device, and wireless access equipment with traffic flow statistics function
WO2018068524A1 (en) * 2016-10-12 2018-04-19 深圳市中兴微电子技术有限公司 Routing-table establishment and ip routing lookup method, device, and storage medium
CN106789727A (en) * 2016-12-27 2017-05-31 锐捷网络股份有限公司 Packet classification method and device
CN110290117A (en) * 2019-06-06 2019-09-27 新华三信息安全技术有限公司 A kind of method and device of Match IP Address

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王相林等: "一种改进的NAT-PT地址映射表查找算法", 《杭州电子科技大学学报》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113518130A (en) * 2021-08-19 2021-10-19 北京航空航天大学 Packet burst load balancing method and system based on multi-core processor
CN113518130B (en) * 2021-08-19 2023-03-24 北京航空航天大学 Packet burst load balancing method and system based on multi-core processor

Also Published As

Publication number Publication date
CN113132261B (en) 2023-01-03

Similar Documents

Publication Publication Date Title
US20140020100A1 (en) Detecting network anomaly
US11816117B2 (en) Data retrieval method and apparatus
CN111062013B (en) Account filtering method and device, electronic equipment and machine-readable storage medium
US11882047B2 (en) Traffic classification method and apparatus
CN111159413A (en) Log clustering method, device, equipment and storage medium
WO2023056723A1 (en) Fault diagnosis method and apparatus, and electronic device and storage medium
CN106649344B (en) Weblog compression method and device
CN110555144A (en) stream clustering method and device, electronic equipment and medium
CN113132261B (en) Traffic data packet classification method and device and electronic equipment
JP2022522790A (en) Methods and devices for tracking blockchain transactions
US10990569B2 (en) Sorting system
CN114168352B (en) Multi-core task scheduling method and device, electronic equipment and storage medium
CN110827036A (en) Method, device, equipment and storage medium for detecting fraudulent transactions
CN114281648A (en) Data acquisition method and device, electronic equipment and storage medium
CN110336813B (en) Access control method, device, equipment and storage medium
CN113127693A (en) Traffic data packet statistical method, device, equipment and storage medium
CN115242436B (en) Malicious traffic detection method and system based on command line characteristics
CN109800775B (en) File clustering method, device, equipment and readable medium
US10554563B2 (en) Generating a packet processing pipeline definition
CN115688099A (en) Computer virus retrieval method and device, computer equipment and storage medium
CN112801070B (en) Target detection method, device, equipment and storage medium
CN112667867B (en) Matching conflict checking method and equipment based on TCAM (ternary content addressable memory) feature code
JP7133037B2 (en) Message processing method, device and system
CN114124704B (en) Route optimization method, device, electronic equipment and storage medium
CN117010011B (en) Data protection system and method

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
GR01 Patent grant
GR01 Patent grant