[ovs-discuss] To Make Open vSwitch Works At Boot with XEN / KVM (Tutorial)
沒
guessi at gmail.com
Sun Oct 23 03:24:43 UTC 2011
Hi~
Today I'm going to share my simple script and a small tutorial about *"How
to Make Open vSwitch Works"*
All of following messages were tested on my machines
My environment settings: *Open vSwitch + CentOS / Debian / Fedora / Ubuntu
+ KVM / XEN *(Sort Alphabetically)
HERE, what I present is focus on *HOW to make it works smoothly on top of
XEN or KVM hypervisor*
for Xen users, you may need to create three control scripts named:
*network-control
/ network-openvswitch / vif-openvswitch*, and my tutorial
for KVM users, you may need to create the file: *network-control*, and
follow the document *INSTALL.KVM*, and my tutorial
Hope my work could give helps to anyone of you, if you find any bugs, or
having any suggestion, please give me some response, thanks all !!!
Okay, that's brief introduction to my work, let's get it start...
*Firstly, create a control script, named it "network-control"*
---- // network-control // START // -------------
#!/bin/sh
#
---------------------------------------------------------------------------
#
# 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: 2011-08-29
#
# license: GPLv2 (GNU General Public License, Version 2)
# http://www.gnu.org/licenses/gpl-2.0.html
#
#
---------------------------------------------------------------------------
##
--------------------------------------------------------------------------
## Global Variable Definition
##
--------------------------------------------------------------------------
DIR=$(dirname "$0")
PROG=network-control
PROGNAME=UniCloud\ OVS\ Control
VERSION=v0.11.0829
KPATH=/lib/modules/`uname -r`/build
OVSETC=/usr/local/etc/openvswitch
OVSRUN=/usr/local/var/run/openvswitch
ULOCALBIN=/usr/local/bin
ULOCALSBIN=/usr/local/sbin
DEFAULTBR=ovsbr0
ISKVM=0
ISXEN=0
OMETHOD=
OIPADDR=
ONETMASK=
OGATEWAY=
##
--------------------------------------------------------------------------
## Check User's Previlege Before Anything
##
--------------------------------------------------------------------------
if test "$1" != "--version" -a "$1" != "--help" -a "$1" != "usage" ; then
if test `whoami` != "root" ; then
echo "Error Occured: Please switch to \"root\" to execute the
command." ;
exit 1 ;
fi
fi
##
--------------------------------------------------------------------------
## Declaration
##
--------------------------------------------------------------------------
detect_system_ip_info()
{
# TODO: distinguish real/virtual NICs
# i.e. eth0:0, eth0:1, eth0:2
local _PATH=/etc/sysconfig/network-scripts/ifcfg-eth0
local _PATH2=/etc/network/interfaces
if test -f $_PATH ; then
# CentOS / Fedora / RHEL
OMETHOD=`cat $_PATH | grep BOOTPROTO | cut -d '=' -f 2` ;
OIPADDR=`cat $_PATH | grep IPADDR | cut -d '=' -f 2` ;
ONETMASK=`cat $_PATH | grep NETMASK | cut -d '=' -f 2` ;
OGATEWAY=`cat $_PATH | grep GATEWAY | cut -d '=' -f 2` ;
elif test -f $_PATH2 ; then
# Debian / Ubuntu
OMETHOD=`grep iface $_PATH2 | grep inet | grep "eth0 " | awk '{print
$4}'` ;
OIPADDR=`grep address $_PATH2 | awk '{print $2}'` ;
ONETMASK=`grep network $_PATH2 | awk '{print $2}'` ;
OGATEWAY=`grep gateway $_PATH2 | awk '{print $2}'` ;
else
echo "Error Occured: detect_system_ip_info()"
exit 1 ;
fi
# For Ubuntu/Debian, A Brand New PC/NB Have No IP Setting
if test "$OMETHOD" = "" ; then
OMETHOD=dhcp ;
fi
}
detect_ovs_hypervisor()
{
test "`/sbin/lsmod | grep kvm`" != "" && ISKVM=1 || ISKVM=0 ;
test "`/bin/uname -r | grep xen`" != "" && ISXEN=1 || ISXEN=0 ;
if test $ISKVM = 0 -a $ISXEN = 0 ; then
echo "Error, no hypervisor was detected" ;
exit 1 ;
fi
}
ovs_hypervisor()
{
printf "Detecting hypervisor type... " ;
test $ISKVM = 1 && echo "KVM" || \
(test $ISXEN = 1 && echo "XEN" || echo "Unknown") ;
printf "Detecting openvswitch_mod... " ;
detect_module_openvswitch_existance ;
test $? = 0 && echo "Found" || echo "Not Found" ;
printf "Detecting brcompat_mod... " ;
detect_module_brcompat_existance ;
test $? = 0 && echo "Found" || echo "Not Found" ;
}
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_mod | grep -v "grep" > /dev/null 2>&1 ;
}
detect_module_brcompat_existance()
{
/sbin/lsmod | grep brcompat_mod | grep -v "grep" > /dev/null 2>&1 ;
}
ovs_clean()
{
printf "Cleaning previous settings... " ;
cd $DIR && make clean > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
}
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
}
ovs_install()
{
printf "Inspecting your system... " ;
echo "`/bin/uname -srio`" ;
printf "Detecting require packages... " ;
test -d $KPATH && echo "Done" || (echo "Failed." && exit 1);
ovs_stop ;
ovs_clean ;
printf "Initializating environment for Open vSwitch... " ;
cd $DIR && ./configure --with-linux=$KPATH > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || (echo "Failed" && exit 1) ;
printf "Preparing for Open vSwitch installation... " ;
cd $DIR && make > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || (echo "Failed" && exit 1) ;
printf "Installing Open vSwitch... " ;
cd $DIR && make install > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || (echo "Failed" && exit 1) ;
}
ovs_create_br()
{
# Check target bridge's existance
printf "Trying to create the default virtual bridge($DEFAULTBR)... " ;
$ULOCALBIN/ovs-vsctl -- --may-exist add-br $DEFAULTBR ;
test $? = 0 && echo "Done" || echo "Failed" ;
printf "Trying to bring up the default virtual bridge($DEFAULTBR)... ";
/sbin/ifconfig $DEFAULTBR down ;
/sbin/ifconfig $DEFAULTBR up ;
test $? = 0 && echo "Done" || echo "Failed" ;
}
ovs_set_br_ip()
{
# Clean previous ip settings for $DEFAULTBR
/sbin/ifconfig $DEFAULTBR 0.0.0.0 down ;
# Clean previous ip settings for eth0
/sbin/ifconfig eth0 0.0.0.0 down ;
/sbin/ifconfig eth0 up ;
# Method: DHCP / Static
if test "$OMETHOD" = "dhcp" ; then
# kill all existed dhclient process
kill `ps aux | grep dhclient | grep -v "grep" | awk '{ print $2 }'`
# get IP via DHCP assign
printf "Trying to set IP for $DEFAULTBR (DHCP)... " ;
/sbin/ifconfig $DEFAULTBR 0.0.0.0 up ;
/sbin/dhclient $DEFAULTBR ;
test $? = 0 && echo "Done" || echo "Failed" ;
elif test "$OMETHOD" = "none" -o "$OMETHOD" = "static" ; then
# set static IP manually
printf "Trying to set IP for $DEFAULTBR (STATIC)... " ;
/sbin/ifconfig $DEFAULTBR $OIPADDR netmask $ONETMASK up ;
/sbin/route add default gw $OGATEWAY ;
test $? = 0 && echo "Done" || echo "Failed" ;
else
echo "Error occured: set_br_ip()" ;
exit 1 ;
fi
}
ovs_attach_if()
{
local PORTNAME= ;
if test $ISKVM = 0 -a $ISXEN = 1 ; then
PORTNAME=peth0 ;
elif test $ISKVM = 1 -a $ISXEN = 0 ; then
PORTNAME=eth0 ;
else
echo "Error occured: no hypervisor for virtualization was detected" ;
exit 1 ;
fi
printf "Trying to attach physical NIC to ($DEFAULTBR)... " ;
$ULOCALBIN/ovs-vsctl \
list-ports $DEFAULTBR | \
grep $PORTNAME | grep -v "grep" > /dev/null 2>&1 ;
if test $? = 0 ; then
echo "Skip, already exist" ;
else
$ULOCALBIN/ovs-vsctl \
-- --may-exist add-port $DEFAULTBR $PORTNAME > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
fi
# find all vif*.* and then attach them to DEFAULTBR
printf "Trying to attach all virtual interface to ($DEFAULTBR)... " ;
for i in `/sbin/ifconfig | grep vif | awk '{print $1}'` ;
do
$ULOCALBIN/ovs-vsctl \
-- --may-exist add-port $DEFAULTBR $i > /dev/null 2>&1 ;
done
test $? = 0 && echo "Done" || echo "Failed" ;
}
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_mod.ko... " ;
detect_module_openvswitch_existance ;
if test $? != 0 ; then
if ! test -f $DIR/datapath/linux/openvswitch_mod.ko ; then
echo "Failed. openvswitch_mod.ko not found" ;
exit 1 ;
fi
# insert kernel module "openvswitch_mod.ko"
/sbin/insmod $DIR/datapath/linux/openvswitch_mod.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 \
$OVSETC/conf.db \
--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_mod.ko... " ;
detect_module_brcompat_existance ;
if test $? != 0 ; then
# First, test if the module exist?
if ! test -f $DIR/datapath/linux/brcompat_mod.ko ; then
echo "Failed. brcompat_mod.ko not found" ;
exit 1 ;
fi
# Second, trying to insert module "brcompat_mod.ko"
/sbin/insmod $DIR/datapath/linux/brcompat_mod.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 \
--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_create_br ;
# Prevent Error, Always Wait For Devices ready
printf "Wait for virtual bridge device ready... "
while true ;
do
sleep 1 ;
detect_ovs_br_existance $DEFAULTBR ;
test $? = 0 && echo "Done" && break ;
done
ovs_set_br_ip ;
ovs_attach_if ;
}
ovs_show_status()
{
local VBRIDGE=${1:-$DEFAULTBR} ;
printf "Status of $VBRIDGE\n\n" ;
printf "ovs-vsctl:\n" ;
$ULOCALBIN/ovs-vsctl show | sed 's/^/\t/g' ;
printf "\nifconfig:\n" ;
/sbin/ifconfig $VBRIDGE | sed 's/^/\t/g' ;
}
ovs_add_port()
{
local vbr=${1:-$DEFAULTBR} ;
local vif=${2:-vif0.0} ;
# Check target bridge's existance
detect_ovs_br_existance $vbr ;
if test $? != 0 ; then
echo "Error Occured: bridge [$vbr] does not exist" ;
exit 1 ;
fi
printf "Trying to add [$vif] to [$vbr]... " ;
# Then, check if $vif is in $vbr or not?
$ULOCALBIN/ovs-vsctl \
list-ports $vbr | grep $vif | grep -v "grep" > /dev/null 2>&1 ;
if test $? = 0 ; then
echo "Skip, $vif has already attached to $vbr" ;
else
$ULOCALBIN/ovs-vsctl \
-- --may-exist add-port $vbr $vif > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
fi
}
ovs_del_port()
{
local vbr=${1:-$DEFAULTBR} ;
local vif=${2:-vif0.0} ;
# Check target bridge's existance
detect_ovs_br_existance $vbr ;
if test $? != 0 ; then
echo "Error Occured: bridge [$vbr] does not exist" ;
exit 1 ;
fi
printf "Trying to del [$vif] from default [$vbr]... " ;
# Then, check if $vif is in $vbr or not?
$ULOCALBIN/ovs-vsctl \
list-ports $vbr | grep $vif | grep -v "grep" > /dev/null 2>&1 ;
if test $? = 0 ; then
$ULOCALBIN/ovs-vsctl \
-- --if-exists del-port $vbr $vif > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
else
echo "Skip, not exist, or not controlled by $vbr" ;
fi
}
ovs_add_bridge()
{
printf "Trying to add bridge... " ;
detect_ovs_br_existance $1 ;
if test $? = 0 ; then
echo "Failed, already exist" ;
else
$ULOCALBIN/ovs-vsctl -- --may-exist add-br $1 > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
fi
}
ovs_del_bridge()
{
printf "Trying to delete bridge... " ;
detect_ovs_br_existance $1 ;
if test $? != 0 ; then
echo "Failed, target not exist" ;
else
$ULOCALBIN/ovs-vsctl -- --if-exists del-br $1 > /dev/null 2>&1 ;
test $? = 0 && echo "Done" || echo "Failed" ;
fi
}
ovs_usage()
{
printf "Usage: $PROG [OPTION]\n" ;
printf "\n" ;
printf "\tinstall initialize, compile and install\n" ;
printf "\tstart start Open vSwitch as daemon\n" ;
printf "\tstop stop all Open vSwitch processes\n" ;
printf "\tadd-br \$vbr create new virtual bridge\n" ;
printf "\tdel-br \$vbr delete exist virtual bridge\n" ;
printf "\tadd-port \$vbr \$vif attach port to bridge\n" ;
printf "\tdel-port \$vbr \$vif detach port from bridge\n" ;
printf "\tstatus show current status\n" ;
printf "\tclean clean all previous settings\n" ;
printf "\tdetect hypervisor detection (KVM/XEN)\n" ;
printf "\t--version display version infomation and exit\n" ;
printf "\t--help display this help and exit\n\n" ;
printf "\tDefault Bridge Name: $DEFAULTBR\n\n" ;
}
##
--------------------------------------------------------------------------
## Main Procedure
##
--------------------------------------------------------------------------
detect_ovs_hypervisor ;
detect_system_ip_info ;
case "$1" in
install)
ovs_install ;
;;
start|restart|reload|force-start|force-reload)
ovs_start ;
;;
stop)
ovs_stop ;
;;
add-port)
ovs_add_port $2 $3 ;
;;
del-port)
ovs_del_port $2 $3 ;
;;
add-br)
ovs_add_bridge $2 ;
;;
del-br)
ovs_del_bridge $2 ;
;;
status)
ovs_show_status $2 ;
;;
clean)
ovs_clean ;
;;
detect)
ovs_hypervisor ;
;;
--version)
echo "$PROGNAME ($VERSION)" ;
;;
--help|usage)
ovs_usage ;
;;
*)
echo $"$PROG: invalid option -- $1" ;
echo $"Try \`$PROG --help' for more information." ;
exit 1 ;
;;
esac
exit 0 ;
---- // network-control // END // ----------------
*Secondary, create another script for Xen hypervisor, named it
"network-openvswitch" & "vif-openvswitch"
*---- // network-openvswitch // START // ----------------
#!/bin/bash
dir=$(dirname "$0")
. "$dir/xen-script-common.sh"
. "$dir/xen-network-common.sh"
findCommand "$@"
evalVariables "$@"
netdev=${netdev:-eth0}
bridge=${bridge:-ovsbr0}
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 'vSwitch interfaces:'
ovs-vsctl list-ifaces ${bridge}
echo ' '
echo 'vSwitch ports:'
ovs-vsctl list-ports ${bridge}
}
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}" 0.0.0.0 down
ovs-vsctl -- --if-exists 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 -- --if-exists 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
---- // network-openvswitch // END // ----------------
*and*
---- // vif-openvswitch // START // ----------------
#!/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 listbr | 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
---- // vif-openvswitch // END // ----------------
Finally, the tutorial
---- // TUTORIAL // START // -----------------
Tutrial for Network Control Setup
---------------------------------
Introduction
============
Instructions for user who wants to setup the network based on Open
vSwitch
Basic Requirement
=================
Comfirm that processer is virtualization compatible
% egrep -c '(vmx|svm)' /proc/cpuinfo
If it is compatible, you will get the result number greater than 0
If not, your processor may not get the support of full virtualization
Hypervisor Installation
=======================
For Xen user (CentOS/Fedora/RHEL):
% yum update
% yum groupinstall Virtualization
% yum install kernel-xen-devel
For KVM user (Debian/Ubuntu):
% apt-get update
% apt-get install kvm
Verify the installation
=======================
For Xen users, use the command:
% /usr/sbin/xm list
If the installation is complete, you should get the result as follow:
-------------------------------------------------------------
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 98 1 r----- 168.6
CentOS 4 256 1 r----- 10.7
-------------------------------------------------------------
For KVM users, use the command:
% /sbin/lsmod | egrep '(kvm|kvm_intel|kvm_amd)'
If the installation is complete, you should get the result as follow:
-----------------------------------------
kvm_intel 35761 0
kvm 213284 1 kvm_intel
-----------------------------------------
OR
-----------------------------------------
kvm_amd 30274 0
kvm 195127 1 kvm_amd
-----------------------------------------
Disable SELinux and NetworkManager
==================================
<OMITTED>
Prepare for Open vSwitch Installation
=====================================
% fetch http://openvswitch.org/releases/openvswitch-1.2.0.tar.gz
% tar zxvf openvswitch-1.2.0.tar.gz -C /opt
% mv /opt/openvswitch-1.2.0 /opt/openvswitch
Setup network conotrol scripts (Terminal Interface)
===================================================
Get the latest network-control script
% fetch <SCRIPT_PATH>
% mv network-control /opt/openvswitch
Set execute-bit for the script, don't forget it!!
% chmod u+x /opt/openvswitch/network-control
Install Open vSwitch to the system
% /opt/openvswitch/network-control install
Make Open vSwitch automatically startup
Edit '/etc/rc.local' and add following command before 'exit 0'
+ /opt/openvswitch/network-control start ;
For XEN user, Domain-U network setup
====================================
% fetch <SCRIPT_PATH>
% cp network-openvswitch /etc/xen/scripts/
% cp vif-openvswitch /etc/xen/scripts/
% chmod u+x network-openvswitch
% chmod u+x vif-openvswitch
For KVM user, Guest-Domain network setup
========================================
Create the following two files (Host Domain)
/etc/ovs-ifup
---%<----------%<----------%<----------%<----------%<----------%<---
#!/bin/sh
switch='ovsbr0'
/sbin/ifconfig $1 0.0.0.0 up
/usr/local/bin/ovs-vsctl -- --may-exist add-port ${switch} $1
--->%---------->%---------->%---------->%---------->%---------->%---
/etc/ovs-ifdown
---%<----------%<----------%<----------%<----------%<----------%<---
#!/bin/sh
switch='ovsbr0'
/sbin/ifconfig $1 0.0.0.0 down
/usr/local/bin/ovs-vsctl -- --if-exists del-port ${switch} $1
--->%---------->%---------->%---------->%---------->%---------->%---
Set execution bit for ovs-ifup / ovs-ifdown
% chmod u+x /etc/ovs-ifup
% chmod u+x /etc/ovs-ifdown
Examples (Network Control)
==========================
To perform a brand new Open vSwitch installation or version upgrade:
% /opt/openvswitch/network-control install
To detect the hypervisor is KVM or XEN:
% /opt/openvswitch/network-control detect
To add a bridge on the server:
% /opt/openvswitch/network-control add-br <BRIDGE_NAME>
To delete a existed bridge from the server:
% /opt/openvswitch/network-control del-br <BRIDGE_NAME>
To add a port to the bridge:
% /opt/openvswitch/network-control add-port <BRIDGE_NAME> <PORT_NAME>
To delete a port from the bridge:
% /opt/openvswitch/network-control del-port <BRIDGE_NAME> <PORT_NAME>
To query current network status:
% /opt/openvswitch/network-control status
To get the version information:
% /opt/openvswitch/network-control --version
To get the help message:
% /opt/openvswitch/network-control --help
Startup a Guest VM
==================
For XEN users:
Dump the information of Domain-U into xml, then patch it
<interface type='bridge'>
<mac ....>
- <source bridge='virbr0'>
- <script path='vif-bridge'>
+ <source bridge='ovsbr0'>
+ <script path='vif-openvswitch'>
<target ...>
<interface>
% virsh create vUbuntu.xml
Access the VM as normal
For KVM users:
Use the executable script 'kvm-control'
Bug Report
==========
Kuo-Le, Mei (guessi at gmail.com)
Dept. of CSIE, National Dong Hwa University, Taiwan
Last Modified
=============
2011-09-05
---- // TUTORIAL // END // ------------------
*Again, thanks to, of course, all Open vSwitch teams' greate job you do
really help a lot !!!*
Since my mother language is not English, if there have any statement
inappropriate, oops... sorry, that's my bad :'(*
Any advice would be appreciate... : )*
Kuo-LE, Mei
guessi at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://openvswitch.org/pipermail/ovs-discuss/attachments/20111023/8b9da44d/attachment.html>
More information about the discuss
mailing list