Debian Codegraph @

test/rist/test_bonded_carrier_never_starved_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 # Regression for the RTT-mute / stall "no carrier" starvation. The sender pulls
6 # a leg from the payload rotation for two independent reasons: RTT-mute (leg RTT
7 # over the ceiling) and stall (leg gone silent on its return path). Each check
8 # keeps at least one leg out of its OWN mechanism, but they run independently:
9 # one leg muted for high RTT PLUS its only sibling stalled for silence leaves
10 # the balancer with zero carriers, and it then drops the payload. The receiver
11 # starves on both legs at once even though one leg is still perfectly able to
12 # deliver (just late).
13 #
14 # This drives exactly that split on a two-leg bonded caller, in sequence so the
15 # mute genuinely fires before the stall:
16 # 1. leg A (ca): +300 ms each way -> smoothed RTT ~600 ms > rtt-drop=400, and
17 # with leg B still healthy it is actually MUTED (its share moves to B).
18 # 2. leg B (cb): 100% loss both ways -> silent on its return path -> STALLED.
19 # Now A is muted and B is stalled: the balancer has no carrier.
20 # The buffer is large (6 s) so the liveness timeout (~12 s) does not tear leg B
21 # down during the window: it stays authenticated-but-stalled, holding the split.
22 #
23 # Before the fix both legs were skipped and the receiver's per-interval
24 # "received" collapsed to ~0 (only the muted leg's 1-in-100 trickle). After it,
25 # the muted leg is kept as the sole carrier and data keeps flowing, late but
26 # continuous.
27 #
28 # Needs real interfaces + tc, so it runs only on Linux as root with netns/tc and
29 # SKIPs (77) otherwise.
30 #
31 # Usage: test_bonded_carrier_never_starved_netns.sh <ristsender> <ristreceiver>
32 # Exit: 0 = a carrier survived the muted+stalled split (fixed)
33 # 1 = receiver starved on both legs at once (regression)
34 # 77 = SKIP (needs Linux root + netns + tc)
35 # 99 = setup error / INDETERMINATE (the split did not form)
36 set -u
37
38 TX="${1:-}"
39 RX="${2:-}"
40 USER=carrieruser; PASS=carrierpass; CN=testcn
41 RXIP=10.0.2.61
42 NS=rist_carrier_snd
43 RXLOG="$(mktempscip-shell system . . mktemp.)"; TXLOG="$(mktempscip-shell system . . mktemp.)"
44
45 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; }
46 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; }
47
48 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
49 ip netns del "$NS" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
50 ip link del veth-ca 2>/dev/nullscip-shell filesystem . . `/dev/null`.
51 ip link del veth-cb 2>/dev/nullscip-shell filesystem . . `/dev/null`.
52 ip link del cbr0 2>/dev/nullscip-shell filesystem . . `/dev/null`.
53 [scip-shell system . . `[`. -n "${TXPID:-}" ] && killscip-shell system . . kill. "$TXPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
54 [scip-shell system . . `[`. -n "${RXPID:-}" ] && killscip-shell system . . kill. "$RXPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
55 [scip-shell system . . `[`. -n "${FEEDPID:-}" ] && killscip-shell system . . kill. "$FEEDPID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
56 rmscip-shell system . . rm. -f "$RXLOG" "$TXLOG" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
57 }
58 trap cleanup EXIT
59
60 # ---- environment gate: skip cleanly where we cannot reproduce ----------
61 [scip-shell system . . `[`. "$(unamescip-shell system . . uname. -s)" = "Linux" ] || skipscip-shell shell shell-project 0.0.0 skip(). "not Linux"
62 [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"
63 [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)"
64 [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)"
65 command -v ip >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "iproute2 'ip' missing"
66 command -v tc >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "iproute2 'tc' missing"
67 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?)"
68
69 # ---- topology: bridge in root ns, two veth legs into a sender netns -----
70 ip link add cbr0 type bridge || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge add"
71 ip addr add ${RXIP}/24 dev cbr0 || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge addr"
72 ip link set cbr0 up || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "bridge up"
73
74 ip link add veth-ca type veth peer name ca || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "veth-ca"
75 ip link add veth-cb type veth peer name cb || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "veth-cb"
76 ip link set veth-ca master cbr0; ip link set veth-ca up
77 ip link set veth-cb master cbr0; ip link set veth-cb up
78 ip link set ca netns "$NS"; ip link set cb netns "$NS"
79 ip netns exec "$NS" ip addr add 10.0.2.30/24 dev ca
80 ip netns exec "$NS" ip addr add 10.0.2.131/24 dev cb
81 ip netns exec "$NS" ip link set ca up
82 ip netns exec "$NS" ip link set cb up
83 ip netns exec "$NS" ip link set lo up
84 # same-subnet multi-homing: disable rp_filter so miface egress is kept
85 ip netns exec "$NS" sysctl -qw net.ipv4.conf.all.rp_filter=0
86 ip netns exec "$NS" sysctl -qw net.ipv4.conf.ca.rp_filter=0
87 ip netns exec "$NS" sysctl -qw net.ipv4.conf.cb.rp_filter=0
88 sysctlscip-shell system . . sysctl. -qw net.ipv4.conf.all.rp_filter=0 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
89
90 ip netns exec "$NS" ping -c1 -W2 -I ca ${RXIP} >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "leg A no connectivity"
91 ip netns exec "$NS" ping -c1 -W2 -I cb ${RXIP} >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "leg B no connectivity"
92
93 # ---- receiver: listener, advanced profile, SRP authenticator -----------
94 # 6 s buffer keeps the liveness timeout (~2x buffer) well above the ~8 s
95 # impairment, so leg B stays authenticated-but-stalled. -S 500 gives fine
96 # stats sampling for the received-per-interval measurement below.
97 $RX -p 2 -v 6 -S 500 \
98 -i "rist://@${RXIP}:2041?username=${USER}&password=${PASS}&buffer=6000" \
99 -o "udp://127.0.0.1:12356" >"$RXLOG" 2>&1 &
100 RXPID=$!
101 sleepscip-shell system . . sleep. 1
102
103 # udp feeder inside the sender netns -> ristsender input (~50 pkt/s)
104 ip netns exec "$NS" bash -c 'while :; do printf "RISTTESTPACKET%08d" $RANDOM > /dev/udp/127.0.0.1/5567; sleep 0.02; done' &
105 FEEDPID=$!
106 sleepscip-shell system . . sleep. 0.5
107
108 # ---- sender: bonded caller, two SRP legs with RTT auto-mute configured --
109 RTTQS="rtt-drop=400&rtt-restore=200&rtt-drop-settle=1000&rtt-drop-trickle=100"
110 ip netns exec "$NS" $TX -p 2 -v 6 \
111 -i "udp://@127.0.0.1:5567" \
112 -o "rist://${RXIP}:2041?miface=ca&weight=5&username=${USER}&password=${PASS}&cname=${CN}&buffer=6000&${RTTQS},rist://${RXIP}:2041?miface=cb&weight=5&username=${USER}&password=${PASS}&cname=${CN}&buffer=6000&${RTTQS}" \
113 >"$TXLOG" 2>&1 &
114 TXPID=$!
115
116 echoscip-shell system . . echo. "== warmup 12s (both legs authenticate + stream) =="
117 sleepscip-shell system . . sleep. 12
118 auths_setup=$(grepscip-shell system . . grep. -c "Successfully authenticated" "$RXLOG")
119 echoscip-shell system . . echo. "after warmup: successful auths=${auths_setup}"
120 if [scip-shell system . . `[`. "$auths_setup" -lt 2 ]; then
121 echoscip-shell system . . echo. "INDETERMINATE: both legs did not authenticate before the impairment."
122 exit 99
123 fi
124
125 echoscip-shell system . . echo. "== step 1: leg A (ca) +300ms each way -> RTT over ceiling, mutes (B healthy) =="
126 ip netns exec "$NS" tc qdisc add dev ca root netem delay 300ms || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add ca"
127 tc qdisc add dev veth-ca root netem delay 300ms || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add veth-ca"
128 sleepscip-shell system . . sleep. 4 # RTT ramp + drop-settle: leg A actually mutes while B still carries
129
130 echoscip-shell system . . echo. "== step 2: leg B (cb) 100% loss both ways -> stalls; A must be kept carrier =="
131 ip netns exec "$NS" tc qdisc add dev cb root netem loss 100% || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add cb"
132 tc qdisc add dev veth-cb root netem loss 100% || setup_errscip-shell shell shell-project 0.0.0 setup_err(). "tc add veth-cb"
133
134 echoscip-shell system . . echo. "== let the split form (3s) =="
135 sleepscip-shell system . . sleep. 3
136 rx_off=$(wcscip-shell system . . wc. -l < "$RXLOG")
137
138 echoscip-shell system . . echo. "== measure received-per-interval for 6s while muted+stalled =="
139 sleepscip-shell system . . sleep. 6
140
141 # ---- teardown impairment; observe recovery briefly ----------------------
142 ip netns exec "$NS" tc qdisc del dev ca root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
143 tc qdisc del dev veth-ca root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
144 ip netns exec "$NS" tc qdisc del dev cb root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
145 tc qdisc del dev veth-cb root 2>/dev/nullscip-shell filesystem . . `/dev/null`.
146
147 # ---- INDETERMINATE guard: the muted+stalled split must actually form -----
148 muted=$(grepscip-shell system . . grep. -c "over .*ceiling" "$TXLOG")
149 stalled=$(grepscip-shell system . . grep. -c "stalled: silent" "$TXLOG")
150 echoscip-shell system . . echo. "== split check: mute events=${muted}, stall events=${stalled} =="
151 if [scip-shell system . . `[`. "$muted" -eq 0 ] || [scip-shell system . . `[`. "$stalled" -eq 0 ]; then
152 echoscip-shell system . . echo. "INDETERMINATE: impairment did not produce a muted+stalled split"\
153 "(mute=${muted}, stall=${stalled}); cannot judge the carrier guard."
154 exit 99
155 fi
156
157 # ---- verdict: with both legs pulled, did the receiver keep getting data? -
158 # Per-interval flow "received" over the measurement window. Streaming ~50 pkt/s
159 # at -S 500 is ~25/interval when a carrier survives; starvation leaves only the
160 # muted leg's 1-in-100 trickle, i.e. ~0.
161 window=$(tailscip-shell system . . tail. -n +"$((rx_off + 1))" "$RXLOG" | grepscip-shell system . . grep. '"receiver-stats"')
162 intervals=$(printfscip-shell system . . printf. '%s\n' "$window" | grepscip-shell system . . grep. -c '"received"')
163 ok=$(printfscip-shell system . . printf. '%s\n' "$window" | grepscip-shell system . . grep. -o '"received":[0-9]*' \
164 | grep -o '[0-9]*' | awk '$1 >= 10 {c++} END {print c+0}')
165 maxrx=$(printfscip-shell system . . printf. '%s\n' "$window" | grepscip-shell system . . grep. -o '"received":[0-9]*' \
166 | grep -o '[0-9]*' | sort -n | tail -1)
167 echoscip-shell system . . echo. "== during split: ${intervals} stats intervals, ${ok} with received>=10,"\
168 "peak received/interval=${maxrx:-0} =="
169
170 if [scip-shell system . . `[`. "${intervals:-0}" -lt 3 ]; then
171 echoscip-shell system . . echo. "INDETERMINATE: too few receiver-stats samples in the window"\
172 "(${intervals}); cannot judge starvation."
173 exit 99
174 fi
175 if [scip-shell system . . `[`. "${ok:-0}" -lt 3 ]; then
176 echoscip-shell system . . echo. "FAIL: receiver starved during the muted+stalled split"\
177 "(${ok}/${intervals} intervals carried data, peak ${maxrx:-0}/interval);"\
178 "both legs were pulled and the payload was dropped."
179 exit 1
180 fi
181
182 echoscip-shell system . . echo. "PASS: a carrier survived the muted+stalled split"\
183 "(${ok}/${intervals} intervals carried data, peak ${maxrx}/interval);"\
184 "data kept flowing on the reinstated leg instead of starving."
185 exit 0