1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) International Business Machines  Corp., 2006                 ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21##                                                                            ##
22################################################################################
23#
24# File:
25#   mcast4-queryfld03
26#
27# Description:
28#   Verify that the kernel is not crashed when joining an IPv4 multicast group
29#   on a single socket, then receiving a large number of Multicast Address
30#   and Source Specific Query
31#
32# Setup:
33#   See ltp-yyyymmdd/testcases/network/stress/README
34#
35# Author:
36#   Mitsuru Chinen <mitch@jp.ibm.com>
37#
38# History:
39#	May 1 2006 - Created (Mitsuru Chinen)
40#
41#-----------------------------------------------------------------------
42# Uncomment line below for debug output.
43#trace_logic=${trace_logic:-"set -x"}
44$trace_logic
45
46# The test case ID, the test case count and the total number of test case
47TCID=mcast4-queryfld03
48TST_TOTAL=1
49TST_COUNT=1
50export TCID
51export TST_COUNT
52export TST_TOTAL
53
54# Make sure the value of LTPROOT
55LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
56export LTPROOT
57
58# Check the environmanet variable
59. check_envval || exit $TST_TOTAL
60
61# Dulation of the test [sec]
62NS_DURATION=${NS_DURATION:-3600}	# 1 hour
63
64# The number of the test link where tests run
65LINK_NUM=${LINK_NUM:-0}
66
67# Network portion of the IPv4 address
68NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
69
70# Netmask of the IPv4 network
71NETWORK_MASK=24
72
73# Host portion of the IPv4 address
74LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
75RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
76
77# Prefix of the Multicast Address
78MCAST_ADDR_PREFIX=224.10
79
80# Multicast Address
81MCAST_ADDR=224.10.0.1	# If you modify this, please refer ns-mcast_join.c
82
83# Source Address
84SRC_ADDR=10.10.10.1
85
86# Filter Mode
87FILTER_MODE="include"
88
89#-----------------------------------------------------------------------
90#
91# Function: do_cleanup
92#
93# Description:
94#   Recover the system configuration
95#
96#-----------------------------------------------------------------------
97do_cleanup()
98{
99    # Make sure to kill the multicast receiver and sender
100    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
101    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
102
103    # Clean up each interface
104    initialize_if lhost ${LINK_NUM}
105    initialize_if rhost ${LINK_NUM}
106}
107
108
109#-----------------------------------------------------------------------
110#
111# Function: do_setup
112#
113# Description:
114#   Configure the ssystem for the test
115#
116#-----------------------------------------------------------------------
117do_setup()
118{
119    # Initialize the system configuration
120    do_cleanup
121
122    # Call do_cleanup function before exit
123    trap do_cleanup 0
124
125    # name of interface of the local/remote host
126    lhost_ifname=`get_ifname lhost $LINK_NUM`
127    if [ $? -ne 0 ]; then
128	tst_resm TBROK "Failed to get the interface name at the local host"
129	exit $TST_TOTAL
130    fi
131
132    rhost_ifname=`get_ifname rhost $LINK_NUM`
133    if [ $? -ne 0 ]; then
134	tst_resm TBROK "Failed to get the interface name at the remote host"
135	exit $TST_TOTAL
136    fi
137
138    # Set IPv4 addresses to the interfaces
139    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
140    if [ $? -ne 0 ]; then
141	tst_resm TBROK "Failed to add any IP address at the local host"
142	exit 1
143    fi
144
145    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
146    if [ $? -ne 0 ]; then
147	tst_resm TBROK "Failed to add any IP address at the remote host"
148	exit 1
149    fi
150
151    # IPv4 address of the local/remote host
152    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
153    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
154
155    # Make sure the connectvity
156    check_icmpv4_connectivity $lhost_ifname $rhost_addr
157    if [ $? -ne 0 ]; then
158	tst_resm TBROK "There is no IPv4 connectivity."
159	exit 1
160    fi
161
162    # Make sure the sysctl values
163    sysctl -w net.ipv4.igmp_max_memberships=20 >/dev/null
164    if [ $? -ne 0 ]; then
165	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
166	exit $TST_TOTAL
167    fi
168
169    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
170    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
171    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
172}
173
174
175#-----------------------------------------------------------------------
176#
177# Main
178#
179#
180
181# Test description
182tst_resm TINFO "Verify that the kernel is not crashed when joining an IPv4 multicast group on a single socket, then receiving a large number of Multicast Address and Source Specific Query in $NS_DURATION [sec]"
183
184do_setup
185
186# Run a multicast join tool
187ns-mcast_join -f 4 -I $lhost_ifname -n 1 -p $MCAST_ADDR_PREFIX -s $SRC_ADDR -F $FILTER_MODE >/dev/null
188if [ $? -ne 0 ]; then
189    tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
190    exit 1
191fi
192
193# Send IGMP Multicast Address and Source Specific Query from the remote host
194ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -m $MCAST_ADDR -s $SRC_ADDR -t $NS_DURATION -r 0' ; echo $?'`
195if [ $ret -ne 0 ]; then
196    tst_resm TBROK "Failed to start IGMP querier"
197    exit 1
198fi
199
200#-----------------------------------------------------------------------
201#
202# Clean up
203#
204
205killall -SIGHUP ns-mcast_join >/dev/null 2>&1
206tst_resm TPASS "Test is finished successfully."
207
208exit 0
209