aboutsummaryrefslogtreecommitdiff
path: root/testcases/network/stress/route/route6-change-gw
blob: 96fd7ee66fd48d76749330d4f5cb393af710f63d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/sh
################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2006                 ##
##                                                                            ##
## This program is free software;  you can redistribute it and#or modify      ##
## it under the terms of the GNU General Public License as published by       ##
## the Free Software Foundation; either version 2 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program is distributed in the hope that it will be useful, but        ##
## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
## for more details.                                                          ##
##                                                                            ##
## You should have received a copy of the GNU General Public License          ##
## along with this program;  if not, write to the Free Software               ##
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
##                                                                            ##
##                                                                            ##
################################################################################
#
# File:
#   route6-change-gw
#
# Description:
#   Verify the kernel is not crashed when the gateway of an IPv6 route is
#   changed frequently
#    test01 - by route command
#    test02 - by ip command
#
# Setup:
#   See testcases/network/stress/README
#
# Author:
#   Mitsuru Chinen <mitch@jp.ibm.com>
#
# History:
#	Mar 16 2006 - Created (Mitsuru Chinen)
#
#-----------------------------------------------------------------------
# Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

# Make sure the value of LTPROOT
LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
export LTPROOT

# Total number of the test case
TST_TOTAL=2
export TST_TOTAL

# Default of the test case ID and the test case count
TCID=route6-change-gw
TST_COUNT=0
export TCID
export TST_COUNT

# Check the environmanet variable
. check_envval || exit $TST_TOTAL

# The number of times where route is changed
NS_TIMES=${NS_TIMES:-10000}

# The number of the test link where tests run
LINK_NUM=${LINK_NUM:-0}

# Network portion of the IPv6 address
IPV6_NETWORK="fec0:1:1:1"

# Netmask of for the tested network
IPV6_NETMASK_NUM=64

# Host portion of the IPv6 address
LHOST_IPV6_HOST=":2"		# src
RHOST_IPV6_HOST_TOP="10"	# gateway
RHOST_IPV6_HOST_LAST="19"

# The destination network
DST_NETWORK="fd00:100:1:1"	# dest network would be fd00:100:1:1:::/64
DST_HOST="5"
DST_PORT="7"


#-----------------------------------------------------------------------
#
# NAME:
#   do_setup
#
# DESCRIPTION:
#   Make a IPv6 connectivity
#
# SET VALUES:
#   rhost_ipv6addr	- IPv6 Address of the remote host
#   lhost_ifname	- Interface name of the local host
#   rhost_ifname	- Interface name of the remote host
#
#-----------------------------------------------------------------------
do_setup()
{
    TCID=route6-change-gw
    TST_COUNT=0

    # Get the Interface name of local host
    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to get the interface name at the local host"
	exit $TST_TOTAL
    fi

    # Get the Interface name of remote host
    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to get the interface name at the remote host"
	exit $TST_TOTAL
    fi

    # Initialize the interfaces of the remote host
    initialize_if rhost ${LINK_NUM}

    # Set IPv6 address to the interface of the remote host
    rhost_part=$RHOST_IPV6_HOST_TOP
    rhost_part_hex=`printf "%x" $rhost_part`
    while [ $rhost_part -le $RHOST_IPV6_HOST_LAST ]; do
	rhost_part_hex=":`printf "%x" $rhost_part`"
	add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${rhost_part_hex}
	if [ $? -ne 0 ]; then
	    tst_resm TBROK "Failed to assign IP address to the interface at the remote host"
	    exit $TST_TOTAL
	fi
	rhost_part=`expr $rhost_part + 1`
    done
}


#-----------------------------------------------------------------------
#
# NAME:
#   do_cleanup
#
# DESCRIPTION:
#   Recover the tested interfaces
#
#-----------------------------------------------------------------------
do_cleanup()
{
    killall -SIGHUP ns-udpsender >/dev/null 2>&1

    # Initialize the interfaces
    initialize_if lhost ${LINK_NUM}
    initialize_if rhost ${LINK_NUM}
}


