xref: /aosp_15_r20/external/ltp/testcases/network/virt/wireguard01.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh
2*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later
3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2020 Oracle and/or its affiliates. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker
5*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="tc"
6*49cdfc7eSAndroid Build Coastguard WorkerTST_SETUP=setup
7*49cdfc7eSAndroid Build Coastguard WorkerTST_CLEANUP=cleanup
8*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC=test
9*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=3
10*49cdfc7eSAndroid Build Coastguard Worker
11*49cdfc7eSAndroid Build Coastguard Workersetup()
12*49cdfc7eSAndroid Build Coastguard Worker{
13*49cdfc7eSAndroid Build Coastguard Worker	if tst_net_use_netns && [ "$VIRT_PERF_THRESHOLD" -lt 700 ]; then
14*49cdfc7eSAndroid Build Coastguard Worker		tst_res TINFO "Adjust threshold for veth (no encap/encrypt)"
15*49cdfc7eSAndroid Build Coastguard Worker		VIRT_PERF_THRESHOLD=700
16*49cdfc7eSAndroid Build Coastguard Worker	fi
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker	local netem_opt="reorder 30% 50% delay 1"
19*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "Use netem $netem_opt"
20*49cdfc7eSAndroid Build Coastguard Worker	ROD tc qdisc add dev $(tst_iface) root netem $netem_opt
21*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_setup
22*49cdfc7eSAndroid Build Coastguard Worker}
23*49cdfc7eSAndroid Build Coastguard Worker
24*49cdfc7eSAndroid Build Coastguard Workercleanup()
25*49cdfc7eSAndroid Build Coastguard Worker{
26*49cdfc7eSAndroid Build Coastguard Worker	tc qdisc del dev $(tst_iface) root netem >/dev/null 2>&1
27*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_cleanup
28*49cdfc7eSAndroid Build Coastguard Worker}
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Workertest1()
31*49cdfc7eSAndroid Build Coastguard Worker{
32*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "Using correct wireguard configuration"
33*49cdfc7eSAndroid Build Coastguard Worker	virt_netperf_msg_sizes
34*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_cleanup
35*49cdfc7eSAndroid Build Coastguard Worker}
36*49cdfc7eSAndroid Build Coastguard Worker
37*49cdfc7eSAndroid Build Coastguard Workertest2()
38*49cdfc7eSAndroid Build Coastguard Worker{
39*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "Invalid configuration with allowed IPs"
40*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_setup invalid_allowed_ips
41*49cdfc7eSAndroid Build Coastguard Worker	virt_minimize_timeout
42*49cdfc7eSAndroid Build Coastguard Worker	virt_compare_netperf "fail"
43*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_cleanup
44*49cdfc7eSAndroid Build Coastguard Worker}
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Workertest3()
47*49cdfc7eSAndroid Build Coastguard Worker{
48*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "Invalid configuration with public keys"
49*49cdfc7eSAndroid Build Coastguard Worker	wireguard_lib_setup invalid_pub_keys
50*49cdfc7eSAndroid Build Coastguard Worker	virt_minimize_timeout
51*49cdfc7eSAndroid Build Coastguard Worker	virt_compare_netperf "fail"
52*49cdfc7eSAndroid Build Coastguard Worker}
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker. wireguard_lib.sh
55*49cdfc7eSAndroid Build Coastguard Workertst_run
56