From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id E91FEDE0 for ; Thu, 20 Apr 2017 20:54:53 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Apr 2017 11:54:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,225,1488873600"; d="scan'208";a="79289196" Received: from sivswdev02.ir.intel.com ([10.237.217.46]) by orsmga004.jf.intel.com with ESMTP; 20 Apr 2017 11:54:52 -0700 From: Ferruh Yigit To: dev@dpdk.org Cc: Ferruh Yigit , John McNamara , Maryam Tahhan Date: Thu, 20 Apr 2017 19:54:48 +0100 Message-Id: <20170420185448.19162-2-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170420185448.19162-1-ferruh.yigit@intel.com> References: <20170420185448.19162-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [RFC 17.08] flow_classify: add librte_flow_classify library X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Apr 2017 18:54:54 -0000 Signed-off-by: Ferruh Yigit --- config/common_base | 5 + doc/api/doxy-api-index.md | 1 + doc/api/doxy-api.conf | 1 + doc/guides/rel_notes/release_17_05.rst | 1 + lib/Makefile | 2 + lib/librte_flow_classify/Makefile | 50 +++++ lib/librte_flow_classify/rte_flow_classify.c | 34 ++++ lib/librte_flow_classify/rte_flow_classify.h | 202 +++++++++++++++++++++ .../rte_flow_classify_version.map | 10 + 9 files changed, 306 insertions(+) create mode 100644 lib/librte_flow_classify/Makefile create mode 100644 lib/librte_flow_classify/rte_flow_classify.c create mode 100644 lib/librte_flow_classify/rte_flow_classify.h create mode 100644 lib/librte_flow_classify/rte_flow_classify_version.map diff --git a/config/common_base b/config/common_base index 412ec3f..c05a411 100644 --- a/config/common_base +++ b/config/common_base @@ -634,6 +634,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n CONFIG_RTE_LIBRTE_METER=y # +# Compile librte_classify +# +CONFIG_RTE_LIBRTE_FLOW_CLASSIFY=y + +# # Compile librte_sched # CONFIG_RTE_LIBRTE_SCHED=y diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index a26846a..7f0be03 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -97,6 +97,7 @@ There are many libraries, so their headers may be grouped by topics: [LPM IPv4 route] (@ref rte_lpm.h), [LPM IPv6 route] (@ref rte_lpm6.h), [ACL] (@ref rte_acl.h), + [flow_classify] (@ref rte_flow_classify.h), [EFD] (@ref rte_efd.h) - **QoS**: diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index 97fb551..9eec10c 100644 --- a/doc/api/doxy-api.conf +++ b/doc/api/doxy-api.conf @@ -45,6 +45,7 @@ INPUT = doc/api/doxy-api-index.md \ lib/librte_efd \ lib/librte_ether \ lib/librte_eventdev \ + lib/librte_flow_classify \ lib/librte_hash \ lib/librte_ip_frag \ lib/librte_jobstats \ diff --git a/doc/guides/rel_notes/release_17_05.rst b/doc/guides/rel_notes/release_17_05.rst index 25e7144..89520e4 100644 --- a/doc/guides/rel_notes/release_17_05.rst +++ b/doc/guides/rel_notes/release_17_05.rst @@ -507,6 +507,7 @@ The libraries prepended with a plus sign were incremented in this version. librte_distributor.so.1 + librte_eal.so.4 librte_ethdev.so.6 + librte_flow_classify.so.1 librte_hash.so.2 librte_ip_frag.so.1 librte_jobstats.so.1 diff --git a/lib/Makefile b/lib/Makefile index 07e1fd0..e63cd61 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -80,6 +80,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_POWER) += librte_power DEPDIRS-librte_power := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_METER) += librte_meter DEPDIRS-librte_meter := librte_eal +DIRS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) += librte_flow_classify +DEPDIRS-librte_flow_classify := librte_eal librte_ether librte_net DIRS-$(CONFIG_RTE_LIBRTE_SCHED) += librte_sched DEPDIRS-librte_sched := librte_eal librte_mempool librte_mbuf librte_net DEPDIRS-librte_sched += librte_timer diff --git a/lib/librte_flow_classify/Makefile b/lib/librte_flow_classify/Makefile new file mode 100644 index 0000000..c57e9a3 --- /dev/null +++ b/lib/librte_flow_classify/Makefile @@ -0,0 +1,50 @@ +# BSD LICENSE +# +# Copyright(c) 2017 Intel Corporation. All rights reserved. +# All rights reserved. +# +# 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 Intel Corporation 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. + +include $(RTE_SDK)/mk/rte.vars.mk + +# library name +LIB = librte_flow_classify.a + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) + +EXPORT_MAP := rte_flow_classify_version.map + +LIBABIVER := 1 + +# all source are stored in SRCS-y +SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) := rte_flow_classify.c + +# install this header file +SYMLINK-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY)-include := rte_flow_classify.h + +include $(RTE_SDK)/mk/rte.lib.mk diff --git a/lib/librte_flow_classify/rte_flow_classify.c b/lib/librte_flow_classify/rte_flow_classify.c new file mode 100644 index 0000000..e6f724e --- /dev/null +++ b/lib/librte_flow_classify/rte_flow_classify.c @@ -0,0 +1,34 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * 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 Intel Corporation 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. + */ + +#include "rte_flow_classify.h" diff --git a/lib/librte_flow_classify/rte_flow_classify.h b/lib/librte_flow_classify/rte_flow_classify.h new file mode 100644 index 0000000..a52394f --- /dev/null +++ b/lib/librte_flow_classify/rte_flow_classify.h @@ -0,0 +1,202 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * 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 Intel Corporation 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. + */ + +#ifndef _RTE_FLOW_CLASSIFY_H_ +#define _RTE_FLOW_CLASSIFY_H_ + +/** + * @file + * + * RTE Flow Classify Library + * + * This library provides flow record information with some measured properties. + * + * Application can select variety of flow types based on various flow keys. + * + * Library only maintains flow records between rte_flow_classify_stats_get() + * calls and with a maximum limit. + * + * Provided flow record will be linked list rte_flow_classify_stat_xxx + * structure. + * + * Library is responsible from allocating and freeing memory for flow record + * table. Previous table freed with next rte_flow_classify_stats_get() call and + * all tables are freed with rte_flow_classify_type_reset() or + * rte_flow_classify_type_set(x, 0). Memory for table allocated on the fly while + * creating records. + * + * A rte_flow_classify_type_set() with a valid type will register Rx/Tx + * callbacks and start filling flow record table. + * With rte_flow_classify_stats_get(), pointer sent to caller and meanwhile + * library continues collecting records. + * + * Usage: + * - application calls rte_flow_classify_type_set() for a device + * - library creates Rx/Tx callbacks for packets and start filling flow table + * for that type of flow (currently only one flow type supported) + * - application calls rte_flow_classify_stats_get() to get pointer to linked + * listed flow table. Library assigns this pointer to another value and keeps + * collecting flow data. In next rte_flow_classify_stats_get(), library first + * free the previous table, and pass current table to the application, keep + * collecting data. + * - application calls rte_flow_classify_type_reset(), library unregisters the + * callbacks and free all flow table data. + * + */ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Types of classification supported. + */ +enum rte_flow_classify_type { + RTE_FLOW_CLASSIFY_TYPE_GENERIC = (1 << 0), + RTE_FLOW_CLASSIFY_TYPE_MAX, +}; + +#define RTE_FLOW_CLASSIFY_TYPE_MASK = (((RTE_FLOW_CLASSIFY_TYPE_MAX - 1) << 1) - 1) + +/** + * Global configuration struct + */ +struct rte_flow_classify_config { + uint32_t type; /* bitwise enum rte_flow_classify_type values */ + void *flow_table_prev; + uint32_t flow_table_prev_item_count; + void *flow_table_current; + uint32_t flow_table_current_item_count; +} rte_flow_classify_config[RTE_MAX_ETHPORTS]; + +#define RTE_FLOW_CLASSIFY_STAT_MAX UINT16_MAX + +/** + * Classification stats data struct + */ +struct rte_flow_classify_stat_generic { + struct rte_flow_classify_stat_generic *next; + uint32_t id; + uint64_t timestamp; + + struct ether_addr src_mac; + struct ether_addr dst_mac; + uint32_t src_ipv4; + uint32_t dst_ipv4; + uint8_t l3_protocol_id; + uint16_t src_port; + uint16_t dst_port; + + uint64_t packet_count; + uint64_t packet_size; /* bytes */ +}; + +/** +* Get flow types to flow_classify +* +* @param port_id +* Ethernet device port id to get classification. +* @param type +* bitmap of enum rte_flow_classify_type values enabled for classification +* @return +* - (0) if successful. +* - (-EINVAL) on failure. +*/ +int +rte_flow_classify_type_get(uint8_t port_id, uint32_t *type); + +/** +* Set flow types to flow_classify +* +* If the type list is zero, no classification done. +* +* @param port_id +* Ethernet device port_id to set classification. +* @param type +* bitmap of enum rte_flow_classify_type values to enable classification +* @return +* - (0) if successful. +* - (-EINVAL) on failure. +*/ +int +rte_flow_classify_type_set(uint8_t port_id, uint32_t type); + +/** +* Disable flow classification for device +* +* @param port_id +* Ethernet device port id to reset classification. +* @return +* - (0) if successful. +* - (-EINVAL) on failure. +*/ +int +rte_flow_classify_type_reset(uint8_t port_id); + +/** +* Get classified results +* +* @param port_id +* Ethernet device port id to get flow stats +* @param stats +* void * to linked list flow data +* @return +* - (0) if successful. +* - (-EINVAL) on failure. +*/ +int +rte_flow_classify_stats_get(uint8_t port_id, void *stats); + +/** +* Reset classified results +* +* @param port_id +* Ethernet device port id to reset flow stats +* @return +* - (0) if successful. +* - (-EINVAL) on failure. +*/ +int +rte_flow_classify_stats_reset(uint8_t port_id); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_FLOW_CLASSIFY_H_ */ diff --git a/lib/librte_flow_classify/rte_flow_classify_version.map b/lib/librte_flow_classify/rte_flow_classify_version.map new file mode 100644 index 0000000..0f396ae --- /dev/null +++ b/lib/librte_flow_classify/rte_flow_classify_version.map @@ -0,0 +1,10 @@ +DPDK_17.08 { + global: + + rte_flow_classify_stats_get; + rte_flow_classify_type_get; + rte_flow_classify_type_reset; + rte_flow_classify_type_set; + + local: *; +}; -- 2.9.3