IP ROUTE LOOKUP BASED ON STANDARD TRIE STRUCTURE
369
Fig. 13.4 Routing entries defining ranges of IP addresses.
Ž .
addresses leaves in the subtree rooted at that node should be routed according to that routing entry. In this manner each routing table entry
Ž defines a range of IP addresses with identical routing information next-hop
. IP address .
If several routing entries cover the same IP address, the rule of the longest match is applied; it states that for a given IP address, the routing entry with
the longest matching prefix should be used. This situation is illustrated in Figure 13.4; the routing entry e1 is hidden by e2 for addresses in the range r.
13.2 IP ROUTE LOOKUP BASED ON CACHING TECHNIQUE
One possible IP route-lookup approach uses a caching technique where the routing entries of the most recently used destination addresses are kept in a
cache. The technique relies on there being enough locality in the traffic so that the cache hit rate is sufficiently high and the cost of a routing lookup
is amortized over several packets. These caching methods have worked well in the past. However, as the current rapid growth of the Internet increases,
the required size of address caches and hardware caches might become uneconomical.
13.3 IP ROUTE LOOKUP BASED ON STANDARD
TRIE STRUCTURE
A trie structure is a multiway tree in which each node contains zero or more w x
pointers to its child nodes. In the 1-bit trie structure 8 , each node contains two pointers, the 0-pointer and the 1-pointer. A node X at level h represents
the set of all route prefixes that have the same h bits as their first bits. Ž
. Depending on the value of the h q 1 th bit, 0 or 1, each pointer of the node
Ž .
X points to the corresponding subtree if it exists , which represents the set
Ž .
of all route prefixes that have the same h q 1 th bits as their first bits. Each IP lookup starts at the root node of the trie. Based on the value of each bit of
the destination address of the packet, the lookup algorithm determines the next node to be visited. The next hop of the longer matching prefix found
along the path is maintained while the trie is traversed.
IP ROUTE LOOKUPS
370
Fig. 13.5
A 1-bit trie structure for IP route lookups.
An example is shown in Figure 13.5. Each node has a flag associated with it, which indicates whether the particular route prefix terminated there is in
the routing table. The flag is indicated with an asterisk. Assume that the destination address 10101101 is given. The IP lookup starts at the top and
traverses the path indicated by the destination address, remembering the last
Ž .
time a flag an asterisk was seen. Starting at the top, the zero-length prefix has a flag. The first bit of 10101101 is 1, so we go to the right and get to the
4 node with the name 1. There is no asterisk, so
is still the longest prefix matched so far. The second and third bits of 10101101 are 0 and 1, so we go
to the left and right to the node 101. Here an asterisk is found, so the 4
longest matching prefix is updated from to 101. The next bit is 0. We go to
the node 10101. The next bit is 1, but there is no pointer marked 1 out of the node 1010. Thus, the lookup is stopped here, and the longest matching prefix
is 101. Maintaining the trie structure is not difficult. To add a route prefix, say
1011, simply follow the pointers to where 1011 would be in the tree. If no pointers exist for that prefix, they should be added. If the node for the prefix
already exists, it needs to be marked as being in the forwarding table, that is, an asterisk must be added. To delete a route prefix that has no children, the
node and the pointer pointing to it are deleted and the parent node is examined. If it has another child or is marked with an asterisk, it is left alone.
Otherwise, that node is also deleted and its parent node is examined. The deletion process is repeated up the tree until a node that has another child or
is marked is found.
Using the 1-bit trie structure for the IP route lookups has the drawback in that the number of memory accesses in the worst case could be 32 for IPv4.
The performance of lookups can be substantially improved by using a multibit trie structure. This more general idea was suggested by Srinivasan
w x
and Varghese 14 . In the multibit, say K-bit, trie structure, each node contains 2
K
pointers. Each route prefix in the forwarding table is expanded to include new prefixes whose lengths are the smallest numbers that are
greater than or equal to the original length and also multiples of K bits. For
IP ROUTE LOOKUP BASED ON STANDARD TRIE STRUCTURE
371 TABLE 13.1
An Example of Expanding the Route Prefixes by Using 2-Bit Trie Structure
Forwarding Table Original
Expanded Ž
. P1 s 0
01 P1 Ž
. P2 s 1
00 P1 Ž
. P3 s 10
10 P3 Ž
. P4 s 111
11 P2 Ž
. P5 s 1000
1110 P4 Ž
. P6 s 11001
1111 P4 Ž
. 1000 P5
Ž .
110010 P6 Ž
. 110011 P6
Fig. 13.6
The 2-bit trie structure corresponding to the forwarding table in Table 13.1.
example, a routing table, shown in the left column of Table 13.1, contains route prefixes P1᎐P6. The asterisk in each route prefix indicates that the
remaining bits are insignificant. By using a 2-bit trie structure, the expanded version of the forwarding table can be obtained as shown in the right column
of Table 13.1. Note that the prefix P2 s 1 can be expanded into 10 and 11, but 10 is not used, since it overlaps P3, which is the longer matching
prefix. The corresponding 2-bit trie structure is also shown in Figure 13.6.
The traversal to the node at each level of the K-bit trie is based on each K
-bit part of the destination address of the packet. The advantage of the
IP ROUTE LOOKUPS
372
K -bit trie structure is that it provides fast lookups; its disadvantage is the
large memory space that is required for nodes of the structure.
13.4 PATRICIA TREE