From patchwork Fri Sep 8 11:03:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 811532 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 3xpZFS4Jdlz9sPk for ; Fri, 8 Sep 2017 21:03:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id F295C978; Fri, 8 Sep 2017 11:03:52 +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 742CA481 for ; Fri, 8 Sep 2017 11:03:51 +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 3421A3F9 for ; Fri, 8 Sep 2017 11:03:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94E3D13A55 for ; Fri, 8 Sep 2017 11:03:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94E3D13A55 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.redhat.com (ovpn-117-139.ams2.redhat.com [10.36.117.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ED4063F74 for ; Fri, 8 Sep 2017 11:03:49 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Fri, 8 Sep 2017 13:03:48 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 08 Sep 2017 11:03:50 +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] 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 ovs-save fails, this patch also fixes that. Replaced "echo -n" with "printf" since "echo -n" is not POSIX and may not work with some shells. Signed-off-by: Timothy Redaelli --- This is a pre-requisite for the new patchset of patch with patchwok id 799223 --- utilities/ovs-save | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/utilities/ovs-save b/utilities/ovs-save index 8b8dbf421..3cfa4c870 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,16 +111,26 @@ save_flows () { fi for bridge in "$@"; do - echo -n "ovs-ofctl add-tlv-map ${bridge} '" - ovs-ofctl dump-tlv-map ${bridge} | \ + # Get the highest enabled OpenFlow version + ofp_version=$(get_highest_ofp_version "$bridge") + + printf "ovs-ofctl -O $ofp_version add-tlv-map %s '" "$bridge" + ovs-ofctl -O $ofp_version 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 "EOF" + 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 + [ ${ofp_version#OpenFlow} -ge 14 ] && echo " --bundle" + + 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' \ + > "$workdir/$bridge.flows.dump" done }