if-mtu-change.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
  4. # Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
  5. # Copyright (c) International Business Machines Corp., 2005
  6. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  7. IF_CMD='ifconfig'
  8. TST_SETUP="do_setup"
  9. TST_CLEANUP="do_cleanup"
  10. . if-lib.sh
  11. # The interval of the mtu change [second]
  12. CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
  13. TST_TIMEOUT=$(((CHANGE_INTERVAL + 30) * MTU_CHANGE_TIMES))
  14. # The array of the value which MTU is changed into sequentially
  15. # 552 - net.ipv4.route.min_pmtu
  16. CHANGE_VALUES="784 1142 552 1500 552 1500 552 748 552 1142 1500"
  17. CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
  18. saved_mtu=
  19. do_setup()
  20. {
  21. [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
  22. if_setup
  23. saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
  24. }
  25. do_cleanup()
  26. {
  27. if_cleanup_restore
  28. if [ "$saved_mtu" ]; then
  29. ip li set $(tst_iface) mtu $saved_mtu
  30. tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
  31. fi
  32. }
  33. test_body()
  34. {
  35. local cmd="$CMD"
  36. local iface=$(tst_iface)
  37. local iface_rmt=$(tst_iface rhost)
  38. [ "$TST_IPV6" ] && local netmask=64 || local netmask=16
  39. tst_res TINFO "'$cmd' changes MTU $MTU_CHANGE_TIMES times" \
  40. "every $CHANGE_INTERVAL seconds"
  41. mtu_array_len=$(echo $CHANGE_VALUES | wc -w)
  42. local cnt=0
  43. while [ $cnt -lt $MTU_CHANGE_TIMES ]; do
  44. local nth=$(($cnt % $mtu_array_len))
  45. field=$(($nth + 1))
  46. cnt=$(($cnt + 1))
  47. mtu=$(echo $CHANGE_VALUES | cut -d ' ' -f $field)
  48. [ $cnt -eq $MTU_CHANGE_TIMES ] && mtu="$saved_mtu"
  49. make_background_tcp_traffic
  50. tst_res TINFO "set MTU to $mtu $cnt/$MTU_CHANGE_TIMES"
  51. local ret=0
  52. case $cmd in
  53. ifconfig) ifconfig $iface mtu $mtu || ret=1
  54. tst_rhost_run -c "ifconfig $iface_rmt mtu $mtu"
  55. ;;
  56. ip) ip link set $iface mtu $mtu || ret=1
  57. tst_rhost_run -c "ip link set $iface_rmt mtu $mtu"
  58. ;;
  59. esac
  60. if [ $? -ne 0 -o $ret -ne 0 ]; then
  61. tst_res TFAIL "Failed to change the mtu at $cnt time"
  62. return
  63. fi
  64. tst_sleep $CHANGE_INTERVAL
  65. tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
  66. done
  67. }
  68. tst_run