diff options
author | Ilya Maximets <i.maximets@samsung.com> | 2015-12-10 18:32:04 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-12-14 11:57:38 +0300 |
commit | 7f45dd40a965bc11d77759a1c838696a8e848759 (patch) | |
tree | 0ba58ba2daf8b184cb426c4f28b38dbb5b7c1b7e /platform | |
parent | 758d7a4b6d62b6b7577d168a18c3456d18cf7e95 (diff) |
linux-generic: pktio: add test for tap pktio
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Reviewed-and-tested-by: Stuart Haslam <stuart.haslam@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/test/Makefile.am | 1 | ||||
-rw-r--r-- | platform/linux-generic/test/pktio/Makefile.am | 3 | ||||
-rwxr-xr-x | platform/linux-generic/test/pktio/pktio_run_tap | 115 |
3 files changed, 118 insertions, 1 deletions
diff --git a/platform/linux-generic/test/Makefile.am b/platform/linux-generic/test/Makefile.am index 76d357aa1..594aa11eb 100644 --- a/platform/linux-generic/test/Makefile.am +++ b/platform/linux-generic/test/Makefile.am @@ -5,6 +5,7 @@ ODP_MODULES = pktio if test_vald TESTS = pktio/pktio_run \ + pktio/pktio_run_tap \ ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) \ ${top_builddir}/test/validation/config/config_main$(EXEEXT) \ diff --git a/platform/linux-generic/test/pktio/Makefile.am b/platform/linux-generic/test/pktio/Makefile.am index 4d39372de..ea0ad87a5 100644 --- a/platform/linux-generic/test/pktio/Makefile.am +++ b/platform/linux-generic/test/pktio/Makefile.am @@ -1,5 +1,6 @@ dist_check_SCRIPTS = pktio_env \ - pktio_run + pktio_run \ + pktio_run_tap if HAVE_PCAP dist_check_SCRIPTS += pktio_run_pcap diff --git a/platform/linux-generic/test/pktio/pktio_run_tap b/platform/linux-generic/test/pktio/pktio_run_tap new file mode 100755 index 000000000..975da81b0 --- /dev/null +++ b/platform/linux-generic/test/pktio/pktio_run_tap @@ -0,0 +1,115 @@ +#!/bin/sh +# +# Copyright (c) 2015, Ilya Maximets <i.maximets@samsung.com> +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +# directories where pktio_main binary can be found: +# -in the validation dir when running make check (intree or out of tree) +# -in the script directory, when running after 'make install', or +# -in the validation when running standalone intree. +# -in the current directory. +# running stand alone out of tree requires setting PATH +PATH=${TEST_DIR}/pktio:$PATH +PATH=$(dirname $0):$PATH +PATH=$(dirname $0)/../../../../test/validation/pktio:$PATH +PATH=.:$PATH + +pktio_main_path=$(which pktio_main${EXEEXT}) +if [ -x "$pktio_main_path" ] ; then + echo "running with $pktio_main_path" +else + echo "cannot find pktio_main${EXEEXT}: please set you PATH for it." +fi + +# exit code expected by automake for skipped tests +TEST_SKIPPED=77 + +TAP_BASE_NAME=iotap_vald +IF0=${TAP_BASE_NAME}0 +IF1=${TAP_BASE_NAME}1 +BR=${TAP_BASE_NAME}_br + +export ODP_PKTIO_IF0="tap:$IF0" +export ODP_PKTIO_IF1="tap:$IF1" + +tap_cleanup() +{ + ret=$? + + for iface in $IF0 $IF1; do + ip link set dev $iface nomaster + done + + ip link delete $BR type bridge + + for iface in $IF0 $IF1; do + ip tuntap del mode tap $iface + done + + trap - EXIT + exit $ret +} + +tap_setup() +{ + if [ "$(id -u)" != "0" ]; then + echo "pktio: need to be root to setup TAP interfaces." + return $TEST_SKIPPED + fi + + for iface in $IF0 $IF1 $BR; do + ip link show $iface 2> /dev/null + if [ $? -eq 0 ]; then + echo "pktio: interface $iface already exist $?" + return 2 + fi + done + + trap tap_cleanup EXIT + + for iface in $IF0 $IF1; do + ip tuntap add mode tap $iface + if [ $? -ne 0 ]; then + echo "pktio: error: unable to create TAP device $iface" + return 3 + fi + done + + ip link add name $BR type bridge + if [ $? -ne 0 ]; then + echo "pktio: error: unable to create bridge $BR" + return 3 + fi + + for iface in $IF0 $IF1; do + ip link set dev $iface master $BR + if [ $? -ne 0 ]; then + echo "pktio: error: unable to add $iface to bridge $BR" + return 4 + fi + done + + for iface in $IF0 $IF1 $BR; do + ifconfig $iface -arp + sysctl -w net.ipv6.conf.${iface}.disable_ipv6=1 + ip link set dev $iface mtu 9216 up + done + + return 0 +} + +tap_setup +ret=$? +if [ $ret -ne 0 ]; then + echo "pktio: tap_setup() FAILED!" + exit $ret +fi + +# Using ODP_WAIT_FOR_NETWORK to prevent fail if tap still not enabled in bridge +ODP_WAIT_FOR_NETWORK=yes pktio_main${EXEEXT} +ret=$? + +exit $ret |