DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 15/18] mbuf: add functions to dump packet type
Date: Tue,  5 Jul 2016 17:41:47 +0200	[thread overview]
Message-ID: <1467733310-20875-16-git-send-email-olivier.matz@6wind.com> (raw)
In-Reply-To: <1467733310-20875-1-git-send-email-olivier.matz@6wind.com>

Dumping the packet type is useful for debug purposes. Instead
of having each application providing its function to do that,
introduce functions to do it.

It factorizes the code and reduces the risk of desynchronization between
the new packet types and the dump function.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 doc/guides/rel_notes/release_16_11.rst |   4 +
 lib/librte_mbuf/rte_mbuf_ptype.c       | 192 +++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf_ptype.h       |  89 +++++++++++++++
 lib/librte_mbuf/rte_mbuf_version.map   |   8 ++
 4 files changed, 293 insertions(+)

diff --git a/doc/guides/rel_notes/release_16_11.rst b/doc/guides/rel_notes/release_16_11.rst
index 0ef8a87..7ce201b 100644
--- a/doc/guides/rel_notes/release_16_11.rst
+++ b/doc/guides/rel_notes/release_16_11.rst
@@ -44,6 +44,10 @@ New Features
   Added a new function ``rte_pktmbuf_get_ptype()`` to parse an Ethernet packet
   in an mbuf chain and retrieve its packet type by software.
 
+* **Added functions to dump the packet type as a string.**
+
+  Added new functions ``rte_get_ptype_*()`` to dump a packet type as a string.
+
 Resolved Issues
 ---------------
 
diff --git a/lib/librte_mbuf/rte_mbuf_ptype.c b/lib/librte_mbuf/rte_mbuf_ptype.c
index 2abb896..848b622 100644
--- a/lib/librte_mbuf/rte_mbuf_ptype.c
+++ b/lib/librte_mbuf/rte_mbuf_ptype.c
@@ -44,6 +44,198 @@
 #include <rte_mpls.h>
 #include <rte_gre.h>
 
