From patchwork Tue Jul 24 21:06:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10543217 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A0B6184F for ; Tue, 24 Jul 2018 21:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 781CE294BD for ; Tue, 24 Jul 2018 21:08:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CBBF294C8; Tue, 24 Jul 2018 21:08:58 +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,LOTS_OF_MONEY,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 7F260294BF for ; Tue, 24 Jul 2018 21:08:57 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41ZrZH66VHzDrSg for ; Wed, 25 Jul 2018 07:08:55 +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="tt7PaOqp"; 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=40.107.6.58; helo=eur04-db3-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="tt7PaOqp"; dkim-atps=neutral Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60058.outbound.protection.outlook.com [40.107.6.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41ZrWW0gKFzDrVM for ; Wed, 25 Jul 2018 07:06:30 +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:X-MS-Exchange-SenderADCheck; bh=PILUUyeHhTgx0aPa5oLH5bftnLO7z1pJFZjCX7JQtAA=; b=tt7PaOqpnOejmaJQdHc1hU5XWQ+3s5DjqlGYrk3cCl2yGHkmrZnEaWGxYKQi8yyGIQ9aCSnf8XFLDHb84sOzzAPXMNt4AriWsjFs+fNdqNvzpamupR8ytAskP+jSvIHZx5ouYj3ShcMJZ5WrxkUootS8tIZ5PnXSpgeKyeVK4CM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (78.45.160.211) by DB7PR05MB4186.eurprd05.prod.outlook.com (2603:10a6:5:18::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.21; Tue, 24 Jul 2018 21:06:23 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw 8/8] selftests: mlxsw: Add test for trust-DSCP In-Reply-To: References: Message-Id: <2d3a40d9cf2ff8f72cd2e92397852450f92054c8.1532465553.git.petrm@mellanox.com> Date: Tue, 24 Jul 2018 23:06:18 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [78.45.160.211] X-ClientProxiedBy: AM0PR02CA0012.eurprd02.prod.outlook.com (2603:10a6:208:3e::25) To DB7PR05MB4186.eurprd05.prod.outlook.com (2603:10a6:5:18::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6f43823-33b8-424b-2296-08d5f1a94fce X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600073)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4186; X-Microsoft-Exchange-Diagnostics: 1; DB7PR05MB4186; 3:+jigL2RCwsushR+KBPhT+7VFOsUlIUY3i7Lnw6EIi6Qb43NK0yb71xGIDtgccXm5qq8AqlkJX/UovRH0ME9rDSiV34OhfGzml6iAmfrTNTYq8kxwMMHsfhdyrMcfUkBO8CaOvx7uPHl86lvYB+6WOVTMbrnF+TICQES/pKEcfFzMwjoG/CBWGWvTlfbi4gCDITnIdE6qaYYnpdkzk6erOyJvDkeVQ5flMj1ca/kJwJAxk1zEXz8kvwpCQltVvcGj; 25:Evw6HCij0U7X6pjRcK1oPiEQJ/9E/7JjrUHudp8kOR8QDr6+8ueih+6YigrYL9YUscSAWpvsMV5CEGLhJ4rI2jbcxr5N/ZJlpLjuXVCV45eW5FpPkiNXrZgAEttC0HYFkXt1j0LnMktFimC7JWuA56pKBZqD61D+rJQzALaS0MuJR4fLlk7AtdxF3S/y//qN3bExzsc8uNHx5X4lm/yfgRut4hirWRk7wfL+fTg3hyKlQyTCy/4qneK3p6UHyPkOjC9dBHzqh29r8LJlr6f0Olfn5gAyJVBtbg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HzIRgHz0tXEJ8Xvzc2Q/+EQyK1818ms3pZN6zfPOUdWz4XUYEI4+YKRm0zFe1HIpSllMcWyiRoxhcqtUZjSFY7Zi5PUQGQsoVAe6tXEzKDd3MKe/PH1o+YGu2qQqE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(190756311086443); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4186; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4186; X-Forefront-PRVS: 0743E8D0A6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(366004)(396003)(376002)(136003)(39860400002)(199004)(189003)(386003)(26005)(186003)(47776003)(16526019)(956004)(476003)(2616005)(486006)(6636002)(105586002)(6116002)(3846002)(66066001)(316002)(5660300001)(37006003)(14444005)(2906002)(86362001)(575784001)(58126008)(52116002)(51416003)(76176011)(11346002)(446003)(16586007)(68736007)(48376002)(50466002)(36756003)(53936002)(6666003)(478600001)(6486002)(6496006)(106356001)(2351001)(8676002)(97736004)(81166006)(81156014)(7736002)(305945005)(25786009)(6862004)(118296001)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4186; 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; DB7PR05MB4186; 23:XzbqQJXMsuCZ9erTzIORhaWopfNRNdaH/yKalzLLM?= yywU1fKDOLksk1ZjaXAztfa1R3uao5yLkmZ8BwVYO46mNhXX3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fDgdBdNPpu0gpft9cmWyR7Y71yUFLrrEfEHzucHN98InL6naFnACBpMAg6cRDW8ZUt9MdG0LWw8309+374=; 7:KtSC4QsYpEgJa53sTHOanP77Y1rGHyQ+Rkj+sxaJ0320xcCJvfH0A9f3iJ1jdW8y+nJG9rteVKwStH+ap89yXJuq0HDO0v/yU+HaR/UdYEmy+iuUPtqN9/LxfGabH/F4KyTL1amrpHT+TrtYR2FT7y5xatUnHCFI27hQ+qvunMf5smg5AklA4giUeyfHaZRPLjMQi+tT5cA78z1dYDWH8t9U5I9GTvGxgQYKiTq1k2SZwxtGMPgGqgu/xV5qkm8M SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2018 21:06:23.0813 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6f43823-33b8-424b-2296-08d5f1a94fce X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4186 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP Add a test that exercises the new code. Send DSCP-tagged packets, and observe how they are prioritized in the switch and the DSCP is updated on egress again. Signed-off-by: Petr Machata --- .../selftests/drivers/net/mlxsw/qos_dscp.sh | 249 +++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/mlxsw/qos_dscp.sh diff --git a/tools/testing/selftests/drivers/net/mlxsw/qos_dscp.sh b/tools/testing/selftests/drivers/net/mlxsw/qos_dscp.sh new file mode 100755 index 000000000000..3793436f1f0d --- /dev/null +++ b/tools/testing/selftests/drivers/net/mlxsw/qos_dscp.sh @@ -0,0 +1,249 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# Test for DSCP prioritization and rewrite. Packets ingress $swp1 with a DSCP +# tag and are prioritized according to the map at $swp1. They egress $swp2 and +# the DSCP value is updated to match the map at that interface. The updated DSCP +# tag is verified at $h2. +# +# ICMP responses are produced with the same DSCP tag that arrived at $h2. They +# go through prioritization at $swp2 and DSCP retagging at $swp1. The tag is +# verified at $h1--it should match the original tag. +# +# +----------------------+ +----------------------+ +# | H1 | | H2 | +# | + $h1 | | $h2 + | +# | | 192.0.2.1/28 | | 192.0.2.2/28 | | +# +----|-----------------+ +----------------|-----+ +# | | +# +----|----------------------------------------------------------------|-----+ +# | SW | | | +# | +-|----------------------------------------------------------------|-+ | +# | | + $swp1 BR $swp2 + | | +# | | APP=0,5,10 .. 7,5,17 APP=0,5,20 .. 7,5,27 | | +# | +--------------------------------------------------------------------+ | +# +---------------------------------------------------------------------------+ + +ALL_TESTS=" + ping_ipv4 + test_dscp +" + +lib_dir=$(dirname $0)/../../../net/forwarding + +NUM_NETIFS=4 +source $lib_dir/lib.sh + +__dscp_capture_add_del() +{ + local add_del=$1; shift + local dev=$1; shift + local base=$1; shift + local dscp; + + for prio in {0..7}; do + dscp=$((base + prio)) + __icmp_capture_add_del $add_del $dscp "" $dev \ + "ip_tos $((dscp << 2))" + done +} + +dscp_capture_install() +{ + local dev=$1; shift + local base=$1; shift + + __dscp_capture_add_del add $dev $base +} + +dscp_capture_uninstall() +{ + local dev=$1; shift + local base=$1; shift + + __dscp_capture_add_del del $dev $base +} + +h1_create() +{ + local dscp; + + simple_if_init $h1 192.0.2.1/28 + tc qdisc add dev $h1 clsact + dscp_capture_install $h1 10 +} + +h1_destroy() +{ + dscp_capture_uninstall $h1 10 + simple_if_fini $h1 192.0.2.1/28 + tc qdisc del dev $h1 clsact +} + +h2_create() +{ + simple_if_init $h2 192.0.2.2/28 + tc qdisc add dev $h2 clsact + dscp_capture_install $h2 20 +} + +h2_destroy() +{ + dscp_capture_uninstall $h2 20 + simple_if_fini $h2 192.0.2.2/28 + tc qdisc del dev $h2 clsact +} + +dscp_map() +{ + local base=$1; shift + + for prio in {0..7}; do + echo app=$prio,5,$((base + prio)) + done +} + +lldpad_wait() +{ + local dev=$1; shift + + while lldptool -t -i $dev -V APP -c app | grep -q pending; do + echo "$dev: waiting for lldpad to push pending APP updates" + sleep 5 + done +} + +switch_create() +{ + 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 + + lldptool -T -i $swp1 -V APP $(dscp_map 10) >/dev/null + lldptool -T -i $swp2 -V APP $(dscp_map 20) >/dev/null + lldpad_wait $swp1 + lldpad_wait $swp2 +} + +switch_destroy() +{ + lldptool -T -i $swp2 -V APP -d $(dscp_map 20) >/dev/null + lldptool -T -i $swp1 -V APP -d $(dscp_map 10) >/dev/null + + # Give lldpad a chance to push down the changes. If the device is downed + # too soon, the updates will be left pending, but will have been struck + # off the lldpad's DB already, and we won't be able to tell. Then on + # next test iteration this would cause weirdness as newly-added APP + # rules conflict with the old ones, sometimes getting stuck in an + # "unknown" state. + sleep 5 + + ip link set dev $swp2 nomaster + ip link set dev $swp1 nomaster + ip link del dev br1 +} + +setup_prepare() +{ + h1=${NETIFS[p1]} + swp1=${NETIFS[p2]} + + swp2=${NETIFS[p3]} + h2=${NETIFS[p4]} + + vrf_prepare + + h1_create + h2_create + switch_create +} + +cleanup() +{ + pre_cleanup + + switch_destroy + h2_destroy + h1_destroy + + vrf_cleanup +} + +dscp_fetch_stats() +{ + local dev=$1; shift + local base=$1; shift + + for prio in {0..7}; do + local dscp=$((base + prio)) + local t=$(tc_rule_stats_get $dev $dscp) + echo "[$dscp]=$t " + done +} + +ping_ipv4() +{ + ping_test $h1 192.0.2.2 +} + +dscp_ping_test() +{ + local vrf_name=$1; shift + local sip=$1; shift + local dip=$1; shift + local prio=$1; shift + local dev_10=$1; shift + local dev_20=$1; shift + + local dscp_10=$(((prio + 10) << 2)) + local dscp_20=$(((prio + 20) << 2)) + + RET=0 + + local -A t0s + eval "t0s=($(dscp_fetch_stats $dev_10 10) + $(dscp_fetch_stats $dev_20 20))" + + ip vrf exec $vrf_name \ + ${PING} -Q $dscp_10 ${sip:+-I $sip} $dip \ + -c 10 -i 0.1 -w 2 &> /dev/null + + local -A t1s + eval "t1s=($(dscp_fetch_stats $dev_10 10) + $(dscp_fetch_stats $dev_20 20))" + + for key in ${!t0s[@]}; do + local expect + if ((key == dscp_10 || key == dscp_20)); then + expect=10 + else + expect=0 + fi + + # Tolerate a couple stray extra packets. + local delta=$((t1s[key] - t0s[key])) + ((expect <= delta && delta <= expect + 2)) + check_err $? "DSCP $key: Expected to capture $expect packets, got $delta." + done + + log_test "DSCP rewrite: $dscp_10-(prio $prio)-$dscp_20" +} + +test_dscp() +{ + for prio in {0..7}; do + dscp_ping_test v$h1 192.0.2.1 192.0.2.2 $prio $h1 $h2 + done +} + +trap cleanup EXIT + +setup_prepare +setup_wait + +tests_run + +exit $EXIT_STATUS