summaryrefslogtreecommitdiff
path: root/network/openvswitch/xen
diff options
context:
space:
mode:
Diffstat (limited to 'network/openvswitch/xen')
-rw-r--r--network/openvswitch/xen/README39
-rw-r--r--network/openvswitch/xen/network-openvswitch124
-rw-r--r--network/openvswitch/xen/vif-openvswitch86
3 files changed, 249 insertions, 0 deletions
diff --git a/network/openvswitch/xen/README b/network/openvswitch/xen/README
new file mode 100644
index 0000000000..93889615e7
--- /dev/null
+++ b/network/openvswitch/xen/README
@@ -0,0 +1,39 @@
+Here are some scripts that I've written for use with Xen at my site.
+In order to use these scripts with your Xen installation you'll need to copy
+both the network-openvswitch and vif-openvswitch files to your
+/etc/xen/scripts directory. You can instruct Xen to use these scripts by
+editing your /etc/xen/xend-config.sxp file and specifying these scripts as
+the default network-script and vif-script.
+
+For example, here are the entries in my xend-config.sxp file:
+
+ (network-script 'network-openvswitch netdev=eth2 bridge=ovs0')
+
+ (vif-script 'vif-openvswitch bridge=ovs0')
+
+If your network interface card and attached network switch support VLAN
+tagged traffic, you can place virtual machines within a seperate VLAN by
+appending a '.' and the VLAN tag number you wish the domain to use. For
+example, to have all domains default to VLAN 2 you can do the following:
+
+ (vif-script 'vif-openvswitch bridge=ovs0.2')
+
+You can also specify tagged traffic in the domain configuration file.
+
+If you are hosting a hardware virtualized domain understand that the
+/etc/xen/scripts/qemu-ifup script is run instead of the vif-script specified
+in the xend-config.sxp file. You'll need to edit this file to add the port
+to the vswitch instead of using the brctl (unless of course you are using
+the appropriate kernel module to control the vswitch using brctl.) Here is
+a snippet from my qemu-ifup to handle hardware virtualized ports:
+
+ if lsmod | grep -c openvswitch_mod 1> /dev/null && ! lsmod | grep -c brcompat_mod 1> /dev/null
+ then
+ ovs-vsctl -- --may-exist add-port $bridge $1
+ else
+ brctl addif $bridge $1 || true
+ fi
+
+This doesn't handle tagged traffic. I'll leave that as an exercise for you.
+
+Enjoy.
diff --git a/network/openvswitch/xen/network-openvswitch b/network/openvswitch/xen/network-openvswitch
new file mode 100644
index 0000000000..45cda0b195
--- /dev/null
+++ b/network/openvswitch/xen/network-openvswitch
@@ -0,0 +1,124 @@
+#!/bin/bash
+#============================================================================
+# Default Xen network start/stop script.
+# Xend calls a network script when it starts.
+# The script name to use is defined in ${XEN_CONFIG_DIR}/xend-config.sxp
+# in the network-script field.
+#
+# This script creates a virtual switch (default ${netdev}) and adds a
+# device (defaults to eth0) to it. The interface that this Open vSwitch
+# is created on should not have a working IP address and will be used as
+# a switch for Xen domU's.
+#
+# Usage:
+# network-openvswitch (start|stop|status) {VAR=VAL}*
+#
+# Vars:
+# bridge The bridge to use (default xenvs0).
+# netdev The interface to add to the bridge (default eth0). This
+# device should not be configured with an IP address. If so
+# this script will tear down the interface and bring it back up
+# without an IP address.
+#
+# start:
+# Creates the bridge as bridge
+# Enslaves netdev to bridge
+#
+# stop:
+# Removes netdev from the bridge
+# Deletes bridge
+#
+# status:
+# Print addresses, interfaces
+#
+#============================================================================
+
+dir=$(dirname "$0")
+. "$dir/logging.sh"
+. "$dir/xen-script-common.sh"
+. "$dir/xen-network-common.sh"
+. "$dir/locking.sh"
+
+findCommand "$@"
+evalVariables "$@"
+
+netdev=${netdev:-eth0}
+bridge=${bridge:-ovs0}
+
+addr=`ip addr show dev ${netdev} | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'`
+if [ -n "$addr" ]; then
+ echo "Invalid device: ${netdev} is up and has a valid IP address!" >&2
+ exit 1
+fi
+
+show_status () {
+ local dev=$1
+ local bridge=$2
+
+ echo '============================================================'
+ echo 'vSwitch interfaces'
+ ovs-vsctl list-ifaces ${bridge}
+ echo ' '
+ echo 'vSwitch ports'
+ ovs-vsctl list-ports ${bridge}
+ echo '============================================================'
+}
+
+op_start () {
+ if [ "${bridge}" = "null" ] ; then
+ return
+ fi
+
+ ifconfig "${netdev}" down
+ ifconfig "${netdev}" 0.0.0.0 up
+ ovs-vsctl -- --may-exist add-br ${bridge}
+ ifconfig "${bridge}" 0.0.0.0 up
+ ovs-vsctl -- --may-exist add-port ${bridge} ${netdev}
+
+ # Remove any stale ports from last time virtual switch was running.
+ # Open vSwitch has the habit of remembering port settings between
+ # runs.
+ for port in $(ovs-vsctl list-ports ${bridge})
+ do
+ if [ "${port}" != "${netdev}" ]
+ then
+ ifconfig "${port}" down
+ ovs-vsctl del-port ${port}
+ fi
+ done
+}
+
+op_stop () {
+ if [ "${bridge}" = "null" ]; then
+ return
+ fi
+
+ # Remove all ports from virtual switch.
+ for port in $(ovs-vsctl list-ports ${bridge})
+ do
+ ifconfig "${port}" down
+ ovs-vsctl del-port ${port}
+ done
+
+ ifconfig "${bridge}" down
+ ovs-vsctl -- --if-exists del-br ${bridge}
+}
+
+case "$command" in
+ start)
+ op_start
+ ;;
+
+ stop)
+ op_stop
+ ;;
+
+ status)
+ show_status ${netdev} ${bridge}
+ ;;
+
+ *)
+ echo "Unknown command: $command" >&2
+ echo 'Valid commands are: start, stop, status' >&2
+ exit 1
+esac
diff --git a/network/openvswitch/xen/vif-openvswitch b/network/openvswitch/xen/vif-openvswitch
new file mode 100644
index 0000000000..bdcd7c46f7
--- /dev/null
+++ b/network/openvswitch/xen/vif-openvswitch
@@ -0,0 +1,86 @@
+#!/bin/bash
+#============================================================================
+# ${XEN_SCRIPT_DIR}/vif-openvswitch
+#
+# Script for configuring a vif using Open vSwitch.
+#
+# Usage:
+# vif-openvswitch (add|remove|online|offline)
+#
+# Environment vars:
+# vif vif interface name (required).
+# XENBUS_PATH path to this device's details in the XenStore (required).
+#
+# Read from the store:
+# bridge bridge to add the vif to (optional). Defaults to searching for the
+# bridge itself.
+#
+# up:
+# Enslaves the vif interface to the bridge.
+#
+# down:
+# Removes the vif interface from the bridge.
+#============================================================================
+
+dir=$(dirname "$0")
+. "$dir/vif-common.sh"
+
+bridge=${bridge:-}
+bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
+
+if [ -z "${bridge}" ]
+then
+ bridge=$(ovs-vsctl listbr | cut -d "
+" -f 1)
+
+ if [ -z "${bridge}" ]
+ then
+ fatal "Could not find bridge and none was specified"
+ fi
+fi
+
+tag=${tag:-}
+
+# Domain on VLAN tagged bridge?
+RET=0
+ovs-vsctl list-br | grep -c ${bridge} 1>/dev/null 2>&1 || RET=1
+if [ $RET -eq 1 ]
+then
+ if [[ $bridge =~ \.[[:digit:]]{1,4}$ ]]
+ then
+ tag=$(echo ${bridge} | cut -d "." -f 2)
+ bridge=$(echo ${bridge} | cut -d "." -f 1)
+ else
+ fatal "Could not find bridge device ${bridge}"
+ fi
+fi
+
+RET=0
+ovs-vsctl list-br | grep -c ${bridge} 1>/dev/null 2>&1 || RET=1
+if [ $RET -eq 1 ]
+then
+ fatal "Could not find bridge device ${bridge}"
+fi
+
+log debug "Successful vif-bridge $command for ${vif}, bridge ${bridge}."
+case "$command" in
+ online)
+ ifconfig "${vif}" 0.0.0.0 up
+ if [ -z $tag ]
+ then
+ ovs-vsctl -- --may-exist add-port ${bridge} ${vif}
+ else
+ ovs-vsctl -- --may-exist add-port ${bridge} ${vif} tag=${tag}
+ fi
+ ;;
+
+ offline)
+ ovs-vsctl -- --if-exists del-port ${bridge} ${vif}
+ ifconfig "$vif" 0.0.0.0 down
+ ;;
+esac
+
+if [ "$command" == "online" ]
+then
+ success
+fi