Skip to contentSkip to conversation

net/tap: add support for fixed mac addresses

PATCH In review Keith Wiles 3 participants 17 messages Apr 10, 2017 – May 12, 2017 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/tap: add support for fixed mac addresses

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
 doc/guides/nics/tap.rst       | 13 +++++++++++-
 drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +12 -1
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
 ``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
 and so on.
 
 The interface name can be changed by adding the ``iface=foo0``, for example::
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
    --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with
+a static configurations the developer may need a fixed MAC address style.
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one
+each time for each interface string containing ``mac=fixed``. The MAC address
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex
+and you get ``00:64:74:61:70:[00-FF]``.
+
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
 
drivers/net/tap/rte_eth_tap.c +46 -3

98 lines not on this page · raw message

Signature · 1 line
2.12.1.430.gafd672630
#1 lore raw

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 25 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
 doc/guides/nics/tap.rst       | 13 +++++++++++-
 drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +1 -1
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
 ``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
 and so on.
 
 The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 61

Quoted 4 lines
doc/guides/nics/tap.rst +1 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
    --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with

"random MAC" -> "a random MAC"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 62

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+a static configurations the developer may need a fixed MAC address style.

"configurations" -> "configuration"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 67

Quoted 5 lines
doc/guides/nics/tap.rst +5 -0
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one

"be" -> "have a"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 68

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+each time for each interface string containing ``mac=fixed``. The MAC address

"each time" -> ""

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 69

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex

" convert" -> ". Convert"

Quoted 10 lines
doc/guides/nics/tap.rst +2 -0
+and you get ``00:64:74:61:70:[00-FF]``.
+
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
 
drivers/net/tap/rte_eth_tap.c +0 -0
index 347a80741..7a676c588 100644

drivers/net/tap/rte_eth_tap.c line 4

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.

Shouldn't it be "2016-2017"?

drivers/net/tap/rte_eth_tap.c line 74

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -0
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,13 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG		"mac"

You used tabs instead of spaces.

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

drivers/net/tap/rte_eth_tap.c static const char *valid_arguments[] = { · line 96

Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +2 -0
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)
@@ -81,10 +88,12 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
 static int tap_unit;
+static int fixed_mac_type;

There is no need for a global variable, especially as the value should not be the same for each driver instance. Typically when one tap uses "mac=fixed" and the next one doesn't.
More comments bellow for that.

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +1 -1
 static volatile uint32_t tap_trigger;	/* Rx trigger */
 
@@ -1230,7 +1239,17 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
 	} else {
-		eth_random_addr((uint8_t *)&pmd->eth_addr);
+		if (fixed_mac_type) {

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1252

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +10 -0
+			static int iface_idx;
+
+			pmd->eth_addr.addr_bytes[0] = 0x00;
+			pmd->eth_addr.addr_bytes[1] = 'd';
+			pmd->eth_addr.addr_bytes[2] = 't';
+			pmd->eth_addr.addr_bytes[3] = 'a';
+			pmd->eth_addr.addr_bytes[4] = 'p';
+			pmd->eth_addr.addr_bytes[5] = 0 + iface_idx++;
+		} else
+			eth_random_addr((uint8_t *)&pmd->eth_addr);

To avoid checkpatch warning, use else { }.

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1311

Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +5 -0
 	}
 
 	return 0;
@@ -1285,6 +1304,16 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
+static int
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
+{
+	/* Assume random mac address */
+	*(int *)extra_args = 0;

With an automatic variable for fixed_mac_type in rte_pmd_tap_probe(), no need for setting it to 0 here.

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1312

Quoted 1 line
drivers/net/tap/rte_eth_tap.c +1 -0
+	if (value && !strcasecmp("fixed", value))

I think a macro for "fixed" would be better. Maybe a ETH_TAP_MAC_FIXED "fixed" at the top?

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(const char *name, const char *params) · line 1333

Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +5 -0
+		*(int *)extra_args = 1;
+	return 0;
+}
+
 /* Open a TAP interface device.
  */
 static int
@@ -1301,6 +1330,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
 
+	fixed_mac_type = 0;

Turn fixed_mac_type to an automatic variable, local to this function. And add the argument to eth_dev_tap_create().

Quoted 20 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	if (params && (params[0] != '\0')) {
 		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
@@ -1332,6 +1362,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1394,4 +1433,8 @@ static struct rte_vdev_driver pmd_tap_drv = {
 };
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

That's it for me,
Thank you.

Pascal

#2 lore raw
Quoted 13 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 6 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

<...>

Quoted 10 lines

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 8 lines

RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);

drivers/net/tap/rte_eth_tap.c +5 -1
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

Hi Pascal,

If you can send a patch for this, it can be quickly merged, so it won't have to be in this patch.

Quoted 6 lines

That's it for me,
Thank you.

Pascal

#3 lore raw
In reply to Pascal Mazon
Quoted 91 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 25 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
doc/guides/nics/tap.rst | 13 +++++++++++-
drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---

2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 61

Quoted 4 lines
doc/guides/nics/tap.rst +1 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
   --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with

"random MAC" -> "a random MAC"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 62

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+a static configurations the developer may need a fixed MAC address style.

