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 02D618DA4 for ; Fri, 15 Jan 2016 15:47:58 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 15 Jan 2016 06:47:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,299,1449561600"; d="scan'208";a="29939459" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by fmsmga004.fm.intel.com with ESMTP; 15 Jan 2016 06:47:58 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.104]) by IRSMSX101.ger.corp.intel.com ([169.254.1.134]) with mapi id 14.03.0248.002; Fri, 15 Jan 2016 14:47:56 +0000 From: "Ananyev, Konstantin" To: "Tan, Jianfeng" , "dev@dpdk.org" Thread-Topic: [PATCH v2 12/12] examples/l3fwd: add option to parse ptype Thread-Index: AQHRT5LIaPUSmkxXbEueg+ZMmP7c+p78ptxw Date: Fri, 15 Jan 2016 14:47:55 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836AE6144@irsmsx105.ger.corp.intel.com> References: <1451544799-70776-1-git-send-email-jianfeng.tan@intel.com> <1452836759-63540-1-git-send-email-jianfeng.tan@intel.com> <1452836759-63540-13-git-send-email-jianfeng.tan@intel.com> In-Reply-To: <1452836759-63540-13-git-send-email-jianfeng.tan@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2 12/12] examples/l3fwd: add option to parse ptype 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: Fri, 15 Jan 2016 14:47:59 -0000 Hi Jianfeng, > -----Original Message----- > From: Tan, Jianfeng > Sent: Friday, January 15, 2016 5:46 AM > To: dev@dpdk.org > Cc: Zhang, Helin; Ananyev, Konstantin; Tan, Jianfeng > Subject: [PATCH v2 12/12] examples/l3fwd: add option to parse ptype >=20 > As a example to use ptype info, l3fwd needs firstly to use > rte_eth_dev_get_ptype_info() API to check if device and/or PMD driver wil= l > parse and fill the needed packet type. If not, use the newly added option= , > --parse-ptype, to analyze it in the callback softly. >=20 > Signed-off-by: Jianfeng Tan > --- > examples/l3fwd/main.c | 91 +++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 91 insertions(+) >=20 > diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c > index 5b0c2dd..3c6e1b7 100644 > --- a/examples/l3fwd/main.c > +++ b/examples/l3fwd/main.c > @@ -174,6 +174,7 @@ static __m128i val_eth[RTE_MAX_ETHPORTS]; > static uint32_t enabled_port_mask =3D 0; > static int promiscuous_on =3D 0; /**< Ports set in promiscuous mode off = by default. */ > static int numa_on =3D 1; /**< NUMA is enabled by default. */ > +static int parse_ptype =3D 0; /**< parse packet type using rx callback *= / >=20 > #if (APP_LOOKUP_METHOD =3D=3D APP_LOOKUP_EXACT_MATCH) > static int ipv6 =3D 0; /**< ipv6 is false by default. */ > @@ -2022,6 +2023,7 @@ parse_eth_dest(const char *optarg) > #define CMD_LINE_OPT_IPV6 "ipv6" > #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" > #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num" > +#define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" >=20 > /* Parse the argument given in the command line of the application */ > static int > @@ -2038,6 +2040,7 @@ parse_args(int argc, char **argv) > {CMD_LINE_OPT_IPV6, 0, 0, 0}, > {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0}, > {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0}, > + {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0}, > {NULL, 0, 0, 0} > }; >=20 > @@ -2125,6 +2128,13 @@ parse_args(int argc, char **argv) > } > } > #endif > + if (!strncmp(lgopts[option_index].name, > + CMD_LINE_OPT_PARSE_PTYPE, > + sizeof(CMD_LINE_OPT_PARSE_PTYPE))) { > + printf("soft parse-ptype is enabled \n"); > + parse_ptype =3D 1; > + } > + > break; >=20 > default: > @@ -2559,6 +2569,74 @@ check_all_ports_link_status(uint8_t port_num, uint= 32_t port_mask) > } > } >=20 > +static int > +check_packet_type_ok(int portid) > +{ > + int i, ret; > + uint32_t *ptypes; > + int ptype_l3_ipv4 =3D 0, ptype_l3_ipv6 =3D 0; > + > + ret =3D rte_eth_dev_get_ptype_info(portid, RTE_PTYPE_L3_MASK, NULL, 0); > + if (ret <=3D 0) > + return 0; > + ptypes =3D malloc(sizeof(uint32_t) * ret); > + rte_eth_dev_get_ptype_info(portid, RTE_PTYPE_L3_MASK, > + ptypes, ret); > + for (i =3D 0; i < ret; ++i) { > + if (ptypes[i] & RTE_PTYPE_L3_IPV4) > + ptype_l3_ipv4 =3D 1; > + if (ptypes[i] & RTE_PTYPE_L3_IPV6) > + ptype_l3_ipv6 =3D 1; > + } I think you forgot to do: free(ptypes); Also, formally speaking malloc can fail here, so probably need to check mal= loc() return value, or just allocate ptypes[] on the stack - would be easier. > + > + if (ptype_l3_ipv4 =3D=3D 0) > + printf("port %d cannot parse RTE_PTYPE_L3_IPV4\n", portid); > + > + if (ptype_l3_ipv6 =3D=3D 0) > + printf("port %d cannot parse RTE_PTYPE_L3_IPV6\n", portid); > + > + if (ptype_l3_ipv4 && ptype_l3_ipv6) > + return 1; > + > + return 0; > +} > +static inline void > +parse_packet_type(struct rte_mbuf *m) > +{ > + struct ether_hdr *eth_hdr; > + uint32_t packet_type =3D 0; > + uint16_t ethertype; > + > + eth_hdr =3D rte_pktmbuf_mtod(m, struct ether_hdr *); > + ethertype =3D rte_be_to_cpu_16(eth_hdr->ether_type); > + switch (ethertype) { > + case ETHER_TYPE_IPv4: > + packet_type |=3D RTE_PTYPE_L3_IPV4_EXT_UNKNOWN; > + break; > + case ETHER_TYPE_IPv6: > + packet_type |=3D RTE_PTYPE_L3_IPV6_EXT_UNKNOWN; > + break; That's enough for LPM, for EM, don't we need to be sure there are no extens= ions in the IP header?=20 Konstantin > + default: > + break; > + } > + > + m->packet_type |=3D packet_type; > +} > + > +static uint16_t > +cb_parse_packet_type(uint8_t port __rte_unused, > + uint16_t queue __rte_unused, > + struct rte_mbuf *pkts[], > + uint16_t nb_pkts, > + uint16_t max_pkts __rte_unused, > + void *user_param __rte_unused) > +{ > + unsigned i; > + > + for (i =3D 0; i < nb_pkts; ++i) > + parse_packet_type(pkts[i]); > +} > + > int > main(int argc, char **argv) > { > @@ -2672,6 +2750,11 @@ main(int argc, char **argv) > rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=3D%d, " > "port=3D%d\n", ret, portid); >=20 > + if (!check_packet_type_ok(portid) && !parse_ptype) > + rte_exit(EXIT_FAILURE, > + "port %d cannot parse packet type, please add --%s\n", > + portid, CMD_LINE_OPT_PARSE_PTYPE); > + > qconf =3D &lcore_conf[lcore_id]; > qconf->tx_queue_id[portid] =3D queueid; > queueid++; > @@ -2705,6 +2788,14 @@ main(int argc, char **argv) > if (ret < 0) > rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=3D%d," > "port=3D%d\n", ret, portid); > + if (parse_ptype && > + !rte_eth_add_rx_callback(portid, queueid, > + cb_parse_packet_type, > + NULL)) > + rte_exit(EXIT_FAILURE, > + "Failed to add rx callback: port=3D%d\n", > + portid); > + > } > } >=20 > -- > 2.1.4