The classification method and device of net packet rule set
Technical field
This application involves field of communication technology more particularly to a kind of classification methods and device of net packet rule set.
Background technique
With the development of internet, traditional routing technology is no longer satisfied the demand of network service, therefore, net packet classification
Technology is come into being.Net packet sorting technique refers to according to the information in net packet, according to preset net packet rule set (net packet rule set
Including multiple net packet rules) process classified is wrapped to net.The division of net packet classifying rules by default rule collection into
Row pretreatment, generates multiple rules subsets, can effectively improve search speed when net packet is classified to net packet rule, improve net
Packet classification performance.
However, asterisk wildcard may be contained in net packet rule in above-mentioned net packet rule set.In the related technology, it is wrapped when according to net
When asterisk wildcard node division classifying rules subset in rule, the more rules subset of net packet rule can be generated, thus occupy compared with
Big memory space.
Summary of the invention
In view of this, the application provides the classification method and device of a kind of net packet rule set, to solve net in the related technology
Packet classification method occupies the problem of larger memory space.
Specifically, the application is achieved by the following technical solution:
The application provides a kind of classification method of net packet rule set, and the net packet rule set includes several net packet rules, institute
Method is stated applied on the network equipment, which comprises
The net packet rule in net packet rule set is encoded based on preset coding rule;
After completing the coding to the net packet rule in the net packet rule set, based on the net in the net packet rule set after coding
Packet rule building net packet rule set state machine;
Classified according to the net packet rule set state machine to net packet rule set.
It is optionally, described that the net packet rule in net packet rule set is encoded based on preset coding rule, comprising:
Based on preset mapping relations by the corresponding character code of each dimension of the net packet rule for by specific character
Collect the character string of composition;
Character string after each dimension coding of the net packet rule is based on specified sequence to combine.
Optionally, the net packet rule set based on after coding constructs net packet rule set state machine, comprising:
Net packet rule set state machine is successively constructed according to the net packet rule after the coding.
Optionally, the net packet rule set based on after coding constructs net packet rule set state machine, comprising:
When having asterisk wildcard in the net packet rule after the coding, the asterisk wildcard in the net packet rule after the coding is replaced
It is changed to preset value;
Net packet rule set state machine is successively constructed according to the net packet rule after the replacement asterisk wildcard.
Optionally, the net packet rule set based on after coding constructs net packet rule set state machine, comprising:
When the net packet rule in the net packet rule set after coding includes multiple bits, successively according to the net after the coding
Packet rule constructs more Binet packet rule set state machines.
The application provides a kind of sorter of net packet rule set simultaneously, and the net packet rule set includes several net packet rule
Then, the method is applied on the network equipment, and described device includes:
Coding unit, for being encoded based on preset coding rule to the net packet rule in net packet rule set;
Construction unit, after completing the coding to the net packet rule in the net packet rule set, based on the net after coding
Net packet rule in packet rule set constructs net packet rule set state machine;
Taxon, for being classified according to the net packet rule set state machine to net packet rule set.
Optionally, the coding unit is specifically used for:
Based on preset mapping relations by the corresponding character code of each dimension of the net packet rule for by specific character
Collect the character string of composition;
Character string after each dimension coding of the net packet rule is based on specified sequence to combine.
Optionally, the construction unit is specifically used for:
Net packet rule set state machine is successively constructed according to the net packet rule after the coding.
Optionally, the construction unit is specifically used for:
When having asterisk wildcard in the net packet rule after the coding, the asterisk wildcard in the net packet rule after the coding is replaced
It is changed to preset value;
Net packet rule set state machine is successively constructed according to the net packet rule after the replacement asterisk wildcard.
Optionally, the construction unit is specifically used for:
When the net packet rule in the net packet rule set after coding includes multiple bits, successively according to the net after the coding
Packet rule constructs more Binet packet rule set state machines.
In this application, the network equipment can carry out the net packet rule in net packet rule set based on preset coding rule
Coding can be based on the net packet rule set after coding then after completing to the coding of the net packet rule in the net packet rule set
Net packet rule set state machine is constructed, and is classified according to the net packet rule set state machine to net packet rule set.Using the application
Can by by the net packet rule in net packet rule set from multidimensional drop to it is one-dimensional construct net packet rule set state machine, and according to structure
The net packet rule set state machine built out classifies to the net packet rule in net packet rule set, since less net packet can be generated
Rule, therefore the problem of can solve the relevant technologies.
Detailed description of the invention
Fig. 1 is a kind of embodiment flow chart of the classification method of net packet rule set shown in the application;
Fig. 2 is a kind of rule set state machine shown in the application;
Fig. 3 is another rule set state machine shown in the application;
Fig. 4 is a kind of more bit rules collection state machines shown in the application;
Fig. 5 is a kind of hardware structure diagram of equipment where the sorter of the application net packet rule set;
Fig. 6 is one embodiment block diagram of the sorter of the application net packet rule set.
Specific embodiment
Example embodiments are described in detail here, and the example is illustrated in the accompanying drawings.Following description is related to
When attached drawing, unless otherwise indicated, the same numbers in different drawings indicate the same or similar elements.Following exemplary embodiment
Described in embodiment do not represent all embodiments consistent with the application.On the contrary, they be only with it is such as appended
The example of the consistent device and method of some aspects be described in detail in claims, the application.
It is only to be not intended to be limiting the application merely for for the purpose of describing particular embodiments in term used in this application.
It is also intended in the application and the "an" of singular used in the attached claims, " described " and "the" including majority
Form, unless the context clearly indicates other meaning.It is also understood that term "and/or" used herein refers to and wraps
It may be combined containing one or more associated any or all of project listed.
It will be appreciated that though various information, but this may be described using term first, second, third, etc. in the application
A little information should not necessarily be limited by these terms.These terms are only used to for same type of information being distinguished from each other out.For example, not departing from
In the case where the application range, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as
One information.Depending on context, word as used in this " if " can be construed to " ... when " or " when ...
When " or " in response to determination ".
In the related technology, net packet rule set may include several net packet rules, wherein can contain in several net packet rules
There is asterisk wildcard.When wrapping the asterisk wildcard node division rules subset in rule according to net, the more rule of net packet rule can be generated
Subset.
For example, above-mentioned net packet rule set can be two-dimensional mesh packet rule set, wherein every dimension can use value 0 or 1, can be with
Assuming that the net packet rule set includes that 4 nets packet is regular, and 4 net packet rules are respectively as follows: R1:0, *, R2:1,0, R3:1,1 with
And R4:*, 0.When being divided to the two-dimensional mesh packet rule set, available following result: 0,0 group: R1 and R4;0,1
Group: R1;1,0 groups: R2 and R4;1,1 groups: R3.From this result, the divided regular sum of the net packet rule set can be
6。
In another hypothesis, asterisk wildcard, and the net packet are not contained in the classifying rules in above-mentioned two-dimensional mesh packet rule set
4 net packet rules in rule set are respectively as follows: R1:0,1, R2:1,0, R3:1,1 and R4:1,0.Then advised when to the two-dimensional mesh packet
When then collection is divided, available following result: 0,0 group: nothing;0,1 group: R1;1,0 groups: R2 and R4;1,1 groups: R3.From
The result is it is found that the divided regular sum of the net packet rule set can be 4.
By above-mentioned two example it is found that can be generated when wrapping the asterisk wildcard node division rules subset in rule according to net
The more rules subset of net packet rule, to occupy biggish memory space.
In order to solve the problems, such as that net packet classifying method occupies larger memory space in the related technology, the application provides a kind of net
The classification method and device of packet rule set.In this application, the network equipment can be based on preset coding rule to net packet rule
The net packet rule of concentration is encoded, and then after completing to the coding of the net packet rule in the net packet rule set, can be based on
Net packet rule set after coding constructs net packet rule set state machine, and according to the net packet rule set state machine to net packet rule set into
Row classification.It can be one-dimensional regular to construct net packet by dropping to the net packet rule in net packet rule set from multidimensional using the application
Collect state machine, and is classified according to the net packet rule set state machine constructed to the net packet rule in net packet rule set, due to
The problem of less net packet rule can be generated, therefore can solve the relevant technologies.
Referring to FIG. 1, the embodiment flow chart of the classification method for a kind of net packet rule set shown in the application, the side
Method is applied to the network equipment, comprising the following steps:
Step 101: the net packet rule in net packet rule set being encoded based on preset coding rule.
In this application, the network equipment can be with pre-arranged code rule, and wraps rule to net according to the preset coding rule
The net packet rule of concentration is encoded.
Specifically, the net in above-mentioned net packet rule set can be wrapped the every of rule based on preset mapping relations by the network equipment
The corresponding character code of one dimension is the character string being made of specific character collection, then by each dimension of the net packet rule
Character string after coding is based on specified sequence and combines.It should be noted that above-mentioned preset mapping relations can be customized by the user
Setting, for example, can be F (x)=X, the application be without limitation.Similarly, above-mentioned specific character collection and specified sequence
Can also be customized by the user setting, the application to this equally with no restrictions.
In the one embodiment shown, it can be assumed that above-mentioned net packet rule set includes that 4 nets wrap rule, and 4 nets
Packet rule is respectively as follows: R1:0, *, R2:1,0, R3:1,1 and R4:*, and 0.Then the network equipment is to the net in the net packet rule set
During packet rule is encoded, above-mentioned each net can first be wrapped to each dimension of rule based on preset mapping relations
Corresponding character code is the character string being made of specific character collection, it can be assumed that preset mapping relations are F (x)=X, specific
Character set can be set { 0,1, * }, then above-mentioned each net is being wrapped each of rule based on above-mentioned mapping relations by the network equipment
After the corresponding character code of a dimension is the character string being combined by above-mentioned collection, available 4 nets packet as follows is regular:
R1 ': 0, *, R2 ': 1,0, R3 ': 1,1 and R4 ': *, 0.Then, the network equipment can be by each of above-mentioned each net packet rule
Character string after dimension coding is based on specified sequence and combines, and in one embodiment, each dimension of above-mentioned 4 nets packet rule is compiled
Character string after code based on specified sequence after being combined, 4 rules that can be as follows: R1 ": 0*, R2 ": 10, R3 ": 11 with
And R4 ": * 0.
Step 102: after completing the coding to the net packet rule in the net packet rule set, based on the net packet rule after coding
The net packet rule of concentration constructs net packet rule set state machine.
In this application, the network equipment, can be with base after completing to the coding of the net packet rule in above-mentioned net packet rule set
Net packet rule in net packet rule set after coding constructs net packet rule set state machine.Specifically, the network equipment can be successively
Net packet rule set state machine is constructed according to net packet rule encoded in above-mentioned net packet rule set.
In one embodiment, the network equipment can by by net packet rule encoded in above-mentioned net packet rule set one by one
Insertion character set is the mode of the state machine of above-mentioned default characters to construct above-mentioned net packet rule set state machine.
In the one embodiment shown, it can be assumed that the net packet rule in the net packet rule set after above-mentioned coding are as follows:
R1 ": 0*, R2 ": 10, R3 ": 11 and R4 ": * 0, then the net packet rule after this 4 codings can be inserted by the network equipment one by one
Character set is in the state machine of { 0,1, * }, and then, the network equipment can obtain rule set state machine as shown in Figure 2.
It in one embodiment, can be by the net after the coding when having asterisk wildcard in the net packet rule after above-mentioned coding
Asterisk wildcard in packet rule replaces with preset value, wherein the preset value can be customized by the user setting, such as can be above-mentioned
Specific character concentrates the character of non-asterisk wildcard, i.e. the preset value can be 1 or 0.After the completion of replacement, the network equipment can successively root
Net packet rule set state machine is constructed according to the net packet rule after replacement asterisk wildcard.Due to wrapping rule building net packet rule set shape according to net
The process of state machine illustrates in the above-described embodiments, therefore details are not described herein by the application.
In the one embodiment shown, it can be assumed that the net packet rule in the net packet rule set after above-mentioned coding are as follows:
R1 ' ': 0*, R2 ' ': 10, R3 ": 11 and R4 ": * 0.There is due to net packet rule R1 " and in R4 ' ' asterisk wildcard, network
Asterisk wildcard in net packet rule R1 ' ' and R4 " can be replaced with 0 or 1 by equipment, and wrap rule building according to replaced net
Rule set state machine as shown in Figure 3.
In one embodiment, when the net packet rule in the net packet rule set after coding includes multiple bits, network is set
It is standby more bit rules collection state machines to be constructed according to the net packet rule after coding.
In the one embodiment shown, it can be assumed that the net packet rule in the net packet rule set after above-mentioned coding are as follows:
R1 ' ': 0*, R2 ' ': 10, R3 ": 11 and R4 ": * 0.Since the net packet rule in above-mentioned net packet rule set includes 2 bits, because
This, the network equipment can wrap rule according to replaced net and generate after the asterisk wildcard in net packet rule is replaced with preset value
More Binet packet rule set state machines as shown in Figure 4.
Step 103: being classified according to the net packet rule set state machine to net packet rule set.
In the application, the network equipment can advise after completing to the building of net packet rule set state machine according to the net packet
Then collect classification of the state machine completion to net packet rule set.
As can be seen from the above embodiments, when the net packet rule set state machine of network equipment building is as shown in Figure 2, the network equipment
Net packet rule set can be divided according to the net packet rule set state machine, it can be assumed that net packet rule set are as follows: R1:0, *,
R2:1,0, R3:1,1 and R4:*, 0, then the network equipment is available as follows after dividing to the net packet rule set
4 nets wrap rule: r1:0*, r2:10, r3:11 and r4:*0;When the net packet rule set state machine of network equipment building is as schemed
When shown in 3, the network equipment can be divided above-mentioned net packet rule set according to the net packet rule set state machine are as follows: r1 ': 00, r2 ':
01, r3 ': 10 and r4 ': 11 totally 4 nets packet rules;When network equipment building more Binet packet rule set shapes as shown in Figure 4
When state machine, the network equipment quickly can be divided above-mentioned net packet rule set according to more Binet packet rule set state machines are as follows:
R1 ": 00, r2 ": 01, r3 ": 10 and r4 ": 11 totally 4 nets packet rules.
In this application, the network equipment can carry out the net packet rule in net packet rule set based on preset coding rule
Coding can be based on the net packet rule set after coding then after completing to the coding of the net packet rule in the net packet rule set
Net packet rule set state machine is constructed, and is classified according to the net packet rule set state machine to net packet rule set.Using the application
Can by by the net packet rule in net packet rule set from multidimensional drop to it is one-dimensional construct net packet rule set state machine, and according to structure
The net packet rule set state machine built out classifies to the net packet rule in net packet rule set, since less net packet can be generated
Rule, therefore the problem of can solve the relevant technologies.
Corresponding with the embodiment of classification method of aforementioned net packet rule set, present invention also provides points of net packet rule set
The embodiment of class device.
The embodiment of the sorter of the application net packet rule set can be using on network devices.Installation practice can be with
By software realization, can also be realized by way of hardware or software and hardware combining.Taking software implementation as an example, it is patrolled as one
Device in volume meaning is by the processor of equipment where it by computer program instructions corresponding in nonvolatile memory
It is read into memory what operation was formed.For hardware view, as shown in figure 5, being the sorter of the application net packet rule set
A kind of hardware structure diagram of place equipment, in addition to processor shown in fig. 5, memory, network interface and nonvolatile memory
Except, the network equipment in embodiment where device can also include usually other hardware, such as be responsible for the forwarding core of processing message
Piece etc..
Referring to FIG. 6, being one embodiment block diagram of the sorter of the application net packet rule set.
The apparatus may include: coding unit 610, construction unit 620 and taxon 630.
Wherein, coding unit 610, for being compiled based on preset coding rule to the net packet rule in net packet rule set
Code;
Construction unit 620, after completing the coding to the net packet rule in the net packet rule set, after coding
Net packet rule in net packet rule set constructs net packet rule set state machine;
Taxon 630, for being classified according to the net packet rule set state machine to net packet rule set.
In an optional implementation, the coding unit 610 can be specifically used for:
Based on preset mapping relations by the corresponding character code of each dimension of the net packet rule for by specific character
Collect the character string of composition;
Character string after each dimension coding of the net packet rule is based on specified sequence to combine.
In an optional implementation, the construction unit 620 can be specifically used for:
Net packet rule set state machine is successively constructed according to the net packet rule after the coding.
In an optional implementation, the construction unit 620 can be specifically used for:
When having asterisk wildcard in the net packet rule after the coding, the asterisk wildcard in the net packet rule after the coding is replaced
It is changed to preset value;
Net packet rule set state machine is successively constructed according to the net packet rule after the replacement asterisk wildcard.
In an optional implementation, the construction unit 620 can be specifically used for:
When the net packet rule in the net packet rule set after coding includes multiple bits, successively according to the net after the coding
Packet rule constructs more Binet packet rule set state machines.
In this application, the network equipment can carry out the net packet rule in net packet rule set based on preset coding rule
Coding can be based on the net packet rule set after coding then after completing to the coding of the net packet rule in the net packet rule set
Net packet rule set state machine is constructed, and is classified according to the net packet rule set state machine to net packet rule set.Using the application
Can by by the net packet rule in net packet rule set from multidimensional drop to it is one-dimensional construct net packet rule set state machine, and according to structure
The net packet rule set state machine built out classifies to the net packet rule in net packet rule set, since less net packet can be generated
Rule, therefore the problem of can solve the relevant technologies.
The function of each unit and the realization process of effect are specifically detailed in the above method and correspond to step in above-mentioned apparatus
Realization process, details are not described herein.
For device embodiment, since it corresponds essentially to embodiment of the method, so related place is referring to method reality
Apply the part explanation of example.The apparatus embodiments described above are merely exemplary, wherein described be used as separation unit
The unit of explanation may or may not be physically separated, and component shown as a unit can be or can also be with
It is not physical unit, it can it is in one place, or may be distributed over multiple network units.It can be according to actual
The purpose for needing to select some or all of the modules therein to realize application scheme.Those of ordinary skill in the art are not paying
Out in the case where creative work, it can understand and implement.
The foregoing is merely the preferred embodiments of the application, not to limit the application, all essences in the application
Within mind and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the application protection.