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