Method and apparatus for encoding a plurality of pre-defined codes into a search key and for locating a longest matching pre-defined code

A method of encoding a plurality of pre-defined codes into a search key and a method of using the search key to locate a longest matching pre-defined code to a given code is disclosed. Encoding the pre-defined codes into a search key involves producing a prefix node bit array (PNBA) having a plurality of bit positions corresponding to possible bit combinations of a bit string having a length equal to or less than the longest predefined code in said plurality of said pre-defined codes such that said bit positions are arranged by the lengths of said possible bit combinations and by numeric value of said possible bit combinations and to setting bits active in bit positions which correspond to bit combinations identified by said pre-defined codes. The method of locating involves producing a search mask encoding at least one portion of said given code and comparing said search mask to a search key having a Prefix Node Bit Array (PNBA) in which a bit is set active in at least one of a plurality of bit positions corresponding to possible bit combinations of bits in a bit string having a length equal to or less than the longest predefined code in said plurality of said pre-defined codes and arranged by the lengths of said possible bit combinations and by numeric values of said bit combinations, to identify a common active bit position in said search key and said search mask corresponding to a one of said pre-defined codes having a length greater than all others of said pre-defined codes which correspond to common active bit positions.

FIELD OF THE INVENTION

The present invention is directed to encoding a plurality of pre-defined codes into a search key and using the search key to locate a longest matching pre-defined code in response to a given code. More particularly, the invention is directed to encoding pre-defined codes into a search key where the pre-defined codes may be destination addresses for packet data, and using the search key to facilitate fast look up of routing or next hop information required to route a data packet to its destination address.

BACKGROUND OF THE INVENTION

The Internet is growing explosively. This explosive growth is reflected in both the number of devices using the Internet and the rate at which data packets are communicated between these devices.

When a sending device and a receiving device exchange a packet via the Internet, the packet generally passes through a number of network elements connected to the Internet between the sending device and the receiving device. A network element might include a switch, a router, or generally any network node. The packet is said to hop from one device to a next device in transit between the sending device and the receiving device via the Internet. Thus, a next device is often called a next hop.

Every device connected to the Internet is identified by a bit-sequence called an address. The number of Internet addresses is also growing explosively. In order to cope with this latter growth, the Internet Protocol (IP) supports multiple address encoding schemes, with the result that Internet address bit-sequences are not all the same length.

A sending device encodes within each packet an address corresponding to the receiving device, which is generally called a destination address. When a packet arrives at a network element, the network element examines the destination address encoded in the packet in order to select an appropriate next hop to forward the packet toward the receiving device. Generally, this next hop selection is made from among a relatively small number of devices that are proximate to the network element in the network.

Typically, the network element selects a next hop device using a routing table that correlates destination addresses to addresses or ports associated with the proximate devices. Usually, the routing table does not include a separate record for each destination address, but instead includes one record for each family of destination addresses, for example destination addresses sharing a common bit-sequence prefix. Thus in order to identify a correlated next hop device, the network element searches the routing table for the longest prefix that matches the destination address encoded in a packet being routed. However, efficiently searching the routing table for a longest matching prefix rather than a complete address can be complicated because there may exist several matching prefixes whereas only the longest matching prefix is being sought. Thus the search algorithm must locate a matching prefix and then determine that no longer matching prefix exists.

It will be appreciated that the explosive growth in both the number of potential destination addresses and the rate at which packets must be routed is placing significant demands on network elements. In fact, it is predicted that a new generation of network element will have to route millions of packets per second. Thus, the routing table lookup mechanism is critical to efficiently operating a network element and the Internet as a whole. Unfortunately, conventional routing table lookup mechanisms are insufficient for this task because they are too slow.

What is needed therefore is a way to encode pre-defined codes such as address-prefix bit-sequences and a way to locate a longest matching pre-defined code to a given code.

SUMMARY OF THE INVENTION

The present invention addresses the above needs by providing a method and apparatus for encoding a plurality of pre-defined codes into a search key and a method and apparatus for locating, in a list of pre-defined codes, a longest code matching a given code.

The method and apparatus for encoding involves using a processor circuit to produce a Prefix Node Bit Array (PNBA) having a plurality of bit positions corresponding to possible bit combinations of a bit string having a length equal to or less than the longest predefined code in the plurality of the pre-defined codes such that the bit positions are arranged by the lengths of the possible bit combinations and by numeric value of the possible bit combinations and to set bits active in bit positions which correspond to bit combinations identified by the pre-defined codes.

As the pre-defined codes are mapped into corresponding bit positions of the PNBA, a single bit can be used to represent the presence or absence of a possible bit combination. Consequently, the memory required to store the pre-defined codes, for look up purposes, is reduced.

Preferably, the method and apparatus also involve producing a next hop array associating bit positions of the PNBA which have active bits with muting information for use by a router to route a packet. Thus, the pre-defined codes are associated with respective bit positions in the PNBA and the respective bit positions in the PNBA are associated wit respective next hop information associated with the pre-defined codes.

In one embodiment, a plurality of PNBAs may be used to encode a plurality of subgroups of bits of the pre-defined codes. The use of a plurality of PNBAs may also involve producing an External Subtree Route Bit Array, having bit positions corresponding to possible further subgroups of bits of the pre-defined codes. In one embodiment, a single PNBA may be used to encode the plurality of pre-defined codes. Alternatively, in another embodiment, a plurality of PNBAs may be used, with associated External Subtree Route Bit Arrays (ESRBAs) as PNBA-ESRBA pairs in a single page of information, or as PNBA-ESRBA pairs on respective pages of information. Each page may include a next page pointer, pointing to a next page in a plurality of respective pages to be searched after considering a given page in a search.

