Port Aggregation Hash Algorithm

When dealing with port aggregation, whether it’s EtherChannel or using the Link Aggregation Control Protocol (LACP), an important part of distributing traffic across the aggregated links is the use of a hash algorithm.

In Cisco switches, this hashing algorithm, also known as load balancing, decides which interface to use for forwarding traffic by using certain fields in the packet header, which can be a source/destination IP address, source/destination MAC address, or source/destination port number for TCP or UDP traffic.

Here’s how the algorithm works:

Step 1: It takes certain fields from the packet header as input. The specific fields used depend on the configured load balancing method.

Step 2: These values are then combined and a hash value is computed. The hash value is then used to determine which physical link in the EtherChannel to use for this specific flow of traffic.

Step 3: All packets of a particular flow (i.e., packets from the same source to the same destination that belong to the same session) will always hash to the same value and hence will use the same link. This ensures that packet order is preserved.

The load-balancing method can be configured with the “port-channel load-balance” global command in Cisco IOS software. The methods available depend on the switch model and the software version, but common options include:

1. src-mac: Source MAC address.
2. dst-mac: Destination MAC address.
3. src-dst-mac: Source and destination MAC address.
4. src-ip: Source IP address.
5. dst-ip: Destination IP address.
6. src-dst-ip: Source and destination IP address.
7. src-port: Source port for TCP or UDP.
8. dst-port: Destination port for TCP or UDP.
9. src-dst-port: Source and destination port for TCP or UDP.

Keep in mind that different flows of traffic could hash to the same value and hence use the same link, while other links might remain unused. Therefore, link utilization might not be equal, especially with a small number of flows. In general, the more flows there are, the better the links will be utilized.

Here’s an example of how to configure the load balancing method on a Cisco switch:

Switch(config)# port-channel load-balance src-dst-ip

You can verify the current load balancing method with the following command:

Switch# show etherchannel load-balance

Remember that this hashing algorithm is used for each EtherChannel individually, not for all EtherChannels on the switch.

# PORTS USED

When you’re referring to the amount of ports used in the bundle and the algorithm, you might be talking about how the hashing algorithm selects a physical link for each flow of traffic in the EtherChannel. The EtherChannel hash algorithm doesn’t directly depend on the number of ports in the bundle, but the result of the hash does determine which port is used.

Here’s how it works in general:

  1. Cisco’s EtherChannel uses a hash algorithm to determine which member link (port) of the EtherChannel to use for forwarding a specific flow of traffic. The result of the hash is a number.
  2. This number is then matched against the number of ports in the EtherChannel. The process can be simplified as calculating the modulo (remainder of the division) of the hash result by the number of ports in the EtherChannel.

For example, let’s say the result of the hash was 7, and we have:

  • 2 ports: The values we can end up with after the modulo operation are 0 and 1 (because 7 divided by 2 equals 3 remainder 1). So, you effectively load balance across two paths.
  • 4 ports: The values we can end up with are 0, 1, 2, 3 (7 divided by 4 equals 1 remainder 3). So, we load balance across four paths.
  • 8 ports: The values we can end up with are 0, 1, 2, 3, 4, 5, 6, 7 (7 divided by 8 equals 0 remainder 7). So, we load balance across eight paths.

So, when you increase the number of links in the EtherChannel, you essentially have more “buckets” that the hash result can fall into. More buckets can potentially lead to better load balancing if you have enough distinct flows of traffic, but it doesn’t guarantee it. The actual distribution of traffic depends on the specific flows and how their hash values map to the links.

Remember, all frames of a single flow (same source and destination IP, same TCP/UDP source and destination port) always take the same path to ensure in order delivery, regardless of the number of ports in the EtherChannel. Only different flows can take different paths.

Keep in mind that while you can bundle up to 8 active ports into an EtherChannel on many Cisco devices (or up to 16 ports with some devices, where 8 can be active and the remaining can be in standby mode), it’s not always the best practice to use as many ports as possible. Depending on the amount of traffic and the number of distinct flows, fewer ports might suffice, and leaving some ports out of the EtherChannel gives you more flexibility to handle other traffic or to provide redundancy for other EtherChannels.