From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 455C469C3 for ; Thu, 9 Feb 2017 07:34:12 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 08 Feb 2017 22:34:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,349,1484035200"; d="scan'208";a="1105001118" Received: from marvin-s2600gz.sh.intel.com ([10.239.129.187]) by fmsmga001.fm.intel.com with ESMTP; 08 Feb 2017 22:34:10 -0800 From: Marvin Liu To: dev@dpdk.org Cc: Jianfeng Tan , Yong Liu Date: Thu, 9 Feb 2017 22:25:33 +0800 Message-Id: <1486650334-34300-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486650334-34300-1-git-send-email-yong.liu@intel.com> References: <1485156509-4919-1-git-send-email-yong.liu@intel.com> <1486650334-34300-1-git-send-email-yong.liu@intel.com> Subject: [dpdk-dev] [PATCH v3 2/3] examples/ip_fragmentation: add parse-ptype option 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, 09 Feb 2017 06:34:13 -0000 Add new option parse-ptype in this sample in case of pmd driver not provide packet type info. If this option enabled, packet type will be analyzed in Rx callback function. Signed-off-by: Jianfeng Tan Signed-off-by: Yong Liu diff --git a/examples/ip_fragmentation/main.c b/examples/ip_fragmentation/main.c index e1e32c6..df0e73c 100644 --- a/examples/ip_fragmentation/main.c +++ b/examples/ip_fragmentation/main.c @@ -143,6 +143,10 @@ static int rx_queue_per_lcore = 1; +#define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" +/* Parse packet type using rx callback and disabled by default */ +static int parse_ptype; + #define MBUF_TABLE_SIZE (2 * MAX(MAX_PKT_BURST, MAX_PACKET_FRAG)) struct mbuf_table { @@ -488,7 +492,9 @@ struct rte_lpm6_config lpm6_config = { { printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n" " -p PORTMASK: hexadecimal bitmask of ports to configure\n" - " -q NQ: number of queue (=ports) per lcore (default is 1)\n", + " -q NQ: number of queue (=ports) per lcore (default is 1)\n" + " --"CMD_LINE_OPT_PARSE_PTYPE": Set to use software to " + "analyze packet type\n", prgname); } @@ -536,6 +542,7 @@ struct rte_lpm6_config lpm6_config = { int option_index; char *prgname = argv[0]; static struct option lgopts[] = { + {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0}, {NULL, 0, 0, 0} }; @@ -567,8 +574,13 @@ struct rte_lpm6_config lpm6_config = { /* long options */ case 0: - print_usage(prgname); - return -1; + 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 = 1; + } + break; default: print_usage(prgname); @@ -598,6 +610,74 @@ struct rte_lpm6_config lpm6_config = { printf("%s%s", name, buf); } +static inline void +parse_ptype_one(struct rte_mbuf *m) +{ + struct ether_hdr *eth_hdr; + uint32_t packet_type = RTE_PTYPE_UNKNOWN; + uint16_t ether_type; + + eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *); + ether_type = eth_hdr->ether_type; + if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) + packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN; + else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) + packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN; + + m->packet_type = packet_type; +} + +static uint16_t +cb_parse_ptype(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 int i; + + for (i = 0; i < nb_pkts; ++i) + parse_ptype_one(pkts[i]); + + return nb_pkts; +} + +static int +add_cb_parse_ptype(uint8_t portid, uint16_t queueid) +{ + printf("Port %d: softly parse packet type info\n", portid); + if (rte_eth_add_rx_callback(portid, queueid, cb_parse_ptype, NULL)) + return 0; + + printf("Failed to add rx callback: port=%d\n", portid); + return -1; +} + +static int check_ptype(uint8_t portid) +{ + int i, ret; + int ptype_l3_ipv4 = 0; + int ptype_l3_ipv6 = 0; + uint32_t ptype_mask = RTE_PTYPE_L3_MASK; + + ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0); + if (ret <= 0) + return 0; + + uint32_t ptypes[ret]; + ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret); + for (i = 0; i < ret; ++i) { + if (ptypes[i] & RTE_PTYPE_L3_IPV4) + ptype_l3_ipv4 = 1; + if (ptypes[i] & RTE_PTYPE_L3_IPV6) + ptype_l3_ipv6 = 1; + } + + if (ptype_l3_ipv4 && ptype_l3_ipv6) + return 1; + + return 0; +} + /* Check the link status of all ports in up to 9s, and print them finally */ static void check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) @@ -901,6 +981,14 @@ struct rte_lpm6_config lpm6_config = { print_ethaddr(" Address:", &ports_eth_addr[portid]); printf("\n"); + if (parse_ptype) { + if (add_cb_parse_ptype(portid, 0) < 0) + rte_exit(EXIT_FAILURE, + "Fail to add ptype cb\n"); + } else if (!check_ptype(portid)) + rte_exit(EXIT_FAILURE, + "PMD can not provide needed ptypes\n"); + /* init one TX queue per couple (lcore,port) */ queueid = 0; for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { -- 1.9.1