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