"configurations" -> "configuration"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 67

Quoted 5 lines
doc/guides/nics/tap.rst +5 -0
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one

"be" -> "have a"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 68

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+each time for each interface string containing ``mac=fixed``. The MAC address

"each time" -> ""

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 69

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex

" convert" -> ". Convert"

Quoted 10 lines
doc/guides/nics/tap.rst +2 -0
+and you get ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +0 -0
index 347a80741..7a676c588 100644

drivers/net/tap/rte_eth_tap.c line 4

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.

Shouldn't it be "2016-2017"?

drivers/net/tap/rte_eth_tap.c line 74

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -0
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,13 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG		"mac"

You used tabs instead of spaces.

Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

This should have been removed in your patch and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

Quoted 32 lines
Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)

drivers/net/tap/rte_eth_tap.c static const char *valid_arguments[] = { · line 96

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -81,10 +88,12 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
 static int tap_unit;
+static int fixed_mac_type;

There is no need for a global variable, especially as the value should not be the same for each driver instance. Typically when one tap uses "mac=fixed" and the next one doesn't.
More comments bellow for that.

Quoted 13 lines

static volatile uint32_t tap_trigger; /* Rx trigger */

drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1230,7 +1239,17 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
 	} else {
-		eth_random_addr((uint8_t *)&pmd->eth_addr);
+		if (fixed_mac_type) {
+			static int iface_idx;
+
+			pmd->eth_addr.addr_bytes[0] = 0x00;
+			pmd->eth_addr.addr_bytes[1] = 'd';
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1252

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+			pmd->eth_addr.addr_bytes[2] = 't';
+			pmd->eth_addr.addr_bytes[3] = 'a';
+			pmd->eth_addr.addr_bytes[4] = 'p';
+			pmd->eth_addr.addr_bytes[5] = 0 + iface_idx++;
+		} else
+			eth_random_addr((uint8_t *)&pmd->eth_addr);

To avoid checkpatch warning, use else { }.

Ferruh, states this is OK and does not need to have the { } added. I will not add the { } here.

Quoted 8 lines
Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 	}
 
 	return 0;
