From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 35653B397 for ; Tue, 12 Aug 2014 05:09:33 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 11 Aug 2014 20:05:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,846,1400050800"; d="scan'208";a="575329708" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 11 Aug 2014 20:12:24 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s7C3CMMW012541; Tue, 12 Aug 2014 11:12:22 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s7C3CJ9D011117; Tue, 12 Aug 2014 11:12:21 +0800 Received: (from jijiangl@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s7C3CJJE011113; Tue, 12 Aug 2014 11:12:19 +0800 From: Jijiang Liu To: dev@dpdk.org Date: Tue, 12 Aug 2014 11:12:03 +0800 Message-Id: <1407813127-10991-3-git-send-email-jijiang.liu@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1407813127-10991-1-git-send-email-jijiang.liu@intel.com> References: <1407813127-10991-1-git-send-email-jijiang.liu@intel.com> Subject: [dpdk-dev] [PATCH 2/6]app/test-pmd:test vxlan packet identification 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: Tue, 12 Aug 2014 03:09:34 -0000 Add commands to test receive vxlan packet identification, which include - use command to add/delete VxLAN UDP port. - use rxonly mode to receive VxLAN packet. Signed-off-by: jijiangl Acked-by: Helin Zhang Acked-by: Jingjing Wu Acked-by: Jing Chen --- app/test-pmd/cmdline.c | 78 ++++++++++++++++++++++++++++++++++++++++++-- app/test-pmd/parameters.c | 13 +++++++ app/test-pmd/rxonly.c | 49 ++++++++++++++++++++++++++++ app/test-pmd/testpmd.c | 8 +++++ app/test-pmd/testpmd.h | 9 +++++ 5 files changed, 153 insertions(+), 4 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 345be11..67cf63e 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -285,6 +285,12 @@ static void cmd_help_long_parsed(void *parsed_result, " Set the outer VLAN TPID for Packet Filtering on" " a port\n\n" + "rx_vxlan_port add (udp_port) (port_id)\n" + " Add an UDP port for VxLAN packet filter on a port\n\n" + + "rx_vxlan_port rm (udp_port) (port_id)\n" + " Remove an UDP port for VxLAN packet filter on a port\n\n" + "tx_vlan set vlan_id (port_id)\n" " Set hardware insertion of VLAN ID in packets sent" " on a port.\n\n" @@ -296,13 +302,17 @@ static void cmd_help_long_parsed(void *parsed_result, " Disable hardware insertion of a VLAN header in" " packets sent on a port.\n\n" - "tx_checksum set mask (port_id)\n" + "tx_checksum set (mask) (port_id)\n" " Enable hardware insertion of checksum offload with" - " the 4-bit mask, 0~0xf, in packets sent on a port.\n" + " the 8-bit mask, 0~0xff, in packets sent on a port.\n" " bit 0 - insert ip checksum offload if set\n" " bit 1 - insert udp checksum offload if set\n" " bit 2 - insert tcp checksum offload if set\n" " bit 3 - insert sctp checksum offload if set\n" + " bit 4 - insert inner ip checksum offload if set\n" + " bit 5 - insert inner udp checksum offload if set\n" + " bit 6 - insert inner tcp checksum offload if set\n" + " bit 7 - insert inner sctp checksum offload if set\n" " Please check the NIC datasheet for HW limits.\n\n" "set fwd (%s)\n" @@ -2646,8 +2656,9 @@ cmdline_parse_inst_t cmd_tx_cksum_set = { .f = cmd_tx_cksum_set_parsed, .data = NULL, .help_str = "enable hardware insertion of L3/L4checksum with a given " - "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip" - "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP", + "mask in packets sent on a port, the bit mapping is given as, Bit 0 for ip " + "Bit 1 for UDP, Bit 2 for TCP, Bit 3 for SCTP, Bit 4 for inner ip " + "Bit 5 for inner UDP, Bit 6 for inner TCP, Bit 7 for inner SCTP", .tokens = { (void *)&cmd_tx_cksum_set_tx_cksum, (void *)&cmd_tx_cksum_set_set, @@ -6112,6 +6123,64 @@ cmdline_parse_inst_t cmd_vf_rate_limit = { }, }; +/* *** CONFIGURE TUNNEL UDP PORT *** */ +struct cmd_tunnel_udp_config { + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t what; + uint16_t udp_port; + uint8_t port_id; +}; + +static void +cmd_tunnel_udp_config_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_tunnel_udp_config *res = parsed_result; + struct rte_eth_udp_tunnel tunnel_udp; + int ret; + + tunnel_udp.udp_port = res->udp_port; + + if (!strcmp(res->cmd, "rx_vxlan_port")) + tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN; + + if (!strcmp(res->what, "add")) + ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp, 1); + else + ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp, 1); + + if (ret < 0) + printf("udp tunneling add error: (%s)\n", strerror(-ret)); +} + +cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, + cmd, "rx_vxlan_port"); +cmdline_parse_token_string_t cmd_tunnel_udp_config_what = + TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config, + what, "add#rm"); +cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = + TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, + udp_port, UINT16); +cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, + port_id, UINT8); + +cmdline_parse_inst_t cmd_tunnel_udp_config = { + .f = cmd_tunnel_udp_config_parsed, + .data = (void *)0, + .help_str = "add/rm an UDP tunneling port filter: " + "rx_vxlan_port add udp_port port_id", + .tokens = { + (void *)&cmd_tunnel_udp_config_cmd, + (void *)&cmd_tunnel_udp_config_what, + (void *)&cmd_tunnel_udp_config_udp_port, + (void *)&cmd_tunnel_udp_config_port_id, + NULL, + }, +}; + /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */ struct cmd_set_mirror_mask_result { cmdline_fixed_string_t set; @@ -7406,6 +7475,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, (cmdline_parse_inst_t *)&cmd_queue_rate_limit, (cmdline_parse_inst_t *)&cmd_vf_rate_limit, + (cmdline_parse_inst_t *)&cmd_tunnel_udp_config, (cmdline_parse_inst_t *)&cmd_set_mirror_mask, (cmdline_parse_inst_t *)&cmd_set_mirror_link, (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 9573a43..fda8c1d 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -202,6 +202,10 @@ usage(char* progname) printf(" --txpkts=X[,Y]*: set TX segment sizes.\n"); printf(" --disable-link-check: disable check on link status when " "starting/stopping ports.\n"); + printf(" --tunnel-type=N: set tunneling packet type " + "(0 <= N <= 4).(0:non-tunneling packet;1:VxLAN; " + "2:GENEVE;3: TEREDO;4: NVGRE)\n"); + } #ifdef RTE_LIBRTE_CMDLINE @@ -600,6 +604,7 @@ launch_args_parse(int argc, char** argv) { "no-flush-rx", 0, 0, 0 }, { "txpkts", 1, 0, 0 }, { "disable-link-check", 0, 0, 0 }, + { "tunnel-type", 1, 0, 0 }, { 0, 0, 0, 0 }, }; @@ -1032,6 +1037,14 @@ launch_args_parse(int argc, char** argv) else rte_exit(EXIT_FAILURE, "rxfreet must be >= 0\n"); } + if (!strcmp(lgopts[opt_idx].name, "tunnel-type")) { + n = atoi(optarg); + if ((n >= 0) && (n < RTE_TUNNEL_TYPE_MAX)) + rx_tunnel_type = (uint16_t)n; + else + rte_exit(EXIT_FAILURE, "tunnel-type must be 0-%d\n", + RTE_TUNNEL_TYPE_MAX); + } if (!strcmp(lgopts[opt_idx].name, "tx-queue-stats-mapping")) { if (parse_queue_stats_mapping_config(optarg, TX)) { rte_exit(EXIT_FAILURE, diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index 5f21a3e..4f529f6 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include "testpmd.h" @@ -112,6 +114,9 @@ pkt_burst_receive(struct fwd_stream *fs) uint16_t ol_flags; uint16_t nb_rx; uint16_t i; + uint8_t ptype; + uint8_t is_encapsulation; + #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t start_tsc; uint64_t end_tsc; @@ -152,6 +157,11 @@ pkt_burst_receive(struct fwd_stream *fs) eth_hdr = (struct ether_hdr *) mb->pkt.data; eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type); ol_flags = mb->ol_flags; + ptype = mb->reserved; + + is_encapsulation = IS_ETH_IPV4_TUNNEL(ptype) | + IS_ETH_IPV6_TUNNEL(ptype); + print_ether_addr(" src=", ð_hdr->s_addr); print_ether_addr(" - dst=", ð_hdr->d_addr); printf(" - type=0x%04x - length=%u - nb_segs=%d", @@ -167,6 +177,45 @@ pkt_burst_receive(struct fwd_stream *fs) if (ol_flags & PKT_RX_VLAN_PKT) printf(" - VLAN tci=0x%x", mb->pkt.vlan_macip.f.vlan_tci); + if (is_encapsulation) { + struct ipv4_hdr *ipv4_hdr; + struct ipv6_hdr *ipv6_hdr; + struct udp_hdr *udp_hdr; + uint8_t l2_len; + uint8_t l3_len; + uint8_t l4_len; + uint8_t l4_proto; + struct vxlan_hdr *vxlan_hdr; + + l2_len = sizeof(struct ether_hdr); + + /* Do not support ipv4 option field */ + if (IS_ETH_IPV4_TUNNEL(ptype)) { + l3_len = sizeof(struct ipv4_hdr); + ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len); + l4_proto = ipv4_hdr->next_proto_id; + } else { + l3_len = sizeof(struct ipv6_hdr); + ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len); + l4_proto = ipv6_hdr->proto; + } + if (l4_proto == IPPROTO_UDP) { + udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len + l3_len); + l4_len = sizeof(struct udp_hdr); + vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb, + unsigned char *) + l2_len + l3_len + + l4_len); + + printf(" - VxLAN packet: packet type =%d, " + "Destination UDP port =%d, VNI = %d", + ptype, RTE_BE_TO_CPU_16(udp_hdr->dst_port), + rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8); + } + } + printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue); printf("\n"); if (ol_flags != 0) { int rxf; diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e8a4b45..daa8f41 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -243,6 +243,12 @@ uint16_t tx_free_thresh = 0; /* Use default values. */ uint16_t tx_rs_thresh = 0; /* Use default values. */ /* + * Configurable value of tunnel type. + */ + +uint8_t rx_tunnel_type = 0; /* Use default values. */ + +/* * Configurable value of TX queue flags. */ uint32_t txq_flags = 0; /* No flags set. */ @@ -1676,6 +1682,8 @@ init_port_config(void) port = &ports[pid]; port->dev_conf.rxmode = rx_mode; port->dev_conf.fdir_conf = fdir_conf; + if (rx_tunnel_type == 1) + port->dev_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN; if (nb_rxq > 1) { port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL; port->dev_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ac86bfe..a304c47 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -80,6 +80,10 @@ typedef uint16_t streamid_t; #define MAX_QUEUE_ID ((1 << (sizeof(queueid_t) * 8)) - 1) +/* For FVL NIC */ +#define IS_ETH_IPV4_TUNNEL(ptype) ((ptype > 58) && (ptype < 87)) +#define IS_ETH_IPV6_TUNNEL(ptype) ((ptype > 124) && (ptype < 153)) + enum { PORT_TOPOLOGY_PAIRED, PORT_TOPOLOGY_CHAINED, @@ -130,6 +134,10 @@ struct fwd_stream { * Bit 1: Insert UDP checksum * Bit 2: Insert TCP checksum * Bit 3: Insert SCTP checksum + * Bit 4: Insert inner IP checksum + * Bit 5: Insert inner UDP checksum + * Bit 6: Insert inner TCP checksum + * Bit 7: Insert inner SCTP checksum * Bit 11: Insert VLAN Label */ struct rte_port { @@ -342,6 +350,7 @@ extern uint8_t rx_drop_en; extern uint16_t tx_free_thresh; extern uint16_t tx_rs_thresh; extern uint32_t txq_flags; +extern uint8_t rx_tunnel_type; extern uint8_t dcb_config; extern uint8_t dcb_test; -- 1.7.7.6