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 new=$(ls /sys/class/net) 237 238 for netdev in $new; do 239 for check in $old; do 240 [ $netdev == $check ] && break 241 done 242 243 if [ $netdev != $check ]; then 244 echo $netdev 245 break 246 fi 247 done 248} 249 250### 251### Code start 252### 253 254# Probe ethtool support 255ethtool -h | grep show-tunnels 2>&1 >/dev/null && HAS_ETHTOOL=y 256 257modprobe netdevsim 258 259# Basic test 260pfx="basic" 261 262for port in 0 1; do 263 old_netdevs=$(ls /sys/class/net) 264 if [ $port -eq 0 ]; then 265 echo $NSIM_ID > /sys/bus/netdevsim/new_device 266 else 267 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 268 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 269 echo 1 > $NSIM_DEV_SYS/new_port 270 fi 271 NSIM_NETDEV=`get_netdev_name old_netdevs` 272 ifconfig $NSIM_NETDEV up 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 NSIM_NETDEV=`get_netdev_name old_netdevs` 435 ifconfig $NSIM_NETDEV up 436 437 overflow_table0 "overflow NIC table" 438 overflow_table1 "overflow NIC table" 439 440 msg="replace VxLAN in overflow table" 441 exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 442 del_dev vxlan1 443 444 msg="vacate VxLAN in overflow table" 445 exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 446 del_dev vxlan2 447 448 msg="replace GENEVE in overflow table" 449 exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` ) 450 del_dev gnv1 451 452 msg="vacate GENEVE in overflow table" 453 exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` ) 454 del_dev gnv2 455 456 msg="table sharing - share" 457 exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` ) 458 new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external" 459 460 msg="table sharing - overflow" 461 new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external" 462 msg="table sharing - overflow v6" 463 new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external" 464 465 exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` ) 466 del_dev gnv4 467 468 msg="destroy NIC" 469 echo $port > $NSIM_DEV_SYS/del_port 470 471 cleanup_tuns 472 exp0=( 0 0 0 0 ) 473 exp1=( 0 0 0 0 ) 474done 475 476cleanup_nsim 477 478# Sync all 479pfx="sync all" 480 481echo $NSIM_ID > /sys/bus/netdevsim/new_device 482echo 0 > $NSIM_DEV_SYS/del_port 483echo 1 > $NSIM_DEV_DFS/udp_ports_sync_all 484 485for port in 0 1; do 486 if [ $port -ne 0 ]; then 487 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 488 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 489 fi 490 491 echo $port > $NSIM_DEV_SYS/new_port 492 NSIM_NETDEV=`get_netdev_name old_netdevs` 493 ifconfig $NSIM_NETDEV up 494 495 overflow_table0 "overflow NIC table" 496 overflow_table1 "overflow NIC table" 497 498 msg="replace VxLAN in overflow table" 499 exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 500 del_dev vxlan1 501 502 msg="vacate VxLAN in overflow table" 503 exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 504 del_dev vxlan2 505 506 msg="replace GENEVE in overflow table" 507 exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` ) 508 del_dev gnv1 509 510 msg="vacate GENEVE in overflow table" 511 exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` ) 512 del_dev gnv2 513 514 msg="table sharing - share" 515 exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` ) 516 new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external" 517 518 msg="table sharing - overflow" 519 new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external" 520 msg="table sharing - overflow v6" 521 new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external" 522 523 exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` ) 524 del_dev gnv4 525 526 msg="destroy NIC" 527 echo $port > $NSIM_DEV_SYS/del_port 528 529 cleanup_tuns 530 exp0=( 0 0 0 0 ) 531 exp1=( 0 0 0 0 ) 532done 533 534cleanup_nsim 535 536# Destroy full NIC 537pfx="destroy full" 538 539echo $NSIM_ID > /sys/bus/netdevsim/new_device 540echo 0 > $NSIM_DEV_SYS/del_port 541 542for port in 0 1; do 543 if [ $port -ne 0 ]; then 544 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 545 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 546 fi 547 548 echo $port > $NSIM_DEV_SYS/new_port 549 NSIM_NETDEV=`get_netdev_name old_netdevs` 550 ifconfig $NSIM_NETDEV up 551 552 overflow_table0 "destroy NIC" 553 overflow_table1 "destroy NIC" 554 555 msg="destroy NIC" 556 echo $port > $NSIM_DEV_SYS/del_port 557 558 cleanup_tuns 559 exp0=( 0 0 0 0 ) 560 exp1=( 0 0 0 0 ) 561done 562 563cleanup_nsim 564 565# IPv4 only 566pfx="IPv4 only" 567 568echo $NSIM_ID > /sys/bus/netdevsim/new_device 569echo 0 > $NSIM_DEV_SYS/del_port 570echo 1 > $NSIM_DEV_DFS/udp_ports_ipv4_only 571 572for port in 0 1; do 573 if [ $port -ne 0 ]; then 574 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 575 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 576 fi 577 578 echo $port > $NSIM_DEV_SYS/new_port 579 NSIM_NETDEV=`get_netdev_name old_netdevs` 580 ifconfig $NSIM_NETDEV up 581 582 msg="create VxLANs v6" 583 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 584 585 msg="create VxLANs v6" 586 new_vxlan vxlanA1 10000 $NSIM_NETDEV 6 587 588 ip link set dev vxlanA0 down 589 ip link set dev vxlanA0 up 590 check_tables 591 592 msg="create VxLANs v4" 593 exp0=( `mke 10000 1` 0 0 0 ) 594 new_vxlan vxlan0 10000 $NSIM_NETDEV 595 596 msg="down VxLANs v4" 597 exp0=( 0 0 0 0 ) 598 ip link set dev vxlan0 down 599 check_tables 600 601 msg="up VxLANs v4" 602 exp0=( `mke 10000 1` 0 0 0 ) 603 ip link set dev vxlan0 up 604 check_tables 605 606 msg="destroy VxLANs v4" 607 exp0=( 0 0 0 0 ) 608 del_dev vxlan0 609 610 msg="recreate VxLANs v4" 611 exp0=( `mke 10000 1` 0 0 0 ) 612 new_vxlan vxlan0 10000 $NSIM_NETDEV 613 614 del_dev vxlanA0 615 del_dev vxlanA1 616 617 msg="destroy NIC" 618 echo $port > $NSIM_DEV_SYS/del_port 619 620 cleanup_tuns 621 exp0=( 0 0 0 0 ) 622 exp1=( 0 0 0 0 ) 623done 624 625cleanup_nsim 626 627# Failures 628pfx="error injection" 629 630echo $NSIM_ID > /sys/bus/netdevsim/new_device 631echo 0 > $NSIM_DEV_SYS/del_port 632 633for port in 0 1; do 634 if [ $port -ne 0 ]; then 635 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 636 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 637 fi 638 639 echo $port > $NSIM_DEV_SYS/new_port 640 NSIM_NETDEV=`get_netdev_name old_netdevs` 641 ifconfig $NSIM_NETDEV up 642 643 echo 110 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error 644 645 msg="1 - create VxLANs v6" 646 exp0=( 0 0 0 0 ) 647 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 648 649 msg="1 - create VxLANs v4" 650 exp0=( `mke 10000 1` 0 0 0 ) 651 new_vxlan vxlan0 10000 $NSIM_NETDEV 652 653 msg="1 - remove VxLANs v4" 654 del_dev vxlan0 655 656 msg="1 - remove VxLANs v6" 657 exp0=( 0 0 0 0 ) 658 del_dev vxlanA0 659 660 msg="2 - create GENEVE" 661 exp1=( `mke 20000 2` 0 0 0 ) 662 new_geneve gnv0 20000 663 664 msg="2 - destroy GENEVE" 665 echo 2 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error 666 exp1=( `mke 20000 2` 0 0 0 ) 667 del_dev gnv0 668 669 msg="2 - create second GENEVE" 670 exp1=( 0 `mke 20001 2` 0 0 ) 671 new_geneve gnv0 20001 672 673 msg="destroy NIC" 674 echo $port > $NSIM_DEV_SYS/del_port 675 676 cleanup_tuns 677 exp0=( 0 0 0 0 ) 678 exp1=( 0 0 0 0 ) 679done 680 681cleanup_nsim 682 683# netdev flags 684pfx="netdev flags" 685 686echo $NSIM_ID > /sys/bus/netdevsim/new_device 687echo 0 > $NSIM_DEV_SYS/del_port 688 689for port in 0 1; do 690 if [ $port -ne 0 ]; then 691 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 692 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 693 fi 694 695 echo $port > $NSIM_DEV_SYS/new_port 696 NSIM_NETDEV=`get_netdev_name old_netdevs` 697 ifconfig $NSIM_NETDEV up 698 699 msg="create VxLANs v6" 700 exp0=( `mke 10000 1` 0 0 0 ) 701 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 702 703 msg="create VxLANs v4" 704 new_vxlan vxlan0 10000 $NSIM_NETDEV 705 706 msg="turn off" 707 exp0=( 0 0 0 0 ) 708 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 709 check_tables 710 711 msg="turn on" 712 exp0=( `mke 10000 1` 0 0 0 ) 713 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 714 check_tables 715 716 msg="remove both" 717 del_dev vxlanA0 718 exp0=( 0 0 0 0 ) 719 del_dev vxlan0 720 check_tables 721 722 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 723 724 msg="create VxLANs v4 - off" 725 exp0=( 0 0 0 0 ) 726 new_vxlan vxlan0 10000 $NSIM_NETDEV 727 728 msg="created off - turn on" 729 exp0=( `mke 10000 1` 0 0 0 ) 730 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 731 check_tables 732 733 msg="destroy NIC" 734 echo $port > $NSIM_DEV_SYS/del_port 735 736 cleanup_tuns 737 exp0=( 0 0 0 0 ) 738 exp1=( 0 0 0 0 ) 739done 740 741cleanup_nsim 742 743# device initiated reset 744pfx="reset notification" 745 746echo $NSIM_ID > /sys/bus/netdevsim/new_device 747echo 0 > $NSIM_DEV_SYS/del_port 748 749for port in 0 1; do 750 if [ $port -ne 0 ]; then 751 echo 1 > $NSIM_DEV_DFS/udp_ports_open_only 752 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 753 fi 754 755 echo $port > $NSIM_DEV_SYS/new_port 756 NSIM_NETDEV=`get_netdev_name old_netdevs` 757 ifconfig $NSIM_NETDEV up 758 759 msg="create VxLANs v6" 760 exp0=( `mke 10000 1` 0 0 0 ) 761 new_vxlan vxlanA0 10000 $NSIM_NETDEV 6 762 763 msg="create VxLANs v4" 764 new_vxlan vxlan0 10000 $NSIM_NETDEV 765 766 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 767 check_tables 768 769 msg="NIC device goes down" 770 ifconfig $NSIM_NETDEV down 771 if [ $port -eq 1 ]; then 772 exp0=( 0 0 0 0 ) 773 exp1=( 0 0 0 0 ) 774 fi 775 check_tables 776 777 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 778 check_tables 779 780 msg="NIC device goes up again" 781 ifconfig $NSIM_NETDEV up 782 exp0=( `mke 10000 1` 0 0 0 ) 783 check_tables 784 785 msg="remove both" 786 del_dev vxlanA0 787 exp0=( 0 0 0 0 ) 788 del_dev vxlan0 789 check_tables 790 791 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 792 check_tables 793 794 msg="destroy NIC" 795 echo $port > $NSIM_DEV_SYS/del_port 796 797 cleanup_tuns 798 exp0=( 0 0 0 0 ) 799 exp1=( 0 0 0 0 ) 800done 801 802cleanup_nsim 803 804# shared port tables 805pfx="table sharing" 806 807echo $NSIM_ID > /sys/bus/netdevsim/new_device 808echo 0 > $NSIM_DEV_SYS/del_port 809 810echo 0 > $NSIM_DEV_DFS/udp_ports_open_only 811echo 1 > $NSIM_DEV_DFS/udp_ports_sleep 812echo 1 > $NSIM_DEV_DFS/udp_ports_shared 813 814old_netdevs=$(ls /sys/class/net) 815echo 1 > $NSIM_DEV_SYS/new_port 816NSIM_NETDEV=`get_netdev_name old_netdevs` 817old_netdevs=$(ls /sys/class/net) 818echo 2 > $NSIM_DEV_SYS/new_port 819NSIM_NETDEV2=`get_netdev_name old_netdevs` 820 821msg="VxLAN v4 devices" 822exp0=( `mke 4789 1` 0 0 0 ) 823exp1=( 0 0 0 0 ) 824new_vxlan vxlan0 4789 $NSIM_NETDEV 825new_vxlan vxlan1 4789 $NSIM_NETDEV2 826 827msg="VxLAN v4 devices go down" 828exp0=( 0 0 0 0 ) 829ifconfig vxlan1 down 830ifconfig vxlan0 down 831check_tables 832 833for ifc in vxlan0 vxlan1; do 834 ifconfig $ifc up 835done 836 837msg="VxLAN v6 device" 838exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 839new_vxlan vxlanC 4790 $NSIM_NETDEV 6 840 841msg="Geneve device" 842exp1=( `mke 6081 2` 0 0 0 ) 843new_geneve gnv0 6081 844 845msg="NIC device goes down" 846ifconfig $NSIM_NETDEV down 847check_tables 848 849msg="NIC device goes up again" 850ifconfig $NSIM_NETDEV up 851check_tables 852 853for i in `seq 2`; do 854 msg="turn feature off - 1, rep $i" 855 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off 856 check_tables 857 858 msg="turn feature off - 2, rep $i" 859 exp0=( 0 0 0 0 ) 860 exp1=( 0 0 0 0 ) 861 ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload off 862 check_tables 863 864 msg="turn feature on - 1, rep $i" 865 exp0=( `mke 4789 1` `mke 4790 1` 0 0 ) 866 exp1=( `mke 6081 2` 0 0 0 ) 867 ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on 868 check_tables 869 870 msg="turn feature on - 2, rep $i" 871 ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload on 872 check_tables 873done 874 875msg="tunnels destroyed 1" 876cleanup_tuns 877exp0=( 0 0 0 0 ) 878exp1=( 0 0 0 0 ) 879check_tables 880 881overflow_table0 "overflow NIC table" 882 883msg="re-add a port" 884 885echo 2 > $NSIM_DEV_SYS/del_port 886echo 2 > $NSIM_DEV_SYS/new_port 887NSIM_NETDEV=`get_netdev_name old_netdevs` 888check_tables 889 890msg="replace VxLAN in overflow table" 891exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` ) 892del_dev vxlan1 893 894msg="vacate VxLAN in overflow table" 895exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` ) 896del_dev vxlan2 897 898echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset 899check_tables 900 901msg="tunnels destroyed 2" 902cleanup_tuns 903exp0=( 0 0 0 0 ) 904exp1=( 0 0 0 0 ) 905check_tables 906 907echo 1 > $NSIM_DEV_SYS/del_port 908echo 2 > $NSIM_DEV_SYS/del_port 909 910cleanup_nsim 911 912# Static IANA port 913pfx="static IANA vxlan" 914 915echo $NSIM_ID > /sys/bus/netdevsim/new_device 916echo 0 > $NSIM_DEV_SYS/del_port 917 918echo 1 > $NSIM_DEV_DFS/udp_ports_static_iana_vxlan 919STATIC_ENTRIES=( `mke 4789 1` ) 920 921port=1 922old_netdevs=$(ls /sys/class/net) 923echo $port > $NSIM_DEV_SYS/new_port 924NSIM_NETDEV=`get_netdev_name old_netdevs` 925 926msg="check empty" 927exp0=( 0 0 0 0 ) 928exp1=( 0 0 0 0 ) 929check_tables 930 931msg="add on static port" 932new_vxlan vxlan0 4789 $NSIM_NETDEV 933new_vxlan vxlan1 4789 $NSIM_NETDEV 934 935msg="add on different port" 936exp0=( `mke 4790 1` 0 0 0 ) 937new_vxlan vxlan2 4790 $NSIM_NETDEV 938 939cleanup_tuns 940 941msg="tunnels destroyed" 942exp0=( 0 0 0 0 ) 943exp1=( 0 0 0 0 ) 944check_tables 945 946msg="different type" 947new_geneve gnv0 4789 948 949cleanup_tuns 950cleanup_nsim 951 952# END 953 954modprobe -r netdevsim 955 956if [ $num_errors -eq 0 ]; then 957 echo "PASSED all $num_cases checks" 958else 959 echo "FAILED $num_errors/$num_cases checks" 960fi 961 962exit $EXIT_STATUS 963