1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci################################################################################
4f08c3bdfSopenharmony_ci##                                                                            ##
5f08c3bdfSopenharmony_ci## Copyright (c) International Business Machines  Corp., 2005                 ##
6f08c3bdfSopenharmony_ci##                                                                            ##
7f08c3bdfSopenharmony_ci## This program is free software;  you can redistribute it and#or modify      ##
8f08c3bdfSopenharmony_ci## it under the terms of the GNU General Public License as published by       ##
9f08c3bdfSopenharmony_ci## the Free Software Foundation; either version 2 of the License, or          ##
10f08c3bdfSopenharmony_ci## (at your option) any later version.                                        ##
11f08c3bdfSopenharmony_ci##                                                                            ##
12f08c3bdfSopenharmony_ci## This program is distributed in the hope that it will be useful, but        ##
13f08c3bdfSopenharmony_ci## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14f08c3bdfSopenharmony_ci## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15f08c3bdfSopenharmony_ci## for more details.                                                          ##
16f08c3bdfSopenharmony_ci##                                                                            ##
17f08c3bdfSopenharmony_ci## You should have received a copy of the GNU General Public License          ##
18f08c3bdfSopenharmony_ci## along with this program;  if not, write to the Free Software               ##
19f08c3bdfSopenharmony_ci## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20f08c3bdfSopenharmony_ci##                                                                            ##
21f08c3bdfSopenharmony_ci##                                                                            ##
22f08c3bdfSopenharmony_ci################################################################################
23f08c3bdfSopenharmony_ci#
24f08c3bdfSopenharmony_ci# File:
25f08c3bdfSopenharmony_ci#   tcp4-multi-diffip01
26f08c3bdfSopenharmony_ci#
27f08c3bdfSopenharmony_ci# Description:
28f08c3bdfSopenharmony_ci#   Verify that the kernel is not crashed with multiple connection to the
29f08c3bdfSopenharmony_ci#   different IP address(alias) with the following condition:
30f08c3bdfSopenharmony_ci#     - The version of IP is IPv4
31f08c3bdfSopenharmony_ci#     - Network is not delayed
32f08c3bdfSopenharmony_ci#     - IPsec is not used
33f08c3bdfSopenharmony_ci#
34f08c3bdfSopenharmony_ci#   *) This script may be read by the other test case
35f08c3bdfSopenharmony_ci#
36f08c3bdfSopenharmony_ci# Setup:
37f08c3bdfSopenharmony_ci#   See testcases/network/stress/README
38f08c3bdfSopenharmony_ci#
39f08c3bdfSopenharmony_ci# Author:
40f08c3bdfSopenharmony_ci#   Mitsuru Chinen <mitch@jp.ibm.com>
41f08c3bdfSopenharmony_ci#
42f08c3bdfSopenharmony_ci# History:
43f08c3bdfSopenharmony_ci#	Oct 19 2005 - Created (Mitsuru Chinen)
44f08c3bdfSopenharmony_ci#
45f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
46f08c3bdfSopenharmony_ci# Uncomment line below for debug output.
47f08c3bdfSopenharmony_ci#trace_logic=${trace_logic:-"set -x"}
48f08c3bdfSopenharmony_ci$trace_logic
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ci# The test case ID, the test case count and the total number of test case
51f08c3bdfSopenharmony_ciTCID=${TCID:-tcp4-multi-diffip01}
52f08c3bdfSopenharmony_ciTST_TOTAL=1
53f08c3bdfSopenharmony_ciTST_COUNT=1
54f08c3bdfSopenharmony_ciexport TCID
55f08c3bdfSopenharmony_ciexport TST_COUNT
56f08c3bdfSopenharmony_ciexport TST_TOTAL
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ci# Test description
59f08c3bdfSopenharmony_citst_resm TINFO "Verify that the kernel is not crashed with multiple connection to the different IP address(alias)."
60f08c3bdfSopenharmony_ci
61f08c3bdfSopenharmony_ci# Make sure the value of LTPROOT
62f08c3bdfSopenharmony_ciLTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
63f08c3bdfSopenharmony_ciexport LTPROOT
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_ci# Check the environmanet variable
66f08c3bdfSopenharmony_ci. check_envval || exit $TST_TOTAL
67f08c3bdfSopenharmony_ci
68f08c3bdfSopenharmony_ci# Dulation of the test [sec]
69f08c3bdfSopenharmony_ciNS_DURATION=${NS_DURATION:-3600}      # 1 hour
70f08c3bdfSopenharmony_ci
71f08c3bdfSopenharmony_ci# The number of IP address (alias)
72f08c3bdfSopenharmony_ciIP_TOTAL_FOR_TCPIP=${IP_TOTAL_FOR_TCPIP:-100}
73f08c3bdfSopenharmony_ci
74f08c3bdfSopenharmony_ci#The number of the test link where tests run
75f08c3bdfSopenharmony_ciLINK_NUM=${LINK_NUM:-0}
76f08c3bdfSopenharmony_ci
77f08c3bdfSopenharmony_ci# The version of IP
78f08c3bdfSopenharmony_ciIP_VER=${IP_VER:-4}
79f08c3bdfSopenharmony_ci
80f08c3bdfSopenharmony_ci# true, if ipsec is used
81f08c3bdfSopenharmony_ciDO_IPSEC=${DO_IPSEC:-false}
82f08c3bdfSopenharmony_ci
83f08c3bdfSopenharmony_ci# The value of SPI
84f08c3bdfSopenharmony_ciSPI=${SPI:-1000}
85f08c3bdfSopenharmony_ci
86f08c3bdfSopenharmony_ci# IPsec Protocol ( ah / esp / ipcomp )
87f08c3bdfSopenharmony_ciIPSEC_PROTO=${IPSEC_PROTO:-ah}
88f08c3bdfSopenharmony_ci
89f08c3bdfSopenharmony_ci# IPsec Mode ( transport / tunnel )
90f08c3bdfSopenharmony_ciIPSEC_MODE=${IPSEC_MODE:-transport}
91f08c3bdfSopenharmony_ci
92f08c3bdfSopenharmony_ci# true, if network is delayed
93f08c3bdfSopenharmony_ciDO_NET_DELAY=${DO_NET_DELAY:-false}
94f08c3bdfSopenharmony_ci
95f08c3bdfSopenharmony_ci# Amount of network delay [ms]
96f08c3bdfSopenharmony_ciNET_DELAY=${NET_DELAY:-600}
97f08c3bdfSopenharmony_ci
98f08c3bdfSopenharmony_ci# The deflection of network delay [ms]
99f08c3bdfSopenharmony_ciNET_DELAY_DEFL=${NET_DELAY_DEFL:-200}
100f08c3bdfSopenharmony_ci
101f08c3bdfSopenharmony_ci
102f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
103f08c3bdfSopenharmony_ci#
104f08c3bdfSopenharmony_ci# Function: do_cleanup
105f08c3bdfSopenharmony_ci#
106f08c3bdfSopenharmony_ci# Description:
107f08c3bdfSopenharmony_ci#   Recover the system configuration
108f08c3bdfSopenharmony_ci#
109f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
110f08c3bdfSopenharmony_cido_cleanup()
111f08c3bdfSopenharmony_ci{
112f08c3bdfSopenharmony_ci    # Kill the tcp traffic server
113f08c3bdfSopenharmony_ci    killall_tcp_traffic
114f08c3bdfSopenharmony_ci
115f08c3bdfSopenharmony_ci    # Unset SAD/SPD
116f08c3bdfSopenharmony_ci    output_ipsec_conf flush | setkey -c >/dev/null 2>&1
117f08c3bdfSopenharmony_ci    $LTP_RSH $RHOST ${LTPROOT}/'testcases/bin/output_ipsec_conf flush | PATH=/sbin:/usr/sbin:$PATH setkey -c' >/dev/null 2>&1
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_ci    # Unset network delay
120f08c3bdfSopenharmony_ci    if [ x$rhost_ifname = x ]; then
121f08c3bdfSopenharmony_ci	rhost_ifname=`get_ifname rhost $LINK_NUM`
122f08c3bdfSopenharmony_ci    fi
123f08c3bdfSopenharmony_ci    $LTP_RSH $RHOST "PATH=/sbin:/usr/sbin:$PATH tc qdisc del dev $rhost_ifname root netem" >/dev/null 2>&1
124f08c3bdfSopenharmony_ci
125f08c3bdfSopenharmony_ci    # Clean up each interface
126f08c3bdfSopenharmony_ci    initialize_if lhost ${LINK_NUM}
127f08c3bdfSopenharmony_ci    initialize_if rhost ${LINK_NUM}
128f08c3bdfSopenharmony_ci}
129f08c3bdfSopenharmony_ci
130f08c3bdfSopenharmony_ci
131f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
132f08c3bdfSopenharmony_ci#
133f08c3bdfSopenharmony_ci# Setup
134f08c3bdfSopenharmony_ci#
135f08c3bdfSopenharmony_ci
136f08c3bdfSopenharmony_ci# Unset the maximum number of processes
137f08c3bdfSopenharmony_ciulimit -u unlimited
138f08c3bdfSopenharmony_ci
139f08c3bdfSopenharmony_ci# Output the informaion
140f08c3bdfSopenharmony_citst_resm TINFO "- Test duration is $NS_DURATION [sec]"
141f08c3bdfSopenharmony_citst_resm TINFO "- Target number of the connection is $IP_TOTAL_FOR_TCPIP"
142f08c3bdfSopenharmony_citst_resm TINFO "- Version of IP is IPv${IP_VER}"
143f08c3bdfSopenharmony_ci
144f08c3bdfSopenharmony_ciif $DO_NET_DELAY ; then
145f08c3bdfSopenharmony_ci    message=`check_netem`
146f08c3bdfSopenharmony_ci    if [ $? -ne 0 ]; then
147f08c3bdfSopenharmony_ci	tst_resm TBROK "$message"
148f08c3bdfSopenharmony_ci	exit 1
149f08c3bdfSopenharmony_ci    fi
150f08c3bdfSopenharmony_ci    tst_resm TINFO "- Network delay is ${NET_DELAY}ms +/- ${NET_DELAY_DEFL}ms"
151f08c3bdfSopenharmony_cifi
152f08c3bdfSopenharmony_ci
153f08c3bdfSopenharmony_ciif $DO_IPSEC ; then
154f08c3bdfSopenharmony_ci    message=`check_setkey`
155f08c3bdfSopenharmony_ci    if [ $? -ne 0 ]; then
156f08c3bdfSopenharmony_ci	tst_resm TBROK "$message"
157f08c3bdfSopenharmony_ci	exit 1
158f08c3bdfSopenharmony_ci    fi
159f08c3bdfSopenharmony_ci
160f08c3bdfSopenharmony_ci    case $IPSEC_PROTO in
161f08c3bdfSopenharmony_ci	ah)
162f08c3bdfSopenharmony_ci	tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]"
163f08c3bdfSopenharmony_ci	;;
164f08c3bdfSopenharmony_ci	esp)
165f08c3bdfSopenharmony_ci	tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]"
166f08c3bdfSopenharmony_ci	;;
167f08c3bdfSopenharmony_ci	ipcomp)
168f08c3bdfSopenharmony_ci	tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]"
169f08c3bdfSopenharmony_ci	;;
170f08c3bdfSopenharmony_ci    esac
171f08c3bdfSopenharmony_cifi
172f08c3bdfSopenharmony_ci
173f08c3bdfSopenharmony_ci# name of interface of the local/remote host
174f08c3bdfSopenharmony_cilhost_ifname=`get_ifname lhost $LINK_NUM`
175f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then
176f08c3bdfSopenharmony_ci    tst_resm TBROK "Failed to get the interface name at the local host"
177f08c3bdfSopenharmony_ci    exit $TST_TOTAL
178f08c3bdfSopenharmony_cifi
179f08c3bdfSopenharmony_ci
180f08c3bdfSopenharmony_cirhost_ifname=`get_ifname rhost $LINK_NUM`
181f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then
182f08c3bdfSopenharmony_ci    tst_resm TBROK "Failed to get the interface name at the remote host"
183f08c3bdfSopenharmony_ci    exit $TST_TOTAL
184f08c3bdfSopenharmony_cifi
185f08c3bdfSopenharmony_ci
186f08c3bdfSopenharmony_ci# Initialize the system configuration
187f08c3bdfSopenharmony_cido_cleanup
188f08c3bdfSopenharmony_ci
189f08c3bdfSopenharmony_ci# Call do_cleanup function before exit
190f08c3bdfSopenharmony_citrap do_cleanup 0
191f08c3bdfSopenharmony_ci
192f08c3bdfSopenharmony_ci# Make the network delay
193f08c3bdfSopenharmony_ciif $DO_NET_DELAY ; then
194f08c3bdfSopenharmony_ci    ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH tc' qdisc add dev $rhost_ifname root netem delay ${NET_DELAY}ms ${NET_DELAY_DEFL}ms distribution normal' ; echo $?'`
195f08c3bdfSopenharmony_ci    if [ $ret -ne 0 ]; then
196f08c3bdfSopenharmony_ci	tst_resm TBROK "Failed to make the delayed network"
197f08c3bdfSopenharmony_ci	exit 1
198f08c3bdfSopenharmony_ci    fi
199f08c3bdfSopenharmony_cifi
200f08c3bdfSopenharmony_ci
201f08c3bdfSopenharmony_ci# Loop for assign IP addresses
202f08c3bdfSopenharmony_ciipaddr_pair_num=0
203f08c3bdfSopenharmony_ciwhile [ $ipaddr_pair_num -lt $IP_TOTAL_FOR_TCPIP ]; do
204f08c3bdfSopenharmony_ci    # Add new IP addresses
205f08c3bdfSopenharmony_ci    x=`expr $ipaddr_pair_num \/ 255 % 255`
206f08c3bdfSopenharmony_ci    y=`expr $ipaddr_pair_num % 255`
207f08c3bdfSopenharmony_ci    if [ $x -ge 255 ]; then
208f08c3bdfSopenharmony_ci	tst_resm TINFO "This script cannot add more than $ipaddr_pair_num addresses"
209f08c3bdfSopenharmony_ci	break
210f08c3bdfSopenharmony_ci    fi
211f08c3bdfSopenharmony_ci
212f08c3bdfSopenharmony_ci    case $IP_VER in
213f08c3bdfSopenharmony_ci	4)
214f08c3bdfSopenharmony_ci	network_part="10.${x}.${y}"
215f08c3bdfSopenharmony_ci	network_broadcast=${network_part}.255
216f08c3bdfSopenharmony_ci	network_mask=24
217f08c3bdfSopenharmony_ci	lhost_addr="${network_part}.2"
218f08c3bdfSopenharmony_ci	rhost_addr="${network_part}.1"
219f08c3bdfSopenharmony_ci
220f08c3bdfSopenharmony_ci	# Set IPv4 addresses to the interfaces
221f08c3bdfSopenharmony_ci	ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
222f08c3bdfSopenharmony_ci	if [ $? -eq 2 ]; then
223f08c3bdfSopenharmony_ci		ip addr del ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname  2>&1
224f08c3bdfSopenharmony_ci		ip addr add ${lhost_addr}/${network_mask} broadcast $network_broadcast dev $lhost_ifname
225f08c3bdfSopenharmony_ci	fi
226f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
227f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
228f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any IP address at the local"
229f08c3bdfSopenharmony_ci		exit 1
230f08c3bdfSopenharmony_ci	    else
231f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
232f08c3bdfSopenharmony_ci	    fi
233f08c3bdfSopenharmony_ci	    break
234f08c3bdfSopenharmony_ci	fi
235f08c3bdfSopenharmony_ci
236f08c3bdfSopenharmony_ci	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
237f08c3bdfSopenharmony_ci
238f08c3bdfSopenharmony_ci	if [ $ret -eq 2 ]; then
239f08c3bdfSopenharmony_ci		$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname
240f08c3bdfSopenharmony_ci		ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} broadcast $network_broadcast dev $rhost_ifname' ; echo $?'`
241f08c3bdfSopenharmony_ci	fi
242f08c3bdfSopenharmony_ci
243f08c3bdfSopenharmony_ci	if [ $ret -ne 0 ]; then
244f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
245f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any IP address at the remote"
246f08c3bdfSopenharmony_ci		exit 1
247f08c3bdfSopenharmony_ci	    else
248f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
249f08c3bdfSopenharmony_ci	    fi
250f08c3bdfSopenharmony_ci	    break
251f08c3bdfSopenharmony_ci	fi
252f08c3bdfSopenharmony_ci	;;
253f08c3bdfSopenharmony_ci
254f08c3bdfSopenharmony_ci	6)
255f08c3bdfSopenharmony_ci	hex_x=`printf %x $x`
256f08c3bdfSopenharmony_ci	hex_y=`printf %x $y`
257f08c3bdfSopenharmony_ci
258f08c3bdfSopenharmony_ci	network_part="fd00:1:${hex_x}:${hex_y}"
259f08c3bdfSopenharmony_ci	network_mask=64
260f08c3bdfSopenharmony_ci	lhost_addr="${network_part}::2"
261f08c3bdfSopenharmony_ci	rhost_addr="${network_part}::1"
262f08c3bdfSopenharmony_ci
263f08c3bdfSopenharmony_ci	# Set IPv6 addresses to the interfaces
264f08c3bdfSopenharmony_ci	ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
265f08c3bdfSopenharmony_ci
266f08c3bdfSopenharmony_ci	if [ $? -eq 2 ]; then
267f08c3bdfSopenharmony_ci		ip addr del ${lhost_addr}/${network_mask} dev $lhost_ifname  2>&1
268f08c3bdfSopenharmony_ci		ip addr add ${lhost_addr}/${network_mask} dev $lhost_ifname
269f08c3bdfSopenharmony_ci	fi
270f08c3bdfSopenharmony_ci
271f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
272f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
273f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any IP address at the local"
274f08c3bdfSopenharmony_ci		exit 1
275f08c3bdfSopenharmony_ci	    else
276f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of IP address at the local host seems to reach the maximum. The number is $ipaddr_pair_num"
277f08c3bdfSopenharmony_ci	    fi
278f08c3bdfSopenharmony_ci	    break
279f08c3bdfSopenharmony_ci	fi
280f08c3bdfSopenharmony_ci
281f08c3bdfSopenharmony_ci	ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
282f08c3bdfSopenharmony_ci
283f08c3bdfSopenharmony_ci	if [ $ret -eq 2 ]; then
284f08c3bdfSopenharmony_ci		$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr del ${rhost_addr}/${network_mask} dev $rhost_ifname
285f08c3bdfSopenharmony_ci		ret=`$LTP_RSH $RHOST 'PATH=/sbin:/usr/sbin:$PATH ip' addr add ${rhost_addr}/${network_mask} dev $rhost_ifname' ; echo $?'`
286f08c3bdfSopenharmony_ci	fi
287f08c3bdfSopenharmony_ci
288f08c3bdfSopenharmony_ci	if [ $ret -ne 0 ]; then
289f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
290f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any IP address at the remote"
291f08c3bdfSopenharmony_ci		exit 1
292f08c3bdfSopenharmony_ci	    else
293f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of IP address at the remote host seems to reach the maximum. The number is $ipaddr_pair_num"
294f08c3bdfSopenharmony_ci	    fi
295f08c3bdfSopenharmony_ci	    break
296f08c3bdfSopenharmony_ci	fi
297f08c3bdfSopenharmony_ci	;;
298f08c3bdfSopenharmony_ci    esac
299f08c3bdfSopenharmony_ci
300f08c3bdfSopenharmony_ci    # Set SAD/SPD
301f08c3bdfSopenharmony_ci    if $DO_IPSEC ; then
302f08c3bdfSopenharmony_ci	ipsec_log=`mktemp -p $TMPDIR`
303f08c3bdfSopenharmony_ci	output_ipsec_conf src \
304f08c3bdfSopenharmony_ci	    $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr \
305f08c3bdfSopenharmony_ci		    | setkey -c 2>&1 | tee $ipsec_log
306f08c3bdfSopenharmony_ci	if [ $? -ne 0 -o -s $ipsec_log ]; then
307f08c3bdfSopenharmony_ci	    rm -f $ipsec_log
308f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
309f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any SAD/SPD"
310f08c3bdfSopenharmony_ci		exit 1
311f08c3bdfSopenharmony_ci	    else
312f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the local host."
313f08c3bdfSopenharmony_ci	    fi
314f08c3bdfSopenharmony_ci	    break
315f08c3bdfSopenharmony_ci	fi
316f08c3bdfSopenharmony_ci	rm -f $ipsec_log
317f08c3bdfSopenharmony_ci
318f08c3bdfSopenharmony_ci	$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/output_ipsec_conf dst $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr' | PATH=/sbin:/usr/sbin:$PATH setkey -c' 2>&1 | tee $ipsec_log
319f08c3bdfSopenharmony_ci	if [ $? -ne 0 -o -s $ipsec_log ]; then
320f08c3bdfSopenharmony_ci	    rm -f $ipsec_log
321f08c3bdfSopenharmony_ci	    if [ $ipaddr_pair_num -eq 0 ]; then
322f08c3bdfSopenharmony_ci		tst_resm TBROK "Failed to add any SAD/SPD"
323f08c3bdfSopenharmony_ci		exit 1
324f08c3bdfSopenharmony_ci	    else
325f08c3bdfSopenharmony_ci		tst_resm TINFO "The number of SAD/SPD seems to reach the maximum at the remote host."
326f08c3bdfSopenharmony_ci	    fi
327f08c3bdfSopenharmony_ci	    break
328f08c3bdfSopenharmony_ci	fi
329f08c3bdfSopenharmony_ci	rm -f $ipsec_log
330f08c3bdfSopenharmony_ci    fi
331f08c3bdfSopenharmony_ci
332f08c3bdfSopenharmony_ci    # Check the connectivity
333f08c3bdfSopenharmony_ci    case $IP_VER in
334f08c3bdfSopenharmony_ci	4)
335f08c3bdfSopenharmony_ci	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv4_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
336f08c3bdfSopenharmony_ci	if [ $ret -ne 0 ]; then
337f08c3bdfSopenharmony_ci	    tst_resm TBROK "No IPv4 connectivity among ${ipaddr_pair_num}th IP address pair"
338f08c3bdfSopenharmony_ci	    exit 1
339f08c3bdfSopenharmony_ci	fi
340f08c3bdfSopenharmony_ci	;;
341f08c3bdfSopenharmony_ci
342f08c3bdfSopenharmony_ci	6)
343f08c3bdfSopenharmony_ci	ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/check_icmpv6_connectivity $rhost_ifname $lhost_addr' ; echo $?'`
344f08c3bdfSopenharmony_ci	if [ $ret -ne 0 ]; then
345f08c3bdfSopenharmony_ci	    tst_resm TBROK "No IPv6 connectivity among ${ipaddr_pair_num}th IP address pair"
346f08c3bdfSopenharmony_ci	    exit 1
347f08c3bdfSopenharmony_ci	fi
348f08c3bdfSopenharmony_ci	;;
349f08c3bdfSopenharmony_ci    esac
350f08c3bdfSopenharmony_ci
351f08c3bdfSopenharmony_ci    if [ $? -ne 0 ]; then
352f08c3bdfSopenharmony_ci	tst_resm TFAIL "There is no connectivity."
353f08c3bdfSopenharmony_ci	exit 1
354f08c3bdfSopenharmony_ci    fi
355f08c3bdfSopenharmony_ci
356f08c3bdfSopenharmony_ci    ipaddr_pair_num=`expr $ipaddr_pair_num + 1`
357f08c3bdfSopenharmony_cidone
358f08c3bdfSopenharmony_ci
359f08c3bdfSopenharmony_ci
360f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
361f08c3bdfSopenharmony_ci#
362f08c3bdfSopenharmony_ci# Main
363f08c3bdfSopenharmony_ci#
364f08c3bdfSopenharmony_ci#
365f08c3bdfSopenharmony_ci
366f08c3bdfSopenharmony_ci# Find the available consecutive ports
367f08c3bdfSopenharmony_ciserver_port=`find_portbundle tcp 1025 1`
368f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then
369f08c3bdfSopenharmony_ci    tst_resm TFAIL "No port is available."
370f08c3bdfSopenharmony_ci    exit 1
371f08c3bdfSopenharmony_cifi
372f08c3bdfSopenharmony_ci
373f08c3bdfSopenharmony_ci# Run a server
374f08c3bdfSopenharmony_ciinfo_file=`mktemp -p $TMPDIR`
375f08c3bdfSopenharmony_ci
376f08c3bdfSopenharmony_cins-tcpserver -b -c -f $IP_VER -p $server_port -o $info_file
377f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then
378f08c3bdfSopenharmony_ci    tst_resm TFAIL "Failed to run tcp traffic server."
379f08c3bdfSopenharmony_ci    rm -f $info_file
380f08c3bdfSopenharmony_ci    exit 1
381f08c3bdfSopenharmony_cifi
382f08c3bdfSopenharmony_ci
383f08c3bdfSopenharmony_ciwhile true ; do
384f08c3bdfSopenharmony_ci    if [ -s $info_file ]; then
385f08c3bdfSopenharmony_ci	break
386f08c3bdfSopenharmony_ci    fi
387f08c3bdfSopenharmony_cidone
388f08c3bdfSopenharmony_ci
389f08c3bdfSopenharmony_ciserver_pid=`grep PID: $info_file | cut -f 2 -d ' '`
390f08c3bdfSopenharmony_cirm -f $info_file
391f08c3bdfSopenharmony_ci
392f08c3bdfSopenharmony_ci# Make connections
393f08c3bdfSopenharmony_ciconnection_num=0
394f08c3bdfSopenharmony_ciwhile [ $connection_num -lt $ipaddr_pair_num ]; do
395f08c3bdfSopenharmony_ci    # IP addresses
396f08c3bdfSopenharmony_ci    x=`expr $connection_num \/ 255 % 255`
397f08c3bdfSopenharmony_ci    y=`expr $connection_num % 255`
398f08c3bdfSopenharmony_ci
399f08c3bdfSopenharmony_ci    case $IP_VER in
400f08c3bdfSopenharmony_ci	4)
401f08c3bdfSopenharmony_ci	lhost_addr="10.${x}.${y}.2"
402f08c3bdfSopenharmony_ci	;;
403f08c3bdfSopenharmony_ci
404f08c3bdfSopenharmony_ci	6)
405f08c3bdfSopenharmony_ci	hex_x=`printf %x $x`
406f08c3bdfSopenharmony_ci	hex_y=`printf %x $y`
407f08c3bdfSopenharmony_ci	lhost_addr="fd00:1:${hex_x}:${hex_y}::2"
408f08c3bdfSopenharmony_ci	;;
409f08c3bdfSopenharmony_ci    esac
410f08c3bdfSopenharmony_ci
411f08c3bdfSopenharmony_ci    ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-tcpclient -b -f $IP_VER -S $lhost_addr -p $server_port' ; echo $?'`
412f08c3bdfSopenharmony_ci    if [ $ret -ne 0 ]; then
413f08c3bdfSopenharmony_ci	if [ $connection_num -eq 0 ]; then
414f08c3bdfSopenharmony_ci	    tst_resm TFAIL "Failed to run any client"
415f08c3bdfSopenharmony_ci		exit 1
416f08c3bdfSopenharmony_ci	else
417f08c3bdfSopenharmony_ci	    tst_resm TINFO "$connection_num seems the maximum number of the client"
418f08c3bdfSopenharmony_ci	fi
419f08c3bdfSopenharmony_ci	break
420f08c3bdfSopenharmony_ci    fi
421f08c3bdfSopenharmony_ci    connection_num=`expr $connection_num + 1`
422f08c3bdfSopenharmony_cidone
423f08c3bdfSopenharmony_ci
424f08c3bdfSopenharmony_ci# Watch the TCP traffic server
425f08c3bdfSopenharmony_cistart_epoc=`date +%s`
426f08c3bdfSopenharmony_ciwhile true ; do
427f08c3bdfSopenharmony_ci    current_epoc=`date +%s`
428f08c3bdfSopenharmony_ci    elapse_epoc=`expr $current_epoc - $start_epoc`
429f08c3bdfSopenharmony_ci
430f08c3bdfSopenharmony_ci    if [ $elapse_epoc -ge $NS_DURATION ]; then
431f08c3bdfSopenharmony_ci	killall -SIGHUP ns-tcpserver
432f08c3bdfSopenharmony_ci	break
433f08c3bdfSopenharmony_ci    else
434f08c3bdfSopenharmony_ci	ps auxw | fgrep ns-tcpserver | fgrep -l $server_pid >/dev/null 2>&1
435f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
436f08c3bdfSopenharmony_ci	    tst_resm TFAIL "tcp traffic server is dead in $elapse_epoc [sec]"
437f08c3bdfSopenharmony_ci	    exit 1
438f08c3bdfSopenharmony_ci	fi
439f08c3bdfSopenharmony_ci    fi
440f08c3bdfSopenharmony_ci    sleep 1
441f08c3bdfSopenharmony_cidone
442f08c3bdfSopenharmony_ci
443f08c3bdfSopenharmony_ci
444f08c3bdfSopenharmony_ci#-----------------------------------------------------------------------
445f08c3bdfSopenharmony_ci#
446f08c3bdfSopenharmony_ci# Clean up
447f08c3bdfSopenharmony_ci#
448f08c3bdfSopenharmony_ci
449f08c3bdfSopenharmony_citst_resm TPASS "Test is finished successfully."
450f08c3bdfSopenharmony_ciexit 0
451