From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0703BA0C4B; Mon, 8 Nov 2021 10:58:44 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D052641100; Mon, 8 Nov 2021 10:58:39 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2087.outbound.protection.outlook.com [40.107.243.87]) by mails.dpdk.org (Postfix) with ESMTP id DA176410FE for ; Mon, 8 Nov 2021 10:58:38 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oWlAbhhjZCadrP2HYA6k7eH3aCFmsEdy/QqmJ5gt2f54GQUg7giP1DpzwFzrRLIrz2F7/ru/3GnZ/X7/IFSoN25yB9tjhuYDiNVgumMrR/izw9Gz0NWJATTkEn9CwLRkkBvuDkep7D65rgjQpo/gTiGf45qFt3zb6Ho0vp5FuHuLzR4m8+x5U+JFN2KqAjxAmXoc1laNpf51bxVnz3OWel5DJIPsHkIQQx3TBr6sLxZyIzpJ/3U4yPGspPJeWMf19OOpIyKvLD4bsZHadxBboh0Tp8lZ2YQ/iDjJdWjReBULfo4Uj3Ub5L6+a8ky3trIiKHia1zvdQY+g2uolbaDRA== 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=9dh6jQ3kc4C/Rs7L1J3k5siL5G6kkYzp0IrhBZeVjCA=; b=dTml1wSIqBUFDOZz7Q2OO3CLefiqAPvwzbzw0CUjFtFdj1IEKE7Ebl+z9U42WQjP+QDDmD3ZaDQsarK4dP9HPWafZVvz9zOgmgc+UDzWfuaZaulQLsNDd+bVAE9AmBmzmG49iTT8Q9n1MFgCYGfqn9FMOiySDwgYVRQR9vdVntwP7N3yXtiYDYIpSRVDhMqkHCEwfS4eQ0qODft93PLHH/2GqFZXA0vJLhP41S7UM1ee/KMrf2ZDXN2Ublg2DC4NAsQPhn34cXsYtZKtFNl+ciS7Cn2D7cusdtOscTc1730WpIqyZZ9+AF9RFaInFt0j16jvnq3DTXnoDP0HTKj5mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine 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=9dh6jQ3kc4C/Rs7L1J3k5siL5G6kkYzp0IrhBZeVjCA=; b=FxwNEu1SBBIVvb4BiOlEu+SkVrQ4XpSusDFGn6XRyeMmPbfQs/P645ywG6yNmvgRyF0wqU+oosI3NKDa90mLs20f5T5pYpmvlq0YSx5eRGE29nSilA7S+jE522onaSu+6+VZCFtjk3dmLf/b43S9Nu5NT1apmiV1+Y1zbr6xfBBPISo08084vo0BMn8ErX9q4kghhCvQUgVJd3jefWCJyuarG8maTwx1Ep68kZZLdFWcIwQNOv4A5Ov6ZMQXxbheZWrcDKQ0MmrAiLl8tvcAfhcf9oeX2re39lBNB1hw4PwZNk4Eukyu5ieN5lCe6+Tf37XL/3CTHhd/XTNt7PdgEA== Received: from DM6PR06CA0076.namprd06.prod.outlook.com (2603:10b6:5:336::9) by CY4PR12MB1720.namprd12.prod.outlook.com (2603:10b6:903:121::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Mon, 8 Nov 2021 09:58:36 +0000 Received: from DM6NAM11FT053.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::18) by DM6PR06CA0076.outlook.office365.com (2603:10b6:5:336::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Mon, 8 Nov 2021 09:58:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT053.mail.protection.outlook.com (10.13.173.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Mon, 8 Nov 2021 09:58:35 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 8 Nov 2021 09:58:33 +0000 From: Rongwei Liu To: , , , , Wisam Jaddo CC: , , Haifei Luo , Jiawei Wang Date: Mon, 8 Nov 2021 11:58:17 +0200 Message-ID: <20211108095819.1783710-2-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211108095819.1783710-1-rongweil@nvidia.com> References: <6177033.fEpqbVaury@thomas> <20211108095819.1783710-1-rongweil@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 435aee67-7177-47cc-a509-08d9a29e548e X-MS-TrafficTypeDiagnostic: CY4PR12MB1720: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:170; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m8E/0quuvJUA/HmUzaAUYOCMs6ZFJmMnyUibftnbRYsrI81W1SXEGiT5N5XDY3TKjEde/H9kZfJV2aJyDeS6a/JNqdsYmwacXvrRP2rh3ZU30ODEVtmraJlLUXclSD85bEw/7OCo5qBvfg8m9jSKEHaFAEDD94jJY5u2amsnsH9TUVFLecJNuIzbMH0L+wW0L6Mn2U4dlmE2iX99IjSNzMrFEvI4aPl+JpbRH3R+MvgWl4qsHaO+dUNKmZt70ddyL78q0NVpqf1/sqdvT8fJdMru7caR7x06bdr/u5TaFbll40KX7RlhFWDRSF8btHwAdOAj3i3Zr2J76KbYEZHhbbtgPA709nDwZliOaxGD2ou0ccvjIrAs8gzKfNqlzmPk+eNXbxZ1zEJSkgWFXnYfkGmrBHGvnDrczoeMZ55D3zVgn8l2bA3AHGESv+jxUAeGCtNPOSJftmnwzNDtJoem1yw8pGVOOy+j1eyVH+e5apcmNGyM7uKjyNrQHZjanTo6YidPSdkrM05xdXlu148+HyhU5mvFB/LvhYn2cwE3Wck2rusOrH7CA1r83iPjnOWM6IXNBKIo3mzpnV5oKmASrnrwuQCvlqdEW9KqiIZM7rrgoM0ELH3Nf8nT4N+ZCdgjl/n1CbPzeHpArNdMnfzcJn2uCKKcBncxGCnjM/E41QjTcsV94B04mg+LFdtGDf6i48sF4L6K/v9cNN1C6xZhzg== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(6636002)(30864003)(5660300002)(110136005)(1076003)(36756003)(36860700001)(107886003)(83380400001)(426003)(2906002)(2616005)(26005)(54906003)(356005)(7636003)(55016002)(47076005)(6286002)(86362001)(336012)(508600001)(6666004)(8936002)(4326008)(70586007)(186003)(316002)(8676002)(7696005)(16526019)(36906005)(70206006)(82310400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2021 09:58:35.5693 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 435aee67-7177-47cc-a509-08d9a29e548e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1720 Subject: [dpdk-dev] [PATCH v6 1/3] app/flow-perf: support meter policy API 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 Sender: "dev" Add option "policy-mtr" to indicate if meter creation will include policy or not. Meter creation will keep the same without it. With "policy-mtr", the policy is introduced. API create_meter_policy is to create a policy. API create_meter_rule will use it to create a meter. The value of it is used to specify meter policy green color actions. Signed-off-by: Haifei Luo Signed-off-by: Jiawei Wang Signed-off-by: Rongwei Liu Acked-by: Wisam Monther --- app/test-flow-perf/main.c | 806 +++++++++++++++++++-------------- doc/guides/tools/flow-perf.rst | 3 + 2 files changed, 466 insertions(+), 343 deletions(-) diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c index c1ad9bb0a3..a960e5b245 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -37,6 +37,7 @@ #include #include "config.h" +#include "actions_gen.h" #include "flow_gen.h" #define MAX_BATCHES_COUNT 100 @@ -49,10 +50,13 @@ static uint8_t flow_group; static uint64_t encap_data; static uint64_t decap_data; +static uint64_t all_actions[RTE_COLORS][MAX_ACTIONS_NUM]; +static char *actions_str[RTE_COLORS]; static uint64_t flow_items[MAX_ITEMS_NUM]; static uint64_t flow_actions[MAX_ACTIONS_NUM]; static uint64_t flow_attrs[MAX_ATTRS_NUM]; +static uint32_t policy_id[MAX_PORTS]; static uint8_t items_idx, actions_idx, attrs_idx; static uint64_t ports_mask; @@ -63,6 +67,7 @@ static bool delete_flag; static bool dump_socket_mem_flag; static bool enable_fwd; static bool unique_data; +static bool policy_mtr; static uint8_t rx_queues_count; static uint8_t tx_queues_count; @@ -124,6 +129,337 @@ static struct multi_cores_pool mc_pool = { .cores_count = 1, }; +static const struct option_dict { + const char *str; + const uint64_t mask; + uint64_t *map; + uint8_t *map_idx; + +} flow_options[] = { + { + .str = "ether", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "ipv4", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV4), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "ipv6", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV6), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "vlan", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VLAN), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "tcp", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TCP), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "udp", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_UDP), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "vxlan", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "vxlan-gpe", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN_GPE), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "gre", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GRE), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "geneve", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GENEVE), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "gtp", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GTP), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "meta", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_META), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "tag", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TAG), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "icmpv4", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "icmpv6", + .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP6), + .map = &flow_items[0], + .map_idx = &items_idx + }, + { + .str = "ingress", + .mask = INGRESS, + .map = &flow_attrs[0], + .map_idx = &attrs_idx + }, + { + .str = "egress", + .mask = EGRESS, + .map = &flow_attrs[0], + .map_idx = &attrs_idx + }, + { + .str = "transfer", + .mask = TRANSFER, + .map = &flow_attrs[0], + .map_idx = &attrs_idx + }, + { + .str = "port-id", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_PORT_ID), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "rss", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_RSS), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "queue", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_QUEUE), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "jump", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_JUMP), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "mark", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_MARK), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "count", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_COUNT), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-meta", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_META), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-tag", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_TAG), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "drop", + .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-src-mac", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_MAC_SRC + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-dst-mac", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_MAC_DST + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-src-ipv4", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-dst-ipv4", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV4_DST + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-src-ipv6", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-dst-ipv6", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV6_DST + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-src-tp", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_TP_SRC + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-dst-tp", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_TP_DST + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "inc-tcp-ack", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_INC_TCP_ACK + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "dec-tcp-ack", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "inc-tcp-seq", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "dec-tcp-seq", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-ttl", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_TTL + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "dec-ttl", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_DEC_TTL + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-ipv4-dscp", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "set-ipv6-dscp", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "flag", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_FLAG + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "meter", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_METER + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "vxlan-encap", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, + { + .str = "vxlan-decap", + .mask = FLOW_ACTION_MASK( + RTE_FLOW_ACTION_TYPE_VXLAN_DECAP + ), + .map = &flow_actions[0], + .map_idx = &actions_idx + }, +}; + static void usage(char *progname) { @@ -143,7 +479,8 @@ usage(char *progname) printf(" --portmask=N: hexadecimal bitmask of ports used\n"); printf(" --unique-data: flag to set using unique data for all" " actions that support data, such as header modify and encap actions\n"); - + printf(" --policy-mtr=\"g1,g2:y1:r1\": To create meter with specified " + "color actions\n"); printf("To set flow attributes:\n"); printf(" --ingress: set ingress attribute in flows\n"); printf(" --egress: set egress attribute in flows\n"); @@ -236,6 +573,44 @@ usage(char *progname) printf(" --vxlan-decap: add vxlan_decap action to flow actions\n"); } +static void +handle_meter_policy(char *prog, char *arg) +{ + char *token; + size_t i, j, k; + j = 0; + k = 0; + policy_mtr = true; + token = strsep(&arg, ":\0"); + while (token != NULL && j < RTE_COLORS) { + actions_str[j++] = token; + token = strsep(&arg, ":\0"); + } + j = 0; + token = strtok(actions_str[0], ",\0"); + while (token == NULL && j < RTE_COLORS - 1) + token = strtok(actions_str[++j], ",\0"); + while (j < RTE_COLORS && token != NULL) { + for (i = 0; i < RTE_DIM(flow_options); i++) { + if (!strcmp(token, flow_options[i].str)) { + all_actions[j][k++] = flow_options[i].mask; + break; + } + } + /* Reached last item with no match */ + if (i >= RTE_DIM(flow_options)) { + fprintf(stderr, "Invalid actions item: %s\n", token); + usage(prog); + rte_exit(EXIT_SUCCESS, "Invalid actions item\n"); + } + token = strtok(NULL, ",\0"); + while (!token && j < RTE_COLORS - 1) { + token = strtok(actions_str[++j], ",\0"); + k = 0; + } + } +} + static void args_parse(int argc, char **argv) { @@ -247,337 +622,6 @@ args_parse(int argc, char **argv) int opt_idx; size_t i; - static const struct option_dict { - const char *str; - const uint64_t mask; - uint64_t *map; - uint8_t *map_idx; - - } flow_options[] = { - { - .str = "ether", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ETH), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "ipv4", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV4), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "ipv6", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_IPV6), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "vlan", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VLAN), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "tcp", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TCP), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "udp", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_UDP), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "vxlan", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "vxlan-gpe", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_VXLAN_GPE), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "gre", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GRE), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "geneve", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GENEVE), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "gtp", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_GTP), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "meta", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_META), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "tag", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_TAG), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "icmpv4", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "icmpv6", - .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP6), - .map = &flow_items[0], - .map_idx = &items_idx - }, - { - .str = "ingress", - .mask = INGRESS, - .map = &flow_attrs[0], - .map_idx = &attrs_idx - }, - { - .str = "egress", - .mask = EGRESS, - .map = &flow_attrs[0], - .map_idx = &attrs_idx - }, - { - .str = "transfer", - .mask = TRANSFER, - .map = &flow_attrs[0], - .map_idx = &attrs_idx - }, - { - .str = "port-id", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_PORT_ID), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "rss", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_RSS), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "queue", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_QUEUE), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "jump", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_JUMP), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "mark", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_MARK), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "count", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_COUNT), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-meta", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_META), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-tag", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_TAG), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "drop", - .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-src-mac", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-dst-mac", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_MAC_DST - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-src-ipv4", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-dst-ipv4", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV4_DST - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-src-ipv6", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-dst-ipv6", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV6_DST - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-src-tp", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_TP_SRC - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-dst-tp", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_TP_DST - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "inc-tcp-ack", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_INC_TCP_ACK - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "dec-tcp-ack", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "inc-tcp-seq", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "dec-tcp-seq", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-ttl", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_TTL - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "dec-ttl", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_DEC_TTL - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-ipv4-dscp", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "set-ipv6-dscp", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "flag", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_FLAG - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "meter", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_METER - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "vxlan-encap", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - { - .str = "vxlan-decap", - .mask = FLOW_ACTION_MASK( - RTE_FLOW_ACTION_TYPE_VXLAN_DECAP - ), - .map = &flow_actions[0], - .map_idx = &actions_idx - }, - }; - static const struct option lgopts[] = { /* Control */ { "help", 0, 0, 0 }, @@ -653,6 +697,7 @@ args_parse(int argc, char **argv) { "raw-decap", 1, 0, 0 }, { "vxlan-encap", 0, 0, 0 }, { "vxlan-decap", 0, 0, 0 }, + { "policy-mtr", 1, 0, 0 }, }; RTE_ETH_FOREACH_DEV(i) @@ -869,6 +914,8 @@ args_parse(int argc, char **argv) RTE_MAX_LCORE); } } + if (strcmp(lgopts[opt_idx].name, "policy-mtr") == 0) + handle_meter_policy(argv[0], optarg); break; default: usage(argv[0]); @@ -979,12 +1026,68 @@ has_meter(void) return 0; } +static void +create_meter_policy(void) +{ + struct rte_mtr_error error; + int ret, port_id; + struct rte_mtr_meter_policy_params policy; + uint16_t nr_ports; + struct rte_flow_action actions[RTE_COLORS][MAX_ACTIONS_NUM]; + int i; + + memset(actions, 0, sizeof(actions)); + memset(&policy, 0, sizeof(policy)); + nr_ports = rte_eth_dev_count_avail(); + for (port_id = 0; port_id < nr_ports; port_id++) { + for (i = 0; i < RTE_COLORS; i++) + fill_actions(actions[i], all_actions[i], 0, 0, 0, + 0, 0, 0, unique_data, rx_queues_count, + dst_ports[port_id]); + policy.actions[RTE_COLOR_GREEN] = actions[RTE_COLOR_GREEN]; + policy.actions[RTE_COLOR_YELLOW] = actions[RTE_COLOR_YELLOW]; + policy.actions[RTE_COLOR_RED] = actions[RTE_COLOR_RED]; + policy_id[port_id] = port_id + 10; + ret = rte_mtr_meter_policy_add(port_id, policy_id[port_id], + &policy, &error); + if (ret) { + fprintf(stderr, "meter policy add failed port_id %d\n", + port_id); + policy_id[port_id] = UINT32_MAX; + } + memset(actions, 0, sizeof(actions)); + } +} + + +static void +destroy_meter_policy(void) +{ + struct rte_mtr_error error; + uint16_t nr_ports; + int port_id; + + nr_ports = rte_eth_dev_count_avail(); + for (port_id = 0; port_id < nr_ports; port_id++) { + /* If port outside portmask */ + if (!((ports_mask >> port_id) & 0x1)) + continue; + + if (rte_mtr_meter_policy_delete + (port_id, policy_id[port_id], &error)) { + fprintf(stderr, "Port %u del policy error(%d) message: %s\n", + port_id, error.type, + error.message ? error.message : "(no stated reason)"); + rte_exit(EXIT_FAILURE, "Error: Destroy meter policy Failed!\n"); + } + } +} + static void create_meter_rule(int port_id, uint32_t counter) { int ret; struct rte_mtr_params params; - uint32_t default_prof_id = 100; struct rte_mtr_error error; memset(¶ms, 0, sizeof(struct rte_mtr_params)); @@ -994,8 +1097,15 @@ create_meter_rule(int port_id, uint32_t counter) params.dscp_table = NULL; /*create meter*/ - params.meter_profile_id = default_prof_id; - ret = rte_mtr_create(port_id, counter, ¶ms, 1, &error); + params.meter_profile_id = DEFAULT_METER_PROF_ID; + + if (!policy_mtr) { + ret = rte_mtr_create(port_id, counter, ¶ms, 1, &error); + } else { + params.meter_policy_id = policy_id[port_id]; + ret = rte_mtr_create(port_id, counter, ¶ms, 0, &error); + } + if (ret != 0) { printf("Port %u create meter idx(%d) error(%d) message: %s\n", port_id, counter, error.type, @@ -1009,11 +1119,17 @@ destroy_meter_rule(int port_id, uint32_t counter) { struct rte_mtr_error error; + if (policy_mtr && policy_id[port_id] != UINT32_MAX) { + if (rte_mtr_meter_policy_delete(port_id, policy_id[port_id], + &error)) + fprintf(stderr, "error delete policy %d\n", counter+1); + policy_id[port_id] = UINT32_MAX; + } if (rte_mtr_destroy(port_id, counter, &error)) { - printf("Port %u destroy meter(%d) error(%d) message: %s\n", - port_id, counter, error.type, - error.message ? error.message : "(no stated reason)"); - rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n"); + fprintf(stderr, "Port %u destroy meter(%d) error(%d) message: %s\n", + port_id, counter, error.type, + error.message ? error.message : "(no stated reason)"); + rte_exit(EXIT_FAILURE, "Error in deleting meter rule"); } } @@ -1118,12 +1234,10 @@ create_meter_profile(void) /* If port outside portmask */ if (!((ports_mask >> port_id) & 0x1)) continue; - mp.alg = RTE_MTR_SRTCM_RFC2697; mp.srtcm_rfc2697.cir = METER_CIR; mp.srtcm_rfc2697.cbs = METER_CIR / 8; mp.srtcm_rfc2697.ebs = 0; - ret = rte_mtr_meter_profile_add (port_id, DEFAULT_METER_PROF_ID, &mp, &error); if (ret != 0) { @@ -1992,16 +2106,22 @@ main(int argc, char **argv) printf(":: Flows Count per port: %d\n\n", rules_count); - if (has_meter()) + if (has_meter()) { create_meter_profile(); + if (policy_mtr) + create_meter_policy(); + } rte_eal_mp_remote_launch(run_rte_flow_handler_cores, NULL, CALL_MAIN); if (enable_fwd) { init_lcore_info(); rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MAIN); } - if (has_meter() && delete_flag) + if (has_meter() && delete_flag) { destroy_meter_profile(); + if (policy_mtr) + destroy_meter_policy(); + } RTE_ETH_FOREACH_DEV(port) { rte_flow_flush(port, &error); diff --git a/doc/guides/tools/flow-perf.rst b/doc/guides/tools/flow-perf.rst index e608a44c24..a23b94bb55 100644 --- a/doc/guides/tools/flow-perf.rst +++ b/doc/guides/tools/flow-perf.rst @@ -383,3 +383,6 @@ Actions: * ``--meter`` Add meter action to all flows actions. Currently, 1 meter profile -> N meter rules -> N rte flows. + +* ``--policy-mtr=`` + Add policy-mtr to create meter with policy and specify policy actions. -- 2.27.0