brintos

brintos / linux-shallow public Read only

0
0
Text · 1.5 KiB · 8e97b1f Raw
85 lines · bash
1# SPDX-License-Identifier: GPL-2.02# Common code for HSR testing scripts3 4source ../lib.sh5ret=06ksft_skip=47 8# $1: IP address9is_v6()10{11	[ -z "${1##*:*}" ]12}13 14do_ping()15{16	local netns="$1"17	local connect_addr="$2"18	local ping_args="-q -c 2"19 20	if is_v6 "${connect_addr}"; then21		$ipv6 || return 022		ping_args="${ping_args} -6"23	fi24 25	ip netns exec ${netns} ping ${ping_args} $connect_addr >/dev/null26	if [ $? -ne 0 ] ; then27		echo "$netns -> $connect_addr connectivity [ FAIL ]" 1>&228		ret=129		return 130	fi31 32	return 033}34 35do_ping_long()36{37	local netns="$1"38	local connect_addr="$2"39	local ping_args="-q -c 10"40 41	if is_v6 "${connect_addr}"; then42		$ipv6 || return 043		ping_args="${ping_args} -6"44	fi45 46	OUT="$(LANG=C ip netns exec ${netns} ping ${ping_args} $connect_addr | grep received)"47	if [ $? -ne 0 ] ; then48		echo "$netns -> $connect_addr ping [ FAIL ]" 1>&249		ret=150		return 151	fi52 53	VAL="$(echo $OUT | cut -d' ' -f1-8)"54	SED_VAL="$(echo ${VAL} | sed -r -e 's/([0-9]{2}).*([0-9]{2}).*[[:space:]]([0-9]+%).*/\1 transmitted \2 received \3 loss/')"55	if [ "${SED_VAL}" != "10 transmitted 10 received 0% loss" ]56	then57		echo "$netns -> $connect_addr ping TEST [ FAIL ]"58		echo "Expect to send and receive 10 packets and no duplicates."59		echo "Full message: ${OUT}."60		ret=161		return 162	fi63 64	return 065}66 67stop_if_error()68{69	local msg="$1"70 71	if [ ${ret} -ne 0 ]; then72		echo "FAIL: ${msg}" 1>&273		exit ${ret}74	fi75}76 77check_prerequisites()78{79	ip -Version > /dev/null 2>&180	if [ $? -ne 0 ];then81		echo "SKIP: Could not run test without ip tool"82		exit $ksft_skip83	fi84}85