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 29FB65A2D for ; Tue, 12 May 2015 16:42:17 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 12 May 2015 07:42:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,415,1427785200"; d="scan'208";a="709009521" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga001.fm.intel.com with ESMTP; 12 May 2015 07:42:15 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.73]) by IRSMSX103.ger.corp.intel.com ([169.254.3.215]) with mapi id 14.03.0224.002; Tue, 12 May 2015 15:42:14 +0100 From: "Ananyev, Konstantin" To: "Richardson, Bruce" , "dev@dpdk.org" Thread-Topic: [PATCH] l3fwd: make destination mac address configurable Thread-Index: AQHQjLXeserQ4kZcZk2q1Pe3SzObP514ag/w Date: Tue, 12 May 2015 14:42:14 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772582142E85E@irsmsx105.ger.corp.intel.com> References: <1431436560-15877-1-git-send-email-bruce.richardson@intel.com> In-Reply-To: <1431436560-15877-1-git-send-email-bruce.richardson@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] l3fwd: make destination mac address configurable 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 May 2015 14:42:18 -0000 > -----Original Message----- > From: Richardson, Bruce > Sent: Tuesday, May 12, 2015 2:16 PM > To: dev@dpdk.org > Cc: Chilikin, Andrey; Ananyev, Konstantin; Richardson, Bruce > Subject: [PATCH] l3fwd: make destination mac address configurable >=20 > Add a command-line parameter to l3fwd, to allow the user to specify the > destination mac address for each ethernet port used. >=20 > Signed-off-by: Andrey Chilikin > Signed-off-by: Bruce Richardson > --- > examples/l3fwd/main.c | 98 +++++++++++++++++++++++++++++++++------------= ------ > 1 file changed, 64 insertions(+), 34 deletions(-) >=20 > diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c > index e32512e..66f55f7 100644 > --- a/examples/l3fwd/main.c > +++ b/examples/l3fwd/main.c > @@ -72,6 +72,9 @@ > #include > #include >=20 > +#include > +#include > + > #define APP_LOOKUP_EXACT_MATCH 0 > #define APP_LOOKUP_LPM 1 > #define DO_RFC_1812_CHECKS > @@ -159,6 +162,7 @@ static uint16_t nb_rxd =3D RTE_TEST_RX_DESC_DEFAULT; > static uint16_t nb_txd =3D RTE_TEST_TX_DESC_DEFAULT; >=20 > /* ethernet addresses of ports */ > +static uint64_t dest_eth_addr[RTE_MAX_ETHPORTS]; > static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; >=20 > static __m128i val_eth[RTE_MAX_ETHPORTS]; > @@ -738,7 +742,6 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t = portid, struct lcore_conf * > { > struct ether_hdr *eth_hdr[4]; > struct ipv4_hdr *ipv4_hdr[4]; > - void *d_addr_bytes[4]; > uint8_t dst_port[4]; > int32_t ret[4]; > union ipv4_5tuple_host key[4]; > @@ -823,16 +826,6 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t= portid, struct lcore_conf * > if (dst_port[3] >=3D RTE_MAX_ETHPORTS || (enabled_port_mask & 1 << dst_= port[3]) =3D=3D 0) > dst_port[3] =3D portid; >=20 > - /* 02:00:00:00:00:xx */ > - d_addr_bytes[0] =3D ð_hdr[0]->d_addr.addr_bytes[0]; > - d_addr_bytes[1] =3D ð_hdr[1]->d_addr.addr_bytes[0]; > - d_addr_bytes[2] =3D ð_hdr[2]->d_addr.addr_bytes[0]; > - d_addr_bytes[3] =3D ð_hdr[3]->d_addr.addr_bytes[0]; > - *((uint64_t *)d_addr_bytes[0]) =3D 0x000000000002 + ((uint64_t)dst_port= [0] << 40); > - *((uint64_t *)d_addr_bytes[1]) =3D 0x000000000002 + ((uint64_t)dst_port= [1] << 40); > - *((uint64_t *)d_addr_bytes[2]) =3D 0x000000000002 + ((uint64_t)dst_port= [2] << 40); > - *((uint64_t *)d_addr_bytes[3]) =3D 0x000000000002 + ((uint64_t)dst_port= [3] << 40); > - > #ifdef DO_RFC_1812_CHECKS > /* Update time to live and header checksum */ > --(ipv4_hdr[0]->time_to_live); > @@ -845,6 +838,12 @@ simple_ipv4_fwd_4pkts(struct rte_mbuf* m[4], uint8_t= portid, struct lcore_conf * > ++(ipv4_hdr[3]->hdr_checksum); > #endif >=20 > + /* dst addr */ > + *(uint64_t *)ð_hdr[0]->d_addr =3D dest_eth_addr[dst_port[0]]; > + *(uint64_t *)ð_hdr[1]->d_addr =3D dest_eth_addr[dst_port[1]]; > + *(uint64_t *)ð_hdr[2]->d_addr =3D dest_eth_addr[dst_port[2]]; > + *(uint64_t *)ð_hdr[3]->d_addr =3D dest_eth_addr[dst_port[3]]; > + > /* src addr */ > ether_addr_copy(&ports_eth_addr[dst_port[0]], ð_hdr[0]->s_addr); > ether_addr_copy(&ports_eth_addr[dst_port[1]], ð_hdr[1]->s_addr); > @@ -880,7 +879,6 @@ simple_ipv6_fwd_4pkts(struct rte_mbuf* m[4], uint8_t = portid, struct lcore_conf * > { > struct ether_hdr *eth_hdr[4]; > __attribute__((unused)) struct ipv6_hdr *ipv6_hdr[4]; > - void *d_addr_bytes[4]; > uint8_t dst_port[4]; > int32_t ret[4]; > union ipv6_5tuple_host key[4]; > @@ -921,15 +919,11 @@ simple_ipv6_fwd_4pkts(struct rte_mbuf* m[4], uint8_= t portid, struct lcore_conf * > if (dst_port[3] >=3D RTE_MAX_ETHPORTS || (enabled_port_mask & 1 << dst_= port[3]) =3D=3D 0) > dst_port[3] =3D portid; >=20 > - /* 02:00:00:00:00:xx */ > - d_addr_bytes[0] =3D ð_hdr[0]->d_addr.addr_bytes[0]; > - d_addr_bytes[1] =3D ð_hdr[1]->d_addr.addr_bytes[0]; > - d_addr_bytes[2] =3D ð_hdr[2]->d_addr.addr_bytes[0]; > - d_addr_bytes[3] =3D ð_hdr[3]->d_addr.addr_bytes[0]; > - *((uint64_t *)d_addr_bytes[0]) =3D 0x000000000002 + ((uint64_t)dst_port= [0] << 40); > - *((uint64_t *)d_addr_bytes[1]) =3D 0x000000000002 + ((uint64_t)dst_port= [1] << 40); > - *((uint64_t *)d_addr_bytes[2]) =3D 0x000000000002 + ((uint64_t)dst_port= [2] << 40); > - *((uint64_t *)d_addr_bytes[3]) =3D 0x000000000002 + ((uint64_t)dst_port= [3] << 40); > + /* dst addr */ > + *(uint64_t *)ð_hdr[0]->d_addr =3D dest_eth_addr[dst_port[0]]; > + *(uint64_t *)ð_hdr[1]->d_addr =3D dest_eth_addr[dst_port[1]]; > + *(uint64_t *)ð_hdr[2]->d_addr =3D dest_eth_addr[dst_port[2]]; > + *(uint64_t *)ð_hdr[3]->d_addr =3D dest_eth_addr[dst_port[3]]; >=20 > /* src addr */ > ether_addr_copy(&ports_eth_addr[dst_port[0]], ð_hdr[0]->s_addr); > @@ -950,7 +944,6 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t port= id, struct lcore_conf *qcon > { > struct ether_hdr *eth_hdr; > struct ipv4_hdr *ipv4_hdr; > - void *d_addr_bytes; > uint8_t dst_port; >=20 > eth_hdr =3D rte_pktmbuf_mtod(m, struct ether_hdr *); > @@ -974,16 +967,13 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t po= rtid, struct lcore_conf *qcon > (enabled_port_mask & 1 << dst_port) =3D=3D 0) > dst_port =3D portid; >=20 > - /* 02:00:00:00:00:xx */ > - d_addr_bytes =3D ð_hdr->d_addr.addr_bytes[0]; > - *((uint64_t *)d_addr_bytes) =3D ETHER_LOCAL_ADMIN_ADDR + > - ((uint64_t)dst_port << 40); > - > #ifdef DO_RFC_1812_CHECKS > /* Update time to live and header checksum */ > --(ipv4_hdr->time_to_live); > ++(ipv4_hdr->hdr_checksum); > #endif > + /* dst addr */ > + *(uint64_t *)ð_hdr->d_addr =3D dest_eth_addr[dst_port]; >=20 > /* src addr */ > ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr); > @@ -1002,10 +992,8 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t po= rtid, struct lcore_conf *qcon > if (dst_port >=3D RTE_MAX_ETHPORTS || (enabled_port_mask & 1 << dst_po= rt) =3D=3D 0) > dst_port =3D portid; >=20 > - /* 02:00:00:00:00:xx */ > - d_addr_bytes =3D ð_hdr->d_addr.addr_bytes[0]; > - *((uint64_t *)d_addr_bytes) =3D ETHER_LOCAL_ADMIN_ADDR + > - ((uint64_t)dst_port << 40); > + /* dst addr */ > + *(uint64_t *)ð_hdr->d_addr =3D dest_eth_addr[dst_port]; >=20 > /* src addr */ > ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr); > @@ -1742,6 +1730,7 @@ print_usage(const char *prgname) > " -p PORTMASK: hexadecimal bitmask of ports to configure\n" > " -P : enable promiscuous mode\n" > " --config (port,queue,lcore): rx queues configuration\n" > + " --eth-dest=3DX,MM:MM:MM:MM:MM:MM: optional, ethernet destination fo= r port X\n" > " --no-numa: optional, disable numa awareness\n" > " --ipv6: optional, specify it if running ipv6 packets\n" > " --enable-jumbo: enable jumbo frame" > @@ -1852,7 +1841,35 @@ parse_config(const char *q_arg) > return 0; > } >=20 > +static void > +parse_eth_dest(const char *optarg) > +{ > + uint8_t portid; > + char *port_end; > + uint8_t c, *dest, peer_addr[6]; > + > + errno =3D 0; > + portid =3D strtoul(optarg, &port_end, 10); > + if (errno !=3D 0 || port_end =3D=3D optarg || *port_end++ !=3D ',') > + rte_exit(EXIT_FAILURE, > + "Invalid eth-dest: %s", optarg); > + if (portid >=3D RTE_MAX_ETHPORTS) > + rte_exit(EXIT_FAILURE, > + "eth-dest: port %d >=3D RTE_MAX_ETHPORTS(%d)\n", > + portid, RTE_MAX_ETHPORTS); > + > + if (cmdline_parse_etheraddr(NULL, port_end, > + &peer_addr, sizeof(peer_addr)) < 0) > + rte_exit(EXIT_FAILURE, > + "Invalid ethernet address: %s\n", > + port_end); > + dest =3D (uint8_t *)&dest_eth_addr[portid]; > + for (c =3D 0; c < 6; c++) > + dest[c] =3D peer_addr[c]; > +} > + > #define CMD_LINE_OPT_CONFIG "config" > +#define CMD_LINE_OPT_ETH_DEST "eth-dest" > #define CMD_LINE_OPT_NO_NUMA "no-numa" > #define CMD_LINE_OPT_IPV6 "ipv6" > #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" > @@ -1868,6 +1885,7 @@ parse_args(int argc, char **argv) > char *prgname =3D argv[0]; > static struct option lgopts[] =3D { > {CMD_LINE_OPT_CONFIG, 1, 0, 0}, > + {CMD_LINE_OPT_ETH_DEST, 1, 0, 0}, > {CMD_LINE_OPT_NO_NUMA, 0, 0, 0}, > {CMD_LINE_OPT_IPV6, 0, 0, 0}, > {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0}, > @@ -1907,6 +1925,11 @@ parse_args(int argc, char **argv) > } > } >=20 > + if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ETH_DEST, > + sizeof (CMD_LINE_OPT_CONFIG))) { > + parse_eth_dest(optarg); > + } > + > if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA, > sizeof(CMD_LINE_OPT_NO_NUMA))) { > printf("numa is disabled \n"); > @@ -2410,6 +2433,12 @@ main(int argc, char **argv) > argc -=3D ret; > argv +=3D ret; >=20 > + /* pre-init dst MACs for all ports to 02:00:00:00:00:xx */ > + for (portid =3D 0; portid < RTE_MAX_ETHPORTS; portid++) { > + dest_eth_addr[portid] =3D ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid <= < 40); > + *(uint64_t *)(val_eth + portid) =3D dest_eth_addr[portid]; > + } > + > /* parse application arguments (after the EAL ones) */ > ret =3D parse_args(argc, argv); > if (ret < 0) > @@ -2458,12 +2487,13 @@ main(int argc, char **argv) > rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); > print_ethaddr(" Address:", &ports_eth_addr[portid]); > printf(", "); > + print_ethaddr("Destination:", > + (const struct ether_addr *)&dest_eth_addr[portid]); > + printf(", "); >=20 > /* > - * prepare dst and src MACs for each port. > + * prepare src MACs for each port. > */ > - *(uint64_t *)(val_eth + portid) =3D > - ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid << 40); > ether_addr_copy(&ports_eth_addr[portid], > (struct ether_addr *)(val_eth + portid) + 1); >=20 > -- Acked-by: Konstantin Ananyev > 2.1.0