• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
3# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
4# Copyright (c) International Business Machines  Corp., 2005
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; either version 2 of
9# the License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it would be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19# Author: Mitsuru Chinen <mitch@jp.ibm.com>
20
21IF_CMD='ifconfig'
22. if-lib.sh
23
24# The interval of the check interface activity
25CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))}
26
27test_body()
28{
29	local cmd="$CMD"
30
31	local iface=$(tst_iface)
32	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
33
34	tst_res TINFO "'$cmd' add $IP_TOTAL IPv$TST_IPVER addresses"
35	tst_res TINFO "check interval that $iface is working: $CHECK_INTERVAL"
36
37	if ! restore_ipaddr; then
38		tst_res TBROK "Failed to set default IP addresses"
39		return
40	fi
41
42	local x=1
43	local y=1
44	local cnt=1
45
46	[ "$TST_IPV6" ] && local xymax=65535 || xymax=254
47
48	if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then
49		tst_res TWARN "set IP_TOTAL to $xymax * $xymax"
50		IP_TOTAL=$((xymax * xymax))
51	fi
52
53	while [ $cnt -le $IP_TOTAL ]; do
54		make_background_tcp_traffic
55
56		if [ "$TST_IPV6" ]; then
57			local hex_x=$(printf '%x' $x)
58			local hex_y=$(printf '%x' $y)
59			local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1
60		else
61			local new_ip=${IPV4_NET16_UNUSED}.$x.$y
62		fi
63
64		case $cmd in
65		ifconfig)
66			if [ "$TST_IPV6" ]; then
67				ifconfig $iface add $new_ip/$netmask
68			else
69				ifconfig $iface:$x:$y $new_ip netmask 255.255.0.0
70			fi
71		;;
72		ip) ip addr add $new_ip/$netmask dev $iface ;;
73		esac
74
75		if [ $? -ne 0 ]; then
76			tst_res TFAIL "command failed to add $new_ip to $iface"
77			return
78		fi
79
80		ip addr show $iface | grep -q $new_ip
81		if [ $? -ne 0 ]; then
82			ip addr show $iface
83			tst_res TFAIL "$new_ip not configured"
84			return
85		fi
86
87		check_connectivity_interval $cnt || return
88
89		case $cmd in
90		ifconfig)
91			if [ "$TST_IPV6" ]; then
92				ifconfig $iface del $new_ip/$netmask
93			else
94				ifconfig $iface:$x:$y down
95			fi
96		;;
97		ip) ip addr del $new_ip/$netmask dev $iface ;;
98		esac
99
100		if [ $? -ne 0 ]; then
101			tst_res TFAIL " delete command failed".
102			return
103		fi
104
105		ip addr show $iface | grep -q $new_ip
106		if [ $? -eq 0 ]; then
107			ip addr show $iface
108			tst_res TFAIL "Failed to remove '$new_ip' address"
109			return
110		fi
111
112		cnt=$(($cnt + 1))
113		y=$(($y + 1))
114		if [ $y -gt $xymax ]; then
115			y=1
116			x=$(($x + 1))
117			if [ $x -gt $xymax ]; then
118				tst_brk TBROK "Too large $IP_TOTAL"
119			fi
120		fi
121	done
122
123	tst_res TPASS "Test is finished correctly"
124}
125
126tst_run
127