@@ -1285,6 +1304,16 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1311

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +5 -0
+static int
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
+{
+	/* Assume random mac address */
+	*(int *)extra_args = 0;

With an automatic variable for fixed_mac_type in rte_pmd_tap_probe(), no need for setting it to 0 here.

It does need to be set of each instance of the call to this routine even if I remove the global. Each interface can have a different state.

Quoted 4 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1312

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+	if (value && !strcasecmp("fixed", value))

I think a macro for "fixed" would be better. Maybe a ETH_TAP_MAC_FIXED "fixed" at the top?

I will use the already existing macro ETH_TAP_MAC_ARG instead.

Quoted 12 lines
Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+		*(int *)extra_args = 1;
+	return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +0 -0
@@ -1301,6 +1330,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
 
Quoted 4 lines

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(const char *name, const char *params) · line 1333

Quoted 1 line
drivers/net/tap/rte_eth_tap.c +1 -0
+	fixed_mac_type = 0;

Turn fixed_mac_type to an automatic variable, local to this function. And add the argument to eth_dev_tap_create().

Need to have the global to exist, because I need to be able to test the variable later. The variable could be placed in a allocated structure, but does it really matter to have a static variable here?

Quoted 33 lines
Quoted 21 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	if (params && (params[0] != '\0')) {
 		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
@@ -1332,6 +1362,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1394,4 +1433,8 @@ static struct rte_vdev_driver pmd_tap_drv = {
 };
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

Quoted 4 lines

That's it for me,
Thank you.

Pascal

Regards,
Keith

#4 lore raw
Quoted 166 lines · Keith
Quoted 92 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 25 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
doc/guides/nics/tap.rst | 13 +++++++++++-
drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---

2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 61

Quoted 4 lines
doc/guides/nics/tap.rst +1 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
  --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with

"random MAC" -> "a random MAC"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 62

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+a static configurations the developer may need a fixed MAC address style.

"configurations" -> "configuration"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 67

Quoted 5 lines
doc/guides/nics/tap.rst +5 -0
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one

"be" -> "have a"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 68

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+each time for each interface string containing ``mac=fixed``. The MAC address

"each time" -> ""

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 69

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex

" convert" -> ". Convert"

Quoted 10 lines
doc/guides/nics/tap.rst +2 -0
+and you get ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +0 -0
index 347a80741..7a676c588 100644

drivers/net/tap/rte_eth_tap.c line 4

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.

Shouldn't it be "2016-2017"?

drivers/net/tap/rte_eth_tap.c line 74

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -0
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,13 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG		"mac"

You used tabs instead of spaces.

Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

This should have been removed in your patch and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

Quoted 32 lines
Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)

drivers/net/tap/rte_eth_tap.c static const char *valid_arguments[] = { · line 96

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -81,10 +88,12 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
 static int tap_unit;
+static int fixed_mac_type;

There is no need for a global variable, especially as the value should not be the same for each driver instance. Typically when one tap uses "mac=fixed" and the next one doesn't.
More comments bellow for that.

Quoted 13 lines

static volatile uint32_t tap_trigger; /* Rx trigger */

drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1230,7 +1239,17 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
 	} else {
-		eth_random_addr((uint8_t *)&pmd->eth_addr);
+		if (fixed_mac_type) {
+			static int iface_idx;
+
+			pmd->eth_addr.addr_bytes[0] = 0x00;
+			pmd->eth_addr.addr_bytes[1] = 'd';
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1252

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+			pmd->eth_addr.addr_bytes[2] = 't';
+			pmd->eth_addr.addr_bytes[3] = 'a';
+			pmd->eth_addr.addr_bytes[4] = 'p';
+			pmd->eth_addr.addr_bytes[5] = 0 + iface_idx++;
+		} else
+			eth_random_addr((uint8_t *)&pmd->eth_addr);

To avoid checkpatch warning, use else { }.

Ferruh, states this is OK and does not need to have the { } added. I will not add the { } here.

Quoted 8 lines
Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 	}
 
 	return 0;
@@ -1285,6 +1304,16 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1311

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +5 -0
+static int
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
+{
+	/* Assume random mac address */
+	*(int *)extra_args = 0;

With an automatic variable for fixed_mac_type in rte_pmd_tap_probe(), no need for setting it to 0 here.

Quoted 8 lines

It does need to be set of each instance of the call to this routine even if I remove the global. Each interface can have a different state.

Quoted 4 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1312

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+	if (value && !strcasecmp("fixed", value))

I think a macro for "fixed" would be better. Maybe a ETH_TAP_MAC_FIXED "fixed" at the top?

I will use the already existing macro ETH_TAP_MAC_ARG instead.

Opps! I will need a macros for this one.

Quoted 52 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+		*(int *)extra_args = 1;
+	return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +0 -0
@@ -1301,6 +1330,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
 
Quoted 4 lines

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(const char *name, const char *params) · line 1333

Quoted 1 line
drivers/net/tap/rte_eth_tap.c +1 -0
+	fixed_mac_type = 0;

Turn fixed_mac_type to an automatic variable, local to this function. And add the argument to eth_dev_tap_create().

Need to have the global to exist, because I need to be able to test the variable later. The variable could be placed in a allocated structure, but does it really matter to have a static variable here?

Quoted 33 lines
Quoted 21 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	if (params && (params[0] != '\0')) {
 		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
@@ -1332,6 +1362,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1394,4 +1433,8 @@ static struct rte_vdev_driver pmd_tap_drv = {
 };
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

Quoted 8 lines
Quoted 4 lines

That's it for me,
Thank you.

Pascal

Regards,
Keith

Regards,
Keith

#5 lore raw
In reply to Wiles, Keith
Quoted 16 lines · Keith
Quoted 16 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 6 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

<...>

Quoted 10 lines
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

This should have been removed in your patch

That is already done, and patch is in main repo:

Fixes 947d949de7de ("net/tap: fix max queues redefinition")
Quoted 1 line

and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

Pascal already send the patch and it is in next-net now:

Fixes f0e5085f4677 ("net/tap: update driver param string")
Quoted 2 lines

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

There is no more updated expected, using latest next-net should be OK to submit your patch.

Thanks,
ferruh

#6 lore raw
Quoted 39 lines · Ferruh
Quoted 16 lines · Keith
Quoted 16 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 6 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

<...>

Quoted 10 lines
Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

This should have been removed in your patch

That is already done, and patch is in main repo:

Fixes 947d949de7de ("net/tap: fix max queues redefinition")
Quoted 1 line

and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

Quoted 8 lines

Pascal already send the patch and it is in next-net now:

Fixes f0e5085f4677 ("net/tap: update driver param string")
Quoted 2 lines

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

There is no more updated expected, using latest next-net should be OK to submit your patch.

OK

Quoted 3 lines

Thanks,
ferruh

Regards,
Keith

#7 lore raw
In reply to Wiles, Keith
Quoted 100 lines · Keith
Quoted 91 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 25 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
doc/guides/nics/tap.rst | 13 +++++++++++-
drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---

2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 61

Quoted 4 lines
doc/guides/nics/tap.rst +1 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
   --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with

"random MAC" -> "a random MAC"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 62

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+a static configurations the developer may need a fixed MAC address style.

"configurations" -> "configuration"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 67

Quoted 5 lines
doc/guides/nics/tap.rst +5 -0
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one

"be" -> "have a"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 68

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+each time for each interface string containing ``mac=fixed``. The MAC address

"each time" -> ""

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 69

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex

" convert" -> ". Convert"

Quoted 10 lines
doc/guides/nics/tap.rst +2 -0
+and you get ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +0 -0
index 347a80741..7a676c588 100644

drivers/net/tap/rte_eth_tap.c line 4

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.

Shouldn't it be "2016-2017"?

drivers/net/tap/rte_eth_tap.c line 74

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -0
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,13 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG		"mac"

You used tabs instead of spaces.

Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

Quoted 3 lines

This should have been removed in your patch and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

Ferruh details how it's been integrated in next-net, nothing to add there :)

Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)

drivers/net/tap/rte_eth_tap.c static const char *valid_arguments[] = { · line 96

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -81,10 +88,12 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
 static int tap_unit;
+static int fixed_mac_type;

There is no need for a global variable, especially as the value should not be the same for each driver instance. Typically when one tap uses "mac=fixed" and the next one doesn't.
More comments bellow for that.

Quoted 3 lines

static volatile uint32_t tap_trigger; /* Rx trigger */

Quoted 7 lines
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1243

Quoted 7 lines
drivers/net/tap/rte_eth_tap.c +2 -1
@@ -1230,7 +1239,17 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
 	} else {
-		eth_random_addr((uint8_t *)&pmd->eth_addr);
+		if (fixed_mac_type) {
+			static int iface_idx;

I'd suggest using something like this, as there's no need for so much lines to do the same:

char mac[ETHER_ADDR_LEN] = "\x00\x64\x74\x61\x70\x00"; /* 0:d:t:a:p:0 */

mac[ETHER_ADDR_LEN-1] = iface_idx++;
rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);

Quoted 12 lines
Quoted 11 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1252

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +9 -0
+
+			pmd->eth_addr.addr_bytes[0] = 0x00;
+			pmd->eth_addr.addr_bytes[1] = 'd';
+			pmd->eth_addr.addr_bytes[2] = 't';
+			pmd->eth_addr.addr_bytes[3] = 'a';
+			pmd->eth_addr.addr_bytes[4] = 'p';
+			pmd->eth_addr.addr_bytes[5] = 0 + iface_idx++;
+		} else
+			eth_random_addr((uint8_t *)&pmd->eth_addr);

To avoid checkpatch warning, use else { }.

Quoted 1 line

Ferruh, states this is OK and does not need to have the { } added. I will not add the { } here.

Very well!

Quoted 37 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 	}
 
 	return 0;
@@ -1285,6 +1304,16 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1311

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +5 -0
+static int
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
+{
+	/* Assume random mac address */
+	*(int *)extra_args = 0;

With an automatic variable for fixed_mac_type in rte_pmd_tap_probe(), no need for setting it to 0 here.

It does need to be set of each instance of the call to this routine even if I remove the global. Each interface can have a different state.

Quoted 4 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1312

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+	if (value && !strcasecmp("fixed", value))

I think a macro for "fixed" would be better. Maybe a ETH_TAP_MAC_FIXED "fixed" at the top?

I will use the already existing macro ETH_TAP_MAC_ARG instead.

Quoted 12 lines
Quoted 12 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+		*(int *)extra_args = 1;
+	return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +0 -0
@@ -1301,6 +1330,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
 
Quoted 6 lines
Quoted 4 lines

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(const char *name, const char *params) · line 1333

Quoted 1 line
drivers/net/tap/rte_eth_tap.c +1 -0
+	fixed_mac_type = 0;

Turn fixed_mac_type to an automatic variable, local to this function. And add the argument to eth_dev_tap_create().

Need to have the global to exist, because I need to be able to test the variable later. The variable could be placed in a allocated structure, but does it really matter to have a static variable here?

I disagree here, I've seen fixed_mac_type only used during probing, in rte_pmd_tap_probe() and rte_eth_dev_tap_create().
The case is similar to the "iface" param, we need it during probing, where it is used appropriately (either setting the pmd->eth_addr for your fixed mac, or setting pmd->remote_iface for iface).

Quoted 42 lines
Quoted 34 lines
Quoted 22 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	if (params && (params[0] != '\0')) {
 		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
@@ -1332,6 +1362,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1394,4 +1433,8 @@ static struct rte_vdev_driver pmd_tap_drv = {
 };
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

Quoted 4 lines

That's it for me,
Thank you.

Pascal

Regards,
Keith

#8 lore raw
Quoted 145 lines · Pascal Mazon
Quoted 100 lines · Keith
Quoted 91 lines · Pascal Mazon

Hi Keith,

I have a few comments on your patch, see inline.

Quoted 25 lines · On Mon, 10 Apr 2017 13:18:50 -0500 Keith Wiles <[email protected]> wrote:

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---
doc/guides/nics/tap.rst | 13 +++++++++++-
drivers/net/tap/rte_eth_tap.c | 49 ++++++++++++++++++++++++++++++++++++++++---

2 files changed, 58 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357..e3819836a 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 61

Quoted 4 lines
doc/guides/nics/tap.rst +1 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
  --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate random MAC address, but when testing or with

"random MAC" -> "a random MAC"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 62

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+a static configurations the developer may need a fixed MAC address style.

"configurations" -> "configuration"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 67

Quoted 5 lines
doc/guides/nics/tap.rst +5 -0
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will be fixed value with the last octet incrementing by one

"be" -> "have a"

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 68

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+each time for each interface string containing ``mac=fixed``. The MAC address

"each time" -> ""

doc/guides/nics/tap.rst needed, but the interface does not enforce that speed, for example:: · line 69

Quoted 1 line
doc/guides/nics/tap.rst +1 -0
+is formatted as 00:'d':'t':'a':'p':[00-FF] convert the characters to hex

" convert" -> ". Convert"

Quoted 10 lines
doc/guides/nics/tap.rst +2 -0
+and you get ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +0 -0
index 347a80741..7a676c588 100644

drivers/net/tap/rte_eth_tap.c line 4

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.

Shouldn't it be "2016-2017"?

drivers/net/tap/rte_eth_tap.c line 74

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -0
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,13 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG		"mac"

You used tabs instead of spaces.

Quoted 8 lines

drivers/net/tap/rte_eth_tap.c line 80

Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +6 -0
+
+#ifdef IFF_MULTI_QUEUE
+#define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif

Remove this IFF_MULTI_QUEUE definition as it is done in rte_eth_tap.h now (needed for pmd_internals).

Quoted 3 lines

This should have been removed in your patch and now that Ferruh wants you to submit a patch for the string at the bottom of the PMD, can you remove it?

I can do both in my patch, but Ferruh and you need to agree before I can submit my patch.

Ferruh details how it's been integrated in next-net, nothing to add there :)

Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)

drivers/net/tap/rte_eth_tap.c static const char *valid_arguments[] = { · line 96

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -81,10 +88,12 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
 static int tap_unit;
+static int fixed_mac_type;

There is no need for a global variable, especially as the value should not be the same for each driver instance. Typically when one tap uses "mac=fixed" and the next one doesn't.
More comments bellow for that.

Quoted 3 lines

static volatile uint32_t tap_trigger; /* Rx trigger */

Quoted 7 lines
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1243

Quoted 7 lines
drivers/net/tap/rte_eth_tap.c +2 -1
@@ -1230,7 +1239,17 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
 	} else {
-		eth_random_addr((uint8_t *)&pmd->eth_addr);
+		if (fixed_mac_type) {
+			static int iface_idx;

I'd suggest using something like this, as there's no need for so much lines to do the same:

Quoted 4 lines

char mac[ETHER_ADDR_LEN] = "\x00\x64\x74\x61\x70\x00"; /* 0:d:t:a:p:0 */

mac[ETHER_ADDR_LEN-1] = iface_idx++;
rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);

Here is the above code:

			static int iface_idx;
			char mac[ETHER_ADDR_LEN] =
				"\x00\x64\x74\x61\x70\x00"; /* 0:d:t:a:p:0 */
			mac[ETHER_ADDR_LEN - 1] = iface_idx++;
			rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);

Not much in the way of fewer lines and not really that readable, so your objection here is only that you would have coded it differently not that it is incorrect, right? Personally I like the code below as it is easier to ready IMHO, but I will covert it your suggestion.

Quoted 60 lines
Quoted 14 lines
Quoted 13 lines

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1252

Quoted 11 lines
drivers/net/tap/rte_eth_tap.c +9 -0
+
+			pmd->eth_addr.addr_bytes[0] = 0x00;
+			pmd->eth_addr.addr_bytes[1] = 'd';
+			pmd->eth_addr.addr_bytes[2] = 't';
+			pmd->eth_addr.addr_bytes[3] = 'a';
+			pmd->eth_addr.addr_bytes[4] = 'p';
+			pmd->eth_addr.addr_bytes[5] = 0 + iface_idx++;
+		} else
+			eth_random_addr((uint8_t *)&pmd->eth_addr);

To avoid checkpatch warning, use else { }.

Quoted 1 line

Ferruh, states this is OK and does not need to have the { } added. I will not add the { } here.

Very well!

Quoted 42 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +0 -0
 	}
 
 	return 0;
