# Patent

## Title
Selection of trunk ports and paths using rotation

## Abstract

Techniques that offer enhanced diversity in the selection of paths (e.g., ECMP paths) and/or ports from ports associated with trunks for forwarding network data traffic. In one embodiment, a network device uses a rotate function to generate a rotated index (path index) that is used to select a path (e.g., an ECMP) path from multiple paths (e.g., multiple ECMP paths) for forwarding a packet. A network device may also generate a rotated index (trunk index) that is used to select an output port from multiple output ports associated with a trunk for forwarding the packet.

## Background
CROSS-REFERENCES TO RELATED APPLICATIONS
The present application claims the benefit and priority under 35 U.S.C. 119(e) from the following U.S. Provisional Applications, the entire contents of which are herein incorporated by reference for all purposes:
(1) U.S. Provisional Application No. 61/015,151 filed Dec. 19, 2007 entitled ADVANCED LOAD BALANCING FOR TRAFFIC OVER TRUNK INTERFACES AND/OR EQUAL COST ROUTED PATHS;
(2) U.S. Provisional Application No. 61/015,153 filed Dec. 19, 2007 entitled EQUAL COST MULTIPLE PATH AND TRUNK DIVERSIFICATION FOR SINGLE AND MULTI-STAGE NETWORK; and
(3) U.S. Provisional Application No. 60/975,363 filed Sep. 26, 2007 entitled FAST AND EFFICIENT TRUNK MANAGEMENT.
The present application also incorporates by reference for all purposes the entire contents of U.S. Non-Provisional application Ser. No. 12/198,710, entitled TECHNIQUES FOR SELECTING PATHS AND/OR TRUNK PORTS FOR FORWARDING TRAFFIC FLOWS filed concurrently with the present application.


BACKGROUND OF THE INVENTION
Embodiments of the present application relate to forwarding data packets in a computer network, and more particularly to techniques for selecting a path such as an Equal Cost MultiPath (ECMP) path and/or a trunk port for forwarding data packets.
Network devices commonly have to select a path from multiple available choices for forwarding a packet. For example, ECMP is a routing strategy where next-hop packet forwarding to a destination can occur over multiple equal cost routing paths. The effect of multipath routing on a network device (e.g., a router) configured to forward packets is that the network device potentially has several next-hops for any given destination and must use some method to choose which path to the next-hop should be used for a given data packet. The use of ECMP helps to reduce delay and congestion in networks by taking advantage of multiple paths through a network by splitting traffic flows across those paths. Accordingly, in order to support ECMP path selection, a network device such as a router has to be able to select a particular ECMP path from multiple available paths to forward a packet.
Trunking is another technique that is commonly used in networks. A trunk represents a logical collection of multiple output ports generally associated with the same route or connected to the same MAC address. In a network environment, when a selected output path for a packet is a trunk, a network device has to be able to select a port from multiple ports associated with the trunk for forwarding the packet. In certain network environments, a selected ECMP path may itself correspond to a trunk. In such an environment, in addition to selecting a particular ECMP path, the network device also has to select a particular output port from the multiple output ports associated with the trunk for forwarding the data packet.
Conventionally, selection of paths (e.g., ECMP paths) and/or trunk ports for data forwarding is done by simply hashing on various fields of a packet header, such as based upon the IP source and destination address fields, and using the hash for selecting the path and/or trunk port. The diversification in the selection offered by such conventional techniques however is quite poor and does not offer proper distribution of traffic to the available paths and/or trunk ports. For example in ECMP forwarding, poor diversification results in the same ECMP path and/or trunk being selected for forwarding the traffic flow packets at multiple stages of the network. As a result, a router forwards traffic with the same source and destination addresses using the same port of a trunk or the same path, not fully utilizing the bandwidth available for the traffic via other ports or paths available to the router. Accordingly, using conventional techniques in which all routers in the network derive their hashing decision purely based on information extracted from the packet header, correlation occurs among routers that any given packet flow traverses, and such correlation reduces diversification. Further, existing ECMP solutions only work in some network topologies and provide limited diversification.
BRIEF SUMMARY OF THE INVENTION
Embodiments of the present invention provide techniques that offer enhanced diversity in the selection of paths (e.g., ECMP paths) and/or ports from ports associated with trunks for forwarding network data traffic. In one embodiment, a network device uses a rotate function to generate a rotated index (path index) that is used to select a path (e.g., an ECMP) path from multiple paths (e.g., multiple ECMP paths) for forwarding a packet. A network device may also generate a rotated index (trunk index) that is used to select an output port from multiple output ports associated with a trunk for forwarding the packet.
In one embodiment, different network devices may be configured to apply different amounts of rotation to generate the rotated indices. As a result, for the same packet, the rotated path and trunk indices generated at one network device may be different from the rotated path and trunk indices generated at a second network device. As a result, different paths and/or port trunks may be selected for forwarding the same packet (or same traffic flows) at different network devices in a multistage network.
According to an embodiment of the present invention, techniques are provided for selecting a path for forwarding a packet. A first value may be generated at a first network device based upon one or more sections of the packet. The first value may be rotated at the first network device by a first amount to generate a first rotated index, wherein the first amount is preconfigured for the first network device. A path from a plurality of paths may be selected at the first network device for forwarding the packet from the first network device based upon the first rotated index.
In one embodiment, the one or more sections of the packet may be hashed to generate a hash value, and the first value may be generated using the hash value.
In one embodiment, the packet may be communicated from the first network device to a second network device using the selected path. At the second network device, a second value may be generated based upon the one or more sections of the packet. The second value may be rotated at the second network device by a second amount to generate a second rotated index, wherein the second amount is preconfigured for the second network device and is different from the first amount. A path from a plurality of paths may be selected at the second network device for forwarding the packet from the second network device based upon the second rotated index.
According to an embodiment of the present invention, techniques are provided for selecting a port for forwarding a packet. A first value may be generated at a first network device based upon one or more sections of the packet. The first value may be rotated at the first network device by a first amount to generate a first rotated index, wherein the first amount is preconfigured for the first network device. A port from a plurality of ports associated with a trunk may be selected at the first network device for forwarding the packet from the first network device based upon the first rotated index. In one embodiment, the one or more sections of the packet may be hashed to generate a hash value, and the first value may be generated using the hash value.
In one embodiment, the packet may be communicated from the first network device to a second network device using the selected port. At the second network device, a second value may be generated based upon the one or more sections of the packet. The second value may be rotated at the second network device by a second amount to generate a second rotated index, wherein the second amount is preconfigured for the second network device and is different from the first amount. A port from a plurality of ports associated with a trunk may be selected at the second network device for forwarding the packet from the second network device based upon the second rotated index.
The foregoing, together with other features and embodiments will become more apparent when referring to the following specification, claims, and accompanying drawings.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 depicts a simplified block diagram of a network device that may incorporate an embodiment of the present invention;
FIG. 2 depicts a simplified flowchart depicting a method for generating a rotated trunk index for selecting a trunk port from multiple ports associated with a trunk for forwarding a packet according to an embodiment of the present invention;
FIG. 3 depicts a simplified block diagram of a module that may be used to generate a rotated trunk index according to an embodiment of the present invention;
FIG. 4 depicts a simplified flowchart depicting a method for generating a rotated path index for selecting a path from multiple paths for forwarding a packet according to an embodiment of the present invention;
FIG. 5 depicts a simplified block diagram of a module that may be used to generate a rotated path index according to an embodiment of the present invention;
FIG. 6 depicts a simplified flowchart depicting a method of using a rotated path index to select a path according to an embodiment of the present invention;
FIG. 7 depicts a simplified flowchart depicting a method of using a rotated trunk index to select an output port from multiple output ports associated with a trunk according to an embodiment of the present invention; and
FIG. 8 depicts a multistage network that may incorporate an embodiment of the present invention.



