2 # SPDX-License-Identifier: GPL-2.0
4 # OVS kernel module self tests
6 trap ovs_exit_sig EXIT TERM INT ERR
8 # Kselftest framework requirement - SKIP code is 4.
16 if test "X$KSFT_MACHINE_SLOW" == "Xyes"; then
21 arp_ping eth-arp: Basic arp ping between two NS
22 ct_connect_v4 ip4-ct-xon: Basic ipv4 tcp connection using ct
23 connect_v4 ip4-xon: Basic ipv4 ping between two NS
24 nat_connect_v4 ip4-nat-xon: Basic ipv4 tcp connection via NAT
25 nat_related_v4 ip4-nat-related: ICMP related matches work with SNAT
26 netlink_checks ovsnl: validate netlink attrs and settings
27 upcall_interfaces ovs: test the upcall interfaces
28 drop_reason drop: test drop reasons are emitted
29 psample psample: Sampling packets with psample"
32 [ "${ovs_dir}" != "" ] &&
33 echo "`date +"[%m-%d %H:%M:%S]"` $*" >> ${ovs_dir}/debug.log
34 [ $VERBOSE = 0 ] || echo $*
38 info "waiting $WAIT_TIMEOUT s for: $@"
41 info "wait succeeded immediately"
45 # A quick re-check helps speed up small races in fast systems.
46 # However, fractional sleeps might not necessarily work.
48 sleep 0.1 || { sleep 1; start=1; }
50 for (( i=start; i<WAIT_TIMEOUT; i++ )); do
52 info "wait succeeded after $i seconds"
57 info "wait failed after $i seconds"
64 info "adding sandbox '$1'"
71 local d="$ovs_base"/$1
76 mkdir "$d" || return 1
81 [ -e ${ovs_dir}/cleanup ] && . "$ovs_dir/cleanup"
85 echo "$1" > ${ovs_dir}/cleanup.tmp
86 cat ${ovs_dir}/cleanup >> ${ovs_dir}/cleanup.tmp
87 mv ${ovs_dir}/cleanup.tmp ${ovs_dir}/cleanup
93 ovs_dir=$ovs_base${1:+/$1}; export ovs_dir
95 test -e ${ovs_dir}/cleanup || : > ${ovs_dir}/cleanup
99 if test "X$2" != X; then
100 (ovs_setenv $1; shift;
101 info "run cmd: $@"; "$@" >> ${ovs_dir}/debug.log)
108 info "Adding DP/Bridge IF: sbx:$1 dp:$2 {$3, $4, $5}"
111 ovs_sbx "$sbxname" python3 $ovs_base/ovs-dpctl.py add-dp $*
112 on_exit "ovs_sbx $sbxname python3 $ovs_base/ovs-dpctl.py del-dp $1;"
116 info "Adding IF to DP: br:$2 if:$3"
117 if [ "$4" != "-u" ]; then
118 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if "$2" "$3" \
121 python3 $ovs_base/ovs-dpctl.py add-if \
122 -u "$2" "$3" >$ovs_dir/$3.out 2>$ovs_dir/$3.err &
124 on_exit "ovs_sbx $1 kill -TERM $pid 2>/dev/null"
129 info "Deleting IF from DP: br:$2 if:$3"
130 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-if "$2" "$3" || return 1
133 ovs_netns_spawn_daemon() {
138 if [ "$netns" == "_default" ]; then
139 $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &
141 ip netns exec $netns $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &
144 ovs_sbx "$sbx" on_exit "kill -TERM $pid 2>/dev/null"
150 ovs_netns_spawn_daemon $sbx "_default" $*
153 ovs_add_netns_and_veths () {
154 info "Adding netns attached: sbx:$1 dp:$2 {$3, $4, $5}"
155 ovs_sbx "$1" ip netns add "$3" || return 1
156 on_exit "ovs_sbx $1 ip netns del $3"
157 ovs_sbx "$1" ip link add "$4" type veth peer name "$5" || return 1
158 on_exit "ovs_sbx $1 ip link del $4 >/dev/null 2>&1"
159 ovs_sbx "$1" ip link set "$4" up || return 1
160 ovs_sbx "$1" ip link set "$5" netns "$3" || return 1
161 ovs_sbx "$1" ip netns exec "$3" ip link set "$5" up || return 1
163 if [ "$6" != "" ]; then
164 ovs_sbx "$1" ip netns exec "$3" ip addr add "$6" dev "$5" \
168 if [ "$7" != "-u" ]; then
169 ovs_add_if "$1" "$2" "$4" || return 1
171 ovs_add_if "$1" "$2" "$4" -u || return 1
174 if [ $TRACING -eq 1 ]; then
175 ovs_netns_spawn_daemon "$1" "$3" tcpdump -l -i any -s 6553
176 ovs_wait grep -q "listening on any" ${ovs_dir}/stderr
183 info "Adding flow to DP: sbx:$1 br:$2 flow:$3 act:$4"
184 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-flow "$2" "$3" "$4"
185 if [ $? -ne 0 ]; then
186 info "Flow [ $3 : $4 ] failed"
193 info "Deleting all flows from DP: sbx:$1 br:$2"
194 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-flows "$2"
198 ovs_drop_record_and_run () {
202 perf record -a -q -e skb:kfree_skb -o ${ovs_dir}/perf.data $* \
203 >> ${ovs_dir}/stdout 2>> ${ovs_dir}/stderr
207 ovs_drop_reason_count()
211 local perf_output=`perf script -i ${ovs_dir}/perf.data -F trace:event,trace`
212 local pattern="skb:kfree_skb:.*reason: $reason"
214 return `echo "$perf_output" | grep "$pattern" | wc -l`
217 ovs_test_flow_fails () {
218 ERR_MSG="Flow actions may not be safe on all matching packets"
220 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
221 ovs_add_flow $@ &> /dev/null $@ && return 1
222 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
224 if [ "$PRE_TEST" == "$POST_TEST" ]; then
232 echo "$0 [OPTIONS] [TEST]..."
233 echo "If no TEST argument is given, all tests will be run."
236 echo " -t: capture traffic via tcpdump"
238 echo " -p: pause on failure"
240 echo "Available tests${tests}"
246 # - use psample to observe packets
248 sbx_add "test_psample" || return $?
250 # Add a datapath with per-vport dispatching.
251 ovs_add_dp "test_psample" psample -V 2:1 || return 1
253 info "create namespaces"
254 ovs_add_netns_and_veths "test_psample" "psample" \
255 client c0 c1 172.31.110.10/24 -u || return 1
256 ovs_add_netns_and_veths "test_psample" "psample" \
257 server s0 s1 172.31.110.20/24 -u || return 1
259 # Check if psample actions can be configured.
260 ovs_add_flow "test_psample" psample \
261 'in_port(1),eth(),eth_type(0x0806),arp()' 'psample(group=1)' &> /dev/null
263 info "no support for psample - skipping"
268 ovs_del_flows "test_psample" psample
270 # Test action verification.
273 min_key='in_port(1),eth(),eth_type(0x0800),ipv4()'
275 "cookie to large"*"psample(group=1,cookie=1615141312111009080706050403020100)" \
276 "no group with cookie"*"psample(cookie=abcd)" \
277 "no group"*"psample()";
280 ovs_test_flow_fails "test_psample" psample $min_key $2
288 ovs_del_flows "test_psample" psample
290 ovs_add_flow "test_psample" psample \
291 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
292 ovs_add_flow "test_psample" psample \
293 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
295 # Sample first 14 bytes of all traffic.
296 ovs_add_flow "test_psample" psample \
297 "in_port(1),eth(),eth_type(0x0800),ipv4()" \
298 "trunc(14),psample(group=1,cookie=c0ffee),2"
300 # Sample all traffic. In this case, use a sample() action with both
301 # psample and an upcall emulating simultaneous local sampling and
303 nlpid=$(grep -E "listening on upcall packet handler" \
304 $ovs_dir/s0.out | cut -d ":" -f 2 | tr -d ' ')
306 ovs_add_flow "test_psample" psample \
307 "in_port(2),eth(),eth_type(0x0800),ipv4()" \
308 "sample(sample=100%,actions(psample(group=2,cookie=eeff0c),userspace(pid=${nlpid},userdata=eeff0c))),1"
310 # Record psample data.
311 ovs_spawn_daemon "test_psample" python3 $ovs_base/ovs-dpctl.py psample-events
312 ovs_wait grep -q "listening for psample events" ${ovs_dir}/stdout
314 # Send a single ping.
315 ovs_sbx "test_psample" ip netns exec client ping -I c1 172.31.110.20 -c 1 || return 1
317 # We should have received one userspace action upcall and 2 psample packets.
318 ovs_wait grep -q "userspace action command" $ovs_dir/s0.out || return 1
320 # client -> server samples should only contain the first 14 bytes of the packet.
321 ovs_wait grep -qE "rate:4294967295,group:1,cookie:c0ffee data:[0-9a-f]{28}$" \
322 $ovs_dir/stdout || return 1
324 ovs_wait grep -q "rate:4294967295,group:2,cookie:eeff0c" $ovs_dir/stdout || return 1
330 # - drop packets and verify the right drop reason is reported
332 which perf >/dev/null 2>&1 || return $ksft_skip
334 sbx_add "test_drop_reason" || return $?
336 ovs_add_dp "test_drop_reason" dropreason || return 1
338 info "create namespaces"
339 for ns in client server; do
340 ovs_add_netns_and_veths "test_drop_reason" "dropreason" "$ns" \
341 "${ns:0:1}0" "${ns:0:1}1" || return 1
344 # Setup client namespace
345 ip netns exec client ip addr add 172.31.110.10/24 dev c1
346 ip netns exec client ip link set c1 up
348 # Setup server namespace
349 ip netns exec server ip addr add 172.31.110.20/24 dev s1
350 ip netns exec server ip link set s1 up
352 # Check if drop reasons can be sent
353 ovs_add_flow "test_drop_reason" dropreason \
354 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(10)' 2>/dev/null
356 info "no support for drop reasons - skipping"
361 ovs_del_flows "test_drop_reason" dropreason
364 ovs_add_flow "test_drop_reason" dropreason \
365 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
366 ovs_add_flow "test_drop_reason" dropreason \
367 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
369 # Allow client ICMP traffic but drop return path
370 ovs_add_flow "test_drop_reason" dropreason \
371 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=1),icmp()" '2'
372 ovs_add_flow "test_drop_reason" dropreason \
373 "in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20,proto=1),icmp()" 'drop'
375 ovs_drop_record_and_run "test_drop_reason" ip netns exec client ping -c 2 172.31.110.20
376 ovs_drop_reason_count 0x30001 # OVS_DROP_FLOW_ACTION
377 if [[ "$?" -ne "2" ]]; then
378 info "Did not detect expected drops: $?"
382 # Drop UDP 6000 traffic with an explicit action and an error code.
383 ovs_add_flow "test_drop_reason" dropreason \
384 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=17),udp(dst=6000)" \
386 # Drop UDP 7000 traffic with an explicit action with no error code.
387 ovs_add_flow "test_drop_reason" dropreason \
388 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=17),udp(dst=7000)" \
391 ovs_drop_record_and_run \
392 "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 6000
393 ovs_drop_reason_count 0x30004 # OVS_DROP_EXPLICIT_ACTION_ERROR
394 if [[ "$?" -ne "1" ]]; then
395 info "Did not detect expected explicit error drops: $?"
399 ovs_drop_record_and_run \
400 "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 7000
401 ovs_drop_reason_count 0x30003 # OVS_DROP_EXPLICIT_ACTION
402 if [[ "$?" -ne "1" ]]; then
403 info "Did not detect expected explicit drops: $?"
411 # - client has 1500 byte MTU
412 # - server has 1500 byte MTU
413 # - send ARP ping between two ns
416 which arping >/dev/null 2>&1 || return $ksft_skip
418 sbx_add "test_arp_ping" || return $?
420 ovs_add_dp "test_arp_ping" arpping || return 1
422 info "create namespaces"
423 for ns in client server; do
424 ovs_add_netns_and_veths "test_arp_ping" "arpping" "$ns" \
425 "${ns:0:1}0" "${ns:0:1}1" || return 1
428 # Setup client namespace
429 ip netns exec client ip addr add 172.31.110.10/24 dev c1
430 ip netns exec client ip link set c1 up
431 HW_CLIENT=`ip netns exec client ip link show dev c1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
432 info "Client hwaddr: $HW_CLIENT"
434 # Setup server namespace
435 ip netns exec server ip addr add 172.31.110.20/24 dev s1
436 ip netns exec server ip link set s1 up
437 HW_SERVER=`ip netns exec server ip link show dev s1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
438 info "Server hwaddr: $HW_SERVER"
440 ovs_add_flow "test_arp_ping" arpping \
441 "in_port(1),eth(),eth_type(0x0806),arp(sip=172.31.110.10,tip=172.31.110.20,sha=$HW_CLIENT,tha=ff:ff:ff:ff:ff:ff)" '2' || return 1
442 ovs_add_flow "test_arp_ping" arpping \
443 "in_port(2),eth(),eth_type(0x0806),arp()" '1' || return 1
445 ovs_sbx "test_arp_ping" ip netns exec client arping -I c1 172.31.110.20 -c 1 || return 1
451 # - client has 1500 byte MTU
452 # - server has 1500 byte MTU
453 # - use ICMP to ping in each direction
454 # - only allow CT state stuff to pass through new in c -> s
455 test_ct_connect_v4 () {
457 which nc >/dev/null 2>/dev/null || return $ksft_skip
459 sbx_add "test_ct_connect_v4" || return $?
461 ovs_add_dp "test_ct_connect_v4" ct4 || return 1
462 info "create namespaces"
463 for ns in client server; do
464 ovs_add_netns_and_veths "test_ct_connect_v4" "ct4" "$ns" \
465 "${ns:0:1}0" "${ns:0:1}1" || return 1
468 ip netns exec client ip addr add 172.31.110.10/24 dev c1
469 ip netns exec client ip link set c1 up
470 ip netns exec server ip addr add 172.31.110.20/24 dev s1
471 ip netns exec server ip link set s1 up
473 # Add forwarding for ARP and ip packets - completely wildcarded
474 ovs_add_flow "test_ct_connect_v4" ct4 \
475 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
476 ovs_add_flow "test_ct_connect_v4" ct4 \
477 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
478 ovs_add_flow "test_ct_connect_v4" ct4 \
479 'ct_state(-trk),eth(),eth_type(0x0800),ipv4()' \
480 'ct(commit),recirc(0x1)' || return 1
481 ovs_add_flow "test_ct_connect_v4" ct4 \
482 'recirc_id(0x1),ct_state(+trk+new),in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' \
484 ovs_add_flow "test_ct_connect_v4" ct4 \
485 'recirc_id(0x1),ct_state(+trk+est),in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' \
487 ovs_add_flow "test_ct_connect_v4" ct4 \
488 'recirc_id(0x1),ct_state(+trk+est),in_port(2),eth(),eth_type(0x0800),ipv4(dst=172.31.110.10)' \
490 ovs_add_flow "test_ct_connect_v4" ct4 \
491 'recirc_id(0x1),ct_state(+trk+inv),eth(),eth_type(0x0800),ipv4()' 'drop' || \
495 ovs_sbx "test_ct_connect_v4" ip netns exec client ping 172.31.110.20 -c 3 || return 1
497 # create an echo server in 'server'
499 ovs_netns_spawn_daemon "test_ct_connect_v4" "server" \
501 ovs_sbx "test_ct_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.20 4443 || return 1
503 # Now test in the other direction (should fail)
505 ovs_netns_spawn_daemon "test_ct_connect_v4" "client" \
507 ovs_sbx "test_ct_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.10 4443
509 info "ct connect to client was successful"
518 # - client has 1500 byte MTU
519 # - server has 1500 byte MTU
520 # - use ICMP to ping in each direction
523 sbx_add "test_connect_v4" || return $?
525 ovs_add_dp "test_connect_v4" cv4 || return 1
527 info "create namespaces"
528 for ns in client server; do
529 ovs_add_netns_and_veths "test_connect_v4" "cv4" "$ns" \
530 "${ns:0:1}0" "${ns:0:1}1" || return 1
534 ip netns exec client ip addr add 172.31.110.10/24 dev c1
535 ip netns exec client ip link set c1 up
536 ip netns exec server ip addr add 172.31.110.20/24 dev s1
537 ip netns exec server ip link set s1 up
539 # Add forwarding for ARP and ip packets - completely wildcarded
540 ovs_add_flow "test_connect_v4" cv4 \
541 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
542 ovs_add_flow "test_connect_v4" cv4 \
543 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
544 ovs_add_flow "test_connect_v4" cv4 \
545 'in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' '2' || return 1
546 ovs_add_flow "test_connect_v4" cv4 \
547 'in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20)' '1' || return 1
550 ovs_sbx "test_connect_v4" ip netns exec client ping 172.31.110.20 -c 3 || return 1
556 # nat_connect_v4 test
557 # - client has 1500 byte MTU
558 # - server has 1500 byte MTU
559 # - use ICMP to ping in each direction
560 # - only allow CT state stuff to pass through new in c -> s
561 test_nat_connect_v4 () {
562 which nc >/dev/null 2>/dev/null || return $ksft_skip
564 sbx_add "test_nat_connect_v4" || return $?
566 ovs_add_dp "test_nat_connect_v4" nat4 || return 1
567 info "create namespaces"
568 for ns in client server; do
569 ovs_add_netns_and_veths "test_nat_connect_v4" "nat4" "$ns" \
570 "${ns:0:1}0" "${ns:0:1}1" || return 1
573 ip netns exec client ip addr add 172.31.110.10/24 dev c1
574 ip netns exec client ip link set c1 up
575 ip netns exec server ip addr add 172.31.110.20/24 dev s1
576 ip netns exec server ip link set s1 up
578 ip netns exec client ip route add default via 172.31.110.20
580 ovs_add_flow "test_nat_connect_v4" nat4 \
581 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
582 ovs_add_flow "test_nat_connect_v4" nat4 \
583 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
584 ovs_add_flow "test_nat_connect_v4" nat4 \
585 "ct_state(-trk),in_port(1),eth(),eth_type(0x0800),ipv4(dst=192.168.0.20)" \
586 "ct(commit,nat(dst=172.31.110.20)),recirc(0x1)"
587 ovs_add_flow "test_nat_connect_v4" nat4 \
588 "ct_state(-trk),in_port(2),eth(),eth_type(0x0800),ipv4()" \
589 "ct(commit,nat),recirc(0x2)"
591 ovs_add_flow "test_nat_connect_v4" nat4 \
592 "recirc_id(0x1),ct_state(+trk-inv),in_port(1),eth(),eth_type(0x0800),ipv4()" "2"
593 ovs_add_flow "test_nat_connect_v4" nat4 \
594 "recirc_id(0x2),ct_state(+trk-inv),in_port(2),eth(),eth_type(0x0800),ipv4()" "1"
597 ovs_sbx "test_nat_connect_v4" ip netns exec client ping 192.168.0.20 -c 3 || return 1
599 # create an echo server in 'server'
601 ovs_netns_spawn_daemon "test_nat_connect_v4" "server" \
603 ovs_sbx "test_nat_connect_v4" ip netns exec client nc -i 1 -zv 192.168.0.20 4443 || return 1
605 # Now test in the other direction (should fail)
607 ovs_netns_spawn_daemon "test_nat_connect_v4" "client" \
609 ovs_sbx "test_nat_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.10 4443
611 info "connect to client was successful"
619 # nat_related_v4 test
620 # - client->server ip packets go via SNAT
621 # - client solicits ICMP destination unreachable packet from server
622 # - undo NAT for ICMP reply and test dst ip has been updated
623 test_nat_related_v4 () {
624 which nc >/dev/null 2>/dev/null || return $ksft_skip
626 sbx_add "test_nat_related_v4" || return $?
628 ovs_add_dp "test_nat_related_v4" natrelated4 || return 1
629 info "create namespaces"
630 for ns in client server; do
631 ovs_add_netns_and_veths "test_nat_related_v4" "natrelated4" "$ns" \
632 "${ns:0:1}0" "${ns:0:1}1" || return 1
635 ip netns exec client ip addr add 172.31.110.10/24 dev c1
636 ip netns exec client ip link set c1 up
637 ip netns exec server ip addr add 172.31.110.20/24 dev s1
638 ip netns exec server ip link set s1 up
640 ip netns exec server ip route add 192.168.0.20/32 via 172.31.110.10
643 ovs_add_flow "test_nat_related_v4" natrelated4 \
644 "in_port(1),eth(),eth_type(0x0806),arp()" "2" || return 1
645 ovs_add_flow "test_nat_related_v4" natrelated4 \
646 "in_port(2),eth(),eth_type(0x0806),arp()" "1" || return 1
648 # Allow IP traffic from client->server, rewrite source IP with SNAT to 192.168.0.20
649 ovs_add_flow "test_nat_related_v4" natrelated4 \
650 "ct_state(-trk),in_port(1),eth(),eth_type(0x0800),ipv4(dst=172.31.110.20)" \
651 "ct(commit,nat(src=192.168.0.20)),recirc(0x1)" || return 1
652 ovs_add_flow "test_nat_related_v4" natrelated4 \
653 "recirc_id(0x1),ct_state(+trk-inv),in_port(1),eth(),eth_type(0x0800),ipv4()" \
656 # Allow related ICMP responses back from server and undo NAT to restore original IP
657 # Drop any ICMP related packets where dst ip hasn't been restored back to original IP
658 ovs_add_flow "test_nat_related_v4" natrelated4 \
659 "ct_state(-trk),in_port(2),eth(),eth_type(0x0800),ipv4()" \
660 "ct(commit,nat),recirc(0x2)" || return 1
661 ovs_add_flow "test_nat_related_v4" natrelated4 \
662 "recirc_id(0x2),ct_state(+rel+trk),in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20,dst=172.31.110.10,proto=1),icmp()" \
664 ovs_add_flow "test_nat_related_v4" natrelated4 \
665 "recirc_id(0x2),ct_state(+rel+trk),in_port(2),eth(),eth_type(0x0800),ipv4(dst=192.168.0.20,proto=1),icmp()" \
668 # Solicit destination unreachable response from server
669 ovs_sbx "test_nat_related_v4" ip netns exec client \
670 bash -c "echo a | nc -u -w 1 172.31.110.20 10000"
672 # Check to make sure no packets matched the drop rule with incorrect dst ip
673 python3 "$ovs_base/ovs-dpctl.py" dump-flows natrelated4 \
674 | grep "drop" | grep "packets:0" >/dev/null || return 1
682 # - check no warning with "old version" simulation
683 test_netlink_checks () {
684 sbx_add "test_netlink_checks" || return 1
686 info "setting up new DP"
687 ovs_add_dp "test_netlink_checks" nv0 || return 1
689 PRE_TEST=$(dmesg | grep -E "RIP: [0-9a-fA-Fx]+:ovs_dp_cmd_new\+")
690 ovs_add_dp "test_netlink_checks" nv0 -V 0 || return 1
691 POST_TEST=$(dmesg | grep -E "RIP: [0-9a-fA-Fx]+:ovs_dp_cmd_new\+")
692 if [ "$PRE_TEST" != "$POST_TEST" ]; then
693 info "failed - gen warning"
697 ovs_add_netns_and_veths "test_netlink_checks" nv0 left left0 l0 || \
699 ovs_add_netns_and_veths "test_netlink_checks" nv0 right right0 r0 || \
701 [ $(python3 $ovs_base/ovs-dpctl.py show nv0 | grep port | \
704 ovs_del_if "test_netlink_checks" nv0 right0 || return 1
705 [ $(python3 $ovs_base/ovs-dpctl.py show nv0 | grep port | \
709 info "Checking clone depth"
710 ERR_MSG="Flow actions may not be safe on all matching packets"
711 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
712 ovs_add_flow "test_netlink_checks" nv0 \
713 'in_port(1),eth(),eth_type(0x800),ipv4()' \
714 'clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(drop)))))))))))))))))' \
715 >/dev/null 2>&1 && return 1
716 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
718 if [ "$PRE_TEST" == "$POST_TEST" ]; then
719 info "failed - clone depth too large"
723 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
724 ovs_add_flow "test_netlink_checks" nv0 \
725 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(0),2' \
726 &> /dev/null && return 1
727 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
728 if [ "$PRE_TEST" == "$POST_TEST" ]; then
729 info "failed - error not generated"
735 test_upcall_interfaces() {
736 sbx_add "test_upcall_interfaces" || return 1
738 info "setting up new DP"
739 ovs_add_dp "test_upcall_interfaces" ui0 -V 2:1 || return 1
741 ovs_add_netns_and_veths "test_upcall_interfaces" ui0 upc left0 l0 \
742 172.31.110.1/24 -u || return 1
744 ovs_wait grep -q "listening on upcall packet handler" ${ovs_dir}/left0.out
746 info "sending arping"
747 ip netns exec upc arping -I l0 172.31.110.20 -c 1 \
748 >$ovs_dir/arping.stdout 2>$ovs_dir/arping.stderr
750 grep -E "MISS upcall\[0/yes\]: .*arp\(sip=172.31.110.1,tip=172.31.110.20,op=1,sha=" $ovs_dir/left0.out >/dev/null 2>&1 || return 1
759 if python3 ovs-dpctl.py -h 2>&1 | \
760 grep -E "Need to (install|upgrade) the python" >/dev/null 2>&1; then
761 stdbuf -o0 printf "TEST: %-60s [PYLIB]\n" "${tdesc}"
765 python3 ovs-dpctl.py show >/dev/null 2>&1 || \
766 echo "[DPCTL] show exception."
768 if ! lsmod | grep openvswitch >/dev/null 2>&1; then
769 stdbuf -o0 printf "TEST: %-60s [NOMOD]\n" "${tdesc}"
773 printf "TEST: %-60s [START]\n" "${tname}"
780 if [ $ret -eq 0 ]; then
781 printf "TEST: %-60s [ OK ]\n" "${tdesc}"
784 elif [ $ret -eq 1 ]; then
785 printf "TEST: %-60s [FAIL]\n" "${tdesc}"
786 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
788 echo "Pausing. Logs in $ovs_dir/. Hit enter to continue"
792 [ "${PAUSE_ON_FAIL}" = "yes" ] || rm -rf "$ovs_dir"
794 elif [ $ret -eq $ksft_skip ]; then
795 printf "TEST: %-60s [SKIP]\n" "${tdesc}"
796 elif [ $ret -eq 2 ]; then
806 [ $all_skipped = true ] && [ $exitcode=$ksft_skip ] && exitcode=0
810 [ $all_skipped = true ] && exitcode=$ksft_skip
829 p) PAUSE_ON_FAIL=yes;;
831 t) if which tcpdump > /dev/null 2>&1; then
834 echo "=== tcpdump not available, tracing disabled"
846 # Check first that all requested tests are available before running any
847 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
852 for t in ${tests}; do
853 [ "${name}" = "" ] && name="${t}" && continue
854 [ "${desc}" = "" ] && desc="${t}"
858 [ "${arg}" != "${arg#--*}" ] && continue
859 [ "${arg}" = "${name}" ] && run_this=1 && break
862 if [ $run_this -eq 1 ]; then
863 run_test "${name}" "${desc}"