]>
git.proxmox.com Git - mirror_ovs.git/blob - utilities/ovs-save
3 # Copyright (c) 2011, 2013, 2016 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 This script is meant as a helper for the Open vSwitch init script commands.
41 if (ip link show
) > /dev
/null
2>&1; then :; else
42 echo "$0: ip not found in $PATH" >&2
46 if test "$#" = 0; then
52 state
=`ip link show dev $dev` ||
continue
55 # Link state (Ethernet addresses, up/down, ...)
58 *"state UP"* |
*[,\
<]"UP"[,\
>]* )
62 linkcmd
="$linkcmd down"
65 if expr "$state" : '.*\bdynamic\b' > /dev
/null
; then
66 linkcmd
="$linkcmd dynamic"
68 if qlen
=`expr "$state" : '.*qlen \([0-9]\+\)'`; then
69 linkcmd
="$linkcmd txqueuelen $qlen"
71 if hwaddr
=`expr "$state" : '.*link/ether \([^ ]*\)'`; then
72 linkcmd
="$linkcmd address $hwaddr"
74 if brd
=`expr "$state" : '.*brd \([^ ]*\)'`; then
75 linkcmd
="$linkcmd broadcast $brd"
77 if mtu
=`expr "$state" : '.*mtu \([0-9]\+\)'`; then
78 linkcmd
="$linkcmd mtu $mtu"
80 if test -n "$linkcmd"; then
81 echo ip link
set dev
$dev down
# Required to change hwaddr.
82 echo ip link
set dev
$dev $linkcmd
85 move_ip_address
$dev $dev
87 move_ip_routes
$dev $dev
92 if (iptables-save
) > /dev
/null
2>&1; then
94 echo "iptables-restore <<'EOF'"
98 echo "# iptables-save not found in $PATH, not saving iptables state"
102 get_highest_ofp_version
() {
103 ovs-vsctl get bridge
"$1" protocols | \
104 awk -F '"' '{ print (NF>1)? $(NF-1) : "OpenFlow14" }'
108 if (ovs-ofctl
--version) > /dev
/null
2>&1; then :; else
109 echo "$0: ovs-ofctl not found in $PATH" >&2
113 workdir
=$
(mktemp
-d "${TMPDIR:-/tmp}/ovs-save.XXXXXXXXXX")
114 for bridge
in "$@"; do
115 # Get the highest enabled OpenFlow version
116 ofp_version
=$
(get_highest_ofp_version
"$bridge")
118 printf "%s" "ovs-ofctl add-tlv-map ${bridge} '"
119 ovs-ofctl dump-tlv-map
${bridge} | \
120 awk '/^ *0x/ {if (cnt != 0) printf ","; \
121 cnt++;printf "{class="$1",type="$2",len="$3"}->"$4}'
124 # If possible use OpenFlow 1.4 atomic bundle txn for flows and groups
125 [ ${ofp_version#OpenFlow} -ge 14 ] && bundle
=" --bundle" || bundle
=""
127 echo "ovs-ofctl -O $ofp_version add-groups ${bridge} \
128 \"$workdir/$bridge.groups.dump\" ${bundle}"
130 echo "ovs-ofctl -O $ofp_version replace-flows ${bridge} \
131 \"$workdir/$bridge.flows.dump\" ${bundle}"
133 ovs-ofctl
-O $ofp_version dump-groups
"$bridge" | \
134 sed -e '/^OFPST_GROUP_DESC/d' \
135 -e '/^NXST_GROUP_DESC/d' > \
136 "$workdir/$bridge.groups.dump"
138 ovs-ofctl
-O $ofp_version dump-flows
--no-names --no-stats "$bridge" | \
139 sed -e '/NXST_FLOW/d' \
141 -e 's/\(idle\|hard\)_age=[^,]*,//g' > \
142 "$workdir/$bridge.flows.dump"
144 echo "rm -rf \"$workdir\""
165 echo >&2 "$0: unknown command \"$1\" (use --help for help)"