123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- #!/bin/sh
- # SPDX-License-Identifier: GPL-2.0-or-later
- # Copyright (c) 2018-2019 Petr Vorel <pvorel@suse.cz>
- # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
- # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
- #
- # VxLAN
- # -----
- # Virtual eXtensible Local Area Network (VxLAN) provides L2 networks
- # over existed L3 networks. It is using UDP (port 8472) to encapsulate
- # data packets. More information:
- # http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-08
- #
- # Warning: Test assumes that machines don't have any existed VxLANs.
- # If machine has VxLANs, the test might fail or eventually delete
- # them in cleanup function. See "start_vni" variable which can
- # solve it.
- TST_SETUP="${TST_SETUP:-virt_lib_setup}"
- TST_CLEANUP="${TST_CLEANUP:-cleanup_vifaces}"
- virt_lib_usage()
- {
- echo "i n start ID to use"
- echo "d x VxLAN destination address, 'uni' or 'multi'"
- }
- virt_lib_parse_args()
- {
- case "$1" in
- i) start_id=$2 ;;
- d) vxlan_dst_addr=$2 ;;
- esac
- }
- virt_lib_setup()
- {
- case "$virt_type" in
- vxlan|geneve)
- if tst_kvcmp -lt "3.8"; then
- tst_brk TCONF "test must be run with kernel 3.8 or newer"
- fi
- if [ "$TST_IPV6" ] && tst_kvcmp -lt "3.12"; then
- tst_brk TCONF "test must be run with kernels >= 3.12"
- fi
- # newer versions of 'ip' complain if this option not set
- ip li add type vxlan help 2>&1 | grep -q dstport && vxlan_dstport=1
- ;;
- esac
- tst_require_cmds "ip"
- virt_add ltp_v0 || \
- tst_brk TCONF "iproute2 or kernel doesn't support $virt_type"
- ROD_SILENT "ip link delete ltp_v0"
- }
- TST_NEEDS_ROOT=1
- . tst_net.sh
- ip_virt_local="$(TST_IPV6= tst_ipaddr_un)"
- ip6_virt_local="$(TST_IPV6=6 tst_ipaddr_un)"
- ip_virt_remote="$(TST_IPV6= tst_ipaddr_un rhost)"
- ip6_virt_remote="$(TST_IPV6=6 tst_ipaddr_un rhost)"
- vxlan_dstport=0
- # Max performance loss (%) for virtual devices during network load
- VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-80}
- if [ -n "$VIRT_PERF_THRESHOLD_MIN" ] && [ "$VIRT_PERF_THRESHOLD" -lt $VIRT_PERF_THRESHOLD_MIN ]; then
- VIRT_PERF_THRESHOLD="$VIRT_PERF_THRESHOLD_MIN"
- fi
- cleanup_vifaces()
- {
- tst_res TINFO "cleanup virtual interfaces..."
- local viface=`ip li | sed -nE 's/^[0-9]+: (ltp_v[0-9]+)[@:].+/\1/p'`
- for vx in $viface; do
- ip link delete $vx
- done
- }
- virt_cleanup_rmt()
- {
- cleanup_vifaces
- tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
- if [ "$virt_tcp_syn" ]; then
- sysctl -q net.ipv4.tcp_syn_retries=$virt_tcp_syn
- virt_tcp_syn=
- fi
- }
- virt_cleanup()
- {
- virt_cleanup_rmt
- }
- virt_add()
- {
- local vname=$1
- shift
- local opt="$*"
- case $virt_type in
- vlan|vxlan)
- [ -z "$opt" ] && opt="id 4094"
- [ "$vxlan_dstport" -eq 1 ] && opt="dstport 0 $opt"
- [ "$virt_type" = "vxlan" ] && opt="$opt dev $(tst_iface)"
- ;;
- geneve)
- [ -z "$opt" ] && opt="id 4094 remote $(tst_ipaddr rhost)"
- ;;
- gre|ip6gre)
- [ -z "$opt" ] && \
- opt="remote $(tst_ipaddr rhost) dev $(tst_iface)"
- ;;
- sit)
- [ -z "$opt" ] && opt="remote $(tst_ipaddr rhost) local $(tst_ipaddr)"
- ;;
- esac
- case $virt_type in
- vxlan|geneve|sit)
- ip li add $vname type $virt_type $opt
- ;;
- gre|ip6gre)
- ip -f inet$TST_IPV6 tu add $vname mode $virt_type $opt
- ;;
- *)
- ip li add link $(tst_iface) $vname type $virt_type $opt
- ;;
- esac
- }
- virt_add_rhost()
- {
- local opt=""
- case $virt_type in
- vxlan|geneve)
- [ "$virt_type" = "vxlan" ] && opt="dev $(tst_iface rhost)"
- [ "$vxlan_dstport" -eq 1 ] && opt="$opt dstport 0"
- tst_rhost_run -s -c "ip li add ltp_v0 type $virt_type $@ $opt"
- ;;
- sit)
- tst_rhost_run -s -c "ip link add ltp_v0 type $virt_type $@"
- ;;
- gre|ip6gre)
- tst_rhost_run -s -c "ip -f inet$TST_IPV6 tu add ltp_v0 \
- mode $virt_type $@"
- ;;
- *)
- tst_rhost_run -s -c "ip li add link $(tst_iface rhost) ltp_v0 \
- type $virt_type $@"
- ;;
- esac
- }
- virt_multiple_add_test()
- {
- local opt="$@"
- local max=$(($start_id + $NS_TIMES - 1))
- local i
- tst_res TINFO "add $NS_TIMES $virt_type, then delete"
- for i in $(seq $start_id $max); do
- virt_add ltp_v$i id $i $opt || \
- tst_brk TFAIL "failed to create 'ltp_v0 $opt'"
- ROD_SILENT "ip link set ltp_v$i up"
- done
- for i in $(seq $start_id $max); do
- ROD_SILENT "ip link set ltp_v$i down"
- ROD_SILENT "ip link delete ltp_v$i"
- done
- tst_res TPASS "done"
- }
- virt_add_delete_test()
- {
- local opt="$@"
- local max=$(($NS_TIMES - 1))
- local i
- tst_res TINFO "add/del $virt_type $NS_TIMES times"
- for i in $(seq 0 $max); do
- virt_add ltp_v0 $opt || \
- tst_brk TFAIL "failed to create 'ltp_v0 $opt'"
- ROD_SILENT "ip link set ltp_v0 up"
- ROD_SILENT "ip link delete ltp_v0"
- done
- tst_res TPASS "done"
- }
- virt_setup()
- {
- local opt="$1"
- local opt_r="${2:-$1}"
- tst_res TINFO "setup local ${virt_type} with '$opt'"
- virt_add ltp_v0 $opt || \
- tst_brk TBROK "failed to create 'ltp_v0 $opt'"
- tst_res TINFO "setup rhost ${virt_type} with '$opt_r'"
- virt_add_rhost "$opt_r"
- ROD_SILENT "ip addr add ${ip6_virt_local}/64 dev ltp_v0 nodad"
- tst_rhost_run -s -c "ip ad add ${ip6_virt_remote}/64 dev ltp_v0 nodad"
- ROD_SILENT "ip addr add ${ip_virt_local}/24 dev ltp_v0"
- tst_rhost_run -s -c "ip addr add ${ip_virt_remote}/24 dev ltp_v0"
- ROD_SILENT "sysctl -q net.ipv6.conf.ltp_v0.accept_dad=0"
- tst_rhost_run -s -c "sysctl -q net.ipv6.conf.ltp_v0.accept_dad=0"
- ROD_SILENT "ip li set up ltp_v0"
- tst_rhost_run -s -c "ip li set up ltp_v0"
- }
- virt_tcp_syn=
- virt_minimize_timeout()
- {
- local mac_loc="$(cat /sys/class/net/ltp_v0/address)"
- local mac_rmt="$(tst_rhost_run -c 'cat /sys/class/net/ltp_v0/address')"
- ROD_SILENT "ip ne replace $ip_virt_remote lladdr \
- $mac_rmt nud permanent dev ltp_v0"
- tst_rhost_run -s -c "ip ne replace $ip_virt_local lladdr \
- $mac_loc nud permanent dev ltp_v0"
- virt_tcp_syn=$(sysctl -n net.ipv4.tcp_syn_retries)
- ROD sysctl -q net.ipv4.tcp_syn_retries=1
- }
- vxlan_setup_subnet_uni()
- {
- if tst_kvcmp -lt "3.10"; then
- tst_brk TCONF "test must be run with kernel 3.10 or newer"
- fi
- [ "$(ip li add type $virt_type help 2>&1 | grep remote)" ] || \
- tst_brk TCONF "iproute doesn't support remote unicast address"
- local opt="$1 remote $(tst_ipaddr rhost)"
- local opt_r="$2 remote $(tst_ipaddr)"
- virt_setup "$opt" "$opt_r"
- }
- vxlan_setup_subnet_multi()
- {
- tst_require_cmds "od"
- local b1=$(($(od -An -d -N1 /dev/urandom) % 254 + 1))
- local b2=$(($(od -An -d -N1 /dev/urandom) % 254 + 1))
- local b3=$(($(od -An -d -N1 /dev/urandom) % 254 + 1))
- local grp=
- if [ "$TST_IPV6" ]; then
- grp="group ff05::$(printf '%x:%x%x' $b1 $b2 $b3)"
- else
- grp="group 239.$b1.$b2.$b3"
- fi
- local opt="$1 $grp"
- local opt_r="$2 $grp"
- virt_setup "$opt" "$opt_r"
- }
- virt_compare_netperf()
- {
- local ret1="pass"
- local ret2="pass"
- local expect_res="${1:-pass}"
- local opts="$2"
- tst_netload -H $ip_virt_remote $opts -d res_ipv4 -e $expect_res \
- -D ltp_v0 || ret1="fail"
- tst_netload -H ${ip6_virt_remote} $opts -d res_ipv6 -e $expect_res \
- -D ltp_v0 || ret2="fail"
- [ "$ret1" = "fail" -o "$ret2" = "fail" ] && return
- local vt="$(cat res_ipv4)"
- local vt6="$(cat res_ipv6)"
- tst_netload -H $(tst_ipaddr rhost) $opts -d res_lan
- local lt="$(cat res_lan)"
- tst_res TINFO "time lan IPv${TST_IPVER}($lt) $virt_type IPv4($vt) and IPv6($vt6) ms"
- per=$(( $vt * 100 / $lt - 100 ))
- per6=$(( $vt6 * 100 / $lt - 100 ))
- case "$virt_type" in
- vxlan|geneve)
- tst_res TINFO "IP4 $virt_type over IP$TST_IPVER slower by $per %"
- tst_res TINFO "IP6 $virt_type over IP$TST_IPVER slower by $per6 %"
- ;;
- *)
- tst_res TINFO "IP4 $virt_type slower by $per %"
- tst_res TINFO "IP6 $virt_type slower by $per6 %"
- esac
- if [ "$per" -ge "$VIRT_PERF_THRESHOLD" -o \
- "$per6" -ge "$VIRT_PERF_THRESHOLD" ]; then
- tst_res TFAIL "Test failed, threshold: $VIRT_PERF_THRESHOLD %"
- else
- tst_res TPASS "Test passed, threshold: $VIRT_PERF_THRESHOLD %"
- fi
- }
- virt_check_cmd()
- {
- $@ > /dev/null 2>&1
- if [ $? -ne 0 ]; then
- tst_res TCONF "'$@' option(s) not supported, skipping it"
- return 1
- fi
- ROD_SILENT "ip li delete ltp_v0"
- return 0
- }
- virt_netperf_msg_sizes()
- {
- local sizes="100 1000 2000 $TST_NET_MAX_PKT"
- local s
- for s in $sizes; do
- virt_compare_netperf pass "-n $s -N $s"
- done
- }
- virt_netperf_rand_sizes()
- {
- local max_pkt_size="$TST_NET_MAX_PKT"
- local types="tcp udp udp_lite"
- for t in $types; do
- virt_compare_netperf pass "-A $max_pkt_size -T $t"
- done
- }
- # Check if we can create then delete virtual interface.
- virt_test_01()
- {
- start_id="${start_id:-1}"
- tst_res TINFO "add $virt_type with '$2'"
- virt_check_cmd virt_add ltp_v0 id 0 $2 || return
- virt_multiple_add_test "$2"
- }
- # Check if we can create then delete virtual interface.
- virt_test_02()
- {
- start_id="${start_id:-1}"
- tst_res TINFO "add and then delete $virt_type with '$2'"
- virt_check_cmd virt_add ltp_v0 $2 || return
- virt_add_delete_test "$2"
- start_id=$(($start_id + $NS_TIMES))
- }
- virt_gre_setup()
- {
- virt_type="gre"
- [ "$TST_IPV6" ] && virt_type="ip6gre"
- virt_lib_setup
- tst_res TINFO "test $virt_type"
- virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
- "local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
- }
|