diff mbox series

[ovs-dev,v2,1/3] ovs-save: Use --bundle to restore flows (on OpenFlow 1.4+)

Message ID e20cf86acfc980a1833b7f4789e08758a67cb8fd.1506350315.git.tredaelli@redhat.com
State Accepted
Headers show
Series ovs-save: Some refactors to speed-up save-flows | expand

Commit Message

Timothy Redaelli Sept. 25, 2017, 2:44 p.m. UTC
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 <tredaelli@redhat.com>
---
 utilities/ovs-save | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Flavio Leitner Oct. 17, 2017, 5:26 p.m. UTC | #1
On Mon, 25 Sep 2017 16:44:04 +0200
Timothy Redaelli <tredaelli@redhat.com> wrote:

> 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 <tredaelli@redhat.com>
> ---
>  utilities/ovs-save | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 

Acked-by: Flavio Leitner <fbl@sysclose.org>
Thanks!
fbl
Ben Pfaff Oct. 27, 2017, 4:55 p.m. UTC | #2
On Mon, Sep 25, 2017 at 04:44:04PM +0200, Timothy Redaelli wrote:
> 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 <tredaelli@redhat.com>

Thanks for working on this.

The get_highest_ofp_version might have surprising semantics.  The
ovs-vsctl command will print protocols in alphabetical order, and
get_highest_ofp_version assumes that the alphabetically last OpenFlow
protocol name is the "best".  That's currently true, but I am not sure
that it will be true forever.  What if, instead of taking the last, we
took all of them?  I believe that ovs-ofctl, given multiple protocols on
-O, will select the "best" or latest itself

Something like this would do the trick, I guess:
        ovs-vsctl get bridge br0 protocols | tr -d '[]" '

This is pretty petty, though.  It makes no difference for now.  I
applied this to master.
diff mbox series

Patch

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
 }