DPDK patches and discussions
 help / color / mirror / Atom feed
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: Ferruh Yigit <ferruh.yigit@intel.com>,
	Gaetan Rivet <gaetan.rivet@6wind.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v1 6/7] ethdev: generate flow API conversion header
Date: Thu,  5 Oct 2017 11:49:07 +0200	[thread overview]
Message-ID: <1c2bcd3d1e44dd94d9c992315bfab9d75776cc20.1507193186.git.adrien.mazarguil@6wind.com> (raw)
In-Reply-To: <cover.1507193185.git.adrien.mazarguil@6wind.com>

Add script and build target to generate rte_flow_conv.h (used by
rte_flow_conv()) from rte_flow.h.

Although the resulting header file is internal and not public, this is not
done automatically since it is versioned in the source tree.

Developers can update it after making changes to rte_flow.h by running:

 make lib/librte_ether_sub RTE_MAKE_SUBTARGET=rte_flow_conv.h

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 MAINTAINERS                       |   1 +
 buildtools/gen-rte_flow_conv-h.sh | 264 +++++++++++++++++++++++++++++++++
 lib/librte_ether/Makefile         |  10 ++
 3 files changed, 275 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9eec984..002b54e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -253,6 +253,7 @@ F: devtools/test-null.sh
 
 Flow API
 M: Adrien Mazarguil <adrien.mazarguil@6wind.com>
+F: buildtools/gen-rte_flow_conv-h.sh
 F: lib/librte_ether/rte_flow*
 
 Traffic Management API - EXPERIMENTAL
