From patchwork Fri May 27 09:00:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ByIScVZI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0Z13kkz9sG0 for ; Fri, 27 May 2022 19:00:46 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5003F42885; Fri, 27 May 2022 09:00:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wjG5vtarf-Iq; Fri, 27 May 2022 09:00:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id B116942868; Fri, 27 May 2022 09:00:39 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 89F97C0080; Fri, 27 May 2022 09:00:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 37EA3C0032 for ; Fri, 27 May 2022 09:00:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 273804285D for ; Fri, 27 May 2022 09:00:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5LXJosm8-hyd for ; Fri, 27 May 2022 09:00:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2061e.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8d::61e]) by smtp4.osuosl.org (Postfix) with ESMTPS id E767C42858 for ; Fri, 27 May 2022 09:00:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jn9+V8M1aIA1BPR1n/15RKGz3oCQGDQV+PN9ynyf0eUjqawNNZrGiH6L/QBpUU3skztN71EoZVETnkfpme5N40/VHaY5wNYlU/PFfB07y9SmOCutghwQKJNI0MuNAXuxcmCetoAEszxnhDS0wP0/NPeSMAwrwrcwae8yer0ajdw9wo0grAv40p42kZT1vu2z/U4tEXXZSVjEEeIOyCPSZen7acvL0m/4SjXF2wTEwHP2alula58O6Rvobb/EqvDN2sTwsvjKBsmgFneasqksigFHpk1Uvouf5JcQmk8ZBkDCaNFG3ShMkU8f1KkpnAq2My1f5f44F0m42FohgadJGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w/PAAYVsno7nwCwpBqe2i3np7zsqr2Kn4ydMctmV1bk=; b=Sodkx37ff65QigSpBuC9UvxC6KoODPbKP0znVoM3+KYKXI3xNPtvyPn0EqGAarXPW9O1puQGkp8KV15SmVjRq9mmtODwuH5GA9n8AXqrid6MfkMUT0yfD9KxL9tOFS9QwU7JbsklHC3npOQTuI1D3ADr4OKWKtO7MbUeX6QmAXiHc+N8j+aIs9ryp8SE6wbQks0t1fWa8UGiLTCyQRUxmVTSb+x3rOiyf2gCuz0cnTNvOKT3KbUdnW2l0NwYkBOf6btvYyFXPPjSxUuG0Z/WERAY70qaTOYWDgiXHMBErXdX4g5SueycIZwuaoagi31ueUS2LELuQBq5GM4y0dePig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w/PAAYVsno7nwCwpBqe2i3np7zsqr2Kn4ydMctmV1bk=; b=ByIScVZIHfbJiEpI/LKZg77dQ6fGENRNfoIKv0JT4p6GqcfwE0zhVo9ghNqruPlHZworDx3VBsPemMcGNXB4OZVTaudW90/Bp2iiBB9g/Ah8pppJqygzFdvsWb+PWUrtpJla11yX0RfXTrAh2m4qqnyL6ILMXr1ZcV79Yj7qPhVSa4MUc2+Ww3HEMUZDxNUjv1O6JnbiQFUQxbSNlE5pjbONHnrvD6R/uiQvWpKjqoWwaoA8bUXhg/ArFYbumSJvBARBodGPRrBWU36vcIdPaGQyVxjbIjk2880U5x2cGF5ObMyc7gvvoM0Poo7BF7MO1W7vJfZeWmT6xY9NBne9QA== Received: from BN9PR03CA0976.namprd03.prod.outlook.com (2603:10b6:408:109::21) by CY4PR12MB1846.namprd12.prod.outlook.com (2603:10b6:903:11b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.17; Fri, 27 May 2022 09:00:31 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:408:109:cafe::6f) by BN9PR03CA0976.outlook.office365.com (2603:10b6:408:109::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:31 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:30 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:29 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:27 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:14 +0000 Message-ID: <20220527090021.22594-2-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 46e50795-e03e-49e3-1dff-08da3fbf5a46 X-MS-TrafficTypeDiagnostic: CY4PR12MB1846:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Jos3hoemAMogBqEs1x2vMkNIP0j/679Ppd6dAkNq1S2onjQlf2YjIWSLRdwt4Jj0/YMzgvBlqZOvAQ34FRLHRX+btrdGS3oTn0Zv8ZN6B2DjXCoAuWFB5h0qFGzh4/pkjLbu73GYYVufSSdYgb2LJ3UyKagZeceQD7ZqEPUXzwf7wCz9Jx6yA/9iO8xdqgShHFgeklVAAPciKWYcPcMPGy4USoD0qe1oW5LPguVXeRiJmZ5wl+3M7uMLaALC/Mw14MaGOQ6rmSBVla5BavUU2qTzMoOygy2fN3QNYFIlUoAscBdXSpQVVB9tvyAUAi/kwk6oS7AoTXJflBKDlT7xxDaaxL+2TD2/gE5yPiSSxNkG/FPL+zGAxtgAx4TxRyPwP/cSx8rPp3SKV5K8HRA/Qj0wp4WrmCYAjUVThOnH99aVc1c8F7u7VsXnogBwjLR9LTQvjbr2ByDLgJw4xV0j3ctvqlsVufnG85Y8S9YJatzQuU/IuAS/DAiTar+8C/vhMh/TwRSEiNSRvbh26qk+sSmNON/LxNsXjNN8wWF+QTEvCbEF37dfakgQLvTANdnt2nfsfbQrFveCrVIc5mJN9adt0uWGQdLHab/k1nYh7kxsqn92L4ABZ9bMsd7hZOnkd/GSG8xSd1nADV0bsDpBQOe96rIvWw9TgSEC/X5LrsrQrR4/MAJvbZiobKT4emLTGECBGMDzMenwe/FgDal88w== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(70206006)(2906002)(316002)(508600001)(6666004)(8676002)(8936002)(81166007)(4326008)(5660300002)(356005)(36860700001)(70586007)(1076003)(2616005)(107886003)(336012)(426003)(47076005)(83380400001)(36756003)(7696005)(82310400005)(110136005)(186003)(40460700003)(86362001)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:31.0319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46e50795-e03e-49e3-1dff-08da3fbf5a46 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1846 Cc: Jianbo Liu Subject: [ovs-dev] [v5 1/8] netdev-offload: Add meter offload API X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add API to offload meter to HW, and the corresponding functions to call the meter callbacks from all the registered flow API providers. The interfaces are like those related to meter in dpif_class, in order to pass necessary info to HW. Signed-off-by: Jianbo Liu --- lib/netdev-offload-provider.h | 19 +++++++++++++ lib/netdev-offload.c | 51 +++++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 8 ++++++ 3 files changed, 78 insertions(+) diff --git a/lib/netdev-offload-provider.h b/lib/netdev-offload-provider.h index 8ff2de983..c3028606b 100644 --- a/lib/netdev-offload-provider.h +++ b/lib/netdev-offload-provider.h @@ -94,6 +94,25 @@ struct netdev_flow_api { * takes ownership of a packet if errno != EOPNOTSUPP. */ int (*hw_miss_packet_recover)(struct netdev *, struct dp_packet *); + /* Offloads or modifies the offloaded meter in HW with the given 'meter_id' + * and the configuration in 'config'. + * + * The meter id specified through 'config->meter_id' is ignored. */ + int (*meter_set)(ofproto_meter_id meter_id, + struct ofputil_meter_config *config); + + /* Queries HW for meter stats with the given 'meter_id'. + * Store the stats of dropped packets to band 0. */ + int (*meter_get)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands); + + /* Removes meter 'meter_id' from HW. Stores meter statistics if successful. + * 'stats' may be passed in as NULL if no stats are needed. */ + int (*meter_del)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands); + /* Initializies the netdev flow api. * Return 0 if successful, otherwise returns a positive errno value. */ int (*init_flow_api)(struct netdev *); diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index fb108c0d5..e853b4e2a 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -58,6 +58,7 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload); +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); static bool netdev_flow_api_enabled = false; #define DEFAULT_OFFLOAD_THREAD_NB 1 @@ -195,6 +196,56 @@ netdev_assign_flow_api(struct netdev *netdev) return -1; } +int +meter_offload_set(ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_set) { + int ret = rfa->flow_api->meter_set(meter_id, config); + if (ret) { + VLOG_DBG_RL(&rl, + "Failed setting meter for flow api %s, error %d", + rfa->flow_api->type, ret); + } + } + } + + return 0; +} + +int +meter_offload_get(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, uint16_t max_bands) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_get) { + rfa->flow_api->meter_get(meter_id, stats, max_bands); + } + } + + return 0; +} + +int +meter_offload_del(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, uint16_t max_bands) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_del) { + rfa->flow_api->meter_del(meter_id, stats, max_bands); + } + } + + return 0; +} + int netdev_flow_flush(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 8237a85dd..a6d4ba3cb 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -22,6 +22,7 @@ #include "openvswitch/types.h" #include "ovs-rcu.h" #include "ovs-thread.h" +#include "openvswitch/ofp-meter.h" #include "packets.h" #include "flow.h" @@ -158,6 +159,13 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, int netdev_ports_get_n_flows(const char *dpif_type, odp_port_t port_no, uint64_t *n_flows); +int meter_offload_set(ofproto_meter_id, + struct ofputil_meter_config *); +int meter_offload_get(ofproto_meter_id, + struct ofputil_meter_stats *, uint16_t); +int meter_offload_del(ofproto_meter_id, + struct ofputil_meter_stats *, uint16_t); + #ifdef __cplusplus } #endif From patchwork Fri May 27 09:00:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=N9hhz83T; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0W1jgBz9sG0 for ; Fri, 27 May 2022 19:00:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 38A3B4286A; Fri, 27 May 2022 09:00:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WtDH5Dy5PMPO; Fri, 27 May 2022 09:00:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id DC3D442811; Fri, 27 May 2022 09:00:37 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 98D81C007C; Fri, 27 May 2022 09:00:37 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1006CC0032 for ; Fri, 27 May 2022 09:00:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E47A861638 for ; Fri, 27 May 2022 09:00:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gCHpszpryveO for ; Fri, 27 May 2022 09:00:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20616.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::616]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1D6716162C for ; Fri, 27 May 2022 09:00:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Run7gp+9h7wJoefjlmAmg690+kJ7VmKa/e7ZOwhUyewsVw8sWbo9Yq1GXyi2jBZCx3slOwxVRdiwwRKyHh8axIazJDc966oPEu3QIgANd3UM7gM7fvCxzA/7UDx/215wuNkZRVI9zTbdSQgI5XmOcGr1xtLcFhWkHNbH/8UpMKC3tnc8bX2FH9RBipW8eZL97r+YQO9eEWaT6lE4UVLcWyazh9KnWeUI4A9M/TQjiKcBtjzV232KibCvRdN40FAMiC7pNBZxNyUrcVOxIgY3FZ9hEB5ZeadP5NSqnyhL3WZkzEZd8DKyzakS/3BudSdP/z2T1ipDw98D0Q4eWx7N/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J9V/Uu2U5+ngcqgBJ49d0ZBzD3P5QArsLzxWfBx9FgY=; b=GjkfR4l+2xaNM2CdsXw7NksP2BFGtGWGDyyIRZc5RcxWxAwZv/Hy9RfDsNndQ7hXsnuBidlgfaiH2cwRpFZRQOnTGls99Smex5dPJx6fCD35lfetQ7l3mnAhbFH3f2BvOYkK8UWbYemV/rVbQZyacaXMLudVDh2ZqMoJfXHQkBTWsvdeDYyAlnGQWi53nH8WEE47+6ZlKJj6xzHokod1IfbdA63uijKJ0nELoEJVHmLmaKWMaho2mUJ0jIW31QLmh3GWfEgHMrSxh+Tp+Q0T3LREyhwOUNXJlNgFDPs3cD9DpZgGbjBONvS0/Udqhx4gs+N5JurDjlLZOtsWYgmtrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J9V/Uu2U5+ngcqgBJ49d0ZBzD3P5QArsLzxWfBx9FgY=; b=N9hhz83TWDIQb0C1RhrvCC3G8/47PpTt0VdS8tde3Q0GYO1Y5hCfY0vQUB9SNF1axANEPm6NWMp17fef0h5Y5fqcKOMETbKxIeKYWUpJrVx19j3KqFq1ENg+DZmpRnzFp1x+iG5U6NaviFPttvnbsx53Zz5teZWXa0VHFvFIe4J86AljTsgnP8zUyy6fsAWO83+47xsNdP7TppsnPceU/T25mcAkfNZodbB72+Pt+fBSXE1wZmiqUZ82OnBMaRN/lu3XpVjRdolhDc2ACqK/c3zJNbbbjiViW44Y4yTqWT3ZVMXdtcda/oPTn1asBxe/gEYHo8M+siAY+eapBD8u3g== Received: from BN8PR04CA0050.namprd04.prod.outlook.com (2603:10b6:408:d4::24) by BN6PR12MB1508.namprd12.prod.outlook.com (2603:10b6:405:f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:34 +0000 Received: from BN8NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:408:d4:cafe::1c) by BN8PR04CA0050.outlook.office365.com (2603:10b6:408:d4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT068.mail.protection.outlook.com (10.13.177.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:32 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:32 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:30 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:15 +0000 Message-ID: <20220527090021.22594-3-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 817419f9-5e2f-4df7-eb56-08da3fbf5be1 X-MS-TrafficTypeDiagnostic: BN6PR12MB1508:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gyNqhhAsCOLdeGOoBiMkfur/qTV01GLeIt9iLNDpZkVhL1bBhfqiLxGfaTgTYRq8WEF/BxNgf/6+btmIhmVmLGBQmAqfY31JhSLjt7Ekoht10EVnl2Z5OzXvn1MQ6jLLqOzsLNhzCyIHb30sHmIOrTYyzLvtjIoZYHlYrObojLG2AQl8aNv7ZDVNJ58z9x/igm8+FPZlk970lsk7H/MErc3qC11D6/rmix4BojFpBCEe+ZgChX1gRZLPok+VAbwpmHfzpESvRUXTIp3wIsjLGmCVy+GMZBFqdxu+XAmAJ6VW2u7dweqiRrklEu5rIkIHeXWfygfBhzA3wXeQX2lpKPA5pJKMHNxy8leabAAEUNiAAxmgWo1Wid4qIeDZUItQTMiPcusD8mIksfMJKaEx4K4vyIOgBJadCaxGR8Tz41EdPw2/tB0uY2SX5QBorccSJDorjySdZGNTkRXiJVXUAJTtHzvKXG63D9lXUMWNAglceHjnCOf5V/W4TDrnxqB5DfVIwM8ERlZaQfiKcqgyEA30nni428/XeAarBiHhD+qVF8G7ckLpq1xCtZY8jjCEqqpk5n+5+uH2cqFjlcyLulPYP4MBUntarhWvjccJTWKU5A7NkXonWK4gT41qRQRwrjHcZeLEnH7D1j03lisbEz8D/3tDWGBvjPdhTYdVTto1BckExQBUQ0AhNSGTUcmFHYtU13XXRMf5jUCfEO73jA== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(4326008)(70586007)(70206006)(86362001)(110136005)(36756003)(316002)(8676002)(36860700001)(47076005)(82310400005)(508600001)(1076003)(2906002)(2616005)(107886003)(7696005)(6666004)(5660300002)(26005)(8936002)(356005)(426003)(83380400001)(336012)(81166007)(186003)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:33.7463 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 817419f9-5e2f-4df7-eb56-08da3fbf5be1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1508 Cc: Jianbo Liu Subject: [ovs-dev] [v5 2/8] tc: Add support parsing tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add function to parse police action from netlink message. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 4 +++ lib/tc.c | 54 +++++++++++++++++++++++++++++++++++++++++ lib/tc.h | 5 ++++ 3 files changed, 63 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index a41b62758..83d57c63b 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1017,6 +1017,10 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_u32(buf, OVS_ACTION_ATTR_RECIRC, action->chain); } break; + case TC_ACT_POLICE: { + /* Not supported yet */ + } + break; } } } diff --git a/lib/tc.c b/lib/tc.c index df73a43d4..5d96567e0 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1339,6 +1339,54 @@ nl_parse_act_gact(struct nlattr *options, struct tc_flower *flower) return 0; } +static const struct nl_policy police_policy[] = { + [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_police), + .optional = false, }, + [TCA_POLICE_RATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_PEAKRATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_AVRATE] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_RESULT] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_TM] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tcf_t), + .optional = true, }, +}; + +static int +nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {}; + const struct tc_police *police; + struct tc_action *action; + struct nlattr *police_tm; + const struct tcf_t *tm; + + if (!nl_parse_nested(options, police_policy, police_attrs, + ARRAY_SIZE(police_policy))) { + VLOG_ERR_RL(&error_rl, "Failed to parse police action options"); + return EPROTO; + } + + police = nl_attr_get_unspec(police_attrs[TCA_POLICE_TBF], sizeof *police); + action = &flower->actions[flower->action_count++]; + action->type = TC_ACT_POLICE; + action->police.index = police->index; + + police_tm = police_attrs[TCA_POLICE_TM]; + if (police_tm) { + tm = nl_attr_get_unspec(police_tm, sizeof *tm); + nl_parse_tcf(tm, flower); + } + + return 0; +} + static const struct nl_policy mirred_policy[] = { [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct tc_mirred), @@ -1761,6 +1809,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, /* Added for TC rule only (not in OvS rule) so ignore. */ } else if (!strcmp(act_kind, "ct")) { nl_parse_act_ct(act_options, flower); + } else if (!strcmp(act_kind, "police")) { + nl_parse_act_police(act_options, flower); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; @@ -2773,6 +2823,10 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) nl_msg_end_nested(request, act_offset); } break; + case TC_ACT_POLICE: { + /* Not supported yet */ + } + break; } } } diff --git a/lib/tc.h b/lib/tc.h index d6cdddd16..751bec891 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -174,6 +174,7 @@ enum tc_action_type { TC_ACT_MPLS_SET, TC_ACT_GOTO, TC_ACT_CT, + TC_ACT_POLICE, }; enum nat_type { @@ -261,6 +262,10 @@ struct tc_action { struct tc_flower_key key; struct tc_flower_key mask; } rewrite; + + struct { + uint32_t index; + } police; }; enum tc_action_type type; From patchwork Fri May 27 09:00:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=oNmebCvP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0b0mMPz9sG4 for ; Fri, 27 May 2022 19:00:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E7A2041334; Fri, 27 May 2022 09:00:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qSG3g4JQLkIR; Fri, 27 May 2022 09:00:43 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 287FF41330; Fri, 27 May 2022 09:00:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ECCEFC0032; Fri, 27 May 2022 09:00:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 35642C007F for ; Fri, 27 May 2022 09:00:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 305EE84A24 for ; Fri, 27 May 2022 09:00:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CABV85ZlFYdf for ; Fri, 27 May 2022 09:00:39 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061f.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::61f]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1EF0D84932 for ; Fri, 27 May 2022 09:00:39 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KHm3XAkgM7creDKJdddLkmbRBvqsXGHklB1F3pKDb8t+zqHfF+OllnFsOX1q0qbiNKFfq2AdSRAnPFZokzEw8VWnrdLhjV4nTp9LyVDQao7hsDY5pzVYYP12DOf2jQkjah7cgN9cXu1f1gjJVZfspfswnspsZT0MyvaCAGHQGcEkxsDUm8xtntJV+ghJZ1kpF/3ghBgM4fD44XhNznPFD1P3W39ZlOxjrWLLBTuX/2i5w4PypCuxLEb3b0ukfZNUF3VZy5O6h6Db0bOXmOV6gDAhYUK6xJVQfFufMnNKkJbDCeqD/1LUD1MImpsDOduXIQVmUcQ5fncqUjjv1O5yCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5APrOF6oiT3LYkek91tq0zpMn1tMQA36E82+8FGplfQ=; b=PXNCW5R20tWtNulUpFXnE1wTbPNV1qTbeIRQ8vAarXSvmr5BrsEObpFFbFdcSXjWhkDIFExa3AgPxwQvjRO5sGxBDjhly4nKVYUE1O4wnUQ2iRHL5KbORwsDC+u2kF5ri78CKe5/fkxSjVk6xV1oWjLkuKONu6e5Lt98xFJKwViEyHo2AvSv9m+5dR3r6uXCWsobS/ahBthZcfH9/pKrqzqg++ANpNBPHU+bgbZrYCXZWkyGMHEdpuu3pTcPR3XFRwxKB+fz/7SHkseORvAkrep/sZRU1MBEDYBZn25zW9mWiqj3ZkL7wYe8OXV8GjTc00Wgg3BBVpw3TIiCof0KnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5APrOF6oiT3LYkek91tq0zpMn1tMQA36E82+8FGplfQ=; b=oNmebCvP7JEK6G1pF3igbVW9o5/6GzjMaMAZIIHNM/KjFrDdt1U+GHpAGf8m69uthp0xOstJWqejWk8Q/VA9EeGhKGBt7Y+44HK+9caIEJyLI5nOug1lHsXxmIPCS2RKudJZxKJRrMXuV5D8Sp0MyCpifv2krI8HxJ8SZMl3TZVQjZUt4HZcj/0pQuHmXxlx+waBxr+WPv7mwCrdH3t7xBhqin7xUZrCp61lbeSFPSKsdKfKo7OdQzxfGtUxfhpr4/xzxsuvWA3GJ7+ni8lu6vggbG9fB4U2WViC41vLSAf03E7BQLdtflGfEU+zM24Dzx7XpC1Vo5wVna8Ae3x1Dg== Received: from BN9PR03CA0930.namprd03.prod.outlook.com (2603:10b6:408:107::35) by DM6PR12MB4060.namprd12.prod.outlook.com (2603:10b6:5:216::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:36 +0000 Received: from BN8NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::b5) by BN9PR03CA0930.outlook.office365.com (2603:10b6:408:107::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.22 via Frontend Transport; Fri, 27 May 2022 09:00:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT003.mail.protection.outlook.com (10.13.177.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:36 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:35 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:34 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:32 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:16 +0000 Message-ID: <20220527090021.22594-4-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74bab1a4-d0d5-47f5-1d7a-08da3fbf5d4f X-MS-TrafficTypeDiagnostic: DM6PR12MB4060:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VhgL1Y9tf6KDy+wt0gsmjOvjnbH+8CWA5kLPsq38AKXHfPdURp93h0el4DQ5dHgVI73WYWKbMXQNThWbS5L9ml2hJ9N00zKgHgEjUsXU3kGmLC1v5y9ocXif11XOXwwtV6OZphDC2YE1Sl7X9fl3pxXOAwfNSK5RHije1Wp93SbvwBXmI1vzndBPKZaMd2yuuNEZS2HWYqDTk6Y+M4gxtsSCcAX+2GssDWQWZXJ7Vp1bCI9EPbmqX3wmWa09uwaIvUiY66U6P/dphS/V+P9XCURgq1evtjD9UahzhEoEEjtCJEw7X/LJAqgAEzB2KBxT/IXu6J4OFftQMJf5d9ZzK4r0Wq7E34KMP2LfhQXYb8xETgrFspf8sg+RovhwiIycyhbRqPcUpeKpAXujXzayHEZz3sHROIU45dtxDbwJVezrgq/nYW3fM2Arz8Stt1KQqNr1eEPN/l3F0M9EiEaqtbyuv0lG/Q71LaqC/bRFX5VH19w1oDBI2V2clJz2pwl63SRafY/b2m/3DS6I0sJAjEOeo8dNj59419pLIW31B7M6Th/Yf4Sg7Fkb/81IANLlfYufkHmHjmqkCzuL4IVHgCnChEXvW9ljiqnl9SGAGwrswuhZ+WmxHZPHB2wK5R4hg4RYsigxrDTSaauIJyQFNLVcgTrNiu62uvr4Ch1tmAOlIx8FP0rOQvJagm6yh1SrEf0vuz0PpS2YH3RuUfScrg== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(15650500001)(1076003)(8936002)(2906002)(70206006)(70586007)(36756003)(4326008)(8676002)(5660300002)(40460700003)(36860700001)(316002)(86362001)(110136005)(83380400001)(82310400005)(2616005)(81166007)(508600001)(186003)(47076005)(336012)(426003)(6666004)(356005)(7696005)(26005)(107886003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:36.1397 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74bab1a4-d0d5-47f5-1d7a-08da3fbf5d4f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4060 Cc: Jianbo Liu Subject: [ovs-dev] [v5 3/8] netdev-linux: Refactor put police action netlink message X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" To reuse the code for manipulating police action, move the common initialization code to a function, and change PPS parameters as meter pktps is in unit of packet per second. null_police is redundant because either BPS or PPS, not both, can be configured in one message. So the police passed in to nl_msg_put_act_police can be reused as its rate is zero for PPS, and it also provides the index for police action to be created. Signed-off-by: Jianbo Liu --- lib/netdev-linux.c | 89 ++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 2766b3f2b..4956e2fd1 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,30 @@ nl_msg_act_police_end_nest(struct ofpbuf *request, size_t offset, } static void -nl_msg_put_act_police(struct ofpbuf *request, struct tc_police police, - uint32_t kpkts_rate, uint32_t kpkts_burst) +nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police, + uint64_t pkts_rate, uint64_t pkts_burst) { size_t offset, act_offset; uint32_t prio = 0; - /* used for PPS, set rate as 0 to act as a single action */ - struct tc_police null_police; - - memset(&null_police, 0, sizeof null_police); - - if (police.rate.rate) { - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - tc_put_rtab(request, TCA_POLICE_RATE, &police.rate); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); - nl_msg_act_police_end_nest(request, offset, act_offset); - } - if (kpkts_rate) { - unsigned int pkt_burst_ticks, pps_rate, size; - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - pps_rate = kpkts_rate * 1000; - size = MIN(UINT32_MAX / 1000, kpkts_burst) * 1000; + + if (!police->rate.rate && !pkts_rate) { + return; + } + + nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); + if (police->rate.rate) { + tc_put_rtab(request, TCA_POLICE_RATE, &police->rate); + } + if (pkts_rate) { + uint64_t pkt_burst_ticks; /* Here tc_bytes_to_ticks is used to convert packets rather than bytes to ticks. */ - pkt_burst_ticks = tc_bytes_to_ticks(pps_rate, size); - nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pps_rate); - nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, - (uint64_t) pkt_burst_ticks); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &null_police, - sizeof null_police); - nl_msg_act_police_end_nest(request, offset, act_offset); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, pkts_rate); + nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, pkt_burst_ticks); } + nl_msg_put_unspec(request, TCA_POLICE_TBF, police, sizeof *police); + nl_msg_act_police_end_nest(request, offset, act_offset); } static int @@ -2692,7 +2685,8 @@ tc_add_matchall_policer(struct netdev *netdev, uint32_t kbits_rate, nl_msg_put_string(&request, TCA_KIND, "matchall"); basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); action_offset = nl_msg_start_nested(&request, TCA_MATCHALL_ACT); - nl_msg_put_act_police(&request, pol_act, kpkts_rate, kpkts_burst); + nl_msg_put_act_police(&request, &pol_act, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, action_offset); nl_msg_end_nested(&request, basic_offset); @@ -5599,6 +5593,29 @@ netdev_linux_tc_make_request(const struct netdev *netdev, int type, return tc_make_request(ifindex, type, flags, request); } +static void +tc_policer_init(struct tc_police *tc_police, uint64_t kbits_rate, + uint64_t kbits_burst) +{ + int mtu = 65535; + + memset(tc_police, 0, sizeof *tc_police); + + tc_police->action = TC_POLICE_SHOT; + tc_police->mtu = mtu; + tc_fill_rate(&tc_police->rate, kbits_rate * 1000 / 8, mtu); + + /* The following appears wrong in one way: In networking a kilobit is + * usually 1000 bits but this uses 1024 bits. + * + * However if you "fix" those problems then "tc filter show ..." shows + * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == + * 1,000,000 bits, whereas this actually ends up doing the right thing from + * tc's point of view. Whatever. */ + tc_police->burst = tc_bytes_to_ticks( + tc_police->rate.rate, kbits_burst * 1024 / 8); +} + /* Adds a policer to 'netdev' with a rate of 'kbits_rate' and a burst size * of 'kbits_burst', with a rate of 'kpkts_rate' and a burst size of * 'kpkts_burst'. @@ -5623,22 +5640,7 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, struct ofpbuf request; struct tcmsg *tcmsg; int error; - int mtu = 65535; - memset(&tc_police, 0, sizeof tc_police); - tc_police.action = TC_POLICE_SHOT; - tc_police.mtu = mtu; - tc_fill_rate(&tc_police.rate, ((uint64_t) kbits_rate * 1000)/8, mtu); - - /* The following appears wrong in one way: In networking a kilobit is - * usually 1000 bits but this uses 1024 bits. - * - * However if you "fix" those problems then "tc filter show ..." shows - * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == - * 1,000,000 bits, whereas this actually ends up doing the right thing from - * tc's point of view. Whatever. */ - tc_police.burst = tc_bytes_to_ticks( - tc_police.rate.rate, MIN(UINT32_MAX / 1024, kbits_burst) * 1024 / 8); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5648,9 +5650,12 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, tcmsg->tcm_info = tc_make_handle(49, (OVS_FORCE uint16_t) htons(ETH_P_ALL)); nl_msg_put_string(&request, TCA_KIND, "basic"); + basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); police_offset = nl_msg_start_nested(&request, TCA_BASIC_ACT); - nl_msg_put_act_police(&request, tc_police, kpkts_rate, kpkts_burst); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset); From patchwork Fri May 27 09:00:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=dtvgN6kb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0n38Rnz9sG0 for ; Fri, 27 May 2022 19:00:57 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 16D27428AE; Fri, 27 May 2022 09:00:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0J-rAaufzF7i; Fri, 27 May 2022 09:00:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 6745C4289B; Fri, 27 May 2022 09:00:52 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01F46C0032; Fri, 27 May 2022 09:00:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0A1B2C007C for ; Fri, 27 May 2022 09:00:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E661741343 for ; Fri, 27 May 2022 09:00:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6vO5sH8Wu6gn for ; Fri, 27 May 2022 09:00:43 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20620.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::620]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1287E4132C for ; Fri, 27 May 2022 09:00:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B78pHHX1H/y1JpR1BDYbAOGoYYyBGjVnpj/ggirAObWfFSOrRBDWck8J3FcY05aaFMkKVwp5Oe7z313wy30TsxdePT/vOq1+rXUX39CaEfoAKSsgkJJhblhRtypQ/qqtrCIKorVixo1wPDDYlPeVbRkoqbwBdgdMZuU5BJ/WVVWZNd/sWxnR76UMawUX+uMSlVBhRD2bthLQADfFV108Avxt0MyzC7IV/VDgpsnKe/DARYHdq/n/I1c/2YRgWl5pNHNyv25YIJDW2XlNmhKieAUeMoW+VEktqW73q9KYYCzHxW0QyzEnKW9696LCbhGooQuc3tMvkfmcAcW7HuS67Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZlfQS/COQsPM7Te8uK4kWXdVoh4zvA+1VVMbTbPSj/g=; b=XBxBfjDA2Op9rjuJ8aotVEXDa8JVH2aafHvlUjJDtVGALIFP4jyLtFSK3su4X5phdNGe79GPOQNrxDLH/OpZe/uv8eKIMxW0ud/WmsJ3e+6HTKESqo67f7rOOHxq+O8BX1+Z1Y2WsIEy0B4oBaRAxF6mo50Ba5wYXpYYaHG3vjR/dYdLfOFzbVEYOcyP0IOsJrKn20zJgP8tl3E1002/idQ1KNDKOTLpLEuNa/OiF38s/eoMNWgnhSZnalNIxNvvZz6aBn1GadJMj/qJmrZaH+gfoJ5dwYJ4o+jjxbrWT34bifuSlboqi+6Ts7Yp5Yjs5XaOM4fSfcOw3EzZpEjBgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZlfQS/COQsPM7Te8uK4kWXdVoh4zvA+1VVMbTbPSj/g=; b=dtvgN6kbLFsYfIonSInalCw2dKSmSYg10RlnmDY24FuuZcILVYQLLkOFGQ2pSPnF3nN61JFDuvMQXBhU6pd9HheXB/BEmEdhtD1mUpYssC4VXTyEudbRV62zfrEAOhxk9cjbjLlnFmSJ6rJmllU8+XIILm1TgEraInE1Uzb5zwJkNWXvzof0XX7uUuwLYBGU02GXeaIiXAiEWkX5/tkNimzMF46yQQEPhr8P35xWcFshTx6cc2mAuFmNukWUzqld61uMTQreX9nGErtCnq1EAAc1z7KEWLum9D4bZqmzdkz6Mt8h4wQrVAjIGdhqUMJWnawbL3D1fzFXRkWqo/uR+A== Received: from BN8PR16CA0002.namprd16.prod.outlook.com (2603:10b6:408:4c::15) by BY5PR12MB5560.namprd12.prod.outlook.com (2603:10b6:a03:1d8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:39 +0000 Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:408:4c:cafe::75) by BN8PR16CA0002.outlook.office365.com (2603:10b6:408:4c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:38 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:37 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:37 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:35 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:17 +0000 Message-ID: <20220527090021.22594-5-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 322ff727-5a87-436e-f70b-08da3fbf5ec7 X-MS-TrafficTypeDiagnostic: BY5PR12MB5560:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: simfDpz9Nbe8tn9oAZoQNi4cDXvT8Q2L96OoDblAo01vZ1WNPSpho6551s6PsUiLHmmtUB4Gv5Kun0Y/UKPML4H2zjK1M23xxha5r07mW+z2RI+faoQ4G8t6lKYjsHNkW3CzyM86ft+U7ckrQ7h6DHjCQHgO/7NkUNH6lt08SotQtk/d2XAbmcvyGX511Y3hGygXCp414bviEumnkF4FbemxcgWFcYXN/jioUCnPbQesFPSPCop81tAKBaLZXcXzQNrQq+4gaM0oK2Gh2uPnwq7P2zKrKfvA6tcwZB74TW3jEBVupD3ZTHdk7ijzsyNDNIThdIgzw/YRv76GenBjjPv7fJ2Hlx0h6W/jhKHpasD36yPyTte3JsOwTQ1/vXxHJXYbEj/jTVcutkOHSbyhnVgUeFK6Cwn9VnaGP9NQx1mz5fzUDZM14+x7rmYREQcbULBt6DIOQl4C/EmztRTPyNVom8EPlIqNmTPTvJE0qK+JkNNin+PD/6XJYx/A5Gh74rT8ivLSvAZiu4uJO8GJaqVR1ysFPYgBvrD/Zx7RYcI9jdD9dIk3lUZWfm+eSFt7pEUzVxuzNnIEv2qbjvXlEXTlYhC9kJfiF8h3MCyhx9vDELvTsIbqiFkn3/E4pxdU258dbMEQtebCTITonhs3CvClV8E0L5p/OGgZ3jBPEYrrL9savMrcYje1m6v5s0vHXqJwdoeQPNaBpcMObXGYJA== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(36860700001)(336012)(426003)(110136005)(47076005)(356005)(36756003)(316002)(83380400001)(107886003)(2616005)(186003)(1076003)(5660300002)(508600001)(30864003)(82310400005)(26005)(8936002)(7696005)(40460700003)(2906002)(81166007)(86362001)(4326008)(8676002)(6666004)(70206006)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:38.5469 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 322ff727-5a87-436e-f70b-08da3fbf5ec7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5560 Cc: Jianbo Liu Subject: [ovs-dev] [v5 4/8] netdev-linux: Add functions to manipulate tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add helpers to add, delete and get stats of police action with the specified index. Signed-off-by: Jianbo Liu --- lib/netdev-linux.c | 142 +++++++++++++++++++++++++++++++++++++++++++++ lib/netdev-linux.h | 6 ++ lib/tc.c | 114 +++++++++++++++++++++++++----------- lib/tc.h | 7 +++ 4 files changed, 235 insertions(+), 34 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 4956e2fd1..94422cbc8 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5667,6 +5667,148 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, return 0; } +int +tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update) +{ + struct tc_police tc_police; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t offset; + int flags; + int error; + + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + tc_police.index = index; + + flags = (update ? NLM_F_REPLACE : NLM_F_EXCL) | NLM_F_CREATE; + tcamsg = tc_make_action_request(RTM_NEWACTION, flags, &request); + if (!tcamsg) { + return ENODEV; + } + + offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + nl_msg_put_act_police(&request, &tc_police, pkts_rate, pkts_burst); + nl_msg_end_nested(&request, offset); + + error = tc_transact(&request, NULL); + if (error) { + VLOG_ERR_RL(&rl, "Failed to %s police action, err=%d", + update ? "update" : "add", error); + } + + return error; +} + +static int +tc_update_policer_action_stats(struct ofpbuf *msg, + struct ofputil_meter_stats *stats) +{ + struct ovs_flow_stats stats_dropped = {}; + struct ovs_flow_stats stats_hw = {}; + struct ovs_flow_stats stats_sw = {}; + const struct nlattr *act = NULL; + struct nlattr *prio; + struct tcamsg *tca; + int error; + + if (!stats) { + return 0; + } + + if (NLMSG_HDRLEN + sizeof *tca > msg->size) { + VLOG_ERR_RL(&rl, "Failed to get action stats, size error"); + return EPROTO; + } + + tca = ofpbuf_at_assert(msg, NLMSG_HDRLEN, sizeof *tca); + act = nl_attr_find(msg, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!act) { + VLOG_ERR_RL(&rl, "Failed to get action stats, can't find attr"); + return EPROTO; + } + + prio = (struct nlattr *) act + 1; + error = tc_parse_action_stats(prio, &stats_sw, &stats_hw, &stats_dropped); + if (!error) { + stats->packet_in_count += + get_32aligned_u64(&stats_sw.n_packets); + stats->byte_in_count += get_32aligned_u64(&stats_sw.n_bytes); + stats->packet_in_count += + get_32aligned_u64(&stats_hw.n_packets); + stats->byte_in_count += get_32aligned_u64(&stats_hw.n_bytes); + stats->bands[0].packet_count += + get_32aligned_u64(&stats_dropped.n_packets); + } + + return error; +} + +int +tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int error; + + tcamsg = tc_make_action_request(RTM_GETACTION, 0, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (error) { + VLOG_ERR_RL(&rl, "Failed to dump police action (index: %u), err=%d", + index, error); + return error; + } + + return tc_update_policer_action_stats(replyp, stats); +} + +int +tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int error; + + tcamsg = tc_make_action_request(RTM_DELACTION, NLM_F_ACK, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (error) { + VLOG_ERR_RL(&rl, "Failed to delete police action (index: %u), err=%d", + index, error); + return error; + } + + return tc_update_policer_action_stats(replyp, stats); +} + static void read_psched(void) { diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h index e1e30f806..9a416ce50 100644 --- a/lib/netdev-linux.h +++ b/lib/netdev-linux.h @@ -19,6 +19,7 @@ #include #include +#include "openvswitch/ofp-meter.h" /* These functions are Linux specific, so they should be used directly only by * Linux-specific code. */ @@ -28,5 +29,10 @@ struct netdev; int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag, const char *flag_name, bool enable); int linux_get_ifindex(const char *netdev_name); +int tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update); +int tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats); +int tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats); #endif /* netdev-linux.h */ diff --git a/lib/tc.c b/lib/tc.c index 5d96567e0..77d0c9de7 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -199,6 +199,20 @@ tc_make_request(int ifindex, int type, unsigned int flags, return tcmsg; } +struct tcamsg * +tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request) +{ + struct tcamsg *tcamsg; + + ofpbuf_init(request, 512); + nl_msg_put_nlmsghdr(request, sizeof *tcamsg, type, NLM_F_REQUEST | flags); + tcamsg = ofpbuf_put_zeros(request, sizeof *tcamsg); + tcamsg->tca_family = AF_UNSPEC; + + return tcamsg; +} + static void request_from_tcf_id(struct tcf_id *id, uint16_t eth_type, int type, unsigned int flags, struct ofpbuf *request) @@ -1759,23 +1773,67 @@ static const struct nl_policy stats_policy[] = { [TCA_STATS_BASIC_HW] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct gnet_stats_basic), .optional = true, }, + [TCA_STATS_QUEUE] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct gnet_stats_queue), + .optional = true, }, }; +static int +nl_parse_action_stats(struct nlattr *act_stats, + struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped) +{ + struct gnet_stats_basic bs_sw = { .packets = 0, .bytes = 0, }; + struct nlattr *stats_attrs[ARRAY_SIZE(stats_policy)]; + const struct gnet_stats_basic *bs_all = NULL; + const struct gnet_stats_basic *bs_hw = NULL; + const struct gnet_stats_queue *qs; + + if (!nl_parse_nested(act_stats, stats_policy, stats_attrs, + ARRAY_SIZE(stats_policy))) { + VLOG_ERR_RL(&error_rl, "failed to parse action stats policy"); + return EPROTO; + } + + bs_all = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof *bs_all); + if (stats_attrs[TCA_STATS_BASIC_HW]) { + bs_hw = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC_HW], + sizeof *bs_hw); + + bs_sw.packets = bs_all->packets - bs_hw->packets; + bs_sw.bytes = bs_all->bytes - bs_hw->bytes; + } else { + bs_sw.packets = bs_all->packets; + bs_sw.bytes = bs_all->bytes; + } + + if (bs_sw.packets > get_32aligned_u64(&stats_sw->n_packets)) { + put_32aligned_u64(&stats_sw->n_packets, bs_sw.packets); + put_32aligned_u64(&stats_sw->n_bytes, bs_sw.bytes); + } + + if (bs_hw && bs_hw->packets > get_32aligned_u64(&stats_hw->n_packets)) { + put_32aligned_u64(&stats_hw->n_packets, bs_hw->packets); + put_32aligned_u64(&stats_hw->n_bytes, bs_hw->bytes); + } + + if (stats_dropped && stats_attrs[TCA_STATS_QUEUE]) { + qs = nl_attr_get_unspec(stats_attrs[TCA_STATS_QUEUE], sizeof *qs); + put_32aligned_u64(&stats_dropped->n_packets, qs->drops); + } + + return 0; +} + static int nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, bool terse) { struct nlattr *act_options; - struct nlattr *act_stats; struct nlattr *act_cookie; const char *act_kind; struct nlattr *action_attrs[ARRAY_SIZE(act_policy)]; - struct nlattr *stats_attrs[ARRAY_SIZE(stats_policy)]; - struct ovs_flow_stats *stats_sw = &flower->stats_sw; - struct ovs_flow_stats *stats_hw = &flower->stats_hw; - const struct gnet_stats_basic *bs_all = NULL; - const struct gnet_stats_basic *bs_hw = NULL; - struct gnet_stats_basic bs_sw = { .packets = 0, .bytes = 0, }; int err = 0; if (!nl_parse_nested(action, act_policy, action_attrs, @@ -1825,37 +1883,25 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, flower->act_cookie.len = nl_attr_get_size(act_cookie); } - act_stats = action_attrs[TCA_ACT_STATS]; - - if (!nl_parse_nested(act_stats, stats_policy, stats_attrs, - ARRAY_SIZE(stats_policy))) { - VLOG_ERR_RL(&error_rl, "failed to parse action stats policy"); - return EPROTO; - } - - bs_all = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof *bs_all); - if (stats_attrs[TCA_STATS_BASIC_HW]) { - bs_hw = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC_HW], - sizeof *bs_hw); - - bs_sw.packets = bs_all->packets - bs_hw->packets; - bs_sw.bytes = bs_all->bytes - bs_hw->bytes; - } else { - bs_sw.packets = bs_all->packets; - bs_sw.bytes = bs_all->bytes; - } + return nl_parse_action_stats(action_attrs[TCA_ACT_STATS], + &flower->stats_sw, &flower->stats_hw, NULL); +} - if (bs_sw.packets > get_32aligned_u64(&stats_sw->n_packets)) { - put_32aligned_u64(&stats_sw->n_packets, bs_sw.packets); - put_32aligned_u64(&stats_sw->n_bytes, bs_sw.bytes); - } +int +tc_parse_action_stats(struct nlattr *action, struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped) +{ + struct nlattr *action_attrs[ARRAY_SIZE(act_policy)]; - if (bs_hw && bs_hw->packets > get_32aligned_u64(&stats_hw->n_packets)) { - put_32aligned_u64(&stats_hw->n_packets, bs_hw->packets); - put_32aligned_u64(&stats_hw->n_bytes, bs_hw->bytes); + if (!nl_parse_nested(action, act_policy, action_attrs, + ARRAY_SIZE(act_policy))) { + VLOG_ERR_RL(&error_rl, "failed to parse single action options"); + return EPROTO; } - return 0; + return nl_parse_action_stats(action_attrs[TCA_ACT_STATS], stats_sw, + stats_hw, stats_dropped); } #define TCA_ACT_MIN_PRIO 1 diff --git a/lib/tc.h b/lib/tc.h index 751bec891..30cd2f7ff 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -23,6 +23,7 @@ #include #include +#include "netlink.h" #include "netlink-socket.h" #include "odp-netlink.h" #include "openvswitch/ofpbuf.h" @@ -80,6 +81,8 @@ tc_get_minor(unsigned int handle) struct tcmsg *tc_make_request(int ifindex, int type, unsigned int flags, struct ofpbuf *); +struct tcamsg *tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request); int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp); int tc_add_del_qdisc(int ifindex, bool add, uint32_t block_id, enum tc_qdisc_hook hook); @@ -375,5 +378,9 @@ int parse_netlink_to_tc_flower(struct ofpbuf *reply, bool terse); int parse_netlink_to_tc_chain(struct ofpbuf *reply, uint32_t *chain); void tc_set_policy(const char *policy); +int tc_parse_action_stats(struct nlattr *action, + struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped); #endif /* tc.h */ From patchwork Fri May 27 09:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=RAosFR/2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0s0hPVz9sG0 for ; Fri, 27 May 2022 19:01:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1B15F849C2; Fri, 27 May 2022 09:00:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sHrNpE5XUXdN; Fri, 27 May 2022 09:00:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 7981E84AB9; Fri, 27 May 2022 09:00:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1B84FC0086; Fri, 27 May 2022 09:00:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 02431C002D for ; Fri, 27 May 2022 09:00:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id F35FE42860 for ; Fri, 27 May 2022 09:00:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A_-1hpHRV8oj for ; Fri, 27 May 2022 09:00:43 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20618.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::618]) by smtp4.osuosl.org (Postfix) with ESMTPS id 7CDCF42883 for ; Fri, 27 May 2022 09:00:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SeF+nSlX6dkcC30g1h1q+WTHTK2d6pavlRGhUrM8oLtbl7BsbVD7U5NVu2POc/EqZZMviSFoOgSjEph+X9QpmcRNa8dwmL4TksPWUYAluGcD+oeO98MCpnxyaM/ba2MXr9RjX0sjBHAnCozSlas01G0E/qDf8wzJCtxo3EU3tNs1W253SkZAYBPEnCdpbHSLlalZcWhkKpPS/gXDnFRl8I/G78FXGWo6HZnBX+jYsmUIfU6q6xC5QuoZi3okXPWZYtyrYrtU4mhRV7fe4D7cfcBV+qr4rapeJjVXL4O2Cu2ZmaDM62d9idORtlfmuDilB2oaRGQ/33uq+oqR3NNlCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ONbWcAPScU/LDRWdfaSrdvJq9ofV8uStv1PUQHSyC/E=; b=kaVsztJwhbNU3aFhSsbuxtN7xc7q4asP2m4/07PDHavrZkZ7pkZgEo3rRu7EyaYLdVL0WqAfwb8OEeQxYM0VDP+YYDZy2CgU9iaBQX44NbyNYpObhDurlUPtkshHtf27zpUI/a0UpKbXprrkDvjz4bfbi+vEudqvPMnbf/C8ue/9mHvWHYJTmxWfzCc4G2wki7gt/4gqmzDYJmMUigPqdULPv19ytEsMWWvPQjQF8h41i03HjzxMEhP1GiHK4Mj1zh3oLPwT61b+7XeHXWHpzpdQhdLQv4bPlicxZlO1y1s75l9MzsaJsZjy38T44aNvSL4KY9GUAzSTvrB8V9hciw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ONbWcAPScU/LDRWdfaSrdvJq9ofV8uStv1PUQHSyC/E=; b=RAosFR/2CmFM4aBQ/fRi1cMnZljh+kd9ad++0IcoxXJ7zmHXGHzkqIUT4C6ztR+lI0Mri9LXa2aSTJa2wJxsLmJKkXKlm/2bVqZiO7tTdB83cGk9dCyjG2b7SQtOuNfk+VAY6cPpmRYnKJzQZQ6cZcJ1/o09N1bxnXE/Puyra/9H4guGjWlWdZ+gmN0O3T5GJgwCNrmgqwXZGoPl2moXCYLopX5ZO0RQG12sK4hK8xg2On0ixppIPUWunYIbLNLwXyrPXV6YvMdW7JKYf0i8hkd97jI00t8wSbzRK2IberZSZsQLa3EOi7QCvrFmYt9fB/8EUkNI3D05fYPZlJ2mUA== Received: from BN0PR02CA0036.namprd02.prod.outlook.com (2603:10b6:408:e5::11) by DM6PR12MB3132.namprd12.prod.outlook.com (2603:10b6:5:3c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:41 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e5:cafe::ab) by BN0PR02CA0036.outlook.office365.com (2603:10b6:408:e5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:40 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:40 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:39 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:37 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:18 +0000 Message-ID: <20220527090021.22594-6-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e72fc4b4-ca22-480a-367e-08da3fbf6005 X-MS-TrafficTypeDiagnostic: DM6PR12MB3132:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wX9bj1rtD8o/M0/MjFRGGuBPBbVrJgLqzj8JXSFKMpEcmhGoUYOy4XRsavRprhtB6ynxDRUBzJvf5+s9SuM6PQtkAyEPXcipWKlWlJoNWzw5Y2GB7nUp3sxK07s2i9DL8N9t0vtW5yguNPajRC6NN3X+HdmZthfjdfEu8jmdTcllm25bxP0SSTWgJlOspRBQuQkm8VbTCEE/87mZL+GtEYTN/E+Q1NGfb9Dtsr3berk1Z4EIRKlhfrjGpGbThUKBTflUrMgWXhjx3puahG/xgZkvmiwInN3p8GJVMLcgJKlCJVXSduBsU0x+/7jvBOjjDJ6jkZ+qt54evFSI2fX2DfBrJKDMFAm/3wrrJIxCsaMJ9LFDd4yzXWFtEMiTYw0uJx9znJk7fyfIgAFaLlt6dq4taDmMAB2MvFylkOahFu+CTC9y/SAFE3ti/wel4676cNQy9zyiTtLzlU5XAFSCpBzBaO5dpnRZ+2cgSN7Fn9LoQNOXykaoqV/6ipqiIJyKh6ljsnrHfqsxAc3e333h1S4eqEjqznp7elnXhBhi5jVilIMXmzkl02zszuYBalUP5gL6DVP1jCrA+5WfI5jJ5NxolWsroVoLbAz4P270Gsc9UxnYwZVpiqX7iKpryr4Gb9r8xeKAnB3UxKJI7odYNjxPD7lkJnX8xmXP/rWWufrmGp6XU5/FFImVZyjt8o8Ceqki4eJZfZJzbr0ItwI+mQ== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(5660300002)(2906002)(426003)(186003)(2616005)(40460700003)(107886003)(1076003)(81166007)(83380400001)(82310400005)(4326008)(8676002)(356005)(86362001)(70586007)(7696005)(70206006)(36756003)(508600001)(110136005)(336012)(47076005)(26005)(316002)(8936002)(36860700001)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:40.6729 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e72fc4b4-ca22-480a-367e-08da3fbf6005 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3132 Cc: Jianbo Liu Subject: [ovs-dev] [v5 5/8] netdev-offload-tc: Implement meter offload API for tc X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" For dpif-netlink, meters are mapped by tc to police actions with one-to-one relationship. Implement meter offload API to set/get/del the police action, and a hmap is used to save the mappings. An id-pool is used to manage all the available police indexes, which are 0x10000000-0x1fffffff, reserved only for OVS. Signed-off-by: Jianbo Liu --- lib/netdev-offload-tc.c | 203 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 83d57c63b..c88fb6a37 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -21,6 +21,7 @@ #include "dpif.h" #include "hash.h" +#include "id-pool.h" #include "openvswitch/hmap.h" #include "openvswitch/match.h" #include "openvswitch/ofpbuf.h" @@ -62,6 +63,22 @@ struct chain_node { uint32_t chain; }; +struct meter_police_mapping_data { + struct hmap_node meter_id_node; + uint32_t meter_id; + uint32_t police_idx; +}; + +#define METER_POLICE_IDS_BASE 0x10000000 +#define METER_POLICE_IDS_MAX 0x1FFFFFFF +/* Protects below meter police ids pool. */ +static struct ovs_mutex meter_police_ids_mutex = OVS_MUTEX_INITIALIZER; +static struct id_pool *meter_police_ids OVS_GUARDED_BY(meter_police_ids_mutex); +/* Protects below meter hashmaps. */ +static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; +static struct hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) + = HMAP_INITIALIZER(&meter_id_to_police_idx); + static bool is_internal_port(const char *type) { @@ -2286,6 +2303,12 @@ netdev_tc_init_flow_api(struct netdev *netdev) probe_multi_mask_per_prio(ifindex); probe_ct_state_support(ifindex); + + ovs_mutex_lock(&meter_police_ids_mutex); + meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + ovs_mutex_unlock(&meter_police_ids_mutex); + ovsthread_once_done(&once); } @@ -2302,6 +2325,183 @@ netdev_tc_init_flow_api(struct netdev *netdev) return 0; } +static struct meter_police_mapping_data * +meter_id_find_locked(uint32_t meter_id) + OVS_REQUIRES(meter_mutex) +{ + struct meter_police_mapping_data *data; + size_t hash = hash_int(meter_id, 0); + + HMAP_FOR_EACH_WITH_HASH (data, meter_id_node, hash, + &meter_id_to_police_idx) { + if (data->meter_id == meter_id) { + return data; + } + } + + return NULL; +} + +static int +meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + *police_idx = data->police_idx; + } + ovs_mutex_unlock(&meter_mutex); + + return data ? 0 : ENOENT; +} + +static void +meter_id_insert(uint32_t meter_id, uint32_t police_idx) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = xzalloc(sizeof *data); + data->meter_id = meter_id; + data->police_idx = police_idx; + hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, + hash_int(meter_id, 0)); + ovs_mutex_unlock(&meter_mutex); +} + +static void +meter_id_remove(uint32_t meter_id) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + free(data); + } + ovs_mutex_unlock(&meter_mutex); +} + +static bool +meter_alloc_police_index(uint32_t *police_index) +{ + bool ret; + + ovs_mutex_lock(&meter_police_ids_mutex); + ret = id_pool_alloc_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_police_ids_mutex); + + return ret; +} + +static void +meter_free_police_index(uint32_t police_index) +{ + ovs_mutex_lock(&meter_police_ids_mutex); + id_pool_free_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_police_ids_mutex); +} + +static int +meter_tc_set_policer(ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + uint32_t police_index; + uint32_t rate, burst; + bool add_policer; + int err; + + ovs_assert(config->bands != NULL); + + rate = config->bands[0].rate; + if (config->flags & OFPMF13_BURST) { + burst = config->bands[0].burst_size; + } else { + burst = config->bands[0].rate; + } + + add_policer = (meter_id_lookup(meter_id.uint32, &police_index) == ENOENT); + if (add_policer) { + if (!meter_alloc_police_index(&police_index)) { + VLOG_WARN_RL(&error_rl, "No free police index for meter id %u", + meter_id.uint32); + return ENOENT; + } + } + + err = tc_add_policer_action(police_index, + (config->flags & OFPMF13_KBPS) ? rate : 0, + (config->flags & OFPMF13_KBPS) ? burst : 0, + (config->flags & OFPMF13_PKTPS) ? rate : 0, + (config->flags & OFPMF13_PKTPS) ? burst : 0, + !add_policer); + if (err) { + VLOG_WARN_RL(&error_rl, + "Failed to %s police %u for meter id %u: %s", + add_policer ? "add" : "modify", + police_index, meter_id.uint32, ovs_strerror(err)); + goto err_add_policer; + } + + if (add_policer) { + meter_id_insert(meter_id.uint32, police_index); + } + + return 0; + +err_add_policer: + if (add_policer) { + meter_free_police_index(police_index); + } + return err; +} + +static int +meter_tc_get_policer(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands OVS_UNUSED) +{ + uint32_t police_index; + int err = ENOENT; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_get_policer_action(police_index, stats); + if (err) { + VLOG_WARN_RL(&error_rl, + "Failed to get police %u stats for meter %u: %s", + police_index, meter_id.uint32, ovs_strerror(err)); + } + } + + return err; +} + +static int +meter_tc_del_policer(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands OVS_UNUSED) +{ + uint32_t police_index; + int err = ENOENT; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_del_policer_action(police_index, stats); + if (err && err != ENOENT) { + VLOG_WARN_RL(&error_rl, + "Failed to del police %u for meter %u: %s", + police_index, meter_id.uint32, ovs_strerror(err)); + } else { + meter_free_police_index(police_index); + } + meter_id_remove(meter_id.uint32); + } + + return err; +} + const struct netdev_flow_api netdev_offload_tc = { .type = "linux_tc", .flow_flush = netdev_tc_flow_flush, @@ -2312,5 +2512,8 @@ const struct netdev_flow_api netdev_offload_tc = { .flow_get = netdev_tc_flow_get, .flow_del = netdev_tc_flow_del, .flow_get_n_flows = netdev_tc_get_n_flows, + .meter_set = meter_tc_set_policer, + .meter_get = meter_tc_get_policer, + .meter_del = meter_tc_del_policer, .init_flow_api = netdev_tc_init_flow_api, }; From patchwork Fri May 27 09:00:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=NMqME2NF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f0y54Ksz9sG0 for ; Fri, 27 May 2022 19:01:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 219C94286E; Fri, 27 May 2022 09:01:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VbO3XGoceebL; Fri, 27 May 2022 09:01:02 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id A96784285A; Fri, 27 May 2022 09:01:01 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8B648C0032; Fri, 27 May 2022 09:01:01 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 15ABCC007E for ; Fri, 27 May 2022 09:01:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 08D9741347 for ; Fri, 27 May 2022 09:00:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DVWlo8OOkvqy for ; Fri, 27 May 2022 09:00:47 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20613.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::613]) by smtp2.osuosl.org (Postfix) with ESMTPS id 678B341312 for ; Fri, 27 May 2022 09:00:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=djzemosRNZabFcf1ARYaOIZ6cLUjCt3/Rapr+tDGY1C+LkE5LE8l2NomwyBLkueMdsALiv1BRM6NvCUybMCavt9k05iOzhc1CNbiOLW2wM0zm39ygENI4DH2mLB6uX+HfLOjHXxC93QJ67gr0L0w5xCETn9g8ecLwQpPqxVzYe5XRuha9ldXxCtHnlqsBSHbVUzfbhKp2/g3THZ47cSiO/EoLad11f9q9YYrztUSAkW5/kyB1voRIhyugBwzWksm8v/YGbcV/RrHxwDxoaFSD21hI+AGkSDhychag1BwAjLYpA2nNMkSEKHif0mPbOZY4ITu+h4FnWqeBNNHoIictA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uIEK+dBjOWUdE+1z8jKLc8/Hx8ORWK+pk8zkc1xk9dc=; b=HgWBVismW9ixR5C6iyC7Sgc6x8ASAHYx0L2xcb8p/Rd7Xt8m/B/Bz5r93sBMrvIynfxnLuxHReW0mV4GfEwt2LbyFArkE2FlnGHtLkW0UESK0hpsnK0GqV80l+2VJLXGMpH3eVWS5DUnkzfSIamy6Ct03ZV+ldkfzf4MQKeqI7OkO9Vs9tmkSE8DTVVj1BFd2ycP1I3109P4wx2LMJShnHWXGxOMyM5yIVxEUugaYxE1ZVpQa4r9DJ/Cwy0ZgDJxxDz80wLP86IyY+2QlYrq6QDmanr+h4gRjHMHFfvqEBuQ8APqjVpP72n4dmiLBnMhKf1DwLs23xnresekQWWPGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uIEK+dBjOWUdE+1z8jKLc8/Hx8ORWK+pk8zkc1xk9dc=; b=NMqME2NFNnKant3Knhn1mQSOFFNPuyEIM2LxT2ZYnrnvd95Bc2mWIrv3kuHsX6eiYlFNsUCXM3+vTHbaxcZFiErjFtcDgUqDabjNtrgwfGfTCSNNUjSn0QjinJW91mB2qj52lFaL7XEW+D+u8hRZGWeJgbP5EEmM3LPzG7caRb7nyRC6qu2YtJgOGlLsLXXzcVYicUnc1guFivHwhAcAlCSoWf/M68yrCAyKsiO4k1l2etltpZLWSs7WQQ6UR09BcNKAUwyB3wpgaJALcxQ8bxlcDsI+qZcma/iDsJD853li58QJEJaADHPrprBSL3DuRbaX7X69qOeFEzb/yEYMLQ== Received: from BN8PR15CA0040.namprd15.prod.outlook.com (2603:10b6:408:80::17) by BYAPR12MB3430.namprd12.prod.outlook.com (2603:10b6:a03:ad::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:44 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:80:cafe::bd) by BN8PR15CA0040.outlook.office365.com (2603:10b6:408:80::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:43 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:42 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:41 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:40 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:19 +0000 Message-ID: <20220527090021.22594-7-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fdb79bb-e417-4219-e129-08da3fbf61f2 X-MS-TrafficTypeDiagnostic: BYAPR12MB3430:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ft+MFzDz02RRtvl6l8Cqj4yo8ZUECz58KRrUOwn+x7ZHW01PGs7IO1RpgNbQ6Sez7gmLp/MQsIt/QtpV5J4tdjaAk6H4CBBsY0pqZFs1vKniA/eMX97vC/iBfWSKnXsfuCjyVwLb7/5nCeBHlrqoerE0GwyRlbKwEFFRgfGIpY7U2kZFF5xFyrV1D5EyK4C1l3ah/1P5LH379w9JZOpKl5El/ncjPaSle/bgxo1L2cc0LbbiD3YuuO81ad2Qu7I0dg3IVnIWM2OTlcItJDxOjgQIwcooxGHXRQM4eTIQKFQsdpOXy08dIckQFSwMhw7INGQ8/y6dnkLsZvK0FOWspOkOFg4NgKAzITy5Y04jnCNumSNf+BMEdzz5n/8BkxTLz5KfBrKqdLNUnThSJGBcEFl9F1n2/ZhLRFUawlQrdc0OVJCFCHP6NFfMcp4i+pI2GWD34Qy+mWivvpMgH0vM9SKKVdt8oNVxcHlPw/9yvUy0Wdj1x4IsEz+0TAW9qvqK7LAUV5o9G+9jjLvKppey7tgCzcxYjKhaXLs24OK1bpnVrc4n+tyvRm6fAP85MFdv96s1bo8un32aIeSE2Jie9L00k+TnhhtsnTcn1z8lbvDFjoOKMyb4iwMDoEwi3hnnaAQjauRnVLJoQKGUuEyXR7wWIvVMQ9QcV48hf8PqFdSUbXMDFhnHyXPPdepZfLBmrbNhwbpW+lCJKp1AAU3huA== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(26005)(36860700001)(83380400001)(6666004)(2906002)(186003)(508600001)(7696005)(47076005)(40460700003)(8936002)(1076003)(2616005)(82310400005)(426003)(336012)(107886003)(86362001)(110136005)(81166007)(36756003)(356005)(316002)(4326008)(70206006)(8676002)(5660300002)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:43.8926 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fdb79bb-e417-4219-e129-08da3fbf61f2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3430 Cc: Jianbo Liu Subject: [ovs-dev] [v5 6/8] netdev-offload-tc: Cleanup police actions with reserved indexes on startup X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" As the police actions with indexes of 0x10000000-0x1fffffff are reserved for meter offload, to provide a clean environment for OVS, these reserved police actions should be deleted on startup. So dump all the police actions, delete those actions with indexes in this range. Signed-off-by: Jianbo Liu --- lib/netdev-offload-tc.c | 75 +++++++++++++++++++++++++++++++++++++++++ lib/tc.c | 60 +++++++++++++++++++++++++++++++++ lib/tc.h | 2 ++ 3 files changed, 137 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index c88fb6a37..7e5f04bdf 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -69,6 +69,11 @@ struct meter_police_mapping_data { uint32_t police_idx; }; +struct policer_node { + struct hmap_node node; + uint32_t police_idx; +}; + #define METER_POLICE_IDS_BASE 0x10000000 #define METER_POLICE_IDS_MAX 0x1FFFFFFF /* Protects below meter police ids pool. */ @@ -2254,6 +2259,74 @@ probe_tc_block_support(int ifindex) } } +static int +tc_get_policer_action_ids(struct hmap *map) +{ + uint32_t police_idx[TCA_ACT_MAX_PRIO] = {}; + struct policer_node *policer_node; + struct netdev_flow_dump *dump; + struct ofpbuf rbuffer, reply; + size_t hash; + int i, err; + + dump = xzalloc(sizeof *dump); + dump->nl_dump = xzalloc(sizeof *dump->nl_dump); + + ofpbuf_init(&rbuffer, NL_DUMP_BUFSIZE); + tc_dump_tc_action_start("police", dump->nl_dump); + + while (nl_dump_next(dump->nl_dump, &reply, &rbuffer)) { + if (parse_netlink_to_tc_policer(&reply, police_idx)) { + continue; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (!police_idx[i]) { + break; + } + policer_node = xzalloc(sizeof *policer_node); + policer_node->police_idx = police_idx[i]; + hash = hash_int(police_idx[i], 0); + hmap_insert(map, &policer_node->node, hash); + } + memset(police_idx, 0, TCA_ACT_MAX_PRIO * sizeof(uint32_t)); + } + + err = nl_dump_done(dump->nl_dump); + ofpbuf_uninit(&rbuffer); + free(dump->nl_dump); + free(dump); + + return err; +} + +static void +tc_cleanup_policer_actions(struct id_pool *police_ids, + uint32_t id_min, uint32_t id_max) +{ + struct policer_node *policer_node; + uint32_t police_idx; + struct hmap map; + int err; + + hmap_init(&map); + tc_get_policer_action_ids(&map); + + HMAP_FOR_EACH_POP (policer_node, node, &map) { + police_idx = policer_node->police_idx; + if (police_idx >= id_min && police_idx <= id_max) { + err = tc_del_policer_action(police_idx, NULL); + if (err && err != ENOENT) { + /* Don't use this police any more. */ + id_pool_add(police_ids, police_idx); + } + } + free(policer_node); + } + + hmap_destroy(&map); +} + static int netdev_tc_init_flow_api(struct netdev *netdev) { @@ -2307,6 +2380,8 @@ netdev_tc_init_flow_api(struct netdev *netdev) ovs_mutex_lock(&meter_police_ids_mutex); meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + tc_cleanup_policer_actions(meter_police_ids, METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX); ovs_mutex_unlock(&meter_police_ids_mutex); ovsthread_once_done(&once); diff --git a/lib/tc.c b/lib/tc.c index 77d0c9de7..ac53c56db 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2087,6 +2087,66 @@ tc_dump_tc_chain_start(struct tcf_id *id, struct nl_dump *dump) return 0; } +int +tc_dump_tc_action_start(char *name, struct nl_dump *dump) +{ + size_t offset, root_offset; + struct ofpbuf request; + + tc_make_action_request(RTM_GETACTION, NLM_F_DUMP, &request); + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, name); + nl_msg_end_nested(&request, offset); + nl_msg_end_nested(&request, root_offset); + + nl_dump_start(dump, NETLINK_ROUTE, &request); + ofpbuf_uninit(&request); + + return 0; +} + +int +parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]) +{ + static struct nl_policy actions_orders_policy[TCA_ACT_MAX_PRIO] = {}; + struct nlattr *actions_orders[ARRAY_SIZE(actions_orders_policy)]; + const int max_size = ARRAY_SIZE(actions_orders_policy); + const struct nlattr *actions; + struct tc_flower flower; + struct tcamsg *tca; + int i, cnt = 0; + int err; + + for (i = 0; i < max_size; i++) { + actions_orders_policy[i].type = NL_A_NESTED; + actions_orders_policy[i].optional = true; + } + + tca = ofpbuf_at_assert(reply, NLMSG_HDRLEN, sizeof *tca); + actions = nl_attr_find(reply, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!actions || !nl_parse_nested(actions, actions_orders_policy, + actions_orders, max_size)) { + VLOG_ERR_RL(&error_rl, "Failed to parse police actions"); + return EPROTO; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (actions_orders[i]) { + memset(&flower, 0, sizeof(struct tc_flower)); + err = nl_parse_single_action(actions_orders[i], &flower, false); + if (err) { + continue; + } + if (flower.actions[0].police.index) { + police_idx[cnt++] = flower.actions[0].police.index; + } + } + } + + return 0; +} + int tc_del_filter(struct tcf_id *id) { diff --git a/lib/tc.h b/lib/tc.h index 30cd2f7ff..4690dce4f 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -382,5 +382,7 @@ int tc_parse_action_stats(struct nlattr *action, struct ovs_flow_stats *stats_sw, struct ovs_flow_stats *stats_hw, struct ovs_flow_stats *stats_dropped); +int tc_dump_tc_action_start(char *name, struct nl_dump *dump); +int parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]); #endif /* tc.h */ From patchwork Fri May 27 09:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=kkW8oqSp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f3n09zFz9sG0 for ; Fri, 27 May 2022 19:03:32 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 3B4F54130E; Fri, 27 May 2022 09:03:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PZdnPBBq2uj9; Fri, 27 May 2022 09:03:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 5AC114049E; Fri, 27 May 2022 09:03:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C5BBDC0032; Fri, 27 May 2022 09:03:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4B086C002D for ; Fri, 27 May 2022 09:03:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 96F1B60774 for ; Fri, 27 May 2022 09:01:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EcjsuaMBOQDn for ; Fri, 27 May 2022 09:01:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20624.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::624]) by smtp3.osuosl.org (Postfix) with ESMTPS id A4D4E60F99 for ; Fri, 27 May 2022 09:01:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jlpiFYgaSKXU754Vgeggiikhkty0EUOKVMTEoYUM4OytZVlta2Rdh+WhK3Hp/vHZmjv+SUzB/+xHuhYYuOLAD6PJmkMkPoltx0sZZdQOpWg9SH/My3xckYW5Ez4ou030kQA8X5PzVLs5CNe1jk9GRFCB9sa0qQ9metTFGmyb7XcCqebvZwmalqCs9WwB+5XddGd7LosO4rwSGa0oNZi4T3ziZw6pLOepBoy+kd0ZaDBSL4yO9bMJenyCqF9x0gGyaNq1KnSypIgC6RKwUOWehBUqY/IrnH71lhOTxynmrpS22Znvn/7/N57ZCm4640vY4bpEE+RP+EdVjeU3q61JLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/ZD2YgHPxXK2PCPLtjH/QFDHGojCd3226Vrcc67yGxo=; b=V0UnM5m97lF8bwZkH7qtZk7MkC9rlEded5LoInmxmqR0jqlmGjnTOLLJE9UMcyaPkuEJXJ3Tm1ELUyQwcN8w+NOpCxJA8x4Mq8ztrKcpWbCFVWNwWYLabQItZjefbVFDGQb49miqlnE9kecveEwli8qHU9yklblU59g1s3OU46kyAJjEodbbAdTNq0o9wULKHKDRNDtWyfCu5mFjSfNISxHYCUD3axQovsklXon0NsWCEeIXExB8tIzwvRok4O6PJmRDpLs1jrz1Qa882K9wi8+CqJnRlXYvR203XfSrN72Gbp5q8QIhhCGQWqW5XzbWYo470IN8y8Uzi0C0lJ6JIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/ZD2YgHPxXK2PCPLtjH/QFDHGojCd3226Vrcc67yGxo=; b=kkW8oqSp5D+nYOyOEYHW7L9U6RW4ehjLMxc7vaSAg9iGPrWc2uwpj/q7+jvQGNP0KEtxoPeHRXItb9qkg/9OUBKOmAC/PSC6F7vKuwwc20STNnU126LAt9o7vX93VSDbbSfe6+FZJQYHdZIAhieEGXqXURU9Ev5fhEj3DOzLxo8UXjl8A5jfKo1T1SOjD6huVKookijjWggYJjBuMBsVvWTJrO4rJ8OpbUAipyom/pzTvCVJA3+urb+ow5NDBIVbMhCWEF9jkXK1VrUE86XYRmLM+7t8WBshXza+fYM2Mw4RCgefZ5O8hLMi3vqtflpVy6sOuQIWvK/8cdmZMPCjcg== Received: from BN6PR1701CA0023.namprd17.prod.outlook.com (2603:10b6:405:15::33) by SN6PR12MB4733.namprd12.prod.outlook.com (2603:10b6:805:ea::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.15; Fri, 27 May 2022 09:01:33 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:405:15:cafe::53) by BN6PR1701CA0023.outlook.office365.com (2603:10b6:405:15::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.15 via Frontend Transport; Fri, 27 May 2022 09:01:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:01:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:45 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:44 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:42 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:20 +0000 Message-ID: <20220527090021.22594-8-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bf954341-b4de-473f-6120-08da3fbf7f6f X-MS-TrafficTypeDiagnostic: SN6PR12MB4733:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: irI7a31F4PbgSJ3VsS2H9Ssex58TYw64UoFim5DjJGBz2RXqptS+/C4FdPaRrR0Z2ENOZIjDtix6zRCZaaLyyvQFvadxuk8kphfNnrCHcpoAT08UGYDzTyImpTzJXI1DHw2dOqRC8qQo5+VuNnr84pZimzb4hSB/5OT/QMkjFybE7AAGNuzBG+yAjmpGad4a31o4acFfEsnR36RtABHbNnuFBp2QRi9bpmbP6b1ocq1MkVTAajnalFchCb3IGZGKC1oDvYjC6cpZA0sDjNhOqgzaksyelRmNvFvpLCkRBNiZCHMfXKqRNDKRGe9rQfAFnyLhhwck3BnyOHrEp6VAmQLmQ7n5neejUL19K9S53iurLPTiF0wd2zIlbbL97wfIftqB4KUZHy/5z9kyY80YwPht/R0j5vrddLZa1FcxRv756hVx/3AcHo0Ig36OnLLeGsOA3hz8V07LUqye3LdLPUyXI5EbzUxBMdLVE3JJ4PiwPRNPgYTUMCHj28WmOqqaFDW4yY/fbXp0uYkazS7V5cxx9FapFYAaT3vGiUONlfT6mBMl01bHLDwyQDqcB3jG1VdgnlW7fdlRFDh1shAOhmfp3H18tiCAj01gI7z56KwubV+OR8dT51lCzcc10nM+j+b6OIzDbYINd+KtmFEY5zUp1n5KhoLpmePmhavfgZbnpT2MPnpmHLCAd7KXKCw+YrGsSwcq1NUVawsMJKsioA== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(107886003)(8936002)(316002)(40460700003)(36860700001)(70586007)(70206006)(8676002)(4326008)(36756003)(82310400005)(2906002)(86362001)(1076003)(110136005)(26005)(508600001)(81166007)(356005)(2616005)(83380400001)(6666004)(47076005)(7696005)(186003)(336012)(426003)(5660300002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:01:33.3937 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf954341-b4de-473f-6120-08da3fbf7f6f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4733 Cc: Jianbo Liu Subject: [ovs-dev] [v5 7/8] netdev-offload-tc: Offloading rules with police actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading rule, tc should be filled with police index, instead of meter id. As meter is mapped to police action, and the mapping is inserted into meter_id_to_police_idx hmap, this hmap is used to find the police index. Besides, the reverse mapping between meter id and police index is also added, so meter id can be retrieved from this hashmap and pass to dpif while dumping rules. Signed-off-by: Jianbo Liu --- lib/netdev-offload-tc.c | 45 ++++++++++++++++++++++++++++++++++++++++- lib/tc.c | 20 +++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 7e5f04bdf..43d13cc56 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -65,6 +65,7 @@ struct chain_node { struct meter_police_mapping_data { struct hmap_node meter_id_node; + struct hmap_node police_idx_node; uint32_t meter_id; uint32_t police_idx; }; @@ -83,6 +84,11 @@ static struct id_pool *meter_police_ids OVS_GUARDED_BY(meter_police_ids_mutex); static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; static struct hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) = HMAP_INITIALIZER(&meter_id_to_police_idx); +static struct hmap police_idx_to_meter_id OVS_GUARDED_BY(meter_mutex) + = HMAP_INITIALIZER(&police_idx_to_meter_id); + +static int meter_id_lookup(uint32_t meter_id, uint32_t *police_idx); +static int police_idx_lookup(uint32_t police_idx, uint32_t *meter_id); static bool is_internal_port(const char *type) @@ -1040,7 +1046,12 @@ parse_tc_flower_to_match(struct tc_flower *flower, } break; case TC_ACT_POLICE: { - /* Not supported yet */ + uint32_t meter_id; + + if (police_idx_lookup(action->police.index, &meter_id)) { + return ENOENT; + } + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id); } break; } @@ -1963,6 +1974,16 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_METER) { + uint32_t police_index, meter_id; + + meter_id = nl_attr_get_u32(nla); + if (meter_id_lookup(meter_id, &police_index)) { + return EOPNOTSUPP; + } + action->type = TC_ACT_POLICE; + action->police.index = police_index; + flower.action_count++; } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); @@ -2432,6 +2453,25 @@ meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) return data ? 0 : ENOENT; } +static int +police_idx_lookup(uint32_t police_idx, uint32_t *meter_id) +{ + struct meter_police_mapping_data *data = NULL; + size_t hash = hash_int(police_idx, 0); + + ovs_mutex_lock(&meter_mutex); + HMAP_FOR_EACH_WITH_HASH (data, police_idx_node, hash, + &police_idx_to_meter_id) { + if (data->police_idx == police_idx) { + *meter_id = data->meter_id; + break; + } + } + ovs_mutex_unlock(&meter_mutex); + + return data ? 0 : ENOENT; +} + static void meter_id_insert(uint32_t meter_id, uint32_t police_idx) { @@ -2443,6 +2483,8 @@ meter_id_insert(uint32_t meter_id, uint32_t police_idx) data->police_idx = police_idx; hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, hash_int(meter_id, 0)); + hmap_insert(&police_idx_to_meter_id, &data->police_idx_node, + hash_int(police_idx, 0)); ovs_mutex_unlock(&meter_mutex); } @@ -2455,6 +2497,7 @@ meter_id_remove(uint32_t meter_id) data = meter_id_find_locked(meter_id); if (data) { hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + hmap_remove(&police_idx_to_meter_id, &data->police_idx_node); free(data); } ovs_mutex_unlock(&meter_mutex); diff --git a/lib/tc.c b/lib/tc.c index ac53c56db..8db18fa2c 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2440,6 +2440,22 @@ nl_msg_put_act_gact(struct ofpbuf *request, uint32_t chain) nl_msg_end_nested(request, offset); } +static void +nl_msg_put_act_police_index(struct ofpbuf *request, uint32_t police_idx) +{ + struct tc_police police; + size_t offset; + + memset(&police, 0, sizeof police); + police.index = police_idx; + + nl_msg_put_string(request, TCA_ACT_KIND, "police"); + offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS); + nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); + nl_msg_put_u32(request, TCA_POLICE_RESULT, TC_ACT_PIPE); + nl_msg_end_nested(request, offset); +} + static void nl_msg_put_act_ct(struct ofpbuf *request, struct tc_action *action) { @@ -2930,7 +2946,9 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) } break; case TC_ACT_POLICE: { - /* Not supported yet */ + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_police_index(request, action->police.index); + nl_msg_end_nested(request, act_offset); } break; } From patchwork Fri May 27 09:00:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1636190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=JERq3OqN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L8f1C5gcbz9sG0 for ; Fri, 27 May 2022 19:01:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 36B114134E; Fri, 27 May 2022 09:01:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zdBGGBje4GvH; Fri, 27 May 2022 09:01:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4AAEE414E7; Fri, 27 May 2022 09:01:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 162FEC0032; Fri, 27 May 2022 09:01:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 40F8FC002D for ; Fri, 27 May 2022 09:01:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 8E7544288A for ; Fri, 27 May 2022 09:00:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BLUR7HOmGIX5 for ; Fri, 27 May 2022 09:00:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eab::61a]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5E8174285A for ; Fri, 27 May 2022 09:00:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kqWgoVC3tOuDV2F8VD/z9b+zpSrZeUmyceTJC2UqAKzvSYF4xQxMNfwz2vBiTmzCOqSFgnWkefOwQyHKUhjiN69iXZDCSuNREJ7ZQzLjNa722Vn4J6zGjiYqt9ZBU9MAKdj6hH7PydUEjTha6oWMlQ9WQFPnrIZD25Sl8Ms7JJhUbNTTwALohJT1vjiGhF8U+RZJs/EEQFnydvG9ZG5fPv+3Ze4qu/mHfCc0r65czbSPhJNBSepSRvC5spP44geWbjQfnaHJ36+yshPTPFFEgGx/ZkWUhWQBhgxg77zYTf6VDzGqYI1gDKk9F/dmDAPEmru7hAOyO1YuO/nE4au9fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ahd26i4EykYiJNNsj3BB2/HT4NeYG2EfV1moBUP4ZJM=; b=iqtneLjgbW9SvnDiL5DCjmkMspJtFnFpbnTGca1iElMhYPyGQNJeYgreDcMcNMkN9/HbQuKeCB5A3qhFrLupwVN+OdJw1qcaePvyGyp5KDPIqIaWkSsSTnHAQrPCxaKu+eFz7YrRqpzbSr3Twg+n5wR6gwGMTtP8VmLQBMoHNFkhwJ4CbjAj8D2qesOXqsRxUt36aw+ZpTd/NOBBGp9UaUNAAyzS2CbxtWLd1LBf/ayQvwHR3aEPlnIQcKJmhlbohRfMRGrKlnXLBucjslLp3R2idOgZm/Q5HH6DjhKQnvR8eMu37g+tL1sMp8tfdjEibVY7Bmu3EIrvLwyB65pNpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ahd26i4EykYiJNNsj3BB2/HT4NeYG2EfV1moBUP4ZJM=; b=JERq3OqNXoZGcLhdT4s6lwmW/rxCDCrr5Bgzf7OYIk+B2vB126CcqoVd4fKcZmsdXE+nnU1GtVQZpSQ1D13t+VBlj2NkWj62fyzoBJbs0o5B616QljB1gT1eCWVM5J4So4y2iQ/6WPHqo7/pHH8CYM1RGySJe2bugONu3fqxK3lmS8BVuk9Zb+mKAn6hMg16/LS/2kx/dVcQnLDZWsIHvo8gSbkEkVKkZ8c97Ftikw1PxjvAOViETzDTXbwXdEsap2RWodN24DLAzZLW37bI89Hu08nLMx/c55M7MF/DhBiUvnceDSGC4ifPXH1cKcFKII0k0aUAI0V1kIf4F76+sA== Received: from BN9PR03CA0526.namprd03.prod.outlook.com (2603:10b6:408:131::21) by DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 09:00:49 +0000 Received: from BN8NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:408:131:cafe::ca) by BN9PR03CA0526.outlook.office365.com (2603:10b6:408:131::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT064.mail.protection.outlook.com (10.13.176.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5293.13 via Frontend Transport; Fri, 27 May 2022 09:00:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 27 May 2022 09:00:47 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 27 May 2022 02:00:46 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Fri, 27 May 2022 02:00:45 -0700 To: , , , , , Date: Fri, 27 May 2022 09:00:21 +0000 Message-ID: <20220527090021.22594-9-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220527090021.22594-1-jianbol@nvidia.com> References: <20220527090021.22594-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 962e0164-8b01-4466-d0c8-08da3fbf649e X-MS-TrafficTypeDiagnostic: DM6PR12MB4153:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ta7XBzypYhRJkPPhjprsBtoKd3GOohvWepLzfGoCJgjOeBbQhkpqzc3zEKHwMNVS3qTy3FwCTmrZmUfaAagF4YKCGzL8gvnL3uyPJ6IhbqQzjdiUxDEXRgrEjW/hRxspy5X8UWavxc6UxGrpOL0JiwALZUmFyuAP+3ViXGc+ibxBVsYBq3b/jNy97sKGc6jzcijB/5h7QT6osW7aNrGFjbQCAxBAl/oG880Py+h4h1faYUt/9UKDiQvTUqB9SH6oqBCaPfbUsRg2p8mJpcPLnz3XMsIGSe1k4fH/oULjtSMyKIwOn71If0VzTELy7YnH/nBmQEVMK4EJff76eMvcDKg9fFBRSYfReTAlwZsD/BJXPxUm8yjP8WrB/pZTls/a/AJ5MVhzdDBe72KzK4PSwGOaqunpAz6cYHx6uNlRRUFAQv+VZG2CQMxJi707+M96MqqU0pvpwdCyBvvkVokPzv3WwY/minGMCXUI6YTswffjTcvhLX10P2lvtwXljT+MAYFvcHZsr4Tw53Noq6/f9yJYQlXLIhHraPCbWebt2Od8MSwn6SyO7fjA8axGVUSMPV3OS8JT1abW7aSLZviWfy4pCpJkrJfWa4zS0Cdk1POsm1M78Ko8sofdSP3Lm2QjJXPW3hZieOiNHM9k5j3fYd/EoCBTCC2OAiLagIx6UgKRyVEPNWQQBaH0wRdVTAC5vmsbUtthgIjQTxCymvVggQ== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(40460700003)(6666004)(36860700001)(86362001)(2616005)(2906002)(1076003)(186003)(8936002)(4326008)(81166007)(8676002)(70206006)(70586007)(356005)(316002)(110136005)(82310400005)(5660300002)(107886003)(26005)(83380400001)(7696005)(508600001)(426003)(336012)(47076005)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 09:00:48.4061 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 962e0164-8b01-4466-d0c8-08da3fbf649e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Cc: Jianbo Liu Subject: [ovs-dev] [v5 8/8] dpif-netlink: Offloading meter to tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" OVS meters are created in advance and openflow rules refer to them by their unique ID. New tc_police API is used to offload them. By calling the API, police actions are created and meters are mapped to them. These actions then can be used in tc filter rules by the index. Signed-off-by: Jianbo Liu --- NEWS | 2 ++ lib/dpif-netlink.c | 31 +++++++++++++++++---- tests/system-offloads-traffic.at | 48 ++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index eece0d0b2..dfd659d4e 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ Post-v2.17.0 - Windows: * Conntrack support for TCPv6, UDPv6, ICMPv6, FTPv6. * IPv6 Geneve tunnel support. + - Linux datapath: + * Add offloading meter tc police. v2.17.0 - 17 Feb 2022 diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 06e1e8ca0..0af9ee77e 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -4163,11 +4163,18 @@ static int dpif_netlink_meter_set(struct dpif *dpif_, ofproto_meter_id meter_id, struct ofputil_meter_config *config) { + int err; + if (probe_broken_meters(dpif_)) { return ENOMEM; } - return dpif_netlink_meter_set__(dpif_, meter_id, config); + err = dpif_netlink_meter_set__(dpif_, meter_id, config); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_set(meter_id, config); + } + + return err; } /* Retrieve statistics and/or delete meter 'meter_id'. Statistics are @@ -4258,16 +4265,30 @@ static int dpif_netlink_meter_get(const struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_GET); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, + OVS_METER_CMD_GET); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_get(meter_id, stats, max_bands); + } + + return err; } static int dpif_netlink_meter_del(struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_DEL); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, + max_bands, OVS_METER_CMD_DEL); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_del(meter_id, stats, max_bands); + } + + return err; } static bool diff --git a/tests/system-offloads-traffic.at b/tests/system-offloads-traffic.at index 80bc1dd5c..7ec75340f 100644 --- a/tests/system-offloads-traffic.at +++ b/tests/system-offloads-traffic.at @@ -168,3 +168,51 @@ matchall ]) OVS_TRAFFIC_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([offloads - check if meter offloading ]) +AT_KEYWORDS([meter]) +AT_SKIP_IF([test $SUPPORT_TC_INGRESS_PPS = "no"]) +OVS_TRAFFIC_VSWITCHD_START() + +AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:hw-offload=true]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=1 pktps bands=type=drop rate=1']) + +ADD_NAMESPACES(at_ns0, at_ns1) +ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24", "f0:00:00:01:01:01") +ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24", "f0:00:00:01:01:02") + +NS_CHECK_EXEC([at_ns0], [ip neigh add 10.1.1.2 lladdr f0:00:00:01:01:02 dev p0]) +NS_CHECK_EXEC([at_ns1], [ip neigh add 10.1.1.1 lladdr f0:00:00:01:01:01 dev p1]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "actions=normal"]) +NS_CHECK_EXEC([at_ns0], [ping -q -c 10 -i 0.1 -w 2 10.1.1.2 | FORMAT_PING], [0], [dnl +10 packets transmitted, 10 received, 0% packet loss, time 0ms +]) + +NETNS_DAEMONIZE([at_ns1], [nc -u -l 5678 > /dev/null ], [nc0.pid]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 del-flows br0]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=10,in_port=ovs-p0,udp actions=meter:1,normal"]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=1 actions=normal"]) + +NS_CHECK_EXEC([at_ns0], [sleep 0.5; echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:0, bytes:0, used:0.001s, actions:outputmeter(0),3 +]) + +for i in `seq 10`; do +NS_CHECK_EXEC([at_ns0], [echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +done + +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:10, bytes:330, used:0.001s, actions:outputmeter(0),3 +]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 meter-stats br0 | sed -e 's/duration:[[0-9]].[[0-9]]*s/duration:0.001s/'], [0], [dnl +OFPST_METER reply (OF1.3) (xid=0x2): +meter:1 flow_count:1 packet_in_count:11 byte_in_count:377 duration:0.001s bands: +0: packet_count:9 byte_count:0 +]) + +OVS_TRAFFIC_VSWITCHD_STOP +AT_CLEANUP