@@ -1285,6 +1304,16 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
Quoted 7 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1311

Quoted 5 lines
drivers/net/tap/rte_eth_tap.c +5 -0
+static int
+set_mac_type(const char *key __rte_unused, const char *value, void *extra_args)
+{
+	/* Assume random mac address */
+	*(int *)extra_args = 0;

With an automatic variable for fixed_mac_type in rte_pmd_tap_probe(), no need for setting it to 0 here.

It does need to be set of each instance of the call to this routine even if I remove the global. Each interface can have a different state.

Quoted 4 lines

drivers/net/tap/rte_eth_tap.c set_remote_iface(const char *key __rte_unused, · line 1312

Quoted 2 lines
drivers/net/tap/rte_eth_tap.c +1 -0
+	if (value && !strcasecmp("fixed", value))

I think a macro for "fixed" would be better. Maybe a ETH_TAP_MAC_FIXED "fixed" at the top?

I will use the already existing macro ETH_TAP_MAC_ARG instead.

Quoted 16 lines

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_probe(const char *name, const char *params) · line 1333

Quoted 13 lines
drivers/net/tap/rte_eth_tap.c +4 -0
+		*(int *)extra_args = 1;
+	return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +1 -0
@@ -1301,6 +1330,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
 
+	fixed_mac_type = 0;

Turn fixed_mac_type to an automatic variable, local to this function. And add the argument to eth_dev_tap_create().

Quoted 4 lines
Quoted 1 line

Need to have the global to exist, because I need to be able to test the variable later. The variable could be placed in a allocated structure, but does it really matter to have a static variable here?

I disagree here, I've seen fixed_mac_type only used during probing, in rte_pmd_tap_probe() and rte_eth_dev_tap_create().
The case is similar to the "iface" param, we need it during probing, where it is used appropriately (either setting the pmd->eth_addr for your fixed mac, or setting pmd->remote_iface for iface).

This code is not really close to “iface” code as the iface code has a place to put the string in the pmd structure and the pmd->eth_addr is setup later on in the code. I would have to add a holding place in the pmd structure to hold the random or fixed mac address or flag to be used in the routine eth_dev_tap_create().

Maybe I am just being slow this morning, but I do not see how you want the code to be done here as I do not see away around a flag someplace.

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 23 lines
drivers/net/tap/rte_eth_tap.c +9 -0
 	if (params && (params[0] != '\0')) {
 		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
@@ -1332,6 +1362,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;

drivers/net/tap/rte_eth_tap.c static struct rte_vdev_driver pmd_tap_drv = { · line 1440

Quoted 9 lines
drivers/net/tap/rte_eth_tap.c +5 -1
@@ -1394,4 +1433,8 @@ static struct rte_vdev_driver pmd_tap_drv = {
 };
 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
-RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");
+RTE_PMD_REGISTER_PARAM_STRING(net_tap,
+			      "iface=<string>,"
+			      "speed=N,"
+			      "remote=<string>,"
+			      "mac=fixed");

Indeed, I forgot to update that when I introduced the remote!

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

That's it for me,
Thank you.

Pascal

Regards,
Keith

Regards,
Keith

#9 lore raw

PATCH 1/1 net/tap: add support for fixed mac addresses

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---

Hi Keith, I've made the changes I suggested.

It does as expected use a mac incremented by 1 for each new tap device, without a global variable for fixed_mac_type.

With the more clean "\0dtap" initialization for mac[], I do think it looks better, don't you?
I agree my version with \x did little improvement to yours, and would be a question of style.
What do you say of this patch?

 doc/guides/nics/tap.rst       | 13 ++++++++++++-
 drivers/net/tap/rte_eth_tap.c | 39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +12 -1
index 5c5ba5357bba..f3ee95d2897b 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
 ``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
 and so on.
 
 The interface name can be changed by adding the ``iface=foo0``, for example::
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
    --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate a random MAC address, but when testing or with
+a static configuration the developer may need a fixed MAC address style.
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will have a fixed value with the last octet incrementing by one
+for each interface string containing ``mac=fixed``. The MAC address is formatted
+as 00:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
+actual MAC address: ``00:64:74:61:70:[00-FF]``.
+
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
 
drivers/net/tap/rte_eth_tap.c +36 -3
index cd82a7e09c75..2092f5d4184b 100644
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,8 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG         "mac"
+#define ETH_TAP_MAC_FIXED       "fixed"
 
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)
@@ -81,6 +83,7 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
@@ -1131,7 +1134,8 @@ tap_kernel_support(struct pmd_internals *pmd)
 }
 
 static int
-eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
+eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface,
+		   int fixed_mac_type)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev = NULL;
@@ -1229,6 +1233,13 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		}
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
+	} else if (fixed_mac_type) {
+		/* fixed mac = 00:64:74:61:70:<iface_idx> */
+		static int iface_idx;
+		char mac[ETHER_ADDR_LEN] = "\0dtap";
+
+		mac[ETHER_ADDR_LEN - 1] = iface_idx++;
+		rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);
 	} else {
 		eth_random_addr((uint8_t *)&pmd->eth_addr);
 	}
