@@ -12,7 +12,8 @@ ksft_skip=4
12
12
TESTS=" unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
13
13
ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \
14
14
ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
15
- ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
15
+ ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \
16
+ ipv4_mpath_list ipv6_mpath_list"
16
17
17
18
VERBOSE=0
18
19
PAUSE_ON_FAIL=no
@@ -2352,6 +2353,156 @@ ipv4_bcast_neigh_test()
2352
2353
cleanup
2353
2354
}
2354
2355
2356
+ mpath_dep_check ()
2357
+ {
2358
+ if [ ! -x " $( command -v mausezahn) " ]; then
2359
+ echo " mausezahn command not found. Skipping test"
2360
+ return 1
2361
+ fi
2362
+
2363
+ if [ ! -x " $( command -v jq) " ]; then
2364
+ echo " jq command not found. Skipping test"
2365
+ return 1
2366
+ fi
2367
+
2368
+ if [ ! -x " $( command -v bc) " ]; then
2369
+ echo " bc command not found. Skipping test"
2370
+ return 1
2371
+ fi
2372
+
2373
+ if [ ! -x " $( command -v perf) " ]; then
2374
+ echo " perf command not found. Skipping test"
2375
+ return 1
2376
+ fi
2377
+
2378
+ perf list fib:* | grep -q fib_table_lookup
2379
+ if [ $? -ne 0 ]; then
2380
+ echo " IPv4 FIB tracepoint not found. Skipping test"
2381
+ return 1
2382
+ fi
2383
+
2384
+ perf list fib6:* | grep -q fib6_table_lookup
2385
+ if [ $? -ne 0 ]; then
2386
+ echo " IPv6 FIB tracepoint not found. Skipping test"
2387
+ return 1
2388
+ fi
2389
+
2390
+ return 0
2391
+ }
2392
+
2393
+ link_stats_get ()
2394
+ {
2395
+ local ns=$1 ; shift
2396
+ local dev=$1 ; shift
2397
+ local dir=$1 ; shift
2398
+ local stat=$1 ; shift
2399
+
2400
+ ip -n $ns -j -s link show dev $dev \
2401
+ | jq ' .[]["stats64"]["' $dir ' "]["' $stat ' "]'
2402
+ }
2403
+
2404
+ list_rcv_eval ()
2405
+ {
2406
+ local file=$1 ; shift
2407
+ local expected=$1 ; shift
2408
+
2409
+ local count=$( tail -n 1 $file | jq ' .["counter-value"] | tonumber | floor' )
2410
+ local ratio=$( echo " scale=2; $count / $expected " | bc -l)
2411
+ local res=$( echo " $ratio >= 0.95" | bc)
2412
+ [[ $res -eq 1 ]]
2413
+ log_test $? 0 " Multipath route hit ratio ($ratio )"
2414
+ }
2415
+
2416
+ ipv4_mpath_list_test ()
2417
+ {
2418
+ echo
2419
+ echo " IPv4 multipath list receive tests"
2420
+
2421
+ mpath_dep_check || return 1
2422
+
2423
+ route_setup
2424
+
2425
+ set -e
2426
+ run_cmd " ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
2427
+
2428
+ run_cmd " ip netns exec ns2 bash -c \" echo 20000 > /sys/class/net/veth2/gro_flush_timeout\" "
2429
+ run_cmd " ip netns exec ns2 bash -c \" echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\" "
2430
+ run_cmd " ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
2431
+ run_cmd " ip -n ns2 link add name nh1 up type dummy"
2432
+ run_cmd " ip -n ns2 link add name nh2 up type dummy"
2433
+ run_cmd " ip -n ns2 address add 172.16.201.1/24 dev nh1"
2434
+ run_cmd " ip -n ns2 address add 172.16.202.1/24 dev nh2"
2435
+ run_cmd " ip -n ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
2436
+ run_cmd " ip -n ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
2437
+ run_cmd " ip -n ns2 route add 203.0.113.0/24
2438
+ nexthop via 172.16.201.2 nexthop via 172.16.202.2"
2439
+ run_cmd " ip netns exec ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1"
2440
+ set +e
2441
+
2442
+ local dmac=$( ip -n ns2 -j link show dev veth2 | jq -r ' .[]["address"]' )
2443
+ local tmp_file=$( mktemp)
2444
+ local cmd=" ip netns exec ns1 mausezahn veth1 -a own -b $dmac
2445
+ -A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q"
2446
+
2447
+ # Packets forwarded in a list using a multipath route must not reuse a
2448
+ # cached result so that a flow always hits the same nexthop. In other
2449
+ # words, the FIB lookup tracepoint needs to be triggered for every
2450
+ # packet.
2451
+ local t0_rx_pkts=$( link_stats_get ns2 veth2 rx packets)
2452
+ run_cmd " perf stat -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd "
2453
+ local t1_rx_pkts=$( link_stats_get ns2 veth2 rx packets)
2454
+ local diff=$( echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
2455
+ list_rcv_eval $tmp_file $diff
2456
+
2457
+ rm $tmp_file
2458
+ route_cleanup
2459
+ }
2460
+
2461
+ ipv6_mpath_list_test ()
2462
+ {
2463
+ echo
2464
+ echo " IPv6 multipath list receive tests"
2465
+
2466
+ mpath_dep_check || return 1
2467
+
2468
+ route_setup
2469
+
2470
+ set -e
2471
+ run_cmd " ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
2472
+
2473
+ run_cmd " ip netns exec ns2 bash -c \" echo 20000 > /sys/class/net/veth2/gro_flush_timeout\" "
2474
+ run_cmd " ip netns exec ns2 bash -c \" echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\" "
2475
+ run_cmd " ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
2476
+ run_cmd " ip -n ns2 link add name nh1 up type dummy"
2477
+ run_cmd " ip -n ns2 link add name nh2 up type dummy"
2478
+ run_cmd " ip -n ns2 -6 address add 2001:db8:201::1/64 dev nh1"
2479
+ run_cmd " ip -n ns2 -6 address add 2001:db8:202::1/64 dev nh2"
2480
+ run_cmd " ip -n ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
2481
+ run_cmd " ip -n ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
2482
+ run_cmd " ip -n ns2 -6 route add 2001:db8:301::/64
2483
+ nexthop via 2001:db8:201::2 nexthop via 2001:db8:202::2"
2484
+ run_cmd " ip netns exec ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1"
2485
+ set +e
2486
+
2487
+ local dmac=$( ip -n ns2 -j link show dev veth2 | jq -r ' .[]["address"]' )
2488
+ local tmp_file=$( mktemp)
2489
+ local cmd=" ip netns exec ns1 mausezahn -6 veth1 -a own -b $dmac
2490
+ -A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q"
2491
+
2492
+ # Packets forwarded in a list using a multipath route must not reuse a
2493
+ # cached result so that a flow always hits the same nexthop. In other
2494
+ # words, the FIB lookup tracepoint needs to be triggered for every
2495
+ # packet.
2496
+ local t0_rx_pkts=$( link_stats_get ns2 veth2 rx packets)
2497
+ run_cmd " perf stat -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd "
2498
+ local t1_rx_pkts=$( link_stats_get ns2 veth2 rx packets)
2499
+ local diff=$( echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
2500
+ list_rcv_eval $tmp_file $diff
2501
+
2502
+ rm $tmp_file
2503
+ route_cleanup
2504
+ }
2505
+
2355
2506
# ###############################################################################
2356
2507
# usage
2357
2508
2433
2584
ipv6_mangle) ipv6_mangle_test;;
2434
2585
ipv4_bcast_neigh) ipv4_bcast_neigh_test;;
2435
2586
fib6_gc_test|ipv6_gc) fib6_gc_test;;
2587
+ ipv4_mpath_list) ipv4_mpath_list_test;;
2588
+ ipv6_mpath_list) ipv6_mpath_list_test;;
2436
2589
2437
2590
help) echo " Test names: $TESTS " ; exit 0;;
2438
2591
esac
0 commit comments