The method described above facilitates locating a longest code matching a given code, in the list of pre-defined codes. This has particular use in routing packets in a computer network, for example, wherein the method can be used to locate routing information or next hop information based upon a destination address of a packet. If a destination address of the packet is considered to be a given code and destination prefixes are considered to be a list of pre-defined codes, the apparatus provides a method of locating in a list of pre-defined codes a longest code matching a given code. The method involves producing a search mask encoding at least one portion of the given code, and comparing the search mask to a search key having a Prefix Node Bit Array (PNBA). In the PNBA, a bit is set active in at least one of a plurality of bit positions corresponding to bit combinations of bits in a bit string having a length equal to or less than the longest predefined code in the plurality of the pre-defined codes and arranged by the lengths of the bit combinations and by numeric values of the bit combinations. The purpose of comparing is to identify a common active bit position in the search key and the search mask corresponding to a one of the pre-defined codes having a length greater than all others of the pre-defined codes which correspond to common active bit positions.

Effectively, the need to compare bits of the given code with bits of pre-defined codes in the list of such codes is eliminated by use of the search mask and the search key.

If the search key includes a single prefix node bit array, then the search mask is produced to include a single prefix node bit array mask of the same length, for comparison with the prefix node bit array. This may be done by logically ANDing the PNBA mask with a search PNBA of the search key to produce a resultant PNBA. A highest bit position in the resultant PNBA identifies a longest code of the predefined codes which is the longest code matching the resultant PNBA.

When the method is used to locate next hop information for a packet having a destination address which acts as the given code, the next hop information can be located by finding the information associated with the highest ordered bit position, which is set active in the resultant PNBA.

Alternatively, a plurality of PNBA masks may be produced to encode possible bit subcombinations of the given code. These PNBA masks can be used with a plurality of PNBAs to consider subcombinations or subprefixes of the given code and the predefined codes to reduce the amount of memory to encode the predefined codes. In such an embodiment, a PNBA mask representing a first k bits of the given code is compared with a first PNBA encoding a first k bits of the pre-defined codes to determine a potential longest matching subprefix.

An External Subtree Route Bit Array (ESRBA) associated with the first PNBA is then compared with a first ESRBA mask derived from the given code to determine whether or not further searching of a further PNBA is required. If not, then in the case where the given code is a destination address for example, the result of the comparison between the first PNBA and the first PNBA mask can be used to determine next hop information. Alternatively, if further searching is to be performed, then a second PNBA is compared with a second PNBA mask to produce a further potential longest matching code and a second ESRBA and a second ESRBA mask are compared to determine whether or not further searching is required. This process is continued until no further searching is required, in which case the last determined longest matching code is taken as the actual longest matching code.

The PNBAs and ESRBAs of the multiple PNBA embodiment may be stored in a plurality of pages comprising a plurality of PNBA-ESRBA pairs on a few pages or single PNBA-ESRBA pairs on respective pages.

The use of multiple pages requires a larger number of memory unit accesses, but requires less memory, whereas the fewer number of pages requires fewer accesses, but more memory unit space for storage. Consequently, trade offs between memory availability and memory accesses can be made.

DETAILED DESCRIPTION

Referring toFIG. 1, a network employing a network element or network node10, according to a first embodiment of the invention is shown generally at12. In this embodiment, the network12is a packet network, such as an internet or intranet, for example. The network element may be a router, or a switch, for example, and generally acts to forward packets received from a packet network to other network elements en route to a destination device identified by a destination address in a packet header of the packet.

The network element10has a plurality of input ports18and a plurality of output ports20for receiving and transmitting signals respectively on the network12. There may be a plurality of network elements10on the network12, each network element representing a “hop” in a path from the sender of a packet to a receiver of the packet.

Referring toFIG. 2, the network element10is illustrated in greater detail. Essentially, the network element encodes and associates a plurality of pre-defined address prefixes with a plurality of corresponding output ports20in such a manner that when a packet is received at the network element10, the packet is routed to an output port associated with the longest pre-defined address prefix matching a destination address encoded in the packet. In the present embodiment, the network12may be an Internet Protocol (IPv4) network and accordingly, the destination address encoded in the packet is 32-bits long. However, for the purposes of explanation a 5-bit destination address will be used herein.

To route a packet from an input port18to an output port20in the manner described above, the network element10includes a processor circuit30in communication with a random access memory (RAM)32and a read only memory (ROM)34. The processor circuit30is also in communication with an input/output (I/O) interface38, which is connected to receive packets from the input ports18and to transmit packets to appropriate output ports20in response to directions provided by the processor circuit30in accordance with the present invention.

To achieve this, the ROM34is programmed with codes for directing the processor circuit30to perform certain functionality, including both conventional functionality of a network element10and the novel functionality of the present invention. The ROM34may be programmed with codes downloaded via the network12from a remote computer (not shown), or may have a media interface (not shown) for reading codes from a computer readable medium such as a CD-ROM, diskette or any other computer readable medium accessible by the processor circuit30. In general, at least one set of codes programmed into the ROM configure the processor circuit to encode a plurality of predefined codes into a search key by producing a Prefix Node Bit Array (PNBA) having a plurality of bit positions corresponding to possible bit combinations of a bit string having a length equal to or less than the longest predefined code in the plurality of the pre-defined codes such that the bit positions are arranged by the lengths of the possible bit combinations and by numeric value of the bit combinations, and by setting active bits in bit positions which correspond to bit combinations identified by the pre-defined codes.

