X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=utilities%2Fovs-save;h=bcaf27cf6298876f13c9dd9b5edc5ba0064834f3;hb=72eaa2baa910ba41ed29b56617bffbc46bafc342;hp=9ed14ebb33deae377eb1eaa32647f89901829cf7;hpb=a41754333f6faad72e0f7b12521de7b7f737f9a6;p=cascardo%2Fovs.git diff --git a/utilities/ovs-save b/utilities/ovs-save index 9ed14ebb3..bcaf27cf6 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. @@ -14,6 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +case $0 in + */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;; + *) dir0=./ ;; +esac +. "$dir0/ovs-lib" || exit 1 + usage() { UTIL=$(basename $0) cat < /dev/null 2>&1; then :; else echo "$0: ip not found in $PATH" >&2 exit 1 fi @@ -94,77 +84,25 @@ save_interfaces () { echo ip link set dev $dev $linkcmd fi - # IP addresses (including IPv6). - echo "ip addr flush dev $dev 2>/dev/null" # Suppresses "Nothing to flush". - ip addr show dev $dev | while read addr; do - set -- $addr - - # Check and trim family. - family=$1 - shift - case $family in - inet | inet6) ;; - *) continue ;; - esac - - # Trim device off the end--"ip" insists on having "dev" precede it. - addrcmd= - while test $# != 0; do - case $1 in - dynamic) - # Omit kernel-maintained route. - continue 2 - ;; - scope) - if test "$2" = link; then - # Omit route derived from IP address, e.g. - # 172.16.0.0/16 derived from 172.16.12.34. - continue 2 - fi - ;; - "$dev"|"$dev:"*) - # Address label string - addrcmd="$addrcmd label $1" - shift - continue - ;; - esac - addrcmd="$addrcmd $1" - shift - done - if test "$1" != "$dev"; then - addrcmd="$addrcmd $1" - fi - - echo ip -f $family addr add $addrcmd dev $dev - done + move_ip_address $dev $dev - # Routes. - echo "ip route flush dev $dev proto boot 2>/dev/null" # Suppresses "Nothing to flush". - ip route show dev $dev | while read route; do - # "proto kernel" routes are installed by the kernel automatically. - case $route in - *" proto kernel "*) continue ;; - esac - - echo "ip route add $route dev $dev" - done + move_ip_routes $dev $dev 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 @@ -177,85 +115,36 @@ save_flows () { done } -save_datapaths () { - if missing_program ovs-dpctl; then - echo "$0: ovs-dpctl not found in $PATH" >&2 - exit 1 - fi - if missing_program ovs-vsctl; then +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 dp in "$@"; do - echo "ovs-dpctl add-dp ${dp}" - ovs-dpctl show $dp | while read line; do - # An example 'ovs-dpctl show' output looks like this: - # system@br1: - # lookups: hit:0 missed:0 lost:0 - # flows: 0 - # port 0: br1 (internal) - # port 2: gre2886795521 (ipsec_gre: key=flow, pmtud=false, remote_ip=172.17.1.1, tos=inherit) - # port 3: gre1 (ipsec_gre: remote_ip=192.168.113.1) - # port 14: gre2 (gre: remote_ip=192.168.115.1) - # port 15: gre3 (gre64: remote_ip=192.168.116.1) - # port 16: eth0 - # port 17: br1- (patch: peer=br1+) - - # Skip lines which do not have 'port' - if port_no=`expr "${line}" : '.*port \([0-9]\+\):'`; then :; else - continue - fi - - netdev=`echo ${line} | awk '{print $3}'` - - # Do not add port that has the same name as the datapath. It gets - # added by default. - [ "${dp#system@}" = "${netdev}" ] && continue - - type=`echo ${line} | awk '{print $4}' | sed 's/[:)(]//g'` - [ ! -n "${type}" ] && type="system" - - command="ovs-dpctl add-if ${dp}\ - ${netdev},type=${type},port_no=${port_no}" - - options=`echo ${line} | awk -F: '{print $3}' | sed 's/[) ]//g'` - [ -n "${options}" ] && command="${command},${options}" - - # For ipsec, ovs-dpctl does not show the key value pairs related - # to certificates. Get that information from ovs-vsctl. - if [ "${type}" = "ipsec_gre" ] ; then - if peer_cert=`ovs-vsctl get interface \ - "${netdev}" options:peer_cert 2>/dev/null`; then - # The option peer_cert comes with an accompanying - # "certificate" or "use_ssl_cert" - if certificate=`ovs-vsctl get interface "${netdev}" \ - options:certificate 2>/dev/null` ; then - command="${command},peer_cert=${peer_cert},certificate=${certificate}" - else - use_ssl_cert=`ovs-vsctl get interface "${netdev}" \ - options:use_ssl_cert 2>/dev/null` - command="${command},peer_cert=${peer_cert},use_ssl_cert=${use_ssl_cert}" - fi - else - psk=`ovs-vsctl get interface "${netdev}" \ - options:psk 2>/dev/null` - command="${command},psk=${psk}" - fi - fi - echo ${command} + 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 case $1 in - "save-datapaths") - shift - save_datapaths "$@" - exit 0 - ;; "save-flows") shift save_flows "$@" @@ -266,6 +155,11 @@ do save_interfaces "$@" exit 0 ;; + "save-ofports") + shift + save_ofports "$@" + exit 0 + ;; -h | --help) usage exit 0