• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
3# Copyright (c) International Business Machines  Corp., 2006
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: Petr Vorel <pvorel@suse.cz>
19#
20# Setup script for multicast stress tests.
21
22TST_SETUP="do_setup"
23TST_CLEANUP="mcast_cleanup"
24TST_TESTFUNC="do_test"
25TST_NEEDS_TMPDIR=1
26. tst_net_stress.sh
27
28mcast_setup4()
29{
30	local igmp_max_memberships="$1"
31
32	SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships)
33	SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf)
34	SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version)
35	SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version)
36
37	[ "$igmp_max_memberships" -gt 5459 ] && tst_res TWARN \
38		"\$1 shouldn't be set higher than 5459 as it's used to set /proc/sys/net/ipv4/igmp_max_memberships"
39
40	ROD sysctl -q -w net.ipv4.igmp_max_memberships=$igmp_max_memberships
41	ROD sysctl -q -w net.ipv4.igmp_max_msf=10
42	ROD sysctl -q -w net.ipv4.conf.$(tst_iface).force_igmp_version=0
43	ROD sysctl -q -w net.ipv4.conf.all.force_igmp_version=0
44}
45
46mcast_setup6()
47{
48	local default_mld_max_msf=64
49	tst_kvcmp -lt '2.6.15' && default_mld_max_msf=10
50
51	SYSCTL_ALL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.all.force_mld_version)
52	SYSCTL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.$(tst_iface).force_mld_version)
53	SYSCTL_MLD_MAX_MSF=$(sysctl -b net.ipv6.mld_max_msf)
54
55	ROD sysctl -q -w net.ipv6.conf.all.force_mld_version=0
56	ROD sysctl -q -w net.ipv6.conf.$(tst_iface).force_mld_version=0
57	ROD sysctl -q -w net.ipv6.mld_max_msf=$default_mld_max_msf
58}
59
60mcast_setup()
61{
62	local max="$1"
63
64	MCAST_LCMD="ns-mcast_join -f $TST_IPVER -I $(tst_iface)"
65
66	local cmd="ns-igmp_querier"
67	[ "$TST_IPV6" ] && cmd="ns-icmpv6_sender"
68	MCAST_RCMD="$cmd -I $(tst_iface rhost)"
69
70	netstress_setup
71
72	[ "$TST_IPV6" ] && mcast_setup6 || mcast_setup4 $max
73}
74
75mcast_cleanup4()
76{
77	[ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -q -w net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS
78	[ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -q -w net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF
79	[ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -q -w net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION
80	[ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -q -w net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION
81}
82
83mcast_cleanup6()
84{
85	[ -n "$SYSCTL_ALL_FORCE_MLD_VERSION" ] && sysctl -q -w net.ipv6.conf.all.force_mld_version=$SYSCTL_ALL_FORCE_MLD_VERSION
86	[ -n "$SYSCTL_FORCE_MLD_VERSION" ] && sysctl -q -w net.ipv6.conf.$(tst_iface).force_mld_version=$SYSCTL_FORCE_MLD_VERSION
87	[ -n "$SYSCTL_MLD_MAX_MSF" ] && sysctl -q -w net.ipv6.mld_max_msf=$SYSCTL_MLD_MAX_MSF
88}
89
90mcast_cleanup()
91{
92	[ "$TST_IPV6" ] && mcast_cleanup6 || mcast_cleanup4
93
94	pkill -SIGHUP -f "$MCAST_LCMD"
95	tst_sleep 10ms
96	pkill -9 -f "$MCAST_LCMD"
97
98	tst_rhost_run -c "pkill -SIGHUP -f '$MCAST_RCMD'"
99}
100
101do_multicast_test_multiple_join()
102{
103	local num="$1"
104	local mprefix="$MCAST_IPV4_ADDR_PREFIX"
105	local param_multi_socket ret tmpfile
106
107	[ "${2:-}" = true ] && param_multi_socket="-m"
108	[ "$TST_IPV6" ] && mprefix="$MCAST_IPV6_ADDR_PREFIX"
109
110	# Run a multicast join tool
111	tmpfile=$$
112	EXPECT_PASS $MCAST_LCMD $param_multi_socket -n $num -p $mprefix \> $tmpfile
113	tst_res TINFO "joined $(grep groups $tmpfile)"
114
115	# Send MLD / IGMP General Query from the remote host
116	if [ "$TST_IPV6" ]; then
117		EXPECT_RHOST_PASS $MCAST_RCMD -S $(tst_ipaddr) -m -o
118	else
119		EXPECT_RHOST_PASS $MCAST_RCMD -o -r 1 -m $MCAST_IPV4_ADDR
120	fi
121}
122
123do_multicast_test_join_leave()
124{
125	local cnt define_src_addr filter params ret
126	local max="$1"
127	local maddr="$MCAST_IPV4_ADDR"
128	[ "$TST_IPV6" ] && maddr="$MCAST_IPV6_ADDR"
129
130	[ "$2" = true ] && define_src_addr=true
131
132	# Send MLD / IGMP General Query from the remote host
133	if [ "$TST_IPV6" ]; then
134		tst_rhost_run -s -c "$MCAST_RCMD -S $(tst_ipaddr) -m -w 1000000000 -r 1000 -b"
135	else
136		tst_rhost_run -s -c "$MCAST_RCMD -i 1000000000 -r 1 -b"
137	fi
138
139	# Run a multicast join tool
140	cnt=0
141	while [ $cnt -lt $max ]; do
142		if [ "$define_src_addr" ]; then
143			[ $((cnt % 5)) -ne 2 ] && filter="include" || filter="exclude"
144			params="-F $filter -s $(tst_ipaddr_un -c$cnt)"
145		fi
146
147		$MCAST_LCMD -l $NS_TIMES -a $maddr $params &
148		cnt=$((cnt + 1))
149	done
150
151	wait
152
153	tst_res TPASS "test is finished successfully"
154}
155