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=1 21 TCID=if4-addr-change 22 TST_CLEANUP="tst_restore_ipaddr" 23 24 . test_net.sh 25 26 # Broadcast address of the tested network 27 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 100))} 28 # Maximum host portion of the IPv4 address on the local host 29 LHOST_IPV4_HOST_MAX="254" 30 31 trap "tst_brkm TBROK 'test interrupted'" INT 32 33 tst_check_cmds ifconfig 34 35 tst_resm TINFO "ifconfig changes IPv4 address $NS_TIMES times" 36 37 tst_restore_ipaddr 38 39 check_icmpv4_connectivity $(tst_iface) $(tst_ipaddr rhost) || \ 40 tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)" 41 42 local cnt=0 43 num=1 44 while [ $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" 66 done 67 68 tst_resm TINFO "ping from $lhost_ipv4addr to $(tst_ipaddr rhost)" 69 check_icmpv4_connectivity $(tst_iface) $(tst_ipaddr rhost) || \ 70 tst_brkm TFAIL "$(tst_iface) is broken" 71 72 tst_resm TPASS "Test is finished successfully" 73 74 tst_exit 75