DETAILED DESCRIPTION OF THE INVENTION
In the following description, for the purposes of explanation, specific details are set forth in order to provide a thorough understanding of embodiments of the invention. However, it will be apparent that the invention may be practiced without these specific details.
Embodiments of the present invention provide techniques that enhance diversification in the selection of paths (e.g., ECMP paths) and/or selection of trunk ports for forwarding traffic flows comprising packets. FIG. 1 depicts a simplified block diagram of a network device 100 that may incorporate an embodiment of the present invention. In the embodiment depicted in FIG. 1, network device 100 comprises a plurality of ports 102, a media access controller (MAC) 104, a packet processor 106, one or more memories associated with packet processor 106 such as a content-addressable memory (CAM) 110, a parameter RAM (PRAM) 112, a table 114 (referred to as CAM2PRAM), a traffic manager 108, and a management processor 116 with associated memory 118. The components of network device 100 depicted in FIG. 1 are meant for illustrative purposes only and are not intended to limit the scope of the invention in any manner. Alternative embodiments may have more or less components. For example, while only one packet processor 106 is depicted in FIG. 1, alternative embodiments may have multiple packet processors.
Network device 100 receives and transmits data flows comprising packets using ports 102. A port within ports 102 may be classified as an input port or an output port depending upon whether a packet is received or transmitted using the port. A port over which a packet is received by network device 100 is referred to as an input port. A port used for communicating or transmitting a packet from network device 100 is referred to as an output port. A particular port may function both as an input port and an output port. Ports 102 may be capable of receiving and/or transmitting different types of data traffic at different speeds including 1 Gigabit/sec, 10 Gigabits/sec, or more. In some embodiments, multiple ports of network device 100 may be logically grouped into one or more trunks. A trunk represents a logical collection of multiple output ports of a network device generally associated with the same route or connected to the same MAC address.
In one embodiment, network device 100 may receive one or more packets via one or more input ports. For a packet received over an input port, network device 100 may be configured to determine an output port for the packet. The packet may then be forwarded to the determined output port and transmitted from network device 100 using the output port. As part of the processing to determine an output port for a packet, network device 100 may be configured to select a particular path (e.g., an ECMP path) from multiple paths (e.g., multiple ECMP paths) that may be available for forwarding the packet and select an output port corresponding to the particular selected path. If the selected path is a trunk, as part of forwarding a packet from an input port to an output port, network device 100 may be configured to select a particular output port from the multiple output ports associated with the selected trunk for forwarding the packet. The packet may then be communicated from network device 100 using the selected trunk output port.
In the embodiment depicted in FIG. 1, ports 102 are coupled to a media access controller (MAC) 104. Packets received by network device 100 via one or more ports 102 may be forwarded to MAC device 104 and then to packet processor 106 for further processing. MAC 104 provides an interface between ports 102 and packet processor 106.
Packet processor 106 is configured to process each packet received by network device 100 and determine how the packet is to be forwarded. This processing may involve performing lookups in CAM 110, PRAM 112, and CAM2PRAM 114. In one embodiment, as part of the processing, packet processor 106 is configured to determine an output port to which the packet is to be forwarded. As part of determining an output port to which the packet is to be forwarded, packet processor 106 is configured to select a particular path from multiple paths for forwarding the packet and then select an output port corresponding to a particular selected path. For example, packet processor 106 may be configured to select an ECMP path from multiple ECMP paths for forwarding the packet and forward the packet to a port corresponding to the selected ECMP path. If the selected path is a trunk, as part of determining an output port to which the packet is to be forwarded, packet processor 106 is configured to select a particular output port from the multiple output ports associated with the selected trunk for forwarding the packet. The packet may then be communicated from network device 100 using the selected output port. In some scenarios, the selected path may itself be a trunk. In such a scenario, upon selecting a particular path, packet processor 106 is configured to select a particular output port from the multiple output ports associated with the selected path for forwarding the packet.
According to an embodiment of the present invention, packet processor 106 performs the selection of a path and/or selection of a port from ports grouped as a trunk using techniques that provide enhanced diversification in the selection of the path and/or trunk port. Embodiments of the present invention provide enhanced diversification by more equally distributing traffic flows between available paths (e.g., ECMP paths) and/or trunk ports.
In one embodiment, packet processor 106 is configured to extract one or more sections of the packet to be forwarded. Packet processor 106 is then configured to hash the extracted sections of the packet to generate a hash value. A trunk index is then determined based upon the hash value. In one embodiment, the trunk index is the hash value itself. The trunk index is then rotated or shifted (e.g., using a barrel shifter) by a certain amount to produce a rotated trunk index that is then used for selecting an output port from multiple ports associated with a trunk for forwarding a packet.
In one embodiment, a path index is derived from the hash value. In some embodiments, the path index is derived from the trunk index (e.g., the path index is set to the trunk index or a flipped trunk index). Network device 100 is then configured to rotate or shift (e.g., using a barrel shifter) the path index by a set amount to generate a rotated path index. The rotated path index is then used for selecting a path from multiple possible paths for forwarding the packet. The packet may then be forwarded by network device 100 using an output port corresponding to the selected path. For example, the rotated path index may be used to select an ECMP path from multiple ECMP paths. A rotated path index used for selecting an ECMP path may also be referred to as a rotated ECMP index. If the selected path is itself a trunk, then the trunk index may be used to select a particular port from the possibly multiple ports associated with the trunk for forwarding the packet.
The amount of rotation that is applied by a network device to generate the rotated trunk index and/or the rotated path index may be user-configurable and may be preconfigured for the network device. Different network devices in a network environment may be configured to apply different amounts of rotations. As a result, the amount of rotation applied by one network device may be different from the amount of rotation applied by another network device. Consequently, for the same packet, the rotated index generated by one network device may be different from the rotated index generated by another network device. In one embodiment, the amount of rotation that a particular network device is configured to perform may be predefined and controlled by a control variable(s) configured for that network device. In a network device, the amount of rotation used for generating a rotated trunk index may be the same as or different from the amount of rotation used for generating a rotated path index. Since different network devices may perform different amounts of rotation, a rotated trunk index generated by one network device for a packet may be different from a rotated trunk index generated for the same packet by another network device. Likewise, a rotated path index generated by one network device for a packet may be different from a rotated path index generated by another network device for the same packet. This enables diversification in the selection of paths and/or trunk ports for forwarding network traffic in a network environment.
As depicted in FIG. 1, network device 100 may comprise a management processor 116 that is configured to perform housekeeping and management functions related to network device 100. For example, programming and maintenance of tables and information in CAM 110, PRAM 112, and CAM2PRAM 114 may be performed using management processor 116. In one embodiment, management processor 116 may be a general purpose microprocessor such as a PowerPC, Intel, AMD, or ARM microprocessor, operating under the control of software stored in a memory 118 accessibly coupled to the management processor 116.
Since processing performed by packet processor 106 needs to be performed at a high packet rate in a deterministic manner, packet processor 106 is generally a dedicated hardware device configured to perform the processing. In one embodiment, packet processor 106 may be a programmable logic device such as a field programmable gate array (FPGA). Packet processor 106 may also be an ASIC.
In one embodiment, network device 100 may comprise multiple linecards, with each linecard comprising the components depicted in FIG. 1. In such an embodiment, an output port to which a packet is forwarded for transmission from the network device may lie on the same linecard as the input port or on a different linecard. Traffic manager 108 is configured to facilitate communications between the different linecards.
FIG. 2 depicts a simplified flowchart 200 depicting a method for generating a rotated trunk index for selecting a trunk port from multiple ports associated with a trunk for forwarding a packet according to an embodiment of the present invention. In one embodiment, the processing depicted in FIG. 2 is performed by packet processor 106 depicted in FIG. 1. In other embodiments, the processing may be performed by one or more components of network device 100, including or not including packet processor 106. The processing may be performed by software executed by a processor, hardware, or combinations thereof.
As depicted in FIG. 2, one or more sections of the packet to be forwarded are extracted (step 202). The extracted sections may include, for example, sections from the header of the packet, sections from the payload section of the packet, and/or combinations of sections selected from different parts of the packet. In one embodiment, the extracted section includes information extracted from the packet such as link layer (L2) network header, network layer (L3) network header, and transport layer (L4) network header of the packet. The sections of a packet that are extracted in 202 may also depend on the type of packet that is to be forwarded. For example, the sections of a packet extracted for a packet of a first type (e.g., IPv4 packet) may be different from the sections extracted for a packet of a different type (e.g., IPv6 packet). The sections of a packet that are to be extracted may be user-programmable. In one embodiment, 256-bits from the header of the packet are extracted. For a network device, packet processor 106 may be preconfigured to extract specific sections of the packet in 202.
A hash value is then generated by hashing the section(s) extracted in 202 (step 204). Different techniques may be used for the hashing. In one embodiment, a random number may also be used along with the extracted portions to generate a hash value in 204.
A trunk index is then determined from the hash value generated in 204 (step 206). Different techniques may be used to determine the trunk index from the hash value. In one embodiment, the trunk index is set to the hash value. In an alternative embodiment, the hash value is flipped to generate the trunk index.
The trunk index generated in 206 is then rotated by a preconfigured amount to generate a rotated trunk index (step 208). The amount of rotation applied by a network device may be preconfigured for the network device. In one embodiment, the amount of rotation may be based upon a control value (trunk index control value) preconfigured for the network device. The rotated trunk index generated in 208 may then be used to select an output port from ports associated with a trunk selected for forwarding the packet (step 210). The packet may then be forwarded to the selected output port and then transmitted from the network device using the output port.
FIG. 3 depicts a simplified block diagram of a module that may be used to generate a rotated trunk index according to an embodiment of the present invention. The module depicted in FIG. 3 may be implemented in software (e.g., program code or instructions executed by a processor), or in hardware, or combinations thereof. The software may be stored on a computer-readable medium such as memory, a disk, etc. In one embodiment, the functionality of the module depicted in FIG. 3 may be implemented by packet processor 106. For example, the module may be implemented as a hardware component of packet processor 106. The functionality of the module may be implemented in a programmable logic device such as a field programmable gate array (FPGA) or in an ASIC.
As depicted in FIG. 3, a trunk index 304 is determined from a hash value 302. Trunk index 304 is then input to a rotate module 306 that is configured to rotate the trunk index by a preconfigured amount and generate a rotated trunk index 308. The amount of rotation applied by module 306 may be based upon a control value “trunk index control” 310. The trunk index control value may be preconfigured for a network device and may be different for different network devices. Rotated trunk index 308 that is generated from the rotation may then be used to select a port from multiple ports associated with a trunk for forwarding the packet.
The following pseudo code depicts a technique that may be used for generating a rotated trunk index according to an embodiment of the present invention:
TRUNK_INDEX [7:0]=Hash Value;
case (TRUNK_INDEX_CONTROL_VALUE[2:0]){
0: ROTATED_TRUNK_INDEX[7:0]=TRUNK_INDEX[7:0];
1: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[0], TRUNK_INDEX[7:1]};
2: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[1:0], TRUNK_INDEX[7:2]};
3: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[2:0], TRUNK_INDEX[7:3]};
4: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[3:0], TRUNK_INDEX[7:4]};
5: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[4:0], TRUNK_INDEX[7:5]};
6: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[5:0], TRUNK_INDEX[7:6]};
7: ROTATED_TRUNK_INDEX[7:0]={TRUNK_INDEX[6:0], TRUNK_INDEX[7]};
}
According to the pseudo code depicted above, the TRUNK INDEX is set to the Hash Value. The amount by which TRUNK_INDEX is rotated is controlled by TRUNK_INDEX_CONTROL_VALUE which may be preconfigured for a network device. If the control value is 0 then no rotation is performed, if the control value is 1 then the TRUNK_INDEX is rotated by 1-bit, if the control value is 2 then the TRUNK_INDEX is rotated by 2-bits, if the control value is 3 then the TRUNK_INDEX is rotated by 3-bits, if the control value is 4 then the TRUNK_INDEX is rotated by 4-bits, if the control value is 5 then the TRUNK_INDEX is rotated by 5-bits, if the control value is 6 then the TRUNK_INDEX is rotated by 6-bits, and if the control value is 7 then the TRUNK_INDEX is rotated by 7-bits. The resultant ROTATED_TRUNK_INDEX may then be used to select an output port from multiple ports associated with a trunk selected for forwarding the packet.
FIG. 4 depicts a simplified flowchart 400 depicting a method for generating a rotated path index for selecting a path (e.g., an ECMP path) from multiple paths (e.g., from multiple ECMP paths) for forwarding a packet according to an embodiment of the present invention. In one embodiment, the processing depicted in FIG. 4 is performed by packet processor 106 depicted in FIG. 1. In other embodiments, the processing may be performed by one or more components of network device 100, including or not including packet processor 106. The processing may be performed by software executed by a processor, hardware, or combinations thereof.
As depicted in FIG. 4, one or more sections of the packet to be forwarded are extracted (step 402). The extracted sections may include, for example, sections from the header of the packet, sections from the payload section of the packet, and/or combinations of sections selected from different parts of the packet. In one embodiment, the extracted section includes information extracted from the packet such as link layer (L2) network header, network layer (L3) network header, and transport layer (L4) network header of the packet. The sections of a packet that are extracted in 402 may also depend on the type of packet that is to be forwarded. For example, the sections of a packet extracted for a packet of a first type (e.g., IPv4 packet) may be different from the sections extracted for a packet of a different type (e.g., IPv6 packet). In one embodiment, 256-bits from the header of the packet are extracted. For a network device, packet processor 106 may be preconfigured to extract specific sections of the packet in 202. The sections of a packet that are to be extracted may be user-programmable. The section(s) of the packet extracted in 202 may be the same as or different from the section(s) extracted in 402.
A hash value is then generated by hashing the section(s) extracted in 402 (step 404). Various different hashing techniques may be used. In one embodiment, a random number may also be used along with the extracted sections to generate a hash value in 404.
A path index is then determined from the hash value generated in 404 (step 406). Different techniques may be used to determine the path index from the hash value. In one embodiment, the path index is set to the hash value. In an alternative embodiment, the hash value is flipped to generate the path index. The generation of the path index from the hash value may also depend upon how the trunk index was generated using the hash value. In one embodiment, the trunk index is set to the hash value while the path index is set to the flipped version of the hash value.
The path index generated in 406 is then rotated by a preconfigured amount to generate a rotated path index (step 408). The amount of rotation applied by a network device may be preconfigured for the network device. In one embodiment, the amount of rotation may be based upon a control value (path index control value) preconfigured for the network device. The rotated path index generated in 408 may then be used to select a path (e.g., an ECMP path) from multiple available paths (e.g., multiple ECMP paths) for forwarding the packet (step 410). An output port corresponding to the selected path may also be determined in 410. The packet may then be forwarded to the selected output port corresponding to the selected path and then transmitted from the network device using the output port.
FIG. 5 depicts a simplified block diagram of a module that may be used to generate a rotated path index according to an embodiment of the present invention. The module depicted in FIG. 5 may be implemented in software (e.g., program code or instructions executed by a processor), or in hardware, or combinations thereof. The software may be stored on a computer-readable medium such as memory, a disk, etc. In one embodiment, the functionality of the module depicted in FIG. 5 may be implemented by packet processor 106. For example, the module may be implemented as a hardware component of packet processor 106. The functionality of the module may be implemented in a programmable logic device such as a field programmable gate array (FPGA) or in an ASIC.
As depicted in FIG. 5, a path index 504 is determined from a hash value 502. Path index 504 is then input to a rotate module 506 that is configured to rotate the path index by a preconfigured amount and generate a rotated path index 508. The amount of rotation applied by module 506 may be based upon a control value “path index control” 510. The path index control value may be preconfigured for a network device and may be different in different network devices. Rotated path index 508 may then be used by the network device to select a path from multiple paths for forwarding the packet.
In one embodiment, the same rotate module may be used for to generate a rotated trunk index and a rotated path index. The amount of rotation applied by a network device to generate a rotated path index may be the same as or different from the amount of rotation applied by the network device to generate a rotated trunk index. The same or different control values (e.g., the path index control value and the trunk index control value) may be used to control the rotation for generating a rotated trunk index and/or a rotated path index.
The following pseudo code depicts a technique that may be used for generating a rotated path index (assumed to be an ECMP index for selecting an ECMP path) according to an embodiment of the present invention:
ECMP_INDEX [7:0]=Hash Value;
case (ECMP_INDEX_CONTROL_VALUE[2:0]){
0: ROTATED_ECMP_INDEX[7:0]=ECMP_INDEX[7:0];
1: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[0], ECMP_INDEX[7:1]};
2: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[1:0], ECMP_INDEX[7:2]};
3: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[2:0], ECMP_INDEX[7:3]};
4: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[3:0], ECMP_INDEX[7:4]};
5: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[4:0], ECMP_INDEX[7:5]};
6: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[5:0], ECMP_INDEX[7:6]};
7: ROTATED_ECMP_INDEX[7:0]={ECMP_INDEX[6:0], ECMP_INDEX[7]};
}
According to the pseudo code depicted above, ECMP_INDEX is set to the hash value. The amount by which ECMP_INDEX is rotated is controlled by ECMP_INDEX_CONTROL_VALUE which may be preconfigured for a network device. If the control value is 0 then no rotation is performed, if the control value is 1 then the ECMP_INDEX is rotated by 1-bit, if the control value is 2 then the ECMP_INDEX is rotated by 2-bits, if the control value is 3 then the ECMP_INDEX is rotated by 3-bits, if the control value is 4 then the ECMP_INDEX is rotated by 4-bits, if the control value is 5 then the ECMP_INDEX is rotated by 5-bits, if the control value is 6 then the ECMP_INDEX is rotated by 6-bits, and if the control value is 7 then the ECMP_INDEX is rotated by 7-bits. The resultant ROTATED_ECMP_INDEX may then be used to select a path from multiple paths available for forwarding the packet.
It should be apparent that both the path index and the trunk index do not have to be used each time. A rotated trunk index may need to be used only when the selected path for forwarding a packet is a trunk. Similarly, a path index may need to be used only when there are multiple paths available for forwarding the packet and a single path has to be selected. There may be no need to use a path index in network topologies where there is only one or no path from a network device for forwarding a packet. Embodiments of the present invention thus provide the flexibility of using a path index and/or a trunk index as and when appropriate.
Once the rotated path index and the rotated trunk index have been determined, the rotated indices are then be used to select a path and/or a trunk port for forwarding a packet. Various different techniques may be used to select the path and/or trunk port using a rotated path index and a rotated trunk index. FIG. 6 depicts a simplified flowchart 600 depicting a method of using a rotated path index to select a path according to an embodiment of the present invention. The method depicted in FIG. 6 assumes that the path index is used for selecting an ECMP path and the index is thus referred to as an ECMP index. The method depicted in FIG. 6 and described below is illustrative of one embodiment of using the path index and is not meant to limit the scope of embodiments of the present invention as recited in the claims. Other methods may be used in alternative embodiments. The processing depicted in FIG. 6 may be performed by packet processor 106 depicted in FIG. 1.
As depicted in FIG. 6, a CAM lookup (e.g., using CAM 110 depicted in FIG. 1) is performed using sections extracted from the packet to be forwarded to get an index to an entry in CAM2PRAM table (e.g., CAM2PRAM 114 depicted in FIG. 1) (step 602). The sections of the packet used in 602 may or may not be the same as the sections used for generating the hash value depicted in FIGS. 2 and 4. In one embodiment, a section of the header of the packet is extracted and used to perform a CAM lookup. A matching entry in the CAM yields an index pointing to an entry in the CAM2PRAM table.
An ECMP_mask value is then determined from the CAM2PRAM table entry determined from the CAM lookup performed in 602 (step 604). In one embodiment, the ECMP_mask is a 4-bit value from zero to the number of ECMP paths minus one. In order to get the number of ECMP paths and to avoid having to deal with a modulo operation (described below) using a zero base, an ECMP_Base value is determined from the ECMP_mask by adding one to the ECMP_mask (step 606). In one embodiment, the ECMP_Base value is determined as follows (by adding 1 to the 4-bit number):
ECMP_Base[4:0]=ECMP_mask[3:0]+4′h1//0-15→1-16 ports
The ECMP_Base identifies the total number of ECMP paths that are available for forwarding the packet from the network device.
An ECMP_Adjust value is then determined based upon the ECMP_Base determined in 606 and the rotated ECMP index generated as previously described (for example, the rotated path index generated in step 408 of FIG. 4) (step 608). In one embodiment, the ECMP_Adjust is determined using a modulo operation as follows:
ECMP_Adjust[4:0]=Rotated ECMP Index[15:0] % ECMP_Base[4:0]
The ECMP_Adjust determined in 608 thus represents a number between 1 and the total number of available ECMP paths and used for path selection. The ECMP_Adjust is used an index to an entry in the PRAM (e.g., in PRAM 112 depicted in FIG. 1) (step 610).
The ECMP path to be used is then determined based upon the contents of the PRAM entry (step 612). In one embodiment, a forwarding identifier (FID) is determined from the PRAM entry. The particular ECMP path to be used for forwarding the packet is then determined from the FID. In one embodiment, an output port corresponding to the selected ECMP path is also determined in 612.
FIG. 7 depicts a simplified flowchart 700 depicting a method of using a rotated trunk index to select an output port from multiple output ports associated with a trunk according to an embodiment of the present invention. The method depicted in FIG. 7 and described below is illustrative of one embodiment of how a network device may use the rotated trunk index and is not intended to limit the scope of the embodiments of the present invention as recited in the claims. Other methods may be used in alternative embodiments. The processing depicted in FIG. 7 may be performed by packet processor 106 depicted in FIG. 1.
As depicted in FIG. 7, an index to an entry in the PRAM is obtained for the packet to be forwarded (step 702). In one embodiment, a section of the packet header is used to perform a lookup in the CAM. A matching entry in the CAM yields an index to an entry in the CAM2PRAM table. The CAM2PRAM table entry provides an index to an entry in the PRAM. In some embodiments, a CAM2PRAM table may not be used and a matching entry in the CAM may itself provide an index to an entry in the PRAM.
A trunk group identifier (TGID) and a PRAM forwarding identifier (PRAM FID) are then determined from the PRAM entry to which an index is obtained in 702 (step 704). In one implementation, the PRAM may be organized as a 32M×4 or 512K×64×4 memory. Each PRAM entry may include, for example, 247 bits of routing and status information, along with a 9-bit TGID (TRUNK_GROUP[8:0]), which indexes into a trunk group table. The TGID references the trunk to be used for forwarding the packet. PRAM entries sharing a trunk are programmed with the trunk's TGID.
In one embodiment, the trunk group table stores information for one or more trunks.
A trunk group table may store one or more entries corresponding to trunks and the entries are addressed by TGIDs stored in the PRAM entries. The information stored for each trunk may include information identifying the current number of active ports associated with the trunk. In one implementation, each trunk group table entry stores information for a trunk and comprises a value representing the number of currently active trunk ports for the trunk. In such an implementation, when the number of active member ports in a trunk changes, the information in the corresponding trunk group table entry is updated to reflect the change. In this manner, the information in the PRAM entries for the trunk does not have to be changed. PRAM entries sharing a trunk may be programmed with the trunk's TGID, which provides an index to an entry in the trunk group table storing information for that trunk. Updates to the trunk information are made in the trunk group table, rather than in the PRAM entries.
The TGID obtained in 704 is used to access an entry in the trunk group table (step 706). The number of active ports of the trunk is then determined from the trunk group table entry accessed in 706 (step 708). In one embodiment, a 4-bit number (TRUNK_PORTS[4:0]) represents a number from zero to the number of currently active member ports of the trunk minus one. Accordingly, TRUNK_PORTS[4:0] ranges from 0 to one less than the number of currently active member ports. Thus, an adjustment may be made in 708 by adding one to the TRUNK_PORTS to obtain the number of currently active ports as follows:
TRUNK_PORTS_ADJ[5:0]=TRUNK_PORTS[4:0]+5′h1
TRUNK_PORTS_ADJ represents the number of active trunk ports.
An output port for forwarding the packet is then determined from the multiple ports associated with the trunk based upon the number of ports determined in 708 and the rotated trunk index (step 710). In one embodiment, this is done by first determining a Trunk_Adjust value based upon the number of active trunk ports determined in 708 and the rotated trunk index previously generated (as generated in step 210 in FIG. 2). In one embodiment, the Trunk_Adjust value is determined as follows (assuming an 8-bit trunk index):
Trunk_Adjust[5:0]=Trunk Index[15:0] % TRUNK_PORTS_ADJ[5:0]
As shown above, a modulo operation is used to select one of the currently active ports of the trunk represented by Trunk_Adjust. A trunk_FID may then be obtained using the PRAM FID determined in 704 and the Trunk_Adjust. In one embodiment, a 16-bit trunk_FID is obtained using a bit-wise OR operation (|) as follows:
TRUNK_FID[15:0]=PRAM_FID[15:0]|Trunk_Adjust[4:0]
In one embodiment, the trunk_FID points to information related to the output port from the trunk to be used for forwarding the packet. Various other techniques may be used in alternative embodiments.
In embodiments wherein a path has to be determined from multiple paths available for forwarding the packet and the selected path is a trunk, then the processing depicted in FIGS. 6 and 7 may be performed to determine a particular ECMP path and a particular output port of the trunk for forwarding a packet.
As described above, embodiments of the present invention provide techniques for generating an index (rotated path index) for selecting a path from multiple paths that may be available for forwarding a packet and for generating an index (rotated trunk index) for selecting a port from multiple ports associated with a port. The manner in which the rotated indices are generated enhances the diversification in the selection of paths and/or trunk ports for forwarding a packet.
Embodiments of the present invention ensure that packets belonging to the same “flow” are forwarded using the same path and/or same trunk port. A “flow” may be characterized by information selected from a packet to be forwarded. For example, one or more fields selected from the header of a packet may define a flow. The definition of a flow may change from one environment to another. In one embodiment, a flow means a combination of the source and destination fields in the packet. In such an environment, two packets may be considered to belong to the same flow if they both have the same source address and destination address. For a given flow, as long as the region boundary (e.g., the number of ports configured) is fixed, the same next-hop will be chosen for packets belonging to the flow. This is useful for several networking protocol and applications. For example, for a connected TCP flow, diverting packets from the same flow to different paths/ports will introduce additional overhead due to path/port setup requirements which will degrade the performance of the network. As a result, embodiments of the present invention ensure that packets belonging to the same flow are forwarded using the same path and/or same trunk port.
Embodiments of the present invention may be used for various applications. For example, service providers and datacenters looking for ECMP and trunk diversification may use embodiments of the present invention. Embodiments of the present invention may be used in various different network topologies including single and multi-stage networks. Embodiments of the present invention provide improved diversification in the selection of paths and/or trunk ports and as a result provide improved data load balancing across paths and trunk ports in a network.
FIG. 8 depicts a multistage network 800 that may incorporate an embodiment of the present invention. FIG. 8 depicts three stages of network 800, with network device 801 belonging to a first stage, network devices 802-1, 802-2, and 802-3 belonging to a second stage, and network devices 803-1 through 803-9 belonging to a third stage. Each network device may be configured to apply a preconfigured amount of rotation to generate a rotated path index and/or a rotated trunk index. The amount of rotation applied by one network device may be different from the amount of rotation applied by another network device. In this manner, different amounts of rotation may be applied by the network devices depicted in FIG. 8 (although they all do not have to be different) in generation of the rotated indices. In this manner, enhanced diversity in the selection of a path and/or a trunk port for data forwarding is provided.
As depicted in FIG. 8, network device 801 may receive packets belonging to multiple traffic flows, including packets belonging to flows X, Y, and Z. At network device 801, three ECMP paths (labeled 1, 2, and 3) may be available for forwarding the data flows to the next-hop. Using a rotated ECMP index generated as described above, network device 801 may select ECMP path 1 for packets belonging to flow X and forward the flow X packets along ECMP path 1 to network device 802-1. Using the same technique for generating a rotated ECMP index, network device 801 may select ECMP path 2 for packets belonging to flow Y and forward the flow Y packets along ECMP path 2 to network device 802-2. Using the same technique for generating a rotated ECMP index, network device 801 may select ECMP path 3 for packets belonging to flow Z and forward the flow Z packets along ECMP path 2 to network device 802-3. Further, all packets belonging to the same flow are forwarded along the same ECMP path.
Network device 802-1 may also provide three different possible ECMP paths for forwarding packets belonging to flow X. Based upon a rotated ECMP index generated by network device 802-1, network device 802-1 may select ECMP path 2 for forwarding packets belonging to flow X and forward the flow X packets along ECMP path 2 to network device 803-2.
Network device 802-2 may also provide three different possible ECMP paths for forwarding packets belonging to flow Y. Based upon a rotated ECMP index generated by network device 802-2, network device 802-1 may select ECMP path 3 for forwarding packets belonging to flow Y and forward the flow Y packets along ECMP path 3 to network device 803-6.
Network device 802-3 may also provide three different possible ECMP paths for forwarding packets belonging to flow Z. Based upon a rotated ECMP index generated by network device 802-3, network device 802-3 may select ECMP path 1 for forwarding packets belonging to flow Z and forward the flow Z packets along ECMP path 1 to network device 803-7.
As can be seen from the above example, the ECMP paths selected for forwarding a particular flow of packets at the different stages are different. This is because the amount of rotation applied by the network devices at the different stages may be different to generate different rotated ECMP indices thereby resulting in different ECMP paths being selected. For example, for packets belonging to flow X, at stage one, ECMP path 1 is selected, whereas, at stage two, ECMP path 2 is selected. This is due to the fact that the amount of rotation applied by network device 701 for generating a rotated path index or ECMP index may be different from the amount of rotation applied by network device 702-1. As a result, the rotated path index generated at network device 702 may be different from the rotated path index generated at network device 702-1. Due to this, a traffic flow may be diverted to different paths at different stages of the network while ensuring that, at a particular network device, all packets belonging to a particular traffic flow are all forwarded using the same path. This is different from conventional selection techniques, wherein the same path is likely to be selected at each network device for a traffic flow. Likewise, for packets belonging to flow Y, at stage one, ECMP path 2 is selected, whereas, at stage two, ECMP path 3 is selected. Further, for packets belonging to flow Z, at stage one, ECMP path 3 is selected, whereas, at stage two, ECMP path 1 is selected.
Accordingly, different ECMP paths may be selected at different stages, thereby enhancing the diversity of the selection, using the same technique for generating rotated path and trunk indices. Embodiments of the present invention may thus be used in a multistage network to enhance diversity in the selection of paths at the different stages.
If the selected path is a trunk, then the trunk index may be used to select a particular port from the multiple ports associated with the trunk for forwarding the packet. As with the selection of paths, the selected port for a particular flow of traffic may be different at different stages of the network since the amount of rotation applied by the network devices at the different stages for generating rotated trunk indices may be different at the different network devices resulting in different rotated trunk indices being generated at the different network devices.
Although specific embodiments of the invention have been described, various modifications, alterations, alternative constructions, and equivalents are also encompassed within the scope of the invention. For example, while embodiments have been described for using a rotated path index to select an ECMP path from multiple ECMP paths, the path index may also be used to select other types of paths. Embodiments of the present invention are not restricted to operation within certain specific data processing environments, but are free to operate within a plurality of data processing environments. Additionally, although embodiments of the present invention have been described using a particular series of transactions and steps, it should be apparent to those skilled in the art that the scope of the present invention is not limited to the described series of transactions and steps. For example, while embodiments of the present invention have been described for selecting ECMP paths, in other embodiments, the techniques described above may also be used to select a path from multiple path choices for forwarding a packet.
Further, while embodiments of the present invention have been described using a particular combination of hardware and software, it should be recognized that other combinations of hardware and software are also within the scope of the present invention. Embodiments of the present invention may be implemented only in hardware, or only in software, or using combinations thereof.
The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense. It will, however, be evident that additions, subtractions, deletions, and other modifications and changes may be made thereunto without departing from the broader spirit and scope as set forth in the claims.