Another set of codes programmed into the ROM configures the processor circuit to locate, in a list of pre-defined codes, a longest code matching a given code by producing a search mask encoding at least one portion of the given code and comparing the search mask to a search key having a Prefix Node Bit Array (PNBA) in which a bit is set active in at least one of a plurality of bit positions corresponding to possible bit combinations of bits in a bit string having a length equal to or less than the longest predefined code in the plurality of the pre-defined codes and arranged by the lengths of the possible bit combinations and by numeric values of the bit combinations, to identify a common active bit position in the search key and the search mask corresponding to a one of the pre-defined codes having a length greater than all others of the pre-defined codes which correspond to common active bit positions.

More particularly, in accordance with the first embodiment of the invention, the codes programmed into the ROM include a first segment of codes33for directing the processor circuit to act as an encoder to encode the pre-defined address prefixes for facilitating fast identification of an output port to which an incoming packet is to be routed and a second segment of codes35for directing the processor circuit30to act as a router by using the encoded pre-defined address prefixes to identify an output port to which an incoming packet is to be routed.

The pre-defined address prefixes which are to be encoded by the processor circuit30are provided by a routing authority such as an owner of the network12or network element10to identify corresponding output ports20of the network node which are to receive packets bearing certain address prefixes. For example, the network authority may specify that packets having the single binary value “0” as the longest matching portion of their destination address with a pre-defined address prefix are to be routed to port number one. In general, the network authority provides to the network element10a list of pre-defined address prefixes referred to hereafter as listed prefixes, together with associated next hop port information, such as an identification of the output port to which a packet is to be routed when at least a prefix of its destination address matches one of the listed prefixes. Preferably, the listed prefixes are pre-sorted by length and bit position entries, in ascending order, into a sorted list or table40of routing records42as shown in FIG.3.

Each routing record42includes three fields, namely a prefix field44, a length field46, and a next-hop field48. The prefix field44holds codes representing a listed prefix for which next hop information exists. The length field46holds codes representing the string length of the listed prefix represented in the prefix field44. The next-hop field48holds codes representing the next hop information, in particular, codes identifying one of the output ports20to which a packet received at an input port18should be directed when the associated listed prefix is the longest listed prefix matching at least a portion of a destination address encoded in a received packet.

In this embodiment, the routing records42have been presorted in the sorted list40, first according to the binary value of the prefix strings stored in the prefix field44and second according to the string lengths stored in the length field46.

Encoding According to the First Embodiment

The processor circuit30shown inFIG. 2ultimately encodes a search key using the listed prefixes shown in FIG.3and produces a next hop array associating bit positions of the search key with next hop information to facilitate fast location of the identity of the output port to which an incoming packet is to be routed.

In this embodiment, generally, the search key includes a Prefix Node Bit Array (PNBA) having bit positions associated with respective listed prefixes. In the general case, all possible address prefixes have corresponding bit positions in the PNBA. Consequently, the size of the PNBA depends upon the maximum length of the listed prefixes. In general, the PNBA has 2n+1−2 bit positions.

In the listed prefixes shown inFIG. 3, the longest listed prefix is seen on Row10of the list and has a length of 5 bits. From the general relationship provided above, there are 62 possible address prefixes or bit combinations of bit strings having a length equal to or less than the longest address prefix or pre-defined code and each of these is shown adjacent its corresponding bit position in FIG.4.FIG. 4also shows that the bit positions of the PNBA are arranged in order by ascending lengths of possible bit combinations and by ascending numeric value of corresponding possible bit combinations. InFIG. 4, the listed prefixes provided in the sorted list shown inFIG. 3are highlighted in bold type. InFIG. 5, a PNBA for these listed prefixes is shown at49and it can be seen that bits in bit positions1,2,3,4,6,9,10,17,29and62are set active as there are corresponding listed prefixes in the prefix table shown in FIG.3.

In general, referring toFIG. 6, for the ithrouting record, a bit in a corresponding bit position biof the PNBA is set active, according to the following expression:bi=(∑ω=1S⁢2ω-1)+value⁡(S),(1)
wherei=index number identifying the ithrouting record;bi=bit position of the PNBA corresponding to the ithrouting record, in which the bit is set active|S|=length of the prefix string as indicated in the prefix length field46of the ithrouting record; andvalue(S)=decimal value of the listed prefix represented in the prefix field44of the ithrouting record.

After determining which bit positions of the PNBA are to be set to one, indicators of these bit positions may be added to PNBA bit position fields50associated with respective listed prefixes of the listed prefix table, to produce an enhanced listed prefix table52as shown in FIG.6. This table has all of the columns of the table40shown in FIG.3and has further columns for PNBA bit position fields50and decimal values of prefix string fields54.

After producing the enhanced listed prefix table shown inFIG. 6, the next hop information associated with the records therein is sorted according to the associated PNBA bit position indicated in the PNBA bit position field50of each record, to produce a next hop array70as shown inFIG. 7having next hop records such as record60with next hop information fields62and associated PNBA bit position fields64. Thus, the processor circuit is configured to produce a next hop array associating bit positions of the PNBA which have active bits with routing information for use by a router to route a packet.

Locating and Routing According to the First Embodiment

The router code segment executed by the processor circuit uses the PNBA shown inFIG. 5to determine a position in the next hop array70shown inFIG. 7to locate the appropriate next hop information in response to a destination address in a packet received at the network element10.

In this embodiment, the router code segment directs the processor circuit30to use the destination address of a received packet to determine a longest matching listed prefix, to find the PNBA bit position of the longest matching prefix and to find the next hop information from the next hop array70using this PNBA bit position.

