xref: /aosp_15_r20/external/ltp/testcases/network/multicast/mc_commo/mc_commo.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
3# Copyright (c) International Business Machines  Corp., 2000
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, write the Free Software Foundation,
17# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18#
19# TEST DESCRIPTION:
20#     To verify that IP Multicast can be used to send UDP datagrams
21#     between two or more nodes on the same subnetwork using
22#     a specific IP Multicast group and a specific port address.
23#
24# Authors:
25#     Robbie Williamson ([email protected])
26#     Michael Reed [email protected]
27
28TTL=10
29OUTFILE=mc_commo_out
30
31TCID=mc_commo
32TST_TOTAL=2
33TST_CLEANUP=do_cleanup
34TST_USE_LEGACY_API=1
35
36do_setup()
37{
38	tst_require_cmds netstat pgrep
39
40	OCTET=$(ps -ewf | grep [m]c_commo | wc -l | awk '{print $1}')
41	GROUP_ADDR=224.0.0.$OCTET
42	PORT=$(tst_get_unused_port ipv4 dgram)
43	tst_tmpdir
44}
45
46do_test()
47{
48	# Run setsockopt/getsockopt test
49	# Start up the recv on local host
50	tst_resm TINFO "Start mc_recv $GROUP_ADDR $(tst_ipaddr) $PORT"
51	mc_recv $GROUP_ADDR $(tst_ipaddr) $PORT >> $OUTFILE &
52	SERVER_PID=$!
53	sleep 5
54	pgrep -x mc_recv > /dev/null || \
55		tst_brkm TFAIL "Could NOT start mc_recv on $(tst_ipaddr)"
56
57	grep -q "cannot join group" $OUTFILE && \
58		tst_brkm TFAIL "Membership NOT set"
59
60	netstat -ng | grep -q $GROUP_ADDR || \
61		tst_brkm TFAIL "membership not set for $GROUP_ADDR"
62
63	tst_resm TINFO "Start on $RHOST mc_send $GROUP_ADDR" \
64	               "$(tst_ipaddr rhost) $PORT $TTL"
65
66	tst_rhost_run -b -c "mc_send $GROUP_ADDR $(tst_ipaddr rhost) $PORT $TTL"
67	sleep 10
68	tst_rhost_run -s -c "pgrep -x mc_send > /dev/null"
69
70	tst_resm TINFO "Waiting for 100 sec.! Do not interrupt."
71	sleep 100  #wait until datagrams are received in $STATUS
72
73	#test if datagrams has been sent
74	grep -q "$(tst_ipaddr rhost) [0-9] [0-9]" $OUTFILE || \
75		tst_brkm TFAIL "NO Datagrams received from $RHOST"
76
77	tst_resm TPASS "Test Successful"
78}
79
80do_cleanup()
81{
82	ps -p $SERVER_PID > /dev/null 2>&1
83	if [ $? -eq 0 ]; then
84		kill -9 $SERVER_PID
85	fi
86
87	tst_rmdir
88}
89
90. tst_net.sh
91do_setup
92
93for i in $(seq 1 $TST_TOTAL); do
94	do_test
95done
96
97tst_exit
98