Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | |
| 4 | ############################################################################## |
| 5 | # Defines |
| 6 | |
| 7 | # Can be overridden by the configuration file. |
| 8 | PING=${PING:=ping} |
| 9 | PING6=${PING6:=ping6} |
Ido Schimmel | d4deb01 | 2018-02-28 12:25:07 +0200 | [diff] [blame] | 10 | MZ=${MZ:=mausezahn} |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 11 | WAIT_TIME=${WAIT_TIME:=5} |
| 12 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} |
| 13 | PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no} |
Ido Schimmel | 59be45c | 2018-03-11 09:57:25 +0200 | [diff] [blame] | 14 | NETIF_TYPE=${NETIF_TYPE:=veth} |
| 15 | NETIF_CREATE=${NETIF_CREATE:=yes} |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 16 | |
| 17 | if [[ -f forwarding.config ]]; then |
| 18 | source forwarding.config |
| 19 | fi |
| 20 | |
| 21 | ############################################################################## |
| 22 | # Sanity checks |
| 23 | |
David Ahern | 198979b | 2018-03-01 13:49:30 -0800 | [diff] [blame] | 24 | check_tc_version() |
| 25 | { |
| 26 | tc -j &> /dev/null |
| 27 | if [[ $? -ne 0 ]]; then |
| 28 | echo "SKIP: iproute2 too old; tc is missing JSON support" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | tc filter help 2>&1 | grep block &> /dev/null |
| 33 | if [[ $? -ne 0 ]]; then |
| 34 | echo "SKIP: iproute2 too old; tc is missing shared block support" |
| 35 | exit 1 |
| 36 | fi |
| 37 | } |
| 38 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 39 | if [[ "$(id -u)" -ne 0 ]]; then |
| 40 | echo "SKIP: need root privileges" |
| 41 | exit 0 |
| 42 | fi |
| 43 | |
David Ahern | 198979b | 2018-03-01 13:49:30 -0800 | [diff] [blame] | 44 | if [[ "$CHECK_TC" = "yes" ]]; then |
| 45 | check_tc_version |
Jiri Pirko | 4908e24 | 2018-02-28 12:25:19 +0200 | [diff] [blame] | 46 | fi |
| 47 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 48 | if [[ ! -x "$(command -v jq)" ]]; then |
| 49 | echo "SKIP: jq not installed" |
David Ahern | 198979b | 2018-03-01 13:49:30 -0800 | [diff] [blame] | 50 | exit 1 |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 51 | fi |
| 52 | |
Ido Schimmel | d4deb01 | 2018-02-28 12:25:07 +0200 | [diff] [blame] | 53 | if [[ ! -x "$(command -v $MZ)" ]]; then |
| 54 | echo "SKIP: $MZ not installed" |
Ido Schimmel | ff0162a | 2018-03-11 09:57:23 +0200 | [diff] [blame] | 55 | exit 1 |
Ido Schimmel | d4deb01 | 2018-02-28 12:25:07 +0200 | [diff] [blame] | 56 | fi |
| 57 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 58 | if [[ ! -v NUM_NETIFS ]]; then |
| 59 | echo "SKIP: importer does not define \"NUM_NETIFS\"" |
Ido Schimmel | 231b85a | 2018-03-11 09:57:24 +0200 | [diff] [blame] | 60 | exit 1 |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 61 | fi |
| 62 | |
| 63 | ############################################################################## |
Jiri Pirko | 781fe63 | 2018-02-28 12:25:15 +0200 | [diff] [blame] | 64 | # Command line options handling |
| 65 | |
| 66 | count=0 |
| 67 | |
| 68 | while [[ $# -gt 0 ]]; do |
| 69 | if [[ "$count" -eq "0" ]]; then |
| 70 | unset NETIFS |
| 71 | declare -A NETIFS |
| 72 | fi |
| 73 | count=$((count + 1)) |
| 74 | NETIFS[p$count]="$1" |
| 75 | shift |
| 76 | done |
| 77 | |
| 78 | ############################################################################## |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 79 | # Network interfaces configuration |
| 80 | |
David Ahern | 190f887 | 2018-03-04 17:37:47 -0800 | [diff] [blame] | 81 | create_netif_veth() |
| 82 | { |
| 83 | local i |
| 84 | |
| 85 | for i in $(eval echo {1..$NUM_NETIFS}); do |
| 86 | local j=$((i+1)) |
| 87 | |
| 88 | ip link show dev ${NETIFS[p$i]} &> /dev/null |
| 89 | if [[ $? -ne 0 ]]; then |
| 90 | ip link add ${NETIFS[p$i]} type veth \ |
| 91 | peer name ${NETIFS[p$j]} |
| 92 | if [[ $? -ne 0 ]]; then |
| 93 | echo "Failed to create netif" |
| 94 | exit 1 |
| 95 | fi |
| 96 | fi |
| 97 | i=$j |
| 98 | done |
| 99 | } |
| 100 | |
| 101 | create_netif() |
| 102 | { |
| 103 | case "$NETIF_TYPE" in |
| 104 | veth) create_netif_veth |
| 105 | ;; |
| 106 | *) echo "Can not create interfaces of type \'$NETIF_TYPE\'" |
| 107 | exit 1 |
| 108 | ;; |
| 109 | esac |
| 110 | } |
| 111 | |
| 112 | if [[ "$NETIF_CREATE" = "yes" ]]; then |
| 113 | create_netif |
| 114 | fi |
| 115 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 116 | for i in $(eval echo {1..$NUM_NETIFS}); do |
| 117 | ip link show dev ${NETIFS[p$i]} &> /dev/null |
| 118 | if [[ $? -ne 0 ]]; then |
| 119 | echo "SKIP: could not find all required interfaces" |
Ido Schimmel | 231b85a | 2018-03-11 09:57:24 +0200 | [diff] [blame] | 120 | exit 1 |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 121 | fi |
| 122 | done |
| 123 | |
| 124 | ############################################################################## |
| 125 | # Helpers |
| 126 | |
| 127 | # Exit status to return at the end. Set in case one of the tests fails. |
| 128 | EXIT_STATUS=0 |
| 129 | # Per-test return value. Clear at the beginning of each test. |
| 130 | RET=0 |
| 131 | |
| 132 | check_err() |
| 133 | { |
| 134 | local err=$1 |
| 135 | local msg=$2 |
| 136 | |
| 137 | if [[ $RET -eq 0 && $err -ne 0 ]]; then |
| 138 | RET=$err |
| 139 | retmsg=$msg |
| 140 | fi |
| 141 | } |
| 142 | |
| 143 | check_fail() |
| 144 | { |
| 145 | local err=$1 |
| 146 | local msg=$2 |
| 147 | |
| 148 | if [[ $RET -eq 0 && $err -eq 0 ]]; then |
| 149 | RET=1 |
| 150 | retmsg=$msg |
| 151 | fi |
| 152 | } |
| 153 | |
| 154 | log_test() |
| 155 | { |
| 156 | local test_name=$1 |
| 157 | local opt_str=$2 |
| 158 | |
| 159 | if [[ $# -eq 2 ]]; then |
| 160 | opt_str="($opt_str)" |
| 161 | fi |
| 162 | |
| 163 | if [[ $RET -ne 0 ]]; then |
| 164 | EXIT_STATUS=1 |
| 165 | printf "TEST: %-60s [FAIL]\n" "$test_name $opt_str" |
| 166 | if [[ ! -z "$retmsg" ]]; then |
| 167 | printf "\t%s\n" "$retmsg" |
| 168 | fi |
| 169 | if [ "${PAUSE_ON_FAIL}" = "yes" ]; then |
| 170 | echo "Hit enter to continue, 'q' to quit" |
| 171 | read a |
| 172 | [ "$a" = "q" ] && exit 1 |
| 173 | fi |
| 174 | return 1 |
| 175 | fi |
| 176 | |
| 177 | printf "TEST: %-60s [PASS]\n" "$test_name $opt_str" |
| 178 | return 0 |
| 179 | } |
| 180 | |
Ido Schimmel | 3d578d8 | 2018-02-28 12:25:11 +0200 | [diff] [blame] | 181 | log_info() |
| 182 | { |
| 183 | local msg=$1 |
| 184 | |
| 185 | echo "INFO: $msg" |
| 186 | } |
| 187 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 188 | setup_wait() |
| 189 | { |
| 190 | for i in $(eval echo {1..$NUM_NETIFS}); do |
| 191 | while true; do |
| 192 | ip link show dev ${NETIFS[p$i]} up \ |
| 193 | | grep 'state UP' &> /dev/null |
| 194 | if [[ $? -ne 0 ]]; then |
| 195 | sleep 1 |
| 196 | else |
| 197 | break |
| 198 | fi |
| 199 | done |
| 200 | done |
| 201 | |
| 202 | # Make sure links are ready. |
| 203 | sleep $WAIT_TIME |
| 204 | } |
| 205 | |
| 206 | pre_cleanup() |
| 207 | { |
| 208 | if [ "${PAUSE_ON_CLEANUP}" = "yes" ]; then |
| 209 | echo "Pausing before cleanup, hit any key to continue" |
| 210 | read |
| 211 | fi |
| 212 | } |
| 213 | |
| 214 | vrf_prepare() |
| 215 | { |
| 216 | ip -4 rule add pref 32765 table local |
| 217 | ip -4 rule del pref 0 |
| 218 | ip -6 rule add pref 32765 table local |
| 219 | ip -6 rule del pref 0 |
| 220 | } |
| 221 | |
| 222 | vrf_cleanup() |
| 223 | { |
| 224 | ip -6 rule add pref 0 table local |
| 225 | ip -6 rule del pref 32765 |
| 226 | ip -4 rule add pref 0 table local |
| 227 | ip -4 rule del pref 32765 |
| 228 | } |
| 229 | |
| 230 | __last_tb_id=0 |
| 231 | declare -A __TB_IDS |
| 232 | |
| 233 | __vrf_td_id_assign() |
| 234 | { |
| 235 | local vrf_name=$1 |
| 236 | |
| 237 | __last_tb_id=$((__last_tb_id + 1)) |
| 238 | __TB_IDS[$vrf_name]=$__last_tb_id |
| 239 | return $__last_tb_id |
| 240 | } |
| 241 | |
| 242 | __vrf_td_id_lookup() |
| 243 | { |
| 244 | local vrf_name=$1 |
| 245 | |
| 246 | return ${__TB_IDS[$vrf_name]} |
| 247 | } |
| 248 | |
| 249 | vrf_create() |
| 250 | { |
| 251 | local vrf_name=$1 |
| 252 | local tb_id |
| 253 | |
| 254 | __vrf_td_id_assign $vrf_name |
| 255 | tb_id=$? |
| 256 | |
| 257 | ip link add dev $vrf_name type vrf table $tb_id |
| 258 | ip -4 route add table $tb_id unreachable default metric 4278198272 |
| 259 | ip -6 route add table $tb_id unreachable default metric 4278198272 |
| 260 | } |
| 261 | |
| 262 | vrf_destroy() |
| 263 | { |
| 264 | local vrf_name=$1 |
| 265 | local tb_id |
| 266 | |
| 267 | __vrf_td_id_lookup $vrf_name |
| 268 | tb_id=$? |
| 269 | |
| 270 | ip -6 route del table $tb_id unreachable default metric 4278198272 |
| 271 | ip -4 route del table $tb_id unreachable default metric 4278198272 |
| 272 | ip link del dev $vrf_name |
| 273 | } |
| 274 | |
| 275 | __addr_add_del() |
| 276 | { |
| 277 | local if_name=$1 |
| 278 | local add_del=$2 |
| 279 | local array |
| 280 | |
| 281 | shift |
| 282 | shift |
| 283 | array=("${@}") |
| 284 | |
| 285 | for addrstr in "${array[@]}"; do |
| 286 | ip address $add_del $addrstr dev $if_name |
| 287 | done |
| 288 | } |
| 289 | |
| 290 | simple_if_init() |
| 291 | { |
| 292 | local if_name=$1 |
| 293 | local vrf_name |
| 294 | local array |
| 295 | |
| 296 | shift |
| 297 | vrf_name=v$if_name |
| 298 | array=("${@}") |
| 299 | |
| 300 | vrf_create $vrf_name |
| 301 | ip link set dev $if_name master $vrf_name |
| 302 | ip link set dev $vrf_name up |
| 303 | ip link set dev $if_name up |
| 304 | |
| 305 | __addr_add_del $if_name add "${array[@]}" |
| 306 | } |
| 307 | |
| 308 | simple_if_fini() |
| 309 | { |
| 310 | local if_name=$1 |
| 311 | local vrf_name |
| 312 | local array |
| 313 | |
| 314 | shift |
| 315 | vrf_name=v$if_name |
| 316 | array=("${@}") |
| 317 | |
| 318 | __addr_add_del $if_name del "${array[@]}" |
| 319 | |
| 320 | ip link set dev $if_name down |
| 321 | vrf_destroy $vrf_name |
| 322 | } |
| 323 | |
Petr Machata | 7d4cbae | 2018-04-27 01:17:56 +0200 | [diff] [blame] | 324 | tunnel_create() |
| 325 | { |
| 326 | local name=$1; shift |
| 327 | local type=$1; shift |
| 328 | local local=$1; shift |
| 329 | local remote=$1; shift |
| 330 | |
| 331 | ip link add name $name type $type \ |
| 332 | local $local remote $remote "$@" |
| 333 | ip link set dev $name up |
| 334 | } |
| 335 | |
| 336 | tunnel_destroy() |
| 337 | { |
| 338 | local name=$1; shift |
| 339 | |
| 340 | ip link del dev $name |
| 341 | } |
| 342 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 343 | master_name_get() |
| 344 | { |
| 345 | local if_name=$1 |
| 346 | |
| 347 | ip -j link show dev $if_name | jq -r '.[]["master"]' |
| 348 | } |
| 349 | |
Ido Schimmel | 3d578d8 | 2018-02-28 12:25:11 +0200 | [diff] [blame] | 350 | link_stats_tx_packets_get() |
| 351 | { |
| 352 | local if_name=$1 |
| 353 | |
| 354 | ip -j -s link show dev $if_name | jq '.[]["stats64"]["tx"]["packets"]' |
| 355 | } |
| 356 | |
Petr Machata | 7d4cbae | 2018-04-27 01:17:56 +0200 | [diff] [blame] | 357 | tc_rule_stats_get() |
| 358 | { |
| 359 | local dev=$1; shift |
| 360 | local pref=$1; shift |
| 361 | |
| 362 | tc -j -s filter show dev $dev ingress pref $pref | |
| 363 | jq '.[1].options.actions[].stats.packets' |
| 364 | } |
| 365 | |
Jiri Pirko | 4e4272d | 2018-02-28 12:25:14 +0200 | [diff] [blame] | 366 | mac_get() |
| 367 | { |
| 368 | local if_name=$1 |
| 369 | |
| 370 | ip -j link show dev $if_name | jq -r '.[]["address"]' |
| 371 | } |
| 372 | |
Ido Schimmel | d4deb01 | 2018-02-28 12:25:07 +0200 | [diff] [blame] | 373 | bridge_ageing_time_get() |
| 374 | { |
| 375 | local bridge=$1 |
| 376 | local ageing_time |
| 377 | |
| 378 | # Need to divide by 100 to convert to seconds. |
| 379 | ageing_time=$(ip -j -d link show dev $bridge \ |
| 380 | | jq '.[]["linkinfo"]["info_data"]["ageing_time"]') |
| 381 | echo $((ageing_time / 100)) |
| 382 | } |
| 383 | |
Petr Machata | f5ae577 | 2018-05-03 12:36:59 +0200 | [diff] [blame^] | 384 | declare -A SYSCTL_ORIG |
| 385 | sysctl_set() |
| 386 | { |
| 387 | local key=$1; shift |
| 388 | local value=$1; shift |
| 389 | |
| 390 | SYSCTL_ORIG[$key]=$(sysctl -n $key) |
| 391 | sysctl -qw $key=$value |
| 392 | } |
| 393 | |
| 394 | sysctl_restore() |
| 395 | { |
| 396 | local key=$1; shift |
| 397 | |
| 398 | sysctl -qw $key=${SYSCTL_ORIG["$key"]} |
| 399 | } |
| 400 | |
Ido Schimmel | 7b7bc87 | 2018-02-28 12:25:09 +0200 | [diff] [blame] | 401 | forwarding_enable() |
| 402 | { |
| 403 | ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding) |
| 404 | ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding) |
| 405 | |
| 406 | sysctl -q -w net.ipv4.conf.all.forwarding=1 |
| 407 | sysctl -q -w net.ipv6.conf.all.forwarding=1 |
| 408 | } |
| 409 | |
| 410 | forwarding_restore() |
| 411 | { |
| 412 | sysctl -q -w net.ipv6.conf.all.forwarding=$ipv6_fwd |
| 413 | sysctl -q -w net.ipv4.conf.all.forwarding=$ipv4_fwd |
| 414 | } |
| 415 | |
Jiri Pirko | 2f19f21 | 2018-02-28 12:25:13 +0200 | [diff] [blame] | 416 | tc_offload_check() |
| 417 | { |
| 418 | for i in $(eval echo {1..$NUM_NETIFS}); do |
| 419 | ethtool -k ${NETIFS[p$i]} \ |
| 420 | | grep "hw-tc-offload: on" &> /dev/null |
| 421 | if [[ $? -ne 0 ]]; then |
| 422 | return 1 |
| 423 | fi |
| 424 | done |
| 425 | |
| 426 | return 0 |
| 427 | } |
| 428 | |
Petr Machata | 7d4cbae | 2018-04-27 01:17:56 +0200 | [diff] [blame] | 429 | slow_path_trap_install() |
| 430 | { |
| 431 | local dev=$1; shift |
| 432 | local direction=$1; shift |
| 433 | |
| 434 | if [ "${tcflags/skip_hw}" != "$tcflags" ]; then |
| 435 | # For slow-path testing, we need to install a trap to get to |
| 436 | # slow path the packets that would otherwise be switched in HW. |
| 437 | tc filter add dev $dev $direction pref 1 \ |
| 438 | flower skip_sw action trap |
| 439 | fi |
| 440 | } |
| 441 | |
| 442 | slow_path_trap_uninstall() |
| 443 | { |
| 444 | local dev=$1; shift |
| 445 | local direction=$1; shift |
| 446 | |
| 447 | if [ "${tcflags/skip_hw}" != "$tcflags" ]; then |
| 448 | tc filter del dev $dev $direction pref 1 flower skip_sw |
| 449 | fi |
| 450 | } |
| 451 | |
| 452 | __icmp_capture_add_del() |
| 453 | { |
| 454 | local add_del=$1; shift |
| 455 | local pref=$1; shift |
| 456 | local vsuf=$1; shift |
| 457 | local tundev=$1; shift |
| 458 | local filter=$1; shift |
| 459 | |
| 460 | tc filter $add_del dev "$tundev" ingress \ |
| 461 | proto ip$vsuf pref $pref \ |
| 462 | flower ip_proto icmp$vsuf $filter \ |
| 463 | action pass |
| 464 | } |
| 465 | |
| 466 | icmp_capture_install() |
| 467 | { |
| 468 | __icmp_capture_add_del add 100 "" "$@" |
| 469 | } |
| 470 | |
| 471 | icmp_capture_uninstall() |
| 472 | { |
| 473 | __icmp_capture_add_del del 100 "" "$@" |
| 474 | } |
| 475 | |
| 476 | icmp6_capture_install() |
| 477 | { |
| 478 | __icmp_capture_add_del add 100 v6 "$@" |
| 479 | } |
| 480 | |
| 481 | icmp6_capture_uninstall() |
| 482 | { |
| 483 | __icmp_capture_add_del del 100 v6 "$@" |
| 484 | } |
| 485 | |
| 486 | matchall_sink_create() |
| 487 | { |
| 488 | local dev=$1; shift |
| 489 | |
| 490 | tc qdisc add dev $dev clsact |
| 491 | tc filter add dev $dev ingress \ |
| 492 | pref 10000 \ |
| 493 | matchall \ |
| 494 | action drop |
| 495 | } |
| 496 | |
Ido Schimmel | 0eb8053 | 2018-05-03 10:51:33 +0300 | [diff] [blame] | 497 | tests_run() |
| 498 | { |
| 499 | local current_test |
| 500 | |
| 501 | for current_test in ${TESTS:-$ALL_TESTS}; do |
| 502 | $current_test |
| 503 | done |
| 504 | } |
| 505 | |
Ido Schimmel | 73bae67 | 2018-02-28 12:25:06 +0200 | [diff] [blame] | 506 | ############################################################################## |
| 507 | # Tests |
| 508 | |
| 509 | ping_test() |
| 510 | { |
| 511 | local if_name=$1 |
| 512 | local dip=$2 |
| 513 | local vrf_name |
| 514 | |
| 515 | RET=0 |
| 516 | |
| 517 | vrf_name=$(master_name_get $if_name) |
| 518 | ip vrf exec $vrf_name $PING $dip -c 10 -i 0.1 -w 2 &> /dev/null |
| 519 | check_err $? |
| 520 | log_test "ping" |
| 521 | } |
| 522 | |
| 523 | ping6_test() |
| 524 | { |
| 525 | local if_name=$1 |
| 526 | local dip=$2 |
| 527 | local vrf_name |
| 528 | |
| 529 | RET=0 |
| 530 | |
| 531 | vrf_name=$(master_name_get $if_name) |
| 532 | ip vrf exec $vrf_name $PING6 $dip -c 10 -i 0.1 -w 2 &> /dev/null |
| 533 | check_err $? |
| 534 | log_test "ping6" |
| 535 | } |
Ido Schimmel | d4deb01 | 2018-02-28 12:25:07 +0200 | [diff] [blame] | 536 | |
| 537 | learning_test() |
| 538 | { |
| 539 | local bridge=$1 |
| 540 | local br_port1=$2 # Connected to `host1_if`. |
| 541 | local host1_if=$3 |
| 542 | local host2_if=$4 |
| 543 | local mac=de:ad:be:ef:13:37 |
| 544 | local ageing_time |
| 545 | |
| 546 | RET=0 |
| 547 | |
| 548 | bridge -j fdb show br $bridge brport $br_port1 \ |
| 549 | | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 550 | check_fail $? "Found FDB record when should not" |
| 551 | |
| 552 | # Disable unknown unicast flooding on `br_port1` to make sure |
| 553 | # packets are only forwarded through the port after a matching |
| 554 | # FDB entry was installed. |
| 555 | bridge link set dev $br_port1 flood off |
| 556 | |
| 557 | tc qdisc add dev $host1_if ingress |
| 558 | tc filter add dev $host1_if ingress protocol ip pref 1 handle 101 \ |
| 559 | flower dst_mac $mac action drop |
| 560 | |
| 561 | $MZ $host2_if -c 1 -p 64 -b $mac -t ip -q |
| 562 | sleep 1 |
| 563 | |
| 564 | tc -j -s filter show dev $host1_if ingress \ |
| 565 | | jq -e ".[] | select(.options.handle == 101) \ |
| 566 | | select(.options.actions[0].stats.packets == 1)" &> /dev/null |
| 567 | check_fail $? "Packet reached second host when should not" |
| 568 | |
| 569 | $MZ $host1_if -c 1 -p 64 -a $mac -t ip -q |
| 570 | sleep 1 |
| 571 | |
| 572 | bridge -j fdb show br $bridge brport $br_port1 \ |
| 573 | | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 574 | check_err $? "Did not find FDB record when should" |
| 575 | |
| 576 | $MZ $host2_if -c 1 -p 64 -b $mac -t ip -q |
| 577 | sleep 1 |
| 578 | |
| 579 | tc -j -s filter show dev $host1_if ingress \ |
| 580 | | jq -e ".[] | select(.options.handle == 101) \ |
| 581 | | select(.options.actions[0].stats.packets == 1)" &> /dev/null |
| 582 | check_err $? "Packet did not reach second host when should" |
| 583 | |
| 584 | # Wait for 10 seconds after the ageing time to make sure FDB |
| 585 | # record was aged-out. |
| 586 | ageing_time=$(bridge_ageing_time_get $bridge) |
| 587 | sleep $((ageing_time + 10)) |
| 588 | |
| 589 | bridge -j fdb show br $bridge brport $br_port1 \ |
| 590 | | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 591 | check_fail $? "Found FDB record when should not" |
| 592 | |
| 593 | bridge link set dev $br_port1 learning off |
| 594 | |
| 595 | $MZ $host1_if -c 1 -p 64 -a $mac -t ip -q |
| 596 | sleep 1 |
| 597 | |
| 598 | bridge -j fdb show br $bridge brport $br_port1 \ |
| 599 | | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 600 | check_fail $? "Found FDB record when should not" |
| 601 | |
| 602 | bridge link set dev $br_port1 learning on |
| 603 | |
| 604 | tc filter del dev $host1_if ingress protocol ip pref 1 handle 101 flower |
| 605 | tc qdisc del dev $host1_if ingress |
| 606 | |
| 607 | bridge link set dev $br_port1 flood on |
| 608 | |
| 609 | log_test "FDB learning" |
| 610 | } |
Ido Schimmel | 236dd50 | 2018-02-28 12:25:08 +0200 | [diff] [blame] | 611 | |
| 612 | flood_test_do() |
| 613 | { |
| 614 | local should_flood=$1 |
| 615 | local mac=$2 |
| 616 | local ip=$3 |
| 617 | local host1_if=$4 |
| 618 | local host2_if=$5 |
| 619 | local err=0 |
| 620 | |
| 621 | # Add an ACL on `host2_if` which will tell us whether the packet |
| 622 | # was flooded to it or not. |
| 623 | tc qdisc add dev $host2_if ingress |
| 624 | tc filter add dev $host2_if ingress protocol ip pref 1 handle 101 \ |
| 625 | flower dst_mac $mac action drop |
| 626 | |
| 627 | $MZ $host1_if -c 1 -p 64 -b $mac -B $ip -t ip -q |
| 628 | sleep 1 |
| 629 | |
| 630 | tc -j -s filter show dev $host2_if ingress \ |
| 631 | | jq -e ".[] | select(.options.handle == 101) \ |
| 632 | | select(.options.actions[0].stats.packets == 1)" &> /dev/null |
| 633 | if [[ $? -ne 0 && $should_flood == "true" || \ |
| 634 | $? -eq 0 && $should_flood == "false" ]]; then |
| 635 | err=1 |
| 636 | fi |
| 637 | |
| 638 | tc filter del dev $host2_if ingress protocol ip pref 1 handle 101 flower |
| 639 | tc qdisc del dev $host2_if ingress |
| 640 | |
| 641 | return $err |
| 642 | } |
| 643 | |
| 644 | flood_unicast_test() |
| 645 | { |
| 646 | local br_port=$1 |
| 647 | local host1_if=$2 |
| 648 | local host2_if=$3 |
| 649 | local mac=de:ad:be:ef:13:37 |
| 650 | local ip=192.0.2.100 |
| 651 | |
| 652 | RET=0 |
| 653 | |
| 654 | bridge link set dev $br_port flood off |
| 655 | |
| 656 | flood_test_do false $mac $ip $host1_if $host2_if |
| 657 | check_err $? "Packet flooded when should not" |
| 658 | |
| 659 | bridge link set dev $br_port flood on |
| 660 | |
| 661 | flood_test_do true $mac $ip $host1_if $host2_if |
| 662 | check_err $? "Packet was not flooded when should" |
| 663 | |
| 664 | log_test "Unknown unicast flood" |
| 665 | } |
| 666 | |
| 667 | flood_multicast_test() |
| 668 | { |
| 669 | local br_port=$1 |
| 670 | local host1_if=$2 |
| 671 | local host2_if=$3 |
| 672 | local mac=01:00:5e:00:00:01 |
| 673 | local ip=239.0.0.1 |
| 674 | |
| 675 | RET=0 |
| 676 | |
| 677 | bridge link set dev $br_port mcast_flood off |
| 678 | |
| 679 | flood_test_do false $mac $ip $host1_if $host2_if |
| 680 | check_err $? "Packet flooded when should not" |
| 681 | |
| 682 | bridge link set dev $br_port mcast_flood on |
| 683 | |
| 684 | flood_test_do true $mac $ip $host1_if $host2_if |
| 685 | check_err $? "Packet was not flooded when should" |
| 686 | |
| 687 | log_test "Unregistered multicast flood" |
| 688 | } |
| 689 | |
| 690 | flood_test() |
| 691 | { |
| 692 | # `br_port` is connected to `host2_if` |
| 693 | local br_port=$1 |
| 694 | local host1_if=$2 |
| 695 | local host2_if=$3 |
| 696 | |
| 697 | flood_unicast_test $br_port $host1_if $host2_if |
| 698 | flood_multicast_test $br_port $host1_if $host2_if |
| 699 | } |