X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-save;h=73895f3375ec71f1418588a35b69a19206d7336a;hb=ec988646afe6aee6a63d6894a3e9b50f715d5941;hp=2ab9d086a023c0d800aa845ed02bd978055bf077;hpb=0311d4f48ddfeb5f7d25b45d53168c02603bcf62;p=sliver-openvswitch.git diff --git a/utilities/ovs-save b/utilities/ovs-save index 2ab9d086a..73895f337 100755 --- a/utilities/ovs-save +++ b/utilities/ovs-save @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (c) 2011 Nicira, Inc. +# Copyright (c) 2011, 2013 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,27 +27,14 @@ Commands: configuration. save-flows Outputs a shell script on stdout that will restore Openflow flows of each Open vSwitch bridge. + save-ofports Outputs a shell script on stdout that will restore + the ofport value across a force-reload-kmod. This script is meant as a helper for the Open vSwitch init script commands. EOF } -PATH=/sbin:/bin:/usr/sbin:/usr/bin - -missing_program () { - save_IFS=$IFS - IFS=: - for dir in $PATH; do - IFS=$save_IFS - if test -x $dir/$1; then - return 1 - fi - done - IFS=$save_IFS - return 0 -} - save_interfaces () { - if missing_program ip; then + if (ip -V) > /dev/null 2>&1; then :; else echo "$0: ip not found in $PATH" >&2 exit 1 fi @@ -150,18 +137,18 @@ save_interfaces () { echo done - if missing_program iptables-save; then - echo "# iptables-save not found in $PATH, not saving iptables state" - else + if (iptables-save) > /dev/null 2>&1; then echo "# global" echo "iptables-restore <<'EOF'" iptables-save echo "EOF" + else + echo "# iptables-save not found in $PATH, not saving iptables state" fi } save_flows () { - if missing_program ovs-ofctl; then + if (ovs-ofctl --version) > /dev/null 2>&1; then :; else echo "$0: ovs-ofctl not found in $PATH" >&2 exit 1 fi @@ -174,6 +161,32 @@ save_flows () { done } +ovs_vsctl () { + ovs-vsctl --no-wait "$@" +} + +save_ofports () +{ + if (ovs-vsctl --version) > /dev/null 2>&1; then :; else + echo "$0: ovs-vsctl not found in $PATH" >&2 + exit 1 + fi + + for bridge in "$@"; do + count=0 + for iface in `ovs_vsctl list-ifaces ${bridge}`; do + ofport=`ovs_vsctl get interface ${iface} ofport` + [ "${count}" -eq 0 ] && cmd="ovs-vsctl --no-wait" + cmd="${cmd} -- --if-exists set interface "${iface}" \ + ofport_request="${ofport}"" + + # Run set interface command on 50 ports at a time. + count=`expr ${count} + 1` + [ "${count}" -eq 50 ] && count=0 && echo "${cmd}" && cmd="" + done + echo "${cmd}" + done +} while [ $# -ne 0 ] do @@ -188,6 +201,11 @@ do save_interfaces "$@" exit 0 ;; + "save-ofports") + shift + save_ofports "$@" + exit 0 + ;; -h | --help) usage exit 0