From patchwork Thu Dec 8 12:16:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Przemyslaw Lal X-Patchwork-Id: 704035 X-Patchwork-Delegate: diproiettod@vmware.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tZDqw5qYDz9t1T for ; Thu, 8 Dec 2016 23:16:44 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1CBE2B4C; Thu, 8 Dec 2016 12:16:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 35E2295E for ; Thu, 8 Dec 2016 12:16:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B32F813C for ; Thu, 8 Dec 2016 12:16:39 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP; 08 Dec 2016 04:16:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,319,1477983600"; d="scan'208";a="38218446" Received: from tandberg-mobl1.ger.corp.intel.com (HELO plalx-MOBL.ger.corp.intel.com) ([10.252.43.197]) by orsmga004.jf.intel.com with ESMTP; 08 Dec 2016 04:16:37 -0800 From: Przemyslaw Lal To: dev@openvswitch.org Date: Thu, 8 Dec 2016 13:16:22 +0100 Message-Id: <20161208121622.36200-1-przemyslawx.lal@intel.com> X-Mailer: git-send-email 2.8.3 X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Przemyslaw Lal Subject: [ovs-dev] [PATCH V2] netdev-dpdk: fix ifindex assignment for DPDK ports X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 infindexes 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 --- lib/netdev-dpdk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index de78ddd..ef99eb3 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -2075,7 +2075,13 @@ netdev_dpdk_get_ifindex(const struct netdev *netdev) int ifindex; ovs_mutex_lock(&dev->mutex); - ifindex = dev->port_id; + /* Calculate hash from the netdev name using hash_bytes() function. + * Because ifindex is declared as signed int in the kernel sources and + * OVS follows this implementation right shift is needed to set sign bit + * to 0 and then XOR to slightly improve collision rate. + */ + uint32_t h = hash_bytes(netdev->name, strlen(netdev->name), 0); + ifindex = (int)((h >> 1) ^ (h & 0x0FFFFFFF)); ovs_mutex_unlock(&dev->mutex); return ifindex;