SLES 11sp2 XEN and Open vSwitch

I was playing around with XEN and Open vSwitch on SLES11sp2, and I made a little “howto” for everybody that’s interested. Any comments and improvements are more than welcome. Here it is:

  1. Install SLES11sp2x64 and XEN

  2. Configure one NIC for management (there will be no VMs associated with it)

  3. Ensure Xen dom0 dedicated memory and preven dom0 memory ballooning (in /boot/grub/menu.lst):
    kernel /xen.gz dom0_mem=2048M,max:2048M vga=mode-0x317
    Also in the same file ensure that the XEN boot option is the default.

  4. Download and extract openvswitch-1.7.0.tar.gz into let’s say /progInstalls . This will create a sub-folder openvswitch-1.7.0 .

  5. Compile and install openvswitch by following these commands (as root):
    rmmod bridge
    cd /progInstalls/openvswitch-1.7.0
    ./configure --with-linux=/lib/modules/3.0.13-0.27-xen/build
    make
    make install
    insmod /progInstalls/openvswitch-1.7.0/datapath/linux/openvswitch.ko
    mkdir -p /usr/local/etc/openvswitch
    ovsdb-tool create /usr/local/etc/openvswitch/conf.db \ vswitchd/vswitch.ovsschema
    ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \ --remote=db:Open_vSwitch,manager_options --pidfile --detach
    ovs-vsctl --no-wait init
    ovs-vswitchd --pidfile --detach
    insmod /progInstalls/openvswitch-1.7.0/datapath/linux/brcompat.ko
    ovs-brcompatd --pidfile --detach

This completes the installation of openvswitch. Now we need to make it start on boot. Create an executable file named openvswitch with the following contents and put it in /etc/init.d/ (you can also make a symbolic link rcopenvswitch in /usr/sbin that points to /etc/init.d/openvswitch) :

------start /etc/init.d/openvswitch file contents --------------------

#!/bin/sh

Template SUSE system startup script for example service/daemon Open vSwitch

Copyright (C) 1995–2005 Kurt Garloff, SUSE / Novell Inc.

This library is free software; you can redistribute it and/or modify it

under the terms of the GNU Lesser General Public License as published by

the Free Software Foundation; either version 2.1 of the License, or (at

your option) any later version.

This library is distributed in the hope that it will be useful, but

WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public

License along with this library; if not, write to the Free Software

Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#---------------------------------------------------------------------------

title: Network Control (Open vSwitch)

description: Integrated Network Control Script via Open vSwitch

author: guessi at gmail.com (Kuo-Le, Mei)

Dept. of CSIE, National Dong Hwa University (Taiwan)

created date: 2011-05-06

lastest modify: 2012-09-11

modified by: msimeonov at intepro-bg dot com (Milko Simeonov)

#mod.description: openvswitch init script for SLES11sp2

license: GPLv2 (GNU General Public License, Version 2)

http://www.gnu.org/licenses/gpl-2.0.html

#---------------------------------------------------------------------------

BEGIN INIT INFO

Provides: openvswitch

Required-Start: $local_fs

Should-Start:

Required-Stop:

Should-Stop:

Default-Start: 3 5

Default-Stop: 0 1 2 6

Short-Description: openvswitch networking for XEN

Description: Loads the appropriate kernel modules and starts openvswitch

in Linux-bridge compatibility mode

END INIT INFO

##--------------------------------------------------------------------------

Global Variable Definition

##--------------------------------------------------------------------------
DIR=/progInstalls/openvswitch-1.7.0
DEFAULTBR=br0
OVSETC=/usr/local/etc/openvswitch
OVSRUN=/usr/local/var/run/openvswitch
ULOCALBIN=/usr/local/bin
ULOCALSBIN=/usr/local/sbin

##--------------------------------------------------------------------------

Declaration

##--------------------------------------------------------------------------

detect_ovs_br_existance()
{
$ULOCALBIN/ovs-vsctl br-exists $1 ;
}

detect_module_xt_physdev_existance()
{
/sbin/lsmod | grep xt_physdev | grep -v “grep” > /dev/null 2>&1 ;
}

detect_module_native_bridge_existance()
{
/sbin/lsmod | grep bridge | grep -v “grep” > /dev/null 2>&1 ;
}

detect_module_openvswitch_existance()
{
/sbin/lsmod | grep openvswitch | grep -v “grep” > /dev/null 2>&1 ;
}

