• No results found

2.3 Asynchronous logic systems

3.1.2 Trie creation and trie search algorithms

Consider the Enhanced Compact Prefix Table (E-CPT) from Table 3.2. To insert the prefixes from this table into an E − Ctrie the APp of each prefix is first identified. For a given prefix

the bits in the APp are used to traverse the trie starting at the head of the trie(the current node

N odecur). If N odecurdoes not have an outgoing  link, the most significant bit in APpis exam-

ined, and the left or right branch out of N odecuris taken depending on whether the bit is a ’0’

or ’1’. The node so reached is the new N odecur, and a new APp is created by shifting the old

APpone bit to the left (effectively discarding the MSB that was just examined). The MSB of the

new APpis now examined, and a decision on the branch to be followed out of the new N odecur

is taken. This process of examining the MSB of the APp, moving to a downstream node and

shifting the APpa bit to the left is continued, until a node is reached that has no successor nodes

(children) in the direction indicated by the MSB of the APp. A new node is then created and

connected to the last N odecur, and the trie traversal continues down to the newly created node.

The process so far is similar to a conventional binary trie traversal, except that in the present case a sub-string (APp) of the prefix is used instead of the complete prefix (Line 3 in Algorithm

1. The special case in Compact-trie traversal occurs when a node with an outgoing epsilon link is encountered. At this node, the bit value is not examined, and the APpis not shifted, and only

the search moves to the node at the next level. This is because, at  connected nodes, there is only one link out and thus no decision needs to be taken.

Algorithm 1:Enhanced Compact-trie construction algorithm

Data:Enhanced Compact Prefix Table (E-CPT) consisting of set of prefixes Pi where Pi =

{APi

p, (M SBpi,LSBpi,Mpi,Lip,N HIpi)}, 0 6 i < N

Data:Root node Prootof Ctrie, Proot.lef t= NULL , Proot.right= NULL, Proot.size= 0

Data:Maximum node size Ptrie

Result: CTtrie structure

1 initialise i = 0;

2 foreach prefix piin CPT do

3 Pnode= binary_trie_traversal (APpi);

4 where Pnodeis the node reached through binary trie traversal

5 Prefix information Piis to be stored at Pnode

6 if Pnode.size < Ptriethen

7 Pnode.inf o= (M SBpi, LSBpi, Mpi, Lip, N HIpi) ;

8 Pnode.size++ ;

9 else

10 if Pnode.out== T RU E then

11 Pnode= Pnode.lef t;

12 Go to Line 5;

13 else

14 Create a new node Pnew;

15 Copy all prefix and pointer information from Pnodeto Pnew;

16 Pnode.lef t= Pnew;

17 Pnode.out= T RU E ;

18 Pnode.inf o= (M SBpi, LSBpi, Mpi, Lip, N HIpi) ;

19 Pnode.size= 1

The trie traversal will finally reach a node, and the APphas no more bits to be examined. It is at

this N odecurthat the prefix has to be inserted (Lines 3-5 in Algorithm 1) . If the total number of

prefixes stored at this node is less than the Ptrievalue, then the new prefix information is stored

at the node (Lines 6-8 in Algorithm 1). However, if the node already contains Ptrienumber of

prefixes then a new node is created (Line 14 in Algorithm 1), with an epsilon link from this node to the N odecur(Lines 10-12 in Algorithm 1), and the link from the parent of the N odecuris

now connected to the newly created node (Lines 15-17 in Algorithm 1). The prefix information is then copied into the new node and the size of the node is set (Lines 18-19 in Algorithm 1). The algorithm used for the creation of the Enhanced Compact-trie is listed in Algorithm 1 and an illustration of the insertion process for prefix P10(110111*) is presented in Figure 3.1. The E − CT rieas it was before insertion of prefix P10 is shown in Figure 3.1a. The APpof prefix

P10 is examined starting at the head node, moving down the trie, until the insertion location is identified as shown in Figures 3.1a to 3.1d . Since the node at the insertion location already contains 2 prefixes and the Ptrie value for the current example is 2, the node cannot hold any

more prefixes. A new node is created, and prefix P10 is stored in this node and the links reordered so that the left child of Node(P1,P2) is now Node(P10) and there is an epsilon link from Node(P10) to Node(P3,P9), denoted by a single thick vertical arrow out of the node in Figure 3.1e. The trie traversal process during the insertion of prefix P10 is indicated by the dotted arrows. The complete E − Ctriefor the E-CPT of Table 3.2 is shown in Figure 3.2.

Algorithm 2: E − Ctriesearch algorithm w/ Bloom filter

Data: Prootis the root node of the E − Ctrie

Data: Keyis the destination IP address to be searched

Result: N HIkeyis the longest matching next hop information

For head node with Lp== 0: matchConditionis

((M SBk == M SBp) and

(Mk> Mp))

For all other nodes: matchConditionis

((M SBk == M SBp) and (Mk== Mp) and (B0 == Lp) and (M APk > Lp > matchLength)) 1 Initialise N HIk= 0, trielevel = 0, Pnode= Proot matchLength = 0 ;

2 while Pnodeis not N U LL do

3 foreach prefix in Pnodedo

4 if matchCondition is T RU E then

5 N HIk= N HIp;

6 matchLength= Mp+ Lp + trielevel;

7 else

8 no updates to N HIkand matchLength ;

9 if Pnode.out == T RU Ethen

10 P nextnode= Pnode.lef t;

11 No updates to matchLength, trielevelor APk;

12 else

13 if B0== 0 then

14 P nextnode= Pnode.lef t

15 else

16 P nextnode= Pnode.right

17 reset matchLength to 0 ;

18 increment trielevelShift APkone bit left ;

19 Pnode= P nextnode

(a) E − Ctriebefore insertion of prefix P10 (b) Insert P10, current node has epsilon link, jump to epsilon connected node

(c) current node has regular links, examine AP=0*, follow left link down the trie, new AP=*

(d) current node has regular links, no more bits in AP. Insert prefix here, check Ptrievalue

(e) E − Ctrie after insertion of prefix P10

Figure 3.2: Complete Enhanced Compact-trie with epsilon links (E −Ctrie) after insertion of all prefixes from the Enhanced Compact Prefix Table of Table 3.2

Table 3.3: Definition of terms used in the E − Ctriealgorithm

Term Definition

B0 Most significant bit in APk

M APk lengthof({B0}*), where {B0}* is a continuous string of bits with the

same value as B0and including B0

trielevel Current level in the trie search. The head node is level 0

matchLength length of the matched prefix

Pnode.out condition that the node has an epsilon link to the next stage

The search procedure for the proposed Enhanced Compact-trie algorithm is listed in Algo- rithm 2, while the terms and definitions used in the Algorithm have been explained in Table 3.3. As an example of the search process, consider that the IP address (key) to be searched is ‘110001010001’. For this key M SBk = 1, Mk = 2 and APk = ‘0001010001’. IP lookup in an

E − Ctriestarts from the head node and traverses the trie using the bits in the APk. At each

stage, a node in the trie is examined, and the stored prefixes are checked for a prefix match by evaluating the matchCondition requirements specified in the Algorithm. If a match is found, the next hop information is stored, and the search moves on to the next level. The address of a child node in the next-level of the trie is determined by the ‘left’ or ‘right’ child pointer in the current node, based on the value of B0. If the node is an epsilon node, then the present B0

value is not checked, and the epsilon link is taken. While progressing the prefix search to the child node, the APkvalue is shifted one bit to the left if the child is connected over a regular

link, but is kept unchanged for epsilon-connected nodes.

The discussion so far suggests that the process of decomposing prefixes into the three sub- strings helps create a trie structure that is shorter than a binary trie although the storage re- quirement at each node in the trie is higher. The search through this Compact-trie structure is expected to be faster than a binary trie. However, it may be noted that the search process still involves accessing the prefix information at each level in the trie. The next section shall discuss further additions to the design that limit the number of accesses.

Related documents