1#!/bin/sh
2# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
3# Copyright (c) 2016-2017 Petr Vorel <pvorel@suse.cz>
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# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
20#
21
22[ -z "$TST_LIB_LOADED" ] && . test.sh
23
24init_ltp_netspace()
25{
26	local pid=
27
28	if [ ! -f /var/run/netns/ltp_ns ]; then
29		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
30		pid="$(ROD ns_create net,mnt)"
31		mkdir -p /var/run/netns
32		ROD ln -s /proc/$pid/ns/net /var/run/netns/ltp_ns
33		ROD ns_exec $pid net,mnt mount --make-rprivate /sys
34		ROD ns_exec $pid net,mnt mount -t sysfs none /sys
35		ROD ns_ifmove ltp_ns_veth1 $pid
36		ROD ns_exec $pid net,mnt ip li set lo up
37	fi
38
39	LHOST_IFACES="${LHOST_IFACES:-ltp_ns_veth2}"
40	RHOST_IFACES="${RHOST_IFACES:-ltp_ns_veth1}"
41
42	export TST_INIT_NETNS="no"
43
44	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
45	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
46
47	tst_restore_ipaddr
48	tst_restore_ipaddr rhost
49
50	tst_wait_ipv6_dad
51}
52
53# Run command on remote host.
54# Options:
55# -b run in background
56# -B run in background and save output to $TST_TMPDIR/bg.cmd
57# -s safe option, if something goes wrong, will exit with TBROK
58# -c specify command to run
59tst_rhost_run()
60{
61	local pre_cmd=
62	local post_cmd=' || echo RTERR'
63	local out=
64	local user="root"
65	local cmd=
66	local safe=0
67	local bg=
68
69	OPTIND=0
70
71	while getopts :bBsc:u: opt; do
72		case "$opt" in
73		b|B) [ "$TST_USE_NETNS" ] && pre_cmd= || pre_cmd="nohup"
74		   [ "$opt" = b ] && bg="/dev/null" || bg="$TST_TMPDIR/bg.cmd"
75		   post_cmd=" > $bg 2>&1 &"
76		   out="1> /dev/null"
77		;;
78		s) safe=1 ;;
79		c) cmd="$OPTARG" ;;
80		u) user="$OPTARG" ;;
81		*) tst_brkm TBROK "tst_rhost_run: unknown option: $OPTARG" ;;
82		esac
83	done
84
85	OPTIND=0
86
87	if [ -z "$cmd" ]; then
88		[ "$safe" -eq 1 ] && \
89			tst_brkm TBROK "tst_rhost_run: command not defined"
90		tst_resm TWARN "tst_rhost_run: command not defined"
91		return 1
92	fi
93
94	local output=
95	local ret=0
96	if [ -n "${TST_USE_SSH:-}" ]; then
97		output=`ssh -n -q $user@$RHOST "sh -c \
98			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
99	elif [ -n "$TST_USE_NETNS" ]; then
100		output=`$LTP_NETNS sh -c \
101			"$pre_cmd $cmd $post_cmd" $out 2>&1 || echo 'RTERR'`
102	else
103		output=`rsh -n -l $user $RHOST "sh -c \
104			'$pre_cmd $cmd $post_cmd'" $out 2>&1 || echo 'RTERR'`
105	fi
106	echo "$output" | grep -q 'RTERR$' && ret=1
107	if [ $ret -eq 1 ]; then
108		output=$(echo "$output" | sed 's/RTERR//')
109		[ "$safe" -eq 1 ] && \
110			tst_brkm TBROK "'$cmd' failed on '$RHOST': '$output'"
111	fi
112
113	[ -z "$out" -a -n "$output" ] && echo "$output"
114
115	return $ret
116}
117
118EXPECT_RHOST_PASS()
119{
120	tst_rhost_run -c "$*" > /dev/null
121	if [ $? -eq 0 ]; then
122		tst_resm TPASS "$* passed as expected"
123	else
124		tst_resm TFAIL "$* failed unexpectedly"
125	fi
126}
127
128EXPECT_RHOST_FAIL()
129{
130	tst_rhost_run -c "$* 2> /dev/null"
131	if [ $? -ne 0 ]; then
132		tst_resm TPASS "$* failed as expected"
133	else
134		tst_resm TFAIL "$* passed unexpectedly"
135	fi
136}
137
138# Get test interface names for local/remote host.
139# tst_get_ifaces [TYPE]
140# TYPE: { lhost | rhost }; Default value is 'lhost'.
141tst_get_ifaces()
142{
143	local type="${1:-lhost}"
144	if [ "$type" = "lhost" ]; then
145		echo "$LHOST_IFACES"
146	else
147		echo "$RHOST_IFACES"
148	fi
149}
150
151# Get HW addresses from defined test interface names.
152# tst_get_hwaddrs [TYPE]
153# TYPE: { lhost | rhost }; Default value is 'lhost'.
154tst_get_hwaddrs()
155{
156	local type="${1:-lhost}"
157	local addr=
158	local list=
159
160	for eth in $(tst_get_ifaces $type); do
161
162		local addr_path="/sys/class/net/${eth}/address"
163
164		case $type in
165		lhost) addr=$(cat $addr_path) ;;
166		rhost) addr=$(tst_rhost_run -s -c "cat $addr_path")
167		esac
168
169		[ -z "$list" ] && list="$addr" || list="$list $addr"
170	done
171	echo "$list"
172}
173
174# Get test HW address.
175# tst_hwaddr [TYPE] [LINK]
176# TYPE: { lhost | rhost }; Default value is 'lhost'.
177# LINK: link number starting from 0. Default value is '0'.
178tst_hwaddr()
179{
180	local type="${1:-lhost}"
181	local link_num="${2:-0}"
182	local hwaddrs=
183	link_num=$(( $link_num + 1 ))
184	[ "$type" = "lhost" ] && hwaddrs=$LHOST_HWADDRS || hwaddrs=$RHOST_HWADDRS
185	echo "$hwaddrs" | awk '{ print $'"$link_num"' }'
186}
187
188# Get test interface name.
189# tst_iface [TYPE] [LINK]
190# TYPE: { lhost | rhost }; Default value is 'lhost'.
191# LINK: link number starting from 0. Default value is '0'.
192tst_iface()
193{
194	local type="${1:-lhost}"
195	local link_num="${2:-0}"
196	link_num="$(( $link_num + 1 ))"
197	echo "$(tst_get_ifaces $type)" | awk '{ print $'"$link_num"' }'
198}
199
200# Blank for an IPV4 test; 6 for an IPV6 test.
201TST_IPV6=
202
203tst_read_opts()
204{
205	OPTIND=0
206	while getopts ":6" opt; do
207		case "$opt" in
208		6)
209			TST_IPV6=6;;
210		esac
211	done
212	OPTIND=0
213}
214
215tst_read_opts $*
216
217# Get IP address
218# tst_ipaddr [TYPE]
219# TYPE: { lhost | rhost }; Default value is 'lhost'.
220tst_ipaddr()
221{
222	local type="${1:-lhost}"
223	if [ "$TST_IPV6" ]; then
224		[ "$type" = "lhost" ] && echo "$IPV6_LHOST" || echo "$IPV6_RHOST"
225	else
226		[ "$type" = "lhost" ] && echo "$IPV4_LHOST" || echo "$IPV4_RHOST"
227	fi
228}
229
230# Get IP address of unused network, specified either by type and counter
231# or by net and host.
232# tst_ipaddr_un [-cCOUNTER] [TYPE]
233# tst_ipaddr_un NET_ID [HOST_ID]
234# TYPE: { lhost | rhost }; Default value is 'lhost'.
235# COUNTER: Integer value for counting HOST_ID and NET_ID. Default is 1.
236# NET_ID: Integer or hex value of net. For IPv4 is 3rd octet, for IPv6
237# is 3rd hextet.
238# HOST_ID: Integer or hex value of host. For IPv4 is 4th octet, for
239# IPv6 is the last hextet. Default value is 0.
240tst_ipaddr_un()
241{
242	local counter host_id net_id max_host_id max_net_id tmp type
243	local OPTIND
244
245	while getopts "c:" opt; do
246		case $opt in
247			c) counter="$OPTARG";;
248		esac
249	done
250	shift $(($OPTIND - 1))
251
252	[ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255
253
254	if [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ]; then
255		[ -z "$counter" ] && counter=1
256		[ $counter -lt 1 ] && counter=1
257		type="${1:-lhost}"
258		max_host_id=$((max_net_id - 1))
259		tmp=$((counter * 2))
260		[ "$type" = "rhost" ] && tmp=$((tmp - 1))
261
262		host_id=$((tmp % max_host_id))
263		net_id=$((tmp / max_host_id))
264
265		if [ $host_id -eq 0 ]; then
266			host_id=$max_host_id
267			net_id=$((net_id - 1))
268		fi
269	else
270		net_id="$1"
271		host_id="${2:-0}"
272		if [ "$TST_IPV6" ]; then
273			net_id=$(printf %d $net_id)
274			host_id=$(printf %d $host_id)
275		fi
276		[ $net_id -lt 0 ] && net_id=0
277		[ $host_id -lt 0 ] && host_id=1
278	fi
279
280	net_id=$((net_id % max_net_id))
281	host_id=$((host_id % max_net_id))
282
283	if [ -z "$TST_IPV6" ]; then
284		echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}"
285		return
286	fi
287
288	[ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id=
289	[ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id=
290	[ "$net_id" ] && net_id=":$net_id"
291	echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}"
292}
293
294# tst_init_iface [TYPE] [LINK]
295# TYPE: { lhost | rhost }; Default value is 'lhost'.
296# LINK: link number starting from 0. Default value is '0'.
297tst_init_iface()
298{
299	local type="${1:-lhost}"
300	local link_num="${2:-0}"
301	local iface="$(tst_iface $type $link_num)"
302	tst_resm TINFO "initialize '$type' '$iface' interface"
303
304	if [ "$type" = "lhost" ]; then
305		ip xfrm policy flush || return $?
306		ip xfrm state flush || return $?
307		ip link set $iface down || return $?
308		ip route flush dev $iface || return $?
309		ip addr flush dev $iface || return $?
310		ip link set $iface up
311		return $?
312	fi
313
314	tst_rhost_run -c "ip xfrm policy flush" || return $?
315	tst_rhost_run -c "ip xfrm state flush" || return $?
316	tst_rhost_run -c "ip link set $iface down" || return $?
317	tst_rhost_run -c "ip route flush dev $iface" || return $?
318	tst_rhost_run -c "ip addr flush dev $iface" || return $?
319	tst_rhost_run -c "ip link set $iface up"
320}
321
322# tst_add_ipaddr [TYPE] [LINK]
323# TYPE: { lhost | rhost }; Default value is 'lhost'.
324# LINK: link number starting from 0. Default value is '0'.
325tst_add_ipaddr()
326{
327	local type="${1:-lhost}"
328	local link_num="${2:-0}"
329	local mask
330
331	if [ "$TST_IPV6" ]; then
332		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
333	else
334		[ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX
335	fi
336
337	local iface=$(tst_iface $type $link_num)
338
339	if [ $type = "lhost" ]; then
340		tst_resm TINFO "set local addr $(tst_ipaddr)/$mask"
341		ip addr add $(tst_ipaddr)/$mask dev $iface
342		return $?
343	fi
344
345	tst_resm TINFO "set remote addr $(tst_ipaddr rhost)/$mask"
346	tst_rhost_run -c "ip addr add $(tst_ipaddr rhost)/$mask dev $iface"
347}
348
349# tst_restore_ipaddr [TYPE] [LINK]
350# Restore default ip addresses defined in network.sh
351# TYPE: { lhost | rhost }; Default value is 'lhost'.
352# LINK: link number starting from 0. Default value is '0'.
353tst_restore_ipaddr()
354{
355	local type="${1:-lhost}"
356	local link_num="${2:-0}"
357
358	tst_init_iface $type $link_num || return $?
359
360	local ret=0
361	local backup_tst_ipv6=$TST_IPV6
362	TST_IPV6= tst_add_ipaddr $type $link_num || ret=$?
363	TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$?
364	TST_IPV6=$backup_tst_ipv6
365
366	return $ret
367}
368
369# tst_wait_ipv6_dad [LHOST_IFACE] [RHOST_IFACE]
370# wait for IPv6 DAD completion
371tst_wait_ipv6_dad()
372{
373	local ret=
374	local i=
375	local iface_loc=${1:-$(tst_iface)}
376	local iface_rmt=${2:-$(tst_iface rhost)}
377
378	for i in $(seq 1 50); do
379		ip a sh $iface_loc | grep -q tentative
380		ret=$?
381
382		tst_rhost_run -c "ip a sh $iface_rmt | grep -q tentative"
383
384		[ $ret -ne 0 -a $? -ne 0 ] && return
385
386		[ $(($i % 10)) -eq 0 ] && \
387			tst_resm TINFO "wait for IPv6 DAD completion $((i / 10))/5 sec"
388
389		tst_sleep 100ms
390	done
391}
392
393tst_dump_rhost_cmd()
394{
395	tst_rhost_run -c "cat $TST_TMPDIR/bg.cmd"
396}
397
398# Run network load test, see 'netstress -h' for option description
399tst_netload()
400{
401	local rfile="tst_netload.res"
402	local expect_res="pass"
403	local ret=0
404	local type="tcp"
405	local hostopt=
406	local setup_srchost=0
407	# common options for client and server
408	local cs_opts=
409
410	local c_num="${TST_NETLOAD_CLN_NUMBER:-2}"
411	local c_requests="${TST_NETLOAD_CLN_REQUESTS:-500000}"
412	local c_opts=
413
414	# number of server replies after which TCP connection is closed
415	local s_replies="${TST_NETLOAD_MAX_SRV_REPLIES:-500000}"
416	local s_opts=
417
418	OPTIND=0
419	while getopts :a:H:d:n:N:r:R:S:b:t:T:fFe:m:A: opt; do
420		case "$opt" in
421		a) c_num="$OPTARG" ;;
422		H) c_opts="${c_opts}-H $OPTARG "
423		   hostopt="$OPTARG" ;;
424		d) rfile="$OPTARG" ;;
425		n) c_opts="${c_opts}-n $OPTARG " ;;
426		N) c_opts="${c_opts}-N $OPTARG " ;;
427		r) c_requests="$OPTARG" ;;
428		A) c_opts="${c_opts}-A $OPTARG " ;;
429		R) s_replies="$OPTARG" ;;
430		S) c_opts="${c_opts}-S $OPTARG "
431		   setup_srchost=1 ;;
432		b) cs_opts="${cs_opts}-b $OPTARG " ;;
433		t) cs_opts="${cs_opts}-t $OPTARG " ;;
434		T) cs_opts="${cs_opts}-T $OPTARG "
435		   type="$OPTARG" ;;
436		m) cs_opts="${cs_opts}-m $OPTARG " ;;
437		f) cs_opts="${cs_opts}-f " ;;
438		F) cs_opts="${cs_opts}-F " ;;
439		e) expect_res="$OPTARG" ;;
440		*) tst_brkm TBROK "tst_netload: unknown option: $OPTARG" ;;
441		esac
442	done
443	OPTIND=0
444
445	[ "$setup_srchost" = 1 ] && s_opts="${s_opts}-S $hostopt "
446
447	local expect_ret=0
448	[ "$expect_res" != "pass" ] && expect_ret=1
449
450	local ptype="stream"
451	[ "$type" = "udp" ] && ptype="dgram"
452
453	local port=$(tst_rhost_run -c "tst_get_unused_port ipv6 $ptype")
454	[ $? -ne 0 ] && tst_brkm TBROK "failed to get unused port"
455
456	tst_rhost_run -c "pkill -9 netstress\$"
457
458	c_opts="${cs_opts}${c_opts}-a $c_num -r $c_requests -d $rfile -g $port"
459	s_opts="${cs_opts}${s_opts}-R $s_replies -g $port"
460
461	tst_resm TINFO "run server 'netstress $s_opts'"
462	tst_rhost_run -s -B -c "netstress $s_opts"
463
464	tst_resm TINFO "check that server port in 'LISTEN' state"
465	local sec_waited=
466
467	local sock_cmd=
468	if [ "$type" = "sctp" ]; then
469		sock_cmd="netstat -naS | grep $port | grep -q LISTEN"
470	else
471		sock_cmd="ss -ln$(echo $type | head -c1) | grep -q $port"
472	fi
473
474	for sec_waited in $(seq 1 1200); do
475		tst_rhost_run -c "$sock_cmd" && break
476		if [ $sec_waited -eq 1200 ]; then
477			tst_dump_rhost_cmd
478			tst_rhost_run -c "ss -dutnp | grep $port"
479			tst_brkm TFAIL "server not in LISTEN state"
480		fi
481		tst_sleep 100ms
482	done
483
484	tst_resm TINFO "run client 'netstress -l $c_opts'"
485	netstress -l $c_opts > tst_netload.log 2>&1 || ret=1
486	tst_rhost_run -c "pkill -9 netstress\$"
487
488	if [ "$expect_ret" -ne "$ret" ]; then
489		tst_dump_rhost_cmd
490		cat tst_netload.log
491		tst_brkm TFAIL "expected '$expect_res' but ret: '$ret'"
492	fi
493
494	if [ "$ret" -eq 0 ]; then
495		if [ ! -f $rfile ]; then
496			tst_dump_rhost_cmd
497			cat tst_netload.log
498			tst_brkm TFAIL "can't read $rfile"
499		fi
500		tst_resm TPASS "netstress passed, time spent '$(cat $rfile)' ms"
501	else
502		tst_resm TPASS "netstress failed as expected"
503	fi
504
505	return $ret
506}
507
508# tst_ping [IFACE] [DST ADDR] [MESSAGE SIZE ARRAY]
509# Check icmp connectivity
510# IFACE: source interface name
511# DST ADDR: destination IPv4 or IPv6 address
512# MESSAGE SIZE ARRAY: message size array
513tst_ping()
514{
515	# The max number of ICMP echo request
516	PING_MAX="${PING_MAX:-500}"
517
518	local src_iface="${1:-$(tst_iface)}"
519	local dst_addr="${2:-$(tst_ipaddr rhost)}"; shift $(( $# >= 2 ? 2 : 0 ))
520	local msg_sizes="$*"
521	local msg="tst_ping IPv${TST_IPV6:-4} iface $src_iface, msg_size"
522	local ret=0
523
524	# ping cmd use 56 as default message size
525	for size in ${msg_sizes:-"56"}; do
526		ping$TST_IPV6 -I $src_iface -c $PING_MAX $dst_addr \
527			-s $size -i 0 > /dev/null 2>&1
528		ret=$?
529		if [ $ret -eq 0 ]; then
530			tst_resm TPASS "$msg $size: pass"
531		else
532			tst_resm TFAIL "$msg $size: fail"
533			break
534		fi
535	done
536	return $ret
537}
538
539# tst_icmp -t TIMEOUT -s MESSAGE_SIZE_ARRAY OPTS
540# TIMEOUT: total time for the test in seconds
541# OPTS: additional options for ns-icmpv4|6-sender tool
542tst_icmp()
543{
544	local timeout=1
545	local msg_sizes=56
546	local opts=
547	local num=
548	local ret=0
549	local ver="${TST_IPV6:-4}"
550
551	OPTIND=0
552	while getopts :t:s: opt; do
553		case "$opt" in
554		t) timeout="$OPTARG" ;;
555		s) msg_sizes="$OPTARG" ;;
556		*) opts="-$OPTARG $opts" ;;
557		esac
558	done
559	OPTIND=0
560
561	local num=$(echo "$msg_sizes" | wc -w)
562	timeout="$(($timeout / $num))"
563	[ "$timeout" -eq 0 ] && timeout=1
564
565	opts="${opts}-I $(tst_iface) -S $(tst_ipaddr) -D $(tst_ipaddr rhost) "
566	opts="${opts}-M $(tst_hwaddr rhost) -t $timeout"
567
568	for size in $msg_sizes; do
569		ns-icmpv${ver}_sender -s $size $opts
570		ret=$?
571		if [ $ret -eq 0 ]; then
572			tst_resm TPASS "'ns-icmpv${ver}_sender -s $size $opts' pass"
573		else
574			tst_resm TFAIL "'ns-icmpv${ver}_sender -s $size $opts' fail"
575			break
576		fi
577	done
578	return $ret
579}
580
581# tst_set_sysctl NAME VALUE [safe]
582# It can handle netns case when sysctl not namespaceified.
583tst_set_sysctl()
584{
585	local name="$1"
586	local value="$2"
587	local safe=
588	[ "$3" = "safe" ] && safe="-s"
589
590	local add_opt=
591	[ "$TST_USE_NETNS" = "yes" ] && add_opt="-e"
592
593	if [ "$safe" ]; then
594		ROD sysctl -qw $name=$value
595	else
596		sysctl -qw $name=$value
597	fi
598
599	tst_rhost_run $safe -c "sysctl -qw $add_opt $name=$value"
600}
601
602tst_cleanup_rhost()
603{
604	tst_rhost_run -c "rm -rf $TST_TMPDIR"
605}
606
607# Management Link
608[ -z "$RHOST" ] && TST_USE_NETNS="yes"
609export RHOST="$RHOST"
610export PASSWD="${PASSWD:-}"
611# Don't use it in new tests, use tst_rhost_run() from test_net.sh instead.
612export LTP_RSH="${LTP_RSH:-rsh -n}"
613
614# Test Links
615# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
616# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
617IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
618IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
619IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
620IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
621
622# tst_net_ip_prefix
623# Strip prefix from IP address and save both If no prefix found sets
624# default prefix.
625#
626# tst_net_iface_prefix reads prefix and interface from rtnetlink.
627# If nothing found sets default prefix value.
628#
629# tst_net_vars exports environment variables related to test links and
630# networks that aren't reachable through the test links.
631#
632# For full list of exported environment variables see:
633# tst_net_ip_prefix -h
634# tst_net_iface_prefix -h
635# tst_net_vars -h
636if [ -z "$TST_PARSE_VARIABLES" ]; then
637	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
638	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
639	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
640	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
641fi
642
643[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
644
645if [ -z "$TST_PARSE_VARIABLES" ]; then
646	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
647	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
648		|| echo "exit $?")
649	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
650	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
651		|| echo "exit $?")
652
653	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX \
654		$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
655	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
656		$IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
657
658	tst_resm TINFO "Network config (local -- remote):"
659	tst_resm TINFO "$LHOST_IFACES -- $RHOST_IFACES"
660	tst_resm TINFO "$IPV4_LHOST/$IPV4_LPREFIX -- $IPV4_RHOST/$IPV4_RPREFIX"
661	tst_resm TINFO "$IPV6_LHOST/$IPV6_LPREFIX -- $IPV6_RHOST/$IPV6_RPREFIX"
662	export TST_PARSE_VARIABLES="yes"
663fi
664
665export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
666export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
667export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
668export FTP_UPLOAD_URLDIR="${FTP_UPLOAD_URLDIR:-pub}"
669
670# network/stress tests require additional parameters
671export NS_DURATION="${NS_DURATION:-720}"
672export NS_TIMES="${NS_TIMES:-2000}"
673export CONNECTION_TOTAL="${CONNECTION_TOTAL:-4000}"
674export IP_TOTAL="${IP_TOTAL:-2000}"
675export IP_TOTAL_FOR_TCPIP="${IP_TOTAL_FOR_TCPIP:-100}"
676export ROUTE_TOTAL="${ROUTE_TOTAL:-2000}"
677export MTU_CHANGE_TIMES="${MTU_CHANGE_TIMES:-1000}"
678export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-2000}"
679export DOWNLOAD_BIGFILESIZE="${DOWNLOAD_BIGFILESIZE:-2147483647}"
680export DOWNLOAD_REGFILESIZE="${DOWNLOAD_REGFILESIZE:-1048576}"
681export UPLOAD_BIGFILESIZE="${UPLOAD_BIGFILESIZE:-2147483647}"
682export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
683export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
684export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
685
686# Warning: make sure to set valid interface names and IP addresses below.
687# Set names for test interfaces, e.g. "eth0 eth1"
688# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
689# want to use more ifaces.
690export LHOST_IFACES="${LHOST_IFACES:-eth0}"
691export RHOST_IFACES="${RHOST_IFACES:-eth0}"
692
693# Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02"
694export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}"
695export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}"
696
697# More information about network parameters can be found
698# in the following document: testcases/network/stress/README
699
700if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
701	tst_tmpdir
702	tst_rhost_run -c "mkdir -p $TST_TMPDIR"
703	tst_rhost_run -c "chmod 777 $TST_TMPDIR"
704	export TST_TMPDIR_RHOST=1
705fi
706