The idea: many cables, one logical port
One 1 Gb/s cable between two switches is often not enough, and if it breaks, everything behind it is cut off. So people run several cables. But four plain links between two switches are a loop, and spanning tree turns three of them off. Link aggregation bundles the cables into one logical port, a port-channel (Cisco: EtherChannel; Linux: a bond). Spanning tree, the MAC table and VLAN settings see only the port-channel, and every cable in it carries traffic.
LACP, the Link Aggregation Control Protocol (IEEE 802.1AX, first 802.3ad), is how the two
switches agree on which ports belong to the bundle. On the page, SW-A and SW-B are joined by four 1 Gb/s
links on ports 1 to 4. Both switches have those ports in channel-group 1 mode active, which
gives them key 1. Hosts H1 and H2 sit behind SW-A, a server S behind SW-B, and six flows run
from the hosts to S.
What a LACPDU says
Every port that runs LACP sends small frames called LACPDUs to a fixed multicast address that switches never forward. A LACPDU has two halves: what the sender says about itself (the actor) and what it has heard about the other end (the partner). Each half holds a system ID (a 2-byte priority, here 32768, plus the switch MAC), a key, a port number and one byte of state bits:
| Bit | Name | Set to 1 means |
|---|---|---|
| A | Activity | active mode: send LACPDUs on my own (passive ports only answer) |
| T | Timeout | short timeout: please send to me every 1 s, not every 30 s |
| G | Aggregation | this port may be bundled (0 = it can only work alone) |
| S | Synchronization | I have attached this port to the right bundle |
| C | Collecting | I accept frames that arrive on this port |
| D | Distributing | I send frames on this port |
Bring-up: four rounds
When the cables come up, no port carries data. Each link goes through the same rounds, both ends at once (Demo 1: LACP bring-up):
- Each port sends A and G with its own system ID, key and port. It knows nothing about its partner yet.
- Now it knows the partner. Ports with the same partner system and matching keys select the same bundle, Po1, attach to it and set S. Each LACPDU echoes what it heard, so each end can check that the other end got it right.
- The partner is in sync, so each port starts collecting (C).
- The partner is collecting, so each port starts distributing (D). Now the link carries data.
Collecting comes before distributing so that no frame is sent to a port that would throw it away. After
bring-up the ports keep sending a LACPDU every 30 s (or 1 s) so that each end knows the other is still there.
At least one end must be active; two passive ends wait for each other forever. Cisco's
mode on skips LACP entirely and bundles without asking, which is how a wiring mistake turns into a loop.
Keys: who may join
A port joins Po1 only if its key is the bundle's key and its partner is the same switch, with the same key, as the partner of the other members. That stops a cable plugged into the wrong switch, or into a port set up for another bundle, from joining. In Demo 7 someone moves SW-B port 4 to channel-group 2 (key 2). The port leaves Po1 and runs LACP again; SW-A hears partner key 2 instead of 1, so the port never sets S and carries no data. Po1 goes on with three links. Cisco reports such a port as suspended.
Hashing flows onto links
The switch does not spread single frames over the links in turn. Frames of one TCP connection could then
overtake each other on links with different queues, and TCP treats reordering as loss. Instead the switch
hashes fields of each frame that are the same for the whole flow, and the result picks one link. On the page
the hash is (src IP ⊕ dst IP ⊕ src port ⊕ dst port) mod 8. The result is one of 8
buckets, and each bucket points at one member link. F1 is H1 port 50004 to S port 443:
(11 ⊕ 20 ⊕ 50004 ⊕ 443) mod 8 = 0, so bucket b0 and link L1, for every frame of F1
(Demo 2).
Two things follow. First, one flow never gets more than one link: F6, a backup that would
take 2000 Mb/s, gets 1000 Mb/s on L4 while Po1 has 4 Gb/s and carries only 2000 Mb/s in all. Four 1 Gb/s
links are not one 4 Gb/s link. Second, the spread depends on which fields go into the hash.
With MACs only, every flow from H1 gets (0x11 ⊕ 0x20) mod 8 = 1 and every flow from H2 gets 2. L2 carries 600
Mb/s, L3 is full at 1000, and L1 and L4 stay idle (Demo 3). Traffic between two routers is worse
still: all of it has the same two MACs. That is why switches let you choose
src-dst-ip or src-dst-ip-port.
| Flow | src → dst | IP + port hash | link | MAC hash | link |
|---|---|---|---|---|---|
| F1 | H1:50004 → S:443 | 0 | L1 | 1 | L2 |
| F2 | H1:50005 → S:443 | 1 | L2 | 1 | L2 |
| F3 | H1:50001 → S:80 | 6 | L3 | 1 | L2 |
| F4 | H2:50007 → S:443 | 4 | L1 | 2 | L3 |
| F5 | H2:50004 → S:22 | 2 | L3 | 2 | L3 |
| F6 | H2:50006 → S:873 | 7 | L4 | 2 | L3 |
Each switch hashes only the frames it sends, so the traffic from S back to the hosts can take other links. Picking a bucket by hash is the same trick a load balancer uses to pick a server; making few keys move when the set changes is the topic of consistent hashing.
A link fails
When the cable on L3 is cut, both ends lose light at once and both ports leave Po1 right away. Only the two buckets of L3 move, to the live links in turn: b2 → L1 and b6 → L2. So F5 moves to L1 and F3 to L2, while F1, F2, F4 and F6 stay where they were and their frames stay in order. L1 now carries 600 Mb/s and L2 400 (Demo 4). The page moves only the dead link's buckets, as "resilient hashing" does. Many switches instead rebuild the whole table for three links, which also moves some flows whose link did not fail. Restore the link and LACP runs its four rounds on it before the buckets come back.
A silent link: fast vs slow rate
A cable can fail without going dark. A bad media converter or a broken patch in the middle may pass no frames while both ports still see light. Then only LACP can notice: a port drops its partner when it has heard no LACPDU for 3 × the partner's sending interval. The T bit a port sends chooses that interval for its partner.
| Rate | LACPDU every | Timeout | Lost on L3 (F3 + F5 = 400 Mb/s) |
|---|---|---|---|
| slow (T = 0, the default) | 30 s | 90 s | 36000 Mbit = 4500 MB (Demo 5) |
fast (T = 1, lacp rate fast) | 1 s | 3 s | 1200 Mbit = 150 MB (Demo 6) |
During the timeout the hash still sends F3 and F5 into the dead link. The fast rate costs one small frame per second per port, so it is a common setting on links between switches and servers.
Spanning tree and the bundle
Turn LACP off and the four links are four separate paths between the same two switches: a loop. Spanning tree makes SW-A the root (its bridge ID 32768.001a.0000.000a is lower), gives SW-B port 1 the root port role because all four links cost the same and port 1 has the lowest port ID, and makes ports 2 to 4 alternate ports that discard. All six flows then share L1: 166 Mb/s each (Demo 8). With Po1, spanning tree sees one port with one cost and nothing to block. If one member fails, the port-channel stays up, so spanning tree does not even notice. How spanning tree picks and repairs its tree is on Rapid Spanning Tree.
See also VLANs: a port-channel is usually a trunk that carries many VLANs, set up once on Po1 instead of on each cable. For a spare default gateway instead of a spare cable, see VRRP and HSRP.
See also Flow Monitoring with NetFlow and IPFIX for counting the flows that a port-channel spreads over its links.
What the page leaves out
The Defaulted and Expired state bits (a port that has not heard a partner yet sets Defaulted, so its first LACPDU reads 0x45, not 0x05), passive mode, the full 802.1AX state machines (receive, periodic, selection, mux, churn), the 3-per-second limit on LACPDUs, the port priority and system priority deciding which ports are active when there are more than the bundle allows (hot standby ports), minimum-links settings, Marker PDUs, bundles spread over two switches (MLAG, vPC, stacking), the traffic from SW-B back to the hosts, and exact vendor hash functions (real ones mix more bits, often with CRC). Flow records and NetFlow export are a separate topic.