[ovs-dev] [PATCH v3] netdev-dpdk: fix ifindex assignment for DPDK ports

Przemyslaw Lal przemyslawx.lal at intel.com
Tue Mar 28 10:04:33 UTC 2017


In current implementation port_id is used as an ifindex for all netdev-dpdk
interfaces.

For physical DPDK interfaces using port_id as ifindex causes that '0' is set as
ifindex for 'dpdk0' interface, '1' for 'dpdk1' and so on. For the DPDK vHost
interfaces ifindexes are not even assigned (0 is used by default) due to the
fact that vHost ports don't use port_id field from the DPDK library.

This causes multiple negative side-effects. First of all 0 is an invalid
ifindex value. The other issue is possible overlapping of 'dpdkX' interfaces
ifindex values with the ifindexes of kernel space interfaces which may cause
problems in any external tools that use those values. Neither 'dpdk0', nor any
DPDK vHost interfaces are visible in sFlow collector tools, as all interfaces
with ifindexes smaller than 1 are ignored.

Proposed solution to these issues is to calculate a hash of interface's name
and use calculated value as an ifindex. This way interfaces keep their
ifindexes during OVS-DPDK restarts, ports re-initialization events, etc., show
up in sFlow collectors and meet RFC2863 specification regarding re-using
ifindex values by the same virtual interfaces.

Signed-off-by: Przemyslaw Lal <przemyslawx.lal at intel.com>
---
 lib/netdev-dpdk.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index ddc651b..d3b2184 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2216,6 +2216,12 @@ netdev_dpdk_get_ifindex(const struct netdev *netdev)
 
     ovs_mutex_lock(&dev->mutex);
     ifindex = dev->port_id;
+    /* Calculate hash from the netdev name. Ensure that ifindex is non-negative
+     * integer, XOR to improve collision rate after right shift and ensure that
+     * calculated value is 1 or larger.
+     */
+    uint32_t h = hash_string(netdev->name, 0);
+    ifindex = (int)(((h >> 1) ^ (h & 0x7fffffff)) % 0x7ffffffe + 1);
     ovs_mutex_unlock(&dev->mutex);
 
     return ifindex;
-- 
1.9.1



More information about the dev mailing list