Debian Codegraph @

test/rist/test_bonded_leg_stall_grace_netns.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # librist. Copyright © 2026 SipRadius LLC.
3 # SPDX-License-Identifier: BSD-2-Clause
4 #
5 # Companion to test_bonded_leg_flap_netns.sh (issue #224). That test silences a
6 # bonded leg long enough to exceed the liveness timeout and asserts the leg tears
7 # down and re-handshakes. This one asserts the opposite for a SHORT stall: a leg
8 # that goes silent for less than the liveness timeout must be fast-muted but kept
9 # authenticated and resume on the SAME session, with no re-auth churn.
10 #
11 # Setup mirrors the #224 test: a bonded EAP-SRP caller with two legs to one
12 # listening receiver, one leg silenced (100% loss both ways, interface UP so the
13 # source tuple persists) while the other keeps the bond alive. The difference is
14 # the buffer: large, so the liveness timeout (max of session_timeout and twice
15 # the buffer) is ~12 s, well above the 6 s silence.
16 #
17 # Before routing and session lifetime were split, any silence past the (then
18 # 250 ms) liveness timeout tore the leg down and forced a cold re-handshake. Now:
19 # 1. No sender EAP reset ("reset EAP and re-initiated the SRP" must stay 0).
20 # 2. No new receiver auth (successful-auth count must not move: the leg keeps
21 # its original session across the stall).
22 # 3. The leg is back in the weighted bond after recovery (two mifaces in the
23 # final sender-stats line), proving the mute self-cleared on resume.
24 #
25 # Needs real interfaces + tc loss, so it runs only on Linux as root with
26 # netns/tc and SKIPs (77) otherwise.
27 #
28 # Usage: test_bonded_leg_stall_grace_netns.sh <ristsender> <ristreceiver>
29 # Exit: 0 = short stall rode through on the same session (fixed)
30 # 1 = leg re-authenticated on a sub-grace stall (regression)
31 # 77 = SKIP (needs Linux root + netns + tc) 99 = setup error
32 set -u
33
34 TX="${1:-}"
35 RX="${2:-}"
36 USER=graceuser; PASS=gracepass; CN=testcn
37 RXIP=10.0.2.51
38 NS=rist_grace_snd
39 RXLOG="$(mktempscip-shell system . . mktemp.)"; TXLOG="$(mktempscip-shell system . . mktemp.)"
40
41 skipscip-shell shell shell-project 0.0.0 skip().() { echoscip-shell system . . echo. "SKIP: $*"; cleanupscip-shell shell shell-project 0.0.0 cleanup(). 2>/dev/nullscip-shell filesystem . . `/dev/null`.; exit 77; }
42 setup_errscip-shell shell shell-project 0.0.0 setup_err().() { echoscip-shell system . . echo. "SETUP ERROR: $*"; cleanupscip-shell shell shell-project 0.0.0 cleanup(). 2>/dev/nullscip-shell filesystem . . `/dev/null`.; exit 99; }
43
44 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
45 ip netns del "$NS" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
46 ip link del veth-ga 2>/dev/nullscip-shell filesystem . . `/dev/null`.
47 ip link del veth-gb 2>/dev/nullscip-shell filesystem . . `/dev/null`.
48 ip link del gbr0 2>/dev/nullscip-shell filesystem . . `/dev/null`.
49 [scip-shell system . . `[`. -n "${TXPID:-}" ] && killscip-shell system . . kill. "$TXPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
50 [scip-shell system . . `[`. -n "${RXPID:-}" ] && killscip-shell system . . kill. "$RXPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
51 [scip-shell system . . `[`. -n "${FEEDPID:-}" ] && killscip-shell system . . kill. "$FEEDPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
52 rmscip-shell system . . rm. -f "$RXLOG" "$TXLOG" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
53 }
54 trap cleanup EXIT
55
56 # ---- environment gate: skip cleanly where we cannot reproduce ----------
57 [scip-shell system . . `[`. "$(unamescip-shell system . . uname. -s)" = "Linux" ] || skipscip-shell shell shell-project 0.0.0 skip(). "not Linux"
58 [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" = "0" ] || skipscip-shell shell shell-project 0.0.0 skip(). "needs root (CAP_NET_ADMIN) for netns/veth/tc"
59 [scip-shell system . . `[`. -n "$TX" ] && [scip-shell system . . `[`. -x "$TX" ] || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "ristsender not found ($TX)"
60 [scip-shell system . . `[`. -n "$RX" ] && [scip-shell system . . `[`. -x "$RX" ] || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "ristreceiver not found ($RX)"
61 command -v ip >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "iproute2 'ip' missing"
62 command -v tc >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "iproute2 'tc' missing"
63 ip netns add "$NS" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || skipscip-shell shell shell-project 0.0.0 skip(). "cannot create netns (no CAP_NET_ADMIN?)"
64
65 # ---- topology: bridge in root ns, two veth legs into a sender netns -----
66 ip link add gbr0 type bridge || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge add"
67 ip addr add ${RXIP}/24 dev gbr0 || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge addr"
68 ip link set gbr0 up || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge up"
69
70 ip link add veth-ga type veth peer name ga || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "veth-ga"
71 ip link add veth-gb type veth peer name gb || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "veth-gb"
72 ip link set veth-ga master gbr0; ip link set veth-ga up
73 ip link set veth-gb master gbr0; ip link set veth-gb up
74 ip link set ga netns "$NS"; ip link set gb netns "$NS"
75 ip netns exec "$NS" ip addr add 10.0.2.20/24 dev ga
76 ip netns exec "$NS" ip addr add 10.0.2.122/24 dev gb
77 ip netns exec "$NS" ip link set ga up
78 ip netns exec "$NS" ip link set gb up
79 ip netns exec "$NS" ip link set lo up
80 # same-subnet multi-homing: disable rp_filter so miface egress is kept
81 ip netns exec "$NS" sysctl -qw net.ipv4.conf.all.rp_filter=0
82 ip netns exec "$NS" sysctl -qw net.ipv4.conf.ga.rp_filter=0
83 ip netns exec "$NS" sysctl -qw net.ipv4.conf.gb.rp_filter=0
84 sysctlscip-shell system . . sysctl. -qw net.ipv4.conf.all.rp_filter=0 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
85
86 ip netns exec "$NS" ping -c1 -W2 -I ga ${RXIP} >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "leg A no connectivity"
87 ip netns exec "$NS" ping -c1 -W2 -I gb ${RXIP} >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "leg B no connectivity"
88
89 # ---- receiver: listener, advanced profile, SRP authenticator -----------
90 # Large buffer so the re-auth grace (~2x buffer) is ~12 s, comfortably above
91 # the 6 s stall below.
92 $RX -p 2 -v 6 \
93 -i "rist://@${RXIP}:2031?username=${USER}&password=${PASS}&buffer=6000" \
94 -o "udp://127.0.0.1:12346" >"$RXLOG" 2>&1 &
95 RXPID=$!
96 sleepscip-shell system . . sleep. 1
97
98 # udp feeder inside the sender netns -> ristsender input
99 ip netns exec "$NS" bash -c 'while :; do printf "RISTTESTPACKET%08d" $RANDOM > /dev/udp/127.0.0.1/5557; sleep 0.02; done' &
100 FEEDPID=$!
101 sleepscip-shell system . . sleep. 0.5
102
103 # ---- sender: bonded caller, two SRP legs (same cname + creds) ----------
104 ip netns exec "$NS" $TX -p 2 -v 6 \
105 -i "udp://@127.0.0.1:5557" \
106 -o "rist://${RXIP}:2031?miface=ga&weight=10&username=${USER}&password=${PASS}&cname=${CN}&buffer=6000,rist://${RXIP}:2031?miface=gb&weight=5&username=${USER}&password=${PASS}&cname=${CN}&buffer=6000" \
107 >"$TXLOG" 2>&1 &
108 TXPID=$!
109
110 echoscip-shell system . . echo. "== warmup 12s (both legs authenticate + stream) =="
111 sleepscip-shell system . . sleep. 12
112 auths_setup=$(grepscip-shell system . . grep. -c "Successfully authenticated" "$RXLOG")
113 echoscip-shell system . . echo. "after warmup: successful auths=${auths_setup}"
114 if [scip-shell system . . `[`. "$auths_setup" -lt 2 ]; then
115 echoscip-shell system . . echo. "INDETERMINATE: both legs did not authenticate before the stall."
116 exit 99
117 fi
118
119 echoscip-shell system . . echo. "== stall leg B (gb): 100% loss both ways, interface UP, 6s (< grace) =="
120 ip netns exec "$NS" tc qdisc add dev gb root netem loss 100% || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add gb"
121 tc qdisc add dev veth-gb root netem loss 100% || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add veth-gb"
122 sleepscip-shell system . . sleep. 6
123 echoscip-shell system . . echo. "== leg B restored (same socket / same source tuple) =="
124 ip netns exec "$NS" tc qdisc del dev gb root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
125 tc qdisc del dev veth-gb root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
126 echoscip-shell system . . echo. "== observe 15s (leg B must resume on the SAME session, no re-auth) =="
127 sleepscip-shell system . . sleep. 15
128
129 auths_final=$(grepscip-shell system . . grep. -c "Successfully authenticated" "$RXLOG")
130 resets=$(grepscip-shell system . . grep. -c "reset EAP and re-initiated the SRP" "$TXLOG")
131 last_sstats=$(grepscip-shell system . . grep. '"sender-stats"' "$TXLOG" | tailscip-shell system . . tail. -1)
132 legs_balancing=$(printfscip-shell system . . printf. '%s' "$last_sstats" | grepscip-shell system . . grep. -o '"miface":"[^"]*"' | sortscip-shell system . . sort. -u | wcscip-shell system . . wc. -l)
133 legs_balancing=$(printfscip-shell system . . printf. '%s' "$legs_balancing" | trscip-shell system . . tr. -d ' ')
134 echoscip-shell system . . echo. "== after stall: successful auths ${auths_setup} -> ${auths_final}, "\
135 "sender EAP resets=${resets}, legs balancing after recovery=${legs_balancing} =="
136
137 # 1 + 2: a sub-grace stall must not tear the session down. Any sender EAP reset
138 # or a rise in the receiver's successful-auth count means the leg re-handshook
139 # instead of riding through on its existing session.
140 if [scip-shell system . . `[`. "$resets" -ne 0 ] || [scip-shell system . . `[`. "$auths_final" -ne "$auths_setup" ]; then
141 echoscip-shell system . . echo. "FAIL: a 6s stall (under the ~12s grace) forced a re-auth"\
142 "(sender EAP resets=${resets}, successful auths ${auths_setup} ->"\
143 "${auths_final}); the leg should have resumed on the same session."
144 exit 1
145 fi
146
147 # 3: the muted leg self-cleared on resume and is back in the weighted bond.
148 if [scip-shell system . . `[`. "${legs_balancing:-0}" -lt 2 ]; then
149 echoscip-shell system . . echo. "FAIL: leg B did not rejoin the weighted bond after the stall"\
150 "(sender balances over only ${legs_balancing} leg)."
151 exit 1
152 fi
153
154 echoscip-shell system . . echo. "PASS: the 6s stall rode through on the same session (no EAP reset,"\
155 "successful auths stayed ${auths_setup}) and leg B rejoined the bond"\
156 "(${legs_balancing} legs balancing)."
157 exit 0