Sub topic 3
How frames are spread across member links
This chapter assumes you know what a LAG (link aggregation group, also called a port channel) is: several physical links presented as one logical interface. It also assumes you understand Ethernet frames, MAC addresses, and IP and TCP/UDP headers. Here you learn how a device picks one member link for each frame it sends, and why that choice limits what a LAG can do.
The ordering constraint
A switch could send each frame on whichever member link is free, like a round-robin dealer. That would use every link evenly. It would also reorder frames.
Two links can have different queue depths, so frame 2 can arrive before frame 1. Ethernet does not repair ordering. TCP tolerates some reordering, but it reads out-of-order segments as possible loss and can slow down. Some protocols that run directly over Ethernet or UDP tolerate reordering poorly or not at all.
Link aggregation therefore follows one rule, set out in IEEE 802.1AX. Frames that belong to the same conversation must always use the same member link. A LAG does not balance frames. It balances conversations, and the standard calls a conversation a flow.
How a member is chosen
Each device decides independently for the frames it transmits. Selection has three steps:
- Select the input fields. The device takes chosen header fields from the frame, such as source and destination MAC address, IP address, or TCP/UDP port.
- Compute a hash. The fields go through a hash function. The result is a number that is the same every time for the same inputs.
- Map the hash to a member. The device reduces the number to a member index. The simplest way is
hash % number_of_active_members. Many switch chips use a table of hash buckets that are assigned to members.
The hash does not know how busy a link is. It cannot notice that member 0 is full while member 1 is idle. The spread is statistical and works well only when there are many different flows.
What counts as a flow
Which fields you feed into the hash decides what "same conversation" means. Wider input means finer-grained flows and usually better spreading. Narrower input keeps more traffic together.
| Hash input | Flow granularity | Typical effect |
|---|---|---|
| Source MAC only | All traffic from one sender | Every frame from a given host uses one link |
| Destination MAC only | All traffic to one receiver | A router or server as destination pins all traffic to one link |
| Source and destination MAC | One pair of devices | A router-to-router link carries only a single flow |
| Source and destination IP | One pair of IP hosts | Better than MAC at a router hop, but still coarse |
| IPs plus TCP/UDP ports | One connection | Finest granularity, and the best spread |
Which options exist depends on the platform. The next chapter covers choosing among them. For now, remember that the field choice sets how many distinct flows your traffic has.
Because the sender chooses, the two directions of a conversation are decided separately. Traffic from host A to host B can cross member 0 while the reply crosses member 1. Each device configures its hash for its own transmissions. You can configure the two ends differently, and often you should. A file server sends far more than it receives, so its sending hash matters most.
A single flow is limited to one link
This is the main consequence. If a port channel has four 1 Gb/s members, its total capacity is 4 Gb/s. A single TCP connection hashes to one member and can use at most 1 Gb/s of it, minus overhead. Other flows can use the other three links at the same time. One flow cannot spread over them.
A LAG helps many-to-many traffic: servers with many clients, or uplinks that carry many hosts. It does not speed up one large transfer between two hosts. For that you need a faster single link, such as 10 Gb/s instead of 4 × 1 Gb/s.
A worked example
Take a two-member LAG and four TCP flows from clients to the same server on port 443. Assume the hash and modulo give these results. These values are made up to show the mechanism.
| Flow (source port) | Hash value | Hash mod 2 | Member |
|---|---|---|---|
| 50000 | 7 | 1 | Link 1 |
| 50001 | 12 | 0 | Link 0 |
| 50002 | 5 | 1 | Link 1 |
| 50003 | 9 | 1 | Link 1 |
Three flows landed on link 1 and one on link 0. Nothing is broken. A small number of flows rarely splits evenly. If flow 50000 is a large backup and the other three are small, link 1 can be saturated while link 0 is nearly idle. Over hundreds of flows of similar size, the split approaches 50/50.
You can reproduce both behaviors in Python. This model uses CRC32. Real switches use their own hash functions, but the behavior is the same.
import zlib
from collections import Counter
def pick_member(src_ip, dst_ip, src_port, dst_port, proto, n_links):
key = f"{src_ip}|{dst_ip}|{src_port}|{dst_port}|{proto}".encode()
return zlib.crc32(key) % n_links
def pick_member_ip_only(src_ip, dst_ip, n_links):
key = f"{src_ip}|{dst_ip}".encode()
return zlib.crc32(key) % n_links
# One flow always maps to the same member.
flow = ("10.0.0.5", "10.0.1.9", 50000, 443, "tcp")
print(pick_member(*flow, n_links=2) == pick_member(*flow, n_links=2))
# 200 connections between the same two hosts, hashed with ports.
with_ports = Counter(
pick_member("10.0.0.5", "10.0.1.9", port, 443, "tcp", 2)
for port in range(50000, 50200)
)
print("IPs + ports:", sorted(with_ports.items()))
# The same 200 connections, hashed on IP addresses only.
ip_only = Counter(
pick_member_ip_only("10.0.0.5", "10.0.1.9", 2)
for port in range(50000, 50200)
)
print("IPs only: ", sorted(ip_only.items()))The first line prints True. The second result splits the 200 connections between both members, roughly evenly. The third puts all 200 connections on one member, because the inputs never change. This is the same effect as a router-to-router LAG hashed on MAC addresses.
Edge cases
- Non-IP traffic. If a frame has no IP header (ARP, or some control or storage protocols), a hash that includes IP or port fields has nothing to read. Most platforms fall back to MAC addresses. Such traffic is coarsely distributed.
- Fragmented packets. Only the first IP fragment carries the TCP/UDP header. Later fragments have no ports. If the hash uses ports, fragments of one packet can take different links, or the platform can ignore ports for fragments. Platform behavior varies, so avoid fragmentation on LAG paths where possible.
- Tunnels. In GRE, VXLAN, or IPsec, the outer header often has the same addresses for every inner conversation. A hash that reads only the outer header sees one flow. Some tunnel protocols vary the outer UDP source port with an inner-flow hash to fix this. Check that your platform and tunnel do so.
- Broadcast, multicast, and unknown unicast. A switch sends these on one member of the LAG, not on all of them. A frame sent out of every member would arrive multiple times at the far end. The receiving side never forwards a frame back out the LAG it arrived on.
- Per-packet distribution. Some operating systems offer modes such as Linux
balance-rr, which alternates members for each packet. It can fill all links for a single flow, but it reorders packets. It also does not interoperate with standard switch LAGs unless the switch is set up for it. Treat it as a special case. - Changing membership. If a member fails or joins,
hash % nchanges for most flows, and they can move to different links. This is the subject of the failure and minimum-links chapter.
Summary of the model
- A LAG distributes flows, not frames, to keep each conversation in order.
- The transmitting device hashes selected header fields and maps the result to a member.
- Each direction is decided independently by the device that sends.
- More distinct flows and wider hash inputs give a more even spread.
- One flow is limited to one member's speed.
Exercise
A server has a port channel of four 1 Gb/s links to a switch. A client on the same VLAN downloads one 20 GB file from it over a single TCP connection. About how fast can this download go, and what would let the transfer use more of the LAG?
Show answer
About 1 Gb/s at most. The single TCP connection is one flow, so the server's hash picks one member for it, and the other three links carry none of it. Splitting the transfer across several parallel connections with different source ports helps, but only if the hash includes Layer 4 ports. Otherwise all connections between the same two hosts still land on one link. A single faster link, such as 10 Gb/s, is the way to speed up one connection.
Exercise
Two routers are joined by a LAG of two links, and the hash uses source and destination MAC addresses. Almost all traffic crosses only one member. Why does this happen, and what change would help?
Show answer
Each router uses its own MAC address as source and the other's as destination for every packet it sends across the link, whatever the end hosts are. The MAC pair never changes, so there is only one flow in each direction. Changing the hash to include IP addresses, and ideally TCP/UDP ports, makes the end-to-end conversations visible and lets the traffic spread over both members.