DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app
@ 2015-05-15 16:08 Andrey Chilikin
  2015-06-03  8:16 ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Chilikin @ 2015-05-15 16:08 UTC (permalink / raw)
  To: dev

Added optional ip version check to l3fwd app to allow to detect
the ip version if mbuf ol_flags are not set in case of running
in a VM with emulated network controllers

Signed-off-by: Andrey Chilikin <andrey.chilikin@intel.com>
---
 examples/l3fwd/main.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c
index e32512e..4d4e5bc 100644
--- a/examples/l3fwd/main.c
+++ b/examples/l3fwd/main.c
@@ -76,6 +76,8 @@
 #define APP_LOOKUP_LPM                  1
 #define DO_RFC_1812_CHECKS
 
+#define DO_IP_VERSION_CHECK             0
+
 #ifndef APP_LOOKUP_METHOD
 #define APP_LOOKUP_METHOD             APP_LOOKUP_LPM
 #endif
@@ -953,6 +955,15 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct lcore_conf *qcon
 	void *d_addr_bytes;
 	uint8_t dst_port;
 
+#if DO_IP_VERSION_CHECK
+	if (!(m->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) {
+		uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) +
+			sizeof(struct ether_hdr)) >> 4;
+		if (ip_ver == 4)
+			m->ol_flags |= PKT_RX_IPV4_HDR;
+	}
+#endif
+
 	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
 	if (m->ol_flags & PKT_RX_IPV4_HDR) {
@@ -1071,6 +1082,17 @@ get_dst_port(const struct lcore_conf *qconf, struct rte_mbuf *pkt,
 	struct ipv6_hdr *ipv6_hdr;
 	struct ether_hdr *eth_hdr;
 
+#if DO_IP_VERSION_CHECK
+	if (!(pkt->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) {
+		uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(pkt, unsigned char *) +
+			sizeof(struct ether_hdr)) >> 4;
+		if (ip_ver == 4)
+			pkt->ol_flags |= PKT_RX_IPV4_HDR;
+		else if (ip_ver == 6)
+			pkt->ol_flags |= PKT_RX_IPV6_HDR;
+	}
+#endif
+
 	if (pkt->ol_flags & PKT_RX_IPV4_HDR) {
 		if (rte_lpm_lookup(qconf->ipv4_lookup_struct, dst_ipv4,
 				&next_hop) != 0)
-- 
1.7.4.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app
  2015-05-15 16:08 [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app Andrey Chilikin
@ 2015-06-03  8:16 ` Thomas Monjalon
  2015-06-03  8:24   ` Chilikin, Andrey
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Monjalon @ 2015-06-03  8:16 UTC (permalink / raw)
  To: Andrey Chilikin; +Cc: dev

2015-05-15 17:08, Andrey Chilikin:
> Added optional ip version check to l3fwd app to allow to detect
> the ip version if mbuf ol_flags are not set in case of running
> in a VM with emulated network controllers
> 
> Signed-off-by: Andrey Chilikin <andrey.chilikin@intel.com>
[...]
> +#define DO_IP_VERSION_CHECK             0
[...]
> @@ -953,6 +955,15 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid, struct lcore_conf *qcon
>  	void *d_addr_bytes;
>  	uint8_t dst_port;
>  
> +#if DO_IP_VERSION_CHECK
> +	if (!(m->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) {
> +		uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) +
> +			sizeof(struct ether_hdr)) >> 4;
> +		if (ip_ver == 4)
> +			m->ol_flags |= PKT_RX_IPV4_HDR;
> +	}
> +#endif

You are adding dead code. When ol_flags will be updated, it will be forget
until someone enables it.
In general, compile-time configurations are avoided and it's even worst
when this is hidden and not easily testable like here.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app
  2015-06-03  8:16 ` Thomas Monjalon
@ 2015-06-03  8:24   ` Chilikin, Andrey
  2015-06-03  8:27     ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Chilikin, Andrey @ 2015-06-03  8:24 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, June 3, 2015 9:17 AM
> To: Chilikin, Andrey
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app
> 
> 2015-05-15 17:08, Andrey Chilikin:
> > Added optional ip version check to l3fwd app to allow to detect the ip
> > version if mbuf ol_flags are not set in case of running in a VM with
> > emulated network controllers
> >
> > Signed-off-by: Andrey Chilikin <andrey.chilikin@intel.com>
> [...]
> > +#define DO_IP_VERSION_CHECK             0
> [...]
> > @@ -953,6 +955,15 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t
> portid, struct lcore_conf *qcon
> >  	void *d_addr_bytes;
> >  	uint8_t dst_port;
> >
> > +#if DO_IP_VERSION_CHECK
> > +	if (!(m->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) {
> > +		uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(m, unsigned
> char *) +
> > +			sizeof(struct ether_hdr)) >> 4;
> > +		if (ip_ver == 4)
> > +			m->ol_flags |= PKT_RX_IPV4_HDR;
> > +	}
> > +#endif
> 
> You are adding dead code. When ol_flags will be updated, it will be forget until
> someone enables it.
> In general, compile-time configurations are avoided and it's even worst when
> this is hidden and not easily testable like here.

Agree, we already thinking about creating separate example l3fwd-vm to cover emulated network controllers.

Thanks,
Andrey

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app
  2015-06-03  8:24   ` Chilikin, Andrey
@ 2015-06-03  8:27     ` Thomas Monjalon
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2015-06-03  8:27 UTC (permalink / raw)
  To: Chilikin, Andrey; +Cc: dev

2015-06-03 08:24, Chilikin, Andrey:
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > 2015-05-15 17:08, Andrey Chilikin:
> > > Added optional ip version check to l3fwd app to allow to detect the ip
> > > version if mbuf ol_flags are not set in case of running in a VM with
> > > emulated network controllers
> > >
> > > Signed-off-by: Andrey Chilikin <andrey.chilikin@intel.com>
> > [...]
> > > +#define DO_IP_VERSION_CHECK             0
> > [...]
> > > @@ -953,6 +955,15 @@ l3fwd_simple_forward(struct rte_mbuf *m, uint8_t
> > portid, struct lcore_conf *qcon
> > >  	void *d_addr_bytes;
> > >  	uint8_t dst_port;
> > >
> > > +#if DO_IP_VERSION_CHECK
> > > +	if (!(m->ol_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV6_HDR))) {
> > > +		uint8_t ip_ver = *(uint8_t *)(rte_pktmbuf_mtod(m, unsigned
> > char *) +
> > > +			sizeof(struct ether_hdr)) >> 4;
> > > +		if (ip_ver == 4)
> > > +			m->ol_flags |= PKT_RX_IPV4_HDR;
> > > +	}
> > > +#endif
> > 
> > You are adding dead code. When ol_flags will be updated, it will be forget until
> > someone enables it.
> > In general, compile-time configurations are avoided and it's even worst when
> > this is hidden and not easily testable like here.
> 
> Agree, we already thinking about creating separate example l3fwd-vm to cover emulated network controllers.

Or you can try to implement some callbacks and choose the implementation
at init when detecting the environment.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-03  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 16:08 [dpdk-dev] [PATCH] examples: add ip version check for l3fwd app Andrey Chilikin
2015-06-03  8:16 ` Thomas Monjalon
2015-06-03  8:24   ` Chilikin, Andrey
2015-06-03  8:27     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).