@@ -1285,6 +1296,17 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
+static int
+set_mac_type(const char *key __rte_unused,
+	     const char *value,
+	     void *extra_args)
+{
+	if (value &&
+	    !strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED)))
+		*(int *)extra_args = 1;
+       return 0;
+}
+
 /* Open a TAP interface device.
  */
 static int
@@ -1295,6 +1317,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	int fixed_mac_type = 0;
 
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
@@ -1332,6 +1355,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;
@@ -1339,7 +1371,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(name, tap_name, remote_iface);
+	ret = eth_dev_tap_create(name, tap_name, remote_iface, fixed_mac_type);
 
 leave:
 	if (ret == -1) {
@@ -1397,4 +1429,5 @@ RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
 RTE_PMD_REGISTER_PARAM_STRING(net_tap,
 			      ETH_TAP_IFACE_ARG "=<string> "
 			      ETH_TAP_SPEED_ARG "=<int> "
+			      ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " "
 			      ETH_TAP_REMOTE_ARG "=<string>");
Signature · 1 line
2.12.0.306.g4a9b9b3
#10 lore raw
Quoted 14 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---

Hi Keith, I've made the changes I suggested.

Quoted 8 lines

It does as expected use a mac incremented by 1 for each new tap device, without a global variable for fixed_mac_type.

With the more clean "\0dtap" initialization for mac[], I do think it looks better, don't you?
I agree my version with \x did little improvement to yours, and would be a question of style.
What do you say of this patch?

The patch looks fine, I guess I did not want to change the function API (for some strange reason), but I agree removing the static works.

I can remove my patch and allow this one to replace it.

Quoted 150 lines

doc/guides/nics/tap.rst | 13 ++++++++++++-
drivers/net/tap/rte_eth_tap.c | 39 ++++++++++++++++++++++++++++++++++++---

2 files changed, 48 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357bba..f3ee95d2897b 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst +11 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
   --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate a random MAC address, but when testing or with
+a static configuration the developer may need a fixed MAC address style.
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will have a fixed value with the last octet incrementing by one
+for each interface string containing ``mac=fixed``. The MAC address is formatted
+as 00:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
+actual MAC address: ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +4 -1
index cd82a7e09c75..2092f5d4184b 100644
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,8 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG         "mac"
+#define ETH_TAP_MAC_FIXED       "fixed"
 
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)
@@ -81,6 +83,7 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
@@ -1131,7 +1134,8 @@ tap_kernel_support(struct pmd_internals *pmd)
 }
 