More particularly, determining a longest matching listed prefix is achieved by first producing a PNBA mask encoding at least a portion of the destination address or more generally, at least a portion of a given code, by applying a procedure similar to that used to generate the PNBA to the destination address in the received packet. In particular, using the expression:j=∑ω=1Si⁢2ω-1+value⁡(Si),(2)
whereSi=one of the prefix substrings of the destination address or given code|Si|=the length of Sivalue(Si)=the decimal value of Si

Since the PNBA was produced using k=5 a PNBA mask having 2k+1−2=62 bit positions is produced with bits in bit positions being set according to the above expression. For example, if the destination address is 11101, a PNBA mask as shown at66inFIG. 8is produced, in which bit positions2,6,14,29and60are set active.

The PNBA mask66shown inFIG. 8is then ANDed with the PNBA49shown inFIG. 5, in which bit positions1,2,3,4,6,9,10,17,29and62are set active, to produce a resultant PNBA as shown at68inFIG. 9in which bit positions2,6and29are set active. Bit position29represents the longest matching listed prefix: 1110. It no such bit position exists, that is, the resultant PNBA is zero, then there is no next hop information in the next hop array70shown in FIG.7and the packet is routed to a default next hop port.

In this example, the resultant PNBA68is non-zero, therefore the position in the next hop array70at which the corresponding next hop information is stored is given by the following expression:∑l-1n-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)+value(next⁢⁢hop⁢⁢in⁢⁢the⁢⁢pointers⁢⁢array),(3)
wherePNBA(i)=0 for i<1.

Using bit position29determined above, the relation produces the following:∑l=129-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)=8;andvalue (next hop in the pointers array)=18+1=9

Consequently, the ninth position in the next hop array holds the appropriate next hop information. The processor circuit is then directed to forward the packet to the output port associated with the information stored in the ninth position of the next hop array70.

Encoding According to a Second Embodiment

It will be appreciated thatFIG. 5indicates that many of the bit positions in the PNBA of the first embodiment have a zero, and therefore only a relatively small number of PNBA bit positions are active. In other words, only a small number of the possible address prefixes are used. Referring toFIG. 10, a prefix table is shown at71in which the table ofFIG. 3is repeated with further columns for a decimal value of a bit prefix field73, a decimal value of sub-prefix length field75, a PNBA bit position field77and a PNBA bit value field79. If a box81is drawn around the first two bits of each listed prefix it can be seen that all but five of the listed prefixes are fully defined by the bits within the box. These bits may be regarded as sub-prefixes of the listed prefixes. A second embodiment of the invention involves producing a search key by encoding sub-prefixes of the listed prefixes or more generally sub groups of bits of the pre-defined codes in a plurality of smaller PNBAs to reduce the amount of memory required to store the search key.

In this second embodiment the sub-prefixes shown within the box81are mapped to their own sub-prefix PNBA using the method described in connection with the first embodiment of the invention. In this example the box separates a plurality of two or less bit sub-prefixes which map into a first PNBA having six possible address sub-prefixes which are shown in FIG.11. The size of the first PNBA in this embodiment depends on the number of bits k used as a sub-prefix. In this embodiment k=2. In general, in this embodiment, the first PNBA has (2k+1−2) bit positions. The sub-prefixes found inFIG. 10correspond to bit positions1,2,3,4, and6as shown in FIG.11. Consequently, bits in these bit positions are set to one in the first PNBA83while all remaining bit positions, in this case only bit position5, are set to zero, as shown in FIG.12.

In general, the bits in a PNBA are set according to the expression:j=∑ω=1Sk⁢2ω-1+value⁡(Sk),(4)
where:|Sk| is the length of the ithsub-prefix; andSkis the last portion of the ithprefix,value(Sk)=the decimal value of the k-bit or less ithsub-prefix.

After determining which bit positions of the first PNBA69are to be loaded with a one, indicators of these bit positions may be inserted into PNBA bit position fields77, in respective records associated with respective listed prefixes in the listed prefix table as shown in FIG.10. In addition, the associated PNBA bit value stored in each bit position may be added to the PNBA bit value fields79of the corresponding records shown inFIG. 10to indicate which of the records are to be used to produce the next hop array. Then, the next hop information associated with records having a PNBA bit value of one in their respective PNBA bit value field are ordered according to the associated first PNBA bit position to produce a next hop array72up to a first PNBA bit position field column85as shown inFIG. 13, wherein the position of next hop information in the next hop array is determined by the contents of the associated first PNBA bit position fields77of the indicated records in the table shown in FIG.10.

As shown inFIG. 14, a next hop pointer74is associated with the first PNBA69to indicate a position in the next hop array72at which the next hop information for the first listed sub-prefix encoded by the first PNBA69is located.

Since some of the sub-prefixes are part of listed prefixes which are longer than two bits, it is necessary to use another code, herein referred to as an External Subtree Root Bit Array (ESRBA) to identify those sub-prefixes which are part of a longer, listed prefix. In general the ESRBA has 2kbit positions, corresponding to the possible bit combinations of k bits. In the example given, with k=2, there are 4 possible bit combinations and therefore as shown inFIG. 15, a first ESRBA76has 4 bit positions representing the bit combinations 00,01,10 and 11 respectively.

As shown inFIG. 10, 00 is a sub-prefix of the third listed prefix 0010 and therefore the first bit position of the first ESRBA is set to one. Similarly, 01 is a sub-prefix of 010 and 011 and therefore the second bit position of the first ESRBA is set to one. The sub-prefix 10 is not found in the first k bits of the records in the table shown in FIG.10and therefore the third bit position of the first ESRBA is set to 0. Finally, the sub-prefix 11 is shown in the table and therefore the fourth ESRBA bit position is set to one. The first ESRBA76thus has the value 1101, as shown inFIGS. 14 and 15.

