examples/flow_filtering: introduce use cases snippets
PATCH 1/1 examples/flow_filtering: introduce use cases snippets
These code snippets demonstrate rule creation using template and non-template APIs.
They include functions that enable developers to create rules. The purpose of providing these snippets is to allow developers to reuse them, thereby saving time and effort during the implementation of flow rules.
The code snippets are categorized based on their usage and can be copied, paste and modified to suit any requirements.
The snippets provided here are kept up to date and are being compiled along with the rest of the examples.
There is a skeleton that demonstrates rule creation using both template and non template APIs.
Developers can change the functions in the skeleton to the corresponding snippet functions with the appropriate suffix and create rules using the snippets themselves for easy testing. Each snippet has the same functions to implement the actions and patterns for the corresponding feature.
--- doc/guides/prog_guide/ethdev/flow_offload.rst | 2 + doc/guides/sample_app_ug/flow_filtering.rst | 295 +++++++----------- examples/flow_filtering/common.h | 29 ++ examples/flow_filtering/flow_blocks.c | 112 ------- examples/flow_filtering/flow_skeleton.c | 83 +++++ examples/flow_filtering/main.c | 134 ++++++-- examples/flow_filtering/meson.build | 9 + .../snippets/snippet_match_gre.c | 54 ++++ .../snippets/snippet_match_gre.h | 25 ++ .../snippets/snippet_match_ipv4.c | 154 +++++++++ .../snippets/snippet_match_ipv4.h | 31 ++ .../snippets/snippet_match_mpls.c | 178 +++++++++++ .../snippets/snippet_match_mpls.h | 29 ++ 13 files changed, 805 insertions(+), 330 deletions(-) create mode 100644 examples/flow_filtering/common.h delete mode 100644 examples/flow_filtering/flow_blocks.c create mode 100644 examples/flow_filtering/flow_skeleton.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.h create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.c create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.h create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.c create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.h
doc/guides/prog_guide/ethdev/flow_offload.rst +2 -0
@@ -3833,6 +3833,8 @@ For example, to configure a RTE_FLOW_TYPE_JUMP action as a miss action for ingre struct rte_flow_error err; rte_flow_group_set_miss_actions(port, 1, &attr, act, &err); +.. _flow_templates: + Flow templates ~~~~~~~~~~~~~~
doc/guides/sample_app_ug/flow_filtering.rst +111 -184
362 lines not on this page · raw message
examples/flow_filtering/common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef COMMON +#define COMMON + +#define QUEUE_ID 1 + +extern struct rte_flow_attr attr; +extern struct rte_flow_op_attr ops_attr; + +/** +* Skeleton for creation of a flow rule using template and non template API +* +* @param port_id +* The selected port. +* @param[out] error +* Perform verbose error reporting if not NULL. +* @param[out] flow_template +* The selected API to use. +* @return +* A flow if the rule could be created else return NULL. +*/ +/* Function responsible for creating the flow rule. 8< */ +struct rte_flow * +generate_flow_skeleton (uint16_t port_id,struct rte_flow_error *error,int use_template_api); + +#endif /* COMMON */
examples/flow_filtering/flow_blocks.c deleted +0 -112
112 lines not on this page · raw message
examples/flow_filtering/flow_skeleton.c new file +83 -0
83 lines not on this page · raw message
examples/flow_filtering/main.c +100 -34
255 lines not on this page · raw message
examples/flow_filtering/meson.build +9 -0
@@ -7,6 +7,15 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['argparse'] + sources = files( 'main.c', + 'flow_skeleton.c', + 'snippets/snippet_match_ipv4.c', + 'snippets/snippet_match_gre.c', + 'snippets/snippet_match_mpls.c', ) + +# The code snippets are not utilized. +cflags += '-Wno-unused-function'
examples/flow_filtering/snippets/snippet_match_gre.c new file +54 -0
54 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_gre.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_GRE +#define SNIPPET_MATCH_GRE + +/* Matching GRE Checksum/Key/Sequence +* GRE optional fields (checksum, key and sequence) can be matched using the gre_option item. +* The item requires a GRE item such as gre_key, and its pattern must correspond with the +* c_bit/k_bit/s_bit in the GRE pattern. +*/ + +#define MAX_PATTERN_NUM 5/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_actions (struct rte_flow_action *action); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_patterns (struct rte_flow_item *pattern); + +#endif /* SNIPPET_MATCH_GRE */
examples/flow_filtering/snippets/snippet_match_ipv4.c new file +154 -0
154 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_ipv4.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_IPV4 +#define SNIPPET_MATCH_IPV4 + +/* Match IPV4 flow +* sends packets with matching src and dest ip to selected queue. +*/ + +#define SRC_IP ((0<<24) + (0<<16) + (0<<8) + 0)/* src ip = 0.0.0.0 */ +#define DEST_IP ((192<<24) + (168<<16) + (1<<8) + 1)/* dest ip = 192.168.1.1 */ +#define FULL_MASK 0xffffffff/* full mask */ +#define EMPTY_MASK 0x0/* empty mask */ +#define DEST_MASK 0xffff/* full mask */ + +#define MAX_PATTERN_NUM 3/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +void +snippet_ipv4_flow_create_actions (struct rte_flow_action *action); + +void +snippet_ipv4_flow_create_patterns (struct rte_flow_item *patterns); + +struct rte_flow_template_table * +snippet_ipv4_flow_create_table (uint16_t port_id,struct rte_flow_error *error); + + +#endif /* SNIPPET_MATCH_IPV4 */
examples/flow_filtering/snippets/snippet_match_mpls.c new file +178 -0
178 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_mpls.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_MPLS +#define SNIPPET_MATCH_MPLS + +/* Multiprotocol Label Switching snippet +* In this example we match MPLS tunnel over UDP when in HW steering mode. +* It supports multiple MPLS headers for matching as well as encapsulation/decapsulation. +* The maximum supported MPLS headers is 5. +*/ + +#define MAX_PATTERN_NUM 6/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_mpls_create_actions (struct rte_flow_action *actions); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_mpls_create_patterns (struct rte_flow_item *pattern); + +/* Replace this function with the snippet_*_create_table() function in flow_skeleton.c. */ +static struct rte_flow_template_table * +snippet_mpls_create_table (uint16_t port_id,struct rte_flow_error *error); + +#endif /* SNIPPET_MATCH_MPLS */
Signature · 1 line
2.34.1
PATCH v2 1/1 examples/flow_filtering: introduce use cases snippets
These code snippets demonstrate rule creation using template and non-template APIs.
They include functions that enable developers to create rules. The purpose of providing these snippets is to allow developers to reuse them, thereby saving time and effort during the implementation of flow rules.
The code snippets are categorized based on their usage and can be copied, paste and modified to suit any requirements.
The snippets provided here are kept up to date and are being compiled along with the rest of the examples.
There is a skeleton that demonstrates rule creation using both template and non template APIs.
Developers can change the functions in the skeleton to the corresponding snippet functions with the appropriate suffix and create rules using the snippets themselves for easy testing. Each snippet has the same functions to implement the actions and patterns for the corresponding feature.
--- doc/guides/prog_guide/rte_flow.rst | 2 + doc/guides/sample_app_ug/flow_filtering.rst | 295 +++++++----------- examples/flow_filtering/Makefile | 19 +- examples/flow_filtering/common.h | 29 ++ examples/flow_filtering/flow_blocks.c | 112 ------- examples/flow_filtering/flow_skeleton.c | 85 +++++ examples/flow_filtering/main.c | 134 ++++++-- examples/flow_filtering/meson.build | 9 + .../snippets/snippet_match_gre.c | 54 ++++ .../snippets/snippet_match_gre.h | 25 ++ .../snippets/snippet_match_ipv4.c | 154 +++++++++ .../snippets/snippet_match_ipv4.h | 31 ++ .../snippets/snippet_match_mpls.c | 179 +++++++++++ .../snippets/snippet_match_mpls.h | 29 ++ 14 files changed, 820 insertions(+), 337 deletions(-) create mode 100644 examples/flow_filtering/common.h delete mode 100644 examples/flow_filtering/flow_blocks.c create mode 100644 examples/flow_filtering/flow_skeleton.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.h create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.c create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.h create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.c create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.h
doc/guides/prog_guide/rte_flow.rst +2 -0
@@ -3833,6 +3833,8 @@ For example, to configure a RTE_FLOW_TYPE_JUMP action as a miss action for ingre struct rte_flow_error err; rte_flow_group_set_miss_actions(port, 1, &attr, act, &err); +.. _flow_templates: + Flow templates ~~~~~~~~~~~~~~
doc/guides/sample_app_ug/flow_filtering.rst +111 -184
362 lines not on this page · raw message
examples/flow_filtering/Makefile +12 -7
@@ -3,7 +3,9 @@ APP = flow -SRCS-y := main.c +SRCS-y := main.c flow_skeleton.c +subdir := snippets +snippet_objects := $(addprefix build/,$(notdir $(patsubst %.c,%.o,$(wildcard $(subdir)/*.c)))) PKGCONF ?= pkg-config
@@ -21,8 +23,8 @@ static: build/$(APP)-static PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null) CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) -LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) -LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk) +LDFLAGS_SHARED += $(shell $(PKGCONF) --libs libdpdk) +LDFLAGS_STATIC += $(shell $(PKGCONF) --static --libs libdpdk) ifeq ($(MAKECMDGOALS),static) # check for broken pkg-config
@@ -34,11 +36,14 @@ endif CFLAGS += -DALLOW_EXPERIMENTAL_API -build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build - $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) +build/$(APP)-shared: $(SRCS-y) $(snippet_objects) Makefile $(PC_FILE) | build + $(CC) $(CFLAGS) $(SRCS-y) $(snippet_objects) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) -build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build - $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) +build/$(APP)-static: $(SRCS-y) $(snippet_objects) Makefile $(PC_FILE) | build + $(CC) $(CFLAGS) $(SRCS-y) $(snippet_objects) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) + +build/snippet_%.o: $(subdir)/snippet_%.c | build + $(CC) -c $(CFLAGS) -Wno-unused-function $< -o $@ build: @mkdir -p $@
examples/flow_filtering/common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef COMMON +#define COMMON + +#define QUEUE_ID 1 + +extern struct rte_flow_attr attr; +extern struct rte_flow_op_attr ops_attr; + +/** +* Skeleton for creation of a flow rule using template and non template API +* +* @param port_id +* The selected port. +* @param[out] error +* Perform verbose error reporting if not NULL. +* @param[out] flow_template +* The selected API to use. +* @return +* A flow if the rule could be created else return NULL. +*/ +/* Function responsible for creating the flow rule. 8< */ +struct rte_flow * +generate_flow_skeleton (uint16_t port_id,struct rte_flow_error *error,int use_template_api); + +#endif /* COMMON */
examples/flow_filtering/flow_blocks.c deleted +0 -112
112 lines not on this page · raw message
examples/flow_filtering/flow_skeleton.c new file +85 -0
85 lines not on this page · raw message
examples/flow_filtering/main.c +100 -34
255 lines not on this page · raw message
examples/flow_filtering/meson.build +9 -0
@@ -7,6 +7,15 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['argparse'] + sources = files( 'main.c', + 'flow_skeleton.c', + 'snippets/snippet_match_ipv4.c', + 'snippets/snippet_match_gre.c', + 'snippets/snippet_match_mpls.c', ) + +# The code snippets are not utilized. +cflags += '-Wno-unused-function'
examples/flow_filtering/snippets/snippet_match_gre.c new file +54 -0
54 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_gre.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_GRE +#define SNIPPET_MATCH_GRE + +/* Matching GRE Checksum/Key/Sequence +* GRE optional fields (checksum, key and sequence) can be matched using the gre_option item. +* The item requires a GRE item such as gre_key, and its pattern must correspond with the +* c_bit/k_bit/s_bit in the GRE pattern. +*/ + +#define MAX_PATTERN_NUM 5/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_actions (struct rte_flow_action *action); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_patterns (struct rte_flow_item *pattern); + +#endif /* SNIPPET_MATCH_GRE */
examples/flow_filtering/snippets/snippet_match_ipv4.c new file +154 -0
154 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_ipv4.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_IPV4 +#define SNIPPET_MATCH_IPV4 + +/* Match IPV4 flow +* sends packets with matching src and dest ip to selected queue. +*/ + +#define SRC_IP ((0<<24) + (0<<16) + (0<<8) + 0)/* src ip = 0.0.0.0 */ +#define DEST_IP ((192<<24) + (168<<16) + (1<<8) + 1)/* dest ip = 192.168.1.1 */ +#define FULL_MASK 0xffffffff/* full mask */ +#define EMPTY_MASK 0x0/* empty mask */ +#define DEST_MASK 0xffff/* full mask */ + +#define MAX_PATTERN_NUM 3/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +void +snippet_ipv4_flow_create_actions (struct rte_flow_action *action); + +void +snippet_ipv4_flow_create_patterns (struct rte_flow_item *patterns); + +struct rte_flow_template_table * +snippet_ipv4_flow_create_table (uint16_t port_id,struct rte_flow_error *error); + + +#endif /* SNIPPET_MATCH_IPV4 */
examples/flow_filtering/snippets/snippet_match_mpls.c new file +179 -0
179 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_mpls.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_MPLS +#define SNIPPET_MATCH_MPLS + +/* Multiprotocol Label Switching snippet +* In this example we match MPLS tunnel over UDP when in HW steering mode. +* It supports multiple MPLS headers for matching as well as encapsulation/decapsulation. +* The maximum supported MPLS headers is 5. +*/ + +#define MAX_PATTERN_NUM 6/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_mpls_create_actions (struct rte_flow_action *actions); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_mpls_create_patterns (struct rte_flow_item *pattern); + +/* Replace this function with the snippet_*_create_table() function in flow_skeleton.c. */ +static struct rte_flow_template_table * +snippet_mpls_create_table (uint16_t port_id,struct rte_flow_error *error); + +#endif /* SNIPPET_MATCH_MPLS */
Signature · 1 line
2.34.1
Review
Quoted 1 line · On Mon, 30 Sep 2024 19:40:15 +0300 Shani Peretz <[email protected]> wrote:
(quoted diff) +1
-0+ /* Function responsible for creating the flow rule. 8< */
What is with the 8< in the comments in this file.
Seems like something non-standard and trying to be cute emoji but is not helpful
Quoted 7 lines · Stephen Hemminger
Review
Quoted 1 line · On Mon, 30 Sep 2024 19:40:15 +0300 Shani Peretz <[email protected]> wrote:
(quoted diff) +1
-0+ /* Function responsible for creating the flow rule. 8< */What is with the 8< in the comments in this file.
Seems like something non-standard and trying to be cute emoji but is not helpful
8< and >8 are used as markers (cut symbols) for including code in the documentation itself.
PATCH v3 1/1 examples/flow_filtering: introduce use cases snippets
In reply to Shani PeretzThese code snippets demonstrate rule creation using template and non-template APIs.
They include functions that enable developers to create rules. The purpose of providing these snippets is to allow developers to reuse them, thereby saving time and effort during the implementation of flow rules.
The code snippets are categorized based on their usage and can be copied, paste and modified to suit any requirements.
The snippets provided here are kept up to date and are being compiled along with the rest of the examples.
There is a skeleton that demonstrates rule creation using both template and non template APIs.
Developers can change the functions in the skeleton to the corresponding snippet functions with the appropriate suffix and create rules using the snippets themselves for easy testing. Each snippet has the same functions to implement the actions and patterns for the corresponding feature.
--- doc/guides/prog_guide/ethdev/flow_offload.rst | 2 + doc/guides/sample_app_ug/flow_filtering.rst | 295 +++++++----------- examples/flow_filtering/Makefile | 19 +- examples/flow_filtering/common.h | 29 ++ examples/flow_filtering/flow_blocks.c | 112 ------- examples/flow_filtering/flow_skeleton.c | 85 +++++ examples/flow_filtering/main.c | 134 ++++++-- examples/flow_filtering/meson.build | 9 + .../snippets/snippet_match_gre.c | 54 ++++ .../snippets/snippet_match_gre.h | 25 ++ .../snippets/snippet_match_ipv4.c | 154 +++++++++ .../snippets/snippet_match_ipv4.h | 31 ++ .../snippets/snippet_match_mpls.c | 179 +++++++++++ .../snippets/snippet_match_mpls.h | 29 ++ 14 files changed, 820 insertions(+), 337 deletions(-) create mode 100644 examples/flow_filtering/common.h delete mode 100644 examples/flow_filtering/flow_blocks.c create mode 100644 examples/flow_filtering/flow_skeleton.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.c create mode 100644 examples/flow_filtering/snippets/snippet_match_gre.h create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.c create mode 100644 examples/flow_filtering/snippets/snippet_match_ipv4.h create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.c create mode 100644 examples/flow_filtering/snippets/snippet_match_mpls.h
doc/guides/prog_guide/ethdev/flow_offload.rst +2 -0
@@ -3833,6 +3833,8 @@ For example, to configure a RTE_FLOW_TYPE_JUMP action as a miss action for ingre struct rte_flow_error err; rte_flow_group_set_miss_actions(port, 1, &attr, act, &err); +.. _flow_templates: + Flow templates ~~~~~~~~~~~~~~
doc/guides/sample_app_ug/flow_filtering.rst +111 -184
362 lines not on this page · raw message
examples/flow_filtering/Makefile +12 -7
@@ -3,7 +3,9 @@ APP = flow -SRCS-y := main.c +SRCS-y := main.c flow_skeleton.c +subdir := snippets +snippet_objects := $(addprefix build/,$(notdir $(patsubst %.c,%.o,$(wildcard $(subdir)/*.c)))) PKGCONF ?= pkg-config
@@ -21,8 +23,8 @@ static: build/$(APP)-static PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null) CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) -LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) -LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk) +LDFLAGS_SHARED += $(shell $(PKGCONF) --libs libdpdk) +LDFLAGS_STATIC += $(shell $(PKGCONF) --static --libs libdpdk) ifeq ($(MAKECMDGOALS),static) # check for broken pkg-config
@@ -34,11 +36,14 @@ endif CFLAGS += -DALLOW_EXPERIMENTAL_API -build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build - $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) +build/$(APP)-shared: $(SRCS-y) $(snippet_objects) Makefile $(PC_FILE) | build + $(CC) $(CFLAGS) $(SRCS-y) $(snippet_objects) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) -build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build - $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) +build/$(APP)-static: $(SRCS-y) $(snippet_objects) Makefile $(PC_FILE) | build + $(CC) $(CFLAGS) $(SRCS-y) $(snippet_objects) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) + +build/snippet_%.o: $(subdir)/snippet_%.c | build + $(CC) -c $(CFLAGS) -Wno-unused-function $< -o $@ build: @mkdir -p $@
examples/flow_filtering/common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef COMMON +#define COMMON + +#define QUEUE_ID 1 + +extern struct rte_flow_attr attr; +extern struct rte_flow_op_attr ops_attr; + +/** +* Skeleton for creation of a flow rule using template and non template API +* +* @param port_id +* The selected port. +* @param[out] error +* Perform verbose error reporting if not NULL. +* @param[out] flow_template +* The selected API to use. +* @return +* A flow if the rule could be created else return NULL. +*/ +/* Function responsible for creating the flow rule. 8< */ +struct rte_flow * +generate_flow_skeleton (uint16_t port_id,struct rte_flow_error *error,int use_template_api); + +#endif /* COMMON */
examples/flow_filtering/flow_blocks.c deleted +0 -112
112 lines not on this page · raw message
examples/flow_filtering/flow_skeleton.c new file +85 -0
85 lines not on this page · raw message
examples/flow_filtering/main.c +100 -34
255 lines not on this page · raw message
examples/flow_filtering/meson.build +9 -0
@@ -7,6 +7,15 @@ # DPDK instance, use 'make' allow_experimental_apis = true +deps += ['argparse'] + sources = files( 'main.c', + 'flow_skeleton.c', + 'snippets/snippet_match_ipv4.c', + 'snippets/snippet_match_gre.c', + 'snippets/snippet_match_mpls.c', ) + +# The code snippets are not utilized. +cflags += '-Wno-unused-function'
examples/flow_filtering/snippets/snippet_match_gre.c new file +54 -0
54 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_gre.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_GRE +#define SNIPPET_MATCH_GRE + +/* Matching GRE Checksum/Key/Sequence +* GRE optional fields (checksum, key and sequence) can be matched using the gre_option item. +* The item requires a GRE item such as gre_key, and its pattern must correspond with the +* c_bit/k_bit/s_bit in the GRE pattern. +*/ + +#define MAX_PATTERN_NUM 5/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_actions (struct rte_flow_action *action); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_match_gre_create_patterns (struct rte_flow_item *pattern); + +#endif /* SNIPPET_MATCH_GRE */
examples/flow_filtering/snippets/snippet_match_ipv4.c new file +154 -0
154 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_ipv4.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_IPV4 +#define SNIPPET_MATCH_IPV4 + +/* Match IPV4 flow +* sends packets with matching src and dest ip to selected queue. +*/ + +#define SRC_IP ((0<<24) + (0<<16) + (0<<8) + 0)/* src ip = 0.0.0.0 */ +#define DEST_IP ((192<<24) + (168<<16) + (1<<8) + 1)/* dest ip = 192.168.1.1 */ +#define FULL_MASK 0xffffffff/* full mask */ +#define EMPTY_MASK 0x0/* empty mask */ +#define DEST_MASK 0xffff/* full mask */ + +#define MAX_PATTERN_NUM 3/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +void +snippet_ipv4_flow_create_actions (struct rte_flow_action *action); + +void +snippet_ipv4_flow_create_patterns (struct rte_flow_item *patterns); + +struct rte_flow_template_table * +snippet_ipv4_flow_create_table (uint16_t port_id,struct rte_flow_error *error); + + +#endif /* SNIPPET_MATCH_IPV4 */
examples/flow_filtering/snippets/snippet_match_mpls.c new file +179 -0
179 lines not on this page · raw message
examples/flow_filtering/snippets/snippet_match_mpls.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2022 NVIDIA Corporation & Affiliates +*/ + +#ifndef SNIPPET_MATCH_MPLS +#define SNIPPET_MATCH_MPLS + +/* Multiprotocol Label Switching snippet +* In this example we match MPLS tunnel over UDP when in HW steering mode. +* It supports multiple MPLS headers for matching as well as encapsulation/decapsulation. +* The maximum supported MPLS headers is 5. +*/ + +#define MAX_PATTERN_NUM 6/* Maximal number of patterns for this example. */ +#define MAX_ACTION_NUM 2/* Maximal number of actions for this example. */ + +/* Replace this function with the snippet_*_create_actions() function in flow_skeleton.c. */ +static void +snippet_mpls_create_actions (struct rte_flow_action *actions); + +/* Replace this function with the snippet_*_create_patterns() function in flow_skeleton.c. */ +static void +snippet_mpls_create_patterns (struct rte_flow_item *pattern); + +/* Replace this function with the snippet_*_create_table() function in flow_skeleton.c. */ +static struct rte_flow_template_table * +snippet_mpls_create_table (uint16_t port_id,struct rte_flow_error *error); + +#endif /* SNIPPET_MATCH_MPLS */
Signature · 1 line
2.34.1
Quoted 15 lines · On Mon, 30 Sep 2024 22:53:21 +0300 Shani Peretz <[email protected]> wrote:
These code snippets demonstrate rule creation using template and non-template APIs.
They include functions that enable developers to create rules. The purpose of providing these snippets is to allow developers to reuse them, thereby saving time and effort during the implementation of flow rules.The code snippets are categorized based on their usage and can be copied, paste and modified to suit any requirements.
The snippets provided here are kept up to date and are being compiled along with the rest of the examples.There is a skeleton that demonstrates rule creation using both template and non template APIs.
Quoted 6 lines
Developers can change the functions in the skeleton to the corresponding snippet functions with the appropriate suffix and create rules using the snippets themselves for easy testing. Each snippet has the same functions to implement the actions and patterns for the corresponding feature.
Signed-off-by Shani Peretz <[email protected]>
Not sure why the intel-compilation failed but other builds worked.
Thomas Monjalon
Applied14/10/2024 18:47, Stephen Hemminger:
Quoted 23 lines
Quoted 20 lines · On Mon, 30 Sep 2024 22:53:21 +0300 Shani Peretz <[email protected]> wrote:
These code snippets demonstrate rule creation using template and non-template APIs.
They include functions that enable developers to create rules. The purpose of providing these snippets is to allow developers to reuse them, thereby saving time and effort during the implementation of flow rules.The code snippets are categorized based on their usage and can be copied, paste and modified to suit any requirements.
The snippets provided here are kept up to date and are being compiled along with the rest of the examples.There is a skeleton that demonstrates rule creation using both template and non template APIs.
Developers can change the functions in the skeleton to the corresponding snippet functions with the appropriate suffix and create rules using the snippets themselves for easy testing. Each snippet has the same functions to implement the actions and patterns for the corresponding feature.
Quoted 5 lines
Quoted 1 line
Signed-off-by Shani Peretz <[email protected]>Not sure why the intel-compilation failed but other builds worked.
Applied, thanks.