+/* get the name of the l2 packet type */
+const char *rte_get_ptype_l2_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_L2_MASK) {
+	case RTE_PTYPE_L2_ETHER: return "L2_ETHER";
+	case RTE_PTYPE_L2_ETHER_TIMESYNC: return "L2_ETHER_TIMESYNC";
+	case RTE_PTYPE_L2_ETHER_ARP: return "L2_ETHER_ARP";
+	case RTE_PTYPE_L2_ETHER_LLDP: return "L2_ETHER_LLDP";
+	case RTE_PTYPE_L2_ETHER_NSH: return "L2_ETHER_NSH";
+	case RTE_PTYPE_L2_ETHER_VLAN: return "L2_ETHER_VLAN";
+	case RTE_PTYPE_L2_ETHER_QINQ: return "L2_ETHER_QINQ";
+	case RTE_PTYPE_L2_ETHER_MPLS: return "L2_ETHER_MPLS";
+	default: return "L2_UNKNOWN";
+	}
+}
+
+/* get the name of the l3 packet type */
+const char *rte_get_ptype_l3_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_L3_MASK) {
+	case RTE_PTYPE_L3_IPV4: return "L3_IPV4";
+	case RTE_PTYPE_L3_IPV4_EXT: return "L3_IPV4_EXT";
+	case RTE_PTYPE_L3_IPV6: return "L3_IPV6";
+	case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN: return "L3_IPV4_EXT_UNKNOWN";
+	case RTE_PTYPE_L3_IPV6_EXT: return "L3_IPV6_EXT";
+	case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN: return "L3_IPV6_EXT_UNKNOWN";
+	default: return "L3_UNKNOWN";
+	}
+}
+
+/* get the name of the l4 packet type */
+const char *rte_get_ptype_l4_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_L4_MASK) {
+	case RTE_PTYPE_L4_TCP: return "L4_TCP";
+	case RTE_PTYPE_L4_UDP: return "L4_UDP";
+	case RTE_PTYPE_L4_FRAG: return "L4_FRAG";
+	case RTE_PTYPE_L4_SCTP: return "L4_SCTP";
+	case RTE_PTYPE_L4_ICMP: return "L4_ICMP";
+	case RTE_PTYPE_L4_NONFRAG: return "L4_NONFRAG";
+	default: return "L4_UNKNOWN";
+	}
+}
+
+/* get the name of the tunnel packet type */
+const char *rte_get_ptype_tunnel_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_TUNNEL_MASK) {
+	case RTE_PTYPE_TUNNEL_IP: return "TUNNEL_IP";
+	case RTE_PTYPE_TUNNEL_GRE: return "TUNNEL_GRE";
+	case RTE_PTYPE_TUNNEL_VXLAN: return "TUNNEL_VXLAN";
+	case RTE_PTYPE_TUNNEL_NVGRE: return "TUNNEL_NVGRE";
+	case RTE_PTYPE_TUNNEL_GENEVE: return "TUNNEL_GENEVE";
+	case RTE_PTYPE_TUNNEL_GRENAT: return "TUNNEL_GRENAT";
+	default: return "TUNNEL_UNKNOWN";
+	}
+}
+
+/* get the name of the inner_l2 packet type */
+const char *rte_get_ptype_inner_l2_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_INNER_L2_MASK) {
+	case RTE_PTYPE_INNER_L2_ETHER: return "INNER_L2_ETHER";
+	case RTE_PTYPE_INNER_L2_ETHER_VLAN: return "INNER_L2_ETHER_VLAN";
+	case RTE_PTYPE_INNER_L2_ETHER_QINQ: return "INNER_L2_ETHER_QINQ";
+	case RTE_PTYPE_INNER_L2_ETHER_MPLS: return "INNER_L2_ETHER_MPLS";
+	default: return "INNER_L2_UNKNOWN";
+	}
+}
+
+/* get the name of the inner_l3 packet type */
+const char *rte_get_ptype_inner_l3_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_INNER_L3_MASK) {
+	case RTE_PTYPE_INNER_L3_IPV4: return "INNER_L3_IPV4";
+	case RTE_PTYPE_INNER_L3_IPV4_EXT: return "INNER_L3_IPV4_EXT";
+	case RTE_PTYPE_INNER_L3_IPV6: return "INNER_L3_IPV6";
+	case RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
+		return "INNER_L3_IPV4_EXT_UNKNOWN";
+	case RTE_PTYPE_INNER_L3_IPV6_EXT: return "INNER_L3_IPV6_EXT";
+	case RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
+		return "INNER_L3_IPV6_EXT_UNKNOWN";
+	default: return "INNER_L3_UNKNOWN";
+	}
+}
+
+/* get the name of the inner_l4 packet type */
+const char *rte_get_ptype_inner_l4_name(uint32_t ptype)
+{
+	switch (ptype & RTE_PTYPE_INNER_L4_MASK) {
+	case RTE_PTYPE_INNER_L4_TCP: return "INNER_L4_TCP";
+	case RTE_PTYPE_INNER_L4_UDP: return "INNER_L4_UDP";
+	case RTE_PTYPE_INNER_L4_FRAG: return "INNER_L4_FRAG";
+	case RTE_PTYPE_INNER_L4_SCTP: return "INNER_L4_SCTP";
+	case RTE_PTYPE_INNER_L4_ICMP: return "INNER_L4_ICMP";
+	case RTE_PTYPE_INNER_L4_NONFRAG: return "INNER_L4_NONFRAG";
+	default: return "INNER_L4_UNKNOWN";
+	}
+}
+
+/* write the packet type name into the buffer */
+int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen)
+{
+	int ret;
+
+	if (buflen == 0)
+		return -1;
+
+	buf[0] = '\0';
+	if ((ptype & RTE_PTYPE_ALL_MASK) == RTE_PTYPE_UNKNOWN) {
+		ret = snprintf(buf, buflen, "UNKNOWN");
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		return 0;
+	}
+
+	if ((ptype & RTE_PTYPE_L2_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_l2_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_L3_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_l3_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_L4_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_l4_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_TUNNEL_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_tunnel_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_INNER_L2_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_inner_l2_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_INNER_L3_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_inner_l3_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+	if ((ptype & RTE_PTYPE_INNER_L4_MASK) != 0) {
+		ret = snprintf(buf, buflen, "%s ",
+			rte_get_ptype_inner_l4_name(ptype));
+		if (ret < 0)
+			return -1;
+		if ((size_t)ret >= buflen)
+			return -1;
+		buf += ret;
+		buflen -= ret;
+	}
+
+	return 0;
+}
+
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
 ptype_l3_ip6(uint8_t ip6_proto)
diff --git a/lib/librte_mbuf/rte_mbuf_ptype.h b/lib/librte_mbuf/rte_mbuf_ptype.h
index 9af52b4..21bba37 100644
--- a/lib/librte_mbuf/rte_mbuf_ptype.h
+++ b/lib/librte_mbuf/rte_mbuf_ptype.h
@@ -562,6 +562,10 @@ extern "C" {
  * Mask of inner layer 4 packet types.
  */
 #define RTE_PTYPE_INNER_L4_MASK             0x0f000000
+/**
+ * All valid layer masks.
+ */
+#define RTE_PTYPE_ALL_MASK                  0x0fffffff
 
 /**
  * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
@@ -587,6 +591,91 @@ extern "C" {
 struct rte_mbuf;
 
 /**
+ * Get the name of the l2 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_l2_name(uint32_t ptype);
+
+/**
+ * Get the name of the l3 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_l3_name(uint32_t ptype);
+
+/**
+ * Get the name of the l4 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_l4_name(uint32_t ptype);
+
+/**
+ * Get the name of the tunnel packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_tunnel_name(uint32_t ptype);
+
+/**
+ * Get the name of the inner_l2 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
+
+/**
+ * Get the name of the inner_l3 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
+
+/**
+ * Get the name of the inner_l4 packet type
+ *
+ * @param ptype
+ *   The packet type value.
+ * @return
+ *   A non-null string describing the packet type.
+ */
+const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
+
+/**
+ * Write the packet type name into the buffer
+ *
+ * @param ptype
+ *   The packet type value.
+ * @param buf
+ *   The buffer where the string is written.
+ * @param buflen
+ *   The length of the buffer.
+ * @return
+ *   - 0 on success
+ *   - (-1) if the buffer is too small
+ */
+int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
+
+/**
  * Structure containing header lengths associated to a packet.
  */
 struct rte_mbuf_hdr_lens {
diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map
index 416af8e..0f04b02 100644
--- a/lib/librte_mbuf/rte_mbuf_version.map
+++ b/lib/librte_mbuf/rte_mbuf_version.map
@@ -23,6 +23,14 @@ DPDK_16.11 {
 	global:
 
 	__rte_pktmbuf_read;
+	rte_get_ptype_inner_l2_name;
+	rte_get_ptype_inner_l3_name;
+	rte_get_ptype_inner_l4_name;
+	rte_get_ptype_l2_name;
+	rte_get_ptype_l3_name;
+	rte_get_ptype_l4_name;
+	rte_get_ptype_name;
+	rte_get_ptype_tunnel_name;
 	rte_pktmbuf_get_ptype;
 
 } DPDK_2.1;
-- 
2.8.1

  parent reply	other threads:[~2016-07-05 15:42 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:41 [dpdk-dev] [PATCH 00/18] software parser for " Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 01/18] doc: add template for release notes 16.11 Olivier Matz
2016-07-06 11:48   ` Mcnamara, John
2016-07-06 12:00     ` Olivier MATZ
2016-07-05 15:41 ` [dpdk-dev] [PATCH 02/18] mbuf: add function to read packet data Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 03/18] net: move Ethernet header definitions to the net library Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 04/18] mbuf: move packet type definitions in a new file Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 05/18] mbuf: add function to get packet type from data Olivier Matz
2016-07-06  6:44   ` Liang, Cunming
2016-07-06  7:42     ` Olivier MATZ
2016-07-06 11:59       ` Chilikin, Andrey
2016-07-06 12:08         ` Olivier MATZ
2016-07-06 12:21           ` Chilikin, Andrey
2016-07-07  8:19       ` Liang, Cunming
2016-07-07 15:48         ` Olivier Matz
2016-07-08 10:08           ` Liang, Cunming
2016-07-05 15:41 ` [dpdk-dev] [PATCH 06/18] mbuf: support Vlan in software packet type parser Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 07/18] mbuf: support QinQ " Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 08/18] net: add Mpls header structure Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 09/18] mbuf: support Mpls in software packet type parser Olivier Matz
2016-07-06  7:08   ` Liang, Cunming
2016-07-06  8:00     ` Olivier MATZ
2016-07-07  8:48       ` Liang, Cunming
2016-07-07 16:01         ` Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 10/18] mbuf: support Ip tunnels " Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 11/18] net: add Gre header structure Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 12/18] mbuf: support Gre in software packet type parser Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 13/18] mbuf: support Nvgre " Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 14/18] mbuf: get ptype for the first layers only Olivier Matz
2016-07-05 15:41 ` Olivier Matz [this message]
2016-07-05 15:41 ` [dpdk-dev] [PATCH 16/18] mbuf: clarify definition of fragment packet types Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 17/18] app/testpmd: dump ptype using the new function Olivier Matz
2016-07-05 15:41 ` [dpdk-dev] [PATCH 18/18] app/testpmd: display sw packet type Olivier Matz
2016-08-29 14:35 ` [dpdk-dev] [PATCH v2 00/16] software parser for " Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 01/16] mbuf: add function to read packet data Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 02/16] net: move Ethernet header definitions to the net library Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 03/16] mbuf: move packet type definitions in a new file Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 04/16] net: introduce net library Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 05/16] net: add function to get packet type from data Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 06/16] net: support Vlan in software packet type parser Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 07/16] net: support QinQ " Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 08/16] net: support Ip tunnels " Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 09/16] net: add Gre header structure Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 10/16] net: support Gre in software packet type parser Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 11/16] net: support Nvgre " Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 12/16] net: get ptype for the first layers only Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 13/16] mbuf: add functions to dump packet type Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 14/16] mbuf: clarify definition of fragment packet types Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 15/16] app/testpmd: dump ptype using the new function Olivier Matz
2016-08-29 14:35   ` [dpdk-dev] [PATCH v2 16/16] app/testpmd: display software packet type Olivier Matz
2016-10-03  8:38   ` [dpdk-dev] [PATCH v3 00/16] software parser for " Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 01/16] mbuf: add function to read packet data Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 02/16] net: move Ethernet header definitions to the net library Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 03/16] mbuf: move packet type definitions in a new file Olivier Matz
2016-10-10 14:52       ` Thomas Monjalon
2016-10-11  9:01         ` Olivier MATZ
2016-10-11 15:51           ` Thomas Monjalon
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 04/16] net: introduce net library Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 05/16] net: add function to get packet type from data Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 06/16] net: support Vlan in software packet type parser Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 07/16] net: support QinQ " Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 08/16] net: support Ip tunnels " Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 09/16] net: add Gre header structure Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 10/16] net: support Gre in software packet type parser Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 11/16] net: support Nvgre " Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 12/16] net: get ptype for the first layers only Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 13/16] mbuf: add functions to dump packet type Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 14/16] mbuf: clarify definition of fragment packet types Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 15/16] app/testpmd: dump ptype using the new function Olivier Matz
2016-10-03  8:38     ` [dpdk-dev] [PATCH v3 16/16] app/testpmd: display software packet type Olivier Matz
2016-10-11 16:24     ` [dpdk-dev] [PATCH v3 00/16] software parser for " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467733310-20875-16-git-send-email-olivier.matz@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).