#-----------------------------------------------------------------------
#
# FUNCTION:
#   test_body
#
# DESCRIPTION:
#   main code of the test
#
# Arguments:
#   $1: define the test type
#       1 - route command case
#       2 - ip command case
#
#-----------------------------------------------------------------------
test_body()
{
    test_type=$1

    TCID=route6-change-gw0${test_type}
    TST_COUNT=$test_type

    case $test_type in
	1)
	test_command="route"
	;;
	2)
	test_command="ip"
	;;
	*)
	tst_resm TBROK "unspecified case"
	return 1
	;;
    esac

    tst_resm TINFO "Verify the kernel is not crashed when the gateway of an IPv6 route is changed frequently by $test_command command in $NS_TIMES times"

    # Initialize the interface of the local host
    initialize_if lhost ${LINK_NUM}

    # Assign IPv6 address to the interface of the local host
    add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to assign an IPv6 address at the local host"
	return 1
    fi

    # Check the connectivity to the gateway
    rhost_part=$RHOST_IPV6_HOST_TOP
    rhost_part_hex=":`printf "%x" $rhost_part`"
    check_icmpv6_connectivity $lhost_ifname ${IPV6_NETWORK}:${rhost_part_hex}
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
	return 1
    fi

    # Set the variables regarding the destination host
    dst_addr=${DST_NETWORK}::${DST_HOST}
    dst_network=${DST_NETWORK}::

    # Set the first route
    case $test_type in
	1)
	route -A inet6 add ${dst_network}/64 gw ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname
	;;
	2)
	ip -f inet6 route add ${dst_network}/64 via ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname
	;;
    esac

    # Load the route with UDP traffic
    ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -b -s 1452
    if [ $? -ne 0 ]; then
	tst_resm TFAIL "Failed to run a UDP datagram sender"
	return 1
    fi

    # Loop for changing the route
    cnt=0
    while [ $cnt -lt $NS_TIMES ]; do
	pre_rhost_part_hex=$rhost_part_hex
	rhost_part=`expr $rhost_part + 1`
	if [ $rhost_part -gt $RHOST_IPV6_HOST_LAST ]; then
	    rhost_part=$RHOST_IPV6_HOST_TOP
	fi
	rhost_part_hex=":`printf "%x" $rhost_part`"

	case $test_type in
	    1)
	    route -A inet6 add ${dst_network}/64 gw ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname
	    route -A inet6 del ${dst_network}/64 gw ${IPV6_NETWORK}:${pre_rhost_part_hex} dev $lhost_ifname
	    ;;
	    2)
	    ip -f inet6 route add ${dst_network}/64 via ${IPV6_NETWORK}:${rhost_part_hex} dev $lhost_ifname
	    ip -f inet6 route del ${dst_network}/64 via ${IPV6_NETWORK}:${pre_rhost_part_hex} dev $lhost_ifname
	    ;;
	esac
	if [ $? -ne 0 ]; then
	    tst_resm TFAIL "Failed to change the gateway to ${IPV6_NETWORK}.${rhost_part}"
	    return 1
	fi

	# Rerun if udp datagram sender is dead
	ps auxw | fgrep -v grep | grep ns-udpsender > /dev/null
	if [ $? -ne 0 ]; then
	    ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
	    if [ $? -ne 0 ]; then
		tst_resm TFAIL "Failed to run a UDP datagram sender"
		return 1
	    fi
	fi

	cnt=`expr $cnt + 1`
    done

    # Kill the udp datagram sender
    killall -SIGHUP ns-udpsender >/dev/null 2>&1

    tst_resm TPASS "Test is finished correctly."
    return 0
}


#-----------------------------------------------------------------------
#
# Main
#
# Exit Value:
#   The number of the failure
#
#-----------------------------------------------------------------------

RC=0
do_setup
test_body 1 || RC=`expr $RC + 1`      # Case of route command
test_body 2 || RC=`expr $RC + 1`      # Case of ip command
do_cleanup

exit $RC