2020-12-07 21:53:29 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Copyright(c) 2020 Intel Corporation.
|
|
|
|
|
|
|
|
ksft_pass=0
|
|
|
|
ksft_fail=1
|
|
|
|
ksft_xfail=2
|
|
|
|
ksft_xpass=3
|
|
|
|
ksft_skip=4
|
|
|
|
|
|
|
|
SPECFILE=veth.spec
|
2020-12-07 21:53:30 +00:00
|
|
|
XSKOBJ=xdpxceiver
|
2020-12-07 21:53:29 +00:00
|
|
|
|
|
|
|
validate_root_exec()
|
|
|
|
{
|
|
|
|
msg="skip all tests:"
|
|
|
|
if [ $UID != 0 ]; then
|
|
|
|
echo $msg must be run as root >&2
|
|
|
|
test_exit $ksft_fail 2
|
|
|
|
else
|
|
|
|
return $ksft_pass
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_veth_support()
|
|
|
|
{
|
|
|
|
msg="skip all tests:"
|
|
|
|
if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
|
|
|
|
echo $msg veth kernel support not available >&2
|
|
|
|
test_exit $ksft_skip 1
|
|
|
|
else
|
|
|
|
ip link del $1
|
|
|
|
return $ksft_pass
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_veth_spec_file()
|
|
|
|
{
|
|
|
|
if [ ! -f ${SPECFILE} ]; then
|
|
|
|
test_exit $ksft_skip 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test_status()
|
|
|
|
{
|
|
|
|
statusval=$1
|
2021-08-25 09:37:07 +00:00
|
|
|
if [ $statusval -eq 2 ]; then
|
|
|
|
echo -e "$2: [ FAIL ]"
|
|
|
|
elif [ $statusval -eq 1 ]; then
|
|
|
|
echo -e "$2: [ SKIPPED ]"
|
|
|
|
elif [ $statusval -eq 0 ]; then
|
|
|
|
echo -e "$2: [ PASS ]"
|
2020-12-07 21:53:29 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test_exit()
|
|
|
|
{
|
|
|
|
retval=$1
|
|
|
|
if [ $2 -ne 0 ]; then
|
|
|
|
test_status $2 $(basename $0)
|
|
|
|
fi
|
|
|
|
exit $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_configs()
|
|
|
|
{
|
|
|
|
if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
|
|
|
|
[ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
|
2021-02-23 16:23:01 +00:00
|
|
|
{ ip netns exec $3 ip link del $2; }
|
2020-12-07 21:53:29 +00:00
|
|
|
ip netns del $3
|
|
|
|
fi
|
|
|
|
#Once we delete a veth pair node, the entire veth pair is removed,
|
|
|
|
#this is just to be cautious just incase the NS does not exist then
|
|
|
|
#veth node inside NS won't get removed so we explicitly remove it
|
|
|
|
[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
|
2021-02-23 16:23:01 +00:00
|
|
|
{ ip link del $1; }
|
2020-12-07 21:53:29 +00:00
|
|
|
if [ -f ${SPECFILE} ]; then
|
|
|
|
rm -f ${SPECFILE}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup_exit()
|
|
|
|
{
|
|
|
|
clear_configs $1 $2 $3
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_ip_utility()
|
|
|
|
{
|
|
|
|
[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; }
|
|
|
|
}
|
|
|
|
|
2020-12-07 21:53:30 +00:00
|
|
|
execxdpxceiver()
|
|
|
|
{
|
2021-08-25 09:37:08 +00:00
|
|
|
./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${VERBOSE_ARG} ${DUMP_PKTS_ARG}
|
2020-12-07 21:53:30 +00:00
|
|
|
}
|