1#!/bin/sh 2# Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved. 3# 4# This program is free software; you can redistribute it and/or 5# modify it under the terms of the GNU General Public License as 6# published by the Free Software Foundation; either version 2 of 7# the License, or (at your option) any later version. 8# 9# This program is distributed in the hope that it would be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# 17# Author: Alexey Kodanev <alexey.kodanev@oracle.com> 18# 19# VxLAN 20# ----- 21# Virtual eXtensible Local Area Network (VxLAN) provides L2 networks 22# over existed L3 networks. It is using UDP (port 8472) to encapsulate 23# data packets. More information: 24# http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-08 25# 26# Warning: Test assumes that machines don't have any existed VxLANs. 27# If machine has VxLANs, the test might fail or eventually delete 28# them in cleanup function. See "start_vni" variable which can 29# solve it. 30 31ip_local=$(tst_ipaddr) 32ip_virt_local="192.168.124.1" 33ip6_virt_local="fe80::381c:c0ff:fea8:7c01" 34mac_virt_local="3A:1C:C0:A8:7C:01" 35 36ip_remote=$(tst_ipaddr rhost) 37ip_virt_remote="192.168.124.2" 38ip6_virt_remote="fe80::381c:c0ff:fea8:7c02" 39mac_virt_remote="3A:1C:C0:A8:7C:02" 40 41clients_num=2 42client_requests=500000 43max_requests=3 44net_load="TFO" 45 46# Max performance loss (%) for virtual devices during network load 47VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-80} 48vxlan_dstport=0 49 50while getopts :hsx:i:r:c:R:p:n:l:t:d:6 opt; do 51 case "$opt" in 52 h) 53 echo "Usage:" 54 echo "h help" 55 echo "s use ssh to run remote cmds" 56 echo "x n n is a number of interfaces for tc1 and tc2" 57 echo "i n start ID to use" 58 echo "r n client requests for TCP performance test" 59 echo "c n clients run concurrently in TCP perf" 60 echo "R n num of reqs, after which conn.closed in TCP perf" 61 echo "p x x and x + 1 are ports in TCP perf" 62 echo "n x virtual network 192.168.x" 63 echo "l x network load: x is PING or TFO(tcp_fastopen)" 64 echo "t x performance threshold, default is 60%" 65 echo "d x VxLAN destination address, 'uni' or 'multi'" 66 echo "6 run over IPv6" 67 exit 0 68 ;; 69 s) TST_USE_SSH=1 ;; 70 x) virt_count=$OPTARG ;; 71 i) start_id=$OPTARG ;; 72 c) clients_num=$OPTARG ;; 73 r) client_requests=$OPTARG ;; 74 R) max_requests=$OPTARG ;; 75 p) srv_port=$OPTARG ;; 76 n) 77 ip_virt_local="192.168.${OPTARG}.1" 78 ip_virt_remote="192.168.${OPTARG}.2" 79 ;; 80 l) net_load=$OPTARG ;; 81 t) VIRT_PERF_THRESHOLD=$OPTARG ;; 82 d) vxlan_dst_addr=$OPTARG ;; 83 6) # skip, test_net library already processed it 84 ;; 85 *) 86 tst_brkm TBROK "unknown option: $opt" 87 ;; 88 esac 89done 90 91cleanup_vifaces() 92{ 93 tst_resm TINFO "cleanup virtual interfaces..." 94 local viface=`ip li | sed -nE 's/^[0-9]+: (ltp_v[0-9]+)[@:].+/\1/p'` 95 for vx in $viface; do 96 ip link delete $vx 97 done 98} 99 100TST_CLEANUP="cleanup_vifaces" 101trap "tst_brkm TBROK 'test interrupted'" INT 102 103virt_add() 104{ 105 local vname=$1 106 local opt="${@:2}" 107 108 case $virt_type in 109 vlan|vxlan) 110 [ -z "$opt" ] && opt="id 4094" 111 [ "$vxlan_dstport" -eq 1 ] && opt="dstport 0 $opt" 112 ;; 113 gre|ip6gre) 114 [ -z "$opt" ] && \ 115 opt="remote $(tst_ipaddr rhost) dev $(tst_iface)" 116 ;; 117 esac 118 119 case $virt_type in 120 vxlan) 121 ip li add $vname type $virt_type $opt 122 ;; 123 gre|ip6gre) 124 ip -f inet$TST_IPV6 tu add $vname mode $virt_type $opt 125 ;; 126 *) 127 ip li add link $(tst_iface) $vname type $virt_type $opt 128 ;; 129 esac 130} 131 132virt_add_rhost() 133{ 134 local opt="" 135 case $virt_type in 136 vxlan) 137 [ "$vxlan_dstport" -eq 1 ] && opt="dstport 0" 138 tst_rhost_run -s -c "ip li add ltp_v0 type $virt_type $@ $opt" 139 ;; 140 gre|ip6gre) 141 tst_rhost_run -s -c "ip -f inet$TST_IPV6 tu add ltp_v0 \ 142 mode $virt_type $@" 143 ;; 144 *) 145 tst_rhost_run -s -c "ip li add link $(tst_iface rhost) ltp_v0 \ 146 type $virt_type $@" 147 ;; 148 esac 149} 150 151virt_multiple_add_test() 152{ 153 local opt="$@" 154 local max=$(($start_id + $virt_count - 1)) 155 156 tst_resm TINFO "add $virt_count $virt_type, then delete" 157 158 for i in $(seq $start_id $max); do 159 ROD_SILENT "virt_add ltp_v$i id $i $opt" 160 ROD_SILENT "ip link set ltp_v$i up" 161 done 162 163 for i in $(seq $start_id $max); do 164 ROD_SILENT "ip link set ltp_v$i down" 165 ROD_SILENT "ip link delete ltp_v$i" 166 done 167 168 tst_resm TPASS "done" 169} 170 171virt_add_delete_test() 172{ 173 local opt="$@" 174 local max=$(($virt_count - 1)) 175 176 tst_resm TINFO "add/del $virt_type $virt_count times" 177 178 for i in $(seq 0 $max); do 179 ROD_SILENT "virt_add ltp_v0 $opt" 180 ROD_SILENT "ip link set ltp_v0 up" 181 ROD_SILENT "ip link delete ltp_v0" 182 done 183 tst_resm TPASS "done" 184} 185 186virt_setup() 187{ 188 local opt="$1" 189 local opt_r="$2" 190 191 tst_resm TINFO "setup local ${virt_type} with '$opt'" 192 ROD_SILENT "virt_add ltp_v0 $opt" 193 194 tst_resm TINFO "setup rhost ${virt_type} with '$opt_r'" 195 virt_add_rhost "$opt_r" 196 197 case $virt_type in 198 gre|ip6gre) 199 # We can't set hwaddr to GRE tunnel, add IPv6 link local 200 # addresses manually. 201 ROD_SILENT "ip addr add ${ip6_virt_local}/64 dev ltp_v0" 202 tst_rhost_run -s -c "ip ad add ${ip6_virt_remote}/64 dev ltp_v0" 203 ;; 204 *) 205 ROD_SILENT "ip li set ltp_v0 address $mac_virt_local" 206 tst_rhost_run -s -c "ip li set ltp_v0 address $mac_virt_remote" 207 ;; 208 esac 209 210 ROD_SILENT "ip addr add ${ip_virt_local}/24 dev ltp_v0" 211 tst_rhost_run -s -c "ip addr add ${ip_virt_remote}/24 dev ltp_v0" 212 213 ROD_SILENT "ip li set up ltp_v0" 214 tst_rhost_run -s -c "ip li set up ltp_v0" 215} 216 217vxlan_setup_subnet_uni() 218{ 219 tst_kvercmp 3 10 0 && \ 220 tst_brkm TCONF "test must be run with kernel 3.10 or newer" 221 222 [ "$(ip li add type vxlan help 2>&1 | grep remote)" ] || \ 223 tst_brkm TCONF "iproute doesn't support remote unicast address" 224 225 local opt="$1 remote $(tst_ipaddr rhost)" 226 local opt_r="$2 remote $(tst_ipaddr)" 227 228 virt_setup "$opt" "$opt_r" 229} 230 231vxlan_setup_subnet_multi() 232{ 233 tst_check_cmds "od" 234 local b1=$(($(od -An -d -N1 /dev/urandom) % 254 + 1)) 235 local b2=$(($(od -An -d -N1 /dev/urandom) % 254 + 1)) 236 local b3=$(($(od -An -d -N1 /dev/urandom) % 254 + 1)) 237 238 local grp= 239 if [ "$TST_IPV6" ]; then 240 grp="group ff05::$(printf '%x:%x%x' $b1 $b2 $b3)" 241 else 242 grp="group 239.$b1.$b2.$b3" 243 fi 244 245 local opt="$1 $grp dev $(tst_iface)" 246 local opt_r="$2 $grp dev $(tst_iface rhost)" 247 248 virt_setup "$opt" "$opt_r" 249} 250 251virt_compare_netperf() 252{ 253 local ret=0 254 local expected_result=${1:-"pass"} 255 256 tst_netload $ip_virt_remote res_ipv4 $net_load || ret=1 257 tst_netload ${ip6_virt_remote}%ltp_v0 res_ipv6 $net_load || ret=1 258 259 ROD_SILENT "ip link delete ltp_v0" 260 tst_rhost_run -s -c "ip link delete ltp_v0" 261 262 if [ "$ret" -eq 1 ]; then 263 if [ "$expected_result" = "pass" ]; then 264 tst_resm TFAIL "Test with virtual iface failed" 265 else 266 tst_resm TPASS "Test failed as expected" 267 fi 268 return 269 fi 270 local vt="$(cat res_ipv4)" 271 local vt6="$(cat res_ipv6)" 272 273 tst_netload $ip_remote res_ipv4 $net_load 274 if [ $? -ne 0 ]; then 275 tst_resm TFAIL "Test with $ip_remote failed" 276 return 277 fi 278 279 local lt="$(cat res_ipv4)" 280 tst_resm TINFO "time lan($lt) $virt_type IPv4($vt) and IPv6($vt6) ms" 281 282 per=$(( $vt * 100 / $lt - 100 )) 283 per6=$(( $vt6 * 100 / $lt - 100 )) 284 285 case "$virt_type" in 286 vxlan) 287 tst_resm TINFO "IPv4 VxLAN over IPv$ipver slower by $per %" 288 tst_resm TINFO "IPv6 VxLAN over IPv$ipver slower by $per6 %" 289 ;; 290 *) 291 tst_resm TINFO "IPv4 $virt_type slower by $per %" 292 tst_resm TINFO "IPv6 $virt_type slower by $per6 %" 293 esac 294 295 if [ "$per" -ge "$VIRT_PERF_THRESHOLD" -o \ 296 "$per6" -ge "$VIRT_PERF_THRESHOLD" ]; then 297 tst_resm TFAIL "Test failed, threshold: $VIRT_PERF_THRESHOLD %" 298 else 299 tst_resm TPASS "Test passed, threshold: $VIRT_PERF_THRESHOLD %" 300 fi 301} 302 303virt_check_cmd() 304{ 305 $@ > /dev/null 2>&1 306 if [ $? -ne 0 ]; then 307 tst_resm TCONF "'$@' option(s) not supported, skipping it" 308 return 1 309 fi 310 ROD_SILENT "ip li delete ltp_v0" 311 return 0 312} 313 314# Check if we can create then delete virtual interface n times. 315# virt_test_01 [OPTIONS] 316# OPTIONS - different options separated by comma. 317virt_test_01() 318{ 319 start_id=${start_id:-"1"} 320 virt_count=${virt_count:-"400"} 321 322 local opts=${1:-""} 323 local n=0 324 325 while true; do 326 n=$((n + 1)) 327 p="$(echo $opts | cut -d',' -f$n)" 328 if [ -z "$p" -a $n -gt 1 ]; then 329 break 330 fi 331 332 tst_resm TINFO "add $virt_type with '$p'" 333 334 virt_check_cmd virt_add ltp_v0 id 0 $p || continue 335 336 virt_multiple_add_test "$p" 337 338 start_id=$(($start_id + $virt_count)) 339 done 340} 341 342# Check if we can create then delete virtual interface n times. 343# virt_test_02 [OPTIONS] 344# OPTIONS - different options separated by comma. 345virt_test_02() 346{ 347 start_id=${start_id:-"1"} 348 virt_count=${virt_count:-"500"} 349 350 local opts=${1:-""} 351 local n=0 352 353 while true; do 354 n=$((n + 1)) 355 p="$(echo $opts | cut -d',' -f$n)" 356 if [ -z "$p" -a $n -gt 1 ]; then 357 break 358 fi 359 360 tst_resm TINFO "add and then delete $virt_type with '$p'" 361 362 virt_check_cmd virt_add ltp_v0 $p || continue 363 364 virt_add_delete_test "$p" 365 366 start_id=$(($start_id + $virt_count)) 367 done 368} 369 370tst_require_root 371 372case "$virt_type" in 373vxlan) 374 tst_kvercmp 3 8 0 && \ 375 tst_brkm TCONF "test must be run with kernel 3.8 or newer" 376 377 if [ "$TST_IPV6" ]; then 378 tst_kvercmp 3 12 0 && \ 379 tst_brkm TCONF "test must be run with kernels >= 3.12" 380 fi 381 382 # newer versions of 'ip' complain if this option not set 383 ip li add type vxlan help 2>&1 | grep -q dstport && vxlan_dstport=1 384;; 385esac 386 387ipver=${TST_IPV6:-'4'} 388 389tst_check_cmds "ip" 390 391virt_add ltp_v0 || \ 392 tst_brkm TCONF "iproute2 or kernel doesn't support $virt_type" 393 394ROD_SILENT "ip link delete ltp_v0" 395