Home | History | Annotate | Download | only in interface
      1 #!/bin/sh
      2 # Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
      3 # Copyright (c) International Business Machines  Corp., 2005
      4 #
      5 # This program is free software; you can redistribute it and/or
      6 # modify it under the terms of the GNU General Public License as
      7 # published by the Free Software Foundation; either version 2 of
      8 # the License, or (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it would be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     17 #
     18 # Author: Mitsuru Chinen <mitch (at] jp.ibm.com>
     19 
     20 TST_TOTAL=2
     21 TCID=if-mtu-change
     22 
     23 . if-lib.sh
     24 
     25 TST_CLEANUP="do_cleanup"
     26 
     27 # The interval of the mtu change [second]
     28 CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
     29 # The array of the value which MTU is changed into sequentially
     30 # 552 - net.ipv4.route.min_pmtu
     31 CHANGE_VALUES="784 1142 552 1500 552 1500 552 748 552 1142 1500"
     32 CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
     33 [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
     34 saved_mtu=
     35 
     36 do_cleanup()
     37 {
     38 	cleanup
     39 	if [ "$saved_mtu" ]; then
     40 		ip li set $(tst_iface) mtu $saved_mtu
     41 		tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
     42 	fi
     43 	tst_restore_ipaddr
     44 	tst_restore_ipaddr rhost
     45 	tst_wait_ipv6_dad
     46 }
     47 
     48 test_body()
     49 {
     50 	local cmd_type=$1
     51 
     52 	case $cmd_type in
     53 	if_cmd) local cmd_name='ifconfig' ;;
     54 	ip_cmd) local cmd_name='ip' ;;
     55 	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
     56 	esac
     57 
     58 	local iface=$(tst_iface)
     59 	local iface_rmt=$(tst_iface rhost)
     60 	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
     61 
     62 	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times " \
     63 	               "every $CHANGE_INTERVAL seconds"
     64 
     65 	make_background_tcp_traffic
     66 
     67 	mtu_array_len=$(echo $CHANGE_VALUES | wc -w)
     68 	local cnt=0
     69 	while [ $cnt -lt $MTU_CHANGE_TIMES ]; do
     70 		local nth=$(($cnt % $mtu_array_len))
     71 		field=$(($nth + 1))
     72 		cnt=$(($cnt + 1))
     73 		mtu=$(echo $CHANGE_VALUES | cut -d ' ' -f $field)
     74 		[ $cnt -eq $MTU_CHANGE_TIMES ] && mtu="$saved_mtu"
     75 
     76 		tst_resm TINFO "set MTU to $mtu $cnt/$MTU_CHANGE_TIMES"
     77 		local ret=0
     78 		case $cmd_type in
     79 		if_cmd) ifconfig $iface mtu $mtu || ret=1
     80 			tst_rhost_run -c "ifconfig $iface_rmt mtu $mtu"
     81 		;;
     82 		ip_cmd) ip link set $iface mtu $mtu || ret=1
     83 			tst_rhost_run -c "ip link set $iface_rmt mtu $mtu"
     84 		;;
     85 		esac
     86 
     87 		if [ $? -ne 0 -o $ret -ne 0 ]; then
     88 			tst_resm TFAIL "Failed to change the mtu at $cnt time"
     89 			return
     90 		fi
     91 
     92 		tst_sleep $CHANGE_INTERVAL
     93 
     94 		EXPECT_PASS tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
     95 
     96 		# Check the background TCP traffic
     97 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
     98 	done
     99 }
    100 
    101 setup
    102 
    103 tst_check_cmds ifconfig
    104 
    105 saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
    106 
    107 test_body 'if_cmd'
    108 test_body 'ip_cmd'
    109 
    110 tst_exit
    111