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=1
21TCID=if4-addr-change
22TST_CLEANUP="tst_restore_ipaddr"
23
24. test_net.sh
25
26# Broadcast address of the tested network
27CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 100))}
28# Maximum host portion of the IPv4 address on the local host
29LHOST_IPV4_HOST_MAX="254"
30
31trap "tst_brkm TBROK 'test interrupted'" INT
32
33tst_check_cmds ifconfig
34
35tst_resm TINFO "ifconfig changes IPv4 address $NS_TIMES times"
36
37tst_restore_ipaddr
38
39check_icmpv4_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
40	tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)"
41
42local cnt=0
43num=1
44while [ $cnt -lt $NS_TIMES ]; do
45	# Define the network portion
46	num=$(($num + 1))
47	[ $num -gt $LHOST_IPV4_HOST_MAX ] && num=1
48
49	[ $num -eq $RHOST_IPV4_HOST ] && continue
50
51	# Change IPv4 address
52	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
53
54	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
55		broadcast 255.255.255.255 || \
56		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
57
58	cnt=$(($cnt + 1))
59
60	[ $CHECK_INTERVAL -eq 0 ] && continue
61	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
62
63	tst_resm TINFO "ping from $lhost_ipv4addr to $(tst_ipaddr rhost)"
64	check_icmpv4_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
65		tst_brkm TFAIL "$(tst_iface) link broken after ${cnt} times"
66done
67
68tst_resm TINFO "ping from $lhost_ipv4addr to $(tst_ipaddr rhost)"
69check_icmpv4_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
70	tst_brkm TFAIL "$(tst_iface) is broken"
71
72tst_resm TPASS "Test is finished successfully"
73
74tst_exit
75