From patchwork Thu Apr 26 23:17:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10367003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D4B7B6032C for ; Thu, 26 Apr 2018 23:18:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCA942929C for ; Thu, 26 Apr 2018 23:18:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C11852929E; Thu, 26 Apr 2018 23:18:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 980902929C for ; Thu, 26 Apr 2018 23:18:35 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40XCfx5wHfzF25l for ; Fri, 27 Apr 2018 09:18:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="ItYWWiTT"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=104.47.1.84; helo=eur01-ve1-obe.outbound.protection.outlook.com; envelope-from=petrm@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="ItYWWiTT"; dkim-atps=neutral Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0084.outbound.protection.outlook.com [104.47.1.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40XCfs218KzF25Z for ; Fri, 27 Apr 2018 09:18:29 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=j1gy3Y8U6v7E18alkzHCXGHc8dhWZtx54ZYMShhaW+E=; b=ItYWWiTTj4/9sRwWlqyJXOaGPOXP9WM7M6vKChjgMrpy8gnE1lNUXS5Q2vvXSJk46JzXSbD9/PFfHU4k1JARveY2gYkGjYKL4bdmj4CVBeh2EbubjMJyiIVQCiYOvnhDdWAMW0tajZki5D0htaIsXgA/i7gZgncls/hxI/cNGlU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (89.176.83.59) by VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.15; Thu, 26 Apr 2018 23:18:23 +0000 From: Petr Machata To: netdev@vger.kernel.org Subject: [PATCH net-next 1/7] selftests: forwarding: Add libs for gretap mirror testing In-Reply-To: References: Message-Id: <5113b631c7b2165fcc99796f953e83c350345fe2.1524784510.git.petrm@mellanox.com> Date: Fri, 27 Apr 2018 01:17:56 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [89.176.83.59] X-ClientProxiedBy: VI1PR08CA0220.eurprd08.prod.outlook.com (2603:10a6:802:15::29) To VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR05MB4191; X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 3:zxvyLD2iSB7T5WI8bI72M7OVe+kS/6vdNcXQcPXUIeG39QMThQYgjSj+mzyG6avOfUovESASWQiS+ETVQr8qorkxWlW8Jy47Eq4WLkhhD4dZAjbCAC1Meyx6GkfXSWedtucyyOLTkXjlOWDx5bMrnISZ+Kdr2+e7UQEtMT7izM40WEH1oStM+OC1wCQ2qaHCjctOGGFGca/q8LqUtSDi6+kf/Zb2dryWYLnNT74ekpW5HMVwFjcf4BV0V+Us9QBq; 25:fgBc5stwD4p5DP6WegPzPjguzsBlp10Z1xv4MOkUK3fNUmxq2UD9lvtrGXWoc1bkpYc9CD1qGiWMteza5bQrV95RFDhYhKivLgO+sNRabo6neCcCVQe+O3x5acnGpfiuD5QpwMloGMf/NQJ2UwrFwNgg5h/yAfDiCC3AwIB5ziNMVkieaEUpHr+wDav7/Hv0QJMqNwRlnKwp7WERF+AYKqizhy/ZzRBvIo6KlQ9aiO4N9dQIBELzMK4u1uzqMhN/cVgQFoZ1e+S3FxOzaq35vtFrwr9z+UAC7e7o6cKYZ63O3qDxvrAlZPvYYTYGKTwgGFoB/UhoUQyVc/FhlaSlpw==; 31:rnSe6uRfA2OsP6kmkLrMEemhlFo1j/rUnr2LzPF73I5JP/jRdEMPotpZF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report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231232)(944501410)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:VI1PR05MB4191; BCL:0; PCL:0; RULEID:; SRVR:VI1PR05MB4191; X-Forefront-PRVS: 0654257CF5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39860400002)(39380400002)(346002)(396003)(376002)(199004)(189003)(386003)(478600001)(6496006)(25786009)(4326008)(6116002)(2906002)(16526019)(2361001)(11346002)(7736002)(3846002)(956004)(446003)(2351001)(316002)(47776003)(16586007)(76176011)(36756003)(51416003)(52116002)(81156014)(8936002)(68736007)(81166006)(58126008)(8676002)(118296001)(26005)(97736004)(305945005)(6916009)(106356001)(2616005)(6486002)(476003)(53936002)(66066001)(5660300001)(105586002)(50466002)(486006)(86362001)(48376002)(186003)(6666003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB4191; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR05MB4191; 23:y/b+1ILDLe2dx4PcIVxvqQcHxAFFyDli2yn63U9xl?= =?us-ascii?Q?EXqIsVtBnLofRBdc1keO1mUvvqXr/WA/fu0eMNCX06qsvBE/i3HO+lspgLTM?= =?us-ascii?Q?2Y3djupZUY5Ys1yAj5fJ9bxGkNHzAwU/TVYjb6mreiMIanITca1FE3JDcDQI?= =?us-ascii?Q?Nw6KZHXxvZT9oL/Hpm2KoVyXR7PH6aFLn8cETp6pqB3f+ihbcg+ZPmyqXEP3?= =?us-ascii?Q?62u65OxBPfI68/fX5rmaVC+lTYWo41x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pYiUtKi13GBYPLKHvLHPJB/qO106GBy5mgxf94u+HRWrzKGoBdvke5prSdfPBR2sPMJ2AceqHsGrZW6WBQwD1I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 7:eZMqj8kHCpAW8iFRj4HoSMaC3Daq6IFL7Nef12DmR9l/8wGEBSxQPtKTYMumsdQ8c1eM23eHd33DSvHpnkQD65beE7RWwQZFdsG1GO6qQzE377ori2iWT0FnLIAYC9xfhDk3t86NRBnbKsuKPOi7UCX6zOH57GJ5ZyVMItXbmuWjamhmD0y4TXzptfJHCL1wKg4Nza+hR+gB3dQzuS0Fxh1zRQGi4rpKBH2vGYiwWwKXwQXzGTcAO0zaosazgmGD X-MS-Office365-Filtering-Correlation-Id: 67bd7dec-16a3-4250-8000-08d5abcc01c1 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2018 23:18:23.2835 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67bd7dec-16a3-4250-8000-08d5abcc01c1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB4191 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mlxsw@lists.ozlabs.org, davem@davemloft.net Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org Sender: "Linux-mlxsw" X-Virus-Scanned: ClamAV using ClamSMTP To simplify implementation of mirror-to-gretap tests, extend lib.sh with several new functions that might potentially be useful more broadly (although right now the mirroring tests will be the only client). Also add mirror_lib.sh with code useful for mirroring tests, mirror_gre_lib.sh with code specifically useful for mirror-to-gretap tests, and mirror_gre_topo.sh that primes a given test with a good baseline topology that the test can then tweak to its liking. Signed-off-by: Petr Machata Reviewed-by: Jiri Pirko --- tools/testing/selftests/net/forwarding/lib.sh | 96 +++++++++++++++ .../selftests/net/forwarding/mirror_gre_lib.sh | 85 ++++++++++++++ .../net/forwarding/mirror_gre_topo_lib.sh | 129 +++++++++++++++++++++ .../testing/selftests/net/forwarding/mirror_lib.sh | 40 +++++++ 4 files changed, 350 insertions(+) create mode 100644 tools/testing/selftests/net/forwarding/mirror_gre_lib.sh create mode 100644 tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh create mode 100644 tools/testing/selftests/net/forwarding/mirror_lib.sh diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 1ac6c62..a066ca5 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -321,6 +321,25 @@ simple_if_fini() vrf_destroy $vrf_name } +tunnel_create() +{ + local name=$1; shift + local type=$1; shift + local local=$1; shift + local remote=$1; shift + + ip link add name $name type $type \ + local $local remote $remote "$@" + ip link set dev $name up +} + +tunnel_destroy() +{ + local name=$1; shift + + ip link del dev $name +} + master_name_get() { local if_name=$1 @@ -335,6 +354,15 @@ link_stats_tx_packets_get() ip -j -s link show dev $if_name | jq '.[]["stats64"]["tx"]["packets"]' } +tc_rule_stats_get() +{ + local dev=$1; shift + local pref=$1; shift + + tc -j -s filter show dev $dev ingress pref $pref | + jq '.[1].options.actions[].stats.packets' +} + mac_get() { local if_name=$1 @@ -381,6 +409,74 @@ tc_offload_check() return 0 } +slow_path_trap_install() +{ + local dev=$1; shift + local direction=$1; shift + + if [ "${tcflags/skip_hw}" != "$tcflags" ]; then + # For slow-path testing, we need to install a trap to get to + # slow path the packets that would otherwise be switched in HW. + tc filter add dev $dev $direction pref 1 \ + flower skip_sw action trap + fi +} + +slow_path_trap_uninstall() +{ + local dev=$1; shift + local direction=$1; shift + + if [ "${tcflags/skip_hw}" != "$tcflags" ]; then + tc filter del dev $dev $direction pref 1 flower skip_sw + fi +} + +__icmp_capture_add_del() +{ + local add_del=$1; shift + local pref=$1; shift + local vsuf=$1; shift + local tundev=$1; shift + local filter=$1; shift + + tc filter $add_del dev "$tundev" ingress \ + proto ip$vsuf pref $pref \ + flower ip_proto icmp$vsuf $filter \ + action pass +} + +icmp_capture_install() +{ + __icmp_capture_add_del add 100 "" "$@" +} + +icmp_capture_uninstall() +{ + __icmp_capture_add_del del 100 "" "$@" +} + +icmp6_capture_install() +{ + __icmp_capture_add_del add 100 v6 "$@" +} + +icmp6_capture_uninstall() +{ + __icmp_capture_add_del del 100 v6 "$@" +} + +matchall_sink_create() +{ + local dev=$1; shift + + tc qdisc add dev $dev clsact + tc filter add dev $dev ingress \ + pref 10000 \ + matchall \ + action drop +} + ############################################################################## # Tests diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh new file mode 100644 index 0000000..207ffd1 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/mirror_gre_lib.sh @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: GPL-2.0 + +do_test_span_gre_dir_ips() +{ + local expect=$1; shift + local tundev=$1; shift + local direction=$1; shift + local ip1=$1; shift + local ip2=$1; shift + + icmp_capture_install h3-$tundev + mirror_test v$h1 $ip1 $ip2 h3-$tundev 100 $expect + mirror_test v$h2 $ip2 $ip1 h3-$tundev 100 $expect + icmp_capture_uninstall h3-$tundev +} + +quick_test_span_gre_dir_ips() +{ + do_test_span_gre_dir_ips 10 "$@" +} + +fail_test_span_gre_dir_ips() +{ + do_test_span_gre_dir_ips 0 "$@" +} + +test_span_gre_dir_ips() +{ + local tundev=$1; shift + local direction=$1; shift + local forward_type=$1; shift + local backward_type=$1; shift + local ip1=$1; shift + local ip2=$1; shift + + quick_test_span_gre_dir_ips "$tundev" "$direction" "$ip1" "$ip2" + + icmp_capture_install h3-$tundev "type $forward_type" + mirror_test v$h1 $ip1 $ip2 h3-$tundev 100 10 + icmp_capture_uninstall h3-$tundev + + icmp_capture_install h3-$tundev "type $backward_type" + mirror_test v$h2 $ip2 $ip1 h3-$tundev 100 10 + icmp_capture_uninstall h3-$tundev +} + +full_test_span_gre_dir_ips() +{ + local tundev=$1; shift + local direction=$1; shift + local forward_type=$1; shift + local backward_type=$1; shift + local what=$1; shift + local ip1=$1; shift + local ip2=$1; shift + + RET=0 + + mirror_install $swp1 $direction $tundev "matchall $tcflags" + test_span_gre_dir_ips "$tundev" "$direction" "$forward_type" \ + "$backward_type" "$ip1" "$ip2" + mirror_uninstall $swp1 $direction + + log_test "$direction $what ($tcflags)" +} + +quick_test_span_gre_dir() +{ + quick_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2 +} + +fail_test_span_gre_dir() +{ + fail_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2 +} + +test_span_gre_dir() +{ + test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2 +} + +full_test_span_gre_dir() +{ + full_test_span_gre_dir_ips "$@" 192.0.2.1 192.0.2.2 +} diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh b/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh new file mode 100644 index 0000000..b3ceda2 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/mirror_gre_topo_lib.sh @@ -0,0 +1,129 @@ +# SPDX-License-Identifier: GPL-2.0 + +# This is the standard topology for testing mirroring to gretap and ip6gretap +# netdevices. The tests that use it tweak it in one way or another--importantly, +# $swp3 and $h3 need to have addresses set up. +# +# +---------------------+ +---------------------+ +# | H1 | | H2 | +# | + $h1 | | $h2 + | +# | | 192.0.2.1/28 | | 192.0.2.2/28 | | +# +-----|---------------+ +---------------|-----+ +# | | +# +-----|-------------------------------------------------------------|-----+ +# | SW o--> mirror | | +# | +---|-------------------------------------------------------------|---+ | +# | | + $swp1 BR $swp2 + | | +# | +---------------------------------------------------------------------+ | +# | | +# | + $swp3 + gt6 (ip6gretap) + gt4 (gretap) | +# | | : loc=2001:db8:2::1 : loc=192.0.2.129 | +# | | : rem=2001:db8:2::2 : rem=192.0.2.130 | +# | | : ttl=100 : ttl=100 | +# | | : tos=inherit : tos=inherit | +# | | : : | +# +-----|---------------------:----------------------:----------------------+ +# | : : +# +-----|---------------------:----------------------:----------------------+ +# | H3 + $h3 + h3-gt6 (ip6gretap) + h3-gt4 (gretap) | +# | loc=2001:db8:2::2 loc=192.0.2.130 | +# | rem=2001:db8:2::1 rem=192.0.2.129 | +# | ttl=100 ttl=100 | +# | tos=inherit tos=inherit | +# | | +# +-------------------------------------------------------------------------+ + +mirror_gre_topo_h1_create() +{ + simple_if_init $h1 192.0.2.1/28 +} + +mirror_gre_topo_h1_destroy() +{ + simple_if_fini $h1 192.0.2.1/28 +} + +mirror_gre_topo_h2_create() +{ + simple_if_init $h2 192.0.2.2/28 +} + +mirror_gre_topo_h2_destroy() +{ + simple_if_fini $h2 192.0.2.2/28 +} + +mirror_gre_topo_h3_create() +{ + simple_if_init $h3 + + tunnel_create h3-gt4 gretap 192.0.2.130 192.0.2.129 + ip link set h3-gt4 vrf v$h3 + matchall_sink_create h3-gt4 + + tunnel_create h3-gt6 ip6gretap 2001:db8:2::2 2001:db8:2::1 + ip link set h3-gt6 vrf v$h3 + matchall_sink_create h3-gt6 +} + +mirror_gre_topo_h3_destroy() +{ + tunnel_destroy h3-gt6 + tunnel_destroy h3-gt4 + + simple_if_fini $h3 +} + +mirror_gre_topo_switch_create() +{ + ip link set dev $swp3 up + + ip link add name br1 type bridge vlan_filtering 1 + ip link set dev br1 up + + ip link set dev $swp1 master br1 + ip link set dev $swp1 up + + ip link set dev $swp2 master br1 + ip link set dev $swp2 up + + tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \ + ttl 100 tos inherit + + tunnel_create gt6 ip6gretap 2001:db8:2::1 2001:db8:2::2 \ + ttl 100 tos inherit allow-localremote + + tc qdisc add dev $swp1 clsact +} + +mirror_gre_topo_switch_destroy() +{ + tc qdisc del dev $swp1 clsact + + tunnel_destroy gt6 + tunnel_destroy gt4 + + ip link set dev $swp1 down + ip link set dev $swp2 down + ip link del dev br1 + + ip link set dev $swp3 down +} + +mirror_gre_topo_create() +{ + mirror_gre_topo_h1_create + mirror_gre_topo_h2_create + mirror_gre_topo_h3_create + + mirror_gre_topo_switch_create +} + +mirror_gre_topo_destroy() +{ + mirror_gre_topo_switch_destroy + + mirror_gre_topo_h3_destroy + mirror_gre_topo_h2_destroy + mirror_gre_topo_h1_destroy +} diff --git a/tools/testing/selftests/net/forwarding/mirror_lib.sh b/tools/testing/selftests/net/forwarding/mirror_lib.sh new file mode 100644 index 0000000..e5028a5 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/mirror_lib.sh @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0 + +mirror_install() +{ + local from_dev=$1; shift + local direction=$1; shift + local to_dev=$1; shift + local filter=$1; shift + + tc filter add dev $from_dev $direction \ + pref 1000 $filter \ + action mirred egress mirror dev $to_dev +} + +mirror_uninstall() +{ + local from_dev=$1; shift + local direction=$1; shift + + tc filter del dev $swp1 $direction pref 1000 +} + +mirror_test() +{ + local vrf_name=$1; shift + local sip=$1; shift + local dip=$1; shift + local dev=$1; shift + local pref=$1; shift + local expect=$1; shift + + local t0=$(tc_rule_stats_get $dev $pref) + ip vrf exec $vrf_name \ + ${PING} ${sip:+-I $sip} $dip -c 10 -i 0.1 -w 2 &> /dev/null + local t1=$(tc_rule_stats_get $dev $pref) + local delta=$((t1 - t0)) + # Tolerate a couple stray extra packets. + ((expect <= delta && delta <= expect + 2)) + check_err $? "Expected to capture $expect packets, got $delta." +}