The IPv6 routing table is searched and method for updating fast
Technical field
The present invention relates to technical field of the computer network, particularly a kind ofly realize quick routing table lookup and method for updating based on the IPv6 address.
Background technology
Method for searching route table is the key technology in the router repeater system, and the height of search efficiency has influenced the forward efficiency of router to a great extent.The basic thought of routing table lookup is that a given address key words need find the longest address prefix that mates this address key words in routing table, carry out follow-up processing according to next jumping port numbers of address prefix.With traditional can only finishing searching of the accurate coupling of keyword compared, the difficulty and the complexity of routing table lookup increase greatly.
At present the method for searching route that conducts a research at the IPv4 router is existing a lot, extensive use comprise two big class lookup methods, be respectively the method set based on trie and based on the binary chop of address prefix length.But along with further popularizing of IPv6 network, these method for searching route table have all run into limitation separately.
Lookup method based on trie tree is such, and trie is a kind of tree structure, and it utilizes the value of each bit in the address prefix to construct the branch of tree.A kind of optimization method of trie is multiple-limb trie tree, and it adopts each node of a plurality of bit structure trees in the address prefix, can reduce to search the degree of depth like this, has brought negative influence also.Its subject matter concentrates in the wide selection of step, go on foot roomy, method efficient height, EMS memory occupation is big; Go on foot wide for a short time, method efficient is low, and EMS memory occupation is few.Though people have used various compression methods to attempt to address this problem, but, in the IPv4 network, because address size is few, it is limited to go on foot wide range of choice, this problem also is not outstanding especially, and the network address of IPv6128 position makes its problem highlight, and causes this method to search performance and seriously descends.
Comparatively speaking, in the IPv6 network the reasonable a kind of lookup method of effectiveness of performance based on the binary chop of address prefix length, this method is to grow up on the linear search technique basis based on Hash table.Its basic thought is that routing table is classified according to different prefix lengths, and the prefix that will have equal length is formed a Hash table, and whole like this routing table will be made up of a plurality of Hash tables.According to the length of address key words these Hash tables are carried out binary chop afterwards, directly navigate to the prefix of long coupling according to the Hash lookup method again.Can run into the problem of some details in the implementation process of this method, for example for prefix table 1
*, 00
*, 111
*, if the address key words of searching is 111, at first binary chop 11
*, in 2 Hash table, have only 00
*, do not have 11
*, at this moment need to introduce a mechanism, in 2 Hash tables, add a marker 11
*, this marker is not actual address prefix, is the needs for search procedure.Find 11
*After, to continue to search in the back of prefix table, can find 111 this moment
*Though the increase of IPv6 address size is little to the influence of this method, but the update efficiency of this method is relatively poor, because between prefix and the prefix, dependence between prefix and the marker is bigger, when a prefix runs into operation such as interpolation, deletion, renewal, need to change the information of a plurality of prefixes or marker, it is very difficult how finding these prefixes that need change or marker.In addition, these upgrade operation, even by optimizing, and also need be in the set of the whole hash table of reconstruct after a period of time.
Summary of the invention
Technical problem to be solved by this invention is to propose a kind of routing table lookup and update method of the IPv6 of being applicable to network router, particularly when having guaranteed routing table lookup efficient, effectively improves the update efficiency of routing table.This method can be used for searching of IPv6 network router repeater system routing table and upgrade.
The present invention is achieved in that and a kind ofly realizes quick routing table lookup and method for updating based on the IPv6 address, it is characterized in that:
At first set up three kinds of data structures:
(1) linear directory table, each list item correspondence wherein zero, one or more length be equal to or less than 16 address prefix;
(2) (Hash Table List HTL), is stored in all length in the routing table in different Hash (hash) table according to the length classification smaller or equal to 16 prefix, and the set of these hash tables has constituted HTL in Hash table tabulation;
(3) Hash table tabulation (the Binary tree-Hash Table List that organizes based on the binary chop tree, B-HTL), all length in the routing table is stored in the different hash tables according to the length classification greater than 16 prefix, and these hash tables are organized by the binary chop tree and are constituted B-HTL;
After the packet of an IPv6 agreement enters router, take out the high 16bit of destination address, navigate to the corresponding list item of linear directory table as index value, if the flag bit of this list item is 0, next of then directly taking out in the list item jumped port as transmitting port; Otherwise,, in the B-HTL of correspondence, utilize the binary chop tree to search according to canned data in the list item;
Utilize the data of storing among the HTL that the linear directory table is upgraded operation.
Describedly realize quick routing table lookup and method for updating based on the IPv6 address, described linear directory table is fixed as 64k list item, and each list item length is 3 bytes, is divided into 3 parts, wherein high 16bit is a first, is used for representing the pointer of prefix length or sensing B-HTL; An ensuing bit is a flag bit, is used for representing the implication of institute of first memory contents; Third part is last 7bit, represents next jumping routed port of this list item correspondence; The correspondence that the list item of each linear directory table is unique a B-HTL.
Described linear directory table list item first, when being used for representing prefix length, each all puts 1 or put 0 the length of its 16bit; When the length address prefix that is n corresponds to certain linear directory list item, the n position 1 of this list item first, otherwise put 0.
In described linear directory table, carry out when upgrading operation, if the prefix length L that upgrades is smaller or equal to 16, earlier with L position 1 in the list item first, judge subsequently and in being higher than the position of L, whether exist for 1 position, if there is no, then the third part of linear directory table list item is rewritten as the port numbers that will upgrade prefix according to marker bit;
When in described linear directory table, carrying out deletion action, if the prefix length L of deletion smaller or equal to 16, puts 0 with L position in the list item first earlier, judge in the position that is higher than L whether exist for 1 position subsequently, if exist, then in the hash of the corresponding prefix length of HTL table, delete this prefix; If there is no, then in being lower than those of L, search the highest value and be 1 position, and in HTL, search corresponding prefix, linear directory table list item third part is rewritten as the port numbers of the prefix that finds according to this bit position.
Describedly realize quick routing table lookup and method for updating based on the IPv6 address, the operation of carrying out routing table lookup comprises the steps:
The preceding 16bit of 5A, taking-up IPv6 grouping destination address searches corresponding list item as index value in the linear directory table;
If the marker bit of this list item of 5B is 1, carry out 5D;
5C, obtain the output port of this list item correspondence, carry out 5F;
The back 112bit of 5D, taking-up IPv6 grouping destination address;
5E, in the list item of linear directory table, obtain the B-HTL pointer, at the B-HTL of correspondence
Binary chop is carried out in the middle 112bit address, back that utilizes, and obtains corresponding output port;
5F, end.
Each node of the binary chop tree of described B-HTL all points to a hash table; Each list item comprises following components in the hash table:
(1) length is the IPv6 address of 16byte;
(2) length is next jumping port numbers of 7bit;
(3) length is the marker bit of 1bit, be used to represent this list item whether corresponding length greater than 16 address prefix;
(4) whether corresponding length is the marker bit of 1bit, be used to represent this list item marker;
(5) length be 8bit longest matching prefix (Best Matched Prefix, BMP), be used to represent this list item correspondence the prefix length of location the most longways;
(6) length is the marker counter of 16bit, is used to add up the marker quantity that superposes on this list item;
(7) expand pointer points to the root node of a longest match address prefix trees (BMP_tree);
(8) next_level pointer points to the downstream site among the BMP_tree;
(9) same_level pointer points to the brother of node among the BMP_tree.
Described BMP_tree is made up of the list item of hash table among the B-HTL, the unique corresponding BMP_tree of the expand pointer of each list item, each node among the BMP_tree is a prefix with this list item all, and the length according to prefix in the node is provided with the level of this node in BMP_tree from low to high, and the node with same prefix length is in same one deck of BMP_tree; When B-HTL being added, deleting or upgrade operation, search those hash that need change table list items by BMP_tree.
Describedly realize quick routing table lookup and method for updating, when B-HTL is added a prefix P2, carry out following steps based on the IPv6 address:
8A, in B-HTL, search the prefix node P1 of location the most longways of P2;
8B, in the BMP-tree of P1, the traversal all levels is higher than the prefix node of P2, carries out 8C, 8D, 8E respectively;
If the 8C traversal does not finish, carry out 8D so, otherwise, carry out 8F;
If 8D P2 is the prefix of this node, carry out 8E so, otherwise traverse next node, carry out 8C;
8E, from the BMP-tree of P1, take out this node, move among the BMP-tree of P2, traverse next node, carry out 8C;
8F, in B-HTL, add marker for P2;
8G, P2 is added among the BMP-tree of P1;
8H, end.
Describedly realize quick routing table lookup and method for updating, during to prefix P2 of B-HTL deletion, carry out following steps based on the IPv6 address:
9A, in B-HTL, search the prefix node P1 of location the most longways of P2;
9B, in the BMP-tree of P1, the traversal all levels is higher than the prefix node of P2, carries out 9C, 9D, 9E respectively;
If the 9C traversal does not finish, carry out 9D so, otherwise, carry out 9F;
If this node of 9D is the prefix of P2, carry out 9E so, otherwise traverse next node, carry out 9C;
9E, revise this node data structure canned data, traverse next node, carry out 9C;
9F, take out the BMP-tree of P2, incorporate the BMP-tree of P1 into;
The prefix information of 9G, deletion P2;
9H, end.
Among the described B-HTL each hash table corresponding unique address prefix length, among the B-HTL all hash table corresponding an address prefix length of interval; Described binary chop tree makes up in this prefix length interval range, each node of binary chop tree covers the prefix length interval, a part of address of B-HTL, the prefix length of the hash of this node correspondence table is also in this section in the address prefix length of interval, and this part address prefix length of interval is divided into two subintervals, and these two subintervals are respectively to two child nodes about should node; In any one node corresponding address prefix length interval, the hash that option table item quantity is maximum shows the hash table as described arbitrary node correspondence.
Among the described B-HTL each hash table corresponding unique address prefix length, among the B-HTL all hash table corresponding an address prefix length of interval; Described binary chop tree makes up in this prefix length interval range, each node of binary chop tree covers the prefix length interval, a part of address of B-HTL, the prefix length of the hash of this node correspondence table is also in this section in the address prefix length of interval, and this part address prefix length of interval is divided into two subintervals, respectively to two child nodes about should node; In any one node corresponding address prefix length interval, select a hash table, with this hash table the address prefix length of interval is divided into two subintervals, make in first subinterval hash table list item quantity and with second subinterval in hash table list item quantity and the most approaching, then this hash table is shown as the hash of this node correspondence.
The present invention adopts the pattern of two-stage look-up and three kinds of data structures, by the one-level linear directory, with whole address spatial division is 64k part, when having guaranteed original binary chop efficient based on address prefix, the operation of the renewal of routing table each time only need be carried out a inside in 64k address space, and need not to change routing table in other address space, improved the efficient of routing table update and reconstruct.Simultaneously, in data structure B-HTL based on the binary chop of address prefix, increased the data organization mode that is called as BMP_tree, by this data organization mode, reduce the hash table list item of required visit in the routing table update operation, further improved the efficient of routing table update.
Description of drawings
Fig. 1 is an IPv6 address format schematic diagram.
Fig. 2 is the correlation figure of data structure used herein.
Fig. 3 is a linear directory table list item structural representation.
Fig. 4 uses the flow chart that the present invention carries out routing table lookup.
Fig. 5 is a BMP-tree structural representation among the present invention.
Fig. 6 (a) is the flow chart that adds prefix P2 in B-HTL.
Fig. 6 (b) is the flow chart of deletion prefix P2 in B-HTL.
Fig. 7 (a) be in the IPv4 routing table address prefix according to the distribution statistics figure of length.
Fig. 7 (b) be in the IPv6 routing table address prefix according to the distribution statistics figure of length.
Embodiment
Below in conjunction with drawings and Examples, the present invention done further elaborating.
Proposed the global unicast address form scheme that can assemble in RFC2373, RFC2374, this scheme is divided into plurality of sections with the IPv6 address, and wherein preceding 64 is network ID, and back 64 is interface ID.In network ID, mark off some network layers again, distribution is responsible for by different the Internet mechanisms in different subnet address.Therefore, the present invention gets preceding 16 of routing table address prefix, it is the pairing scope of climax aggregation identifier, index value as the one-level linear directory, and make up HTL, form B-HTL according to remaining 112 bit address again, carry out binary search therein, the data structure schematic diagram as shown in Figure 2 as shown in Figure 1.It mainly is divided into three kinds of data structures: linear directory table, HTL and B-HTL.Wherein, B-HTL is made up of one group of hash table, a list item in the corresponding linear directory table of each B-HTL.B-HTL derives from based on the binary chop in address prefix space and sends out data structure employed, only in its hash table address stored prefix preceding 16 all identical, all be the index value of corresponding linear directory table list item.
The structure of each list item of linear directory table as shown in Figure 3, it has two kinds of forms:
When marker bit is 0, be illustrated in that not exist with this 16 bit address prefix in the routing table be initial length greater than 16 other address prefix, this moment, preceding 16 of list item was used for representing mask-length, and the prefix that promptly indicates how many different lengths all corresponds to this list item; 7 is output port behind the list item, just corresponds to the output port of a longest routing table prefix of prefix length in this list item.
When marker bit was 1, expression existed length greater than 16 address prefix, and this moment, preceding 16 of list item was used as B-HTL of pointed, searched longest matching prefix so that carry out therein based on the binary chop of address prefix length; Behind the list item 7 this moments nonsensical, need put 0.
Because the efficiency far that the linear directory table is searched is searched greater than hash, and if this one-level concordance list can be positioned in the buffer memory, its time of searching more can ignore.The most important thing is that the linear directory table is the experimental process space with the address prefix spatial division,, can not have influence on the address prefix of other subspace interpolation, deletion and the reconstruct data structure of address prefix in each subspace.
After the grouping of an IPv6 entered router, the method for searching route table flow chart as shown in Figure 4.At first take out the preceding 16bit of the destination address of IPv6 grouping, as index value, suppose that this value is N, directly navigates on N the list item of linear directory table with the content of this 16bit.If the marker bit of this list item is 0, illustrate in routing table, not with the length of this 16bit content beginning greater than 16 prefix, directly take out the third part output port of this list item this moment, as the forwarding port of this IPv6 grouping, end is once searched; If the marker bit of this list item is 1, explanation exists in routing table with the length of this 16bit content beginning greater than 16 prefix, in order to find this prefix, need to take out the first of this list item, when marker bit is 1, the pointer of B-HTL is being deposited by first, navigates to corresponding B-HTL by this pointer, and the content according to the back 112bit of IPv6 destination address in B-HTL is carried out binary search.After this similar with binary chop method based on address prefix length, up to finding the routing table prefix of long coupling, take out corresponding next and jump port numbers, finish once to search.
The original binary chop update efficiency based on address prefix is very low, and time complexity has reached O (N*logW).Under the very big situation of routing table, because the frequent generation of routing table update in the network, such efficient can't be accepted.The key factor that influences update efficiency in the original lookup method is: the marker that how to find those to upgrade.
Renewal to marker comprises following several situation.
● when replacing an address prefix,, only need simple the replacement to get final product owing to do not influence the marker of this prefix node.
● when inserting an address prefix, need add the marker that needs in the time of searching, need simultaneously and will be rewritten as this prefix as the BMP of all marker of BMP (Best Matched Prefix) with this prefix for this prefix.
● when deleting a prefix, need the pairing marker of this prefix of deletion, if notice that certain marker has multiplexing situation, then can not be deleted, need simultaneously and will be rewritten as the BMP of this prefix as the BMP of all marker of BMP with this prefix.
By analyzing as can be known, when upgrading an address prefix and writing down p/l (p is a prefix addresses, and l is a prefix length), original lookup method need upgrade two class marker, and the first kind is the marker of length less than l, and this class marker uses during for binary chop; Second class is that its BMP is the marker of p/l, and the effect of this class marker is for fear of recalling.Renewal to first kind marker is comparatively simple, because the address of p is known, its pairing first kind marker can directly search acquisition by carry out hash in the hash of corresponding length table.And the second class marker has represented the Prefix Expansion of p/l, owing to and do not know which Prefix Expansion p/l has in routing table, therefore need the hash table of traversal all length greater than l, or be that the complete set of p/l carry out hash search to prefix at all length in greater than the hash of l table, this efficient is very low.
A simple method is, when making up data structure, the second class marker of each prefix entries linked by linear linked list, can dwindle the scope of searching greatly like this.But such lookup method is carried out the space that efficient still has raising.Therefore, the present invention uses tree data structure, and BMP-tree is used for organizing the list item with same BMP.
Not all marker has longest matching prefix.For consistency, in hash table, added two pseudo-prefix hash list items, in the present embodiment, it is in 17 the hash table that these two pseudo-prefix entries are added on length.Suppose that all list items all have common prefix p/16 in this hash tabular table, two pseudo-prefix entries of Tian Jiaing are respectively { p, 0}/17 and { p, 1}/17 so.
Be depicted as BMP-tree data structure schematic diagram as Fig. 5 (a).Wherein Fig. 5 (a) is (or adding the back) before the prefix P2 deletion, and Fig. 5 (b) is prefix P2 deletion back (or before adding).The left side is the binary search tree, has shown the relation between each hash table.The right is the BMP-tree that each list item is formed in hash tabular table and the hash table, and wherein p represents that this list item is pure prefix, and m represents that this list item is pure marker, and b represents that this list item is a prefix, also is a marker, and they use same hash list item.
For a hash list item, if it has represented a prefix, promptly be labeled as p or b, it has its pairing BMP-tree of a pointed so, and each node among the BMP-tree all is with the hash list item of this prefix as BMP (longest matching prefix).Each father node, the prefix length of its left child node is greater than the prefix length of father node in BMP-tree, and the prefix length of its right child node equals the prefix length of father node.Will be from root node, the trunk that unique paths of all left child nodes compositions is called this BMP-tree, the length that a certain node on the trunk is begun path that all right nodes form and becomes this BMP-tree is the Zhi Gan of l, and wherein l is the prefix length of all nodes on this Zhi Gan.
Be labeled as among the figure P1 the list item correspondence BMP-tree, represent with light node.Be labeled as P2 the list item correspondence an other BMP-tree, represent with dark node.As can be known, the BMP of P2 is P1.During remove entries P2, at first upgrade the first kind marker of P2, deleted if this marker needs, then in the BMP-tree of P1, search for the Zhi Gan of those length less than the prefix length of P2.Upgrade the second class marker of P2 then, only need this moment the BMP of all nodes among the BMP-tree of P2 is rewritten as P1, then the BMP-tree of P2 is merged among the BMP-tree of P1 and get final product, the data structure after the merging is shown in Fig. 5 (b), and its flow chart is seen Fig. 6 (a).
The operation and the deletion action of adding route prefix are similar.For example in the data structure shown in Fig. 5 (b), add prefix P2, at first will add the first kind marker of P2, if relate to the operation of newly-increased list item, so will be at the BMP of P2, just the Zhi Gan of corresponding length goes up the interpolation node among the BMP-tree of P1.To construct the BMP-tree of P2 then, length is greater than a dried neutral line search of the prefix length of P2 in the BMP-tree of P1, and searching those is the node of prefix with P2, and its BMP is rewritten as P2, and they are sheared from the BMP-tree of P1, add among the BMP-tree of P2 getting final product to.Add the flow chart of prefix and see Fig. 6 (b).
By introducing BMP-tree, it is very quick that the deletion action of prefix entries becomes, if use doubly linked list, the time complexity of deletion action can be controlled at O (kWlogW) so, wherein k is single operation chained list required memory access times, and efficient improves greatly compared with original method that needs linear search.And the operating efficiency that adds route table items also is not very good, but compares original method, introduces after the BMP-tree, can get rid of a large amount of alternative list items according to the length of address prefix, has improved efficient to a certain extent yet.
Fig. 6 (a) is the flow chart that adds prefix P2 in B-HTL.Fig. 7 (a) is depicted as in the IPv4 backbone network router route prefix according to the statistic histogram of distribution of lengths.Can see that in the drawings the quantity of the prefix of different length in routing table is different, and specific distribution characteristics is arranged.If make full use of these features, can effectively improve the average efficiency of lookup method.Fig. 6 (b) is the flow chart of deletion prefix P2 in B-HTL.Similarly, be depicted as the route prefix of IPv6 backbone network router by distribution of lengths statistic histogram (only having shown preceding 64 network addresss) as Fig. 7 (b).
For the purpose of simplifying the description, be that example illustrates and adopts the influence of different binary search trees for search efficiency with the IPv4 routing table, as shown in Figure 7, Fig. 7 (a) be in the IPv4 routing table address prefix according to the distribution statistics figure of length.
Fig. 7 (b) be in the IPv6 routing table address prefix according to the distribution statistics figure of length.If using balance binary search tree searches, though the prefix quantity of some hash tables takes advantage, but its residing position is positioned at the darker level of search tree, for most search mission, needs more internal storage access just can finish once and searches.And if by the binary search path is designed, will have a fairly large number of hash of prefix table to place higher level, though increased the depth capacity of tree, make the maximum search degree of depth increase, improved average efficiency.
In addition, traditional additive decrementation that must bring internal memory based on the binary chop of address prefix length to the introducing of marker.Since some marker can be same with real route prefix information multiplexing memory headroom, marker can control to a certain extent to the influence of space efficiency.For this reason, present embodiment has used two kinds of different search tree organization plans, reduces marker taking memory headroom as far as possible.
Scheme one is used and is comprised the upper layer node that a fairly large number of hash table of prefix constitutes search tree, can make marker have maximum may with real route prefix information multiplexing memory headroom; Scheme two with that in mind, for certain node in the binary search tree, the prefix information in its right subtree can generate a marker at this node, if can reduce the size of right subtree as far as possible, can reduce the quantity of marker greatly.A limiting case is that each node has only left child node in this binary tree, do not need the storage of extra marker like this, but binary tree degenerates to linear search.For this reason, scheme two has adopted the method for balance left and right sides subtree, and when selecting father node, the quantity of prefix is equal as far as possible in its left and right sides subtree, and preferably prefix quantity is slightly larger than prefix quantity in the right node in the left sibling.
The scheme of two kinds of structure search tree structures has all improved the efficient of searching method to a great extent, and has reduced the storage of marker.
As from the foregoing, the present invention has used the search pattern of two-stage on the binary chop basis based on address prefix length, separated the address prefix space by the linear directory table of the first order, reduce influencing each other when address prefix upgrades in the different subspace, also guaranteed the efficient of searching; In based on the employed data structure of the binary chop of address prefix length, increased a kind of data organization mode BMP-tree, the expense when further having reduced routing table update; At last, the invention provides two kinds of different binary chop tree organizational forms, reduced the expense of storage.