From patchwork Fri Sep 12 06:33:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijiang Liu X-Patchwork-Id: 364 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 7C4B8B3A1; Fri, 12 Sep 2014 08:28:59 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 4F14EB39E for ; Fri, 12 Sep 2014 08:28:57 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 11 Sep 2014 23:28:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,511,1406617200"; d="scan'208";a="572150045" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 11 Sep 2014 23:34:11 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s8C6YARW005977; Fri, 12 Sep 2014 14:34:10 +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 s8C6Y7f1010809; Fri, 12 Sep 2014 14:34:10 +0800 Received: (from jijiangl@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s8C6Y7tk010805; Fri, 12 Sep 2014 14:34:07 +0800 From: Jijiang Liu To: dev@dpdk.org Date: Fri, 12 Sep 2014 14:33:54 +0800 Message-Id: <1410503639-10753-4-git-send-email-jijiang.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1410503639-10753-1-git-send-email-jijiang.liu@intel.com> References: <1410503639-10753-1-git-send-email-jijiang.liu@intel.com> Subject: [dpdk-dev] [PATCH v3 3/8]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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add commands to test VxLAN packet identification, which include - use commands to add/delete VxLAN UDP port. - use rxonly mode to receive VxLAN packet. Signed-off-by: Jijiang Liu 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 | 4 ++ 5 files changed, 148 insertions(+), 4 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b04a4e8..de910db 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" @@ -2745,8 +2755,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, @@ -6211,6 +6222,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 tunneling UDP 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; @@ -7506,6 +7575,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 a112559..3d09817 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. */ @@ -1688,6 +1694,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 b8322a2..1bd9f8d 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -80,6 +80,9 @@ typedef uint16_t streamid_t; #define MAX_QUEUE_ID ((1 << (sizeof(queueid_t) * 8)) - 1) +#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, @@ -342,6 +345,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;