Open vSwitch on VirtualBox
Here is a quick tutorial for installing Open vSwitch on VirtualBox. VirtualBox is an open source virtualization project from Oracle. It is supported on Windows, Mac, BSD and Linux to name a few. It has a nice GUI for VM management out of the box. Open vSwitch is an open source vSwitch from Martin Casado, Ben Pfaff and a whole crew of awesome. If you are here, OVS probably doesn’t require anymore explanation, learn it, love it.
Install VirtualBox
Install VirtualBox from the VirtualBox repository.
Add the following repo to /etc/apt/sources.list deb http://download.virtualbox.org/virtualbox/debian precise contrib wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add - sudo apt-get update sudo apt-get install dkms sudo apt-get install virtualbox-4.2
Install Open vSwitch from repo
Install Open vSwitch from Package. This is easiest for those not familiar with compiling from source or just need basic functionality rather than the latest features.
sudo apt-get install openvswitch-datapath-source bridge-utils sudo module-assistant auto-install openvswitch-datapath sudo apt-get install openvswitch-brcompat openvswitch-common openvswitch-controller
Open vSwitch Install from Source
Install dependencies and install from source on Ubuntu Linux.
apt-get install -y git python-simplejson python-qt4 python-twisted-conch automake autoconf gcc uml-utilities libtool build-essential git pkg-config linux-headers-uname -rgit clone git://openvswitch.org/openvswitch cd openvswitch ./boot.sh ./configure --with-linux=/lib/modules/uname -r/build make && make install ./boot.sh ./configure --with-linux=/lib/modules/uname -r/build make && make install insmod datapath/linux/openvswitch.ko touch /usr/local/etc/ovs-vswitchd.conf mkdir -p /usr/local/etc/openvswitch ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema ovsdb-server /usr/local/etc/openvswitch/conf.db \ --remote=punix:/usr/local/var/run/openvswitch/db.sock \ --remote=db:Open_vSwitch,manager_options \ --private-key=db:SSL,private_key \ --certificate=db:SSL,certificate \ --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach --log-file ovs-vsctl --no-wait init ovs-vswitchd --pidfile --detach
Create Open vSwitch bridge and interfaces
To setup the virtual interfaces use Tuntap. Tuntap sets up a emulates an L2 interface. That interface will show up in the interface as a physical interface.
ovs-vsctl add-br br0 ip tuntap add mode tap vnet0 ip link set vnet0 up ovs-vsctl add-port br0 vnet0 ip link (View the created interface)
Spin up VirtualBox instances with Open vSwitch Interfaces
For testing Open vSwitch or any other hypervisor testing, I highly recommend this Linux image linux-0.2.img. It only takes a couple of MB of memory. It is perfect for nested hypervisor testing.
Connect the Open vSwitch bridge to the physical network
You can put the following into a text file and give it execute permissions with “chmod +x filename” and then run it “./filename”. If your network settings are right it should flip the IP to the bridge and not cut you off. Keyword “should” so have a way to get to the box if you cut yourself off. What is happening here is you are placing both the virtual interface “vnet0″ and the physical Nic “eth0″ into the same bridge “br0″. You can think of a bridge as a logical grouping of virtual and physical interface much like a locally significant VLAN without the 0×8100 Ethertype framing and tag.
ovs-vsctl add-br br0 ovs-vsctl add-port br0 eth0 ovs-vsctl add-port br0 vnet0 ifconfig eth0 0 && ifconfig br0 192.168.1.(X) netmask 255.255.255.0 route add default gw 192.168.1.1 br0 route del default gw 192.168.1.1 eth0
Download your test image. If using the Linux-0.2.img it needs to be converted to vdi first using the VBoxManage utility included with the VirtualBox binary.
wget http://wiki.qemu.org/download/linux-0.2.img.bz2 bunzip2 linux-0.2.img.bz2 VBoxManage convertdd linux-0.2.img linux-0.2.vdi
- Create a new Virtualbox instance. Choose the linux-0.2.vdi (must duplicate the VDI or else all meta-data is the same and Vbox wont load the IMG). Do this as a regular user or else you will get permissions error.
- Choose “use existing virtual HD”
- Ignore “failed to get USB blah”.
- If you get “dpif_linux|ERR|Generic Netlink family ‘ovs_datapath’ does not exist. The Open vSwitch kernel module is probably not loaded.” Make sure you are adding the Open vSwitch kernel module e.g insmod datapath/linux/openvswitch.ko.
- Under interfaces set to “bridged interface” and choose the port on the appropriate bridge. E.g Bridge1-p2, br-head-p1 etc. Make sure it is a port and not a bridge.
- You can go really low on memory, I tend to just use 32mb but you can go less.
Thanks for stopping by.
















Nice writing, I’ll give it a try on upcoming weekend!
Brent , it is unclear how can I load the vSwitch on OS X Mountain Lion . I have virtualbox installed on it and have Fedora/Ubuntu running as VM on VirtualBox
Hi Raj, you would install (binary) or compile (source) Open vSwitch on the Ubuntu guest host running inside nested inside the Ubuntu host.
-So on your mac install VMFusion or Virtualbox and spin up an Ubuntu host.
-On the Ubuntu host, install OVS and VirtualBox.
-For performance you would run Ubuntu natively on the bare metal pc/server.
Lemme know if that doesnt make sense.
Respect,
-Brent
Hello! Thank for this note. But I have just a question, Can we do a ping to an external network (to internet, for example “ping 8.8.8.8″)? If it isn’t possible, how could I do it?
Thank you.
Hi Daniel,
Couple of things to check.
1. Make sure you added eth0 to br0 (or whatever you named the OVS bridge with “ovs-vsctl add-br br0″). To add eth0 to the br0 bridge run “ovs-vsctl add-port br0 eth0″. vnet0 needs to also be in that same bridge with “ovs-vsctl add-port br0 vnet0″
2. zero out eth0. “ifconfig eth0 0″ (warning that will cut you off, pop it in a bash script if remote).
3. Add the eth0 ip to br0. “ifconfig br0 192.168.1.10 netmask 255.255.255.0″ < -insert your IPs.
4. Add a default route/gateway. “route add default gw 192.168.1.1 br0″ <-insert your default gw.
5. Do a “route -n” and check for the 0.0.0.0 route using br0. If there is one still with eth0 run “route del default gw 192.168.1.1 eth0″ to delete the old eth0 route.
6. Try pinging your default gateway to make sure you have local connectivity.
7. “ifconfig -a”
Hello Brent,
Thank you very much for this useful guide.
I was trying to follow it and install a ovs with several VMs in virtual box.
I wasn’t sure if I should define a new virtual interface for each VM, and if so should it also be in the same bridge interface?
Thank you,
Avi.
Hi Avi,
You got it, new vPort needs be created and added to the single bridge. New bridges would be if you need seperate datapaths. Think of the different bridges as totally seperate physical switches. Like a VDC on a Cisco Nexus or logical-system in Junos on Juniper platforms.
In the following example:
Bridge == Bridge1
Portnames == Bridge1p1 && Bridge1p2
ovs-vsctl add-br Bridge1
ip tuntap add mode tap Bridge1p1
ip link set Bridge1p1 up
ip link
ovs-vsctl add-port Bridge1 Bridge1p1
ovs-vsctl add-br Bridge1
ip tuntap add mode tap Bridge1p2
ip link set Bridge1p2 up
ip link
ovs-vsctl add-port Bridge1 Bridge1p2
This article was really the kick in the teeth to run Ubuntu as my primary OS on every desktop+laptop I use. Everything I have is either Ubuntu, or a bare metal hypervisor of some sort. Too much stuff to test!