xref: /aosp_15_r20/external/ltp/testcases/network/stress/multicast/packet-flood/mcast-pktfld02.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2006 International Business Machines  Corp.
4# Copyright (c) 2020 Joerg Vehlow <[email protected]>
5# Author: Mitsuru Chinen <[email protected]>
6#
7# Verify that the kernel is not crashed when joining multiple multicast
8# groups on separate sockets, then receiving a large number of UDP
9# packets at each socket
10
11TST_NEEDS_ROOT=1
12TST_NEEDS_TMPDIR=1
13TST_SETUP="mcast_setup_normal_udp"
14TST_CLEANUP="mcast_cleanup"
15TST_TESTFUNC="do_test"
16
17do_test()
18{
19	tst_res TINFO "joining $MCASTNUM_NORMAL IPv${TST_IPVER} multicast groups on separate sockets, then receiving a large number of UDP packets at each socket in $NS_DURATION seconds"
20
21	local addr port
22	local n=0
23
24	while [ $n -lt $MCASTNUM_NORMAL ]; do
25		# Define the multicast address
26		if [ "$TST_IPV6" ]; then
27			local n_hex=$(printf "%x" $n)
28			addr=${MCAST_IPV6_ADDR_PREFIX}:${n_hex}
29		else
30			local x=$((n / 254))
31			local y=$((n % 254 + 1))
32			addr=${MCAST_IPV4_ADDR_PREFIX}.${x}.${y}
33		fi
34
35		port=$(tst_get_unused_port ipv${TST_IPVER} dgram)
36		[ $? -ne 0 ] && tst_brk TBROK "no free udp port available"
37
38		# Run a receiver
39		ROD $MCAST_LCMD -f $TST_IPVER -I $(tst_iface lhost) -m $addr -p $port -b
40
41		# Run a sender
42		tst_rhost_run -s -c "$MCAST_RCMD -D $addr -f $TST_IPVER -p $port -m -I $(tst_iface rhost) -b -t $NS_DURATION"
43
44		n=$((n+1))
45	done
46
47	sleep $NS_DURATION
48
49	tst_res TPASS "test finished successfully"
50}
51
52. mcast-lib.sh
53tst_run
54