A kind of method for recovering internal storage that IP searches
The present invention relates to a kind of IP lookup method of on network router, realizing, relate in particular to the method for recovering internal storage of IP in searching.
The present invention carries out on the basis of " expanding the prefix method " (hereinafter to be referred as the CPE method), the CPE method is a kind of fast searching method that is proposed by Srinivasan, the paper name is called " Faster IP Lookups using Controlled Prefix Expansion ", come from proc.ACM sigmetrics ' 98 conf., madison, WI, the 1-11 page or leaf.Method is utilized the time complexity of the thought minimizing method of segmentation compression, makes seek rate increase greatly, according to different configurations, can search between 3~32 steps and finish, and simply introduces the CPE method below.
Since adopting CIDR (CIDR) agreement in 1993, the IP route just comprises two parts<IP prefix, the length of prefix>and, the length range of prefix is between 0~32.For each input bag, IP searches the IP prefix sets that engine need find out coupling, and finds out the prefix of long coupling from the prefix sets of coupling.The indicated address of prefix of long coupling is exactly the address of next jumping of finding out.About CIDR, in detail visible RFC1519 Classless Inter-Domain Routing (CEIR): an AddressAssignment and Aggregation Strategy.V.Fuller, T.Li, J.Yu , ﹠amp; K.Varadhan.September 1993 and RFC1817 CIDR and ClassfulRouting.Y.Rekhter.August 1995.
Rule in the routing table can be expressed as the form of prefix, and the length of prefix changes between 8 and 32, and the IP lookup method is promptly found out the prefix of long coupling, because the diversity of prefix length is a key factor that causes the lookup method time complexity high.For the prefix maximum length is W, (NetBSD is a kind of Unix operating system of standard to NetBSD, this operating system has realized the ICP/IP protocol stack, wherein comprise the realization that IP searches) in the method complexity of binary tree be O (W), (L<W), then the method complexity will be reduced to O (L) if the prefix maximum length is reduced to L.Obviously, the maximum length of minimizing prefix will improve the speed of method.The basic thought of control prefix extending method is to increase the step-length of method by the diversity that reduces prefix length, thereby has reduced the complexity of method, reaches the purpose of searching fast.
Any prefix can be extended for the prefix sets of designated length, as for prefix 10
*, can be extended for length and be 4 prefix sets { 1000
*, 1001
*, 1010
*, 1011
*, by expanding the length of prefix to appointment, length that can the normalization prefix, thus reduced the diversity of prefix length.Expanding the prefix method can be divided into what expanding the normalized prefix length in back, and the length of each grade prefix is the same, just can find other node of this level by array indexing.
Expand prefix tries tree 32 grades of 1 original bit tree boil down to 3 level structures as a result, search number of times and shorten to 3 times, the time complexity of method is O (3).Thereby reach the purpose of searching fast.Suppose P5=0
*, P1=10
*, P2=111
*, P3=11001
*, P4=1
*, P6=1000
*, P7=100000
*, P8=1000000
*, the structure that then typically expands prefix trees as shown in Figure 1.
But in the CPE method, the CPE method is behind route entry of deletion, if there is not other prefix to exist in the node array at route entry place, need to reclaim the memory headroom of node array, if promptly all following prefixes of this node and node are all deleted, then need this node and this all nodes below node are carried out the internal memory recovery.How whether the prefix in the decision node deletes that to finish be a problem, and the CPE method is discussed to this problem, and common way is to carry out traversing operation.Traversing operation will take a large amount of internal memory operation time, and revise when frequent, need a large amount of internal memories, and this occasion at high speed router is unpractical.
Purpose of the present invention is exactly that the internal memory that will solve deletion route entry in the CPE method reclaims problem, reduces the internal memory operation time, reduces taking of internal memory.
In order to realize above purpose, the present invention proposes a kind of method for recovering internal storage, it is characterized in that may further comprise the steps: establish a node counts device for each node array; When inserting in the downstream node array of present node array or present node array and during the deletion prefix, the node counts device is corresponding to add one or subtract one; And when the node counts device is zero, reclaim this node array with and the shared internal memory of downstream node array.
The present invention is specially adapted to the CPE method, but those of ordinary skill in the art can use principle of the present invention in other the method easily.
In addition, method of the present invention can also make simultaneously with other method and be used for further improving the CPE method, for example, can be optimized the CPE method with the LeafPush method earlier, and then use the present invention.Method perhaps of the present invention can be used separately.
From above method as can be seen, when prefix was inserted into a node, the node counts device of the upstream node of this node and this node added one, and when prefix during from a knot removal, the node counts device of the upstream node of this node and this node subtracts one.If the counter of a node is kept to zero, then can delete this node and following node.Reclaim problem with regard to perfect internal memory when having solved knot removal like this.
Below with reference to accompanying drawings the present invention is carried out more detailed description, in the accompanying drawing:
Fig. 1 is the typical structure that expands prefix trees in the CPE method;
Fig. 2 is the insertion flow chart that adopts the prefix of node counts device realization according to the present invention;
Fig. 3 is the deletion flow chart that adopts the prefix of node counts device realization according to the present invention.
The insertion flow chart that adopts the prefix of node counts device realization according to the present invention is described below with reference to Fig. 2.At first node counts device of the present invention is described.In the present invention, the node counts device is preserved the information that prefix was inserted and deleted to each node array, in the present invention, corresponding each node array has a node counts device, for the pairing node node counts of P1 device can be placed on forward and backward and other position of node array.Be placed under the situation of other position, needing the index value between each counter and the corresponding node array.In a preferred embodiment, before the node counts device is placed on the node array.In the present invention, the node counts device is used for writing down the prefix item that inserts and delete, rather than is used for being recorded in the insertion and the deletion number of times of present node.Promptly have only and insert and deletion causes the increase of prefix item or just cause the increase or the minimizing of counter when reducing, if insert and deletion just causes the change of node array and do not cause the increase or the minimizing of prefix item, then the node counts device does not change.In the present invention, insert in the present node array and during the deletion prefix, the node counts device is corresponding to add one and subtract one.Insert and during the deletion prefix in the downstream of present node array array, the node counts device adds one and subtract one accordingly.When insertion of present node array upstream and deletion prefix, the node counts device is constant.When the node counts device is zero, can delete this node, promptly can reclaim the internal memory of node array.
Describe in accordance with a preferred embodiment of the present invention according to Fig. 2 below, insert the operational flowchart of prefix.Flow process is carried out initialization in square frame 201 beginnings to system.Under the situation of Fig. 1, for node 11 is set a counter C11, for node 21 is set counter C21, for node 22 is set counter C22, for node 31 is set counter C31, principle according to counter of the present invention, the initial value of setting each counter is respectively C11=8 (below 8 prefix P1-P8 are arranged), C21=3 (3 prefix P6 being arranged, P7 and P8), C22=2 (two prefix P2 are arranged, and P3) and C31=2 (two prefix P7 and P8 are arranged).It should be noted that here and described initialization, in the reality, do not need each flow process to begin all to need to carry out initialization for the convenience of describing.Only need be in system begin to carry out initialization.The beginning of later on each flow process only needs the result of last time is carried out as initial value.Then, flow process arrives square frame 202.At square frame 202, get the prefix that needs insertion, for example, suppose that the prefix that will insert is P9=1001*.Then, flow process arrives square frame 203, judges this prefix at this and belongs to node 21, so flow process then arrives square frame 204, at this, because node 21 is present nodes, its upstream node is a node 11, so all add 1 for node counts device C21 and C11.Afterwards, flow process is inserted prefix P9 and end at square frame 205.Can insert with the method for the prior art that any those of ordinary skill in the art was familiar with at square frame 205, for example carry out like this: earlier P9 is extended for 10010 with CPE
*With 10011
*, then find 10010 and 10011 position, and write P9.
In other cases, increase the increase that prefix can cause node, at this moment, needing to distribute new node also is that new node increases the node counts device.For example, if the prefix that obtains adding at square frame 202 is 010
*, then will judge prefix and can not put into any existing node at square frame 203, thus newly-built for example node 23, and for this node distribute a counter C23 and for this counter setting initial value be 0.After arriving square frame 204, all add 1 for counter C23 and C11.Inserting this prefix and flow process at last finishes.In a preferred embodiment, the internal memory length scale of distributing for a node is 2
n, wherein n is node place other length of level.For example under the situation of Fig. 1, if distribute one at partial node, the internal memory length of then being distributed is 2
3=8, because partial length is 5-2=3.In like manner, the node size of the third level of distribution is 2
7-5=4.
The deletion flow chart that adopts the prefix of node counts device realization according to the present invention is described below with reference to Fig. 3.
The flow process of Fig. 3 is then got the prefix that needs deletion at square frame 302 in square frame 301 beginning, and for example, needing the prefix of deletion is p8, then judges P8 and is the node C31 the third level, and delete this prefix P8.Then the counter C31 of this node is subtracted one at square frame 303, judging this counter at square frame 304 is not 0, then arrive square frame 306 and judge whether to arrive afterbody node counts device, the result who judges this moment finds partial node 21 also the counter C21 of this node to be subtracted 1 for not so flow process proceeds to square frame 303.Then, this flow process is again by square frame 306 and 303.In current cyclic process, arrive zero without any a node counts device, so need not delete any one node.If then also want deletion of node P7, then the counter C31 of node 31 becomes 0 in this process, so will discharge internal memory in the array of square frame 305 deletion of node 31.
In the embodiments of figure 3, flow process is to subtract 1 back to each interdependent node counter just to judge that then whether it is 0, and then handle accordingly at once.In other embodiments, flow process can be changed into all counters that will be correlated with earlier and all subtract 1, node counts device from minimum one-level begins to judge whether counter is 0 then, if running into first is not 0 just can withdraw from circulation, because be not that senior node counts device can not be 0 under 0 the situation at rudimentary node counts device.For example under the situation of Fig. 1, be not that counter C21 and C11 do not affirm can be 0, so can directly withdraw from circulation under 0 the situation at counter C31.