## Claims

1. A method comprising:
generating, at a first network device, a first value based upon one or more sections of a first packet;
bit rotating, at the first network device, the first value by a first amount to generate a first rotated index, wherein the first amount is specified by a first control variable that is configured for the first network device, and wherein the first rotated index is used to select a path from a plurality of paths for forwarding the first packet from the first network device;
generating, at the first network device, a second value based upon one or more sections of a second packet; and
bit rotating, at the first network device, the second value by a second amount to generate a second rotated index, wherein the second amount is specified by a second control variable that is configured for the network device and is distinct from the first control variable, and wherein the second rotated index is used to select a port from a plurality of ports associated with a trunk for forwarding the second packet from the first network device.

2. The method of claim 1 wherein generating the first value comprises:
hashing the one or more sections of the first packet to generate a hash value; and
generating the first value using the hash value.

3. The method of claim 1 further comprising:
communicating the first packet from the first network device to a second network device using the selected path;
generating, at the second network device, a third value based upon the one or more sections of the first packet;
bit rotating, at the second network device, the third value by a third amount to generate a third rotated index, wherein the third amount is specified by a third control variable configured for the second network device, and wherein the third amount specified by the third control variable is different from the first amount specified by the first control variable; and
selecting, at the second network device, a path from a plurality of paths for forwarding the first packet from the second network device based upon the third rotated index.