Under each sub-prefix, there may be further combinations of k or less bits and therefore a separate PNBA is produced to encode the possible k bit sequences after each sub-prefix having a length longer than k. In the example shown, the sub-prefixes which have a length longer than 2 are on rows3,5,6,9and10and have the values 00, 01 and 11. Thus, as shown inFIG. 14, a second PNBA78is produced for all of the possible bit combinations which follow the sub-prefix 00, a third PNBA80is produced to encode all of the bit combinations which follow the sub-prefix 01, and a fourth PNBA82is produced to encode all of the bit combinations which follow the sub-prefix 11.

As shown inFIG. 10, for the second PNBA78, the only bit combination which follows the 00 prefix is 10, which corresponds to bit position5of the two-bit PNBA shown in FIG.11. Bit position five is thus set with a one and all other bit positions are set to zero. Consequently, as shown inFIG. 14, the second PNBA78has the value 000010.

As there is only one bit combination which follows the 00 prefix, there is only one record and the next hop information for the corresponding listed prefix, that is, for the listed prefix in row3of the table shown inFIG. 10is appended to the bottom of the next hop array72to form a sixth position of that array, as shown in a second PNBA bit position field column87of the next hop array72shown in FIG.13.

As shown inFIG. 14, a second next hop pointer84is associated with the second PNBA78to indicate the position, in the present example position6, of the next hop array72at which next hop information for the first listed prefix encoded by the second PNBA78is stored.

As shown inFIG. 10, for the third PNBA80, there are two combinations which follow the 01 sub-prefix: 0 and 1 respectively. These combinations correspond to the first and second bit positions of the two-bit PNBA shown in FIG.11. Bit positions1and2of the third PNBA80are thus set to one and all other bit positions are set to zero. Consequently, as shown inFIG. 14the third PNBA80has the value 110000.

As there are two combinations which follow the 01 sub-prefix, the corresponding listed strings are appended to the next hop array72shown in FIG.13. Thus, the next hop information for the listed strings on rows5and6of the listed prefix table inFIG. 10are appended to the next hop array72to occupy positions7and8of the next hop array as shown in a third PNBA bit position column89in FIG.13.

As shown inFIG. 14a third next hop pointer86is associated with the third PNBA80to indicate the address of the next hop array72at which next hop information for the first listed prefix encoded by the third PNBA80is stored.

As shown inFIG. 10, for the fourth PNBA82, there is one combination which follows the 11 sub-prefix, and has a length of 2 or less and that is, 10, which correspond to bit positions5of the two-bit PNBA shown in FIG.11. Bit positions five of the fourth PNBA is thus set to one and all other bit positions are set to zero. Consequently, as shown inFIG. 14, the fourth PNBA82has the value 000010.

Therefore the next hop information associated with only this one sub-prefix can be appended to the next hop array72. Consequently, the next hop information from the listed prefix on row nine of the listed prefix table shown inFIG. 10is appended to occupy position nine of the next hop array72as shown in the fourth PNBA bit position field column91in FIG.13.

As shown inFIG. 14a fourth next hop pointer88is associated with the fourth PNBA82to indicate the position of the next hop array72at which next hop information for the first listed prefix encoded by the fourth PNBA82is stored.

As shown inFIG. 14, second, third and fourth ESRBAs90,92and94may also be associated with each of the second through fourth PNBAs, although in this embodiment, the ESRBAs for the second and third PNBAs contain all zeros because there are no further bits after those already encoded in some of the listed prefixes.

The fourth PNBA82has a non-zero fourth ESRBA94because, as shown inFIG. 10, the listed prefix shown in row10has at least one more bit, that is, it has a fifth bit whereas all of the other listed prefixes have four bits. Consequently, as shown inFIG. 14the fourth ESRBA has the value 0001 and a fifth PNBA96is required to encode the fifth bit of the listed prefix in row10of the listed prefix table shown in FIG.10. Following the procedure above, the fifth PNBA96must encode all of the possible k bit sequences following the bit combination 11 under the sub-prefix 11. The fifth PNBA96also has six bits, like all of the other PNBAs of this embodiment. Still referring toFIG. 10, the only bit combination following the bit combination 1111 is 1, which corresponds to the second bit position of the fifth PNBA96. Consequently, as shown inFIG. 14the fifth PNBA96has the value 010000.

As shown inFIG. 10, as there is only one bit combination which follows the 1111 bit combination, there is only one record and therefore the next hop information for the corresponding listed prefix, that is, the listed prefix in row10of the table is appended to the bottom of the next hop array72to form a tenth position of that array as shown in FIG.13.

As shown inFIG. 14a fifth next hop pointer98is associated with the fifth PNBA96to indicate the position of the next hop array72at which next hop information for the first listed prefix encoded by the fifth PNBA96is stored.

The fifth PNBA96may also have associated with it a fifth ESRBA100, although in this example this ESRBA will have all zeros, i.e. 0000, since there are no further bits following the bit combination 11111.

