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 AC3B6A0524 for ; Tue, 25 Feb 2020 06:56:51 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A61C51BFAC; Tue, 25 Feb 2020 06:56:51 +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 60DC53B5 for ; Tue, 25 Feb 2020 06:56:49 +0100 (CET) X-dD-Source: Outbound Received: from zssg-mailmd104.ddreams.local (zssg-mailmd900.ddreams.local [10.160.172.63]) by zssg-mailou103.ddreams.local (Postfix) with ESMTP id A0EF812010C; Tue, 25 Feb 2020 14:56:48 +0900 (JST) Received: from zssg-mailmf101.ddreams.local (zssg-mailmf900.ddreams.local [10.160.172.84]) by zssg-mailmd104.ddreams.local (dDREAMS) with ESMTP id <0Q68009ZRTUOPD80@dDREAMS>; Tue, 25 Feb 2020 14:56:48 +0900 (JST) Received: from zssg-mailmf101.ddreams.local (unknown [127.0.0.1]) by zssg-mailmf101.ddreams.local (Postfix) with ESMTP id 847A27E603A; Tue, 25 Feb 2020 14:56:48 +0900 (JST) Received: from zssg-mailmf101.ddreams.local (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 821E28E605C; Tue, 25 Feb 2020 14:56:48 +0900 (JST) Received: from localhost (unknown [127.0.0.1]) by IMSVA (Postfix) with SMTP id 802478E6064; Tue, 25 Feb 2020 14:56:48 +0900 (JST) X-IMSS-HAND-OFF-DIRECTIVE: localhost:10026 Received: from zssg-mailmf101.ddreams.local (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 304F98E605C; Tue, 25 Feb 2020 14:56:48 +0900 (JST) Received: from davinci.ntt-tx.co.jp (unknown [10.160.183.139]) by zssg-mailmf101.ddreams.local (Postfix) with ESMTP; Tue, 25 Feb 2020 14:56:48 +0900 (JST) From: x-fn-spp-ml@ntt-tx.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Tue, 25 Feb 2020 14:56:30 +0900 Message-id: <20200225055639.31616-9-x-fn-spp-ml@ntt-tx.co.jp> X-Mailer: git-send-email 2.18.0 In-reply-to: <20200219112155.13964-1-yamashita.hideyuki@ntt-tx.co.jp> References: <20200219112155.13964-1-yamashita.hideyuki@ntt-tx.co.jp> X-TM-AS-GCONF: 00 Subject: [spp] [PATCH v3 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: Naoki Takada --- 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