[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-users] openvswitch on xen 4.x
A huge thank you to mario from the 'openvswitch on Xen 4.1' post. I was having some trouble with using openvswitch with Xen 4.1 (I'm currently migrating from 4.0.1) until I saw his post and noticed that the xl.conf needed the full path to the networking script. Made this change and all is good now. Thank you. I would like to contribute what I have for using openvswitch with Xen. Again, I'm migrating from Xen 4.0.1 and can confirm that this works for Xen 4.0. Please feel free to provide feedback for Xen 4.1. Please excuse the length of this post, I'm basically doing a dump of the scripts that are on my hard drive for all to see and use. The network-openvswitch script works with Xen 4.0 (xm) and Xen 4.1 (xm). I'm using Slackware as my host and can provide the rc script that I use to start and stop Xen if requested since I've basically moved the contents of network-openvswitch into an rc script as part of my migration to the xl toolchain. The only bug I've noticed is that the ports aren't cleaned up whenever xend is stopped. I never investigated this further and most likely never will since I'm moving to the xl toolchain. The vif-openvswitch script works for both Xen 4.0 (xm) and Xen 4.1 (xm/xl). When I was first setting up Xen I was playing with VLAN tagging for separating test domains so I designed the vif-network script to handle tagging traffic on a port. In order to take advantage of tagging you must append the tag number to the bridge name in your guest domain configuration file separated by a period. i.e., vif = [ 'bridge=ovs0.3' ] I hope this helps someone. Enjoy and good luck! /etc/xen/scripts/network-openvswitch: #!/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). # # 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 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 /etc/xen/scripts/vif-openvswitch: #!/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 if [ -z "${tag}" ] then log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}." else log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}, tag ${tag}." fi 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 ;; add) ;; esac if [ "$command" == "online" ] then success fi _______________________________________________ Xen-users mailing list Xen-users@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-users
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |