Background technology
In the prior art, the IP in the network router searches common use control prefix and expands CPE (control prefix expansion) method.The CPE method is a kind of fast searching method that is proposed by Srinivasan, the paper name is called " Faster IP Lookups usingControlled Prefix Expansion " and (comes from proc.ACM sigmetrics ' 98conf., madison, WI, the 1-11 page or leaf), this method is utilized the time complexity of the thought minimizing method of segmentation compression, makes seek rate increase greatly, according to different configurations, can between 3~32 steps, search and finish.Simply introduce the CPE method below.
Since adopting CIDR (CIDR agreement) agreement in 1993, the IP route just comprises two parts<IP prefix, the length of prefix 〉, 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 the detailed content of CIDR as seen: RFC1519 Classless Inter-Domain Routing (CIDR): anAddress Assinment and Aggregation Strategy.V.Fuller, T.Li, J.Yu , ﹠amp; K.Varadhan.September 1993. and RFC1817 CIDR stabilize Classful Routing.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 (a kind of unix operating system of standard, 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 original 1-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, when carrying out the route modification, need judge the length of original prefix and modification prefix by auxiliary 1-bit tree as shown in Figure 2, when inserting a prefix item, if original prefix length greater than the prefix length that inserts, this prefix can not cover original prefix, if original prefix length less than existing prefix length, then needs to cover this prefix.
And auxiliary 1-bit tree needs committed memory, when 40,000 route entries, approximately need take the space of 1.5M.In addition, carry out needing complicated traversal and read-write operation when route is revised in the mode that adopts auxiliary 1-bit tree, thereby need a large amount of memory bandwidth of waste.
Embodiment
Before describing embodiments of the invention, the difference of two terms among the present invention once is described earlier.One is rank length, the length of a level.In this manual, rank length refers to first bit of this grade and the distance between last bit, and the length of level is the distance between the beginning bit of last bit of this grade and the first order.
Fig. 2 is the auxiliary 1-bit tree that comprises 6 prefixes.With reference to Fig. 2, the prefix in (1)~(6) the expression 1-bit tree.For the convenience that illustrates, suppose that the insertion sequence of prefix is consistent with sequence number (1)~(6).In the auxiliary 1-bit tree of Fig. 2, the node with prefix represents do not have the node of prefix to represent with hollow dots with solid dot.The left sibling of 1-bit tree represents 0, and right node represents 1, for prefix (3), represents that with the 1-bit tree its prefix is 11001
*1-bit tree among Fig. 2 is divided into 2 grades, and wherein rank 1 comprises 2 bits, and rank 2 comprises 3 bits.Principle of the present invention for convenience of explanation, we carry out corresponding with auxiliary 1-bit the classification among the present invention.In a preferred embodiment of the invention, classification refers to the classification in the CPE method, and hypothesis is divided into 2 grades with prefix in Fig. 2.Can find out with reference to Fig. 2, the prefix of the prefix in the rank 1 in always can not cover grade 2, on the contrary the prefix of the prefix in the rank 2 in always can cover grade 1 is because the length of the prefix in the rank 1 is shorter than the length of the prefix of rank 2.What will solve like this, in the present invention is exactly the covering relation of the prefix in the same rank of interpretation how.Notice that principle of the present invention for convenience of explanation and quoted auxiliary 1-bit tree just here realizes that in practice the present invention is need be by the 1-bit tree.
Fig. 3 is a kind of implementation-network address mask level code according to the prefix mask of preferred implementation of the present invention.In an embodiment of the present invention, the expression mode of prefix mask is the length of prefix, for example, for prefix (3), comprises 5 bits altogether, and its length is 5, so its prefix mask value of representing with length is 5.In like manner, the prefix mask of prefix (6) is 3.Because the length of prefix (6) is shorter than the length of prefix (3), so when inserting (6) this node, just can not cover the unit at downstream site (3) place of (6).In a word, if the length of the prefix of inserting than original length, then covers; Than original weak point or equally long, then do not cover.
In another embodiment of the present invention, represent prefix mask with the relative length of prefix.The relative length of prefix is the length of prefix in current rank, just prefix length is deducted other length of upper level, and for example, for prefix (6), its relative length in rank 2 is 3-2=1; The relative length of prefix (3) in rank 2 is 5-2=3, and the length that can draw prefix (6) equally is shorter than the length of prefix (3).As seen, the relative length of prefix does not change the relativeness between the prefix length.Adopt the relative length of prefix, can reduce the prefix mask occupation space, thereby reach the purpose that reduces EMS memory occupation.One of a same embodiment is if the relative length of the prefix of inserting than original length or equally long, then covers; Weak point than original does not then cover.
Prefix in the router uses " network address " and " network address mask " to represent usually, if calculate the length of prefix, a kind of method of calculating prefix length is that the network address mask to prefix shifts left, whenever move then once a counter is added 1, finish zero the time when arriving first.Value in the counter is exactly the length of prefix.The relative length of prefix also can calculate with similar way.Those skilled in the art are easy to design the additive method of computational length.
In other preferred embodiment of the present invention, represent prefix mask by the data of intercepting certain-length from the mask of the network address, and judge covering relation by the size that compares prefix mask.
Noted earlier as this specification, only need in same rank, judge the covering relation of prefix, so as long as the length that intercepts can be more than or equal to the length of prefix at appropriate level.Therefore, the longest a kind of form is the length of the whole network address of intercepting mask, promptly directly represents prefix mask with network address mask.Then by will when judging covering relation, the size to prefix mask comparing.For example, according to this method, the prefix mask of prefix (3) is 11111000 ..., the prefix mask of prefix (6) is 111000, obviously the prefix mask of prefix (6) is less than the prefix mask of prefix (3), so can not cover.But obviously oversize owing to directly representing with network address mask, committed memory is too many, so in other interception way, we carry out brachymemma to network address mask.A kind of brachymemma mode is to adopt the fixedly mode of prefix length, and promptly the length of all prefix mask is the same, according to the principle of front, obviously needs only the length of intercepting more than or equal to the longest rank length.In a preferred embodiment, select the length of prefix mask to equal the longest other length of level.Another kind of mode is to adopt the mode of elongated prefix length, be prefix mask length to the prefix of different stage length be different, according to principle of the present invention, as long as the length of prefix mask is more than or equal to the length of this prefix at appropriate level.In the present invention, select the length of prefix mask to equal the length of prefix, and claim the prefix mask of this form to be " network address mask level code " at appropriate level.For example, for the prefix among Fig. 1 (3), its prefix value is 11001
*, its network address mask is 11111000 ..., prefix (3) on rank 2, can the intercept network address mask in rank 2 pairing values as prefix mask, promptly " 111 " are as prefix mask.As shown in Figure 3.Equally, the prefix mask that can draw prefix (6) is " 100 ".Like this, size that just can be by " 111 " and " 100 " relatively judge covering relation.100 is obviously little than 111, so prefix (6) can not cover prefix (3).
Above execution mode in, it is all very familiar how the prefix mask of representing about length and relative length generates those skilled in the art, just is not described in detail here.Directly with network address mask represent also very simple, the preferred implementation when generating prefix mask with network address mask once is described below.
First kind of mode is to produce by moving to left earlier afterwards to move to right.Suppose that prefix is divided into the L level, take out prefix in other length of M level, then can move to left earlier, the length that moves to left moves to right then for the length of level M-1, and the length that moves to right deducts the rank length of rank M for the length of level L.For example, L is 3, and length overall is 8, and rank length is respectively 2,3,3 (length of respective stages is 2,5,8).The network address mask of supposing prefix is 1111000, and then the procurement process of prefix mask is as follows:
| Rank 1 | Rank 2 | Rank 3 |
Network address mask | 11 | 111 | 000 |
Move to left after 2 | 11 100 000 00 000 111 |
Move to right 5 |
Shifting function is obviously relatively taken time, and can carry out the method for " position with " dextroposition then for this reason by using with a mask value and carry out.Can be earlier the different different mask values of level definition, for rank M, the constituting of mask value F (M) " position of corresponding appropriate level is 1, and all the other positions are 0 ".Like this, in as above example, F (1)=11000000, F (2)=00111000, F (3)=00000111.
The network address mask of prefix and other mask value of level can be obtained prefix mask with moving to right then like this, the figure place that moves to right is that the length of afterbody deducts the length when prime.For example, computational process is as follows:
| Rank 1 | Rank 2 | Rank 3 |
Network address mask | 11 | 111 | 000 |
Mask value | 00 111 000 00 111 000 |
Xiang Yuhou |
After the displacement | 00 000 111 |
The generating mode of network address mask level code also has a lot, basic principle with above-described be the same.For example, also adding " 1 " in front forms prefix mask can also directly to get the value of prefix in appropriate level.For example, under the situation of the prefix 3 in Fig. 2, its prefix mask will be " 1+001 "=" 1001 ".For prefix 6, prefix mask will be " 10 ".
Fig. 4 is the insertion operating process of prefix overlay code.After the various prefix mask of above introduction have been arranged, when carrying out the prefix modification, can can remove original data structure " auxiliary 1-bit tree " like this by judging that prefix mask determines whether carrying out the overlapping operation of prefix, and the operation of complicated judgement covering.
When sewing mask before use, need increase the space of preserving prefix mask in the data structure of CPE, the data structure of CPE is based on node.Each node is represented a route entry, and each node all needs to increase the space of preserving prefix mask.When actual treatment, can put the data structure of node and prefix mask together, also can separate, when separate processes, need the data structure of node and prefix mask to keep index relative one to one.In a preferred embodiment of the invention, the data structure of prefix mask and node is put together.And, in the following description, suppose that prefix mask is a network address mask level code.
The flow process of Fig. 4 arrives the prefix mask that square frame 402 calculates the prefix that will insert from square frame 401.The method of calculating prefix mask comprises length, relative length and network address mask level code etc. as mentioned above.If for example the prefix that will insert in Fig. 1 is P9=1111
*, then the prefix mask of representing with network address mask level code is " 110 ".Flow process proceeds to square frame 403 after calculating prefix mask, searches the starting position that prefix is inserted.According to method well-known to those skilled in the art, the starting position of finding the insertion of prefix is " 110 " among the node S.Then flow process arrives square frame 404, calculates prefix and inserts end position.The end position of prefix calculates like this, and promptly the starting position of prefix adds 2
K, wherein K is the residue length of prefix in this rank, because the residue length of prefix P9 in rank 2 is 1, so K=1, then end position equals 110+001=111.Then flow process arrival square frame 405 begins expansion prefix node is inserted in the prefix circulation.The beginning flow process of circulation obviously can not finish, so flow process arrives the prefix mask that square frame 406 is got present node, and when square frame 407, the mask of the prefix P9 that will the insert prefix mask with the present node of being got is compared, present node is P2, its prefix mask is " 100 ", because 110 greater than 100, so P2 is covered by P9.Then flow process arrives square frame 408 and inserts the expansion prefix, promptly writes P9.Then, the prefix mask of flow process arrival square frame 409 modification present nodes is " 110 ".In like manner, at circulation time next time the P2 of 111 positions is replaced with P9, and the prefix mask of present node is revised as 110.Arrive circulation time for the third time, judge circulation at square frame 405 and finish, then flow process arrival square frame 410 withdraws from.In a word, when judging the covering relation of prefix,, then can directly insert if original node is empty (being that prefix mask is 000); If originally the prefix mask value of node is littler or equal than present, then directly cover; If node mask value originally is bigger than present, then keep original node.
In addition, those skilled in the art can understand, and the starting position and the end position that insert prefix can form when carrying out the prefix expansion in practice naturally.For example prefix P9 is 11110 after expanding
*With 11111
*So, can obtain beginning and end position naturally and be respectively 110 and 111.Certainly, those skilled in the art also can use other method that obtains beginning and end position.
As can be seen, the insertion of prefix operation is very simple, only need judge the size of prefix mask, just can determine whether can insert, and has avoided the situation that original prefix is inserted needs to pass through the 1-bit tree from the prefix insertion flow chart of Fig. 4.By prefix mask, significantly reduced the computation complexity that prefix is inserted.
Fig. 5 is the flow chart of route deletion action according to a preferred embodiment of the invention.
Equally can be by judging that prefix mask determine whether deleting present node during the deletion of prefix, but after deleting present node, need back to suck and find an adjacent prefix, be filled into the node place of deletion.This adjacent prefix can't obtain by original structure, also can't obtain this prefix in the prefix mask.This is a key issue of deletion action.
In router, a Routing Protocol processing unit is often arranged, the Routing Protocol processing unit produces the prefix that needs modification, and the Routing Protocol processing unit is often independent with forward processing unit.Keep a structure that is similar to the 1-bit tree in the Routing Protocol processing unit, so the Routing Protocol processing unit is can return to suck to obtain an adjacent prefix when generating the prefix that needs modification.So use for reference this structure here, when initiating the prefix deletion action, need be simultaneously with the structure that goes up adjacent prefix.The data structure of deletion prefix is as follows:
struct DEL_ROUTE
{
Prefix cur_prefix;
Prefix up_prefix;
};
In actual router design, also can adopt a 1-bit tree to produce this DEL_R0UTE structure, the DEL_ROUTE structure can be at master control borad, interface board, network management platforms etc. are local to be generated, and also can adopt other the class 1-bit tree or the mode of the data structure of quasi-protocol processing unit to produce.
Prefix is the data structure of prefix in the DEL_ROUTE structure, comprises the value of prefix, the value of network address mask, and routing iinformation.Cur_prefix represents the prefix of needs deletion, and up_prefix needs a last adjacent prefix of filling after being deletion cur_prefix.For example, 11
*A last adjacent prefix be 1
*, 1110
*A last adjacent prefix be 111
*This structure is that the Routing Protocol processing unit produces when producing a deletion route messages, this structure has been arranged after, in conjunction with the notion of prefix mask, can finish the deletion action of route easily, the flow chart of route deletion action as shown in Figure 5.
The flow process of Fig. 5 is from square frame 501.Then calculate the prefix mask of the prefix that will delete at square frame 502.That suppose will to delete now is the P9 that inserts in the description at Fig. 4 in the above, and the prefix mask of P9 is " 110 ".Information from the data structure DEL_ROUTE that the comes up_prefix of prefix P9 as can be known is P2.So flow process calculates the prefix of up_prefix in square frame 503 be " 100 ".Then, flow process is calculated prefix deletion original position at square frame 504.With the same principle of describing among Fig. 4, calculating original position is 110.In like manner, calculating end position at square frame 505 is 111.Then arrive square frame 506 and judge whether to enter loop body.Obviously, current judged result is not for withdrawing from circulation, so follow the prefix mask of getting present node at square frame 507.Take out and be " 110 ".Compare two prefix mask at square frame 508 then, the result is identical, so deletion.Then change P9 into P2, and then change the prefix mask of present node into " 100 " at square frame 510 at square frame 509.At square frame 508, if find to delete present node through judging, then flow process is got back to square frame 506.If finish through judging circulation, then withdraw from the circulation back and finish at square frame 511 at square frame 506.
From prefix deletion flow chart as can be seen, after increasing the DEL_ROUTE structure, the deletion action of prefix also is and simply, and both prefix mask values relatively wherein refer to the size of the prefix mask value of the prefix mask value of relatively deleting prefix and present node prefix.If the prefix mask value of deletion prefix will equal the prefix mask value of present node, then delete present node.Otherwise do not delete present node.If the deletion present node is inserted into present node to a last adjacent prefix (up_prefix) in fact exactly, and the prefix mask of modification present node is the prefix mask of up_prefix.If up_prefix is empty, then putting present node and prefix mask is 0.
When deletion prefix node, need to obtain the value of a last adjacent prefix, here use the result of Routing Protocol processing unit, when the Routing Protocol processing unit generates prefix, produce the value of an adjacent prefix, when deletion of node, adopt the structure of DEL_ROUTE, solved the problem of deletion of node, made the knot removal operation same simple, can satisfy the processing requirements of high speed router with node insertion operation.
Top reference preferred implementation of the present invention has been described the present invention, obviously, in disclosed principle of the present invention and essential scope, can do various replacements, conversion or equivalence to the disclosed embodiments.In addition, the present invention can use jointly with other method of saving internal memory, and for example leaf moves down (LeafPush) technology, and this technology mainly is that leaf node is moved down into root node, accelerates searching speed.