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 B046F5320 for ; Wed, 29 Jan 2014 16:45:19 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 29 Jan 2014 07:46:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,742,1384329600"; d="scan'208";a="474512171" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by orsmga002.jf.intel.com with ESMTP; 29 Jan 2014 07:46:31 -0800 Received: from irsmsx103.ger.corp.intel.com ([169.254.3.84]) by IRSMSX104.ger.corp.intel.com ([169.254.5.244]) with mapi id 14.03.0123.003; Wed, 29 Jan 2014 15:46:30 +0000 From: "Richardson, Bruce" To: Olivier Matz , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 02/11] kvargs: use the new library in pmd_pcap Thread-Index: AQHPHEM3EIuMC4ao9kur8syjWJGL/pqb2e2A Date: Wed, 29 Jan 2014 15:46:30 +0000 Message-ID: <59AF69C657FD0841A61C55336867B5B01A995B38@IRSMSX103.ger.corp.intel.com> References: <1390925204-10800-1-git-send-email-olivier.matz@6wind.com> <1390925204-10800-3-git-send-email-olivier.matz@6wind.com> In-Reply-To: <1390925204-10800-3-git-send-email-olivier.matz@6wind.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: 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] [PATCH 02/11] kvargs: use the new library in pmd_pcap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jan 2014 15:45:20 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Olivier Matz > Sent: Tuesday, January 28, 2014 4:07 PM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH 02/11] kvargs: use the new library in pmd_pcap >=20 > The rte_kvargs library is a reworked copy of rte_eth_pcap_arg_parser, so = it > provides the same service. Therefore we can use it and remove the code of > rte_eth_pcap_arg_parser. >=20 > Signed-off-by: Olivier Matz > --- > lib/librte_pmd_pcap/Makefile | 8 +- > lib/librte_pmd_pcap/rte_eth_pcap.c | 29 +-- > lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.c | 255 --------------------= ------ > lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.h | 71 ------- > 4 files changed, 19 insertions(+), 344 deletions(-) delete mode 100644 > lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.c > delete mode 100644 lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.h >=20 > diff --git a/lib/librte_pmd_pcap/Makefile b/lib/librte_pmd_pcap/Makefile > index 33174c0..741dafc 100644 > --- a/lib/librte_pmd_pcap/Makefile > +++ b/lib/librte_pmd_pcap/Makefile > @@ -1,6 +1,7 @@ > # BSD LICENSE > # > # Copyright(c) 2010-2013 Intel Corporation. All rights reserved. > +# Copyright(c) 2014 6WIND S.A. > # All rights reserved. > # > # Redistribution and use in source and binary forms, with or without > @@ -43,16 +44,15 @@ CFLAGS +=3D $(WERROR_FLAGS) # all source are > stored in SRCS-y # > SRCS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D rte_eth_pcap.c > -SRCS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D rte_eth_pcap_arg_parser.c > - >=20 > # > # Export include files > # > SYMLINK-y-include +=3D rte_eth_pcap.h > -SYMLINK-y-include +=3D rte_eth_pcap_arg_parser.h >=20 > # this lib depends upon: > -DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D lib/librte_mbuf > lib/librte_ether > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D lib/librte_mbuf > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D lib/librte_ether > +DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) +=3D lib/librte_kvargs >=20 > include $(RTE_SDK)/mk/rte.lib.mk > diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c > b/lib/librte_pmd_pcap/rte_eth_pcap.c > index 208e316..e47afcb 100644 > --- a/lib/librte_pmd_pcap/rte_eth_pcap.c > +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c > @@ -2,6 +2,7 @@ > * BSD LICENSE > * > * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. > + * Copyright(c) 2014 6WIND S.A. > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -39,9 +40,9 @@ > #include > #include > #include > +#include >=20 > #include "rte_eth_pcap.h" > -#include "rte_eth_pcap_arg_parser.h" >=20 > #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535 #define > RTE_ETH_PCAP_SNAPLEN 4096 @@ -701,11 +702,11 @@ > rte_pmd_pcap_init(const char *name, const char *params) { > unsigned numa_node, using_dumpers =3D 0; > int ret; > - struct args_dict dict; > + struct rte_kvargs kvlist; > struct rx_pcaps pcaps; > struct tx_pcaps dumpers; >=20 > - rte_eth_pcap_init_args_dict(&dict); > + rte_kvargs_init(&kvlist); >=20 > numa_node =3D rte_socket_id(); >=20 > @@ -713,16 +714,16 @@ rte_pmd_pcap_init(const char *name, const > char *params) > start_cycles =3D rte_get_timer_cycles(); > hz =3D rte_get_timer_hz(); >=20 > - if (rte_eth_pcap_parse_args(&dict, name, params, > valid_arguments) < 0) > + if (rte_kvargs_parse(&kvlist, name, params, valid_arguments) < 0) > return -1; >=20 > /* > * If iface argument is passed we open the NICs and use them for > * reading / writing > */ > - if (rte_eth_pcap_num_of_args(&dict, ETH_PCAP_IFACE_ARG) =3D=3D 1) > { > + if (rte_kvargs_count(&kvlist, ETH_PCAP_IFACE_ARG) =3D=3D 1) { >=20 > - ret =3D rte_eth_pcap_post_process_arguments(&dict, > ETH_PCAP_IFACE_ARG, > + ret =3D rte_kvargs_process(&kvlist, ETH_PCAP_IFACE_ARG, > &open_rx_tx_iface, &pcaps.pcaps[0]); > if (ret < 0) > return -1; > @@ -734,13 +735,13 @@ rte_pmd_pcap_init(const char *name, const > char *params) > * We check whether we want to open a RX stream from a real NIC > or a > * pcap file > */ > - if ((pcaps.num_of_rx =3D rte_eth_pcap_num_of_args(&dict, > ETH_PCAP_RX_PCAP_ARG))) { > - ret =3D rte_eth_pcap_post_process_arguments(&dict, > ETH_PCAP_RX_PCAP_ARG, > + if ((pcaps.num_of_rx =3D rte_kvargs_count(&kvlist, > ETH_PCAP_RX_PCAP_ARG))) { > + ret =3D rte_kvargs_process(&kvlist, > ETH_PCAP_RX_PCAP_ARG, > &open_rx_pcap, &pcaps); > } else { > - pcaps.num_of_rx =3D rte_eth_pcap_num_of_args(&dict, > + pcaps.num_of_rx =3D rte_kvargs_count(&kvlist, > ETH_PCAP_RX_IFACE_ARG); > - ret =3D rte_eth_pcap_post_process_arguments(&dict, > ETH_PCAP_RX_IFACE_ARG, > + ret =3D rte_kvargs_process(&kvlist, > ETH_PCAP_RX_IFACE_ARG, > &open_rx_iface, &pcaps); > } >=20 > @@ -751,15 +752,15 @@ rte_pmd_pcap_init(const char *name, const > char *params) > * We check whether we want to open a TX stream to a real NIC or a > * pcap file > */ > - if ((dumpers.num_of_tx =3D rte_eth_pcap_num_of_args(&dict, > + if ((dumpers.num_of_tx =3D rte_kvargs_count(&kvlist, > ETH_PCAP_TX_PCAP_ARG))) { > - ret =3D rte_eth_pcap_post_process_arguments(&dict, > ETH_PCAP_TX_PCAP_ARG, > + ret =3D rte_kvargs_process(&kvlist, > ETH_PCAP_TX_PCAP_ARG, > &open_tx_pcap, &dumpers); > using_dumpers =3D 1; > } else { > - dumpers.num_of_tx =3D rte_eth_pcap_num_of_args(&dict, > + dumpers.num_of_tx =3D rte_kvargs_count(&kvlist, > ETH_PCAP_TX_IFACE_ARG); > - ret =3D rte_eth_pcap_post_process_arguments(&dict, > ETH_PCAP_TX_IFACE_ARG, > + ret =3D rte_kvargs_process(&kvlist, > ETH_PCAP_TX_IFACE_ARG, > &open_tx_iface, &dumpers); > } >=20 > diff --git a/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.c > b/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.c > deleted file mode 100644 > index c881f3b..0000000 > --- a/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.c > +++ /dev/null > @@ -1,255 +0,0 @@ > -/*- > - * BSD LICENSE > - * > - * Copyright(c) 2010-2013 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 > -#include > -#include > - > -#include > -#include > -#include > - > -#include "rte_eth_pcap_arg_parser.h" > - > -/* > - * Initializes a non NULL dictionary reference to be used later on. > - */ > -inline int > -rte_eth_pcap_init_args_dict(struct args_dict *dict) -{ > - dict->index =3D 0; > - dict->size =3D RTE_ETH_PCAP_ARG_PARSER_MAX_ARGS; > - memset(dict->pairs, 0, dict->size); > - return 0; > -} > - > -/* > - * Adds a key-value pair to a given non-NULL dictionary reference. > - * The final key will be the name+key. > - * Returns error in case the dictionary is full or if the key is duplica= ted. > - */ > -inline int > -rte_eth_pcap_add_pair_to_dict(struct args_dict *dict, > - char *key, > - char *val) > -{ > - unsigned i; > - struct key_value* entry; > - > - /* is the dictionary full? */ > - if (dict->index >=3D dict->size) { > - RTE_LOG(ERR, PMD, "Couldn't add %s, dictionary is full\n", > key); > - return -1; > - } > - > - /* Check if the key is duplicated */ > - for (i =3D 0; i < dict->index; i++) { > - entry =3D &dict->pairs[i]; > - if (strcmp(entry->key, key) =3D=3D 0) { > - RTE_LOG(ERR, PMD, "Couldn't add %s, duplicated > key\n", key); > - return -1; > - } > - } > - > - entry =3D &dict->pairs[dict->index]; > - entry->key =3D key; > - entry->value =3D val; > - dict->index++; > - return 0; > - > -} > - > -#define RTE_ETH_PCAP_PAIRS_DELIM ';' > -#define RTE_ETH_PCAP_KEY_VALUE_DELIM '=3D' > -/* > - * Receives a string with a list of arguments following the pattern > - * key=3Dvalue;key=3Dvalue;... and inserts them into the non NULL dictio= nary. > - * strtok is used so the params string will be copied to be modified. > - */ > -inline int > -rte_eth_pcap_tokenize_args(struct args_dict *dict, > - const char *name, > - const char *params) > -{ > - int i; > - char *args; > - char *pairs[RTE_ETH_PCAP_ARG_PARSER_MAX_ARGS]; > - char *pair[2]; > - int num_of_pairs; > - > - /* If params are empty, nothing to do */ > - if (params =3D=3D NULL || params[0] =3D=3D 0) { > - RTE_LOG(ERR, PMD, "Couldn't parse %s device, empty > arguments\n", name); > - return -1; > - } > - > - /* Copy the const char *params to a modifiable string > - * to pass to rte_strsplit > - */ > - args =3D strdup(params); > - if(args =3D=3D NULL){ > - RTE_LOG(ERR, PMD, "Couldn't parse %s device \n", name); > - return -1; > - } > - > - num_of_pairs =3D rte_strsplit(args, strnlen(args, MAX_ARG_STRLEN), > pairs, > - RTE_ETH_PCAP_ARG_PARSER_MAX_ARGS, > RTE_ETH_PCAP_PAIRS_DELIM); > - > - for (i =3D 0; i < num_of_pairs; i++) { > - pair[0] =3D NULL; > - pair[1] =3D NULL; > - > - rte_strsplit(pairs[i], strnlen(pairs[i], MAX_ARG_STRLEN), > pair, 2, > - RTE_ETH_PCAP_KEY_VALUE_DELIM); > - > - if (pair[0] =3D=3D NULL || pair[1] =3D=3D NULL || pair[0][0] =3D=3D 0 > - || pair[1][0] =3D=3D 0) { > - RTE_LOG(ERR, PMD, > - "Couldn't parse %s device, wrong key > or value \n", name); > - goto error; > - } > - > - if (rte_eth_pcap_add_pair_to_dict(dict, pair[0], pair[1]) < 0) > - goto error; > - } > - return 0; > - > -error: > - rte_free(args); > - return -1; > -} > - > -/* > - * Determines whether a key is valid or not by looking > - * into a list of valid keys. > - */ > -static inline int > -is_valid_key(const char *valid[], > - struct key_value *pair) > -{ > - const char **valid_ptr; > - > - for (valid_ptr =3D valid; *valid_ptr !=3D NULL; valid_ptr++) > - if (strstr(pair->key, *valid_ptr) !=3D NULL) > - return 1; > - return 0; > -} > - > -/* > - * Determines whether all keys are valid or not by looking > - * into a list of valid keys. > - */ > -static inline int > -check_for_valid_keys(struct args_dict *dict, > - const char *valid[]) > -{ > - unsigned k_index, ret; > - struct key_value *pair; > - > - for (k_index =3D 0; k_index < dict->index; k_index++) { > - pair =3D &dict->pairs[k_index]; > - ret =3D is_valid_key(valid, pair); > - if (!ret) { > - RTE_LOG(ERR, PMD, > - "Error parsing device, invalid key > %s\n", pair->key); > - return -1; > - } > - } > - return 0; > -} > - > -/* > - * Returns the number of times a given arg_name exists on a dictionary. > - * E.g. given a dict =3D { rx0 =3D 0, rx1 =3D 1, tx0 =3D 2 } the number = of args for > - * arg "rx" will be 2. > - */ > -inline unsigned > -rte_eth_pcap_num_of_args(struct args_dict *dict, const char *arg_name) > -{ > - unsigned k_index; > - struct key_value *pair; > - unsigned num_of_keys; > - > - num_of_keys =3D 0; > - for (k_index =3D 0; k_index < dict->index; k_index++) { > - pair =3D &dict->pairs[k_index]; > - if (strcmp(pair->key, arg_name) =3D=3D 0) > - num_of_keys++; > - } > - > - return num_of_keys; > -} > - > -/* > - * Calls the handler function for a given arg_name passing the > - * value on the dictionary for that key and a given extra argument. > - */ > -inline int > -rte_eth_pcap_post_process_arguments(struct args_dict *dict, > - const char *arg_name, > - arg_handler_t handler, > - void *extra_args) > -{ > - unsigned k_index; > - struct key_value *pair; > - > - for (k_index =3D 0; k_index < dict->index; k_index++) { > - pair =3D &dict->pairs[k_index]; > - if (strstr(pair->key, arg_name) !=3D NULL) { > - if ((*handler)(pair->value, extra_args) < 0) > - return -1; > - } > - } > - return 0; > -} > - > -/* > - * Parses the arguments "key=3Dvalue;key=3Dvalue;..." string and returns > - * a simple dictionary implementation containing these pairs. It also > - * checks if only valid keys were used. > - */ > -inline int > -rte_eth_pcap_parse_args(struct args_dict *dict, > - const char *name, > - const char *args, > - const char *valids[]) > -{ > - > - int ret; > - > - ret =3D rte_eth_pcap_tokenize_args(dict, name, args); > - if (ret < 0) > - return ret; > - > - return check_for_valid_keys(dict, valids); > -} > - > diff --git a/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.h > b/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.h > deleted file mode 100644 > index 47eb3a0..0000000 > --- a/lib/librte_pmd_pcap/rte_eth_pcap_arg_parser.h > +++ /dev/null > @@ -1,71 +0,0 @@ > -/*- > - * BSD LICENSE > - * > - * Copyright(c) 2010-2013 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_ETH_ARG_PARSER_H_ > -#define _RTE_ETH_ARG_PARSER_H_ > - > -#ifdef __cplusplus > -extern "C" { > -#endif > - > -#define RTE_ETH_PCAP_ARG_PARSER_MAX_ARGS 32 > - > -typedef int (*arg_handler_t)(char*, void*); > - > -struct key_value { > - char *key; > - char *value; > -}; > - > -struct args_dict { > - unsigned index; > - size_t size; > - struct key_value pairs[RTE_ETH_PCAP_ARG_PARSER_MAX_ARGS]; > -}; > - > -int rte_eth_pcap_tokenize_args(struct args_dict *dict, const char *name, > - const char *args); > -int rte_eth_pcap_init_args_dict(struct args_dict *dict); -int > rte_eth_pcap_add_pair_to_dict(struct args_dict *dict, char *key, char > *val); -int rte_eth_pcap_parse_args(struct args_dict *dict, const char* > name, > - const char *args, const char *valids[]); > -int rte_eth_pcap_post_process_arguments(struct args_dict *dict, > - const char *arg_name, arg_handler_t handler, void > *extra_args); > -unsigned rte_eth_pcap_num_of_args(struct args_dict *dict, const char > *key); -void rte_eth_pcap_free_dict(struct args_dict *dict); > - > -#ifdef __cplusplus > -} > -#endif > - > -#endif > -- > 1.8.4.rc3 Acked-by: Bruce Richardson