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-updown
22
23. if-lib.sh
24
25CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 100))}
26
27test_body()
28{
29	local cmd_type=$1
30
31	case $cmd_type in
32	if_cmd) local cmd_name='ifconfig' ;;
33	ip_cmd) local cmd_name='ip' ;;
34	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
35	esac
36
37	local iface=$(tst_iface)
38
39	tst_resm TINFO "'$cmd_name ups/downs $iface $IF_UPDOWN_TIMES times"
40	tst_resm TINFO "check connectivity interval is $CHECK_INTERVAL"
41	tst_restore_ipaddr || \
42		tst_resm TBROK "Failed to set default IP addresses"
43
44	local cnt=1
45	while [ $cnt -le $IF_UPDOWN_TIMES ]; do
46		case $cmd_type in
47		if_cmd) ifconfig $iface down ;;
48		ip_cmd) ip link set $iface down ;;
49		esac
50		if [ $? -ne 0 ]; then
51			tst_resm TFAIL "Failed to down $iface"
52			return
53		fi
54
55		case $cmd_type in
56		if_cmd) ifconfig $iface up ;;
57		ip_cmd) ip link set $iface up ;;
58		esac
59		if [ $? -ne 0 ]; then
60			tst_resm TFAIL "Failed to up $iface"
61			return
62		fi
63
64		check_connectivity $cnt || return
65
66		cnt=$(($cnt + 1))
67	done
68
69	tst_resm TPASS "Test is finished correctly"
70}
71
72setup
73
74tst_check_cmds ifconfig
75
76test_body 'if_cmd'
77test_body 'ip_cmd'
78
79tst_exit
80