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