~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/netdevsim/udp_tunnel_nic.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0-only
  3 
  4 VNI_GEN=$RANDOM
  5 NSIM_ID=$((RANDOM % 1024))
  6 NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
  7 NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID
  8 NSIM_NETDEV=
  9 HAS_ETHTOOL=
 10 STATIC_ENTRIES=
 11 EXIT_STATUS=0
 12 num_cases=0
 13 num_errors=0
 14 
 15 clean_up_devs=( )
 16 
 17 function err_cnt {
 18     echo "ERROR:" $@
 19     EXIT_STATUS=1
 20     ((num_errors++))
 21     ((num_cases++))
 22 }
 23 
 24 function pass_cnt {
 25     ((num_cases++))
 26 }
 27 
 28 function 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 
 35 function cleanup_nsim {
 36     if [ -e $NSIM_DEV_SYS ]; then
 37         echo $NSIM_ID > /sys/bus/netdevsim/del_device
 38     fi
 39 }
 40 
 41 function cleanup {
 42     cleanup_tuns
 43     cleanup_nsim
 44 }
 45 
 46 trap cleanup EXIT
 47 
 48 function 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 
 75 function 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 
100 function 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
108 function mke {
109     local port=$1
110     local type=$2
111 
112     echo $((port << 16 | type))
113 }
114 
115 function pre {
116     local val=$1
117 
118     echo -e "port: $((val >> 16))\ttype: $((val & 0xffff))"
119 }
120 
121 function 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 
144 function 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 
185 function 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 
214 function 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 
228 function print_tables {
229     print_table 0
230     print_table 1
231 }
232 
233 function 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
256 ethtool -h | grep show-tunnels 2>&1 >/dev/null && HAS_ETHTOOL=y
257 
258 modprobe netdevsim
259 
260 # Basic test
261 pfx="basic"
262 
263 for 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
334 done
335 
336 modprobe -r netdevsim
337 
338 # Module tests
339 pfx="module tests"
340 
341 if modinfo netdevsim | grep udp_tunnel >/dev/null; then
342     err_cnt "netdevsim depends on udp_tunnel"
343 else
344     pass_cnt
345 fi
346 
347 modprobe netdevsim
348 
349 old_netdevs=$(ls /sys/class/net)
350 port=0
351 echo $NSIM_ID > /sys/bus/netdevsim/new_device
352 echo 0 > $NSIM_DEV_SYS/del_port
353 echo 1000 > $NSIM_DEV_DFS/udp_ports_sleep
354 echo 0 > $NSIM_DEV_SYS/new_port
355 NSIM_NETDEV=`get_netdev_name old_netdevs`
356 
357 msg="create VxLANs"
358 exp0=( 0 0 0 0 ) # sleep is longer than out wait
359 new_vxlan vxlan0 10000 $NSIM_NETDEV
360 
361 modprobe -r vxlan
362 modprobe -r udp_tunnel
363 
364 msg="remove tunnels"
365 exp0=( 0 0 0 0 )
366 check_tables
367 
368 msg="create VxLANs"
369 exp0=( 0 0 0 0 ) # sleep is longer than out wait
370 new_vxlan vxlan0 10000 $NSIM_NETDEV
371 
372 exp0=( 0 0 0 0 )
373 
374 modprobe -r netdevsim
375 modprobe netdevsim
376 
377 # Overflow the table
378 
379 function 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 
402 function 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 
425 echo $NSIM_ID > /sys/bus/netdevsim/new_device
426 echo 0 > $NSIM_DEV_SYS/del_port
427 
428 for 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 )
475 done
476 
477 cleanup_nsim
478 
479 # Sync all
480 pfx="sync all"
481 
482 echo $NSIM_ID > /sys/bus/netdevsim/new_device
483 echo 0 > $NSIM_DEV_SYS/del_port
484 echo 1 > $NSIM_DEV_DFS/udp_ports_sync_all
485 
486 for 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 )
533 done
534 
535 cleanup_nsim
536 
537 # Destroy full NIC
538 pfx="destroy full"
539 
540 echo $NSIM_ID > /sys/bus/netdevsim/new_device
541 echo 0 > $NSIM_DEV_SYS/del_port
542 
543 for 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 )
562 done
563 
564 cleanup_nsim
565 
566 # IPv4 only
567 pfx="IPv4 only"
568 
569 echo $NSIM_ID > /sys/bus/netdevsim/new_device
570 echo 0 > $NSIM_DEV_SYS/del_port
571 echo 1 > $NSIM_DEV_DFS/udp_ports_ipv4_only
572 
573 for 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 )
624 done
625 
626 cleanup_nsim
627 
628 # Failures
629 pfx="error injection"
630 
631 echo $NSIM_ID > /sys/bus/netdevsim/new_device
632 echo 0 > $NSIM_DEV_SYS/del_port
633 
634 for 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 )
680 done
681 
682 cleanup_nsim
683 
684 # netdev flags
685 pfx="netdev flags"
686 
687 echo $NSIM_ID > /sys/bus/netdevsim/new_device
688 echo 0 > $NSIM_DEV_SYS/del_port
689 
690 for 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 )
740 done
741 
742 cleanup_nsim
743 
744 # device initiated reset
745 pfx="reset notification"
746 
747 echo $NSIM_ID > /sys/bus/netdevsim/new_device
748 echo 0 > $NSIM_DEV_SYS/del_port
749 
750 for 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 )
801 done
802 
803 cleanup_nsim
804 
805 # shared port tables
806 pfx="table sharing"
807 
808 echo $NSIM_ID > /sys/bus/netdevsim/new_device
809 echo 0 > $NSIM_DEV_SYS/del_port
810 
811 echo 0 > $NSIM_DEV_DFS/udp_ports_open_only
812 echo 1 > $NSIM_DEV_DFS/udp_ports_sleep
813 echo 1 > $NSIM_DEV_DFS/udp_ports_shared
814 
815 old_netdevs=$(ls /sys/class/net)
816 echo 1 > $NSIM_DEV_SYS/new_port
817 NSIM_NETDEV=`get_netdev_name old_netdevs`
818 old_netdevs=$(ls /sys/class/net)
819 echo 2 > $NSIM_DEV_SYS/new_port
820 NSIM_NETDEV2=`get_netdev_name old_netdevs`
821 
822 msg="VxLAN v4 devices"
823 exp0=( `mke 4789 1` 0 0 0 )
824 exp1=( 0 0 0 0 )
825 new_vxlan vxlan0 4789 $NSIM_NETDEV
826 new_vxlan vxlan1 4789 $NSIM_NETDEV2
827 
828 msg="VxLAN v4 devices go down"
829 exp0=( 0 0 0 0 )
830 ip link set dev vxlan1 down
831 ip link set dev vxlan0 down
832 check_tables
833 
834 for ifc in vxlan0 vxlan1; do
835     ip link set dev $ifc up
836 done
837 
838 msg="VxLAN v6 device"
839 exp0=( `mke 4789 1` `mke 4790 1` 0 0 )
840 new_vxlan vxlanC 4790 $NSIM_NETDEV 6
841 
842 msg="Geneve device"
843 exp1=( `mke 6081 2` 0 0 0 )
844 new_geneve gnv0 6081
845 
846 msg="NIC device goes down"
847 ip link set dev $NSIM_NETDEV down
848 check_tables
849 
850 msg="NIC device goes up again"
851 ip link set dev $NSIM_NETDEV up
852 check_tables
853 
854 for 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
874 done
875 
876 msg="tunnels destroyed 1"
877 cleanup_tuns
878 exp0=( 0 0 0 0 )
879 exp1=( 0 0 0 0 )
880 check_tables
881 
882 overflow_table0 "overflow NIC table"
883 
884 msg="re-add a port"
885 
886 echo 2 > $NSIM_DEV_SYS/del_port
887 echo 2 > $NSIM_DEV_SYS/new_port
888 NSIM_NETDEV=`get_netdev_name old_netdevs`
889 check_tables
890 
891 msg="replace VxLAN in overflow table"
892 exp0=( `mke 10000 1` `mke 10004 1` `mke 10002 1` `mke 10003 1` )
893 del_dev vxlan1
894 
895 msg="vacate VxLAN in overflow table"
896 exp0=( `mke 10000 1` `mke 10004 1` 0 `mke 10003 1` )
897 del_dev vxlan2
898 
899 echo 1 > $NSIM_DEV_DFS/ports/$port/udp_ports_reset
900 check_tables
901 
902 msg="tunnels destroyed 2"
903 cleanup_tuns
904 exp0=( 0 0 0 0 )
905 exp1=( 0 0 0 0 )
906 check_tables
907 
908 echo 1 > $NSIM_DEV_SYS/del_port
909 echo 2 > $NSIM_DEV_SYS/del_port
910 
911 cleanup_nsim
912 
913 # Static IANA port
914 pfx="static IANA vxlan"
915 
916 echo $NSIM_ID > /sys/bus/netdevsim/new_device
917 echo 0 > $NSIM_DEV_SYS/del_port
918 
919 echo 1 > $NSIM_DEV_DFS/udp_ports_static_iana_vxlan
920 STATIC_ENTRIES=( `mke 4789 1` )
921 
922 port=1
923 old_netdevs=$(ls /sys/class/net)
924 echo $port > $NSIM_DEV_SYS/new_port
925 NSIM_NETDEV=`get_netdev_name old_netdevs`
926 
927 msg="check empty"
928 exp0=( 0 0 0 0 )
929 exp1=( 0 0 0 0 )
930 check_tables
931 
932 msg="add on static port"
933 new_vxlan vxlan0 4789 $NSIM_NETDEV
934 new_vxlan vxlan1 4789 $NSIM_NETDEV
935 
936 msg="add on different port"
937 exp0=( `mke 4790 1` 0 0 0 )
938 new_vxlan vxlan2 4790 $NSIM_NETDEV
939 
940 cleanup_tuns
941 
942 msg="tunnels destroyed"
943 exp0=( 0 0 0 0 )
944 exp1=( 0 0 0 0 )
945 check_tables
946 
947 msg="different type"
948 new_geneve gnv0 4789
949 
950 cleanup_tuns
951 cleanup_nsim
952 
953 # END
954 
955 modprobe -r netdevsim
956 
957 if [ $num_errors -eq 0 ]; then
958     echo "PASSED all $num_cases checks"
959 else
960     echo "FAILED $num_errors/$num_cases checks"
961 fi
962 
963 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php