From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4815AA0525 for ; Tue, 18 Feb 2020 07:37:33 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 427F81DA0C; Tue, 18 Feb 2020 07:37:33 +0100 (CET) Received: from dish-sg.nttdocomo.co.jp (dish-sg.nttdocomo.co.jp [202.19.227.74]) by dpdk.org (Postfix) with ESMTP id 577701DA28 for ; Tue, 18 Feb 2020 07:37:31 +0100 (CET) X-dD-Source: Outbound Received: from zssg-mailmd101.ddreams.local (zssg-mailmd900.ddreams.local [10.160.172.63]) by zssg-mailou102.ddreams.local (Postfix) with ESMTP id 9A857120138; Tue, 18 Feb 2020 15:37:30 +0900 (JST) Received: from zssg-mailmf104.ddreams.local (zssg-mailmf900.ddreams.local [10.160.172.84]) by zssg-mailmd101.ddreams.local (dDREAMS) with ESMTP id <0Q5V00KRQX2IB980@dDREAMS>; Tue, 18 Feb 2020 15:37:30 +0900 (JST) Received: from zssg-mailmf104.ddreams.local (unknown [127.0.0.1]) by zssg-mailmf104.ddreams.local (Postfix) with ESMTP id 6BCC57E603A; Tue, 18 Feb 2020 15:37:30 +0900 (JST) Received: from zssg-mailmf104.ddreams.local (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A5178E605D; Tue, 18 Feb 2020 15:37:30 +0900 (JST) Received: from localhost (unknown [127.0.0.1]) by IMSVA (Postfix) with SMTP id 693028E605E; Tue, 18 Feb 2020 15:37:30 +0900 (JST) X-IMSS-HAND-OFF-DIRECTIVE: localhost:10026 Received: from zssg-mailmf104.ddreams.local (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1BDE8E605E; Tue, 18 Feb 2020 15:37:29 +0900 (JST) Received: from davinci.ntt-tx.co.jp (unknown [10.160.183.139]) by zssg-mailmf104.ddreams.local (Postfix) with ESMTP; Tue, 18 Feb 2020 15:37:29 +0900 (JST) From: x-fn-spp-ml@ntt-tx.co.jp To: ferruh.yigit@intel.com, yasufum.o@gmail.com Cc: spp@dpdk.org Date: Tue, 18 Feb 2020 15:37:11 +0900 Message-id: <20200218063720.6597-9-x-fn-spp-ml@ntt-tx.co.jp> X-Mailer: git-send-email 2.18.0 In-reply-to: <20200218063720.6597-1-x-fn-spp-ml@ntt-tx.co.jp> References: <20200218063720.6597-1-x-fn-spp-ml@ntt-tx.co.jp> X-TM-AS-GCONF: 00 Subject: [spp] [PATCH 08/17] spp_primary: add attribute of rte_flow X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Hideyuki Yamashita To support rte_flow in SPP, this patch provides support of various attribute of rte_flow. Signed-off-by: Hideyuki Yamashita Signed-off-by: Yasufumi Ogawa --- src/primary/flow/attr.c | 105 ++++++++++++++++++++++++++++++++++++++++ src/primary/flow/attr.h | 13 +++++ 2 files changed, 118 insertions(+) create mode 100644 src/primary/flow/attr.c create mode 100644 src/primary/flow/attr.h diff --git a/src/primary/flow/attr.c b/src/primary/flow/attr.c new file mode 100644 index 0000000..8be7319 --- /dev/null +++ b/src/primary/flow/attr.c @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#include + +#include "attr.h" + +int +parse_flow_attr(char *token_list[], int *index, + struct rte_flow_attr *attr) +{ + int ret; + char *token; + char *end; + unsigned long temp = 0; + + while (token_list[*index] != NULL) { + token = token_list[*index]; + + if (!strcmp(token, "group")) { + /* "group" requires option argument */ + if (token_list[*index + 1] == NULL) { + ret = -1; + break; + } + + temp = strtoul(token_list[*index + 1], &end, 10); + if (end == NULL || *end != '\0') { + ret = -1; + break; + } + + attr->group = (uint32_t)temp; + (*index)++; + + } else if (!strcmp(token, "priority")) { + /* "priority" requires option argument */ + if (token_list[*index + 1] == NULL) { + ret = -1; + break; + } + + temp = strtoul(token_list[*index + 1], &end, 10); + if (end == NULL || *end != '\0') { + ret = -1; + break; + } + + attr->priority = (uint32_t)temp; + (*index)++; + + } else if (!strcmp(token, "ingress")) { + attr->ingress = 1; + + } else if (!strcmp(token, "egress")) { + attr->egress = 1; + + } else if (!strcmp(token, "transfer")) { + attr->transfer = 1; + + } else if (!strcmp(token, "pattern")) { + /* Attribute parameter end */ + ret = 0; + break; + + } else { + /* Illegal parameter */ + ret = -1; + break; + + } + + (*index)++; + } + + if (token_list[*index] == NULL) + ret = -1; + + return ret; +} + +int +append_flow_attr_json(const struct rte_flow_attr *attr, int buf_size, + char *attr_str) +{ + char tmp_str[128] = { 0 }; + + snprintf(tmp_str, 128, + "{\"group\":%d," + "\"priority\":%d," + "\"ingress\":%d," + "\"egress\":%d," + "\"transfer\":%d}", + attr->group, attr->priority, attr->ingress, + attr->egress, attr->transfer); + + if ((int)strlen(attr_str) + (int)strlen(tmp_str) + > buf_size) + return -1; + + strncat(attr_str, tmp_str, strlen(tmp_str)); + + return 0; +} diff --git a/src/primary/flow/attr.h b/src/primary/flow/attr.h new file mode 100644 index 0000000..5fb22e3 --- /dev/null +++ b/src/primary/flow/attr.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#ifndef _PRIMARY_FLOW_ATTR_H_ +#define _PRIMARY_FLOW_ATTR_H_ + +int parse_flow_attr(char *token_list[], int *index, + struct rte_flow_attr *attr); +int append_flow_attr_json(const struct rte_flow_attr *attr, + int buf_size, char *attr_str); + +#endif -- 2.17.1