static int

drivers/net/tap/rte_eth_tap.c +2 -1
-eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
+eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface,
+		   int fixed_mac_type)
{
	int numa_node = rte_socket_id();
	struct rte_eth_dev *dev = NULL;
drivers/net/tap/rte_eth_tap.c +18 -0
@@ -1229,6 +1233,13 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		}
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);
+	} else if (fixed_mac_type) {
+		/* fixed mac = 00:64:74:61:70:<iface_idx> */
+		static int iface_idx;
+		char mac[ETHER_ADDR_LEN] = "\0dtap";
+
+		mac[ETHER_ADDR_LEN - 1] = iface_idx++;
+		rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);
 	} else {
 		eth_random_addr((uint8_t *)&pmd->eth_addr);
 	}
@@ -1285,6 +1296,17 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
+static int
+set_mac_type(const char *key __rte_unused,
+	     const char *value,
+	     void *extra_args)
+{
+	if (value &&
+	    !strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED)))
+		*(int *)extra_args = 1;
+       return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +11 -1
@@ -1295,6 +1317,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	int fixed_mac_type = 0;
 
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
@@ -1332,6 +1355,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;
@@ -1339,7 +1371,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(name, tap_name, remote_iface);
+	ret = eth_dev_tap_create(name, tap_name, remote_iface, fixed_mac_type);
 

