1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
4f08c3bdfSopenharmony_ci# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
5f08c3bdfSopenharmony_ci# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ciTST_TESTFUNC="do_test"
8f08c3bdfSopenharmony_ciTST_SETUP="setup"
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_cisetup()
11f08c3bdfSopenharmony_ci{
12f08c3bdfSopenharmony_ci	cmd="tracepath"
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ci	if [ "$TST_IPV6" ]; then
15f08c3bdfSopenharmony_ci		cmd="tracepath$TST_IPVER"
16f08c3bdfSopenharmony_ci		tst_cmd_available $cmd || cmd="tracepath -6"
17f08c3bdfSopenharmony_ci	fi
18f08c3bdfSopenharmony_ci	tst_require_cmds $(echo $cmd | cut -f 1 -d' ')
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci	if $cmd -V >/dev/null 2>&1; then
21f08c3bdfSopenharmony_ci		tst_res TINFO "traceroute version:"
22f08c3bdfSopenharmony_ci		tst_res TINFO $($cmd -V 2>&1)
23f08c3bdfSopenharmony_ci	fi
24f08c3bdfSopenharmony_ci}
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_cido_test()
27f08c3bdfSopenharmony_ci{
28f08c3bdfSopenharmony_ci	local len=1280
29f08c3bdfSopenharmony_ci	local output
30f08c3bdfSopenharmony_ci	local rhost="$(tst_ipaddr rhost)"
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_ci	tst_res TINFO "test $cmd with $rhost, pmtu is $len"
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_ci	output=$($cmd $rhost -l $len | grep "pmtu $len")
35f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
36f08c3bdfSopenharmony_ci		tst_res TFAIL "$cmd failed: pmtu $len not found in output"
37f08c3bdfSopenharmony_ci		return
38f08c3bdfSopenharmony_ci	fi
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_ci	# Usually only one hop is required to get to remote test machine
41f08c3bdfSopenharmony_ci	hops_num=$(echo "$output" | sed -nE 's/.*hops ([0-9]+).*/\1/p')
42f08c3bdfSopenharmony_ci	if [ -z "$hops_num" ]; then
43f08c3bdfSopenharmony_ci		tst_res TFAIL "failed to trace path to '$rhost'"
44f08c3bdfSopenharmony_ci		return
45f08c3bdfSopenharmony_ci	fi
46f08c3bdfSopenharmony_ci
47f08c3bdfSopenharmony_ci	if [ "$hops_num" -eq 0 ]; then
48f08c3bdfSopenharmony_ci		tst_res TFAIL "can't trace path to '$rhost' in 1+ hops"
49f08c3bdfSopenharmony_ci		return
50f08c3bdfSopenharmony_ci	fi
51f08c3bdfSopenharmony_ci
52f08c3bdfSopenharmony_ci	tst_res TPASS "traced path to '$rhost' in $hops_num hops"
53f08c3bdfSopenharmony_ci}
54f08c3bdfSopenharmony_ci
55f08c3bdfSopenharmony_ci. tst_net.sh
56f08c3bdfSopenharmony_citst_run
57