From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 18822A034C;
	Tue, 18 Jan 2022 16:33:59 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 09F134272D;
	Tue, 18 Jan 2022 16:33:59 +0100 (CET)
Received: from NAM12-MW2-obe.outbound.protection.outlook.com
 (mail-mw2nam12on2067.outbound.protection.outlook.com [40.107.244.67])
 by mails.dpdk.org (Postfix) with ESMTP id 19D094068E
 for <dev@dpdk.org>; Tue, 18 Jan 2022 16:33:57 +0100 (CET)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=LRaYdVGIWtVMV7z/fSZaig91afp/7cGjVHLvGv1tGmnRZU7xiqHeLARzCnJhaNNZGcOEIlEMl35CX91v16SC8Qsq6J/V+guZ7SETupVXZz4YES/kri4HxP0t66/fAAecrhhhzq4tmm5s8C+ICNduI5g1QxftUjfPPk+22rRI8DMywN6K3vic1pXjrlu+eX3z09aZDbxJFH0t/eQLQ/jNzKsC1YiLe8uZJXNSvpAaMP9wM7pl44Tsutwwc0wsJuKgsQeSvDnrZGuQJJCYnV92LiLr1+v9s+Fg54f7Q4d/WjYh16pfsC51H9CVBFAVc0sv/Cns+kkWMBhpF+ANkPrkGA==
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=zaP4Zu1mqFVes0mJrAy1+MkHqAdnTbTvzs20cmYsYBs=;
 b=XDvBebEvM1roNDtCiCqIM9cFBv1ftItYJRIdnkVPUf41Xbz756AU2OncveA85gqVJQHEpF10aINTqISQOsJPhrHdLwZu7NPYulwcMgvm3bFeKWt0eQgjdGt9khsD/P6zNs80b9GxLUCx9dhwU5/oQDGubnuOZf/po23Dx6SDqP0cqUTLqgiSAjttLkYyHN4Mu5kbF3mcqaQm2dDIpdCBnh/FfO1gTlFgsuqgvj4z+DVdIfn6nQqOLt3NQecvS6MdZyOwS97Z8rTCgayW2YHdiEcUKy/Y8O40agyE58XRmFdaLpqcrKXa23wKmzPOXDbTw83U7vqRJR4jS911Lp9QnQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 12.22.5.238) 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=zaP4Zu1mqFVes0mJrAy1+MkHqAdnTbTvzs20cmYsYBs=;
 b=F0JYug+IwyQywPdPruvTs0n1fwpvWS2sjn3BlwVB+MEjVEnNtzSzj2Mqu7933u/yB2HBAmUB9vE8rPEZlnvCKTe+AJByWMNSmryN5pKPeohYjleGJCP4923xsDYTDtZn3Iaoc/+lb6rtRc6qzbVl5C/f6sOUN7i/vw/0dIBYzWVPI0dlEuvIcoe5igJSQ4i/sJDqFV3vF+bfNzvInUBzcgzdYaD4FHi/pDTQVup39cPoj4TBFgK18FkgUidB64aS+TeE7vIIqn/NGvrqaCunOZUQ4YaJw6XiAYXdoC/YqiEkW5WFTgEKBvxXbhARW4x/GPfUi7dGCq6ACV4fwvXX8Q==
Received: from DM5PR12MB1628.namprd12.prod.outlook.com (2603:10b6:4:7::13) by
 CH2PR12MB4040.namprd12.prod.outlook.com (2603:10b6:610:ac::20) with
 Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.4909.7; Tue, 18 Jan 2022 15:33:54 +0000
Received: from BN9PR03CA0795.namprd03.prod.outlook.com (2603:10b6:408:13f::20)
 by DM5PR12MB1628.namprd12.prod.outlook.com (2603:10b6:4:7::13) with
 Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.4888.11; Tue, 18 Jan 2022 15:33:53 +0000
Received: from BN8NAM11FT048.eop-nam11.prod.protection.outlook.com
 (2603:10b6:408:13f:cafe::14) by BN9PR03CA0795.outlook.office365.com
 (2603:10b6:408:13f::20) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7 via Frontend
 Transport; Tue, 18 Jan 2022 15:33:53 +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;