As shown inFIG. 14, the first through fifth PNBAs and their associated ESRBAs and next hop pointers are best arranged into a search key102comprising first, second, third, fourth and fifth pages102,104,106,108and110with directions for a second routing program to determine which page to address if further searching can be performed after a page has been considered. In general, any page having a non-zero ESRBA must have a next page pointer for this purpose. Thus the first page103has a next page pointer111pointing to the second page104to direct the routing program to the second page if further searching can be done after considering page one. The second and third pages,104and106each have no next page pointers as they already fully encode all listed bit combinations after their respective sub-prefixes 00 and 01. The fourth page108has a next page pointer113pointing to the fifth page, since the fourth page has a fourth ESRBA94indicating that more bits follow after the bit combination 1111 and since the fifth page represents the encoding of such bits under this bit combination. The fifth page has no next page pointer as the fifth PNBA on the fifth page fully encodes all listed prefixes after the bit combination 1111.

The search key102represents full encoding of the listed prefixes and is operable to be used by a routing program according to the second embodiment of the invention, to determine a next hop address for a packet received at the network element.

Locating and Routing According to the Second Embodiment

In this embodiment, like the first embodiment, the router code segment directs the processor circuit to use the destination address of a received packet to determine a longest matching listed prefix from the search key and to find the next hop information from the next hop array72using the PNBA bit position associated with the longest matching listed prefix.

More particularly, determining a longest matching listed prefix is achieved by first producing PNBA masks for each k or less bit combination in the destination address, using a procedure similar to that used to generate the PNBAs of the search key102shown in FIG.14.

In particular, for each k-bit combination in the destination address a (2k+1−2)-bit PNBA mask is generated wherein bit positions of the PNBA mask are set to 1 at position j according to the expressionj=∑i=1Si⁢2i-1+value⁡(Si),(5)
where:Si=one of the prefix substrings of the first, second, . . . nthk-bit substring of the destination address;|Si|=the length of Si, andvalue(Si) is the decimal value of Si.

In this embodiment, since the search key described above was generated with k=2, the PNBA masks should also be generated using k=2.

For example, if the destination address is 11101 it has three 2 or less bit combinations which are 11, 10 and 1.

The first set of two bits is 11 and therefore the second and sixth bit positions of a first PNBA mask produced according to the relation above, have ones, whereas the remaining bit positions have zeros, as shown in FIG.16. This first PNBA mask is for searching the first page103of the search key102.

The second set of two bits is 10 and therefore the second and fifth bit positions of a second PNBA mask114produced according to the relation above, have ones, whereas the remaining bit positions have zeros, as shown in FIG.17. This second PNBA mask is for searching the next page indicated by the next page pointer111associated with the first page103shown in FIG.14. Thus, in the embodiment shown, this second PNBA mask is for searching the second page104of the search key102.

The third set of two bits is only one bit long and is the single bit 1. Therefore only the second bit position of a third PNBA mask116produced according to the relation above, has a one, whereas the remaining bit positions have zeros, as shown in FIG.18. This third PNBA mask116is for searching the next page indicated by the next page pointer associated with the previous page. In general to avoid wasting computation time unused PNBA masks are not generated, in practice.

After producing the first, second and third PNBA masks shown inFIGS. 16-18, these masks are then compared against PNBAs of appropriate pages in the search key102, the appropriate pages being determined as described below.

The first PNBA mask112shown inFIG. 16is compared against the first PNBA69of the first page103shown inFIG. 14by ANDing the first PNBA69and the first PNBA mask112together to produce a first resultant PNBA118as shown in FIG.19.

In the first resultant PNBA118the bit position n associated with possible next hop information is the highest numbered bit position with a bit value of one. As shown inFIG. 19, in this embodiment that position is position6. If no such bit position exists, then there is no next hop information in the next hop array and the packet is routed to a default port.

If the bit position located above is greater than or equal to 1, then the next hop information is given at a position in the next hop array72shown inFIG. 13as determined by the following expression:∑i=1n-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)+value(next⁢⁢hop⁢⁢pointer⁢⁢in⁢⁢the⁢⁢page),(6)
wherePNBA(i)=0 for i<1.

Using the above expression, with position6determined from FIG.19.n=6∑i=16-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)=4;andvalue(next hop pointer in the page)=14+1=5.

Consequently, possible next hop information is given in the fifth position of the next hop array72shown in FIG.13. An index to this fifth position is stored for later use.

Before deciding to use the possible next hop information determined above as the actual next hop information, it is necessary to determine whether or not any longer matching listed prefix is encoded. To do this it is necessary to determine which page should be used next in looking for a longest match. To determine which page is to be used next, it is necessary to produce an ESRBA mask for each PNBA mask. In general, each ESRBA mask has 2kbits with bits at positions p set to 1 according to the following expression:
p=largest PNBA mask bit position−2k−1,  (7)

In the present example k=2 and the largest PNBA mask bit position which is set to one in the first PNBA mask112shown inFIG. 16is6. Therefore as shown inFIG. 20the fourth bit position of a first ESRBA mask120is set to one while all other bit positions are set to zero. Similarly, the largest PNBA mask bit position which is set to one in the second PNBA mask114shown inFIG. 17is5and therefore as shown inFIG. 21the third bit position of a second ESRBA mask122is set to one. Finally, the largest PNBA mask bit position which is set to one in the third PNBA mask116shown inFIG. 18is2and therefore as shown inFIG. 22no bits in a third ESRBA mask124are set to one, rather they are all set to zero.

After having produced the above ESRBA masks, the first ESRBA mask120shown inFIG. 20is ANDed with the first ESRBA76of the first page103shown in FIG.14. This produces a first resultant ESRBA126as shown in FIG.23. Next it is necessary to locate the bit position m of the first resultant ESRBA126which has a one. If no such bit position exists, then there is no next page to continue the search and the search is terminated, in which case the pointer to the next hop information located above in connection with the first resultant PNBA118shown inFIG. 19is used as the actual pointer to the next hop information. In this example, the next hop information associated with the fifth position in the next hop array72shown inFIG. 13would be used.

