3 # Copyright (c) 2011, 2013 Nicira, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 */*) dir0=`echo "$0" | sed 's,/[^/]*$,,'` ;;
21 . "$dir0/ovs-lib" || exit 1
26 ${UTIL}: Provides helper functions to save Open vSwitch's configuration.
30 save-interfaces Outputs a shell script on stdout that will restore
31 the current kernel configuration of the specified
32 network interfaces, as well as the system iptables
34 save-flows Outputs a shell script on stdout that will restore
35 OpenFlow flows of each Open vSwitch bridge.
36 save-ofports Outputs a shell script on stdout that will restore
37 the ofport value across a force-reload-kmod.
38 This script is meant as a helper for the Open vSwitch init script commands.
43 if (ip -V) > /dev/null 2>&1; then :; else
44 echo "$0: ip not found in $PATH" >&2
48 if test "$#" = 0; then
54 state=`ip link show dev $dev` || continue
57 # Link state (Ethernet addresses, up/down, ...)
60 *"state UP"* | *[,\<]"UP"[,\>]* )
64 linkcmd="$linkcmd down"
67 if expr "$state" : '.*\bdynamic\b' > /dev/null; then
68 linkcmd="$linkcmd dynamic"
70 if qlen=`expr "$state" : '.*qlen \([0-9]+\)'`; then
71 linkcmd="$linkcmd txqueuelen $qlen"
73 if hwaddr=`expr "$state" : '.*link/ether \([^ ]*\)'`; then
74 linkcmd="$linkcmd address $hwaddr"
76 if brd=`expr "$state" : '.*brd \([^ ]*\)'`; then
77 linkcmd="$linkcmd broadcast $brd"
79 if mtu=`expr "$state" : '.*mtu \([0-9]+\)'`; then
80 linkcmd="$linkcmd mtu $mtu"
82 if test -n "$linkcmd"; then
83 echo ip link set dev $dev down # Required to change hwaddr.
84 echo ip link set dev $dev $linkcmd
87 move_ip_address $dev $dev
89 move_ip_routes $dev $dev
94 if (iptables-save) > /dev/null 2>&1; then
96 echo "iptables-restore <<'EOF'"
100 echo "# iptables-save not found in $PATH, not saving iptables state"
105 if (ovs-ofctl --version) > /dev/null 2>&1; then :; else
106 echo "$0: ovs-ofctl not found in $PATH" >&2
110 for bridge in "$@"; do
111 echo "ovs-ofctl add-flows ${bridge} - << EOF"
112 ovs-ofctl dump-flows "${bridge}" | sed -e '/NXST_FLOW/d' \
113 -e 's/\(idle\|hard\)_age=[^,]*,//g'
119 ovs-vsctl --no-wait "$@"
124 if (ovs-vsctl --version) > /dev/null 2>&1; then :; else
125 echo "$0: ovs-vsctl not found in $PATH" >&2
129 for bridge in "$@"; do
131 for iface in `ovs_vsctl list-ifaces ${bridge}`; do
132 ofport=`ovs_vsctl get interface ${iface} ofport`
133 [ "${count}" -eq 0 ] && cmd="ovs-vsctl --no-wait"
134 cmd="${cmd} -- --if-exists set interface "${iface}" \
135 ofport_request="${ofport}""
137 # Run set interface command on 50 ports at a time.
138 count=`expr ${count} + 1`
139 [ "${count}" -eq 50 ] && count=0 && echo "${cmd}" && cmd=""
168 echo >&2 "$0: unknown command \"$1\" (use --help for help)"