Home | History | Annotate | Download | only in interface
      1 #!/bin/sh
      2 # Copyright (c) 2015 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 
     22 TST_CLEANUP="netstress_cleanup"
     23 
     24 . test_net_stress.sh
     25 
     26 # The interval of the check interface activity
     27 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
     28 
     29 test_body()
     30 {
     31 	local cmd_type=$1
     32 
     33 	case $cmd_type in
     34 	if_cmd) local cmd_name='ifconfig' ;;
     35 	ip_cmd) local cmd_name='ip' ;;
     36 	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
     37 	esac
     38 
     39 	local num=$(($(od -A n -t u1 -N 1 /dev/random) * 253 / 255 + 2 ))
     40 	local iface=$(tst_iface)
     41 	if [ "$TST_IPV6" ]; then
     42 		local new_ip=${IPV6_NET32_UNUSED}::$num
     43 		local netmask=64
     44 	else
     45 		local new_ip=${IPV4_NET16_UNUSED}.1.$num
     46 		local netmask=24
     47 	fi
     48 
     49 	tst_resm TINFO "'$cmd_name' add/del IPv$ipver '$new_ip' $NS_TIMES times"
     50 
     51 	if ! restore_ipaddr; then
     52 		tst_resm TBROK "Failed to set default IP addresses"
     53 		return
     54 	fi
     55 
     56 	local cnt=1
     57 	while [ $cnt -le $NS_TIMES ]; do
     58 		make_background_tcp_traffic
     59 
     60 		case $cmd_type in
     61 		if_cmd)
     62 			if [ "$TST_IPV6" ]; then
     63 				ifconfig $iface add $new_ip/$netmask
     64 			else
     65 				ifconfig $iface:1 $new_ip netmask 255.255.255.0
     66 			fi
     67 		;;
     68 		ip_cmd) ip addr add $new_ip/$netmask dev $iface ;;
     69 		esac
     70 
     71 		if [ $? -ne 0 ]; then
     72 			tst_resm TFAIL "command failed to add $new_ip to $iface"
     73 			return
     74 		fi
     75 
     76 		ip addr show $iface | grep -q $new_ip
     77 		if [ $? -ne 0 ]; then
     78 			ip addr show $iface
     79 			tst_resm TFAIL "$new_ip not configured"
     80 			return
     81 		fi
     82 
     83 		check_connectivity_interval $cnt || return
     84 
     85 		cnt=$(($cnt + 1))
     86 
     87 		case $cmd_type in
     88 		if_cmd)
     89 			if [ "$TST_IPV6" ]; then
     90 				ifconfig $iface del $new_ip/$netmask
     91 			else
     92 				ifconfig $iface:1 down
     93 			fi
     94 		;;
     95 		ip_cmd) ip addr del $new_ip/$netmask dev $iface ;;
     96 		esac
     97 
     98 		if [ $? -ne 0 ]; then
     99 			tst_resm TFAIL " delete command failed".
    100 			return
    101 		fi
    102 
    103 		ip addr show $iface | grep -q $new_ip
    104 		if [ $? -eq 0 ]; then
    105 			ip addr show $iface
    106 			tst_resm TFAIL "Failed to remove '$new_ip' address"
    107 			return
    108 		fi
    109 	done
    110 
    111 	tst_resm TPASS "Test is finished correctly"
    112 }
    113 
    114 netstress_setup
    115 
    116 tst_check_cmds ifconfig
    117 
    118 test_body 'if_cmd'
    119 test_body 'ip_cmd'
    120 
    121 tst_exit
    122