leave:

	if (ret == -1) {
drivers/net/tap/rte_eth_tap.c +1 -0
@@ -1397,4 +1429,5 @@ RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
 RTE_PMD_REGISTER_PARAM_STRING(net_tap,
 			      ETH_TAP_IFACE_ARG "=<string> "
 			      ETH_TAP_SPEED_ARG "=<int> "
+			      ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " "
 			      ETH_TAP_REMOTE_ARG "=<string>");
Signature · 1 line
2.12.0.306.g4a9b9b3

Regards,
Keith

#11 lore raw
In reply to Pascal Mazon
Quoted 102 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---

Hi Keith, I've made the changes I suggested.

It does as expected use a mac incremented by 1 for each new tap device, without a global variable for fixed_mac_type.

With the more clean "\0dtap" initialization for mac[], I do think it looks better, don't you?
I agree my version with \x did little improvement to yours, and would be a question of style.
What do you say of this patch?

doc/guides/nics/tap.rst | 13 ++++++++++++-
drivers/net/tap/rte_eth_tap.c | 39 ++++++++++++++++++++++++++++++++++++---

2 files changed, 48 insertions(+), 4 deletions(-)
doc/guides/nics/tap.rst +0 -0
index 5c5ba5357bba..f3ee95d2897b 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK

along with being able to be used as a network connection to the DPDK application. The method enable one or more interfaces is to use the ``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1, +``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, and so on.

The interface name can be changed by adding the ``iface=foo0``, for example::

doc/guides/nics/tap.rst +11 -0
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
   --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate a random MAC address, but when testing or with
+a static configuration the developer may need a fixed MAC address style.
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will have a fixed value with the last octet incrementing by one
+for each interface string containing ``mac=fixed``. The MAC address is formatted
+as 00:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
+actual MAC address: ``00:64:74:61:70:[00-FF]``.
+

It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::

drivers/net/tap/rte_eth_tap.c +4 -1
index cd82a7e09c75..2092f5d4184b 100644
@@ -1,7 +1,7 @@
 /*-
 *   BSD LICENSE
 *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,8 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 #define ETH_TAP_REMOTE_ARG      "remote"
+#define ETH_TAP_MAC_ARG         "mac"
+#define ETH_TAP_MAC_FIXED       "fixed"
 
 #define FLOWER_KERNEL_VERSION KERNEL_VERSION(4, 2, 0)
 #define FLOWER_VLAN_KERNEL_VERSION KERNEL_VERSION(4, 9, 0)
@@ -81,6 +83,7 @@ static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_SPEED_ARG,
 	ETH_TAP_REMOTE_ARG,
+	ETH_TAP_MAC_ARG,
 	NULL
 };
 
@@ -1131,7 +1134,8 @@ tap_kernel_support(struct pmd_internals *pmd)
 }
 

static int

drivers/net/tap/rte_eth_tap.c +2 -1
-eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
+eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface,
+		   int fixed_mac_type)
{
	int numa_node = rte_socket_id();
	struct rte_eth_dev *dev = NULL;
drivers/net/tap/rte_eth_tap.c +0 -0
@@ -1229,6 +1233,13 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		}
 		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
 			   ETHER_ADDR_LEN);

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) · line 1245

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +7 -0
+	} else if (fixed_mac_type) {
+		/* fixed mac = 00:64:74:61:70:<iface_idx> */
+		static int iface_idx;
+		char mac[ETHER_ADDR_LEN] = "\0dtap";
+
+		mac[ETHER_ADDR_LEN - 1] = iface_idx++;
+		rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN);
 	} else {
 		eth_random_addr((uint8_t *)&pmd->eth_addr);
 	}

