~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/mptcp/diag.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 # Double quotes to prevent globbing and word splitting is recommended in new
  5 # code but we accept it, especially because there were too many before having
  6 # address all other issues detected by shellcheck.
  7 #shellcheck disable=SC2086
  8 
  9 . "$(dirname "${0}")/mptcp_lib.sh"
 10 
 11 ns=""
 12 timeout_poll=30
 13 timeout_test=$((timeout_poll * 2 + 1))
 14 ret=0
 15 
 16 flush_pids()
 17 {
 18         # mptcp_connect in join mode will sleep a bit before completing,
 19         # give it some time
 20         sleep 1.1
 21 
 22         ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGUSR1 &>/dev/null
 23 
 24         for _ in $(seq $((timeout_poll * 10))); do
 25                 [ -z "$(ip netns pids "${ns}")" ] && break
 26                 sleep 0.1
 27         done
 28 }
 29 
 30 # This function is used in the cleanup trap
 31 #shellcheck disable=SC2317
 32 cleanup()
 33 {
 34         ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null
 35 
 36         mptcp_lib_ns_exit "${ns}"
 37 }
 38 
 39 mptcp_lib_check_mptcp
 40 mptcp_lib_check_tools ip ss
 41 
 42 get_msk_inuse()
 43 {
 44         ip netns exec $ns cat /proc/net/protocols | awk '$1~/^MPTCP$/{print $3}'
 45 }
 46 
 47 __chk_nr()
 48 {
 49         local command="$1"
 50         local expected=$2
 51         local msg="$3"
 52         local skip="${4-SKIP}"
 53         local nr
 54 
 55         nr=$(eval $command)
 56 
 57         mptcp_lib_print_title "$msg"
 58         if [ "$nr" != "$expected" ]; then
 59                 if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; then
 60                         mptcp_lib_pr_skip "Feature probably not supported"
 61                         mptcp_lib_result_skip "${msg}"
 62                 else
 63                         mptcp_lib_pr_fail "expected $expected found $nr"
 64                         mptcp_lib_result_fail "${msg}"
 65                         ret=${KSFT_FAIL}
 66                 fi
 67         else
 68                 mptcp_lib_pr_ok
 69                 mptcp_lib_result_pass "${msg}"
 70         fi
 71 }
 72 
 73 __chk_msk_nr()
 74 {
 75         local condition=$1
 76         shift 1
 77 
 78         __chk_nr "ss -inmHMN $ns | $condition" "$@"
 79 }
 80 
 81 chk_msk_nr()
 82 {
 83         __chk_msk_nr "grep -c token:" "$@"
 84 }
 85 
 86 chk_listener_nr()
 87 {
 88         local expected=$1
 89         local msg="$2"
 90 
 91         __chk_nr "ss -nlHMON $ns | wc -l" "$expected" "$msg - mptcp" 0
 92         __chk_nr "ss -nlHtON $ns | wc -l" "$expected" "$msg - subflows"
 93 }
 94 
 95 wait_msk_nr()
 96 {
 97         local condition="grep -c token:"
 98         local expected=$1
 99         local timeout=20
100         local msg nr
101         local max=0
102         local i=0
103 
104         shift 1
105         msg=$*
106 
107         while [ $i -lt $timeout ]; do
108                 nr=$(ss -inmHMN $ns | $condition)
109                 [ $nr == $expected ] && break;
110                 [ $nr -gt $max ] && max=$nr
111                 i=$((i + 1))
112                 sleep 1
113         done
114 
115         mptcp_lib_print_title "$msg"
116         if [ $i -ge $timeout ]; then
117                 mptcp_lib_pr_fail "timeout while expecting $expected max $max last $nr"
118                 mptcp_lib_result_fail "${msg} # timeout"
119                 ret=${KSFT_FAIL}
120         elif [ $nr != $expected ]; then
121                 mptcp_lib_pr_fail "expected $expected found $nr"
122                 mptcp_lib_result_fail "${msg} # unexpected result"
123                 ret=${KSFT_FAIL}
124         else
125                 mptcp_lib_pr_ok
126                 mptcp_lib_result_pass "${msg}"
127         fi
128 }
129 
130 chk_msk_fallback_nr()
131 {
132         __chk_msk_nr "grep -c fallback" "$@"
133 }
134 
135 chk_msk_remote_key_nr()
136 {
137         __chk_msk_nr "grep -c remote_key" "$@"
138 }
139 
140 __chk_listen()
141 {
142         local filter="$1"
143         local expected=$2
144         local msg="$3"
145 
146         __chk_nr "ss -N $ns -Ml '$filter' | grep -c LISTEN" "$expected" "$msg" 0
147 }
148 
149 chk_msk_listen()
150 {
151         lport=$1
152 
153         # destination port search should always return empty list
154         __chk_listen "dport $lport" 0 "listen match for dport $lport"
155 
156         # should return 'our' mptcp listen socket
157         __chk_listen "sport $lport" 1 "listen match for sport $lport"
158 
159         __chk_listen "src inet:0.0.0.0:$lport" 1 "listen match for saddr and sport"
160 
161         __chk_listen "" 1 "all listen sockets"
162 
163         nr=$(ss -Ml $filter | wc -l)
164 }
165 
166 chk_msk_inuse()
167 {
168         local expected=$1
169         local msg="....chk ${2:-${expected}} msk in use"
170         local listen_nr
171 
172         if [ "${expected}" -eq 0 ]; then
173                 msg+=" after flush"
174         fi
175 
176         listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
177         expected=$((expected + listen_nr))
178 
179         for _ in $(seq 10); do
180                 if [ "$(get_msk_inuse)" -eq $expected ]; then
181                         break
182                 fi
183                 sleep 0.1
184         done
185 
186         __chk_nr get_msk_inuse $expected "${msg}" 0
187 }
188 
189 # $1: cestab nr
190 chk_msk_cestab()
191 {
192         local expected=$1
193         local msg="....chk ${2:-${expected}} cestab"
194 
195         if [ "${expected}" -eq 0 ]; then
196                 msg+=" after flush"
197         fi
198 
199         __chk_nr "mptcp_lib_get_counter ${ns} MPTcpExtMPCurrEstab" \
200                  "${expected}" "${msg}" ""
201 }
202 
203 msk_info_get_value()
204 {
205         local port="${1}"
206         local info="${2}"
207 
208         ss -N "${ns}" -inHM dport "${port}" | \
209                 mptcp_lib_get_info_value "${info}" "${info}"
210 }
211 
212 chk_msk_info()
213 {
214         local port="${1}"
215         local info="${2}"
216         local cnt="${3}"
217         local msg="....chk ${info}"
218         local delta_ms=250  # half what we waited before, just to be sure
219         local now
220 
221         now=$(msk_info_get_value "${port}" "${info}")
222 
223         mptcp_lib_print_title "${msg}"
224         if { [ -z "${cnt}" ] || [ -z "${now}" ]; } &&
225            ! mptcp_lib_expect_all_features; then
226                 mptcp_lib_pr_skip "Feature probably not supported"
227                 mptcp_lib_result_skip "${msg}"
228         elif [ "$((cnt + delta_ms))" -lt "${now}" ]; then
229                 mptcp_lib_pr_ok
230                 mptcp_lib_result_pass "${msg}"
231         else
232                 mptcp_lib_pr_fail "value of ${info} changed by $((now - cnt))ms," \
233                                   "expected at least ${delta_ms}ms"
234                 mptcp_lib_result_fail "${msg}"
235                 ret=${KSFT_FAIL}
236         fi
237 }
238 
239 chk_last_time_info()
240 {
241         local port="${1}"
242         local data_sent data_recv ack_recv
243 
244         data_sent=$(msk_info_get_value "${port}" "last_data_sent")
245         data_recv=$(msk_info_get_value "${port}" "last_data_recv")
246         ack_recv=$(msk_info_get_value "${port}" "last_ack_recv")
247 
248         sleep 0.5  # wait to check after if the timestamps difference
249 
250         chk_msk_info "${port}" "last_data_sent" "${data_sent}"
251         chk_msk_info "${port}" "last_data_recv" "${data_recv}"
252         chk_msk_info "${port}" "last_ack_recv" "${ack_recv}"
253 }
254 
255 wait_connected()
256 {
257         local listener_ns="${1}"
258         local port="${2}"
259 
260         local port_hex i
261 
262         port_hex="$(printf "%04X" "${port}")"
263         for i in $(seq 10); do
264                 ip netns exec ${listener_ns} grep -q " 0100007F:${port_hex} " /proc/net/tcp && break
265                 sleep 0.1
266         done
267 }
268 
269 trap cleanup EXIT
270 mptcp_lib_ns_init ns
271 
272 echo "a" | \
273         timeout ${timeout_test} \
274                 ip netns exec $ns \
275                         ./mptcp_connect -p 10000 -l -t ${timeout_poll} -w 20 \
276                                 0.0.0.0 >/dev/null &
277 mptcp_lib_wait_local_port_listen $ns 10000
278 chk_msk_nr 0 "no msk on netns creation"
279 chk_msk_listen 10000
280 
281 echo "b" | \
282         timeout ${timeout_test} \
283                 ip netns exec $ns \
284                         ./mptcp_connect -p 10000 -r 0 -t ${timeout_poll} -w 20 \
285                                 127.0.0.1 >/dev/null &
286 wait_connected $ns 10000
287 chk_msk_nr 2 "after MPC handshake"
288 chk_last_time_info 10000
289 chk_msk_remote_key_nr 2 "....chk remote_key"
290 chk_msk_fallback_nr 0 "....chk no fallback"
291 chk_msk_inuse 2
292 chk_msk_cestab 2
293 flush_pids
294 
295 chk_msk_inuse 0 "2->0"
296 chk_msk_cestab 0 "2->0"
297 
298 echo "a" | \
299         timeout ${timeout_test} \
300                 ip netns exec $ns \
301                         ./mptcp_connect -p 10001 -l -s TCP -t ${timeout_poll} -w 20 \
302                                 0.0.0.0 >/dev/null &
303 mptcp_lib_wait_local_port_listen $ns 10001
304 echo "b" | \
305         timeout ${timeout_test} \
306                 ip netns exec $ns \
307                         ./mptcp_connect -p 10001 -r 0 -t ${timeout_poll} -w 20 \
308                                 127.0.0.1 >/dev/null &
309 wait_connected $ns 10001
310 chk_msk_fallback_nr 1 "check fallback"
311 chk_msk_inuse 1
312 chk_msk_cestab 1
313 flush_pids
314 
315 chk_msk_inuse 0 "1->0"
316 chk_msk_cestab 0 "1->0"
317 
318 NR_CLIENTS=100
319 for I in $(seq 1 $NR_CLIENTS); do
320         echo "a" | \
321                 timeout ${timeout_test} \
322                         ip netns exec $ns \
323                                 ./mptcp_connect -p $((I+10001)) -l -w 20 \
324                                         -t ${timeout_poll} 0.0.0.0 >/dev/null &
325 done
326 mptcp_lib_wait_local_port_listen $ns $((NR_CLIENTS + 10001))
327 
328 for I in $(seq 1 $NR_CLIENTS); do
329         echo "b" | \
330                 timeout ${timeout_test} \
331                         ip netns exec $ns \
332                                 ./mptcp_connect -p $((I+10001)) -w 20 \
333                                         -t ${timeout_poll} 127.0.0.1 >/dev/null &
334 done
335 
336 wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
337 chk_msk_inuse $((NR_CLIENTS*2)) "many"
338 chk_msk_cestab $((NR_CLIENTS*2)) "many"
339 flush_pids
340 
341 chk_msk_inuse 0 "many->0"
342 chk_msk_cestab 0 "many->0"
343 
344 chk_listener_nr 0 "no listener sockets"
345 NR_SERVERS=100
346 for I in $(seq 1 $NR_SERVERS); do
347         ip netns exec $ns ./mptcp_connect -p $((I + 20001)) \
348                 -t ${timeout_poll} -l 0.0.0.0 >/dev/null 2>&1 &
349 done
350 mptcp_lib_wait_local_port_listen $ns $((NR_SERVERS + 20001))
351 
352 chk_listener_nr $NR_SERVERS "many listener sockets"
353 
354 # graceful termination
355 for I in $(seq 1 $NR_SERVERS); do
356         echo a | ip netns exec $ns ./mptcp_connect -p $((I + 20001)) 127.0.0.1 >/dev/null 2>&1 &
357 done
358 flush_pids
359 
360 mptcp_lib_result_print_all_tap
361 exit $ret

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php