xref: /linux/tools/testing/selftests/drivers/net/netdevsim/udp_tunnel_nic.sh (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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    ip link set dev $NSIM_NETDEV up
274
275    msg="new NIC device created"
276    exp0=( 0 0 0 0 )
277    exp1=( 0 0 0 0 )
278    check_tables
279
280    msg="VxLAN v4 devices"
281    exp0=( `mke 4789 1` 0 0 0 )
282    new_vxlan vxlan0 4789 $NSIM_NETDEV
283    new_vxlan vxlan1 4789 $NSIM_NETDEV
284
285    msg="VxLAN v4 devices go down"
286    exp0=( 0 0 0 0 )
287    ip link set dev vxlan1 down
288    ip link set dev vxlan0 down
289    check_tables
290
291    msg="VxLAN v6 devices"
292    exp0=( `mke 4789 1` 0 0 0 )
293    new_vxlan vxlanA 4789 $NSIM_NETDEV 6
294
295    for ifc in vxlan0 vxlan1; do
296	ip link set dev $ifc up
297    done
298
299    new_vxlan vxlanB 4789 $NSIM_NETDEV 6
300
301    msg="another VxLAN v6 devices"
302    exp0=( `mke 4789 1` `mke 4790 1` 0 0 )
303    new_vxlan vxlanC 4790 $NSIM_NETDEV 6
304
305    msg="Geneve device"
306    exp1=( `mke 6081 2` 0 0 0 )
307    new_geneve gnv0 6081
308
309    msg="NIC device goes down"
310    ip link set dev $NSIM_NETDEV down
311    if [ $port -eq 1 ]; then
312	exp0=( 0 0 0 0 )
313	exp1=( 0 0 0 0 )
314    fi
315    check_tables
316    msg="NIC device goes up again"
317    ip link set dev $NSIM_NETDEV up
318    exp0=( `mke 4789 1` `mke 4790 1` 0 0 )
319    exp1=( `mke 6081 2` 0 0 0 )
320    check_tables
321
322    cleanup_tuns
323
324    msg="tunnels destroyed"
325    exp0=( 0 0 0 0 )
326    exp1=( 0 0 0 0 )
327    check_tables
328
329    modprobe -r geneve
330    modprobe -r vxlan
331    modprobe -r udp_tunnel
332
333    check_tables
334done
335
336modprobe -r netdevsim
337
338# Module tests
339pfx="module tests"
340
341if modinfo netdevsim | grep udp_tunnel >/dev/null; then
342    err_cnt "netdevsim depends on udp_tunnel"
343else
344    pass_cnt
345fi
346
347modprobe netdevsim
348
349old_netdevs=$(ls /sys/class/net)
350port=0
351echo $NSIM_ID > /sys/bus/netdevsim/new_device
352echo 0 > $NSIM_DEV_SYS/del_port
353echo 1000 > $NSIM_DEV_DFS/udp_ports_sleep
354echo 0 > $NSIM_DEV_SYS/new_port
355NSIM_NETDEV=`get_netdev_name old_netdevs`
356
357msg="create VxLANs"
358exp0=( 0 0 0 0 ) # sleep is longer than out wait
359new_vxlan vxlan0 10000 $NSIM_NETDEV
360
361modprobe -r vxlan
362modprobe -r udp_tunnel
363
364msg="remove tunnels"
365exp0=( 0 0 0 0 )
366check_tables
367
368msg="create VxLANs"
369exp0=( 0 0 0 0 ) # sleep is longer than out wait
370new_vxlan vxlan0 10000 $NSIM_NETDEV
371
372exp0=( 0 0 0 0 )
373
374modprobe -r netdevsim
375modprobe netdevsim
376
377# Overflow the table
378
379function overflow_table0 {
380    local pfx=$1
381
382    msg="create VxLANs 1/5"
383    exp0=( `mke 10000 1` 0 0 0 )
384    new_vxlan vxlan0 10000 $NSIM_NETDEV
385
386    msg="create VxLANs 2/5"
387    exp0=( `mke 10000 1` `mke 10001 1` 0 0 )
388    new_vxlan vxlan1 10001 $NSIM_NETDEV
389
390    msg="create VxLANs 3/5"
391    exp0=( `mke 10000 1` `mke 10001 1` `mke 10002 1` 0 )
392    new_vxlan vxlan2 10002 $NSIM_NETDEV
393
394    msg="create VxLANs 4/5"
395    exp0=( `mke 10000 1` `mke 10001 1` `mke 10002 1` `mke 10003 1` )
396    new_vxlan vxlan3 10003 $NSIM_NETDEV
397
398    msg="create VxLANs 5/5"
399    new_vxlan vxlan4 10004 $NSIM_NETDEV
400}
401
402function overflow_table1 {
403    local pfx=$1
404
405    msg="create GENEVE 1/5"
406    exp1=( `mke 20000 2` 0 0 0 )
407    new_geneve gnv0 20000
408
409    msg="create GENEVE 2/5"
410    exp1=( `mke 20000 2` `mke 20001 2` 0 0 )
411    new_geneve gnv1 20001
412
413    msg="create GENEVE 3/5"
414    exp1=( `mke 20000 2` `mke 20001 2` `mke 20002 2` 0 )
415    new_geneve gnv2 20002
416
417    msg="create GENEVE 4/5"
418    exp1=( `mke 20000 2` `mke 20001 2` `mke 20002 2` `mke 20003 2` )
419    new_geneve gnv3 20003
420
421    msg="create GENEVE 5/5"
422    new_geneve gnv4 20004
423}
424
425echo $NSIM_ID > /sys/bus/netdevsim/new_device
426echo 0 > $NSIM_DEV_SYS/del_port
427
428for port in 0 1; do
429    if [ $port -ne 0 ]; then
430	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
431	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
432    fi
433
434    echo $port > $NSIM_DEV_SYS/new_port
435    NSIM_NETDEV=`get_netdev_name old_netdevs`
436    ip link set dev $NSIM_NETDEV up
437
438    overflow_table0 "overflow NIC table"
439    overflow_table1 "overflow NIC table"
440
441    msg="replace VxLAN in overflow table"
442    exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` )
443    del_dev vxlan1
444
445    msg="vacate VxLAN in overflow table"
446    exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` )
447    del_dev vxlan2
448
449    msg="replace GENEVE in overflow table"
450    exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` )
451    del_dev gnv1
452
453    msg="vacate GENEVE in overflow table"
454    exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` )
455    del_dev gnv2
456
457    msg="table sharing - share"
458    exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` )
459    new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external"
460
461    msg="table sharing - overflow"
462    new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external"
463    msg="table sharing - overflow v6"
464    new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external"
465
466    exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` )
467    del_dev gnv4
468
469    msg="destroy NIC"
470    echo $port > $NSIM_DEV_SYS/del_port
471
472    cleanup_tuns
473    exp0=( 0 0 0 0 )
474    exp1=( 0 0 0 0 )
475done
476
477cleanup_nsim
478
479# Sync all
480pfx="sync all"
481
482echo $NSIM_ID > /sys/bus/netdevsim/new_device
483echo 0 > $NSIM_DEV_SYS/del_port
484echo 1 > $NSIM_DEV_DFS/udp_ports_sync_all
485
486for port in 0 1; do
487    if [ $port -ne 0 ]; then
488	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
489	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
490    fi
491
492    echo $port > $NSIM_DEV_SYS/new_port
493    NSIM_NETDEV=`get_netdev_name old_netdevs`
494    ip link set dev $NSIM_NETDEV up
495
496    overflow_table0 "overflow NIC table"
497    overflow_table1 "overflow NIC table"
498
499    msg="replace VxLAN in overflow table"
500    exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` )
501    del_dev vxlan1
502
503    msg="vacate VxLAN in overflow table"
504    exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` )
505    del_dev vxlan2
506
507    msg="replace GENEVE in overflow table"
508    exp1=( `mke 20000 2` `mke 20004 2` `mke 20002 2` `mke 20003 2` )
509    del_dev gnv1
510
511    msg="vacate GENEVE in overflow table"
512    exp1=( `mke 20000 2` `mke 20004 2` 0 `mke 20003 2` )
513    del_dev gnv2
514
515    msg="table sharing - share"
516    exp1=( `mke 20000 2` `mke 20004 2` `mke 30001 4` `mke 20003 2` )
517    new_vxlan vxlanG0 30001 $NSIM_NETDEV 4 "gpe external"
518
519    msg="table sharing - overflow"
520    new_vxlan vxlanG1 30002 $NSIM_NETDEV 4 "gpe external"
521    msg="table sharing - overflow v6"
522    new_vxlan vxlanG2 30002 $NSIM_NETDEV 6 "gpe external"
523
524    exp1=( `mke 20000 2` `mke 30002 4` `mke 30001 4` `mke 20003 2` )
525    del_dev gnv4
526
527    msg="destroy NIC"
528    echo $port > $NSIM_DEV_SYS/del_port
529
530    cleanup_tuns
531    exp0=( 0 0 0 0 )
532    exp1=( 0 0 0 0 )
533done
534
535cleanup_nsim
536
537# Destroy full NIC
538pfx="destroy full"
539
540echo $NSIM_ID > /sys/bus/netdevsim/new_device
541echo 0 > $NSIM_DEV_SYS/del_port
542
543for port in 0 1; do
544    if [ $port -ne 0 ]; then
545	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
546	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
547    fi
548
549    echo $port > $NSIM_DEV_SYS/new_port
550    NSIM_NETDEV=`get_netdev_name old_netdevs`
551    ip link set dev $NSIM_NETDEV up
552
553    overflow_table0 "destroy NIC"
554    overflow_table1 "destroy NIC"
555
556    msg="destroy NIC"
557    echo $port > $NSIM_DEV_SYS/del_port
558
559    cleanup_tuns
560    exp0=( 0 0 0 0 )
561    exp1=( 0 0 0 0 )
562done
563
564cleanup_nsim
565
566# IPv4 only
567pfx="IPv4 only"
568
569echo $NSIM_ID > /sys/bus/netdevsim/new_device
570echo 0 > $NSIM_DEV_SYS/del_port
571echo 1 > $NSIM_DEV_DFS/udp_ports_ipv4_only
572
573for port in 0 1; do
574    if [ $port -ne 0 ]; then
575	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
576	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
577    fi
578
579    echo $port > $NSIM_DEV_SYS/new_port
580    NSIM_NETDEV=`get_netdev_name old_netdevs`
581    ip link set dev $NSIM_NETDEV up
582
583    msg="create VxLANs v6"
584    new_vxlan vxlanA0 10000 $NSIM_NETDEV 6
585
586    msg="create VxLANs v6"
587    new_vxlan vxlanA1 10000 $NSIM_NETDEV 6
588
589    ip link set dev vxlanA0 down
590    ip link set dev vxlanA0 up
591    check_tables
592
593    msg="create VxLANs v4"
594    exp0=( `mke 10000 1` 0 0 0 )
595    new_vxlan vxlan0 10000 $NSIM_NETDEV
596
597    msg="down VxLANs v4"
598    exp0=( 0 0 0 0 )
599    ip link set dev vxlan0 down
600    check_tables
601
602    msg="up VxLANs v4"
603    exp0=( `mke 10000 1` 0 0 0 )
604    ip link set dev vxlan0 up
605    check_tables
606
607    msg="destroy VxLANs v4"
608    exp0=( 0 0 0 0 )
609    del_dev vxlan0
610
611    msg="recreate VxLANs v4"
612    exp0=( `mke 10000 1` 0 0 0 )
613    new_vxlan vxlan0 10000 $NSIM_NETDEV
614
615    del_dev vxlanA0
616    del_dev vxlanA1
617
618    msg="destroy NIC"
619    echo $port > $NSIM_DEV_SYS/del_port
620
621    cleanup_tuns
622    exp0=( 0 0 0 0 )
623    exp1=( 0 0 0 0 )
624done
625
626cleanup_nsim
627
628# Failures
629pfx="error injection"
630
631echo $NSIM_ID > /sys/bus/netdevsim/new_device
632echo 0 > $NSIM_DEV_SYS/del_port
633
634for port in 0 1; do
635    if [ $port -ne 0 ]; then
636	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
637	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
638    fi
639
640    echo $port > $NSIM_DEV_SYS/new_port
641    NSIM_NETDEV=`get_netdev_name old_netdevs`
642    ip link set dev $NSIM_NETDEV up
643
644    echo 110 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error
645
646    msg="1 - create VxLANs v6"
647    exp0=( 0 0 0 0 )
648    new_vxlan vxlanA0 10000 $NSIM_NETDEV 6
649
650    msg="1 - create VxLANs v4"
651    exp0=( `mke 10000 1` 0 0 0 )
652    new_vxlan vxlan0 10000 $NSIM_NETDEV
653
654    msg="1 - remove VxLANs v4"
655    del_dev vxlan0
656
657    msg="1 - remove VxLANs v6"
658    exp0=( 0 0 0 0 )
659    del_dev vxlanA0
660
661    msg="2 - create GENEVE"
662    exp1=( `mke 20000 2` 0 0 0 )
663    new_geneve gnv0 20000
664
665    msg="2 - destroy GENEVE"
666    echo 2 > $NSIM_DEV_DFS/ports/$port/udp_ports_inject_error
667    exp1=( `mke 20000 2` 0 0 0 )
668    del_dev gnv0
669
670    msg="2 - create second GENEVE"
671    exp1=( 0 `mke 20001 2` 0 0 )
672    new_geneve gnv0 20001
673
674    msg="destroy NIC"
675    echo $port > $NSIM_DEV_SYS/del_port
676
677    cleanup_tuns
678    exp0=( 0 0 0 0 )
679    exp1=( 0 0 0 0 )
680done
681
682cleanup_nsim
683
684# netdev flags
685pfx="netdev flags"
686
687echo $NSIM_ID > /sys/bus/netdevsim/new_device
688echo 0 > $NSIM_DEV_SYS/del_port
689
690for port in 0 1; do
691    if [ $port -ne 0 ]; then
692	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
693	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
694    fi
695
696    echo $port > $NSIM_DEV_SYS/new_port
697    NSIM_NETDEV=`get_netdev_name old_netdevs`
698    ip link set dev $NSIM_NETDEV up
699
700    msg="create VxLANs v6"
701    exp0=( `mke 10000 1` 0 0 0 )
702    new_vxlan vxlanA0 10000 $NSIM_NETDEV 6
703
704    msg="create VxLANs v4"
705    new_vxlan vxlan0 10000 $NSIM_NETDEV
706
707    msg="turn off"
708    exp0=( 0 0 0 0 )
709    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off
710    check_tables
711
712    msg="turn on"
713    exp0=( `mke 10000 1` 0 0 0 )
714    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on
715    check_tables
716
717    msg="remove both"
718    del_dev vxlanA0
719    exp0=( 0 0 0 0 )
720    del_dev vxlan0
721    check_tables
722
723    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off
724
725    msg="create VxLANs v4 - off"
726    exp0=( 0 0 0 0 )
727    new_vxlan vxlan0 10000 $NSIM_NETDEV
728
729    msg="created off - turn on"
730    exp0=( `mke 10000 1` 0 0 0 )
731    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on
732    check_tables
733
734    msg="destroy NIC"
735    echo $port > $NSIM_DEV_SYS/del_port
736
737    cleanup_tuns
738    exp0=( 0 0 0 0 )
739    exp1=( 0 0 0 0 )
740done
741
742cleanup_nsim
743
744# device initiated reset
745pfx="reset notification"
746
747echo $NSIM_ID > /sys/bus/netdevsim/new_device
748echo 0 > $NSIM_DEV_SYS/del_port
749
750for port in 0 1; do
751    if [ $port -ne 0 ]; then
752	echo 1 > $NSIM_DEV_DFS/udp_ports_open_only
753	echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
754    fi
755
756    echo $port > $NSIM_DEV_SYS/new_port
757    NSIM_NETDEV=`get_netdev_name old_netdevs`
758    ip link set dev $NSIM_NETDEV up
759
760    msg="create VxLANs v6"
761    exp0=( `mke 10000 1` 0 0 0 )
762    new_vxlan vxlanA0 10000 $NSIM_NETDEV 6
763
764    msg="create VxLANs v4"
765    new_vxlan vxlan0 10000 $NSIM_NETDEV
766
767    echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset
768    check_tables
769
770    msg="NIC device goes down"
771    ip link set dev $NSIM_NETDEV down
772    if [ $port -eq 1 ]; then
773	exp0=( 0 0 0 0 )
774	exp1=( 0 0 0 0 )
775    fi
776    check_tables
777
778    echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset
779    check_tables
780
781    msg="NIC device goes up again"
782    ip link set dev $NSIM_NETDEV up
783    exp0=( `mke 10000 1` 0 0 0 )
784    check_tables
785
786    msg="remove both"
787    del_dev vxlanA0
788    exp0=( 0 0 0 0 )
789    del_dev vxlan0
790    check_tables
791
792    echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset
793    check_tables
794
795    msg="destroy NIC"
796    echo $port > $NSIM_DEV_SYS/del_port
797
798    cleanup_tuns
799    exp0=( 0 0 0 0 )
800    exp1=( 0 0 0 0 )
801done
802
803cleanup_nsim
804
805# shared port tables
806pfx="table sharing"
807
808echo $NSIM_ID > /sys/bus/netdevsim/new_device
809echo 0 > $NSIM_DEV_SYS/del_port
810
811echo 0 > $NSIM_DEV_DFS/udp_ports_open_only
812echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
813echo 1 > $NSIM_DEV_DFS/udp_ports_shared
814
815old_netdevs=$(ls /sys/class/net)
816echo 1 > $NSIM_DEV_SYS/new_port
817NSIM_NETDEV=`get_netdev_name old_netdevs`
818old_netdevs=$(ls /sys/class/net)
819echo 2 > $NSIM_DEV_SYS/new_port
820NSIM_NETDEV2=`get_netdev_name old_netdevs`
821
822msg="VxLAN v4 devices"
823exp0=( `mke 4789 1` 0 0 0 )
824exp1=( 0 0 0 0 )
825new_vxlan vxlan0 4789 $NSIM_NETDEV
826new_vxlan vxlan1 4789 $NSIM_NETDEV2
827
828msg="VxLAN v4 devices go down"
829exp0=( 0 0 0 0 )
830ip link set dev vxlan1 down
831ip link set dev vxlan0 down
832check_tables
833
834for ifc in vxlan0 vxlan1; do
835    ip link set dev $ifc up
836done
837
838msg="VxLAN v6 device"
839exp0=( `mke 4789 1` `mke 4790 1` 0 0 )
840new_vxlan vxlanC 4790 $NSIM_NETDEV 6
841
842msg="Geneve device"
843exp1=( `mke 6081 2` 0 0 0 )
844new_geneve gnv0 6081
845
846msg="NIC device goes down"
847ip link set dev $NSIM_NETDEV down
848check_tables
849
850msg="NIC device goes up again"
851ip link set dev $NSIM_NETDEV up
852check_tables
853
854for i in `seq 2`; do
855    msg="turn feature off - 1, rep $i"
856    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload off
857    check_tables
858
859    msg="turn feature off - 2, rep $i"
860    exp0=( 0 0 0 0 )
861    exp1=( 0 0 0 0 )
862    ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload off
863    check_tables
864
865    msg="turn feature on - 1, rep $i"
866    exp0=( `mke 4789 1` `mke 4790 1` 0 0 )
867    exp1=( `mke 6081 2` 0 0 0 )
868    ethtool -K $NSIM_NETDEV rx-udp_tunnel-port-offload on
869    check_tables
870
871    msg="turn feature on - 2, rep $i"
872    ethtool -K $NSIM_NETDEV2 rx-udp_tunnel-port-offload on
873    check_tables
874done
875
876msg="tunnels destroyed 1"
877cleanup_tuns
878exp0=( 0 0 0 0 )
879exp1=( 0 0 0 0 )
880check_tables
881
882overflow_table0 "overflow NIC table"
883
884msg="re-add a port"
885
886echo 2 > $NSIM_DEV_SYS/del_port
887echo 2 > $NSIM_DEV_SYS/new_port
888NSIM_NETDEV=`get_netdev_name old_netdevs`
889check_tables
890
891msg="replace VxLAN in overflow table"
892exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` )
893del_dev vxlan1
894
895msg="vacate VxLAN in overflow table"
896exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` )
897del_dev vxlan2
898
899echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset
900check_tables
901
902msg="tunnels destroyed 2"
903cleanup_tuns
904exp0=( 0 0 0 0 )
905exp1=( 0 0 0 0 )
906check_tables
907
908echo 1 > $NSIM_DEV_SYS/del_port
909echo 2 > $NSIM_DEV_SYS/del_port
910
911cleanup_nsim
912
913# Static IANA port
914pfx="static IANA vxlan"
915
916echo $NSIM_ID > /sys/bus/netdevsim/new_device
917echo 0 > $NSIM_DEV_SYS/del_port
918
919echo 1 > $NSIM_DEV_DFS/udp_ports_static_iana_vxlan
920STATIC_ENTRIES=( `mke 4789 1` )
921
922port=1
923old_netdevs=$(ls /sys/class/net)
924echo $port > $NSIM_DEV_SYS/new_port
925NSIM_NETDEV=`get_netdev_name old_netdevs`
926
927msg="check empty"
928exp0=( 0 0 0 0 )
929exp1=( 0 0 0 0 )
930check_tables
931
932msg="add on static port"
933new_vxlan vxlan0 4789 $NSIM_NETDEV
934new_vxlan vxlan1 4789 $NSIM_NETDEV
935
936msg="add on different port"
937exp0=( `mke 4790 1` 0 0 0 )
938new_vxlan vxlan2 4790 $NSIM_NETDEV
939
940cleanup_tuns
941
942msg="tunnels destroyed"
943exp0=( 0 0 0 0 )
944exp1=( 0 0 0 0 )
945check_tables
946
947msg="different type"
948new_geneve gnv0	4789
949
950cleanup_tuns
951cleanup_nsim
952
953# END
954
955modprobe -r netdevsim
956
957if [ $num_errors -eq 0 ]; then
958    echo "PASSED all $num_cases checks"
959else
960    echo "FAILED $num_errors/$num_cases checks"
961fi
962
963exit $EXIT_STATUS
964