• 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-adddel
22
23. if-lib.sh
24
25TST_CLEANUP="do_cleanup"
26
27CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
28
29do_cleanup()
30{
31	cleanup
32	restore_ipaddr
33}
34
35test_body()
36{
37	local cmd_type=$1
38
39	case $cmd_type in
40	rt_cmd) local cmd_name='route' ;;
41	ip_cmd) local cmd_name='ip' ;;
42	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
43	esac
44
45	local iface=$(tst_iface)
46	local inet="inet$TST_IPV6"
47	local new_rt=
48	local opt_rt=
49	if [ "$TST_IPV6" ]; then
50		new_rt=${IPV6_NET32_UNUSED}::
51		opt_rt="/64"
52	else
53		new_rt="${IPV4_NET16_UNUSED}.23.0"
54		case $cmd_type in
55		rt_cmd) ;;
56		ip_cmd) opt_rt='/24' ;;
57		esac
58	fi
59
60	tst_resm TINFO "'$cmd_name' add/del ${new_rt}${opt_rt} $NS_TIMES times"
61
62	if ! restore_ipaddr; then
63		tst_resm TBROK "Failed to set default IP addresses"
64		return
65	fi
66
67	make_background_tcp_traffic
68
69	local cnt=1
70	while [ $cnt -le $NS_TIMES ]; do
71		case $cmd_type in
72		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
73		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
74		esac
75		if [ $? -ne 0 ]; then
76			tst_resm TFAIL "Can't add route $new_rt to $iface"
77			return
78		fi
79
80		case $cmd_type in
81		rt_cmd) route -A $inet del ${new_rt}${opt_rt} dev $iface ;;
82		ip_cmd) ip route del ${new_rt}${opt_rt} dev $iface ;;
83		esac
84		if [ $? -ne 0 ]; then
85			tst_resm TFAIL "Can't del route $new_rt from $iface"
86			return
87		fi
88
89		check_connectivity $cnt || return
90
91		# Check the background TCP traffic
92		pgrep -x netstress > /dev/null || make_background_tcp_traffic
93
94		cnt=$(($cnt + 1))
95	done
96
97	tst_resm TPASS "Test is finished correctly"
98}
99
100setup
101
102tst_check_cmds route
103
104test_body 'rt_cmd'
105test_body 'ip_cmd'
106
107tst_exit
108