• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@jp.ibm.com>
19
20TST_TOTAL=2
21TCID=if-route-addlarge
22TST_CLEANUP="cleanup"
23
24. if-lib.sh
25
26CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 100))}
27
28test_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	tst_restore_ipaddr || \
53		tst_resm TBROK "Failed to set default IP addresses"
54
55	make_background_tcp_traffic
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
70		if [ "$TST_IPV6" ]; then
71			local hex_x=$(printf '%x' $x)
72			local hex_y=$(printf '%x' $y)
73			local new_rt=${IPV6_NET32_UNUSED}:$hex_x:$hex_y::
74		else
75			local new_rt=${IPV4_NET16_UNUSED}.$x.$y
76		fi
77
78		case $cmd_type in
79		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
80		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
81		esac
82		if [ $? -ne 0 ]; then
83			tst_resm TFAIL "Can't add route $new_rt to $iface"
84			return
85		fi
86
87		check_connectivity $cnt || return
88
89		# Check the background TCP traffic
90		pgrep -x tcp_fastopen > /dev/null || make_background_tcp_traffic
91
92		cnt=$(($cnt + 1))
93		y=$(($y + 1))
94		if [ $y -gt $xymax ]; then
95			y=1
96			x=$(($x + 1))
97			if [ $x -gt $xymax ]; then
98				tst_brkm TBROK "Too large $ROUTE_TOTAL"
99			fi
100		fi
101	done
102
103	tst_resm TPASS "Test is finished correctly"
104}
105
106setup
107
108tst_check_cmds route
109
110test_body 'rt_cmd'
111test_body 'ip_cmd'
112
113tst_exit
114