From patchwork Mon Sep 25 14:44:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 818265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3y16Ll70nnz9tXC for ; Tue, 26 Sep 2017 00:45:03 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9ECE6B5E; Mon, 25 Sep 2017 14:44:24 +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 184E3B55 for ; Mon, 25 Sep 2017 14:44:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5B8674BD for ; Mon, 25 Sep 2017 14:44:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA55B128B for ; Mon, 25 Sep 2017 14:44:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA55B128B Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=tredaelli@redhat.com Received: from graphite.mxp.redhat.com (unknown [10.32.181.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DF5D6F137 for ; Mon, 25 Sep 2017 14:44:20 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Mon, 25 Sep 2017 16:44:04 +0200 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 25 Sep 2017 14:44:20 +0000 (UTC) X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 1/3] ovs-save: Use --bundle to restore flows (on OpenFlow 1.4+) 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 If possible, use OpenFlow 1.4 atomic bundle transaction to restore flows. The patch uses also the highest enabled OpenFlow version to do the queries. With the actual implementation, if you have the default OpenFlow version disabled then ovs-save fails. This patch also fixes that problem. Signed-off-by: Timothy Redaelli Acked-by: Flavio Leitner --- utilities/ovs-save | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/utilities/ovs-save b/utilities/ovs-save index 8b8dbf421..fc9418c3d 100755 --- a/utilities/ovs-save +++ b/utilities/ovs-save @@ -99,6 +99,11 @@ save_interfaces () { fi } +get_highest_ofp_version() { + ovs-vsctl get bridge "$1" protocols | \ + awk -F '"' '{ print (NF>1)? $(NF-1) : "OpenFlow14" }' +} + save_flows () { if (ovs-ofctl --version) > /dev/null 2>&1; then :; else echo "$0: ovs-ofctl not found in $PATH" >&2 @@ -106,15 +111,26 @@ save_flows () { fi for bridge in "$@"; do + # Get the highest enabled OpenFlow version + ofp_version=$(get_highest_ofp_version "$bridge") + echo -n "ovs-ofctl add-tlv-map ${bridge} '" ovs-ofctl dump-tlv-map ${bridge} | \ awk '/^ 0x/ {if (cnt != 0) printf ","; \ cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}' echo "'" - echo "ovs-ofctl add-flows ${bridge} - << EOF" - ovs-ofctl dump-flows "${bridge}" | sed -e '/NXST_FLOW/d' \ - -e 's/\(idle\|hard\)_age=[^,]*,//g' + echo -n "ovs-ofctl -O $ofp_version add-flows ${bridge} " + + # If possible, use OpenFlow 1.4 atomic bundle transaction to add flows + [ ${ofp_version#OpenFlow} -ge 14 ] && echo -n "--bundle " + + echo "- << EOF" + + ovs-ofctl -O $ofp_version dump-flows --no-names --no-stats "$bridge" | \ + sed -e '/NXST_FLOW/d' \ + -e '/OFPST_FLOW/d' \ + -e 's/\(idle\|hard\)_age=[^,]*,//g' echo "EOF" done } From patchwork Mon Sep 25 14:44:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 818266 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3y16MS6MvJz9t4Z for ; Tue, 26 Sep 2017 00:45:40 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A0E3AB5D; Mon, 25 Sep 2017 14:44:26 +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 1BD87B43 for ; Mon, 25 Sep 2017 14:44:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E02E44BD for ; Mon, 25 Sep 2017 14:44:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D3644E4C3 for ; Mon, 25 Sep 2017 14:44:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D3644E4C3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=tredaelli@redhat.com Received: from graphite.mxp.redhat.com (unknown [10.32.181.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id E44CF77C0E for ; Mon, 25 Sep 2017 14:44:22 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Mon, 25 Sep 2017 16:44:05 +0200 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 25 Sep 2017 14:44:23 +0000 (UTC) X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 2/3] ovs-save: Use a file to restore flows instead of heredoc 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 This patch makes ovs-save to use a file to restore flows instead of using shell script here-document. This is needed since eval + here-documents are much slower than reading a file with the rules directly. Signed-off-by: Timothy Redaelli Acked-by: Flavio Leitner --- utilities/ovs-save | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/utilities/ovs-save b/utilities/ovs-save index fc9418c3d..da65c41ec 100755 --- a/utilities/ovs-save +++ b/utilities/ovs-save @@ -110,6 +110,7 @@ save_flows () { exit 1 fi + workdir=$(mktemp -d "${TMPDIR:-/tmp}/ovs-save.XXXXXXXXXX") for bridge in "$@"; do # Get the highest enabled OpenFlow version ofp_version=$(get_highest_ofp_version "$bridge") @@ -120,19 +121,19 @@ save_flows () { cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}' echo "'" - echo -n "ovs-ofctl -O $ofp_version add-flows ${bridge} " + echo -n "ovs-ofctl -O $ofp_version add-flows ${bridge} " \ + "\"$workdir/$bridge.flows.dump\"" # If possible, use OpenFlow 1.4 atomic bundle transaction to add flows - [ ${ofp_version#OpenFlow} -ge 14 ] && echo -n "--bundle " - - echo "- << EOF" + [ ${ofp_version#OpenFlow} -ge 14 ] && echo " --bundle" || echo ovs-ofctl -O $ofp_version dump-flows --no-names --no-stats "$bridge" | \ sed -e '/NXST_FLOW/d' \ -e '/OFPST_FLOW/d' \ - -e 's/\(idle\|hard\)_age=[^,]*,//g' - echo "EOF" + -e 's/\(idle\|hard\)_age=[^,]*,//g' > \ + "$workdir/$bridge.flows.dump" done + echo "rm -rf \"$workdir\"" } while [ $# -ne 0 ] From patchwork Mon Sep 25 14:44:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 818267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3y16N82RQFz9t4Z for ; Tue, 26 Sep 2017 00:46:16 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A8E78B73; Mon, 25 Sep 2017 14:44:27 +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 A06F1B30 for ; Mon, 25 Sep 2017 14:44:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 689804BD for ; Mon, 25 Sep 2017 14:44:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E490A552EA for ; Mon, 25 Sep 2017 14:44:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E490A552EA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=tredaelli@redhat.com Received: from graphite.mxp.redhat.com (unknown [10.32.181.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6526A6F137 for ; Mon, 25 Sep 2017 14:44:24 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Mon, 25 Sep 2017 16:44:06 +0200 Message-Id: <6c09f8dea5ccdc77d28bbc4d132db4ee06be5e69.1506350315.git.tredaelli@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 25 Sep 2017 14:44:25 +0000 (UTC) X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 3/3] ovs-save: Replace "echo -n" with "printf" 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 This is neeed since "echo -n" is not POSIX and may not work with some shells. Signed-off-by: Timothy Redaelli Acked-by: Flavio Leitner --- utilities/ovs-save | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/ovs-save b/utilities/ovs-save index da65c41ec..ea8fb6a45 100755 --- a/utilities/ovs-save +++ b/utilities/ovs-save @@ -115,13 +115,13 @@ save_flows () { # Get the highest enabled OpenFlow version ofp_version=$(get_highest_ofp_version "$bridge") - echo -n "ovs-ofctl add-tlv-map ${bridge} '" + printf "%s" "ovs-ofctl add-tlv-map ${bridge} '" ovs-ofctl dump-tlv-map ${bridge} | \ awk '/^ 0x/ {if (cnt != 0) printf ","; \ cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}' echo "'" - echo -n "ovs-ofctl -O $ofp_version add-flows ${bridge} " \ + printf "%s" "ovs-ofctl -O $ofp_version add-flows ${bridge} " \ "\"$workdir/$bridge.flows.dump\"" # If possible, use OpenFlow 1.4 atomic bundle transaction to add flows