From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 252256910 for ; Fri, 23 Sep 2016 15:50:59 +0200 (CEST) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B4022A1052; Fri, 23 Sep 2016 13:50:58 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-7-3.ams2.redhat.com [10.36.7.3]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8NDosCv030133; Fri, 23 Sep 2016 09:50:57 -0400 From: Maxime Coquelin To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com, john.mcnamara@intel.com, dev@dpdk.org Cc: maxime.coquelin@redhat.com Date: Fri, 23 Sep 2016 15:50:53 +0200 Message-Id: <1474638654-26919-2-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1474638654-26919-1-git-send-email-maxime.coquelin@redhat.com> References: <1474638654-26919-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 23 Sep 2016 13:50:58 +0000 (UTC) Subject: [dpdk-dev] [PATCH v2 1/2] examples/l2fwd: Add new option to enable/disable MAC addresses updating 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, 23 Sep 2016 13:51:00 -0000 l2fwd could be useful for testing virtual devices without the need of physical ones. To achieve this, this patch adds a new option to enable/disable the MAC addresses updating done at forwarding time: --[no-]mac-updating By default, MAC address updating remains enabled, to keep consistency with previous usage. Acked-by: John McNamara Signed-off-by: Maxime Coquelin --- examples/l2fwd/main.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 3827aa4..b2f5851 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -73,6 +73,9 @@ static volatile bool force_quit; +/* MAC updating enabled by default */ +static int mac_updating = 1; + #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1 #define NB_MBUF 8192 @@ -185,23 +188,32 @@ print_stats(void) } static void -l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid) +l2fwd_mac_updating(struct rte_mbuf *m, unsigned dest_portid) { struct ether_hdr *eth; void *tmp; - unsigned dst_port; - int sent; - struct rte_eth_dev_tx_buffer *buffer; - dst_port = l2fwd_dst_ports[portid]; eth = rte_pktmbuf_mtod(m, struct ether_hdr *); /* 02:00:00:00:00:xx */ tmp = ð->d_addr.addr_bytes[0]; - *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40); + *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40); /* src addr */ - ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], ð->s_addr); + ether_addr_copy(&l2fwd_ports_eth_addr[dest_portid], ð->s_addr); +} + +static void +l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid) +{ + unsigned dst_port; + int sent; + struct rte_eth_dev_tx_buffer *buffer; + + dst_port = l2fwd_dst_ports[portid]; + + if (mac_updating) + l2fwd_mac_updating(m, dst_port); buffer = tx_buffer[dst_port]; sent = rte_eth_tx_buffer(dst_port, 0, buffer, m); @@ -321,7 +333,11 @@ l2fwd_usage(const char *prgname) 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" - " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n", + " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n" + " --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n" + " When enabled:\n" + " - The source MAC address is replaced by the TX port MAC address\n" + " - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n", prgname); } @@ -385,6 +401,8 @@ l2fwd_parse_args(int argc, char **argv) int option_index; char *prgname = argv[0]; static struct option lgopts[] = { + { "mac-updating", no_argument, &mac_updating, 1}, + { "no-mac-updating", no_argument, &mac_updating, 0}, {NULL, 0, 0, 0} }; @@ -427,8 +445,7 @@ l2fwd_parse_args(int argc, char **argv) /* long options */ case 0: - l2fwd_usage(prgname); - return -1; + break; default: l2fwd_usage(prgname); @@ -541,6 +558,8 @@ main(int argc, char **argv) if (ret < 0) rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n"); + printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled"); + /* convert to number of cycles */ timer_period *= rte_get_timer_hz(); -- 2.7.4