From patchwork Fri Mar 26 13:09:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12166599 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29E40C433DB for ; Fri, 26 Mar 2021 13:10:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D820861A1A for ; Fri, 26 Mar 2021 13:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbhCZNKU (ORCPT ); Fri, 26 Mar 2021 09:10:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbhCZNKF (ORCPT ); Fri, 26 Mar 2021 09:10:05 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615D7C0613AA for ; Fri, 26 Mar 2021 06:10:03 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id w18so6314981edc.0 for ; Fri, 26 Mar 2021 06:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cqXIl3nwtcXjCwONbLFI8a44o/exKSenAY5upZa6Mis=; b=L7QKC6rpbss6E/VmgvGb+h8f37syWflsXOcaBGGdqAvjviyJJknjurnRGw1bqzFhFx NMGBo7a+E+x2KJvqUWT4Nxkpsh5GPIKN2l1Atp4ltYH6152OQbdXZ1srmeHC0kbD7d5U NINNgll8lTGxtvgtsuEiEh23p6/SQL5rQAZ/s5jYW3ZUwZbPuK8FfM5neVTjLjFou+ID clzpbMoeyOCNzuoVhjZ8ZoVZtFL4ofmXu77SJmdMobpX953czONiSL64jOGCE2HP5XFj /Y7jH53Ta2TYz44o3/xrB+QD91UJ7tE7TUO3mjrNIwGay0m63LCtJxWDA+KAhvItB12+ Hrfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cqXIl3nwtcXjCwONbLFI8a44o/exKSenAY5upZa6Mis=; b=U5SXLNivX0IXdeVyVyGMi2uOeqZ3AHL/1ramF9m0tOQMpHgSLww/K0mUD+HAYe04YJ nZbuTwIWqEL+4wm1drdOpezv/dGxY7Xwj8KqMlRKFEzW9lYjJO4cd0yzDS2cxNoIPCo/ kzbuiZsqpZ8jISYuF6cd6bIUcxp5EFuD5uxdyChtX7+B+weMJ6CxDqfDwzD5kpbtnudB IxZom2psPGUG2W1chmv6WMgz5n2HJ+O+3c4GB15hcNpESqQ4eNrEnVdK2o7c2dnaHqYj lAHGPP++WxkNvqrf8QBdqXsutOrSgWohAhSxreSuOGUqBKioZ5CsMN8JhdcZaMPTXe+S kjNQ== X-Gm-Message-State: AOAM530daXouDemLl4LUWIDTpB41ul0Ba3g2Fr9agW2UUTobXo2yI0wo GxhYwLBz8pPHKMWhSK1NHne0tQ== X-Google-Smtp-Source: ABdhPJwkp0DOilUwvwPGWoiKsEEblhE1NcqzRA0XV/S8opzUTIFU7PjE8PV9kki02FMf8vE65nS3SA== X-Received: by 2002:a05:6402:278d:: with SMTP id b13mr2391878ede.34.1616764202178; Fri, 26 Mar 2021 06:10:02 -0700 (PDT) Received: from madeliefje.horms.nl ([2001:982:7ed1:404:a2a4:c5ff:fe4c:9ce9]) by smtp.gmail.com with ESMTPSA id 90sm4202624edf.31.2021.03.26.06.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 06:10:00 -0700 (PDT) From: Simon Horman To: David Miller , Jakub Kicinski Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, oss-drivers@netronome.com, Ido Schimmel , Baowen Zheng , Simon Horman Subject: [PATCH net-next 1/2] selftests: tc-testing: add action police selftest for packets per second Date: Fri, 26 Mar 2021 14:09:37 +0100 Message-Id: <20210326130938.15814-2-simon.horman@netronome.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210326130938.15814-1-simon.horman@netronome.com> References: <20210326130938.15814-1-simon.horman@netronome.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Baowen Zheng Add selftest cases in action police for packets per second. These tests depend on corresponding iproute2 command support. Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman Reviewed-by: Jamal Hadi Salim --- It is also planned, as a follow-up, to provide packet per second rate limiting tests in tools/testing/selftests/net/forwarding/tc_police.sh --- .../tc-testing/tc-tests/actions/police.json | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json index b8268da5adaa..8e45792703ed 100644 --- a/tools/testing/selftests/tc-testing/tc-tests/actions/police.json +++ b/tools/testing/selftests/tc-testing/tc-tests/actions/police.json @@ -764,5 +764,53 @@ "teardown": [ "$TC actions flush action police" ] + }, + { + "id": "cdd7", + "name": "Add valid police action with packets per second rate limit", + "category": [ + "actions", + "police" + ], + "setup": [ + [ + "$TC actions flush action police", + 0, + 1, + 255 + ] + ], + "cmdUnderTest": "$TC actions add action police pkts_rate 1000 pkts_burst 200 index 1", + "expExitCode": "0", + "verifyCmd": "$TC actions ls action police", + "matchPattern": "action order [0-9]*: police 0x1 rate 0bit burst 0b mtu 4096Mb pkts_rate 1000 pkts_burst 200", + "matchCount": "1", + "teardown": [ + "$TC actions flush action police" + ] + }, + { + "id": "f5bc", + "name": "Add invalid police action with both bps and pps", + "category": [ + "actions", + "police" + ], + "setup": [ + [ + "$TC actions flush action police", + 0, + 1, + 255 + ] + ], + "cmdUnderTest": "$TC actions add action police rate 1kbit burst 10k pkts_rate 1000 pkts_burst 200 index 1", + "expExitCode": "255", + "verifyCmd": "$TC actions ls action police", + "matchPattern": "action order [0-9]*: police 0x1 ", + "matchCount": "0", + "teardown": [ + "$TC actions flush action police" + ] } ] From patchwork Fri Mar 26 13:09:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12166603 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 440A4C433E1 for ; Fri, 26 Mar 2021 13:10:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE70A61A13 for ; Fri, 26 Mar 2021 13:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbhCZNKV (ORCPT ); Fri, 26 Mar 2021 09:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbhCZNKF (ORCPT ); Fri, 26 Mar 2021 09:10:05 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C98E5C0613B1 for ; Fri, 26 Mar 2021 06:10:04 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id dm8so6270986edb.2 for ; Fri, 26 Mar 2021 06:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xyFIGb5tgMoLJ+C2dLCptTO4xPo45801GBsThwDgsdE=; b=yZub6IN6FEffpOqBoIHjmb6uaXRoSs4BRTBqbsRHtRQ97W/Xs4E+g3TvZcG/fTXBbG ZhfdP/RcMig042ealI6G6498ZXTfBm5kaET4BVhHJbmA6JG2FdZxGQmbjvPnlVULbLsv 5B3N6bTEVvhUmBbQVI1J5JYmDvAazIv7HCYtV47IGRBe1rIVdp7mYjDgJClK9X9JL32w etlY5AdButybXr+Lmk4VY7HJ+RUkEyfJi4HEyY2gDEGeG9pT1+6JtCH2WzzszQMiugUl iOIEtiu5RipYzGK+1MDPn7DlWt6f34nBcXgvsfoEn9V2uhUaE+ncjdMMTp514ynwGKhl dhBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xyFIGb5tgMoLJ+C2dLCptTO4xPo45801GBsThwDgsdE=; b=slqTabAB6rhdjJaz+xRl4yMeRnM2LS4Ow/wkBRosI70AgRlJmHDDGzCDJvQ8fbls/B wB+S2UV+LLAbBEkVUCfvKw8zt7mFW3b0CvMZwzrkQ+qlrIfwOlENehB8E1QwG10QuB8u peaBy3ngeZg1ZsgfrEwlOvviMXjp6M1qkZ/PquWEoFNRTago3808Mh/g3tjEBhGzVlNy uZcVneX4H/PkkFt5eq35Cai6BWKaEQCrvy9xxT0EY2ByLE/sOxXlSpwZ3OkBG1mgKGhJ DInm/niIG1r21PvVqosxuM3fsGHpT9bLXlejbpdfbMiAqwwan8363ov+pjNsP0T/Xmw1 pqtQ== X-Gm-Message-State: AOAM532QuclH3KjbCdu1GTC1ww610+PYXyJRY+0QKIxlw64JiMaMme/6 8XLLOoMAgSlkKiveN7t262MH9w== X-Google-Smtp-Source: ABdhPJwhi191Ank03/s9Kg/631INEG5Z4Qf9mmKT+a3aXomFF1EUF2Oc+PaTvPCxXcKAG3zpYfgJBg== X-Received: by 2002:aa7:c889:: with SMTP id p9mr14880198eds.82.1616764203539; Fri, 26 Mar 2021 06:10:03 -0700 (PDT) Received: from madeliefje.horms.nl ([2001:982:7ed1:404:a2a4:c5ff:fe4c:9ce9]) by smtp.gmail.com with ESMTPSA id 90sm4202624edf.31.2021.03.26.06.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 06:10:02 -0700 (PDT) From: Simon Horman To: David Miller , Jakub Kicinski Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, oss-drivers@netronome.com, Ido Schimmel , Baowen Zheng , Simon Horman Subject: [PATCH net-next 2/2] selftests: forwarding: Add tc-police tests for packets per second Date: Fri, 26 Mar 2021 14:09:38 +0100 Message-Id: <20210326130938.15814-3-simon.horman@netronome.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210326130938.15814-1-simon.horman@netronome.com> References: <20210326130938.15814-1-simon.horman@netronome.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Baowen Zheng Test tc-police action for packets per second. The test is mainly in scenarios Rx policing and Tx policing. The test passes with veth pairs ports. Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman Reviewed-by: Ido Schimmel --- tools/testing/selftests/net/forwarding/lib.sh | 9 +++ .../selftests/net/forwarding/tc_police.sh | 56 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 05c05e02bade..42e28c983d41 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -772,6 +772,15 @@ rate() echo $((8 * (t1 - t0) / interval)) } +packets_rate() +{ + local t0=$1; shift + local t1=$1; shift + local interval=$1; shift + + echo $(((t1 - t0) / interval)) +} + mac_get() { local if_name=$1 diff --git a/tools/testing/selftests/net/forwarding/tc_police.sh b/tools/testing/selftests/net/forwarding/tc_police.sh index 160f9cccdfb7..4f9f17cb45d6 100755 --- a/tools/testing/selftests/net/forwarding/tc_police.sh +++ b/tools/testing/selftests/net/forwarding/tc_police.sh @@ -35,6 +35,8 @@ ALL_TESTS=" police_shared_test police_rx_mirror_test police_tx_mirror_test + police_pps_rx_test + police_pps_tx_test " NUM_NETIFS=6 source tc_common.sh @@ -290,6 +292,60 @@ police_tx_mirror_test() police_mirror_common_test $rp2 egress "police tx and mirror" } +police_pps_common_test() +{ + local test_name=$1; shift + + RET=0 + + # Rule to measure bandwidth on ingress of $h2 + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ + dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \ + action drop + + mausezahn $h1 -a own -b $(mac_get $rp1) -A 192.0.2.1 -B 198.51.100.1 \ + -t udp sp=12345,dp=54321 -p 1000 -c 0 -q & + + local t0=$(tc_rule_stats_get $h2 1 ingress .packets) + sleep 10 + local t1=$(tc_rule_stats_get $h2 1 ingress .packets) + + local er=$((2000)) + local nr=$(packets_rate $t0 $t1 10) + local nr_pct=$((100 * (nr - er) / er)) + ((-10 <= nr_pct && nr_pct <= 10)) + check_err $? "Expected rate $(humanize $er), got $(humanize $nr), which is $nr_pct% off. Required accuracy is +-10%." + + log_test "$test_name" + + { kill %% && wait %%; } 2>/dev/null + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower +} + +police_pps_rx_test() +{ + # Rule to police traffic destined to $h2 on ingress of $rp1 + tc filter add dev $rp1 ingress protocol ip pref 1 handle 101 flower \ + dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \ + action police pkts_rate 2000 pkts_burst 400 conform-exceed drop/ok + + police_pps_common_test "police pps on rx" + + tc filter del dev $rp1 ingress protocol ip pref 1 handle 101 flower +} + +police_pps_tx_test() +{ + # Rule to police traffic destined to $h2 on egress of $rp2 + tc filter add dev $rp2 egress protocol ip pref 1 handle 101 flower \ + dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \ + action police pkts_rate 2000 pkts_burst 400 conform-exceed drop/ok + + police_pps_common_test "police pps on tx" + + tc filter del dev $rp2 egress protocol ip pref 1 handle 101 flower +} + setup_prepare() { h1=${NETIFS[p1]}