detect_module_brcompat_existance()
{
/sbin/lsmod | grep brcompat | grep -v “grep” > /dev/null 2>&1 ;
}

ovs_stop()
{
local PROCESS1=/usr/local/var/run/openvswitch/ovsdb-server.pid ;
printf "Trying to kill Open vSwitch processes (Part 1)… " ;
if test -f $PROCESS1 ; then
kill cat $PROCESS1 > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || (echo “Failed” && exit 1) ;
else
echo “Skip” ;
fi

local PROCESS2=/usr/local/var/run/openvswitch/ovs-vswitchd.pid ;
printf "Trying to kill Open vSwitch processes (Part 2)… " ;
if test -f $PROCESS2 ; then
kill cat $PROCESS2 > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || (echo “Failed” && exit 1) ;
else
echo “Skip” ;
fi

local PROCESS3=/usr/local/var/run/openvswitch/ovs-brcompatd.pid ;
printf "Trying to kill Open vSwitch processes (Part 3)… " ;
if test -f $PROCESS3 ; then
kill cat $PROCESS3 > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || (echo “Failed” && exit 1) ;
else
echo “Skip” ;
fi
}

ovs_start()
{

Step 0. Detect if module xt_physdev exist?

printf "Trying to remove module xt_physdev… " ;
detect_module_xt_physdev_existance ;
if test $? = 0 ; then
echo “Found” ;

   printf "Trying to remove the module xt_physdev... " ; 
   /sbin/rmmod xt_physdev > /dev/null 2>&1 ; 
   test $? = 0 && echo "Done" || echo "Failed" ; 

else
echo “Not Found” ;
fi

Step 1. Detect if module bridge exist?

printf "Detecting module bridge… " ;
detect_module_native_bridge_existance ;
if test $? = 0 ; then
echo “Found” ;

   printf "Trying to remove the module bridge... " ; 
   /sbin/rmmod bridge > /dev/null 2>&1 ; 
   test $? = 0 && echo "Done" || echo "Failed" ; 

else
echo “Not Found” ;
fi

Step 2. Insert OVS module

printf "Trying to insert module openvswitch.ko… " ;
detect_module_openvswitch_existance ;
if test $? != 0 ; then
if ! test -f $DIR/datapath/linux/openvswitch.ko ; then
echo “Failed. openvswitch.ko not found” ;
exit 1 ;
fi
# insert kernel module “openvswitch.ko”
/sbin/insmod $DIR/datapath/linux/openvswitch.ko > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || (echo “Failed” && exit 1) ;
else
echo “Skip, already loaded” ;
fi

Step 3. Create folder for OVS

printf "Trying to create the folder for Open vSwitch… " ;
if test -d $OVSETC ; then
echo “Skip, already exist” ;
else
mkdir -p $OVSETC > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;
fi

Step 4. Create/Convert database for OVS

if test -f $OVSETC/conf.db ; then
printf "Trying to convert the database… " ;
$ULOCALBIN/ovsdb-tool \
convert $OVSETC/conf.db $DIR/vswitchd/vswitch.ovsschema > /dev/null
2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;
else
printf "Trying to create the database… " ;
$ULOCALBIN/ovsdb-tool \
create $OVSETC/conf.db $DIR/vswitchd/vswitch.ovsschema > /dev/null
2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;
fi

Step 5. Start OVS database server

printf "Trying to startup the database server… " ;
$ULOCALSBIN/ovsdb-server \
–remote=punix:$OVSRUN/db.sock \
–remote=db:Open_vSwitch,manager_options \
–pidfile --detach > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;

Step 6. Initialize

printf "Initializing controls for Open vSwitch… " ;
$ULOCALBIN/ovs-vsctl --no-wait init > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;

Step 7. Start OVS daemon

printf "Starting the Open vSwitch daemon… " ;
$ULOCALSBIN/ovs-vswitchd --pidfile --detach > /dev/null 2>&1 ;
test $? = 0 && echo “Done” || echo “Failed” ;

Step 8. Start OVS-COMPAT daemon

printf "Trying to insert module brcompat.ko… " ;
detect_module_brcompat_existance ;
if test $? != 0 ; then
# First, test if the module exist?
if ! test -f $DIR/datapath/linux/brcompat.ko ; then
echo “Failed. brcompat.ko not found” ;
exit 1 ;
fi

   # Second, trying to insert module "brcompat.ko" 
   /sbin/insmod $DIR/datapath/linux/brcompat.ko > /dev/null 2>&1 ; 
   test $? = 0  && echo "Done" || (echo "Failed" && exit 1) ; 

   # Finally, start the brcompat daemon 
   printf "Trying to start brcompat daemon... " ; 
   #$ULOCALSBIN/ovs-brcompatd --pidfile --detach > /dev/null 2>&1 ; 
   $ULOCALSBIN/ovs-brcompatd \\ 
   --appctl=/usr/local/bin/ovs-appctl \\ 
   --vsctl=/usr/local/bin/ovs-vsctl \\ 
   --pidfile --detach > /dev/null 2>&1 ; 
   test $? = 0 && echo "Done" || echo "Failed" ; 

else
echo “Skip, already loaded” ;
fi

}

