1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0-only 3 4VNI_GEN=$RANDOM 5NSIM_ID=$((RANDOM % 1024)) 6NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID 7NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID 8NSIM_NETDEV= 9HAS_ETHTOOL= 10STATIC_ENTRIES= 11EXIT_STATUS=0 12num_cases=0 13num_errors=0 14 15clean_up_devs=( ) 16 17function err_cnt { 18 echo "ERROR:" $@ 19 EXIT_STATUS=1 20 ((num_errors++)) 21 ((num_cases++)) 22} 23 24function pass_cnt { 25 ((num_cases++)) 26} 27 28function cleanup_tuns { 29 for dev in "${clean_up_devs[@]}"; do 30 [ -e /sys/class/net/$dev ] && ip link del dev $dev 31 done 32 clean_up_devs=( ) 33} 34 35function cleanup_nsim { 36 if [ -e $NSIM_DEV_SYS ]; then 37 echo $NSIM_ID > /sys/bus/netdevsim/del_device 38 fi 39} 40 41function cleanup { 42 cleanup_tuns 43 cleanup_nsim 44} 45 46trap cleanup EXIT 47 48function new_vxlan { 49 local dev=$1 50 local dstport=$2 51 local lower=$3 52 local ipver=$4 53 local flags=$5 54 55 local group ipfl 56 57 [ "$ipver" != '6' ] && group=239.1.1.1 || group=fff1::1 58 [ "$ipver" != '6' ] || ipfl="-6" 59 60 [[ ! "$flags" =~ "external" ]] && flags="$flags id $((VNI_GEN++))" 61 62 ip $ipfl link add $dev type vxlan \ 63 group $group \ 64 dev $lower \ 65 dstport $dstport \ 66 $flags 67 68 ip link set dev $dev up 69 70 clean_up_devs=("${clean_up_devs[@]}" $dev) 71 72 check_tables 73} 74 75function new_geneve { 76 local dev=$1 77 local dstport=$2 78 local ipver=$3 79 local flags=$4 80 81 local group ipfl 82 83 [ "$ipver" != '6' ] && remote=1.1.1.2 || group=::2 84 [ "$ipver" != '6' ] || ipfl="-6" 85 86 [[ ! "$flags" =~ "external" ]] && flags="$flags vni $((VNI_GEN++))" 87 88 ip $ipfl link add $dev type geneve \ 89 remote $remote \ 90 dstport $dstport \ 91 $flags 92 93 ip link set dev $dev up 94 95 clean_up_devs=("${clean_up_devs[@]}" $dev) 96 97 check_tables 98} 99 100function del_dev { 101 local dev=$1 102 103 ip link del dev $dev 104 check_tables 105} 106 107# Helpers for netdevsim port/type encoding 108function mke { 109 local port=$1 110 local type=$2 111 112 echo $((port << 16 | type)) 113} 114 115function pre { 116 local val=$1 117 118 echo -e "port: $((val >> 16))\ttype: $((val & 0xffff))" 119} 120 121function pre_ethtool { 122 local val=$1 123 local port=$((val >> 16)) 124 local type=$((val & 0xffff)) 125 126 case $type in 127 1) 128 type_name="vxlan" 129 ;; 130 2) 131 type_name="geneve" 132 ;; 133 4) 134 type_name="vxlan-gpe" 135 ;; 136 *) 137 type_name="bit X" 138 ;; 139 esac 140 141 echo "port $port, $type_name" 142} 143 144function check_table { 145 local path=$NSIM_DEV_DFS/ports/$port/udp_ports_table$1 146 local -n expected=$2 147 local last=$3 148 149 read -a have < $path 150 151 if [ ${#expected[@]} -ne ${#have[@]} ]; then 152 echo "check_table: BAD NUMBER OF ITEMS" 153 return 0 154 fi 155 156 for i in "${!expected[@]}"; do 157 if [ -n "$HAS_ETHTOOL" -a ${expected[i]} -ne 0 ]; then 158 pp_expected=`pre_ethtool ${expected[i]}` 159 ethtool --show-tunnels $NSIM_NETDEV | grep "$pp_expected" >/dev/null 160 if [ $? -ne 0 -a $last -ne 0 ]; then 161 err_cnt "ethtool table $1 on port $port: $pfx - $msg" 162 echo " check_table: ethtool does not contain '$pp_expected'" 163 ethtool --show-tunnels $NSIM_NETDEV 164 return 0 165 166 fi 167 fi 168 169 if [ ${expected[i]} != ${have[i]} ]; then 170 if [ $last -ne 0 ]; then 171 err_cnt "table $1 on port $port: $pfx - $msg" 172 echo " check_table: wrong entry $i" 173 echo " expected: `pre ${expected[i]}`" 174 echo " have: `pre ${have[i]}`" 175 return 0 176 fi 177 return 1 178 fi 179 done 180 181 pass_cnt 182 return 0 183} 184 185function check_tables { 186 # Need retries in case we have workqueue making the changes 187 local retries=10 188 189 while ! check_table 0 exp0 $((retries == 0)); do 190 sleep 0.02 191 ((retries--)) 192 done 193 while ! check_table 1 exp1 $((retries == 0)); do 194 sleep 0.02 195 ((retries--)) 196 done 197 198 if [ -n "$HAS_ETHTOOL" -a -n "${STATIC_ENTRIES[0]}" ]; then 199 fail=0 200 for i in "${!STATIC_ENTRIES[@]}"; do 201 pp_expected=`pre_ethtool ${STATIC_ENTRIES[i]}` 202 cnt=$(ethtool --show-tunnels $NSIM_NETDEV | grep -c "$pp_expected") 203 if [ $cnt -ne 1 ]; then 204 err_cnt "ethtool static entry: $pfx - $msg" 205 echo " check_table: ethtool does not contain '$pp_expected'" 206 ethtool --show-tunnels $NSIM_NETDEV 207 fail=1 208 fi 209 done 210 [ $fail == 0 ] && pass_cnt 211 fi 212} 213 214function print_table { 215 local path=$NSIM_DEV_DFS/ports/$port/udp_ports_table$1 216 read -a have < $path 217 218 tree $NSIM_DEV_DFS/ 219 220 echo "Port $port table $1:" 221 222 for i in "${!have[@]}"; do 223 echo " `pre ${have[i]}`" 224 done 225 226} 227 228function print_tables { 229 print_table 0 230 print_table 1 231} 232 233function get_netdev_name { 234 local -n old=$1 235 236 udevadm settle 237 new=$(ls /sys/class/net) 238 239 for netdev in $new; do 240 for check in $old; do 241 [ $netdev == $check ] && break 242 done 243 244 if [ $netdev != $check ]; then 245 echo $netdev 246 break 247 fi 248 done 249} 250 251### 252### Code start 253### 254 255# Probe ethtool support 256ethtool -h | grep show-tunnels 2>&1 >/dev/null && HAS_ETHTOOL=y 257 258modprobe netdevsim 259 260# Basic test 261pfx="basic" 262 263for port in 0 1; do 264 old_netdevs=$(ls /sys/class/net) 265 if [ $port -eq 0 ]; then 266 echo $NSIM_ID > /sys/bus/netdevsim/new_device 267 else 268 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 269 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 270 echo 1 > $NSIM_DEV_SYS/new_port 271 fi 272 NSIM_NETDEV=`get_netdev_name old_netdevs` 273 274 msg="new NIC device created" 275 exp0=( 0 0 0 0 ) 276 exp1=( 0 0 0 0 ) 277 check_tables 278 279 msg="VxLAN v4 devices" 280 exp0=( `mke 4789 1` 0 0 0 ) 281 new_vxlan vxlan0 4789 $NSIM_NETDEV 282 new_vxlan vxlan1 4789 $NSIM_NETDEV 283 284 msg="VxLAN v4 devices go down" 285 exp0=( 0 0 0 0 ) 286 ifconfig vxlan1 down 287 ifconfig vxlan0 down 288 check_tables 289 290 msg="VxLAN v6 devices" 291 exp0=( `mke 4789 1` 0 0 0 ) 292 new_vxlan vxlanA 4789 $NSIM_NETDEV 6 293 294 for ifc in vxlan0 vxlan1; do 295 ifconfig $ifc up 296 done 297 298 new_vxlan vxlanB 4789 $NSIM_NETDEV 6 299 300 msg="another VxLAN v6 devices" 301 exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 302 new_vxlan vxlanC 4790 $NSIM_NETDEV 6 303 304 msg="Geneve device" 305 exp1=( `mke 6081 2` 0 0 0 ) 306 new_geneve gnv0 6081 307 308 msg="NIC device goes down" 309 ifconfig $NSIM_NETDEV down 310 if [ $port -eq 1 ]; then 311 exp0=( 0 0 0 0 ) 312 exp1=( 0 0 0 0 ) 313 fi 314 check_tables 315 msg="NIC device goes up again" 316 ifconfig $NSIM_NETDEV up 317 exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 318 exp1=( `mke 6081 2` 0 0 0 ) 319 check_tables 320 321 cleanup_tuns 322 323 msg="tunnels destroyed" 324 exp0=( 0 0 0 0 ) 325 exp1=( 0 0 0 0 ) 326 check_tables 327 328 modprobe -r geneve 329 modprobe -r vxlan 330 modprobe -r udp_tunnel 331 332 check_tables 333done 334 335modprobe -r netdevsim 336 337# Module tests 338pfx="module tests" 339 340if modinfo netdevsim | grep udp_tunnel >/dev/null; then 341 err_cnt "netdevsim depends on udp_tunnel" 342else 343 pass_cnt 344fi 345 346modprobe netdevsim 347 348old_netdevs=$(ls /sys/class/net) 349port=0 350echo $NSIM_ID > /sys/bus/netdevsim/new_device 351echo 0 > $NSIM_DEV_SYS/del_port 352echo 1000 > $NSIM_DEV_DFS/udp_ports_sleep 353echo 0 > $NSIM_DEV_SYS/new_port 354NSIM_NETDEV=`get_netdev_name old_netdevs` 355 356msg="create VxLANs" 357exp0=( 0 0 0 0 ) # sleep is longer than out wait 358new_vxlan vxlan0 10000 $NSIM_NETDEV 359 360modprobe -r vxlan 361modprobe -r udp_tunnel 362 363msg="remove tunnels" 364exp0=( 0 0 0 0 ) 365check_tables 366 367msg="create VxLANs" 368exp0=( 0 0 0 0 ) # sleep is longer than out wait 369new_vxlan vxlan0 10000 $NSIM_NETDEV 370 371exp0=( 0 0 0 0 ) 372 373modprobe -r netdevsim 374modprobe netdevsim 375 376# Overflow the table 377 378function overflow_table0 { 379 local pfx=$1 380 381 msg="create VxLANs 1/5" 382 exp0=( `mke 10000 1` 0 0 0 ) 383 new_vxlan vxlan0 10000 $NSIM_NETDEV 384 385 msg="create VxLANs 2/5" 386 exp0=( `mke 10000 1` `mke 10001 1` 0 0 ) 387 new_vxlan vxlan1 10001 $NSIM_NETDEV 388 389 msg="create VxLANs 3/5" 390 exp0=( `mke 10000 1` `mke 10001 1` `mke 10002 1` 0 ) 391 new_vxlan vxlan2 10002 $NSIM_NETDEV 392 393 msg="create VxLANs 4/5" 394 exp0=( `mke 10000 1` `mke 10001 1` `mke 10002 1` `mke 10003 1` ) 395 new_vxlan vxlan3 10003 $NSIM_NETDEV 396 397 msg="create VxLANs 5/5" 398 new_vxlan vxlan4 10004 $NSIM_NETDEV 399} 400 401function overflow_table1 { 402 local pfx=$1 403 404 msg="create GENEVE 1/5" 405 exp1=( `mke 20000 2` 0 0 0 ) 406 new_geneve gnv0 20000 407 408 msg="create GENEVE 2/5" 409 exp1=( `mke 20000 2` `mke 20001 2` 0 0 ) 410 new_geneve gnv1 20001 411 412 msg="create GENEVE 3/5" 413 exp1=( `mke 20000 2` `mke 20001 2` `mke 20002 2` 0 ) 414 new_geneve gnv2 20002 415 416 msg="create GENEVE 4/5" 417 exp1=( `mke 20000 2` `mke 20001 2` `mke 20002 2` `mke 20003 2` ) 418 new_geneve gnv3 20003 419 420 msg="create GENEVE 5/5" 421 new_geneve gnv4 20004 422} 423 424echo $NSIM_ID > /sys/bus/netdevsim/new_device 425echo 0 > $NSIM_DEV_SYS/del_port 426 427for port in 0 1; do 428 if [ $port -ne 0 ]; then 429 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 430 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 431 fi 432 433 echo $port > $NSIM_DEV_SYS/new_port 434 ifconfig $NSIM_NETDEV up 435 436 overflow_table0 "overflow NIC table" 437 overflow_table1 "overflow NIC table" 438 439 msg="replace VxLAN in overflow table" 440 exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 441 del_dev vxlan1 442 443 msg="vacate VxLAN in overflow table" 444 exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 445 del_dev vxlan2 446 447 msg="replace GENEVE in overflow table" 448 exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` ) 449 del_dev gnv1 450 451 msg="vacate GENEVE in overflow table" 452 exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` ) 453 del_dev gnv2 454 455 msg="table sharing - share" 456 exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` ) 457 new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external" 458 459 msg="table sharing - overflow" 460 new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external" 461 msg="table sharing - overflow v6" 462 new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external" 463 464 exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` ) 465 del_dev gnv4 466 467 msg="destroy NIC" 468 echo $port > $NSIM_DEV_SYS/del_port 469 470 cleanup_tuns 471 exp0=( 0 0 0 0 ) 472 exp1=( 0 0 0 0 ) 473done 474 475cleanup_nsim 476 477# Sync all 478pfx="sync all" 479 480echo $NSIM_ID > /sys/bus/netdevsim/new_device 481echo 0 > $NSIM_DEV_SYS/del_port 482echo 1 > $NSIM_DEV_DFS/udp_ports_sync_all 483 484for port in 0 1; do 485 if [ $port -ne 0 ]; then 486 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 487 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 488 fi 489 490 echo $port > $NSIM_DEV_SYS/new_port 491 ifconfig $NSIM_NETDEV up 492 493 overflow_table0 "overflow NIC table" 494 overflow_table1 "overflow NIC table" 495 496 msg="replace VxLAN in overflow table" 497 exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 498 del_dev vxlan1 499 500 msg="vacate VxLAN in overflow table" 501 exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 502 del_dev vxlan2 503 504 msg="replace GENEVE in overflow table" 505 exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` ) 506 del_dev gnv1 507 508 msg="vacate GENEVE in overflow table" 509 exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` ) 510 del_dev gnv2 511 512 msg="table sharing - share" 513 exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` ) 514 new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external" 515 516 msg="table sharing - overflow" 517 new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external" 518 msg="table sharing - overflow v6" 519 new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external" 520 521 exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` ) 522 del_dev gnv4 523 524 msg="destroy NIC" 525 echo $port > $NSIM_DEV_SYS/del_port 526 527 cleanup_tuns 528 exp0=( 0 0 0 0 ) 529 exp1=( 0 0 0 0 ) 530done 531 532cleanup_nsim 533 534# Destroy full NIC 535pfx="destroy full" 536 537echo $NSIM_ID > /sys/bus/netdevsim/new_device 538echo 0 > $NSIM_DEV_SYS/del_port 539 540for port in 0 1; do 541 if [ $port -ne 0 ]; then 542 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 543 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 544 fi 545 546 echo $port > $NSIM_DEV_SYS/new_port 547 ifconfig $NSIM_NETDEV up 548 549 overflow_table0 "destroy NIC" 550 overflow_table1 "destroy NIC" 551 552 msg="destroy NIC" 553 echo $port > $NSIM_DEV_SYS/del_port 554 555 cleanup_tuns 556 exp0=( 0 0 0 0 ) 557 exp1=( 0 0 0 0 ) 558done 559 560cleanup_nsim 561 562# IPv4 only 563pfx="IPv4 only" 564 565echo $NSIM_ID > /sys/bus/netdevsim/new_device 566echo 0 > $NSIM_DEV_SYS/del_port 567echo 1 > $NSIM_DEV_DFS/udp_ports_ipv4_only 568 569for port in 0 1; do 570 if [ $port -ne 0 ]; then 571 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 572 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 573 fi 574 575 echo $port > $NSIM_DEV_SYS/new_port 576 ifconfig $NSIM_NETDEV up 577 578 msg="create VxLANs v6" 579 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 580 581 msg="create VxLANs v6" 582 new_vxlan vxlanA1 10000 $NSIM_NETDEV 6 583 584 ip link set dev vxlanA0 down 585 ip link set dev vxlanA0 up 586 check_tables 587 588 msg="create VxLANs v4" 589 exp0=( `mke 10000 1` 0 0 0 ) 590 new_vxlan vxlan0 10000 $NSIM_NETDEV 591 592 msg="down VxLANs v4" 593 exp0=( 0 0 0 0 ) 594 ip link set dev vxlan0 down 595 check_tables 596 597 msg="up VxLANs v4" 598 exp0=( `mke 10000 1` 0 0 0 ) 599 ip link set dev vxlan0 up 600 check_tables 601 602 msg="destroy VxLANs v4" 603 exp0=( 0 0 0 0 ) 604 del_dev vxlan0 605 606 msg="recreate VxLANs v4" 607 exp0=( `mke 10000 1` 0 0 0 ) 608 new_vxlan vxlan0 10000 $NSIM_NETDEV 609 610 del_dev vxlanA0 611 del_dev vxlanA1 612 613 msg="destroy NIC" 614 echo $port > $NSIM_DEV_SYS/del_port 615 616 cleanup_tuns 617 exp0=( 0 0 0 0 ) 618 exp1=( 0 0 0 0 ) 619done 620 621cleanup_nsim 622 623# Failures 624pfx="error injection" 625 626echo $NSIM_ID > /sys/bus/netdevsim/new_device 627echo 0 > $NSIM_DEV_SYS/del_port 628 629for port in 0 1; do 630 if [ $port -ne 0 ]; then 631 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 632 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 633 fi 634 635 echo $port > $NSIM_DEV_SYS/new_port 636 ifconfig $NSIM_NETDEV up 637 638 echo 110 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error 639 640 msg="1 - create VxLANs v6" 641 exp0=( 0 0 0 0 ) 642 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 643 644 msg="1 - create VxLANs v4" 645 exp0=( `mke 10000 1` 0 0 0 ) 646 new_vxlan vxlan0 10000 $NSIM_NETDEV 647 648 msg="1 - remove VxLANs v4" 649 del_dev vxlan0 650 651 msg="1 - remove VxLANs v6" 652 exp0=( 0 0 0 0 ) 653 del_dev vxlanA0 654 655 msg="2 - create GENEVE" 656 exp1=( `mke 20000 2` 0 0 0 ) 657 new_geneve gnv0 20000 658 659 msg="2 - destroy GENEVE" 660 echo 2 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error 661 exp1=( `mke 20000 2` 0 0 0 ) 662 del_dev gnv0 663 664 msg="2 - create second GENEVE" 665 exp1=( 0 `mke 20001 2` 0 0 ) 666 new_geneve gnv0 20001 667 668 msg="destroy NIC" 669 echo $port > $NSIM_DEV_SYS/del_port 670 671 cleanup_tuns 672 exp0=( 0 0 0 0 ) 673 exp1=( 0 0 0 0 ) 674done 675 676cleanup_nsim 677 678# netdev flags 679pfx="netdev flags" 680 681echo $NSIM_ID > /sys/bus/netdevsim/new_device 682echo 0 > $NSIM_DEV_SYS/del_port 683 684for port in 0 1; do 685 if [ $port -ne 0 ]; then 686 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 687 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 688 fi 689 690 echo $port > $NSIM_DEV_SYS/new_port 691 ifconfig $NSIM_NETDEV up 692 693 msg="create VxLANs v6" 694 exp0=( `mke 10000 1` 0 0 0 ) 695 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 696 697 msg="create VxLANs v4" 698 new_vxlan vxlan0 10000 $NSIM_NETDEV 699 700 msg="turn off" 701 exp0=( 0 0 0 0 ) 702 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 703 check_tables 704 705 msg="turn on" 706 exp0=( `mke 10000 1` 0 0 0 ) 707 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 708 check_tables 709 710 msg="remove both" 711 del_dev vxlanA0 712 exp0=( 0 0 0 0 ) 713 del_dev vxlan0 714 check_tables 715 716 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 717 718 msg="create VxLANs v4 - off" 719 exp0=( 0 0 0 0 ) 720 new_vxlan vxlan0 10000 $NSIM_NETDEV 721 722 msg="created off - turn on" 723 exp0=( `mke 10000 1` 0 0 0 ) 724 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 725 check_tables 726 727 msg="destroy NIC" 728 echo $port > $NSIM_DEV_SYS/del_port 729 730 cleanup_tuns 731 exp0=( 0 0 0 0 ) 732 exp1=( 0 0 0 0 ) 733done 734 735cleanup_nsim 736 737# device initiated reset 738pfx="reset notification" 739 740echo $NSIM_ID > /sys/bus/netdevsim/new_device 741echo 0 > $NSIM_DEV_SYS/del_port 742 743for port in 0 1; do 744 if [ $port -ne 0 ]; then 745 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 746 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 747 fi 748 749 echo $port > $NSIM_DEV_SYS/new_port 750 ifconfig $NSIM_NETDEV up 751 752 msg="create VxLANs v6" 753 exp0=( `mke 10000 1` 0 0 0 ) 754 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 755 756 msg="create VxLANs v4" 757 new_vxlan vxlan0 10000 $NSIM_NETDEV 758 759 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 760 check_tables 761 762 msg="NIC device goes down" 763 ifconfig $NSIM_NETDEV down 764 if [ $port -eq 1 ]; then 765 exp0=( 0 0 0 0 ) 766 exp1=( 0 0 0 0 ) 767 fi 768 check_tables 769 770 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 771 check_tables 772 773 msg="NIC device goes up again" 774 ifconfig $NSIM_NETDEV up 775 exp0=( `mke 10000 1` 0 0 0 ) 776 check_tables 777 778 msg="remove both" 779 del_dev vxlanA0 780 exp0=( 0 0 0 0 ) 781 del_dev vxlan0 782 check_tables 783 784 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 785 check_tables 786 787 msg="destroy NIC" 788 echo $port > $NSIM_DEV_SYS/del_port 789 790 cleanup_tuns 791 exp0=( 0 0 0 0 ) 792 exp1=( 0 0 0 0 ) 793done 794 795cleanup_nsim 796 797# shared port tables 798pfx="table sharing" 799 800echo $NSIM_ID > /sys/bus/netdevsim/new_device 801echo 0 > $NSIM_DEV_SYS/del_port 802 803echo 0 > $NSIM_DEV_DFS/udp_ports_open_only 804echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 805echo 1 > $NSIM_DEV_DFS/udp_ports_shared 806 807old_netdevs=$(ls /sys/class/net) 808echo 1 > $NSIM_DEV_SYS/new_port 809NSIM_NETDEV=`get_netdev_name old_netdevs` 810old_netdevs=$(ls /sys/class/net) 811echo 2 > $NSIM_DEV_SYS/new_port 812NSIM_NETDEV2=`get_netdev_name old_netdevs` 813 814msg="VxLAN v4 devices" 815exp0=( `mke 4789 1` 0 0 0 ) 816exp1=( 0 0 0 0 ) 817new_vxlan vxlan0 4789 $NSIM_NETDEV 818new_vxlan vxlan1 4789 $NSIM_NETDEV2 819 820msg="VxLAN v4 devices go down" 821exp0=( 0 0 0 0 ) 822ifconfig vxlan1 down 823ifconfig vxlan0 down 824check_tables 825 826for ifc in vxlan0 vxlan1; do 827 ifconfig $ifc up 828done 829 830msg="VxLAN v6 device" 831exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 832new_vxlan vxlanC 4790 $NSIM_NETDEV 6 833 834msg="Geneve device" 835exp1=( `mke 6081 2` 0 0 0 ) 836new_geneve gnv0 6081 837 838msg="NIC device goes down" 839ifconfig $NSIM_NETDEV down 840check_tables 841 842msg="NIC device goes up again" 843ifconfig $NSIM_NETDEV up 844check_tables 845 846for i in `seq 2`; do 847 msg="turn feature off - 1, rep $i" 848 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 849 check_tables 850 851 msg="turn feature off - 2, rep $i" 852 exp0=( 0 0 0 0 ) 853 exp1=( 0 0 0 0 ) 854 ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload off 855 check_tables 856 857 msg="turn feature on - 1, rep $i" 858 exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 859 exp1=( `mke 6081 2` 0 0 0 ) 860 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 861 check_tables 862 863 msg="turn feature on - 2, rep $i" 864 ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload on 865 check_tables 866done 867 868msg="tunnels destroyed 1" 869cleanup_tuns 870exp0=( 0 0 0 0 ) 871exp1=( 0 0 0 0 ) 872check_tables 873 874overflow_table0 "overflow NIC table" 875 876msg="re-add a port" 877 878echo 2 > $NSIM_DEV_SYS/del_port 879echo 2 > $NSIM_DEV_SYS/new_port 880check_tables 881 882msg="replace VxLAN in overflow table" 883exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 884del_dev vxlan1 885 886msg="vacate VxLAN in overflow table" 887exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 888del_dev vxlan2 889 890echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 891check_tables 892 893msg="tunnels destroyed 2" 894cleanup_tuns 895exp0=( 0 0 0 0 ) 896exp1=( 0 0 0 0 ) 897check_tables 898 899echo 1 > $NSIM_DEV_SYS/del_port 900echo 2 > $NSIM_DEV_SYS/del_port 901 902cleanup_nsim 903 904# Static IANA port 905pfx="static IANA vxlan" 906 907echo $NSIM_ID > /sys/bus/netdevsim/new_device 908echo 0 > $NSIM_DEV_SYS/del_port 909 910echo 1 > $NSIM_DEV_DFS/udp_ports_static_iana_vxlan 911STATIC_ENTRIES=( `mke 4789 1` ) 912 913port=1 914old_netdevs=$(ls /sys/class/net) 915echo $port > $NSIM_DEV_SYS/new_port 916NSIM_NETDEV=`get_netdev_name old_netdevs` 917 918msg="check empty" 919exp0=( 0 0 0 0 ) 920exp1=( 0 0 0 0 ) 921check_tables 922 923msg="add on static port" 924new_vxlan vxlan0 4789 $NSIM_NETDEV 925new_vxlan vxlan1 4789 $NSIM_NETDEV 926 927msg="add on different port" 928exp0=( `mke 4790 1` 0 0 0 ) 929new_vxlan vxlan2 4790 $NSIM_NETDEV 930 931cleanup_tuns 932 933msg="tunnels destroyed" 934exp0=( 0 0 0 0 ) 935exp1=( 0 0 0 0 ) 936check_tables 937 938msg="different type" 939new_geneve gnv0 4789 940 941cleanup_tuns 942cleanup_nsim 943 944# END 945 946modprobe -r netdevsim 947 948if [ $num_errors -eq 0 ]; then 949 echo "PASSED all $num_cases checks" 950else 951 echo "FAILED $num_errors/$num_cases checks" 952fi 953 954exit $EXIT_STATUS 955