This does not show up as a change in the patch, I thought it should.

Quoted 60 lines
drivers/net/tap/rte_eth_tap.c +11 -0
@@ -1285,6 +1296,17 @@ set_remote_iface(const char *key __rte_unused,
 	return 0;
 }
 
+static int
+set_mac_type(const char *key __rte_unused,
+	     const char *value,
+	     void *extra_args)
+{
+	if (value &&
+	    !strncasecmp(ETH_TAP_MAC_FIXED, value, strlen(ETH_TAP_MAC_FIXED)))
+		*(int *)extra_args = 1;
+       return 0;
+}
+
 /* Open a TAP interface device.
 */

static int

drivers/net/tap/rte_eth_tap.c +11 -1
@@ -1295,6 +1317,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
+	int fixed_mac_type = 0;
 
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
@@ -1332,6 +1355,15 @@ rte_pmd_tap_probe(const char *name, const char *params)
 				if (ret == -1)
 					goto leave;
 			}
+
+			if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) {
+				ret = rte_kvargs_process(kvlist,
+							 ETH_TAP_MAC_ARG,
+							 &set_mac_type,
+							 &fixed_mac_type);
+				if (ret == -1)
+					goto leave;
+			}
 		}
 	}
 	pmd_link.link_speed = speed;
@@ -1339,7 +1371,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(name, tap_name, remote_iface);
+	ret = eth_dev_tap_create(name, tap_name, remote_iface, fixed_mac_type);
 

leave:

	if (ret == -1) {
drivers/net/tap/rte_eth_tap.c +1 -0
@@ -1397,4 +1429,5 @@ RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
 RTE_PMD_REGISTER_PARAM_STRING(net_tap,
 			      ETH_TAP_IFACE_ARG "=<string> "
 			      ETH_TAP_SPEED_ARG "=<int> "
+			      ETH_TAP_MAC_ARG "=" ETH_TAP_MAC_FIXED " "
 			      ETH_TAP_REMOTE_ARG "=<string>");
Signature · 1 line
2.12.0.306.g4a9b9b3

Regards,
Keith

#12 lore raw
Quoted 9 lines · Keith
Quoted 9 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

<...>

Quoted 1 line

This does not show up as a change in the patch, I thought it should.

It does: http://dpdk.org/dev/patchwork/patch/23508/

author Acked-by Keith Wiles on v1 1/1
#13 lore raw
In reply to Pascal Mazon
Quoted 11 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

—

Just to be clear:

Regards,
Keith

#14 lore raw

PATCH v2 1/1 net/tap: add support for fixed mac addresses

In reply to Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

---

v2:
- fix spaces instead of tab in front of a return
- MAC address generation should happen before checking for flower support. Otherwise the address could be unset with old kernels.

 doc/guides/nics/tap.rst       | 13 ++++++++++++-
 drivers/net/tap/rte_eth_tap.c | 45 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 52 insertions(+), 6 deletions(-)
doc/guides/nics/tap.rst +12 -1
index 5c5ba5357bba..f3ee95d2897b 100644
@@ -46,7 +46,7 @@ These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
 ``--vdev=net_tap0`` option on the DPDK application command line. Each
-``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1,
 and so on.
 
 The interface name can be changed by adding the ``iface=foo0``, for example::
@@ -58,6 +58,17 @@ needed, but the interface does not enforce that speed, for example::
 
    --vdev=net_tap0,iface=foo0,speed=25000
 
+Normally the PMD will generate a random MAC address, but when testing or with
+a static configuration the developer may need a fixed MAC address style.
+Using the option ``mac=fixed`` you can create a fixed known MAC address::
+
+   --vdev=net_tap0,mac=fixed
+
+The MAC address will have a fixed value with the last octet incrementing by one
+for each interface string containing ``mac=fixed``. The MAC address is formatted
+as 00:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the
+actual MAC address: ``00:64:74:61:70:[00-FF]``.
+
 It is possible to specify a remote netdevice to capture packets from by adding
 ``remote=foo1``, for example::
 
drivers/net/tap/rte_eth_tap.c +40 -5

109 lines not on this page · raw message

Signature · 1 line
2.12.0.306.g4a9b9b3
#15 lore raw
Quoted 8 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

Quoted 7 lines

---

v2:
- fix spaces instead of tab in front of a return
- MAC address generation should happen before checking for flower support. Otherwise the address could be unset with old kernels.

Thanks for the patch, this will be considered for 17.08

Applied
#16 lore raw
In reply to Pascal Mazon
Quoted 8 lines · Pascal Mazon

Support for a fixed MAC address for testing with the last octet incrementing by one for each interface defined with the new 'mac=fixed' string on the --vdev option. The default option is still to randomize the MAC address for each tap interface.

Applied to dpdk-next-net/master, thanks.