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 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
     27 
     28 test_body()
     29 {
     30 	local cmd_type=$1
     31 
     32 	case $cmd_type in
     33 	rt_cmd) local cmd_name='route' ;;
     34 	ip_cmd) local cmd_name='ip' ;;
     35 	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
     36 	esac
     37 
     38 	local iface=$(tst_iface)
     39 	local inet="inet$TST_IPV6"
     40 	local opt_rt=
     41 	if [ "$TST_IPV6" ]; then
     42 		opt_rt="/64"
     43 	else
     44 		case $cmd_type in
     45 		rt_cmd) ;;
     46 		ip_cmd) opt_rt='/32' ;;
     47 		esac
     48 	fi
     49 
     50 	tst_resm TINFO "'$cmd_name' add IPv$ipver $ROUTE_TOTAL routes"
     51 
     52 	if ! restore_ipaddr; then
     53 		tst_resm TBROK "Failed to set default IP addresses"
     54 		return
     55 	fi
     56 
     57 	local x=1
     58 	local y=1
     59 	local cnt=1
     60 
     61 	[ "$TST_IPV6" ] && local xymax=65535 || xymax=254
     62 
     63 	if [ $ROUTE_TOTAL -gt $((xymax * xymax)) ]; then
     64 		tst_resm TWARN "set ROUTE_TOTAL to $xymax * $xymax"
     65 		ROUTE_TOTAL=$((xymax * xymax))
     66 	fi
     67 
     68 	while [ $cnt -le $ROUTE_TOTAL ]; do
     69 		make_background_tcp_traffic
     70 
     71 		if [ "$TST_IPV6" ]; then
     72 			local hex_x=$(printf '%x' $x)
     73 			local hex_y=$(printf '%x' $y)
     74 			local new_rt=${IPV6_NET32_UNUSED}:$hex_x:$hex_y::
     75 		else
     76 			local new_rt=${IPV4_NET16_UNUSED}.$x.$y
     77 		fi
     78 
     79 		case $cmd_type in
     80 		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
     81 		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
     82 		esac
     83 		if [ $? -ne 0 ]; then
     84 			tst_resm TFAIL "Can't add route $new_rt to $iface"
     85 			return
     86 		fi
     87 
     88 		check_connectivity_interval $cnt || return
     89 
     90 		cnt=$(($cnt + 1))
     91 		y=$(($y + 1))
     92 		if [ $y -gt $xymax ]; then
     93 			y=1
     94 			x=$(($x + 1))
     95 			if [ $x -gt $xymax ]; then
     96 				tst_brkm TBROK "Too large $ROUTE_TOTAL"
     97 			fi
     98 		fi
     99 	done
    100 
    101 	tst_resm TPASS "Test is finished correctly"
    102 }
    103 
    104 netstress_setup
    105 
    106 tst_check_cmds route
    107 
    108 test_body 'rt_cmd'
    109 test_body 'ip_cmd'
    110 
    111 tst_exit
    112