ovs_show_status()
{
local VBRIDGE=${1:-$DEFAULTBR} ;

printf "Status of $VBRIDGE

" ;
printf "ovs-vsctl:
" ;
$ULOCALBIN/ovs-vsctl show | sed ‘s/^/\t/g’ ;
printf "
ifconfig:
" ;
/sbin/ifconfig $VBRIDGE | sed ‘s/^/\t/g’ ;
}

##--------------------------------------------------------------------------

Main Procedure

##--------------------------------------------------------------------------

case “$1” in
start)
ovs_start ;
;;
stop)
ovs_stop ;
;;
restart)
ovs_stop ;
ovs_start ;
;;
status)
ovs_show_status $2 ;
;;
*)
echo “Usage: $0 {start|stop|status|restart}”
exit 1 ;
;;
esac

exit 0 ;

------end /etc/init.d/openvswitch file contents --------------------

  1. Create a bridge named br0 in YaST. Don’t enter any IP Address for it, just associate a physical ethernet interface to it.

  2. Make a backup copy of the /etc/xen/scripts/vif-bridge script and create a new one with the same name and the following contents:

-------- begin “/etc/xen/script/vif-bridge” contents------------------------------

#!/bin/bash

dir=$(dirname “$0”)
. “$dir/vif-common.sh”

bridge=${bridge:-}
bridge=$(xenstore_read_default “$XENBUS_PATH/bridge” “$bridge”)

if [ -z “${bridge}” ]
then
bridge=$(ovs-vsctl list-br | cut -d "
" -f 1)

if [ -z "${bridge}" ] 
then 
    fatal "Could not find bridge and none was specified" 
fi 

fi

RET=0
ovs-vsctl list-br | grep -c ${bridge} > /dev/null 2>&1 || RET=1
if [ $RET -eq 1 ]
then
fatal “Could not find bridge device ${bridge}”
fi

case “$command” in
online)
ifconfig “${vif}” 0.0.0.0 up
ovs-vsctl – --may-exist add-port ${bridge} ${vif}
;;

offline) 
ovs-vsctl -- --if-exists del-port ${bridge} ${vif} 
ifconfig "$vif" 0.0.0.0 down 
;; 

esac

handle_iptable

log debug “Successful vif-openvswitch $command for ${vif}, bridge
${bridge}.”
if [ “$command” == “online” ]
then
success
fi
-------- end “/etc/xen/script/vif-bridge” contents------------------------------

  1. You are ready now to create VMs in XEN with virt-manager . Make sure their virtual NICs are connected to br0. Also, if you want them to shutdown nicely when rebooting or halting the host server, then follow this TID:
    http://www.novell.com/support/kb/doc.php?id=3029956

After applying server updates, check to make sure the /etc/xen/scripts/vif-bridge script is not overwritten by the update!

I’ve used the following for refferences:

http://openvswitch.org/pipermail/discuss/2011-October/005891.html
http://www.openvswitch.org
INSTALL.Linux (text file from the downloaded material openvswitch-1.7.0)
INSTALL.bridge (text file from the downloaded material openvswitch-1.7.0)

Simeonof,

It appears that in the past few days you have not received a response to your
posting. That concerns us, and has triggered this automated reply.

Has your issue been resolved? If not, you might try one of the following options:

Be sure to read the forum FAQ about what to expect in the way of responses:
http://forums.suse.com/faq.php

If this is a reply to a duplicate posting, please ignore and accept our apologies
and rest assured we will issue a stern reprimand to our posting bot.

Good luck!

Your SUSE Forums Team
http://forums.suse.com