From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 426197D66 for ; Tue, 30 May 2017 14:59:15 +0200 (CEST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2017 05:59:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,418,1491289200"; d="scan'208";a="92868463" Received: from irsmsx107.ger.corp.intel.com ([163.33.3.99]) by orsmga004.jf.intel.com with ESMTP; 30 May 2017 05:59:11 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.133]) by IRSMSX107.ger.corp.intel.com ([169.254.10.129]) with mapi id 14.03.0319.002; Tue, 30 May 2017 13:59:10 +0100 From: "Iremonger, Bernard" To: "Yigit, Ferruh" , "dev@dpdk.org" CC: "Mcnamara, John" , "Tahhan, Maryam" , Adrien Mazarguil Thread-Topic: [RFC v3] flow_classify: add librte_flow_classify library Thread-Index: AQHS1W4dWZz930vGEUaqOTD5k5ByNaIM3bdw Date: Tue, 30 May 2017 12:59:10 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C24E0127F4@IRSMSX108.ger.corp.intel.com> References: <20170518181203.15244-1-ferruh.yigit@intel.com> <20170525154634.44352-1-ferruh.yigit@intel.com> <20170525154634.44352-2-ferruh.yigit@intel.com> In-Reply-To: <20170525154634.44352-2-ferruh.yigit@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjNkMGNkNGUtZmUwYy00ZGJlLWJjZDEtYWI2N2I1YzM3YTM1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IldOWkpKMTdxSERSTFJCcEo5YW8yZFQ0WkdIcGNKZk9Ba3E4YThGWGJPT2M9In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [RFC v3] 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: Tue, 30 May 2017 12:59:17 -0000 Hi Ferruh, > -----Original Message----- > From: Yigit, Ferruh > Sent: Thursday, May 25, 2017 4:47 PM > To: dev@dpdk.org > Cc: Yigit, Ferruh ; Mcnamara, John > ; Tahhan, Maryam > ; Iremonger, Bernard > ; Adrien Mazarguil > > Subject: [RFC v3] flow_classify: add librte_flow_classify library >=20 > Signed-off-by: Ferruh Yigit > --- > Cc: Bernard Iremonger > Cc: Adrien Mazarguil >=20 > RFC v3: > * add create() / destroy() APIs > * query() gets rte_flow_classify object as param > * query() gets one flow at a time >=20 > RFC v2: > * prefer user called functions to callbacks > * use rte_flow to define flows and actions > --- > config/common_base | 5 + > doc/api/doxy-api-index.md | 1 + > doc/api/doxy-api.conf | 1 + > doc/guides/rel_notes/release_17_08.rst | 1 + > lib/Makefile | 2 + > lib/librte_flow_classify/Makefile | 50 +++++++ > lib/librte_flow_classify/rte_flow_classify.c | 153 > +++++++++++++++++++++ > lib/librte_flow_classify/rte_flow_classify.h | 149 > ++++++++++++++++++++ > .../rte_flow_classify_version.map | 9 ++ > mk/rte.app.mk | 1 + > 10 files changed, 372 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.ma= p >=20 > diff --git a/config/common_base b/config/common_base index > 8907bea..3a7e73a 100644 > --- a/config/common_base > +++ b/config/common_base > @@ -651,6 +651,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=3Dn > CONFIG_RTE_LIBRTE_METER=3Dy >=20 > # > +# Compile librte_classify > +# > +CONFIG_RTE_LIBRTE_FLOW_CLASSIFY=3Dy > + > +# > # Compile librte_sched > # > CONFIG_RTE_LIBRTE_SCHED=3Dy > diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index > f5f1f19..d18c2b6 100644 > --- a/doc/api/doxy-api-index.md > +++ b/doc/api/doxy-api-index.md > @@ -98,6 +98,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) >=20 > - **QoS**: > diff --git a/doc/api/doxy-api.conf b/doc/api/doxy-api.conf index > ca9194f..94f3d0f 100644 > --- a/doc/api/doxy-api.conf > +++ b/doc/api/doxy-api.conf > @@ -46,6 +46,7 @@ INPUT =3D 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_08.rst > b/doc/guides/rel_notes/release_17_08.rst > index 74aae10..6362bb2 100644 > --- a/doc/guides/rel_notes/release_17_08.rst > +++ b/doc/guides/rel_notes/release_17_08.rst > @@ -152,6 +152,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) +=3D librte_power > DEPDIRS-librte_power :=3D librte_eal > DIRS-$(CONFIG_RTE_LIBRTE_METER) +=3D librte_meter DEPDIRS- > librte_meter :=3D librte_eal > +DIRS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) +=3D librte_flow_classify > +DEPDIRS-librte_flow_classify :=3D librte_eal librte_ether librte_net > DIRS-$(CONFIG_RTE_LIBRTE_SCHED) +=3D librte_sched DEPDIRS-librte_sched > :=3D librte_eal librte_mempool librte_mbuf librte_net DEPDIRS-librte_sch= ed > +=3D 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 copyrigh= t > +# 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 =3D librte_flow_classify.a > + > +CFLAGS +=3D -O3 > +CFLAGS +=3D $(WERROR_FLAGS) -I$(SRCDIR) > + > +EXPORT_MAP :=3D rte_flow_classify_version.map > + > +LIBABIVER :=3D 1 > + > +# all source are stored in SRCS-y > +SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) :=3D rte_flow_classify.c > + > +# install this header file > +SYMLINK-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY)-include :=3D > +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..7c99c88 > --- /dev/null > +++ b/lib/librte_flow_classify/rte_flow_classify.c > @@ -0,0 +1,153 @@ > +/*- > + * 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 copyrig= ht > + * 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 > + > +LIST_HEAD(rte_flow_classify_list, rte_flow_classify) rte_flow_classify_h= ead > =3D > + LIST_HEAD_INITIALIZER(rte_flow_classify_head); > + > +struct rte_flow_classify { > + LIST_ENTRY(rte_flow_classify) next; > + struct rte_flow_action action; > + uint32_t id; > +}; > + > +static uint32_t unique_id =3D 1; > + > +static struct rte_flow_classify * > +allocate(const struct rte_flow_action *action) { > + > + struct rte_flow_classify *flow_classify =3D NULL; > + > + flow_classify =3D malloc(sizeof(struct rte_flow_classify)); > + > + if (!flow_classify) > + return flow_classify; > + > + flow_classify->action =3D *action; > + flow_classify->id =3D unique_id++; > + > + return flow_classify; > +} > + > +struct rte_flow_classify * > +rte_flow_classify_create(const struct rte_flow_attr *attr, > + const struct rte_flow_item pattern[], > + const struct rte_flow_action *action) { > + struct rte_flow_classify *flow_classify; > + > + if (!attr || !pattern || !action) > + return NULL; > + > + flow_classify =3D allocate(action); > + if (!flow_classify) > + return NULL; > + > + /* parse attr, pattern and action, > + * create mask or hash values etc to match flow easier > + * update flow_classify object to include these data */ > + > + LIST_INSERT_HEAD(&rte_flow_classify_head, flow_classify, next); > + > + return flow_classify; > +} > + > +int > +rte_flow_classify_destroy(struct rte_flow_classify *flow_classify) { > + if (!flow_classify) > + return -EINVAL; > + > + LIST_REMOVE(flow_classify, next); > + > + free(flow_classify); > + > + return 0; > +} > + > +static int > +flow_match(const struct rte_flow_classify *flow_classify, > + const struct rte_mbuf *m) > +{ > + (void)flow_classify; > + (void)m; > + > + return 0; > +} > + > +static int > +action_apply(const struct rte_flow_classify *flow_classify, > + const struct rte_mbuf *m, > + struct rte_flow_classify_stats *stats) { > + switch (flow_classify->action.type) { > + default: > + return -ENOTSUP; > + } > + > + stats->used_space++; > + > + (void)m; > + > + return 0; > +} > + > +int > +rte_flow_classify_query(const struct rte_flow_classify *flow_classify, > + struct rte_mbuf **pkts, > + const uint16_t nb_pkts, > + struct rte_flow_classify_stats *stats) { > + const struct rte_mbuf *m; > + int ret =3D 0; > + uint16_t i; > + > + if (stats->available_space =3D=3D 0) > + return -EINVAL; > + > + stats->used_space =3D 0; > + > + for (i =3D 0; i < nb_pkts; i++) { > + m =3D pkts[i]; > + > + if (!flow_match(flow_classify, m)) { > + ret =3D action_apply(flow_classify, m, stats); > + if (ret) > + break; > + } > + } > + > + return ret; > +} > 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..5440775 > --- /dev/null > +++ b/lib/librte_flow_classify/rte_flow_classify.h > @@ -0,0 +1,149 @@ > +/*- > + * 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 copyrig= ht > + * 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 should define the flow and measurement criteria (action) = for > it. > + * > + * Library doesn't maintain any flow records itself, instead flow > +information is > + * returned to upper layer only for given packets. > + * > + * It is application's responsibility to call rte_flow_classify_query() > + * for group of packets, just after receive them or before transmit them= . > + * Application should provide the flow type interested in, measurement > +to apply > + * that flow in rte_flow_classify_create() API, and should provide > + * rte_flow_classify object and storage to put results in > + * rte_flow_classify_query() API. > + * > + * Usage: > + * - application calls rte_flow_classify_create() to create a rte_flow_= classify > + * object. > + * - application calls rte_flow_classify_query() in a polling manner, > + * preferably after rte_eth_rx_burst(). This will cause the library t= o > + * convert packet information to flow information with some > measurements. > + * - rte_flow_classify object can be destroyed when they are no more > needed via > + * rte_flow_classify_destroy() > + */ > + > +#include > +#include > +#include > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +struct rte_flow_classify; > + > +/** > + * Flow stats > + * > + * For single action an array of stats can be returned by API. > +Technically each > + * packet can return a stat at max. > + * > + * Storage for stats is provided by application, library should know > +available > + * space, and should return the number of used space. > + * > + * stats type is based on what measurement (action) requested by > application. > + * > + */ > +struct rte_flow_classify_stats { > + const unsigned int available_space; > + unsigned int used_space; > + void **stats; > +}; > + > +/** > + * Create a flow classify rule. > + * > + * @param[in] attr > + * Flow rule attributes > + * @param[in] pattern > + * Pattern specification (list terminated by the END pattern item). > + * @param[in] action > + * Associated action > + * > + * @return > + * A valid handle in case of success, NULL otherwise. > + */ > +struct rte_flow_classify * > +rte_flow_classify_create(const struct rte_flow_attr *attr, > + const struct rte_flow_item pattern[], > + const struct rte_flow_action *action); > + > +/** > + * Destroy a flow classify rule. > + * > + * @param flow_classify > + * Flow rule handle to destroy > + * > + * @return > + * 0 on success, a negative errno value otherwise. > + */ > +int > +rte_flow_classify_destroy(struct rte_flow_classify *flow_classify); > + > +/** > + * Get flow classification stats for given packets. > + * > + * @param flow_classify > + * Flow rule object > + * @param pkts > + * Pointer to packets to process > + * @param nb_pkts > + * Number of packets to process > + * @param stats > + * To store stats define by action > + * > + * @return > + * 0 on success, a negative errno value otherwise. > + */ > +int > +rte_flow_classify_query(const struct rte_flow_classify *flow_classify, > + struct rte_mbuf **pkts, > + const uint16_t nb_pkts, > + struct rte_flow_classify_stats *stats); > + > +#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..5aaf664 > --- /dev/null > +++ b/lib/librte_flow_classify/rte_flow_classify_version.map > @@ -0,0 +1,9 @@ > +DPDK_17.08 { > + global: > + > + rte_flow_classify_create; > + rte_flow_classify_destroy; > + rte_flow_classify_query; > + > + local: *; > +}; > diff --git a/mk/rte.app.mk b/mk/rte.app.mk index bcaf1b3..adb6be4 100644 > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -81,6 +81,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_POWER) +=3D - > lrte_power > _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER) +=3D -lrte_timer > _LDLIBS-$(CONFIG_RTE_LIBRTE_EFD) +=3D -lrte_efd > _LDLIBS-$(CONFIG_RTE_LIBRTE_CFGFILE) +=3D -lrte_cfgfile > +_LDLIBS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) +=3D -lrte_flow_classify >=20 > _LDLIBS-y +=3D --whole-archive >=20 > -- > 2.9.3 It is probably useful to add an rte_flow_classify_validate API . Regards, Bernard.