Method for searching route table
Technical field
The present invention relates to network service, particularly routing table finding method.
Background technology
The life that develops rapidly to us of Internet has brought huge variation, and the thing followed is increasing rapidly of network traffics.Router is the exemplary apparatus that grouping is transmitted to data in network, and routing table is its basis of transmitting packet.When transmitting packet, router need be searched the route table items that can mate according to purpose IP address, thereby definite correct next jumped out mouth.In IP route table, each list item all comprises routing address, and routing address is called prefix again, generally is expressed as P/L, and P represents prefix addresses, i.e. the main frame or the network address; L represents prefix length, i.e. the mask-length of this main frame or the network address.The search procedure of route table items is also referred to as the longest matched and searched process, promptly earlier with destination address to be found, carry out the logical AND operation with the bit of prefix length in the route table items, again prefix addresses in its result and this route table items is mated, select in all occurrences prefix length the longest that.
In the prior art, the Radix of BSD tree is searched because of it efficiently becomes routing table institutional framework relatively more commonly used at present.Generally be purpose IP address at present, utilize the longest prefix match principle, select the most accurate coupling route according to be found to searching of Radix tree route table items.But, in some applications, for example rely on the most accurate coupling route table items and transmitting fast of setting up when this a certain route table items deletion, cause the consumption of cpu resource for fear of the mode that adopts newly-increased quick forwarding-table item, in this time, need in routing table, search alternative current other route that is complementary of waiting to delete the P/L list item that is relied on of transmitting fast.And can not support searching of this kind application to Radix tree route table items in the prior art.Search particulars about BSD radix tree and see " TCP/IP Illustrated Volume 2:TheImplementation ", 18 chapters---Radix sets routing table.
Summary of the invention
Technical problem to be solved by this invention just provides a kind of method for searching route table that can be used for transmitting fast renewal, searches the inapplicable problem of principle to solve existing Radix tree, thereby avoids unnecessary system resource waste.
The present invention solve the technical problem, and the technical scheme of employing is that method for searching route table may further comprise the steps:
A. determine the prefix addresses and the prefix length of routing address to be found;
B. when searching routing table, the setting matching condition is: one, the prefix addresses of the prefix addresses of route table items and routing address to be found is complementary; Two, the prefix length of the prefix length of route table items and routing address to be found is complementary; Meet above-mentioned two route table items that are coupling.
Further be, among the step b, the prefix length of described route table items and the prefix length of routing address to be found are complementary and are meant, in the route table items that satisfies above-mentioned matching condition one, its prefix length is the longest, and is equal to or less than the route table items of the prefix length of routing address to be found.
Concrete is that described step b comprises:
B1. according to the prefix addresses of routing address to be found, search flow process according to the Radix tree, begin to find first leaf node from root node, whether prefix addresses and this leaf node prefix addresses of judging routing address to be found mate, if coupling, then enter step b2, otherwise enter step b4;
Whether b2. more described leaf node prefix length is less than or equal to the prefix length of routing address to be found, if, then determine the route table items of this leaf node for coupling, enter step b5; Otherwise enter step b3;
B3. the leaf node that judges whether to exist the prefix addresses of other and routing address to be found to be complementary; If have, then one by one with the prefix length of these leaf nodes, compare with the prefix length of routing address to be found, determine prefix length the leaf node of the prefix length of approaching routing address to be found be the route table items that is complementary, enter step b5; If no, enter step b4;
B4. according to the longest prefix match algorithm retrospective search that makes progress, determine that the prefix addresses with routing address to be found is complementary, prefix length is the coupling route table items less than first leaf node of the prefix length of routing address to be found;
B5. the route table items of output coupling is searched end.
Further be, among the step b3, the described prefix length leaf node of the prefix length of approaching routing address to be found is meant, the prefix length of this leaf node, the longest in the leaf node that the prefix addresses of all and routing address to be found is complementary, and be equal to or less than the prefix length of routing address to be found.
The invention has the beneficial effects as follows, according to the prefix addresses and the prefix length of user's appointment, search the route table items that all mates with its prefix addresses and prefix length, can solve in some practical application, the Radix tree is searched the inapplicable problem of principle, has enlarged the range of application of BSD Radix tree.
Description of drawings
Fig. 1 is a program flow diagram of the present invention.
Embodiment
Technical scheme of the present invention according to the prefix addresses and the prefix length of routing address to be found, is searched the route table items of Satisfying Matching Conditions, searches flow process and is:
1, at first uses the prefix addresses of routing address to be found after beginning to search,, begin to search from the Radix root node according to Radix tree institutional framework.Use test position decision coupling branch in search procedure, test position is included on the Radix tree in the interior nodes, the prefix addresses of routing address to be found is 0 to walk left subtree with the test bit test, and the prefix addresses of routing address to be found and test bit test are 1 to walk right subtree.Finally can find unique leaf node (route table items) according to such rule;
Find after the route table items, whether prefix addresses and this route table items prefix addresses of determining routing address to be found mate: with the prefix addresses of routing address to be found, carry out the logical AND operation with this route table items prefix length, if the result who obtains is identical with this route table items prefix addresses, representative and this route table items coupling, on the contrary then expression does not match.If the match is successful for prefix addresses, need also to determine whether prefix length satisfies condition:
If I. this route table items prefix length is less than or equal to the prefix length of routing address to be found, then find the coupling route, the output lookup result is searched end.
II. otherwise, also need to judge whether to exist the leaf node of the prefix addresses coupling of other and routing address to be found, these leaf nodes are called as repeat key, their difference is the prefix length difference.If have such leaf node then one by one their prefix length and the prefix length of routing address to be found compared, find that wherein prefix length is the longest, and its prefix length is less than or equal to the leaf node of the prefix length of routing address to be found, as the route table items output that is complementary, search end.
So just need be if the route table items prefix addresses does not match or prefix length does not match according to the longest prefix match algorithm retrospective search that makes progress.
In the trace-back process, find that there is the mask tabulation in interior nodes, the subtree of this interior nodes is described so, might have the route table items that mates with the prefix addresses of routing address to be found.According to such hypothesis, the prefix addresses of routing address to be found and the mask address in the mask tabulation are carried out the logical AND operation, the result who obtains according to Radix tree traversal method compare test position successively, finally can obtain a leaf node again.Determine the prefix addresses of leaf node, whether mate, and the leaf node prefix length is less than or equal to the prefix length of routing address to be found, return the coupling route, search end if two conditions all satisfy with the prefix addresses of routing address to be found; Otherwise continue to use the next mask in the mask tabulation to mate.If the mask address of all mask tabulations does not satisfy condition, continue upwards to recall till root node, finish to search.
Embodiment
At present,, quick forwarding module is set all in forwarding units such as router generally, to improve the message forwarding rate in order to guarantee forward efficiency.Because if new transmit fast to set up need a period of time, during the packet that needs to transmit have only the upper strata CPU of submission to handle, the consumption of system resource is bigger.Therefore transmit fast by initiatively upgrading, saved the time, avoided unnecessary resource waste.After certain the bar route that is relied in the forwarding cache of quick forwarding module is deleted, can be routed to other one by what direct renewal forwarding cache was relied on, thus just need in routing table, search the route table items that can substitute this route,
Suppose to have 3 routes, they comprise successively:
1.0.0.0/8
1.2.0.0/16
1.2.3.0/24
If deletion 1.2.3.0/24 route in the routing table, forwarding module then needs to search routing table fast, after determining that this route table items is deleted, also have any bar route table items to use in the routing table, and will rely on the packet of route 1.2.3.0/24 originally, transmit according to the route table items that newly finds.The route table items that newly finds this time should be to substitute original route 1.2.3.0/24, just searches to be complementary with this prefix addresses 1.2.3.0, and length is less than the route table items of this prefix length 24.
According to lookup method provided by the invention, here it is 1.2.3.0 that prefix addresses is searched in our setting, prefix length is 23, because the prefix length of former prefix addresses is 24, in matching process, route 1.2.3.0/24 can not mate so, so route to be found can be referred to as time accurate route table items, by specified prefix length 23, have only mask-length could mate smaller or equal to 23 route table items.We search prefix addresses and 1.2.3.0 coupling in routing table, prefix length is equal to or less than 23 route table items.Example above using, we import keyword 1.2.3.0/23 when searching, the mask-length here is 23, so in matching process, route 1.2.3.0/24 can not mate, because what search is not the most accurate route table items, could mate so have only mask-length to be equal to or less than 23 route table items.Search the matched rule that prefix length is equal to or less than the route table items of 23 prefix addresses so utilize, will match route 1.2.0.0/16, so quick forwarding module can carry out corresponding forwarding work fast according to lookup result.Program circuit of the present invention is seen Fig. 1.
The renewal that purposes of the present invention is not limited to transmit fast also has some other to use, and as when new route table items of interpolation is more accurate than old list item, needs more the old and new's forwarding cache.Need to find time accurate route table items of forwarding cache dependence so, then they are updated to more accurate route table items and get on.If transmit by traveling through fast, upgrade the forwarding cache that relies on old route table items, then such operating efficiency is lower, transmits the route table items that is relied on fast by direct renewal, and then efficient is higher.Time accurate route that so just need find forwarding cache to rely in routing table, we can quote the forwarding cache of old road by list item by quick indexing originally according to this route, then they were updated to more accurate route table items and got on.Can improve update efficiency greatly like this.