If m≧1, then the next page p is given according to the following expression:p=∑i=1m-1⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢A⁡(i)+value(next⁢⁢page⁢⁢pointer⁢⁢in⁢⁢the⁢⁢current⁢⁢page),(8)
whereESRBA(i)=0 for i<1.

In the present example, the bit position in the first resultant ESRBA126shown inFIG. 23which has a one is4and therefore m=4.

Using the above expression,m=4,∑i=14-1⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢A⁡(i)=2;andvalue (next page pointer in the current page)=22+2=4.

Consequently, the next page to be considered is the fourth page108of the search key102shown in FIG.14. Therefore the second PNBA mask114shown inFIG. 17is to be ANDed with the fourth PNBA82shown inFIG. 14to determine a second resultant PNBA128shown in FIG.24.

In the second resultant PNBA128the bit position associated with possible next hop information is the highest numbered bit position with a bit value of one. As shown inFIG. 24, in this embodiment that position is position5. If no such bit position exists, then the packet is routed to the port identified by the position determined in considering the first resultant PNBA, which in this embodiment would be the fifth position.

If the bit position is greater than or equal to 1, then the next hop information is given at a position in the next hop array determined by the following expression:∑i=1n-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)+value(next⁢⁢hop⁢⁢pointer⁢⁢in⁢⁢the⁢⁢page),(9)
wherePNBA(i)=0 for i<1.

In this example, using the above expression, with position5(n=5), the entry in the next hop array72shown inFIG. 13is given at the following location:∑i=15-1⁢P⁢⁢N⁢⁢B⁢⁢A⁡(i)=0;andvalue (next hop pointer in the page)=90+9=9.

Consequently, the ninth position in the next hop array is the next most possible position which holds the necessary next hop information, if no further searching is to be done.

To determine whether or not any further searching is to be done, it is necessary to determine whether or not there is a next page on which further searching can be performed. To find which page, if any with which to continue the search, the second ESRBA mask122shown inFIG. 21is ANDed with the ESRBA associated with the current page under consideration. In this embodiment the current page under consideration is the fourth page108, so the second ESRBA mask122is ANDed with the fourth ESRBA94shown in FIG.14and this produces a second resultant ESRBA130as shown in FIG.25.

The next page on which to continue searching would be given by examining the second resultant ESRBA130to determine the bit position having a one and using the number of that position in expression (8) above for determining a next page. In the present example, the second resultant ESRBA130has all zeros and therefore, there are no further pages on which to continue the search. The search process is therefore terminated here and the next hop information stored at the ninth position of the next hop array72shown inFIG. 13contains the next hop information corresponding to the longest matching prefix. The packet may then be routed to a port associated with next hop information specified by the ninth position of the next hop array. If no next hop entry location is found by the time the search process is completed, the packet is routed to the default port.

Encoding According to a Third Embodiment

Referring toFIG. 26, in accordance with a third embodiment of the invention, a search key comprising a single page, comprising first, second, third, fourth and fifth PNBA-ESRBA pairs140,142,144,146and148is shown generally at138. In this embodiment, the five PNBAs and ESRBAs comprising the PNBA-ESRBA pairs are the same as the first, second, third, fourth and fifth PNBAs69,78,80,82and96and first, second, third, fourth and fifth ESRBAs76,90,92,94and100of the second embodiment, and are produced in the same manner. They are merely listed differently, in a single page format. In addition, the generic page in this embodiment includes a next hop pointer150and a next page pointer152. In generating successive PNBAs, the same next hop array as shown inFIG. 13is also produced. ThusFIG. 13represents the next hop array produced by either of the second or third embodiments.

Locating and Routing According to the Third Embodiment

In this embodiment, like the first and second embodiments, the router code segment directs the processor circuit30to use the destination address of a received packet to determine a longest matching listed prefix from the search key and to find the next hop information from the next hop array72using the PNBA bit position associated with the longest matching prefix.

More particularly, determining a longest matching listed prefix is achieved by first producing PNBA masks for each k or less bit combination in the destination address, using the procedure described above in connection with the second embodiment. Consequently, the same first, second and third PNBA masks112,114, and116shown inFIGS. 16,17and18respectively are produced.

The first PNBA mask112is ANDed with the first PNBA69in the single page shown inFIG. 26to produce a first resultant PNBA118which is the same as the first resultant PNBA118generated in accordance with the second embodiment of the invention and shown in FIG.19.

In the first resultant PNBA118the bit position associated with possible next hop information is the highest numbered bit position with a bit value of one. As shown inFIG. 19, that position is position6. If no such bit position, n, exists in the resultant PNBA, then there is no next hop information in the next hop array.

If n≧1, then the location of the next hop information in the next hop array72shown inFIG. 13is given by the following expression:∑j=1i=1⁢∑i=1PNBAj⁢P⁢⁢N⁢⁢B⁢⁢Aj⁡(i)+∑i=1n-1⁢P⁢⁢N⁢⁢B⁢⁢Ai⁡(i)+value(next⁢⁢hop⁢⁢pointer⁢⁢in⁢⁢the⁢⁢page),(10)
wherePNBAt(i)=0 for i<1 or t<0;|PNBA| is the length of the PNBA string; andPNBAtis the tthPNBA in the page and the current PNBA being examined.

In this example there are five PNBA-ESRBA pairs.

Consequently, possible next hop information is given in the fifth position of the next hop array72shown in FIG.13.

