Friday, January 6, 2012

Openvswitch with Virtualbox

This tutorial assume that you already configured openvswitch on virtualbox host machine.

Create the virtual switch on the host machine:
ovs-vsctl add-br lan0
Now we have a virtual switch called lan0 :)

Next we create tap devices on the host machine so we can bind them to the guests laters.
for tap in `seq 0 15`; do
        ip tuntap add mode tap lan0p$tap
done;
# check if the interfaces are there
ip tuntap list

Bring the tap interfaces up:
for tap in `seq 0 15`; do 
        ip link set lan0p$tap up
done;

# check if the interface are up
ip link

Now we use ovs-vsctl to "bind" the tap devices to "lan0" switch
for tap in `seq 0 15`; do
        ovs-vsctl add-port lan0 lan0p$tap
done;

# see that the tap devices are mapped to ports in lan0
ovs-vsctl list-ports lan0

Now we have 16 ports switch called lan0 with 16 tap interfaces binded to lan0 virtual switch.

Next thing is to connect virtualbox guests to it:

I assume you are using the GUI for this so under the network setting select in "Attached to" "Bridge Adapter" and in "Name" select "lan0p1" for port number 1 in the switch.

Repeat this action for each guest you want to connect to the switch.

Now your virtual machines has a virtual network ;)

Enjoy !

Golan

5 comments:

Anonymous said...

Thank you, this was extremely helpful.

Gilbert Standen said...

Hi Golan,

To say this was extremely helpful post is an understatement. I built on your work here and extended it to openvswitch config with 2 redundant switches connected by bonded switch vports with 2 Oracle RAC node bonded private interconnect connected criss-cross over the switches with the bonded vport interswitch link as the "pathway of last resort" so to speak. Here is my howto:

http://thecomingstorm.us/smf/index.php?topic=323.0

Golan Zakai said...

Hey Gilbert,

I am very happy that my post helped ya, nice work with the dual switch + bonding !

Golan

Anonymous said...

To connect to an external switch via a trunk containing multiple vlans:

ovs-vsctl add-port lan0 eth1

ovs-vsctl set port lan0 lan0p3 tag=333

port 3 on the virtual switch will become an access port for vlan 333.

Anonymous said...

How to make it to survive reboots in ubuntu 12.04.

Suppose your server has eth1 connected to a VLAN trunk port to a physical switch, and you want to access some VLANs (say 222 and 221) from there withing your server as discrete virtual switch ports (for example, to brigde VirtualBox machines to them).

In /etc/network/interfaces eth1 defined as VLAN trunk and calling the build-up of the TAP interfaces connected to the virtual switch.

iface eth1 inet manual
pre-up ifconfig eth1 up
post-up /etc/network/add_vswitch0.sh
post-down ifconfig eth1 down


Contents of the /etc/network/add_vswitch0.sh script:


#!/bin/sh

for i in 222 221; do
ip tuntap del sw0_vlan$i mode tap
done;
ovs-vsctl del-br sw0

sleep 1

ovs-vsctl add-br sw0
ovs-vsctl add-port sw0 eth1
for i in 222 221; do
ip tuntap add mode tap sw0_vlan$i
ip link set sw0_vlan$i up
ovs-vsctl add-port sw0 sw0_vlan$i tag=$i
done;


I agree it's not too nice but it works reliably.