From patchwork Wed Jun 1 03:44:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Kozyrev X-Patchwork-Id: 112176 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6BFE5A0552; Wed, 1 Jun 2022 05:45:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38EC442B92; Wed, 1 Jun 2022 05:44:56 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062.outbound.protection.outlook.com [40.107.223.62]) by mails.dpdk.org (Postfix) with ESMTP id 574FC42B92 for ; Wed, 1 Jun 2022 05:44:55 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxglfwYvtzJcvjSkyUndfuOlk73MMFtmjVzojVIr6avwbIZi3JS9/UjLtSz5zobpPwWoVB7gBILFt2L6b4k0mZERo4jiwlv3PKKZpD/RzqjPd1D15PIFMCvhbI1hJ/OzL8OksTcR/Zb9xSG6cM3WtH8xJX83Y38mRRD+TGDDj1SrduVvgnfc2ddWaqOgGgnGFFnp+XzycdSNniT81QA6JKy+1hxRZ/+TtcM5EhPGniw2UHUJPENtG+pzCLCOjMlAkEnFNwGfN98j/j5skCqz/N8WQsEgHWQ/LII614E3x4gtiGCvPOervsurL7fuxPiNPBxS50t7m+oy+R4WXK+7Qw== 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=/M4pif3XjpsmFoIdffCMnAA9AOVTQfbhoM+yQgr48X0=; b=loPIsmeSwC9Y5SNgbBWZ45RZVMKEhZHk/LJ0WWXJlGw8TZhQtcI3DS1GLqTVOU6U2uVrZRj/H6V3t4X1vWZnNfrD/1jzJdm4BjxQ+R3Gfj9f206BmuDoqY/O6NvJZ+DkkBBDCDqZUA1R4eRHS22ydlQuvnyOaPP0mShl4Ayj+CXWVNhonvaHBCPZTG1UUVe+0DSEiYkORDoSTbQPw4aHUWMBPvsx2NmSOY9M3iw2kIyNulEvg6AgRQQy1N4Z1JeeQkiteRPXWieDIjCYzOAkmRK1x7+/bYZtrFbyBanUn4UFWniYlYysogfSOZMsPDZlDDyBquTxD4P/bT+eZSCjQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=intel.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=/M4pif3XjpsmFoIdffCMnAA9AOVTQfbhoM+yQgr48X0=; b=D4WMfSn6QnQt8382Guq+7N1MafhiaSGiIsir4xpW1aFW9W+ssnZOt9Sgr4tBfAbF5WUUXyZa2DCAAboEFiu/Duo8531jijXkGUPq0WQY+92fUmbhoFAvD6JUV+rqatwVpBnaz/CtehRVzOLh4UXgd9/AzYnnbs9bbv1NTUda/QvQZkUhNXxmAZFUkY3428U9ekTv/utlPuKJEK8QF5Y1rO5rMN6Xo+8EU/nAZfJph/wDh5R/YfEmpXGAkOErLfg2CtL8D9SztSq/mviYXiBZY8/ggTrGbJXYm5BljyDTgY6MUxHIjTVSB/mYaTMnPFzEl7xUKxjDzrsOz5IUjZ1avA== Received: from DM5PR06CA0036.namprd06.prod.outlook.com (2603:10b6:3:5d::22) by CO6PR12MB5491.namprd12.prod.outlook.com (2603:10b6:303:13b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:44:53 +0000 Received: from DM6NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:3:5d:cafe::5a) by DM5PR06CA0036.outlook.office365.com (2603:10b6:3:5d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Wed, 1 Jun 2022 03:44:52 +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 DM6NAM11FT046.mail.protection.outlook.com (10.13.172.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:44:52 +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; Wed, 1 Jun 2022 03:44:52 +0000 Received: from pegasus01.mtr.labs.mlnx (10.126.231.35) 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; Tue, 31 May 2022 20:44:48 -0700 From: Alexander Kozyrev To: CC: , , , , , , , , , , , Subject: [PATCH v3 7/7] app/testpmd: add meter color mark flow action Date: Wed, 1 Jun 2022 06:44:08 +0300 Message-ID: <20220601034408.2579943-8-akozyrev@nvidia.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20220601034408.2579943-1-akozyrev@nvidia.com> References: <20220522105102.1692526-1-akozyrev@nvidia.com> <20220601034408.2579943-1-akozyrev@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16a027f8-6bff-4d30-bf9a-08da4381163a X-MS-TrafficTypeDiagnostic: CO6PR12MB5491:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr 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: Ub1BpoQnsgh9rs6KVUy78baVal0FmFlB//+lHAqPTa8ODwYL3Uwj9zWr6aKdwn0WpXRGFQuCqesIq/gPey9NLdUoIWu9Ro/8OjM4NMmhsKWoImBizfDnBdQBbEVspQRy+j2eMg7C02fpaW/4Rz8DN6IBqxyNxKZDN+HgJY9VJLorZ9wsUoDdsQ0X/nsnubumwaOzPHN5w6KYrJwGMlqML7O43IYej06u8JJcWsozfi1WThMa61sjBKITzNhiVYfLOxpWaUextAc2Alf6IIEo5vl6xCdefamWEsilw2gDND3g91QF38DyrbQntI8y1bj9scH3F2cnphyBPm56cy2LB5pk0kcVRniMR6QIoLamnGQmJQPQ/HZRZjBzW0ek25RvAQbpFGT5+d1qN/xynsWnJd3Aa5DY/2SG8lD2MoHe0GyuKGiUQlhZFE6En+hgvLAQtRmAZ/qeNakzfp2QxaYD/24w6ppGWvzv6X/tD0u6lExjen18lTZhdfzo2/Mh/iFlBd5X5FAn4CW2Yu0O2TRwVCpfRZjIDnywKgMbKlAMEg6zM0xgnxwVc97RxrogfEv28V9PH7B28BVURBF0tDOBUBQZSrM1PkD/8uTwa/+44ixv/yMkFbRYyct5bpQxL9ag9nvwves/h3IHr5MadnEjsQyi/MZQMJaB+QMrk9ummp9M62VCb3xXJX5ACx5nJKMTqH6rmwn+WRscB9GXA8YC5A== 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)(40470700004)(46966006)(36840700001)(26005)(16526019)(186003)(2616005)(36860700001)(316002)(356005)(36756003)(70206006)(70586007)(4326008)(8676002)(81166007)(6916009)(8936002)(6666004)(5660300002)(7416002)(508600001)(2906002)(82310400005)(86362001)(83380400001)(426003)(40460700003)(336012)(1076003)(47076005)(54906003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:44:52.8043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16a027f8-6bff-4d30-bf9a-08da4381163a 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: DM6NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5491 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add testpmd command line to match for METER_MARK action: flow create ... actions meter_mark mtr_profile 20 / end Signed-off-by: Alexander Kozyrev Acked-by: Ori Kam --- app/test-pmd/cmdline_flow.c | 127 ++++++++++++++++++++ app/test-pmd/config.c | 26 ++++ app/test-pmd/testpmd.h | 4 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 5 + 4 files changed, 162 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 401922fc34..7261d6f52e 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -53,6 +53,7 @@ enum index { COMMON_GROUP_ID, COMMON_PRIORITY_LEVEL, COMMON_INDIRECT_ACTION_ID, + COMMON_PROFILE_ID, COMMON_POLICY_ID, COMMON_FLEX_HANDLE, COMMON_FLEX_TOKEN, @@ -508,6 +509,11 @@ enum index { ACTION_METER_COLOR_YELLOW, ACTION_METER_COLOR_RED, ACTION_METER_ID, + ACTION_METER_MARK, + ACTION_METER_PROFILE, + ACTION_METER_PROFILE_ID2PTR, + ACTION_METER_POLICY, + ACTION_METER_POLICY_ID2PTR, ACTION_OF_SET_MPLS_TTL, ACTION_OF_SET_MPLS_TTL_MPLS_TTL, ACTION_OF_DEC_MPLS_TTL, @@ -1835,6 +1841,7 @@ static const enum index next_action[] = { ACTION_PORT_ID, ACTION_METER, ACTION_METER_COLOR, + ACTION_METER_MARK, ACTION_OF_SET_MPLS_TTL, ACTION_OF_DEC_MPLS_TTL, ACTION_OF_SET_NW_TTL, @@ -1951,6 +1958,13 @@ static const enum index action_meter_color[] = { ZERO, }; +static const enum index action_meter_mark[] = { + ACTION_METER_PROFILE, + ACTION_METER_POLICY, + ACTION_NEXT, + ZERO, +}; + static const enum index action_of_set_mpls_ttl[] = { ACTION_OF_SET_MPLS_TTL_MPLS_TTL, ACTION_NEXT, @@ -2389,6 +2403,14 @@ static int parse_mp(struct context *, const struct token *, static int parse_meter_color(struct context *ctx, const struct token *token, const char *str, unsigned int len, void *buf, unsigned int size); +static int parse_meter_profile_id2ptr(struct context *ctx, + const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size); +static int parse_meter_policy_id2ptr(struct context *ctx, + const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size); static int comp_none(struct context *, const struct token *, unsigned int, char *, unsigned int); static int comp_boolean(struct context *, const struct token *, @@ -2550,6 +2572,13 @@ static const struct token token_list[] = { .call = parse_int, .comp = comp_none, }, + [COMMON_PROFILE_ID] = { + .name = "{profile_id}", + .type = "PROFILE_ID", + .help = "profile id", + .call = parse_int, + .comp = comp_none, + }, [COMMON_POLICY_ID] = { .name = "{policy_id}", .type = "POLICY_ID", @@ -5428,6 +5457,42 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)), .call = parse_vc_conf, }, + [ACTION_METER_MARK] = { + .name = "meter_mark", + .help = "meter the directed packets using profile and policy", + .priv = PRIV_ACTION(METER_MARK, + sizeof(struct rte_flow_action_meter_mark)), + .next = NEXT(action_meter_mark), + .call = parse_vc, + }, + [ACTION_METER_PROFILE] = { + .name = "mtr_profile", + .help = "meter profile id to use", + .next = NEXT(NEXT_ENTRY(ACTION_METER_PROFILE_ID2PTR)), + .args = ARGS(ARGS_ENTRY_ARB(0, sizeof(uint32_t))), + }, + [ACTION_METER_PROFILE_ID2PTR] = { + .name = "{mtr_profile_id}", + .type = "PROFILE_ID", + .help = "meter profile id", + .next = NEXT(action_meter_mark), + .call = parse_meter_profile_id2ptr, + .comp = comp_none, + }, + [ACTION_METER_POLICY] = { + .name = "mtr_policy", + .help = "meter policy id to use", + .next = NEXT(NEXT_ENTRY(ACTION_METER_POLICY_ID2PTR)), + ARGS(ARGS_ENTRY_ARB(0, sizeof(uint32_t))), + }, + [ACTION_METER_POLICY_ID2PTR] = { + .name = "{mtr_policy_id}", + .type = "POLICY_ID", + .help = "meter policy id", + .next = NEXT(action_meter_mark), + .call = parse_meter_policy_id2ptr, + .comp = comp_none, + }, [ACTION_OF_SET_MPLS_TTL] = { .name = "of_set_mpls_ttl", .help = "OpenFlow's OFPAT_SET_MPLS_TTL", @@ -9747,6 +9812,68 @@ parse_ia_id2ptr(struct context *ctx, const struct token *token, return ret; } +static int +parse_meter_profile_id2ptr(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct rte_flow_action *action = ctx->object; + struct rte_flow_action_meter_mark *meter; + struct rte_flow_meter_profile *profile = NULL; + uint32_t id; + int ret; + + (void)buf; + (void)size; + ctx->objdata = 0; + ctx->object = &id; + ctx->objmask = NULL; + ret = parse_int(ctx, token, str, len, ctx->object, sizeof(id)); + ctx->object = action; + if (ret != (int)len) + return ret; + /* set meter profile */ + if (action) { + meter = (struct rte_flow_action_meter_mark *) + (uintptr_t)(action->conf); + profile = port_meter_profile_get_by_id(ctx->port, id); + meter->profile = profile; + ret = (profile) ? ret : -1; + } + return ret; +} + +static int +parse_meter_policy_id2ptr(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct rte_flow_action *action = ctx->object; + struct rte_flow_action_meter_mark *meter; + struct rte_flow_meter_policy *policy = NULL; + uint32_t id; + int ret; + + (void)buf; + (void)size; + ctx->objdata = 0; + ctx->object = &id; + ctx->objmask = NULL; + ret = parse_int(ctx, token, str, len, ctx->object, sizeof(id)); + ctx->object = action; + if (ret != (int)len) + return ret; + /* set meter policy */ + if (action) { + meter = (struct rte_flow_action_meter_mark *) + (uintptr_t)(action->conf); + policy = port_meter_policy_get_by_id(ctx->port, id); + meter->policy = policy; + ret = (policy) ? ret : -1; + } + return ret; +} + /** Parse set command, initialize output buffer for subsequent tokens. */ static int parse_set_raw_encap_decap(struct context *ctx, const struct token *token, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 1b1e738f83..413dcb6e9d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -2184,6 +2184,32 @@ port_meter_policy_add(portid_t port_id, uint32_t policy_id, return ret; } +/** Get port meter profile */ +struct rte_flow_meter_profile * +port_meter_profile_get_by_id(portid_t port_id, uint32_t id) +{ + struct rte_mtr_error error; + struct rte_flow_meter_profile *profile; + + profile = rte_mtr_meter_profile_get(port_id, id, &error); + if (!profile) + print_mtr_err_msg(&error); + return profile; +} + +/** Get port meter policy */ +struct rte_flow_meter_policy * +port_meter_policy_get_by_id(portid_t port_id, uint32_t id) +{ + struct rte_mtr_error error; + struct rte_flow_meter_policy *policy; + + policy = rte_mtr_meter_policy_get(port_id, id, &error); + if (!policy) + print_mtr_err_msg(&error); + return policy; +} + /** Validate flow rule. */ int port_flow_validate(portid_t port_id, diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index f04a9a11b4..5fed46ae17 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -985,6 +985,10 @@ void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops); int port_flow_isolate(portid_t port_id, int set); int port_meter_policy_add(portid_t port_id, uint32_t policy_id, const struct rte_flow_action *actions); +struct rte_flow_meter_profile *port_meter_profile_get_by_id(portid_t port_id, + uint32_t id); +struct rte_flow_meter_policy *port_meter_policy_get_by_id(portid_t port_id, + uint32_t id); void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id); void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id); diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 5e2f5ffb40..fd5a05dbad 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -4453,6 +4453,11 @@ This section lists supported actions and their attributes, if any. - ``ethdev_port_id {unsigned}``: ethdev port ID +- ``meter_mark``: meter the directed packets using profile and policy + + - ``mtr_profile {unsigned}``: meter profile id to use + - ``mtr_policy {unsigned}``: meter policy id to use + Destroying flow rules ~~~~~~~~~~~~~~~~~~~~~