The present invention relates to the field of communications technologies, and in particular, to a routing table establishment method and device and a routing table lookup method and device.
In order to prevent exhaustion of address space, the Internet Engineering Task Force (The Internet Engineering Task Force; IETF for short) proposed a temporary solution of an address structure about Classless Inter-Domain Routing (Classless Inter-Domain Routing; CIDR for short) in 1993. The CIDR is the current basis of actual lookup of a routing table, and departs from the conventional A-E classification address structure. In the CIDR, an IP network is represented by a prefix (prefix), and the prefix is synthetically represented by an IP address and a mask indicating valid bits of the IP address. The CIDR allows a router to perform routing aggregation, that is, entries of a routing table, having the same size, being adjacent in the address space, and routing the same sub-networks of the number of an integral power of 2, may be combined into one path, which only occupies one entry in the routing table. Consequently, a given address block may be partitioned according to a random bit (bit) boundary, a computer on the network allocates addresses according to a consecutive range, but the range does not need a correspondingly predefined classification, and therefore, it is called classless addressing. The CIDR can avoid extremely quick exhaustion of network addresses and rapid expansion of entries of a routing table of a backbone router, and at the same time, the length of the prefix of the network address is enabled to be a random value, and the longest prefix match (the longest prefix match) search must be performed when the routing table is looked up. Main factors of measuring the quality of a table lookup algorithm of the routing table include: the lookup speed of the routing table (determined by the times for accessing a memory, the memory's capacity required by the routing table, the difficulty of inserting/deleting entries of the routing table, and so on.
A data structure of the classless routing table may be stored in a layered data structure. The searching of the routing table is performed downwards layer by layer, and therefore, a Binary Tree (Binary Tree) or a Radix Tree (Radix Tree) and the transformations of their data structures may be used for demonstration. Table 1 is an exemplary routing table.
The prefixes in Table 1 may be stored in a basic Binary Tree.
Patricia tree is a variation of the basic Binary Tree (Binary Tree), and the Patricia tree allows each node to designate a value and detect the number of bits consecutively hopped, so as to accelerate the search speed. The prefix is stored on a leave node of the Patricia tree, and it is assumed that when N prefixes exist, N leave nodes exist, and N−1 internal nodes exist additionally. A redundant branch link is compressed to a node, and therefore, the table lookup algorithm does not need to perform consecutive bit match, but matches multiple bits once to reach the leave node rapidly.
The IP address prefix may be considered as a range, for example, 10.110.0.0/16 actually represents all IP addresses from 10.110.0.0 to 10.110.255.255, and therefore, the IP address prefix may be represented by a range [10.110.0.0, 10.110.255.255]. All the IP address prefixes are converted to ranges, and then, the problem of the longest prefix match may be converted to the problem of finding which range the IP address to be looked up falls in. This problem is similar to a sorting problem, and a routing table may be established by using a Binary Tree method. It is assumed that the IP address has 8 bits, and totally 7 IP addresses exist, masks and ranges of the IP addresses are shown as follows in Table 2.
As shown in
In order to improve the low space utilization of the routing table, a routing table may be established and looked up by adopting a TRIE algorithm, and the TRIE algorithm has advantages of high compression ratio and rapid update speed. However, times for the TRIE algorithm accessing the nodes is proportional to times for accessing a memory and the length of entries, and along with the increase of a key (key) value of the TRIE algorithm, the height of the routing table is increased, and times for an IPv6 forwarding information base (Forwarding Information Base; FIB for short) looking up and accessing the memory is large, thereby reducing the throughput, deteriorating the performance, prolonging the delay, and reducing the capacity.
Embodiments of the present invention provide a routing table establishment method and device and a routing table lookup method and device, so as to solve the problems of slow speed of looking up the routing table and prolonged delay due to the extremely great height of the tree in the conventional TRIE algorithm, thereby improving lookup speed of the routing table and reducing lookup delay.
A routing table establishment method is provided in an embodiment of the present invention, which includes:
partitioning a data structure of a routing table into a trunk and a TRIE sub-tree;
adding entries of the routing table to the TRIE sub-tree; and
storing an upgrade sub-node of the TRIE sub-tree's root in the trunk, where the height of the TRIE sub-tree is smaller than or equal to a set height threshold, and the upgrade sub-node of the TRIE sub-tree's root is a sub-root among prefix sub-nodes included in the TRIE sub-tree's root.
A routing table lookup method is further provided in an embodiment of the present invention, where a data structure of a routing table includes a trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk of the routing table. The method includes:
looking up, in the trunk of the routing table, an upgrade sub-node longest matching a key word;
obtaining a location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds; and according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, looking up, in the TRIE sub-tree, a lookup result corresponding to the key word by using the TRIE algorithm.
A routing table establishment device is further provided in an embodiment of the present invention, which includes:
a partitioning module, configured to partition a data structure of a routing table into a trunk and a TRIE sub-tree;
an entry adding module, configured to add entries of the routing table to the TRIE sub-tree; and
a storing module, configured to store an upgrade sub-node of the TRIE sub-tree's root in the trunk, where the height of the TRIE sub-tree is smaller than or equal to a set height threshold, and the upgrade sub-node of the TRIE sub-tree's root is a sub-root among prefix sub-nodes included in the TRIE sub-tree's root.
A routing table lookup device is further provided in an embodiment of the present invention, which includes:
a trunk lookup module, configured to look up, in a trunk of a routing table, an upgrade sub-node longest matching a key word, where a data structure of the routing table includes the trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk of the routing table;
a sub-tree location obtaining module, configured to obtain a location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds; and
a sub-tree lookup module, configured to, according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, look up, in the TRIE sub-tree, a lookup result corresponding to the key word by using the TRIE algorithm.
Embodiments of the present invention provide a routing table establishment method and device and a routing table lookup method and device. The data structure of the routing table is partitioned into the trunk and the TRIE sub-tree, and the sub-tree is a TRIE sub-tree established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and the height of the TRIE sub-tree is controlled when the entries of the routing table are added, thereby reducing times for accessing a memory, improving lookup speed of the routing table, and reducing lookup delay.
To illustrate the technical solutions according to the embodiments of the present invention or in the prior art more clearly, the accompanying drawings for describing the embodiments or the prior art are introduced briefly in the following. The accompanying drawings in the following description are only about some embodiments of the present invention, and persons of ordinary skill in the art can derive other drawings from the accompanying drawings without creative efforts.
a is a schematic structural diagram of a trunk and a TRIE sub-tree in an embodiment of a routing table establishment method of the present invention;
b is a schematic diagram of a multi-bit TRIE algorithm in an embodiment of a routing table establishment method of the present invention;
c is a schematic diagram of an internal bitmap of a tree bitmap algorithm in an embodiment of a routing table establishment method of the present invention;
d is a schematic diagram of an external bitmap of a tree bitmap algorithm in an embodiment of a routing table establishment method of the present invention;
a is a schematic diagram before splitting resulting from adding entries of a routing table in an embodiment of a routing table establishment method of the present invention;
b is a schematic diagram after splitting resulting from adding entries of a routing table in an embodiment of a routing table establishment method of the present invention;
c is a schematic flow chart of adding entries of a routing table in an embodiment of a routing table establishment method of the present invention;
d is a schematic diagram before adding IP address prefixes in an embodiment of a routing table establishment method of the present invention;
e is a schematic diagram after adding IP address prefixes in an embodiment of a routing table establishment method of the present invention;
Technical solutions of the present invention are further illustrated in detail below through the accompanying drawings and embodiments.
101: Partition a data structure of a routing table into a trunk and a TRIE sub-tree.
102: Add entries of the routing table to the TRIE sub-tree.
103: Store an upgrade sub-node of the TRIE sub-tree's root in the trunk, where the height of the TRIE sub-tree is smaller than or equal to a set height threshold, and the upgrade sub-node of the TRIE sub-tree's root is a sub-root among prefix sub-nodes included in the TRIE sub-tree's root.
The routing table may be stored in a layered data structure, a data structure of the routing table may be partitioned in advance into a trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk. The TRIE sub-tree may be established by adopting the TRIE algorithm. The tree established by using the TRIE algorithm is also referred to as a Trie tree, which is of a tree structure and is a variation of Hash Tree. The establishment method of the trunk may adopt, but not limited to, range matching, B tree, a ternary content addressable memory or other algorithms.
Two kinds of TRIE algorithm are introduced in the following.
b is a schematic diagram of a multi-bit (multi-bit) TRIE algorithm in an embodiment of a routing table establishment method of the present invention. The multi-bit TRIE algorithm uses indexes of multiple bits (bit) of an IP address to form an array, associates, according to the precedence order of the arrays in the IP address, arrays formed by different bits of the IP address, and looks up, level by level, multiple bits at a time during the lookup. In
c is a schematic diagram of an internal bitmap of a tree bitmap (Tree bitmap) algorithm in an embodiment of a routing table establishment method of the present invention, and
When the data structure of the routing table is established, the TRIE algorithm may be adopted to establish a TRIE sub-tree, and then, during the specific process of adding entries of the routing table or deleting entries of the routing table, corresponding update is performed on an upgrade sub-node stored in the trunk of the routing table according to a set height threshold, and specifically the following scenarios are included.
Scenario 1: Add entries of a routing table.
If the height of the TRIE sub-tree after adding the entries of the routing table is greater than the height threshold, then a branch that is in the TRIE sub-tree and has the height greater than the height threshold is split from the TRIE sub-tree, so as to obtain a new TRIE sub-tree.
An upgrade sub-node of a root of the new TRIE sub-tree is stored in the trunk, where the new TRIE sub-tree's root is a node connected between the branch that is in the TRIE sub-tree and has the height greater than the height threshold and the TRIE sub-tree's root.
a is a schematic diagram before splitting resulting from adding entries of a routing table in an embodiment of a routing table establishment method of the present invention, and
Further, during the process of adding entries of the routing table, if the height of the TRIE sub-tree after splitting is smaller than the height threshold and the TRIE sub-tree has a parent TRIE sub-tree, the TRIE sub-tree's root may be combined to the parent TRIE sub-tree, and the upgrade sub-node of the TRIE sub-tree's root is deleted from the trunk.
According to
201: A certain node N1 (root) in a TRIE sub-tree T finds that the height of the TRIE sub-tree T is greater than a height threshold h.
202: Look up from the node N1 towards the ancestor of the TRIE sub-tree T, and find a node N2 having the height h.
203: By using the node N2 as a root, split the TRIE sub-tree T to obtain a new TRIE sub-tree T2, where the rest part of the T is T1.
204: Determine whether the height of the T1 is smaller than the preset height threshold h, and if the T1 has a parent TRIE sub-tree (also referred to as a father sub-tree, a father, and so on) and the height of the T1 is smaller than h, perform 205; otherwise, end the process.
205: Combine the TRIE sub-tree T1 into the parent TRIE sub-tree of the T1, use the combined TRIE sub-tree as the TRIE sub-tree T, and return to 201.
In order to illustrate the specific process of adding the entries of the routing table, by taking an example that entries that are added to the routing table are IP address prefixes, it is assumed that the height threshold of the TRIE sub-tree is “2”, the prefix sub-nodes in each node of the TRIE sub-tree are of 3 levels, and each node has totally 7 prefix sub-nodes, 14 bits are used to identity an IP address prefix, and the trunk is stored in a ternary content addressable memory (Ternary Content Addressable Memory; TCAM for short). As shown in
As shown in
Scenario 2: Delete entries of a routing table.
If the height of the TRIE sub-tree after deleting the entries of the routing table is smaller than the height threshold and the TRIE sub-tree has a parent TRIE sub-tree, the TRIE sub-tree's root may be combined to the parent TRIE sub-tree, and the upgrade sub-node of the TRIE sub-tree's root is deleted from the trunk.
The process of combing the TRIE sub-tree's root to the parent TRIE sub-tree is similar to the process of adding entries of the routing table to the parent TRIE sub-tree. Whether the height of the parent TRIE sub-tree is greater than the height threshold may also be determined, and if the height of the parent TRIE sub-tree is greater than the height threshold, splitting processing may be performed on the parent TRIE sub-tree. It is also possible to perform combining or splitting processing on a grandparent TRIE sub-tree. After layers of combination and splitting, it is ensured that the height of each TRIE sub-tree without a parent TRIE sub-tree is a set height threshold.
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree, and the sub-tree is a TRIE sub-tree established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and the height of the TRIE sub-tree may be controlled according to the set height threshold, thereby reducing times for accessing a memory, improving lookup speed, and reducing lookup delay.
301: Look up, in a trunk of a routing table, an upgrade sub-node longest matching a key word.
The routing table may be stored in a layered data structure, a data structure of the routing table includes a trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk, where the upgrade sub-node of the TRIE sub-tree's root is a sub-root among prefix sub-nodes included i n the TRIE sub-tree's, root. The TRIE sub-tree may be established by adopting the TRIE algorithm, and the establishment method of the trunk may adopt, but not limited to, range matching, B tree, a ternary content addressable memory or other algorithms. For the specific structure of the routing table, reference may be made to related description in the foregoing embodiment and
The specific process of looking up the upgrade sub-node longest matching the key word in the trunk of the routing table may include: looking up, from upgrade sub-nodes of TRIE sub-trees stored in the trunk of the routing table, first prefixes matching the key word; and selecting, from the first prefixes, a first prefix of the longest mask length to serve as the upgrade sub-node longest matching the key word. When the first prefixes corresponding to the key word is looked up, a part of data in the key word is matched with each upgrade sub-node in the trunk, and the matching method may be selected according to the establishment method of the trunk.
302: Obtain a location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds.
Address information of the upgrade sub-node longest matching the key word may direct to the TRIE sub-tree's root where the upgrade sub-node is located, and according to the address information, the location of the TRIE sub-tree's root to which the upgrade sub-node corresponds may be obtained.
303: According to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, look up, in the TRIE sub-tree, a lookup result corresponding to the key word by using the TRIE algorithm.
303 may specifically include:
according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, looking up, from prefix sub-nodes of nodes of the TRIE sub-tree to which the upgrade sub-node longest matching the key word corresponds, second prefixes matching the key word; and
selecting, from the second prefixes, a second prefix of the longest mask length to serve as the lookup result.
When each second prefix corresponding to the key word is looked up, a part of data in the key word is matched with a prefix sub-node of each node of the TRIE sub-tree, and the matching method may adopt the TRIE algorithm used for establishing the TRIE sub-tree.
The lookup process is illustrated specifically by taking the lookup in the routing table in
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree that is established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and the height of the TRIE sub-tree may be controlled according to the set height threshold, thereby reducing times for accessing a memory when a routing table is searched, improving lookup speed, and reducing lookup delay.
The partitioning module 51 is configured to partition a data structure of a routing table into a trunk and a TRIE sub-tree.
The entry adding module 52 is configured to add entries of the routing table to the TRIE sub-tree.
The storing module 53 is configured to store an upgrade sub-node of the TRIE sub-tree's root in the trunk, where the height of the TRIE sub-tree is smaller than or equal to a set height threshold, and the upgrade sub-node of the TRIE sub-tree's root's root is a sub-root among prefix sub-nodes included in the TRIE sub-tree's root.
Specifically, in the data structure stored in the routing table, the partitioning module 51 partitions the data structure of the routing table into the trunk and the TRIE sub-tree, the TRIE sub-tree is established by adopting the TRIE algorithm, and the trunk is established by another algorithm such as: range matching, B tree, or a ternary content addressable memory. After the entry adding module 52 adds entries of the routing table to the TRIE sub-tree, the storing module 53 stores the upgrade sub-node of the TRIE sub-tree's root in the trunk, and presets a height threshold, where the height of the TRIE sub-tree is smaller than or equal to the set height threshold. If the TRIE sub-tree is established by adopting the TRIE algorithm, and the height after adding the entries of the routing table, for example, IP address prefixes, is greater than the height threshold, the TRIE sub-tree after adding the entries of the routing table may be split, and the height of the TRIE sub-tree in the data structure of the routing table is controlled to be the height threshold. After the data structure of the routing table is established, entries of the routing table therein may need to be deleted, and after certain entries of the routing table are deleted, if the height of the TRIE sub-tree after deleting the entries of the routing table is smaller than or equal to the height threshold, the TRIE sub-tree after deleting the entries of the routing table is combined with a parent TRIE sub-tree. In this embodiment, for the specific process of establishing the routing table, reference may be made to the related description in the embodiment of the routing table establishment method of the present invention.
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree, and the sub-tree is established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and an update module may control the height of the TRIE sub-tree according to the set height threshold, thereby reducing times for accessing a memory, improving lookup speed, and reducing lookup delay.
In addition, the storing module 53 is further configured to store an upgrade sub-node of the new TRIE sub-tree's root in the trunk, where the new TRIE sub-tree's root is a node connected between the branch that is in the TRIE sub-tree and has the height greater than the height threshold and the TRIE sub-tree's root.
Alternatively, the routing table establishment device may further include: a combining and deleting module 56, configured to, if the height of the TRIE sub-tree after splitting is smaller than the height threshold and the TRIE sub-tree has a parent TRIE sub-tree, combine the TRIE sub-tree's root to the parent TRIE sub-tree, and delete, from the trunk, the upgrade sub-node of the TRIE sub-tree's root.
The combining and deleting module 56 is further configured to, if the height of the TRIE sub-tree after deleting the entries of the routing table is smaller than the height threshold and the TRIE sub-tree has a parent TRIE sub-tree, combine the TRIE sub-tree's root to the parent TRIE sub-tree, and delete the upgrade sub-node of the TRIE sub-tree's root from the trunk.
Specifically, in the data structure stored in the routing table, the partitioning module 51 may partition the data structure of the routing table into the trunk and the TRIE sub-tree in advance, and the upgrade sub-node of the TRIE sub-tree's root is stored in the trunk. The TRIE sub-tree is established by adopting the TRIE algorithm, and for the specific method of establishing the TRIE sub-tree, reference may be referred to the description of related examples of the embodiment of the routing table establishment method of the present invention. The trunk where the TRIE sub-tree is located is established by adopting a method such as: range matching, B tree, or a TCAM. After the entry adding module 52 adds entries of the routing table to the TRIE sub-tree, the storing module 53 stores the upgrade sub-node of the TRIE sub-tree's root in the trunk, and presets a height threshold, where the height of the TRIE sub-tree is smaller than or equal to the set height threshold. When the entries of the routing table are added, if the height of the TRIE sub-tree after adding the entries of the routing table is greater than the set height threshold, the splitting module 54 splits, from the TRIE sub-tree, the branch that is in the TRIE sub-tree and has the height greater than the height threshold, to obtain the new TRIE sub-tree. If the height of the TRIE sub-tree after splitting is smaller than the height threshold and the TRIE sub-tree has a parent TRIE sub-tree, the combining and deleting module 56 combines the TRIE sub-tree's root to the parent TRIE sub-tree, and deletes, from the trunk, the upgrade sub-node of the TRIE sub-tree's root.
After the data structure of the routing table is established, entries of the routing table therein, for example, IP address prefixes, may need to be deleted, and after certain entries of the routing table are deleted, if the height of the TRIE sub-tree after deleting the entries of the routing table is smaller than or equal to the height threshold, and the TRIE sub-tree has a parent TRIE sub-tree, the combining and deleting module 56 may further be configured to combine the TRIE sub-tree's root to the parent TRIE sub-tree, and delete, from the trunk, the upgrade sub-node of the TRIE sub-tree's root.
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree, and the sub-tree is established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; when the entries of the routing table are added, the splitting module and the storing module may split the TRIE sub-tree whose height is greater than the height threshold; and when the entries of the routing table are deleted the deleting module and then entry adding module may combine the TRIE sub-tree whose height is smaller than the height threshold, so that the height of the TRIE sub-tree is controlled, thereby reducing times for accessing a memory, improving lookup speed, and reducing lookup delay.
a trunk lookup module 71, configured to look up, in a trunk of a routing table, an upgrade sub-node longest matching a key word, where a data structure of the routing table includes the trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk of the routing table;
a sub-tree location obtaining module 72, configured to obtain a location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds; and
a sub-tree lookup module 73, configured to, according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, look up, in the TRIE sub-tree, a lookup result corresponding to the key word by using the TRIE algorithm.
Specifically, the routing table may be stored in a layered data structure, a data structure of the routing table includes a trunk and a TRIE sub-tree, and an upgrade sub-node of the TRIE sub-tree's root is stored in the trunk, where the upgrade sub-node of the TRIE sub-tree's root is a sub-root among prefix sub-nodes included in the TRIE sub-tree's root. The TRIE sub-tree may be established by adopting the TRIE algorithm, and the establishment method of the trunk may adopt, but not limited to, range matching, B tree, a ternary content addressable memory or other algorithms. The trunk lookup module 71 may look up, in the trunk of the data structure of the routing table, the upgrade sub-node longest matching the key word. The sub-tree location obtaining module 72 may obtain, according to address information in the upgrade sub-node longest matching the key word, the location of the root of the corresponding TRIE sub-tree. The sub-tree lookup module 73 may find, according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, in the corresponding TRIE sub-tree the lookup result corresponding to the key word by using the TRIE algorithm.
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree that is established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and the height of the TRIE sub-tree may be controlled according to the set height threshold, and therefore, when the routing table is searched, the trunk lookup module finds the upgrade sub-node longest matching the key word, the sub-tree location obtaining module may obtain the location of the TRIE sub-tree corresponding to the key word, and the sub-tree lookup module looks up, in the corresponding TRIE sub-tree, the lookup result corresponding to the key word, thereby reducing times for accessing a memory, improving lookup speed, and reducing lookup delay.
a first prefix sub-module 711, configured to look up, from upgrade sub-nodes of TRIE sub-trees stored in the trunk of the routing table, first prefixes matching the key word; and
a longest matching sub-module 712, configured to select, from the first prefixes, a first prefix of the longest mask length to serve as the upgrade sub-node longest matching the key word.
Further, the sub-tree lookup module 73 includes:
a second prefix sub-module 731, configured to, according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the key word corresponds, look up, from prefix sub-nodes of nodes of the TRIE sub-tree to which the upgrade sub-node longest matching the key word corresponds, second prefixes matching the key word; and
a lookup result sub-module 732, configured to select, from the second prefixes, a second prefix of the longest mask length to serve as the lookup result.
Specifically, after the first prefix sub-module 711 looks up, from the upgrade sub-nodes of TRIE sub-trees stored in the trunk of the routing table, the first prefixes matching the key word, the longest matching sub-module 712 selects, from the first prefixes, the first prefix of the longest mask length to serve as the upgrade sub-node longest matching the key word. The sub-tree location obtaining module 72 obtains the location of the root of the corresponding TRIE sub-tree according to the upgrade sub-node longest matching the key word. Then, according to the location of the TRIE sub-tree's root to which the upgrade sub-node longest matching the keyword corresponds, the second prefix sub-module 731 looks up, from prefix sub-nodes of nodes of the TRIE sub-tree to which the upgrade sub-node longest matching the key word corresponds, the second prefixes matching the key word. The lookup result sub-module 732 selects, from the second prefixes, the second prefix of the longest mask length to serve as the lookup result.
In this embodiment, the data structure of the routing table is partitioned into the trunk and the TRIE sub-tree that is established by using the TRIE algorithm, thereby ensuring the high compression ratio of the routing table; and the height of the TRIE sub-tree may be controlled according to the set height threshold, and therefore, when the routing table is searched, after each sub-module of the trunk lookup module finds the upgrade sub-node longest matching the key word, the sub-tree location obtaining module may obtain the location of the TRIE sub-tree corresponding to the key word, and each sub-module of the sub-tree lookup module looks up, in the corresponding TRIE sub-tree, the lookup result corresponding to the key word, thereby reducing times for accessing a memory, improving lookup speed, and reducing lookup delay.
Persons of ordinary skill in the art should understand that all or a part of the steps of the method according to the method embodiments of the present invention may be implemented by a program instructing relevant hardware. The program may be stored in a computer readable storage medium. When the program is executed, the steps of the method according to the embodiments of the present invention are performed. The storage medium may be any medium that is capable of storing program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
Finally, it should be noted that the above embodiments are merely provided for describing the technical solutions of the present invention, but not intended to limit the present invention. It should be understood by persons of ordinary skill in the art that although the present invention has been described in detail with reference to the embodiments, modifications can be made to the technical solutions described in the embodiments, or equivalent replacements can be made to some technical features in the technical solutions, as long as such modifications or replacements do not cause the essence of the corresponding technical solutions to depart from the scope of the technical solutions of the embodiment of the present invention.
This application is a continuation of International Application No. PCT/CN2010/071698, filed on Apr. 12, 2010, which is hereby incorporated by reference in their entireties.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2010/071698 | Apr 2010 | US |
Child | 13649633 | US |