diff --git a/buildtools/gen-rte_flow_conv-h.sh b/buildtools/gen-rte_flow_conv-h.sh
new file mode 100755
index 0000000..482e733
--- /dev/null
+++ b/buildtools/gen-rte_flow_conv-h.sh
@@ -0,0 +1,264 @@
+#!/bin/sh -e
+#
+#   BSD LICENSE
+#
+#   Copyright 2017 6WIND S.A.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of 6WIND S.A. nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# This script generates an internal flow API header file needed by
+# conversion function rte_flow_conv().
+#
+# This is done by feeding rte_flow.h to the C preprocessor and transforming
+# its output into a different C header file whose name is provided as a
+# command-line argument.
+#
+# CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
+# environment.
+
+# Check command-line parameters and environment.
+: ${CC:=cc}
+output=${1:?missing output file name}
+
+# Generate pattern for C punctuators.
+punctuators=$(printf '%s' \
+'[ ] ( ) { } . ->
+++ -- & * + - ~ !
+/ % << >> < > <= >= == != ^ | && ||
+? : ; ...
+= *= /= %= += -= <<= >>= &= ^= |=
+, # ##
+<: :> <% %> %: %: %:' |
+	tr '\n' ' ' |
+	sed -ne 's/[[/.*\?]/\\&/g' -e 's/[[:space:]]\+/\\|/gp')
+
+# Generate include guard.
+guard=$(printf '%s_' "${output##*/}" |
+	tr [[:lower:]] [[:upper:]] |
+	sed -e 's/[^A-Z0-9]/_/g' -e 's/^.\{,4\}$//')
+
+# Retrieve C preprocessor output and expand it to one token per line.
+preprocess ()
+{
+	{
+		temp=/tmp/${0##*/}.$$.c
+		printf '#include "rte_flow.h"' > "$temp"
+		${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} \
+			${CFLAGS} ${EXTRA_CFLAGS} -E "$temp"
+		rm -f "$temp"
+	} |
+	sed -e '
+/^[[:space:]]*#/d
+s/[[:space:]]\+/\n/g
+s/'"$punctuators"'/\n&\n/g
+' |
+	sed -e '/^[[:space:]]*$/d'
+}
+
+# Retrieve defined pattern items and actions.
+items=''
+actions=''
+while read -r type name dummy
+do
+	case "$type" in
+	ITEM)
+		items="$items $name"
+		;;
+	ACTION)
+		actions="$actions $name"
+		;;
+	esac
+done <<EOF
+$(preprocess |
+sed -ne '
+/^enum$/{
+	n
+	/rte_flow_\(item\|action\)_type/{
+		n
+		/{/{
+			:a
+			n
+			/}/b
+			s/^RTE_FLOW_\(ITEM\|ACTION\)_TYPE_\([A-Z_0-9]\+\)$/\1 \2/
+			p
+			ba
+		}
+	}
+}')
+EOF
+
+# Complain if something went wrong.
+: ${guard:?include guard is either too short or empty}
+: ${items:?no items found in input file}
+: ${actions:?no actions found in input file}
+
+# Open output file.
+exec 1> "${output}" ||
+exit
+
+# Reuse license header from this script.
+sed -ne '
+/^#.*BSD LICENSE/{
+	i\
+/*-
+	:a
+	/^#/!{
+		i\
+ */
+		q
+	}
+	s/^#/ */
+	p
+	n
+	ba
+}
+' "$0"
+
+# Output includes and structure definitions.
+printf '
+/**
+ * @file
+ * RTE generic flow API (internal)
+ *
+ * This file exports resources needed by rte_flow_conv().
+ *
+ * DO NOT EDIT THIS FILE.
+ *
+ * It was generated from rte_flow.h, run %s to update it.
+ */
+
+#ifndef %s
+#define %s
+
+#include <stddef.h>
+
+#include "rte_flow.h"
+
+/**
+ * This structure describes either a pattern item or an action as well as
+ * their associated specification or configuration structure.
+ */
+struct rte_flow_conv_res {
+	const char *name; /**< Object name. */
+	const void *mask; /**< Default mask for structure if relevant. */
+	size_t size; /**< Associated structure size. */
+	size_t flex_len_type; /**< Length field type for flexible array. */
+	size_t flex_len_off; /**< Length field offset for flexible array. */
+	size_t flex_elt_size; /**< Flexible array element size. */
+	size_t flex_off; /**< Flexible array field offset. */
+};
+' \
+	"${0##*/}" \
+	"$guard" \
+	"$guard"
+
+# Pattern items/actions arrays generator.
+generate ()
+{
+	type=${1:?missing type}
+	desc=${2:?missing description}
+	lc_type=$(printf '%s' "$type" | tr [:upper:] [:lower:])
+	: ${lc_type:?cannot convert type to lower case}
+	shift 2
+	objects=${@:?missing objects}
+	printf '
+/** %s description table. */
+static const struct rte_flow_conv_res rte_flow_conv_res_%s[] = {' \
+		"$desc" "$lc_type"
+	for object in $objects
+	do
+		lc_object=$(printf '%s' "$object" | tr [:upper:] [:lower:]) ||
+		break
+		set -- $(preprocess |
+		sed -ne '
+/^struct$/{
+	n
+	/^rte_flow_'"$lc_type"'_'"$lc_object"'$/{
+		:a
+		p
+		/^{$/{
+			H
+			n
+			ba
+		}
+		/^}$/{
+			x
+			s/\n{$//
+			/^$/q
+			x
+		}
+		n
+		ba
+	}
+}' |
+		tr '\n' ' ' |
+		sed -ne '
+s/ /\n/
+P
+s/^.* \([^ ]\+\) ; [^ ]\+ \([^ ]\+\) \[ ] ; } $/\1 \2/p')
+		size=${1:+"sizeof(struct $1)"}
+		: ${size:=0}
+		flex_len_type=${2:+"sizeof(((struct $1 *)0)->$2)"}
+		: ${flex_len_type:=0}
+		flex_len_off=${2:+"offsetof(struct $1, $2)"}
+		: ${flex_len_off:=0}
+		flex_elt_size=${2:+"sizeof(((struct $1 *)0)->$3[0])"}
+		: ${flex_elt_size:=0}
+		flex_off=${3:+"offsetof(struct $1, $3)"}
+		: ${flex_off:=0}
+		printf '
+	[RTE_FLOW_'"$type"'_TYPE_%s] = {
+		.name = "%s",
+		.size = %s,
+		.flex_len_type = %s,
+		.flex_len_off = %s,
+		.flex_elt_size = %s,
+		.flex_off = %s,
+	},' \
+		"$object" \
+		"$lc_object" \
+		"$size" \
+		"$flex_len_type" \
+		"$flex_len_off" \
+		"$flex_elt_size" \
+		"$flex_off"
+	done
+	printf '
+};
+'
+}
+
+# Generate pattern items/actions arrays.
+generate ITEM "Pattern items" $items &&
+generate ACTION "Actions" $actions ||
+exit
+
+# Output footer.
+printf '
+#endif /* %s */
+' \
+	"$guard"
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 5f65d05..0b3f77e 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -61,4 +61,14 @@ SYMLINK-y-include += rte_flow_driver.h
 SYMLINK-y-include += rte_tm.h
 SYMLINK-y-include += rte_tm_driver.h
 
+#
+# This file is versioned thus not built automatically.
+# To re-generate it, run:
+#
+#     make lib/librte_ether_sub RTE_MAKE_SUBTARGET=rte_flow_conv.h
+#
+rte_flow_conv.h: rte_flow.h
+	@$(if $V,,echo "  GEN $(@F)")
+	$Q sh -- $(RTE_SDK)/buildtools/gen-rte_flow_conv-h.sh "$(<D)/$(@F)"
+
 include $(RTE_SDK)/mk/rte.lib.mk
-- 
2.1.4

  parent reply	other threads:[~2017-10-05  9:49 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05  9:49 [dpdk-dev] [PATCH v1 0/7] Flow API helpers enhancements Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 1/7] ethdev: expose flow API error helper Adrien Mazarguil
2017-10-11  9:23   ` Thomas Monjalon
2017-10-11 11:56     ` Adrien Mazarguil
2017-10-11 19:05       ` Aaron Conole
2017-10-12 13:37         ` Neil Horman
2017-10-12 14:02         ` Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 2/7] ethdev: replace flow API object copy function Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 3/7] ethdev: add flow API item/action name conversion Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 4/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 5/7] ethdev: enhance flow API item/action descriptions Adrien Mazarguil
2017-10-05  9:49 ` Adrien Mazarguil [this message]
2017-10-05  9:49 ` [dpdk-dev] [PATCH v1 7/7] ethdev: update flow API conversion header Adrien Mazarguil
2017-10-06  1:13 ` [dpdk-dev] [PATCH v1 0/7] Flow API helpers enhancements Ferruh Yigit
2017-10-06  8:05   ` Adrien Mazarguil
2017-10-10 18:05     ` Ferruh Yigit
2017-10-11  9:57       ` Adrien Mazarguil
2017-10-11 18:07         ` Ferruh Yigit
2017-10-12 12:53           ` Adrien Mazarguil
2017-10-12 16:37             ` Ferruh Yigit
2017-10-13 10:42               ` Adrien Mazarguil
2018-08-03 13:36 ` [dpdk-dev] [PATCH v2 0/7] ethdev: add flow API object converter Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 1/7] " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 2/7] ethdev: add flow API item/action name conversion Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 3/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 4/7] net/failsafe: switch to flow API object " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 5/7] net/bonding: " Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 6/7] ethdev: deprecate rte_flow_copy function Adrien Mazarguil
2018-08-03 13:36   ` [dpdk-dev] [PATCH v2 7/7] ethdev: add missing item/actions to flow object converter Adrien Mazarguil
2018-08-03 14:06   ` [dpdk-dev] [PATCH v2 0/7] ethdev: add flow API " Thomas Monjalon
2018-08-23 13:48   ` Ferruh Yigit
2018-08-27 15:14     ` Adrien Mazarguil
2018-08-24 10:58   ` Ferruh Yigit
2018-08-27 14:12     ` Adrien Mazarguil
2018-08-31  9:00   ` [dpdk-dev] [PATCH v3 " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 1/7] " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 2/7] ethdev: add flow API item/action name conversion Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 3/7] app/testpmd: rely on flow API conversion function Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 4/7] net/failsafe: switch to flow API object " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 5/7] net/bonding: " Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 6/7] ethdev: add missing items/actions to flow object converter Adrien Mazarguil
2018-08-31  9:01     ` [dpdk-dev] [PATCH v3 7/7] ethdev: deprecate rte_flow_copy function Adrien Mazarguil
2018-10-04 14:21       ` Ferruh Yigit
2018-08-31 11:32     ` [dpdk-dev] [PATCH v3 0/7] ethdev: add flow API object converter Nélio Laranjeiro
2018-10-03 20:31       ` Thomas Monjalon
2018-10-04 14:25         ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c2bcd3d1e44dd94d9c992315bfab9d75776cc20.1507193186.git.adrien.mazarguil@6wind.com \
    --to=adrien.mazarguil@6wind.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gaetan.rivet@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).