The Rule That Said Move Both Cables
We had servers to move between two switches, each on a two-cable LACP bond, with no MLAG between the switches. We wrote the careful rule into the runbook: never leave a bond split across two switches, move both cables together. Then we built a rig to check it. Both cables at once took the host off the network for the whole walk. One cable at a time cost a few tenths of a second, however long the walk took.
The rule, and why it sounded right#
Each server had a two-port 802.3ad bond to one gigabit switch. The destination was a second switch, already configured with a matching bond and joined to the first by a trunk. Nothing else joined them: no MLAG, no stacking. Each switch runs LACP on its own, with its own system id.
Our runbook put it like this:
Never leave one leg of a bond on one switch and the other leg on the other switch. These are two independent switches with no MLAG between them. The host’s bond will see two different LACP partners, pick one aggregator arbitrarily and idle the other slave, and which one wins is not predictable. Both cables move together, in one motion, or not at all.
The kernel’s own bonding documentation leans the same way. Of a host cabled to two switches, it says the modes other than active-backup and broadcast “require all links to terminate on the same peer for them to behave rationally.” As advice for how to run a server permanently, that is fair. The question we had not asked was whether it describes the move itself.
Moving both cables together has an obvious cost, which the rule accepts: the host has no link at all from the moment the first cable comes out until the bond comes back up on the other side. That is the length of the walk, plus however long LACP takes to come up with a new partner.
What the bonding driver actually does#
Two properties of the Linux 802.3ad driver decide this, and neither is arbitrary.
The first is how a port finds an aggregator. When a port needs one, the
driver looks for an existing aggregator with the same keys and the same
partner. From drivers/net/bonding/bond_3ad.c, the
test is:
if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) &&
MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) &&
(aggregator->partner_system_priority == port->partner_oper.system_priority) &&
(aggregator->partner_oper_aggregator_key == port->partner_oper.key)
) && ...
The partner system is the switch’s LACP system id. Two independent switches have two ids, so a bond with one leg on each forms two aggregators, one leg in each. Only one aggregator carries traffic at a time.
The second is which one. That is the ad_select option, and its default,
stable, is documented like this:
The active aggregator is chosen by largest aggregate bandwidth. Reselection of the active aggregator occurs only when all slaves of the active aggregator are down or the active aggregator has no slaves.
So it does not pick arbitrarily. It keeps the aggregator it already has for as long as that aggregator has a live port. Move one cable to the new switch and that leg forms a second aggregator and waits. The old one, with one cable still in the old switch, keeps the job. Pull the last old cable and the old aggregator is empty, reselection runs, and the waiting one takes over.
And a bond is not a bridge. It does not forward frames from one of its legs to the other, so there is no loop to worry about, and the waiting leg carries nothing but LACP’s own frames.
stable is the kernel’s default. It is worth checking on the host rather
than trusting whatever wrote the network configuration:
ip -d link show bond0 | grep -o 'ad_select [a-z_]*'
ad_select stable
The bandwidth and count policies reselect whenever a port is added,
removed or changes state, which is exactly what you do not want in the
middle of a move.
The rig#
Reading the source says what should happen. It does not say how long the switchover takes, or whether something we had not thought of gets in the way. So we built the topology out of network namespaces: two “switches”, each a Linux 802.3ad bond plus a bridge, with different MAC addresses so they present different LACP system ids, and a trunk between them; a host with a two-leg bond; and a target behind the first switch, pinged at 20 per second for the whole run.
A cable move is: take the switch end of the leg down, wait for the walk, move that end into the other switch’s namespace, add it to that switch’s bond, bring it up.
#!/bin/sh
# bond-move.sh CASE WALK: move a two-leg 802.3ad bond between two switches
# that share a trunk and nothing else, pinging through it 20 times a second.
# CASE one | both | live-first | dead-first
# WALK seconds a cable spends out of any switch
# Needs root, iproute2, iputils ping and GNU date. Replaces four netns.
set -u
CASE=$1 WALK=$2 SETTLE=15 OUT=/tmp/bondrig; export CASE WALK
n() { ns=$1; shift; nsenter --net=/run/netns/"$ns" "$@"; }
mark() { echo "$(date +%s.%N) $1" >> $OUT/marks; }
for ns in swa swb host tgt; do
ip netns del $ns 2>/dev/null; ip netns add $ns
done
mkdir -p $OUT; : > $OUT/marks
# Two "switches": a bond and a bridge each, and a trunk between them.
for s in a b; do
n sw$s ip link add bond$s type bond mode 802.3ad lacp_rate fast miimon 100
n sw$s ip link set bond$s address 02:00:00:00:0$s:00 # LACP system id
n sw$s ip link add br0 type bridge
n sw$s ip link set bond$s master br0
done
n swa ip link add ta type veth peer name tb netns swb
n swa ip link add sa type veth peer name tg netns tgt
n swa ip link set ta master br0; n swa ip link set sa master br0
n swb ip link set tb master br0
# The host: bond0 over h1 and h2, both cabled to switch A.
n host ip link add bond0 type bond mode 802.3ad lacp_rate fast miimon 100
n host ip link set bond0 address 02:00:00:00:11:00
for i in 1 2; do
n host ip link add h$i type veth peer name p$i netns swa
n host ip link set h$i master bond0; n host ip link set h$i up
n swa ip link set p$i master bonda
done
n host ip addr add 192.0.2.2/24 dev bond0
n tgt ip addr add 192.0.2.1/24 dev tg
for l in p1 p2 bonda ta sa br0; do n swa ip link set $l up; done
for l in bondb tb br0; do n swb ip link set $l up; done
n host ip link set bond0 up; n tgt ip link set tg up
sleep 6
n host ping -c 3 -W 2 192.0.2.1 >/dev/null || { echo "no baseline"; exit 1; }
case $CASE in # in both degraded cases, leg 1's old port has died
live-first|dead-first) n swa ip link set p1 down; sleep 3 ;;
esac
n host ping -D -i 0.05 192.0.2.1 > $OUT/ping 2>&1 & pp=$!
sleep 3
unplug() { mark "unplug-$1"; n swa ip link set "$1" down
n swa ip link set "$1" nomaster; }
plug() { n swa ip link set "$1" netns swb
n swb ip link set "$1" master bondb
n swb ip link set "$1" up; mark "plug-$1"; }
show() { n host ip -d link show bond0 |
grep -o 'ad_aggregator [0-9]*\|ad_partner_mac [0-9a-f:]*' |
paste -sd' ' | sed 's/^/ bond0: /'
for h in h1 h2; do n host ip -d link show $h |
grep -o 'slave state [A-Z]*\|ad_aggregator_id [0-9]*' |
paste -sd' ' | sed "s/^/ $h: /"; done
n swb bridge fdb show br br0 | grep 02:00:00:00:11:00 |
sed 's/^/ switch B: /'; }
case $CASE in
both) unplug p1; unplug p2; sleep "$WALK"; plug p1; plug p2 ;;
*) case $CASE in one|live-first) a=p2 b=p1 ;; dead-first) a=p1 b=p2 ;; esac
unplug $a; sleep "$WALK"; plug $a; sleep $SETTLE
[ "$CASE" = one ] && { echo " -- one leg on each switch --"; show; }
unplug $b; sleep "$WALK"; plug $b ;;
esac
sleep $SETTLE; mark end; kill $pp
# Every gap over 0.2s between replies, across the WHOLE trace, and the
# marks it spans. "windowed" is the analysis we wrote first: it restarts
# at every mark, so a gap that crosses one is never counted.
awk -v marks=$OUT/marks '
BEGIN { while ((getline l < marks) > 0) {
split(l, a, " "); mt[++m] = a[1]; mn[m] = a[2] } }
/bytes from/ { t = substr($1, 2, length($1) - 2) + 0
if (p && t - p > 0.2) {
s = ""; for (i = 1; i <= m; i++) if (mt[i] > p && mt[i] <= t) s = s " " mn[i]
if (s == "") { w += t - p; for (i = 1; i <= m; i++) if (mt[i] <= p) k = i
s = sprintf(" %.1fs after %s", p - mt[k], mn[k]) }
printf " gap %6.2fs %s\n", t - p, s; tot += t - p }
p = t }
END { if (mt[m] - p > 0.2) { printf " gap %6.2fs not back\n", mt[m] - p
tot += mt[m] - p }
printf " %s, walk %ss: outage %.2fs, windowed analysis %.2fs\n",
ENVIRON["CASE"], ENVIRON["WALK"], tot, w }' $OUT/ping
for ns in swa swb host tgt; do ip netns del $ns; done
The namespace helper uses nsenter because the container we ran it in
would not let ip netns exec remount /sys. On an ordinary host,
ip netns exec does the same job. It needs root, and it leaves nothing
behind.
What it measured#
One cable at a time, with a 10 and then a 20 second walk:
sh bond-move.sh one 10; sh bond-move.sh one 20
-- one leg on each switch --
bond0: ad_aggregator 1 ad_partner_mac 02:00:00:00:0a:00
h1: slave state ACTIVE ad_aggregator_id 1
h2: slave state BACKUP ad_aggregator_id 2
switch B: 02:00:00:00:11:00 dev tb master br0
gap 0.36s unplug-p1
one, walk 10s: outage 0.36s, windowed analysis 0.00s
-- one leg on each switch --
bond0: ad_aggregator 1 ad_partner_mac 02:00:00:00:0a:00
h1: slave state ACTIVE ad_aggregator_id 1
h2: slave state BACKUP ad_aggregator_id 2
switch B: 02:00:00:00:11:00 dev tb master br0
gap 0.20s unplug-p1
gap 0.26s 2.4s after plug-p1
one, walk 20s: outage 0.46s, windowed analysis 0.26s
In the middle of the move, with one leg on each switch, the host’s bond is
doing what the source says. The active aggregator is 1, and its partner is
switch A’s system id, 02:00:00:00:0a:00. h1, still on switch A, is in
it. h2, on switch B, is in aggregator 2, and BACKUP. Switch B has
learned the host’s MAC address on the trunk, not on the port the host just
arrived on. Nothing is lost while either cable is out, for ten seconds or
for twenty. The gap comes when the last cable leaves switch A and
aggregator 2 takes over. On the second run there is another, a couple of
seconds after that cable reaches switch B and joins its new aggregator.
None is longer than 0.36 seconds.
Both cables at once, the procedure our runbook prescribed:
sh bond-move.sh both 10; sh bond-move.sh both 20
gap 18.65s unplug-p2 plug-p1 plug-p2
both, walk 10s: outage 18.65s, windowed analysis 0.00s
gap 29.29s unplug-p2 plug-p1 plug-p2
both, walk 20s: outage 29.29s, windowed analysis 0.00s
| procedure | 10 s walk | 20 s walk |
|---|---|---|
| one cable at a time | 0.36 s | 0.46 s |
| both cables at once | 18.65 s | 29.29 s |
Both-at-once is the walk plus a further eight or nine seconds. One cable at a time does not grow with the walk at all. Our first rig, on a 6.8 kernel, had the same shape: a quarter of a second against the walk plus six.
The extra seconds after the plug belong to the switch side, and the stand-in for a switch here is a Linux bond. Watching the port states in a side run, the switch side held the newly arrived port out of service for about six seconds after the host side was ready. It shows again in the dead-leg run below, where there is no other leg to hide it. A real switch will have its own number, and we did not measure one. With one cable at a time, that settling happens to the waiting aggregator, where it costs nothing. With both at once, it is added to the outage.
The control, and the analysis that scored it zero#
The both-at-once case is the negative control. A rig that reports a quarter of a second for the cheap procedure is only telling you something if the same rig can report a long outage for the expensive one. If it cannot fail, the quarter second is an artifact.
Ours could fail, and our first analysis still missed it. We had marked each unplug and plug in the trace, and the first pass measured the gaps inside each window between two marks. A gap with a mark inside it belonged to neither window, and was not counted. The both-at-once outage begins at an unplug and ends after a plug, so it had marks inside it: the first pass scored the control at 0.05 seconds. The script above still computes that version, as the “windowed analysis” figure, so you can watch it say the outage is zero.
What produced the real numbers was computing every gap between consecutive replies over the whole trace, and only then asking which marks each gap spans. The control is what caught it. Pointed only at the cheap case, the windowed analysis says zero, which is close enough to the truth that nobody would have looked twice.
Why the extra seconds matter#
The servers were Ceph hosts. Ceph’s osd_heartbeat_grace defaults to 20
seconds, documented as “the elapsed time when a Ceph OSD Daemon hasn’t
shown a heartbeat that the Ceph Storage Cluster considers it down.” A
20-second walk with both cables out reaches that before the cables are back
in, and the settling time takes it past. One cable at a time never comes
close.
The runbook also set noout and norebalance before the move, and it is
easy to think that covers the gap. It covers a different clock. noout
means, in Ceph’s words, “down OSDs are not automatically being marked
out after the configured interval,” and that interval,
mon_osd_down_out_interval, defaults to ten minutes. The flags stop the
cluster from moving data while the host is away. They do not stop its OSDs
from being marked down.
The exception: the leg you keep has to work#
One cable at a time protects you on one condition: the leg you leave in place is a working one. One of our servers had been running on a single leg for at least a month. The switch reported one of its two ports dark for the whole 30 days we looked back; the bond was up on the other one, and carrying traffic.
For that server the order decides everything. Moving the live leg first leaves the host on a dead one, for the whole walk and then for the six seconds our stand-in switch takes to accept the leg, 26.86 seconds in all:
sh bond-move.sh live-first 20
gap 20.78s plug-p2
gap 6.08s 2.2s after plug-p2
live-first, walk 20s: outage 26.86s, windowed analysis 6.08s
Moving the dead leg first costs nothing, the live one after it costs the usual quarter second, and the first move tells you something:
sh bond-move.sh dead-first 20
gap 0.25s unplug-p2
dead-first, walk 20s: outage 0.25s, windowed analysis 0.00s
In the rig the dead leg comes up on the new switch because the fault was the old switch’s port. On the real server that was the open question: port, cable, or the server’s own NIC. The procedure we wrote for it was to move the dead leg first and stop. If it comes up on the new switch, the old port was at fault; move the other leg and take the quarter second. If it stays dead, there is no second working leg, and pulling the remaining one is a walk-length outage, so do not, until the cable or the NIC is fixed.
It came up. Both of that server’s legs were live on the new switch, for the first time in a month, and the move itself was the diagnosis. A second server showed the same symptom for the opposite reason: a second NIC that had been added to its bond and never cabled at all. The same one-legged bond, nothing broken, a cable nobody had plugged in.
Where the correction went#
The runbook was written first, with the rule in it. The rig ran the same day, and an hour and a half after the runbook was posted the result went up underneath it as a comment: the both-cables instruction is wrong, move one cable at a time, and here is the order for the server with the dead leg. The body of the runbook, the part with the instructions in it, was not changed to match. It still says both cables move together, in one motion, or not at all.
The move ran eight days later. All three servers came up on the new switch, which we confirmed from the switches’ own port states rather than from the report, and every port the runbook said to leave alone still had link. We do not know which instruction the person at the rack followed. We wrote both.
That is the part worth keeping. The rig was cheap, the result was clear, and it was written up the same day with a table and an order of operations. It was then filed one scroll below the paragraph it overturned. A measurement that corrects a procedure has done its job only when the procedure says something different. Edit the step. Strike the old text through if you want the history. Do not leave the wrong instruction as the first thing a person with a cable in each hand reads.