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:-$(($IP_TOTAL / 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 iface=$(tst_iface)
     40 	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
     41 
     42 	tst_resm TINFO "'$cmd_name' add $IP_TOTAL IPv$ipver addresses"
     43 	tst_resm TINFO "check interval that $iface is working: $CHECK_INTERVAL"
     44 
     45 	if ! restore_ipaddr; then
     46 		tst_resm TBROK "Failed to set default IP addresses"
     47 		return
     48 	fi
     49 
     50 	local x=1
     51 	local y=1
     52 	local cnt=1
     53 
     54 	[ "$TST_IPV6" ] && local xymax=65535 || xymax=254
     55 
     56 	if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then
     57 		tst_resm TWARN "set IP_TOTAL to $xymax * $xymax"
     58 		IP_TOTAL=$((xymax * xymax))
     59 	fi
     60 
     61 	while [ $cnt -le $IP_TOTAL ]; do
     62 		make_background_tcp_traffic
     63 
     64 		if [ "$TST_IPV6" ]; then
     65 			local hex_x=$(printf '%x' $x)
     66 			local hex_y=$(printf '%x' $y)
     67 			local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1
     68 		else
     69 			local new_ip=${IPV4_NET16_UNUSED}.$x.$y
     70 		fi
     71 
     72 		case $cmd_type in
     73 		if_cmd)
     74 			if [ "$TST_IPV6" ]; then
     75 				ifconfig $iface add $new_ip/$netmask
     76 			else
     77 				ifconfig $iface:$x:$y $new_ip netmask 255.255.0.0
     78 			fi
     79 		;;
     80 		ip_cmd) ip addr add $new_ip/$netmask dev $iface ;;
     81 		esac
     82 
     83 		if [ $? -ne 0 ]; then
     84 			tst_resm TFAIL "command failed to add $new_ip to $iface"
     85 			return
     86 		fi
     87 
     88 		ip addr show $iface | grep -q $new_ip
     89 		if [ $? -ne 0 ]; then
     90 			ip addr show $iface
     91 			tst_resm TFAIL "$new_ip not configured"
     92 			return
     93 		fi
     94 
     95 		check_connectivity_interval $cnt || return
     96 
     97 		case $cmd_type in
     98 		if_cmd)
     99 			if [ "$TST_IPV6" ]; then
    100 				ifconfig $iface del $new_ip/$netmask
    101 			else
    102 				ifconfig $iface:$x:$y down
    103 			fi
    104 		;;
    105 		ip_cmd) ip addr del $new_ip/$netmask dev $iface ;;
    106 		esac
    107 
    108 		if [ $? -ne 0 ]; then
    109 			tst_resm TFAIL " delete command failed".
    110 			return
    111 		fi
    112 
    113 		ip addr show $iface | grep -q $new_ip
    114 		if [ $? -eq 0 ]; then
    115 			ip addr show $iface
    116 			tst_resm TFAIL "Failed to remove '$new_ip' address"
    117 			return
    118 		fi
    119 
    120 		cnt=$(($cnt + 1))
    121 		y=$(($y + 1))
    122 		if [ $y -gt $xymax ]; then
    123 			y=1
    124 			x=$(($x + 1))
    125 			if [ $x -gt $xymax ]; then
    126 				tst_brkm TBROK "Too large $IP_TOTAL"
    127 			fi
    128 		fi
    129 	done
    130 
    131 	tst_resm TPASS "Test is finished correctly"
    132 }
    133 
    134 netstress_setup
    135 
    136 tst_check_cmds ifconfig
    137 
    138 test_body 'if_cmd'
    139 test_body 'ip_cmd'
    140 
    141 tst_exit
    142