1#!/bin/sh 2# Copyright (c) International Business Machines Corp., 2006 3# Copyright (c) 2017 Petr Vorel <pvorel@suse.cz> 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_TOTAL=1 23TST_CLEANUP="mcast_cleanup" 24 25. test_net_stress.sh 26 27MCAST_LCMD="ns-mcast_join -f $ipver -I $(tst_iface)" 28 29MCAST_RCMD="ns-igmp_querier" 30[ "$TST_IPV6" ] && MCAST_RCMD="ns-icmpv6_sender" 31MCAST_RCMD="$MCAST_RCMD -I $(tst_iface rhost)" 32 33mcast_setup4() 34{ 35 local igmp_max_memberships="$1" 36 37 SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships) 38 SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf) 39 SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version) 40 SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version) 41 42 [ "$igmp_max_memberships" -gt 5459 ] && tst_resm TWARN \ 43 "\$1 shouldn't be set higher than 5459 as it's used to set /proc/sys/net/ipv4/igmp_max_memberships" 44 45 ROD sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships 46 ROD sysctl -qw net.ipv4.igmp_max_msf=10 47 ROD sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=0 48 ROD sysctl -qw net.ipv4.conf.all.force_igmp_version=0 49} 50 51mcast_setup6() 52{ 53 local default_mld_max_msf=64 54 tst_kvcmp -lt '2.6.15' && default_mld_max_msf=10 55 56 SYSCTL_ALL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.all.force_mld_version) 57 SYSCTL_FORCE_MLD_VERSION=$(sysctl -b net.ipv6.conf.$(tst_iface).force_mld_version) 58 SYSCTL_MLD_MAX_MSF=$(sysctl -b net.ipv6.mld_max_msf) 59 60 ROD sysctl -qw net.ipv6.conf.all.force_mld_version=0 61 ROD sysctl -qw net.ipv6.conf.$(tst_iface).force_mld_version=0 62 ROD sysctl -qw net.ipv6.mld_max_msf=$default_mld_max_msf 63} 64 65mcast_setup() 66{ 67 local max="$1" 68 69 netstress_setup 70 tst_tmpdir 71 72 [ "$TST_IPV6" ] && mcast_setup6 || mcast_setup4 $max 73} 74 75mcast_cleanup4() 76{ 77 [ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -qw net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS 78 [ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -qw net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF 79 [ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION 80 [ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -qw 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 -qw net.ipv6.conf.all.force_mld_version=$SYSCTL_ALL_FORCE_MLD_VERSION 86 [ -n "$SYSCTL_FORCE_MLD_VERSION" ] && sysctl -qw net.ipv6.conf.$(tst_iface).force_mld_version=$SYSCTL_FORCE_MLD_VERSION 87 [ -n "$SYSCTL_MLD_MAX_MSF" ] && sysctl -qw 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_resm 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_resm TPASS "test is finished successfully" 154} 155