Longest prefix match (LPM) algorithm implementation for a network processor
First Claim
1. A method for determining a longest prefix match for a variable length search key by a computer processing device, comprising:
- reading an input key as a search string;
using the N most significant bits of the input key as an address to index into a table representing a plurality of root nodes of search trees wherein each non-empty entry contains a pointer to a next branch in the search tree or a leaf;
determining if the pointer in a non-empty table entry points to a leaf or a next branch of the corresponding search tree;
reading the next branch contents if the pointer does not point to the leaf of the corresponding search tree and comparing the prefix represented by the next branch with the input key to find a distinguishing bit position;
reading a leaf pattern when the leaf of a corresponding search tree is reached and comparing the leaf pattern with the input key to determine if the leaf pattern matches the input key; and
returning the longest prefix match found for the input key to a requesting application.
1 Assignment
0 Petitions
Accused Products
Abstract
Novel data structures, methods and apparatus for finding the longest prefix match search when searching tables with variable length patterns or prefixes. To find the exact match or the best matching prefix, patterns have to be compared a bit at a time until the exact or first match is found. This requires “n” number of comparisons or memory accesses to identify the closest matching pattern. The trees are built in such a way that the matching result is guaranteed to be a best match, whether it is an exact match or a longest prefix match. Using the trail of all the birds and associated prefix lengths enables determination of the correct prefix result from the trail. By construction, the search tree provides the best matching prefix at or after the first compare during walking of the trail or tree.
-
Citations
41 Claims
-
1. A method for determining a longest prefix match for a variable length search key by a computer processing device, comprising:
-
reading an input key as a search string; using the N most significant bits of the input key as an address to index into a table representing a plurality of root nodes of search trees wherein each non-empty entry contains a pointer to a next branch in the search tree or a leaf; determining if the pointer in a non-empty table entry points to a leaf or a next branch of the corresponding search tree; reading the next branch contents if the pointer does not point to the leaf of the corresponding search tree and comparing the prefix represented by the next branch with the input key to find a distinguishing bit position; reading a leaf pattern when the leaf of a corresponding search tree is reached and comparing the leaf pattern with the input key to determine if the leaf pattern matches the input key; and returning the longest prefix match found for the input key to a requesting application. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
-
-
14. A computer readable medium containing a plurality of data structures for finding a longest prefix match for a variable length search key, comprising:
-
an input key that is to be searched; a direct table that stores a first address location for a search tree; a plurality of pattern search control blocks that each represent a branch in the search tree; at least one bird representing a partial match of the input key; and a plurality of leaves wherein each leaf is an address location for the result of a search. - View Dependent Claims (15, 16, 17, 18, 19, 20, 21, 22, 23, 24)
-
-
25. A computer readable medium containing a program product for determining a longest prefix match for a variable length search key, comprising:
-
program instructions that read an input key as a search string; program instructions that use the N most significant bits of the input key as an address to index into a table representing a plurality of root nodes of search trees wherein each non-empty entry contains a pointer to a next branch in the search tree or a leaf; program instructions that determine if the pointer in a non-empty table entry points to a leaf or a next branch of the corresponding search tree; program instructions that read the next branch contents if the pointer does not point to the leaf of the corresponding search tree and compare the prefix represented by the next branch with the input key to find a distinguishing bit position; program instructions that read a leaf pattern when the leaf of a corresponding search tree is reached and compare the leaf pattern with the input key to determine if the leaf pattern matches the input key; and program instructions that return the longest prefix match found for the input key to the requesting application. - View Dependent Claims (26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36)
-
-
37. A method for determining a longest prefix match for a variable length search key by a computer processing device, comprising:
-
reading an input key as a search string; using N bits of the input key as an address to access a table representing a plurality of root nodes of search trees wherein each non-empty entry contains a pointer; determining if the pointer in a non-empty table entry points to at least a leaf of the corresponding search tree; reading a leaf pattern in the leaf; comparing the leaf pattern with the input key, to determine if the leaf pattern matches the input key, only if the leaf is an end leaf; and returning the leaf pattern as the longest prefix match found for the input key to a requesting application only if there is an exact match between the leaf pattern and the input key. - View Dependent Claims (38, 39, 40)
-
-
41. A method for determining a longest prefix match for a variable length search key by a computer processing device, comprising
(a) reading an input key as a search string; -
(b) using the N most significant bits of the input key as an address to index into a table representing a plurality of root nodes of search trees wherein each non-empty entry contains a pointer to a next branch in the search tree or a leaf; (c) determining if the pointer in a non-empty table entry points to a leaf or a next branch of the corresponding search tree; (d) reading the next branch contents if the pointer does not point to a leaf of the corresponding search tree; (e) repeating acts (c) and (d) until a leaf is reached; reading a leaf pattern when the leaf of a corresponding search tree is reached and comparing the leaf pattern with the input key to determine if the leaf pattern matches the input key; and returning the leaf pattern as the longest prefix match found for the input key to a requesting application.
-
Specification