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