[spp] [PATCH 08/17] spp_primary: add attribute of rte_flow

x-fn-spp-ml at ntt-tx.co.jp x-fn-spp-ml at ntt-tx.co.jp
Tue Feb 18 07:37:11 CET 2020


From: Hideyuki Yamashita <yamashita.hideyuki at ntt-tx.co.jp>

To support rte_flow in SPP, this patch provides support of various
attribute of rte_flow.

Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki at ntt-tx.co.jp>
Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
 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 <rte_flow.h>
+
+#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



More information about the spp mailing list