Received: from mail.nvidia.com (12.22.5.238) by
 BN8NAM11FT048.mail.protection.outlook.com (10.13.177.117) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id
 15.20.4888.9 via Frontend Transport; Tue, 18 Jan 2022 15:33:53 +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.18;
 Tue, 18 Jan 2022 15:33:52 +0000
Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com
 (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.9; Tue, 18 Jan 2022
 07:33:49 -0800
From: Alexander Kozyrev <akozyrev@nvidia.com>
To: <dev@dpdk.org>
CC: <orika@nvidia.com>, <thomas@monjalon.net>, <ivan.malov@oktetlabs.ru>,
 <andrew.rybchenko@oktetlabs.ru>, <ferruh.yigit@intel.com>,
 <mohammad.abdul.awal@intel.com>, <qi.z.zhang@intel.com>,
 <jerinj@marvell.com>, <ajit.khaparde@broadcom.com>
Subject: [v2,05/10] app/testpmd: implement rte flow item/action template
Date: Tue, 18 Jan 2022 17:33:15 +0200
Message-ID: <20220118153315.3947641-1-akozyrev@nvidia.com>
X-Mailer: git-send-email 2.18.2
In-Reply-To: <20220118153027.3947448-1-akozyrev@nvidia.com>
References: <20220118153027.3947448-1-akozyrev@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [10.126.230.35]
X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To
 rnnvmail201.nvidia.com (10.129.68.8)
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: 074bca11-a019-481f-376a-08d9da97ef18
X-MS-TrafficTypeDiagnostic: DM5PR12MB1628:EE_|CH2PR12MB4040:EE_
X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr,ExtAddr
X-Microsoft-Antispam-PRVS: <DM5PR12MB162834BCE9F30D41CA91C87AAF589@DM5PR12MB1628.namprd12.prod.outlook.com>
X-MS-Oob-TLC-OOBClassifiers: OLM:6430;
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: cDM+WHQLP4cNom1Lt1iBUGCyIdqGJGLLMVtaeHEBxfJ4hCL2dfS6E+txiA0eFkosqprO/GPhZxTphCiw/45xDZxQn2O1KKNoO/Ts/z0FKb8mstfx0EYRrJ6anlKh6elCMLLLKBJIBTIGaXWO1AwTiwFyBK3UlUz6BaC9qp9J0nd8GWeKDKqYuAT3SAps+2oYitGgeaBBZSuYeXPDCVIhK/kz9pGgxbU0Jui8ZS9KEBYP4W7Ix2i2J8IDLF0xoTMiOT9w8vfcx2GJCjxr9WTaPgDvPWJsB6puOv9SCboLvLMt3R+HeONsY9XzmfcAeWwiJJDfsWirlfjkH5/qLf7fXQACfrFdfKsQx2IbTZ/b+nfDayhMVnVk28i72dzmusoa+5E80ZEduhjMm/0sZY6ZtC97FsQUDfmE1OAs8szyyW4KqKCv2NDFUErsMyrfI7sZW3T9zzjSFkqOPCglSvvCk8SOzWlh27hKnMTrM6YxoZRdliIRrBzbQwthudOGko/w6seXk85hutW+81kix3PwP7kGTjLE1JLOhanWsP9KIOsJB1mS303RjhZ/ZH5m46y2IZsJu/jCDgeOdv3mMNr+tztEUc5ifL+0ePEy6Gtftph0BsHfoVjYNirtE1/Ot7sFs42qZbOaiA2EGXXm89tfDwGwDU+qMqYdGvGpJJ7yMh+oxlypIg3En4rJDkjnWMUgEWLo9DCbvLPYQUP8zGiekf1E5nGOK2BemwF/pNvXylU/cwsr9JvQmaKVvAjMBn4vFU03tXxOfMmGmgSooICFQ6N6h3ad1A7gfgEgB1dek00=
X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:;
 IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE;
 SFS:(4636009)(46966006)(36840700001)(40470700002)(47076005)(54906003)(83380400001)(2906002)(6286002)(336012)(356005)(81166007)(7696005)(36860700001)(186003)(316002)(55016003)(30864003)(82310400004)(1076003)(6916009)(426003)(5660300002)(508600001)(36756003)(8676002)(8936002)(40460700001)(6666004)(26005)(16526019)(70586007)(70206006)(86362001)(4326008)(2616005)(36900700001);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: Nvidia.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 15:33:53.4331 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 074bca11-a019-481f-376a-08d9da97ef18
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-FromEntityHeader: HybridOnPrem
X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT048.eop-nam11.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4040
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add testpmd support for the rte_flow_item_template and
rte_flow_action_template APIs. Provide the command line interface
for the template creation/destruction. Usage example:
  testpmd> flow item_template 0 create item_template_id 2
           template eth dst is 00:16:3e:31:15:c3 / end
  testpmd> flow action_template 0 create action_template_id 4
           template drop / end mask drop / end
  testpmd> flow action_template 0 destroy action_template 4
  testpmd> flow item_template 0 destroy item_template 2

Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 376 +++++++++++++++++++-
 app/test-pmd/config.c                       | 204 +++++++++++
 app/test-pmd/testpmd.h                      |  22 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  97 +++++
 4 files changed, 697 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index ea4af8dd45..fb27a97855 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -56,6 +56,8 @@ enum index {
 	COMMON_POLICY_ID,
 	COMMON_FLEX_HANDLE,
 	COMMON_FLEX_TOKEN,
+	COMMON_ITEM_TEMPLATE_ID,
+	COMMON_ACTION_TEMPLATE_ID,
 
 	/* TOP-level command. */
 	ADD,
@@ -73,6 +75,8 @@ enum index {
 	FLOW,
 	/* Sub-level commands. */
 	CONFIGURE,
+	ITEM_TEMPLATE,
+	ACTION_TEMPLATE,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -91,6 +95,22 @@ enum index {
 	FLEX_ITEM_CREATE,
 	FLEX_ITEM_DESTROY,
 
+	/* Item template arguments. */
+	ITEM_TEMPLATE_CREATE,
+	ITEM_TEMPLATE_DESTROY,
+	ITEM_TEMPLATE_CREATE_ID,
+	ITEM_TEMPLATE_DESTROY_ID,
+	ITEM_TEMPLATE_RELAXED_MATCHING,
+	ITEM_TEMPLATE_SPEC,
+
+	/* Action template arguments. */
+	ACTION_TEMPLATE_CREATE,
+	ACTION_TEMPLATE_DESTROY,
+	ACTION_TEMPLATE_CREATE_ID,
+	ACTION_TEMPLATE_DESTROY_ID,
+	ACTION_TEMPLATE_SPEC,
+	ACTION_TEMPLATE_MASK,
+
 	/* Tunnel arguments. */
 	TUNNEL_CREATE,
 	TUNNEL_CREATE_TYPE,
@@ -858,6 +878,10 @@ struct buffer {
 			struct rte_flow_port_attr port_attr;
 			struct rte_flow_queue_attr queue_attr;
 		} configure; /**< Configuration arguments. */
+		struct {
+			uint32_t *template_id;
+			uint32_t template_id_n;
+		} templ_destroy; /**< Template destroy arguments. */
 		struct {
 			uint32_t *action_id;
 			uint32_t action_id_n;
@@ -866,10 +890,13 @@ struct buffer {
 			uint32_t action_id;
 		} ia; /* Indirect action query arguments */
 		struct {
+			uint32_t it_id;
+			uint32_t at_id;
 			struct rte_flow_attr attr;
 			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
+			struct rte_flow_action *masks;
 			uint32_t pattern_n;
 			uint32_t actions_n;
 			uint8_t *data;
@@ -949,6 +976,43 @@ static const enum index next_config_attr[] = {
 	ZERO,
 };
 
+static const enum index next_it_subcmd[] = {
+	ITEM_TEMPLATE_CREATE,
+	ITEM_TEMPLATE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_it_attr[] = {
+	ITEM_TEMPLATE_CREATE_ID,
+	ITEM_TEMPLATE_RELAXED_MATCHING,
+	ITEM_TEMPLATE_SPEC,
+	ZERO,
+};
+
+static const enum index next_it_destroy_attr[] = {
+	ITEM_TEMPLATE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index next_at_subcmd[] = {
+	ACTION_TEMPLATE_CREATE,
+	ACTION_TEMPLATE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_at_attr[] = {
+	ACTION_TEMPLATE_CREATE_ID,
+	ACTION_TEMPLATE_SPEC,
+	ZERO,
+};
+
+static const enum index next_at_destroy_attr[] = {
+	ACTION_TEMPLATE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -1987,6 +2051,12 @@ static int parse_isolate(struct context *, const struct token *,
 static int parse_configure(struct context *, const struct token *,
 			   const char *, unsigned int,
 			   void *, unsigned int);
+static int parse_template(struct context *, const struct token *,
+			  const char *, unsigned int,
+			  void *, unsigned int);
+static int parse_template_destroy(struct context *, const struct token *,
+				  const char *, unsigned int,
+				  void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2056,6 +2126,10 @@ static int comp_set_modify_field_op(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
 static int comp_set_modify_field_id(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_item_template_id(struct context *, const struct token *,
+				 unsigned int, char *, unsigned int);
+static int comp_action_template_id(struct context *, const struct token *,
+				   unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -2206,6 +2280,20 @@ static const struct token token_list[] = {
 		.call = parse_flex_handle,
 		.comp = comp_none,
 	},
+	[COMMON_ITEM_TEMPLATE_ID] = {
+		.name = "{item_template_id}",
+		.type = "ITEM_TEMPLATE_ID",
+		.help = "item template id",
+		.call = parse_int,
+		.comp = comp_item_template_id,
+	},
+	[COMMON_ACTION_TEMPLATE_ID] = {
+		.name = "{action_template_id}",
+		.type = "ACTION_TEMPLATE_ID",
+		.help = "action template id",
+		.call = parse_int,
+		.comp = comp_action_template_id,
+	},
 	/* Top-level command. */
 	[FLOW] = {
 		.name = "flow",
@@ -2213,6 +2301,8 @@ static const struct token token_list[] = {
 		.help = "manage ingress/egress flow rules",
 		.next = NEXT(NEXT_ENTRY
 			     (CONFIGURE,
+			      ITEM_TEMPLATE,
+			      ACTION_TEMPLATE,
 			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
@@ -2278,6 +2368,112 @@ static const struct token token_list[] = {
 					args.configure.port_attr.nb_meters)),
 	},
 	/* Top-level command. */
+	[ITEM_TEMPLATE] = {
+		.name = "item_template",
+		.type = "{command} {port_id} [{arg} [...]]",
+		.help = "manage item templates",
+		.next = NEXT(next_it_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template,
+	},
+	/* Sub-level commands. */
+	[ITEM_TEMPLATE_CREATE] = {
+		.name = "create",
+		.help = "create item template",
+		.next = NEXT(next_it_attr),
+		.call = parse_template,
+	},
+	[ITEM_TEMPLATE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy item template",
+		.next = NEXT(NEXT_ENTRY(ITEM_TEMPLATE_DESTROY_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template_destroy,
+	},
+	/* Item arguments. */
+	[ITEM_TEMPLATE_CREATE_ID] = {
+		.name = "item_template_id",
+		.help = "specify a item template id to create",
+		.next = NEXT(next_it_attr,
+			     NEXT_ENTRY(COMMON_ITEM_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.it_id)),
+	},
+	[ITEM_TEMPLATE_DESTROY_ID] = {
+		.name = "item_template",
+		.help = "specify an item template id to destroy",
+		.next = NEXT(next_it_destroy_attr,
+			     NEXT_ENTRY(COMMON_ITEM_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.templ_destroy.template_id)),
+		.call = parse_template_destroy,
+	},
+	[ITEM_TEMPLATE_RELAXED_MATCHING] = {
+		.name = "relaxed",
+		.help = "is matching relaxed",
+		.next = NEXT(next_it_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY_BF(struct buffer,
+			     args.vc.attr.reserved, 1)),
+	},
+	[ITEM_TEMPLATE_SPEC] = {
+		.name = "template",
+		.help = "specify item to create item template",
+		.next = NEXT(next_item),
+	},
+	/* Top-level command. */
+	[ACTION_TEMPLATE] = {
+		.name = "action_template",
+		.type = "{command} {port_id} [{arg} [...]]",
+		.help = "manage action templates",
+		.next = NEXT(next_at_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template,
+	},
+	/* Sub-level commands. */
+	[ACTION_TEMPLATE_CREATE] = {
+		.name = "create",
+		.help = "create action template",
+		.next = NEXT(next_at_attr),
+		.call = parse_template,
+	},
+	[ACTION_TEMPLATE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy action template",
+		.next = NEXT(NEXT_ENTRY(ACTION_TEMPLATE_DESTROY_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template_destroy,
+	},
+	/* Action  arguments. */
+	[ACTION_TEMPLATE_CREATE_ID] = {
+		.name = "action_template_id",
+		.help = "specify a action template id to create",
+		.next = NEXT(NEXT_ENTRY(ACTION_TEMPLATE_MASK),
+			     NEXT_ENTRY(ACTION_TEMPLATE_SPEC),
+			     NEXT_ENTRY(COMMON_ACTION_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.at_id)),
+	},
+	[ACTION_TEMPLATE_DESTROY_ID] = {
+		.name = "action_template",
+		.help = "specify an action template id to destroy",
+		.next = NEXT(next_at_destroy_attr,
+			     NEXT_ENTRY(COMMON_ACTION_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.templ_destroy.template_id)),
+		.call = parse_template_destroy,
+	},
+	[ACTION_TEMPLATE_SPEC] = {
+		.name = "template",
+		.help = "specify action to create action template",
+		.next = NEXT(next_action),
+		.call = parse_template,
+	},
+	[ACTION_TEMPLATE_MASK] = {
+		.name = "mask",
+		.help = "specify action mask to create action template",
+		.next = NEXT(next_action),
+		.call = parse_template,
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -2600,7 +2796,7 @@ static const struct token token_list[] = {
 		.name = "end",
 		.help = "end list of pattern items",
 		.priv = PRIV_ITEM(END, 0),
-		.next = NEXT(NEXT_ENTRY(ACTIONS)),
+		.next = NEXT(NEXT_ENTRY(ACTIONS, END)),
 		.call = parse_vc,
 	},
 	[ITEM_VOID] = {
@@ -5704,7 +5900,9 @@ parse_vc(struct context *ctx, const struct token *token,
 	if (!out)
 		return len;
 	if (!out->command) {
-		if (ctx->curr != VALIDATE && ctx->curr != CREATE)
+		if (ctx->curr != VALIDATE && ctx->curr != CREATE &&
+		    ctx->curr != ITEM_TEMPLATE_CREATE &&
+		    ctx->curr != ACTION_TEMPLATE_CREATE)
 			return -1;
 		if (sizeof(*out) > size)
 			return -1;
@@ -7568,6 +7766,114 @@ parse_configure(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for template create command. */
+static int
+parse_template(struct context *ctx, const struct token *token,
+	       const char *str, unsigned int len,
+	       void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != ITEM_TEMPLATE &&
+		    ctx->curr != ACTION_TEMPLATE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case ITEM_TEMPLATE_CREATE:
+		out->args.vc.pattern =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		out->args.vc.it_id = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case ACTION_TEMPLATE_CREATE:
+		out->args.vc.at_id = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case ACTION_TEMPLATE_SPEC:
+		out->args.vc.actions =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		ctx->object = out->args.vc.actions;
+		ctx->objmask = NULL;
+		return len;
+	case ACTION_TEMPLATE_MASK:
+		out->args.vc.masks =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)
+					       (out->args.vc.actions +
+						out->args.vc.actions_n),
+					       sizeof(double));
+		ctx->object = out->args.vc.masks;
+		ctx->objmask = NULL;
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for template destroy command. */
+static int
+parse_template_destroy(struct context *ctx, const struct token *token,
+		       const char *str, unsigned int len,
+		       void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *template_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command ||
+		out->command == ITEM_TEMPLATE ||
+		out->command == ACTION_TEMPLATE) {
+		if (ctx->curr != ITEM_TEMPLATE_DESTROY &&
+			ctx->curr != ACTION_TEMPLATE_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.templ_destroy.template_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	template_id = out->args.templ_destroy.template_id
+		    + out->args.templ_destroy.template_id_n++;
+	if ((uint8_t *)template_id > (uint8_t *)out + size)
+		return -1;
+	ctx->objdata = 0;
+	ctx->object = template_id;
+	ctx->objmask = NULL;
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -8535,6 +8841,54 @@ comp_set_modify_field_id(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+/** Complete available item template IDs. */
+static int
+comp_item_template_id(struct context *ctx, const struct token *token,
+		      unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+	struct port_template *pt;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (pt = port->item_templ_list; pt != NULL; pt = pt->next) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", pt->id);
+		++i;
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
+/** Complete available iaction template IDs. */
+static int
+comp_action_template_id(struct context *ctx, const struct token *token,
+			unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+	struct port_template *pt;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (pt = port->action_templ_list; pt != NULL; pt = pt->next) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", pt->id);
+		++i;
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -8798,6 +9152,24 @@ cmd_flow_parsed(const struct buffer *in)
 		port_flow_configure(in->port, &in->args.configure.port_attr,
 				    &in->args.configure.queue_attr);
 		break;
+	case ITEM_TEMPLATE_CREATE:
+		port_flow_item_template_create(in->port, in->args.vc.it_id,
+				in->args.vc.attr.reserved, in->args.vc.pattern);
+		break;
+	case ITEM_TEMPLATE_DESTROY:
+		port_flow_item_template_destroy(in->port,
+				in->args.templ_destroy.template_id_n,
+				in->args.templ_destroy.template_id);
+		break;
+	case ACTION_TEMPLATE_CREATE:
+		port_flow_action_template_create(in->port, in->args.vc.at_id,
+				in->args.vc.actions, in->args.vc.masks);
+		break;
+	case ACTION_TEMPLATE_DESTROY:
+		port_flow_action_template_destroy(in->port,
+				in->args.templ_destroy.template_id_n,
+				in->args.templ_destroy.template_id);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 85d31de7f7..80678d851f 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1595,6 +1595,49 @@ action_alloc(portid_t port_id, uint32_t id,
 	return 0;
 }
 
+static int
+template_alloc(uint32_t id, struct port_template **template,
+	       struct port_template **list)
+{
+	struct port_template *lst = *list;
+	struct port_template **ppt;
+	struct port_template *pt = NULL;
+
+	*template = NULL;
+	if (id == UINT32_MAX) {
+		/* taking first available ID */
+		if (lst) {
+			if (lst->id == UINT32_MAX - 1) {
+				printf("Highest item template ID is already"
+				" assigned, delete it first\n");
+				return -ENOMEM;
+			}
+			id = lst->id + 1;
+		} else {
+			id = 0;
+		}
+	}
+	pt = calloc(1, sizeof(*pt));
+	if (!pt) {
+		printf("Allocation of port template failed\n");
+		return -ENOMEM;
+	}
+	ppt = list;
+	while (*ppt && (*ppt)->id > id)
+		ppt = &(*ppt)->next;
+	if (*ppt && (*ppt)->id == id) {
+		printf("Template #%u is already assigned,"
+			" delete it first\n", id);
+		free(pt);
+		return -EINVAL;
+	}
+	pt->next = *ppt;
+	pt->id = id;
+	*ppt = pt;
+	*template = pt;
+	return 0;
+}
+
 /** Configure flow management resources. */
 int
 port_flow_configure(portid_t port_id,
@@ -2039,6 +2082,167 @@ age_action_get(const struct rte_flow_action *actions)
 	return NULL;
 }
 
+/** Create item template */
+int
+port_flow_item_template_create(portid_t port_id, uint32_t id, bool relaxed,
+			       const struct rte_flow_item *pattern)
+{
+	struct rte_port *port;
+	struct port_template *pit;
+	int ret;
+	struct rte_flow_item_template_attr attr = {
+					.relaxed_matching = relaxed };
+	struct rte_flow_error error;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+	ret = template_alloc(id, &pit, &port->item_templ_list);
+	if (ret)
+		return ret;
+	/* Poisoning to make sure PMDs update it in case of error. */
+	memset(&error, 0x22, sizeof(error));
+	pit->template.itempl = rte_flow_item_template_create(port_id,
+						&attr, pattern, &error);
+	if (!pit->template.itempl) {
+		uint32_t destroy_id = pit->id;
+		port_flow_item_template_destroy(port_id, 1, &destroy_id);
+		return port_flow_complain(&error);
+	}
+	printf("Item template #%u created\n", pit->id);
+	return 0;
+}
+
+/** Destroy item template */
+int
+port_flow_item_template_destroy(portid_t port_id, uint32_t n,
+				const uint32_t *template)
+{
+	struct rte_port *port;
+	struct port_template **tmp;
+	uint32_t c = 0;
+	int ret = 0;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+	tmp = &port->item_templ_list;
+	while (*tmp) {
+		uint32_t i;
+
+		for (i = 0; i != n; ++i) {
+			struct rte_flow_error error;
+			struct port_template *pit = *tmp;
+
+			if (template[i] != pit->id)
+				continue;
+			/*
+			 * Poisoning to make sure PMDs update it in case
+			 * of error.
+			 */
+			memset(&error, 0x33, sizeof(error));
+
+			if (pit->template.itempl &&
+			    rte_flow_item_template_destroy(port_id,
+							   pit->template.itempl,
+							   &error)) {
+				ret = port_flow_complain(&error);
+				continue;
+			}
+			*tmp = pit->next;
+			printf("Item template #%u destroyed\n", pit->id);
+			free(pit);
+			break;
+		}
+		if (i == n)
+			tmp = &(*tmp)->next;
+		++c;
+	}
+	return ret;
+}
+
+/** Create action template */
+int
+port_flow_action_template_create(portid_t port_id, uint32_t id,
+				 const struct rte_flow_action *actions,
+				 const struct rte_flow_action *masks)
+{
+	struct rte_port *port;
+	struct port_template *pat;
+	int ret;
+	struct rte_flow_action_template_attr attr = { 0 };
+	struct rte_flow_error error;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+	ret = template_alloc(id, &pat, &port->action_templ_list);
+	if (ret)
+		return ret;
+	/* Poisoning to make sure PMDs update it in case of error. */
+	memset(&error, 0x22, sizeof(error));
+	pat->template.atempl = rte_flow_action_template_create(port_id,
+						&attr, actions, masks, &error);
+	if (!pat->template.atempl) {
+		uint32_t destroy_id = pat->id;
+		port_flow_action_template_destroy(port_id, 1, &destroy_id);
+		return port_flow_complain(&error);
+	}
+	printf("Action template #%u created\n", pat->id);
+	return 0;
+}
+
+/** Destroy action template */
+int
+port_flow_action_template_destroy(portid_t port_id, uint32_t n,
+				  const uint32_t *template)
+{
+	struct rte_port *port;
+	struct port_template **tmp;
+	uint32_t c = 0;
+	int ret = 0;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+	tmp = &port->action_templ_list;
+	while (*tmp) {
+		uint32_t i;
+
+		for (i = 0; i != n; ++i) {
+			struct rte_flow_error error;
+			struct port_template *pat = *tmp;
+
+			if (template[i] != pat->id)
+				continue;
+			/*
+			 * Poisoning to make sure PMDs update it in case
+			 * of error.
+			 */
+			memset(&error, 0x33, sizeof(error));
+
+			if (pat->template.atempl &&
+			    rte_flow_action_template_destroy(port_id,
+					pat->template.atempl, &error)) {
+				ret = port_flow_complain(&error);
+				continue;
+			}
+			*tmp = pat->next;
+			printf("Action template #%u destroyed\n", pat->id);
+			free(pat);
+			break;
+		}
+		if (i == n)
+			tmp = &(*tmp)->next;
+		++c;
+	}
+	return ret;
+}
+
 /** Create flow rule. */
 int
 port_flow_create(portid_t port_id,
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ce80a00193..4befa6d7a4 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -166,6 +166,17 @@ enum age_action_context_type {
 	ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION,
 };
 
+/** Descriptor for a template. */
+struct port_template {
+	struct port_template *next; /**< Next template in list. */
+	struct port_template *tmp; /**< Temporary linking. */
+	uint32_t id; /**< Template ID. */
+	union {
+		struct rte_flow_item_template *itempl;
+		struct rte_flow_action_template *atempl;
+	} template; /**< PMD opaque template object */
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
@@ -246,6 +257,8 @@ struct rte_port {
 	queueid_t               queue_nb; /**< nb. of queues for flow rules */
 	uint32_t                queue_sz; /**< size of a queue for flow rules */
 	uint8_t                 slave_flag; /**< bonding slave port */
+	struct port_template    *item_templ_list; /**< Item templates. */
+	struct port_template    *action_templ_list; /**< Action templates. */
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_indirect_action *actions_list;
 	/**< Associated indirect actions. */
@@ -890,6 +903,15 @@ int port_action_handle_update(portid_t port_id, uint32_t id,
 int port_flow_configure(portid_t port_id,
 			const struct rte_flow_port_attr *port_attr,
 			const struct rte_flow_queue_attr *queue_attr);
+int port_flow_item_template_create(portid_t port_id, uint32_t id, bool relaxed,
+				   const struct rte_flow_item *pattern);
+int port_flow_item_template_destroy(portid_t port_id, uint32_t n,
+				    const uint32_t *template);
+int port_flow_action_template_create(portid_t port_id, uint32_t id,
+				     const struct rte_flow_action *actions,
+				     const struct rte_flow_action *masks);
+int port_flow_action_template_destroy(portid_t port_id, uint32_t n,
+				      const uint32_t *template);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 8af28bd3b3..d23cfa6572 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3317,6 +3317,24 @@ following sections.
        [aging_counters_number {number}]
        [meters_number {number}]
 
+- Create an item template::
+   flow item_template {port_id} create [item_template_id {id}]
+       [relaxed {boolean}] template {item} [/ {item} [...]] / end
+
+- Destroy an item template::
+
+   flow item_template {port_id} destroy item_template {id} [...]
+
+- Create an action template::
+
+   flow action_template {port_id} create [action_template_id {id}]
+       template {action} [/ {action} [...]] / end
+       mask {action} [/ {action} [...]] / end
+
+- Destroy an action template::
+
+   flow action_template {port_id} destroy action_template {id} [...]
+
 - Check whether a flow rule can be created::
 
    flow validate {port_id}
@@ -3398,6 +3416,85 @@ Otherwise it will show an error message of the form::
 
    Caught error type [...] ([...]): [...]
 
+Creating item templates
+~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow item_template create`` creates the specified item template.
+It is bound to ``rte_flow_item_template_create()``::
+
+   flow item_template {port_id} create [item_template_id {id}]
+       [relaxed {boolean}] template {item} [/ {item} [...]] / end
+
+If successful, it will show::
+
+   Item template #[...] created
+
+Otherwise it will show an error message of the form::
+
+   Caught error type [...] ([...]): [...]
+
+This command uses the same pattern items as ``flow create``,
+their format is described in `Creating flow rules`_.
+
+Destroying item templates
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow item_template destroy`` destroys one or more item templates
+from their template ID (as returned by ``flow item_template create``),
+this command calls ``rte_flow_item_template_destroy()`` as many
+times as necessary::
+
+   flow item_template {port_id} destroy item_template {id} [...]
+
+If successful, it will show::
+
+   Item template #[...] destroyed
+
+It does not report anything for item template IDs that do not exist.
+The usual error message is shown when an item template cannot be destroyed::
+
+   Caught error type [...] ([...]): [...]
+
+Creating action templates
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow action_template create`` creates the specified action template.
+It is bound to ``rte_flow_action_template_create()``::
+
+   flow action_template {port_id} create [action_template_id {id}]
+       template {action} [/ {action} [...]] / end
+       mask {action} [/ {action} [...]] / end
+
+If successful, it will show::
+
+   Action template #[...] created
+
+Otherwise it will show an error message of the form::
+
+   Caught error type [...] ([...]): [...]
+
+This command uses the same actions as ``flow create``,
+their format is described in `Creating flow rules`_.
+
+Destroying action templates
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow action_template destroy`` destroys one or more action templates
+from their template ID (as returned by ``flow action_template create``),
+this command calls ``rte_flow_action_template_destroy()`` as many
+times as necessary::
+
+   flow action_template {port_id} destroy action_template {id} [...]
+
+If successful, it will show::
+
+   Action template #[...] destroyed
+
+It does not report anything for item template IDs that do not exist.
+The usual error message is shown when an item template cannot be destroyed::
+
+   Caught error type [...] ([...]): [...]
+
 Creating a tunnel stub for offload
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.18.2