4. The method of claim 1 wherein the control variable is configurable by a user.

5. A network device comprising:
a plurality of ports; and
a packet processor configured to
generate a first value based upon one or more sections of a first packet to be forwarded from the network device,
bit rotate the first value by a first amount to generate a first rotated index, wherein the first amount is specified by a first control variable that is configured for the network device, and wherein the first rotated index is used to select a path from a plurality of paths for forwarding the first packet from the first network device;
generate a second value based upon one or more sections of a second packet to be forwarded from the network device; and
bit rotate the second value by a second amount to generate a second rotated index, wherein the second amount is specified by a second control variable that is configured for the network device and is distinct from the first control variable, and wherein the second rotated index is used to select a port from a plurality of ports associated with a trunk for forwarding the second packet from the first network device.

6. The network device of claim 5 wherein the packet processor is configured to:
hash the one or more sections of the first packet to generate a hash value; and
generate the first value using the hash value.

7. The network device of claim 5 further configured to:
communicate the first packet from the network device to a second network device using the selected path;
wherein the second network device is configured to apply a different amount of rotation from the first amount for generating a third rotated index that is used to select a path for forwarding the first packet from the second network device.

8. The network device of claim 5 wherein the control variable is configurable by a user.

9. A network device comprising:
means for generating a first value based upon one or more sections of a first packet;
means for bit rotating the first value by a first amount to generate a first rotated index, wherein the first amount is specified by a first control variable that is configured for the first network device, and wherein the first rotated index is used to select a path from a plurality of paths for forwarding the first packet from the network device;
means for generating a second value based upon one or more sections of a second packet; and
means for bit rotating the second value by a second amount to generate a second rotated index, wherein the second amount is specified by a second control variable that is configured for the network device and is distinct from the first control variable, and wherein the second rotated index is used to select a port from a plurality of ports associated with a trunk for forwarding the second packet from the network device.

10. The network device of claim 9 further comprising:
means for hashing the one or more sections of the first packet to generate a hash value; and
means for generating the first value using the hash value.

11. The network device of claim 9 further comprising:
means for communicating the first packet from the network device to a second network device using the selected path;
wherein the second network device is configured to apply a different amount of rotation from the first amount for generating a third rotated index that is used to select a path for forwarding the first packet from the second network device.