1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2021 Oracle and/or its affiliates. All Rights Reserved.
4f08c3bdfSopenharmony_ci
5f08c3bdfSopenharmony_ciTST_TESTFUNC=virt_netperf_rand_sizes
6f08c3bdfSopenharmony_ciTST_SETUP=do_setup
7f08c3bdfSopenharmony_ciTST_CLEANUP=do_cleanup
8f08c3bdfSopenharmony_ciTST_NEEDS_TMPDIR=1
9f08c3bdfSopenharmony_ciTST_OPTS="t:"
10f08c3bdfSopenharmony_ciTST_PARSE_ARGS="parse_args"
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_civirt_type="fou"
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ciGRE_IP_PROTO=47
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_ciparse_args()
17f08c3bdfSopenharmony_ci{
18f08c3bdfSopenharmony_ci	case $1 in
19f08c3bdfSopenharmony_ci	t) virt_type="$2";;
20f08c3bdfSopenharmony_ci	esac
21f08c3bdfSopenharmony_ci}
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_cido_cleanup()
24f08c3bdfSopenharmony_ci{
25f08c3bdfSopenharmony_ci	if [ "$FOU_PORT" ]; then
26f08c3bdfSopenharmony_ci		tst_net_run -l $FOU_PORT -r $FOU_PORT_RMT \
27f08c3bdfSopenharmony_ci			"ip fou del $FOU_PROTO ${TST_IPV6_FLAG} port"
28f08c3bdfSopenharmony_ci	fi
29f08c3bdfSopenharmony_ci
30f08c3bdfSopenharmony_ci	virt_cleanup_rmt
31f08c3bdfSopenharmony_ci	virt_cleanup
32f08c3bdfSopenharmony_ci}
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_cido_setup()
35f08c3bdfSopenharmony_ci{
36f08c3bdfSopenharmony_ci	local get_port_cmd="tst_get_unused_port ipv${TST_IPVER} dgram"
37f08c3bdfSopenharmony_ci	local encap_cmd="encap $virt_type encap-sport auto encap-dport"
38f08c3bdfSopenharmony_ci	local loc_ip=$(tst_ipaddr)
39f08c3bdfSopenharmony_ci	local rmt_ip=$(tst_ipaddr rhost)
40f08c3bdfSopenharmony_ci	local fou="fou$TST_IPV6"
41f08c3bdfSopenharmony_ci
42f08c3bdfSopenharmony_ci	case $virt_type in
43f08c3bdfSopenharmony_ci	fou) FOU_PROTO="ipproto $GRE_IP_PROTO";;
44f08c3bdfSopenharmony_ci	gue) FOU_PROTO="gue";;
45f08c3bdfSopenharmony_ci	esac
46f08c3bdfSopenharmony_ci
47f08c3bdfSopenharmony_ci	tst_require_drivers $fou
48f08c3bdfSopenharmony_ci	tst_net_run -s modprobe $fou
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ci	FOU_PORT=$($get_port_cmd)
51f08c3bdfSopenharmony_ci	FOU_PORT_RMT=$(tst_rhost_run -c "$get_port_cmd")
52f08c3bdfSopenharmony_ci
53f08c3bdfSopenharmony_ci	tst_net_run -s -l $FOU_PORT -r $FOU_PORT_RMT \
54f08c3bdfSopenharmony_ci		"ip fou add $FOU_PROTO ${TST_IPV6_FLAG} port"
55f08c3bdfSopenharmony_ci
56f08c3bdfSopenharmony_ci	virt_setup "local $loc_ip remote $rmt_ip $encap_cmd $FOU_PORT_RMT" \
57f08c3bdfSopenharmony_ci		   "local $rmt_ip remote $loc_ip $encap_cmd $FOU_PORT"
58f08c3bdfSopenharmony_ci}
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci. virt_lib.sh
61f08c3bdfSopenharmony_citst_run
62