Before deciding to use the possible next hop information determined above as actual next hop information, it is necessary to determine whether or not any longer matching listed prefix is encoded. To do this it is necessary to determine which PNBA-ESRBA pair in the current page or some other page if there is one, should be used next in looking for a longest match. To determine which PNBA-ESRBA pair is to be used next, it is necessary to produce an ESRBA mask for each PNBA mask. In general, each ESRBA mask has 2kbits with bits at positions p set to 1 according to the following expression:
p=largest PNBA mask bit position−2k−1,  (11)

The three PNBA masks are shown at112,114and116respectively inFIGS. 16,17and18respectively. In the present example k=2 and the largest PNBA mask bit position which is set to one in the first PNBA mask112shown inFIG. 16is6. Therefore as shown inFIG. 20the fourth bit position of the first ESRBA mask120is set to one while all other bit positions are set to zero. Similarly, the largest PNBA mask bit position which is set to one in the second PNBA mask114shown inFIG. 17is5and therefore as shown inFIG. 21the third bit position of the second ESRBA mask122is set to zero. Finally, the largest PNBA mask bit position which is set to one in the third PNBA mask116shown inFIG. 18is2and therefore as shown inFIG. 22no bits in the third ESRBA MASK124shown inFIG. 22are set to one, rather they are all set to zero.

After having produced the above three ESRBA masks, the first ESRBA mask120shown inFIG. 20is ANDed with the first ESRBA76of the first PNBA-ESRBA pair140shown in FIG.26. This produces a first resultant ESRBA126as shown in FIG.23. Next it is necessary to locate the bit position m of the first resultant ESRBA126which has a one. If no such bit position, m, exists, then there is no next page to continue the search and the search is terminated, in which case the pointer to the next hop information located above in connection with the first resultant PNBA shown inFIG. 19is used as the actual pointer to the next hop information.

If m≧1, then the next PNBA-ESRBA pair to consider is an entry in the current page or in another page as given by the following expression:r=∑j=1t-1⁢∑i=1ESRBAj⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢Aj⁡(i)+∑i=1m⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢Ai⁡(i)+1,(12)
where:ESRBAt(i)=0 for i<1 or t<0,|ESRBA| is the length of the ESRBA string,ESRBAtis the tthESRBA in a page and the current ESRBA being examined; andu is the number of PNBA-ESRBA pairs stored in a page.

In this example there are five PNBA-ESRBA pairs.

Using the above expression in the present example:r=∑j=10⁢∑i=1ESRBAj⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢Aj⁡(i)=0;and⁢⁢∑i=16⁢E⁢⁢S⁢⁢R⁢⁢B⁢⁢Ai⁡(i)=30+3+1=4.

Note that r=4≦u=5. Consequently, the fourth PNBA-ESRBA pair of the current page is the next PNBA-ESRBA pair to be considered.

If r>U, then the next PNBA-ESRBA pair is determined (according to the relation v=(r−1) mod u+1 and this remainder identifies the PNBA-ESRBA pair of another page identified according to the following expression:Next⁢⁢page=next⁢⁢page⁢⁢pointer⁢⁢in⁢⁢current⁢⁢page+⌊ru⌋.(13)

In the present example, to this point the next PNBA-ESRBA pair in the present page has been identified as the fourth PNBA-ESRBA pair146shown in FIG.26. The fourth PNBA82of this fourth PNBA-ESRBA pair146is then ANDed with the second PNBA mask114shown inFIG. 17to produce the second resultant PNBA128as shown in FIG.24.

In the second resultant PNBA128the bit position associated with possible next hop information is the highest numbered bit position with a bit value of one. As shown inFIG. 24, in this embodiment that position is position5. If no such bit position exists, then the packet is routed to the location determined above as provided by evaluation of expression (10) above, which was found to be the fifth position of the next hop array72, in this embodiment.

If the bit position located above is greater than or equal to 1, then the next hop information is given at a position in the next hop array72shown inFIG. 13determined by the following expression:∑j=1i-1⁢∑i=1PNBAj⁢P⁢⁢N⁢⁢B⁢⁢Aj⁡(i)+∑i=1n-1⁢P⁢⁢N⁢⁢B⁢⁢Ai⁡(i)+value(next⁢⁢hop⁢⁢pointer⁢⁢in⁢⁢the⁢⁢page),(14)
wherePNBAt(i)=0 for i<1 or t<0 and|PNBA| is the length of the PNBA string.

Consequently, the ninth position of the next hop array is the next most possible position of the next hop array72which holds the necessary next hop information, if no further searching is to be done.

To determine whether or not any further searching is to be done, it is necessary to determine whether or not there is a next PNBA-ESRBA pair on the same page or on another page on which further searching can be performed. To find which pair, if any on which to continue the search, the second ESRBA mask122shown inFIG. 21is ANDed with the ESRBA associated with the PNBA-ESRBA pair under current consideration. In this embodiment the current PNBA-ESRBA pair under consideration is the fourth pair146so the second ESRBA mask122is ANDed with the fourth ESRBA94and this produces the second resultant ESRBA130shown in FIG.25.

The next pair on which to continue searching would be given by examining the second resultant ESRBA130to determine the bit position having a one and using the number of that position in expression (12) above for determining a next pair. In the present example, the second resultant ESRBA130has all zeros and therefore, there are no further PNBA-ESRBA pairs on which to search. The search process is therefore terminated here and the next hop information stored at the ninth position of the next hop array72shown inFIG. 13contains the next hop information corresponding to the longest matching prefix. The packet may then be routed to a port associated with next hop information specified by the ninth position of the next hop array. If no next hop array position is found by the time the search process is completed, the packet is routed to a default port.