diff mbox

[PATCHv3] api: implement odp_pktio_name

Message ID 1421170589-6362-1-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Jan. 13, 2015, 5:36 p.m. UTC
Introduced odp_pktio_name() function to translate pktio id
to readable name provided to odp_pktio_open(). Needed mostly
for debug messages.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 v3: add test and extend description.
 v2: doxygen fix

 platform/linux-generic/include/api/odp_packet_io.h | 13 +++++++++++++
 platform/linux-generic/odp_packet_io.c             | 11 +++++++++++
 test/validation/odp_pktio.c                        | 19 +++++++++++++++++++
 3 files changed, 43 insertions(+)

Comments

Maxim Uvarov Jan. 20, 2015, 11:19 a.m. UTC | #1
Mike, Anders, you comments are fixed. Can you add your review-by?

Maxim,

On 01/13/2015 08:36 PM, Maxim Uvarov wrote:
> Introduced odp_pktio_name() function to translate pktio id
> to readable name provided to odp_pktio_open(). Needed mostly
> for debug messages.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>   v3: add test and extend description.
>   v2: doxygen fix
>
>   platform/linux-generic/include/api/odp_packet_io.h | 13 +++++++++++++
>   platform/linux-generic/odp_packet_io.c             | 11 +++++++++++
>   test/validation/odp_pktio.c                        | 19 +++++++++++++++++++
>   3 files changed, 43 insertions(+)
>
> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
> index 0c34f29..c0ced4f 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -169,6 +169,19 @@ size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
>   			  size_t addr_size);
>   
>   /**
> + * Packet IO interface name
> + *
> + * Return the interface name from a pktio handle. This is the
> + * name that was passed to the odp_pktio_open() call.
> + *
> + * @param id ODP Packet IO handle.
> + *
> + * @retval Pointer to the interface name.
> + * @retval NULL if packet handle is invalid.
> + */
> +const char *odp_pktio_name(odp_pktio_t id);
> +
> +/**
>    * @}
>    */
>   
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index cd109d2..7b08edf 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -746,3 +746,14 @@ size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
>   
>   	return ETH_ALEN;
>   }
> +
> +const char *odp_pktio_name(odp_pktio_t id)
> +{
> +	pktio_entry_t *entry;
> +
> +	entry = get_pktio_entry(id);
> +	if (entry == NULL)
> +		return NULL;
> +
> +	return entry->s.name;
> +}
> diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c
> index d1eb0d5..dcbdee2 100644
> --- a/test/validation/odp_pktio.c
> +++ b/test/validation/odp_pktio.c
> @@ -472,6 +472,24 @@ static void test_odp_pktio_mac(void)
>   	return;
>   }
>   
> +static void test_odp_pktio_name(void)
> +{
> +	odp_pktio_t pktio;
> +	const char *name;
> +	int ret;
> +
> +	pktio = create_pktio(iface_name[0]);
> +	name = odp_pktio_name(pktio);
> +
> +	ret = strcmp(iface_name[0], name);
> +	CU_ASSERT(0 == ret);
> +
> +	ret = odp_pktio_close(pktio);
> +	CU_ASSERT(0 == ret);
> +
> +	return;
> +}
> +
>   static void test_odp_pktio_open(void)
>   {
>   	odp_pktio_t pktio;
> @@ -582,6 +600,7 @@ CU_TestInfo pktio_tests[] = {
>   	{"pktio mtu",		test_odp_pktio_mtu},
>   	{"pktio promisc mode",	test_odp_pktio_promisc},
>   	{"pktio mac",		test_odp_pktio_mac},
> +	{"pktio name",		test_odp_pktio_name},
>   	CU_TEST_INFO_NULL
>   };
>
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
index 0c34f29..c0ced4f 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -169,6 +169,19 @@  size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
 			  size_t addr_size);
 
 /**
+ * Packet IO interface name
+ *
+ * Return the interface name from a pktio handle. This is the
+ * name that was passed to the odp_pktio_open() call.
+ *
+ * @param id ODP Packet IO handle.
+ *
+ * @retval Pointer to the interface name.
+ * @retval NULL if packet handle is invalid.
+ */
+const char *odp_pktio_name(odp_pktio_t id);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index cd109d2..7b08edf 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -746,3 +746,14 @@  size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr,
 
 	return ETH_ALEN;
 }
+
+const char *odp_pktio_name(odp_pktio_t id)
+{
+	pktio_entry_t *entry;
+
+	entry = get_pktio_entry(id);
+	if (entry == NULL)
+		return NULL;
+
+	return entry->s.name;
+}
diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c
index d1eb0d5..dcbdee2 100644
--- a/test/validation/odp_pktio.c
+++ b/test/validation/odp_pktio.c
@@ -472,6 +472,24 @@  static void test_odp_pktio_mac(void)
 	return;
 }
 
+static void test_odp_pktio_name(void)
+{
+	odp_pktio_t pktio;
+	const char *name;
+	int ret;
+
+	pktio = create_pktio(iface_name[0]);
+	name = odp_pktio_name(pktio);
+
+	ret = strcmp(iface_name[0], name);
+	CU_ASSERT(0 == ret);
+
+	ret = odp_pktio_close(pktio);
+	CU_ASSERT(0 == ret);
+
+	return;
+}
+
 static void test_odp_pktio_open(void)
 {
 	odp_pktio_t pktio;
@@ -582,6 +600,7 @@  CU_TestInfo pktio_tests[] = {
 	{"pktio mtu",		test_odp_pktio_mtu},
 	{"pktio promisc mode",	test_odp_pktio_promisc},
 	{"pktio mac",		test_odp_pktio_mac},
+	{"pktio name",		test_odp_pktio_name},
 	CU_TEST_INFO_NULL
 };