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