Summary of the invention
For solve existing route table implementation method exist do not satisfy can high-speed searching, upgrade fast, again can internal memory expend lessly, the technical problem such as cost is lower the invention provides a kind of processing method of route prefix, comprises searching, increasing and the operation such as deletion.
A kind of processing method of route prefix is characterized in that: said method comprising the steps of:
1) fast finding: the relationship map of IP prefix and route table items is become all concrete IP addresses of IP prefix representative and the relation of route table items, and constantly preserve the corresponding route table items of longest-prefix by each concrete IP address;
2) upgrade fast: the non-longest-prefix of each concrete IP address is preserved, when longest-prefix changes because of additions and deletions, can from other non-longest-prefixes, be sought rapidly a longest-prefix;
3) prefix diffusion: solve the incidence relation of prefix between the adjacent Tire node by the prefix diffusion method, avoided the back tracking operation in the search procedure.
2, the processing method of route prefix according to claim 1 is characterized in that: described Tire node is the Tire node in the Multi-branch Trie Tree structure, and when Trie node step-length was K, this Trie node comprised 2
KIndividual IP bit section has comprised K+1 kind mask simultaneously, wherein mask 0 expression default mask or from the expansion mask of father node, mask 2
K-1 is long code mask.
As further improvement in the technical proposal, above-mentioned Trie tree structure is preserved corresponding all K+1 kind masks of each IP bit section in the described Trie node; Long code mask is corresponding one by one with concrete IP address, but not long code mask is the corresponding of one-to-many with the IP address.
As further improvement in the technical proposal, the structure of above-mentioned Trie tree is carried out the prefix diffusion between adjacent two-stage Trie node, by the longest-prefix of father node is spread to all child nodes, full 0 mask as own node is kept among the Trie of child node, child node is when searching longest-prefix, if find own to longer prefix, just the long code mask of the mask of this full 0 as oneself.
A kind of lookup method of route prefix said method comprising the steps of:
1) obtain IP address to be checked, IP address bit position begins to point to high-order Far Left, and the Trie tree is pointed to root node;
2) obtain the wide M of being of this grade Trie node step, then in the IP address, follow order from the left side and get the M bit value;
3) in this grade Trie node, directly search the longest-prefix descriptor that obtains correspondence with the M bit value;
4) in the longest-prefix descriptor, if the index territory equals-1, then failure; Otherwise, if the leaf territory equals 1, then to search successfully, route table items is index; If the leaf territory equals 0, then index is the index of next stage Trie node, jumps to next stage Trie node, and repeating step 2 again.
A kind of increase method of route prefix is characterized in that: said method comprising the steps of:
1) obtain IP prefix addresses to be added/MASK address, corresponding route table items Rn, IP/MASK address bit position begins to point to high-order Far Left, and the Trie tree is pointed to root node;
2) obtain the wide M of being of this grade Trie node step, in the IP/MASK address, then sequentially get the M bit value from the left side, be respectively ip_M, mask_M, the right, MASK address remainder score value is mask_L;
3) in this grade Trie node, directly find corresponding longest-prefix descriptor with ip_M;
4) if mask_M is not complete 1 mask, illustrate that the prefix back is 0 entirely, need not to continue to process, then add and upgrade Trie node at the corresponding levels;
If this Trie node also has child node, then prefix diffusion;
At this moment, interpolation is finished, and withdraws from.
5) if mask_M is complete 1 mask, and mask_L is 0, and explanation is that prefix has arrived the end, and perhaps the back is 0 entirely, need not to continue to process;
If prefix has arrived the end, the longest-prefix descriptor that then upgrades Trie node i p_M position is Rn, otherwise, read ip_M nodes of locations state;
If be 1, then prefix diffusion, otherwise the longest-prefix descriptor of renewal Trie node i p_M position is Rn;
At this moment, interpolation is finished, and withdraws from;
6) if mask_M is complete 1 mask, and mask_L is not 0, and the child node that also has at the corresponding levels is described, needs to continue to process;
Obtaining ip_M nodes of locations state at the corresponding levels, is 0, then needs to create child node; The longest-prefix descriptor that upgrades simultaneously Trie node i p_M position is the child node sequence number; If 1, need not operation; Be 2 and 3, then need to create child node, the prefix diffusion, the longest-prefix descriptor that upgrades simultaneously Trie node i p_M position is the child node sequence number;
7) jump to next node, and repeat repeating step 2.
As further improvement in the technical proposal, add the method for upgrading Trie node at the corresponding levels in the described step 4 and may further comprise the steps:
1) obtains Trie node at the corresponding levels, IP bit section address ip_M, MASK bit section address mask_M, corresponding route table items Rn;
2) the number affect_N of the calculating concrete IP address that mask_M had influence on; The IP address number that affects such as the mask_M of full 0 is 2
M, and the IP address number that complete 1 mask_M has influence on is 2
0=1;
3) from ip_M, circular treatment affect_N IP address, namely ip_M is to ip_M+affect_N;
4) obtaining each pending ip nodes of locations state, is 0, and the longest-prefix descriptor that then will revise this ip position is Rn; Be 1 and 3, then do not process; Be 2, judge that then this mask_M is the longest-prefix in the ip_M network segment, if so, the longest-prefix descriptor of then revising this ip position is Rn, otherwise does not process;
5) cycle-index is enough affect_N time, then carries out next step, and if not, then repeating step 3;
6) corresponding relation with this prefix ip_M and route Rn adds in the alternate prefix descriptor.
As further improvement in the technical proposal, the method for prefix diffusion may further comprise the steps in the described step 4:
1) obtains child node Trie corresponding to father node, prefix ip_M to be spread, and corresponding route table items Rn, and the Prefix Expansion length spread_prefixlen of the accepted father node of this child node;
2) if the length of prefix ip_M to be spread is little and the Prefix Expansion length spread_prefixlen of the accepted father node of this node, withdraw from, need not diffusion;
3) obtain the wide K of step of this node, then affected concrete IP address is 2
KIndividual, from 0 to 2
K-1 circular treatment;
4) obtaining each pending ip nodes of locations state, is 0, and the longest-prefix descriptor that then will revise this ip position is Rn; Be 1 and 3, then do not process; Be 2, judge that then this ip_M is the longest-prefix in the ip network segment, if so, the longest-prefix descriptor of then revising this ip position is Rn, otherwise does not process;
5) Rn is added in the descriptor for subsequent use of each ip and go;
6) cycle-index enough 2
KInferior, then carry out next step, if not, then repeating step 3;
7) the Prefix Expansion length spread_prefixlen that revises the accepted father node of this node is the length of ip_M.
A kind of delet method of route prefix said method comprising the steps of:
1) obtain IP address to be deleted/MASK address, IP/MASK address bit position begins to point to Far Left, and the Trie tree is pointed to root node;
2) obtain this grade Trie node and go on foot wide M, order is obtained M bit value ip_M in the IP address, and order is obtained M bit value mask_M in the MASK address, and the right, MASK address remainder score value is mask_L;
3) in this grade Trie node, directly find corresponding longest-prefix descriptor with ip_M;
4) if mask_M is not complete 1 coding, illustrate that the prefix back is 0 entirely, need not to continue to process, then the corresponding list item of ip_M (as described in [10] [1]) in the backup sheet of deletion renewal Trie node at the corresponding levels; If node at the corresponding levels has child node, then oppositely prefix diffusion (as described in [10] [2]);
5) if mask_M is complete 1 mask, and mask_L is 0, and explanation is that prefix has arrived the end, and perhaps the back is 0 entirely; Reading ip_M nodes of locations state, is 1, then oppositely prefix diffusion (as described in [10] [2]); Be 3, then delete the corresponding list item of ip_M (as described in [10] [1]) in the prefix table that upgrades Trie node at the corresponding levels; Being 0 and 2, is non-existent situation, deletes unsuccessfully, returns;
6) if mask_M is complete 1 mask, and mask_L is not 0, then in addition child node at the corresponding levels; Read the prefix descriptor, if prefix descriptor index territory is invalid, then prefix to be deleted does not exist, and deletes unsuccessfully, returns;
7) obtain child node, jump to next stage Trie node, repeating step 2.
As further improvement in the technical proposal, when Trie node at the corresponding levels is upgraded in the deletion in described step 4 and the step 5, if prefix to be deleted is complete 1, then delete the corresponding list item of ip_M in the prefix table, seeking simultaneously a prefix the longest from descriptor for subsequent use is filled in the prefix table, if there has not been any list item in backing sheet, then prefix table will become invalidly, and its index territory is-1; If prefix to be deleted is not complete 1, the corresponding list item of ip_M in the deletion backing sheet needs to detect the whether longest-prefix of all concrete ip that ip_M affects of this alternate prefix simultaneously.
As further improvement in the technical proposal, the method that Trie node at the corresponding levels is upgraded in described deletion may further comprise the steps:
1) obtains Trie node at the corresponding levels, IP bit section address ip_M to be deleted, MASK bit section address mask_M;
2) calculate the number affect_N of the concrete IP address that mask_M has influence on;
3) from ip_M, circular treatment affect_N IP address, namely ip_M is to ip_M+affect_N;
4) obtain each pending ip nodes of locations state, if 0,1,3 are not processed; If 2 needs are processed, because this mask_M may appear at the ip position in the prefix table descriptor;
Judge that mask_M is the longest-prefix of ip position in this node prefix table,
If so, then again be longest-prefix of ip searching in the backing sheet descriptor, the ip that is filled in the prefix descriptor is the position, if nothing, it is invalid that the ip position is made as;
If not, then do not process;
5) if cycle-index reaches affect_N time, then carry out next step, otherwise repeating step 3;
6) the corresponding route table items of deletion ip_M in descriptor for subsequent use.
As further improvement in the technical proposal, when oppositely prefix spreads in described step 4 and the step 5, if the father node of a child node is deleted, then need simultaneously to delete the prefix diffusion of this father node in byte point.Moreover, father node also needs longest-prefix remaining in its backing sheet is spread to child node.
As further improvement in the technical proposal, when also comprising deletion, described method recalls step, if namely in delete procedure success found prefix to be deleted, and in most end one-level Trie node with the final stage prefix bits from the prefix table of Trie or for subsequent use after the deletion, and do not mean that end; Specifically further comprising the steps of:
1) the Trie tree pointer points to afterbody Trie node;
2) if this grade Trie node has not comprised any one prefix information, then directly this knot removal is fallen; If only remain next prefix information, then this prefix information must be from the father node diffusion, with the position that this diffusion prefix can be write the prefix descriptor of father node, then deletes this node;
3) the Trie tree pointer points to the father node of present node, if father node is empty, explanation is the Trie root node, withdraws from.Otherwise carry out next step;
4) if this node surplus next prefix only is that ip prefix to be deleted is corresponding to the prefix bits section of this section Trie node so certainly.Implement the present invention and have following beneficial effect:
1) memory consumption: it is again 2 times that general T rie sets that the inventive method expends internal memory;
2) seek rate is fast: the seek rate of multi-fork Trie tree is very fast among the present invention, and generally the 1-5 step finishes, and each step is exactly an addressing and numerical value comparison operation, without other any extra process.Its processing speed is only second to the parallel search of hardware.
3) renewal speed is fast: update time mainly by the time of searching and more new data two parts form.The time of searching is very fast among the present invention, and more new data only relates to those concrete IP addresses that the final stage of prefix to be updated has influence in corresponding Trie node, and the step of this Trie node is wide, then affects concrete IP address just many, go on foot wide narrowlyer, then affect concrete IP address just few.But operating procedure is limited generally, and opereating specification is concentrated, and does not affect the operation of other Trie node, does not need outside assisting, and therefore more new data rate is still very fast.Concrete operations number of times and node go on foot wide K, and prefix length L is relevant.Go on foot wide K also little, prefix length L is larger, and then number of operations is fewer.In a word, the concrete operations number of times is 1-2
K, most cases.
4) utilization benefit is good: available pure software realization, and efficient is high, and need not other subsystem supports, and independence is good, can realize the linear forward efficiency of 10G on multi-core network processor.
Embodiment
The present invention mainly proposes a kind of high-speed searching of realizing route table items based on Multi-branch Trie Tree, and realize upgrading fast, namely add fast and fast deletion, and the method for storage consumption preferably, the method can be widely used in the express network forward node.The present invention utilizes multi-fork Trie tree, ingehious design Trie node data structure, and unique Processing Algorithm has been proposed.Specifically comprise route prefix list item store data structure and algorithm; High-speed searching route longest-prefix method; Increase fast the route prefix method; And delete fast the route prefix method.
The route table items prefix store data structure and the algorithm that wherein provide are specifically described as follows: the concrete methods of realizing of this algorithm is:
Step 1, the relationship map of IP prefix and route table items is become all concrete IP addresses of IP prefix representative and the relation of route table items, and constantly be the corresponding route table items of each concrete IP address preservation longest-prefix.Realize thus fast finding;
Step 2, the non-longest-prefix of each concrete IP address is preserved, when longest-prefix changes because of additions and deletions, can from other non-longest-prefixes, be sought rapidly a longest-prefix.Realize thus upgrading fast.
Step 3, employing prefix diffusion technique solve the incidence relation of prefix between the adjacent Tire node.
On the basis that above-mentioned algorithm is considered carefully, the present invention has also designed a kind of special routing table prefix storage organization, makes a concrete analysis of as follows:
When Trie node step-length was K, this Trie node had just comprised 2
KIndividual IP bit section; Comprised simultaneously K+1 mask, wherein mask 0(full 0) the expression default mask, perhaps from the expansion mask of father node, and mask 2
K-1(complete 1) then represent long code mask.
Store corresponding all route table items situations of mask among this K+1 fully, the simplest situation needs 2
K(K+1) individual memory cell.Ingehious design of the present invention is 2
KX2=2
K+1Individual memory cell, its mathematical principle are that 1 memory cell of storage full 0 mask needs is stored complete 1 mask needs 2
KIndividual memory cell, from the full 0 mask to complete 1 mask, tolerance of memory cell formation is 2 Geometric Sequence, therefore altogether needing memory cell is 2
K+1-1.Complete 1 mask has represented the longest-prefix of corresponding IP bit section, and other masks have then represented non-longest-prefix, i.e. alternate prefix.
Prefix diffusion technique wherein, different from the Prefix Expansion technology of carrying in the background, refer in the present invention in the Trie tree structure, different section in IP bit/MASK bit that every one-level node is corresponding respectively, all prefixes that the intersection of adjacent two-stage node (father node and child node) is father node are the prefix of child node all, when the parton node of a father node has longer prefix, and the parton node is during without longer prefix.When searching, just should choose the prefix of father node as its longest-prefix without the part child node of longer prefix.For avoiding this back tracking operation, just need to spread the longest-prefix of the sensing route of father node performance to all child nodes, exist as the full 0 mask of child node, will be the long code mask of the mask of this full 0 as oneself without the child node of longer prefix.This diffusion is only limited between the adjacent two-stage.
When increasing operation, prefix spreads to child node from father node; During deletion action, if father node deletion then needs to delete simultaneously in the child node from the diffusion prefix of father node, be referred to as reverse prefix diffusion.
Therefore, Trie node data structural design such as table 1:
Table 1
Wherein, longest-prefix descriptor nodind structure such as table 2:
Table 2
In the table 2, have 2 flag bits, to its coding, explain such as table 3:
Table 3
Follow-up leaf and this combination of from are called: certain nodes of locations state.The renewal operation of Trie node is carried out according to its nodes of locations state.In addition, below mention ip prefix length or mask address size, refer to the number on the left side continuous 1 in the ip/mask Bit String.Supported the fast finding that the present invention will realize by above data structure and rudimentary algorithm, the various concrete operations that increase and delete.
The method of high-speed searching route longest-prefix provided by the invention as shown in Figure 1, concrete lookup method may further comprise the steps:
Step 1 is obtained IP address to be checked, and IP address bit position begins to point to Far Left (high position), and the Trie tree is pointed to root node;
Step 2 is obtained the wide M of being of this grade Trie node step, then follows order from the left side in the IP address and gets the M bit value;
Step 3 is directly searched with the M bit value in this grade Trie node and is obtained corresponding longest-prefix descriptor (array search operation);
Step 4, in the longest-prefix descriptor, if the index territory equals-1, then failure; Otherwise, if the leaf territory equals 1, then to search successfully, route table items is index; If the leaf territory equals 0, then index is the index of next stage Trie node, jumps to next stage Trie node, repeating step 2;
In the above-mentioned search procedure, once circulation is exactly an addressing and numerical value comparison operation, and is very simple.Search time complexity 0 (1).
Referring to shown in Figure 2, the process of quick increase routing table provided by the present invention is: add and preserve all prefixes, and guarantee that the nodind territory of corresponding all the concrete IP addresses of prefix keeps all corresponding values of its longest-prefix all the time.
Concrete grammar may further comprise the steps:
Step 1, obtain IP prefix addresses to be added/MASK address, corresponding route table items Rn, IP/MASK address bit position begins to point to Far Left (high position), and the Trie tree is pointed to root node;
Step 2, obtain this grade Trie node step and widely be M, in the IP/MASK address from the left side then order get the M bit value, be respectively ip_M, mask_M, the right, MASK address remainder score value is mask_L;
Step 3, in this grade Trie node, directly find corresponding longest-prefix descriptor (array search operation) with ip_M;
If step 4 mask_M is not complete 1 mask, illustrate that the prefix back is 0 entirely, need not to continue to process, then add and upgrade Trie node at the corresponding levels, if this Trie node also has child node, then prefix diffusion; At this moment, interpolation is finished, and withdraws from.
If step 5 mask_M is complete 1 mask, and mask_L is 0, explanation is that prefix has arrived the end, and perhaps the back is 0 entirely, need not to continue to process.If prefix has arrived the end, the longest-prefix descriptor that then upgrades Trie node i p_M position is Rn; Otherwise, read ip_M nodes of locations state, if be 1, then prefix diffusion, otherwise the longest-prefix descriptor of renewal Trie node i p_M position is Rn.At this moment, interpolation is finished, and withdraws from.
If step 6 mask_M is complete 1 mask, and mask_L is not 0, the child node that also has at the corresponding levels is described, need to continue to process.Obtaining ip_M nodes of locations state at the corresponding levels, is 0, then needs to create child node; The longest-prefix descriptor that upgrades simultaneously Trie node i p_M position is the child node sequence number; Be 1, need not operation; Be 2 and 3, then need to create child node, the prefix diffusion, the longest-prefix descriptor that upgrades simultaneously Trie node i p_M position is the child node sequence number.
Step 7, jump to next node, repeating step 2.
Shown in Fig. 2 A, add the method for upgrading Trie node at the corresponding levels in the above-mentioned steps 4 and 5 and may further comprise the steps:
Step 1, obtain Trie node at the corresponding levels, IP bit section address ip_M, MASK bit section address mask_M, corresponding route table items Rn;
The number affect_N of step 2, the calculating concrete IP address that mask_M had influence on.The IP address number that affects such as the mask_M of full 0 is 2
M, and the IP address number that complete 1 mask_M has influence on is 2
0=1.
Step 3, from ip_M, circular treatment affect_N IP address, namely ip_M is to ip_M+affect_N;
Step 4, obtaining each pending ip nodes of locations state, is 0, and the longest-prefix descriptor that then will revise this ip position is Rn; Be 1 and 3, then do not process; Be 2, judge that then this mask_M is the longest-prefix in the ip_M network segment, if so, the longest-prefix descriptor of then revising this ip position is Rn, otherwise does not process;
Enough affect_N time of step 5, cycle-index jump to step 6, otherwise repeating step 3;
Step 6, the corresponding relation of this prefix ip_M and route Rn added in the alternate prefix descriptor go.
Shown in Fig. 2 B, add the method for upgrading the Trie of subordinate node in the above-mentioned steps 4,5 and 6 and may further comprise the steps:
Step 1, obtain child node Trie corresponding to father node, prefix ip_M to be spread, and corresponding route table items Rn, and the Prefix Expansion length spread_prefixlen of the accepted father node of this child node.
If the length of the prefix ip_M that step 2 is to be spread is little and the Prefix Expansion length spread_prefixlen of the accepted father node of this node, withdraw from, need not diffusion;
Step 3, obtain the wide K of step of this node, then affected concrete IP address is 2
KIndividual.From 0 to 2
K-1Circular treatment;
Step 4, obtaining each pending ip nodes of locations state, is 0, and the longest-prefix descriptor that then will revise this ip position is Rn; Be 1 and 3, then do not process; Be 2, judge that then this ip_M is the longest-prefix in the ip network segment, if so, the longest-prefix descriptor of then revising this ip position is Rn, otherwise does not process;
Step 5, Rn added in the descriptor for subsequent use of each ip and go;
Step 6, cycle-index enough 2
KInferior, jump to step 7, otherwise repeating step 3;
Step 7, the Prefix Expansion length spread_prefixlen that revises the accepted father node of this node are the length of ip_M.
Referring to shown in Figure 3, quick deletion route prefix method provided by the invention is: delete prefix to be deleted, revise simultaneously the nodind territory of all concrete IP addresses that this prefix affects, make it keep eventually all corresponding route table items values of longest-prefix.The method specifically may further comprise the steps:
Step 1, obtain IP address to be deleted/MASK address, IP/MASK address bit position begins to point to Far Left, and the Trie tree is pointed to root node;
Step 2, obtain this grade Trie node and go on foot wide M, order is obtained M bit value ip_M in the IP address, and order is obtained M bit value mask_M in the MASK address, and the right, MASK address remainder score value is mask_L.
Step 3, in this grade Trie node, directly find corresponding longest-prefix descriptor (array search operation) with ip_M;
If step 4 mask_M is not complete 1 coding, illustrate that the prefix back is 0 entirely, need not to continue to process, then the corresponding list item of ip_M (as shown in Figure 3A) in the backup sheet of deletion renewal Trie node at the corresponding levels; If node at the corresponding levels has child node, then oppositely prefix diffusion (shown in Fig. 3 B);
If step 5 mask_M is complete 1 mask, and mask_L is 0, explanation is that prefix has arrived the end, and perhaps the back is 0 entirely.Reading ip_M nodes of locations state, is 1, then oppositely prefix diffusion (shown in Fig. 3 B); Be 3, then delete the corresponding list item of ip_M (as shown in Figure 3A) in the prefix table that upgrades Trie node at the corresponding levels; Being 0 and 2, is non-existent situation, deletes unsuccessfully, returns;
If step 6 mask_M is complete 1 mask, and mask_L is not 0, the child node that also has at the corresponding levels is described.Read the prefix descriptor, if prefix descriptor index territory is invalid, illustrate that prefix to be deleted does not exist, delete unsuccessfully, return;
Step 7, obtain child node, jump to next stage Trie node, repeating step 2.
Shown in Fig. 3 A, Trie node at the corresponding levels is upgraded in deletion in above-mentioned steps 4 and the step 5, if prefix to be deleted is complete 1, then delete the corresponding list item of ip_M in the prefix table, seeking simultaneously a prefix the longest from descriptor for subsequent use is filled in the prefix table, if there has not been any list item in backing sheet, then prefix table will become invalidly, and its index territory is-1.If prefix to be deleted is not complete 1, the corresponding list item of ip_M in the deletion backing sheet needs to detect the whether longest-prefix of all concrete ip that ip_M affects of this alternate prefix simultaneously.Its processing method is specific as follows:
Step 1, obtain Trie node at the corresponding levels, IP bit section address ip_M to be deleted, MASK bit section address mask_M;
The number affect_N of step 2, the calculating concrete IP address that mask_M had influence on;
Step 3, from ip_M, circular treatment affect_N IP address, namely ip_M is to ip_M+affect_N;
Step 4, obtain each pending ip nodes of locations state, be 0,1,3 and do not process; Be that 2 needs are processed, because this mask_M may appear at the ip position in the prefix table descriptor.Judge that mask_M is the longest-prefix of ip position in this node prefix table, if so, then again be longest-prefix of ip searching in the backing sheet descriptor, the ip that is filled in the prefix descriptor is the position, if nothing, it is invalid that the ip position is made as; If not, then do not process;
Enough affect_N time of step 5, cycle-index jump to step 6, otherwise repeating step 3;
Step 6, in descriptor for subsequent use deletion ip_M corresponding route table items.
The reverse process of prefix diffusion when the reverse prefix diffusion in above-mentioned steps step 4 and the step 5 is this operation.If the father node of a child node is deleted, then need simultaneously to delete the prefix diffusion of this father node in byte point.Moreover, father node also needs longest-prefix remaining in its backing sheet is spread to child node.Whole process with referring to shown in Fig. 2 B, repeat no more here.
Back tracking operation when also comprising deletion in the delet method provided by the invention, in delete procedure, if success found prefix to be deleted, and in most end one-level Trie node with the final stage prefix bits from the prefix table of Trie or for subsequent use after the deletion, and do not mean that end.This moment is further comprising the steps of:
Step 1, Trie tree pointer point to afterbody Trie node;
If this grade of step 2 Trie node has not comprised any one prefix information, then directly this knot removal is fallen; If only remain next prefix information, then this prefix information must be from the father node diffusion, with the position that this diffusion prefix can be write the prefix descriptor of father node, then deletes this node;
Step 3, Trie tree pointer point to the father node of present node, if father node is empty, explanation is the Trie root node, withdraws from.Otherwise carry out next step;
If this node of step 4 is surplus next prefix only, be that ip prefix to be deleted is corresponding to the prefix bits section of this section Trie node so certainly.
Method of operation is with (2); Repeat (3). by upper, the operation of deletion prefix is very similar to increasing the prefix operating process.
Further said method is described below in conjunction with object lesson:
Example: realize the IPV4 routing table based on 256 Trie of branch tree
1, step-length be 8 Multi-branch Trie Tree of (namely 256) such as adopt to realize the quick renewal of IPV4 routing table prefix and search in the example.
2, data structure adopts described in the above-mentioned table 1-table 3.
3, adding procedure:
According to the implementation method of above-mentioned interpolation route prefix, to add following route table items as example:
The route table items prefix |
The route table items index |
192.168.1.1/0 be 0.0.0.0 |
N0 |
192.168.1.1/1 be 128.0.0.0 |
N1 |
...... |
...... |
192.168.1.1/10 be 192.128.0.0 |
Na |
192.168.1.1/11 be 192.160.0.0 |
Nb |
...... |
...... |
192.168.1.1/24 be 192.168.1.0 |
N18 |
...... |
...... |
192.168.1.1/31 be 192.168.1.0 |
N1f |
192.168.1.1/32 be 192.168.1.1 |
N20 |
Table 4
Routing table memory map after the interpolation is as shown in table 4:
Wherein, taken altogether 4 Tire node: node1-node4, left side one row of each node have represented the part alternate prefix descriptor of this node, and right side one row have represented the part longest-prefix descriptor of this node.In the longest-prefix descriptor, arrow represents to point to next node, and data value then represents to point to concrete route table items.
4, search procedure
In table 5, carry out search operation:
(1) if purpose ip is 191.2.2.2, then can be in node1 to 0xbf(namely 191) can to find route be N1 in the position;
(2) if purpose ip is 192.167.2.2, then can in node1, search 0xc0(namely 192) position points to node2, at the 0xa7(of node2 namely 167) can to search route be N8 in the position;
(3) if purpose ip is 192.168.2.2, can find route in 2 positions of node 3 is N10;
(4) if purpose ip is 192.168.1.2, can search route in 2 positions of node4 is N18;
(5) if purpose ip is 192.168.1.1, can find route in 1 position of node4 is N20;
Above-mentioned lookup result is correct (satisfying the longest-prefix principle), and speed is very fast!
Below, to search (3) as example, purpose ip to be found is that the search procedure of 192.168.2.2 is:
(1) Bit String of 192.168.2.2 is that the whenever wide step by step of 11,000,000 10,101,000 00,000,010 00000010, Trie tree node is 8.
(2) getting front 8 bits of purpose ip, is 11000000, namely 0xc0. in the prefix descriptor of Trie root node node1 take 0xc0 as index, search nodind[0xc0], obtaining the index territory is 2, points to child node, Trie tree sensing index is 2 child node, i.e. node2;
(3) continuing to get 8 bits in purpose ip, is 10101000, namely in the prefix descriptor of 0xa0. in node2 take 0xa0 as index, search nodind[0xa0], obtaining the index territory is 3, points to child node, Trie tree sensing index is 3 child node, i.e. node3;
(4) continuing to get 8 bits at purpose ip, is 00000010, namely in the prefix descriptor of 0x02. in node3 take 0x02 as index, search nodind[0x02], obtaining the index territory is N10, points to route table items;
(5) search and finish, the route table items that obtains 192.168.2.2 is N10, and its longest-prefix is 192.168.1.1/16, i.e. 192.168.0.0.
Table 5
5, delete procedure is as follows: in the table 4 added finish after routing table as example, as delete 192.168.1.1/0 (being 0.0.0.0), then the routing table memory-mapped is attempted to change, and is as shown in table 6, behind the deletion 192.168.1.1/0 (being 0.0.0.0), N0 has not closely existed in node1.This moment, the 0x00-0x80 position of longest-prefix descriptor became-1, and expression is without route table items; As delete 192.168.1.1/24 (being 192.168.1.0)-192.168.1.1/32 (being 192.168.1.1), namely delete prefix length greater than 24 route table items, then routing table memory map.
Table 6
As shown in table 7, deletion is greater than after 24 the prefix, and node4 has not existed, and route table items has directly been pointed in 1 position of node3, and no longer points to child node.If be 192.168.1.1 searching purpose ip this moment, can find route in 1 position of node3 is N18, rather than original N20.
Table 7
Implement the concrete comparative illustration of beneficial effect of the present invention as follows:
1, memory consumption: with other common similar approach relatively, the memory consumption situation is referring to table 8:
Table 8
Memory size depends on two parts: the step in (1) each step is wide; (2) for the data width of storing prefix index and down hop index, as require total number below 60,000,16 data width (is used short int type, 16 bit widths), require more than 60,000 to millions, then need the data width more than 24 (to use the int type, 32 bit widths).The internal memory that the latter uses is the former 2 times.Wherein go on foot wide greatlyr, seek rate is just faster, and memory consumption is just larger; Otherwise.Therefore must compromise to some extent.The below analyzes the situation of several practicalities take IPV4 as example.A wide Trie node required memory for K of step is 2
K+1* 2byte. or 2
K+1* 4byte
Table 9
Can find out, adopt bifurcated Trie tree, it is many that internal memory expends, but at nowadays 32, especially in the 64 bit CPU environment (such as multi-core network processor), above-mentioned internal memory can be accepted fully, and seek rate is very fast.
2, the 1-5 step finishes in the situation, and each step is exactly an addressing and numerical value comparison operation, without other any extra process.Its processing speed is only second to the parallel search of hardware.
3, renewal speed is fast: update time mainly by the time of searching and more new data two parts form.The time of searching is very fast among the present invention, and more new data only relates to those concrete IP addresses that the final stage of prefix to be updated has influence in corresponding Trie node.The step of this Trie node is wide, then affects concrete IP address just many, go on foot wide narrowlyer, then affects concrete IP address just less.But operating procedure is limited generally, and opereating specification is concentrated, and does not affect the operation of other Trie node, does not need outside assisting, and therefore more new data rate is still very fast.Concrete operations number of times and node go on foot wide K, and prefix length L is relevant.Go on foot wide K also little, prefix length L is larger, and then number of operations is fewer.In a word, the concrete operations number of times is 1-2
K, most cases.
4, utilization benefit: available pure software realization, efficient is high, and need not other subsystem supports, and independence is good.On the multi-core network processor of our company's exploitation, realized the linear forward efficiency of 10G.
Above-described embodiment is the embodiment of one embodiment of the present invention; but embodiments of the present invention are not restricted to the described embodiments; other any do not deviate from change, the modification done under Spirit Essence of the present invention and the principle, substitutes, combination, simplify; all should be the substitute mode of equivalence, be included within protection scope of the present invention.