Open vSwitch on Gentoo – Setting Up Your First vSwitch

image_pdfimage_print

In my last post I outlined how to get Open vSwitch installed on Gentoo from source for version 1.11.0 as well as from portage using version 2.0.0. I also described how to associate Open vSwitch with with Xen based virtual machines. This guide will detail how to build your first virtual switch from scratch and create virtual switch ports associated with the virtual switch that persist upon a reboot of the host machine. The virtual ports can then be used with VirtualBox VMs and other generic applications that can make use of them.

If you followed my last post you should have Open vSwitch installed and the respective services running. You should also have created an initial bridge interface, this was called xenbr0 and was created with the following commands:

ovs-vsctl add-br xenbr0
ovs-vsctl add-port xenbr0 enp4s0
ovs-vsctl set bridge xenbr0 stp_enable=true

where enp4s0 is your physical interface that is bound to the bridge. This is necessary since this will be the “switch” port that “uplinks” the vSwitch to the rest of the physical network.

You should now be able to view the current bridge setup by using the following command:

ovs-vsctl show

Which should display output similar to this:

b73df7bf-446c-4e59-ad63-e9fa198cbaa7
    Bridge "xenbr0"
        Port "enp4s0"
            Interface "enp4s0"
        Port "xenbr0"
            Interface "xenbr0"
                type: internal

This shows that the bridge is created and has a single port attached to it labeled enp4s0 that is bound to the physical interface enp4s0.

At this point you should be fine if you were using this for a Xen based setup since the hotplug scripts provided with xen-tools will take care of the virtual interface setup for each VM. However if you want to use Open vSwitch with VirtualBox based VMs on a Gentoo host read on …

In order to create virtual switch ports that you can bind to your virtual machines a tun/tap interface must be created for each port that will be needed. So if you wish to create a 16 port switch 16 tap interfaces will be necessary. These interfaces can be added to the vSwitch as follows:

First verify that the tun module is loaded

modprobe tun

If this does not run verify that you have tun compiled as a module in your kernel.

grep -i tun /usr/sr/linux/.config
CONFIG_TUN=m

And that the tun module is set to load on boot up in /etc/conf.d/modules:

modules_3="tun"

Next create the tap interfaces for each virtual switch port, in this example I will create an 8 port switch.

ovs-vsctl add-port xenbr0 xenbr0p0
ovs-vsctl add-port xenbr0 xenbr0p1
ovs-vsctl add-port xenbr0 xenbr0p2
ovs-vsctl add-port xenbr0 xenbr0p3
ovs-vsctl add-port xenbr0 xenbr0p4
ovs-vsctl add-port xenbr0 xenbr0p5
ovs-vsctl add-port xenbr0 xenbr0p6
ovs-vsctl add-port xenbr0 xenbr0p7

Now check that they were added:

ovs-vsctl list-ports xenbr0

Which should display:

enp4s0
xenbr0p0
xenbr0p1
xenbr0p2
xenbr0p3
xenbr0p4
xenbr0p5
xenbr0p6
xenbr0p7

This indicates that the virtual ports have been associated with the vSwitch xenbr0, however the interfaces still need to be created. In order to do this entries need to be made in /etc/conf.d/net that describes each tap interface and how they will be configured at bootup. In the case of these tap interfaces we want them to be brought up but not configured. So in /etc/conf.d/net add the following entries:

config_enp4s0="null"

tuntap_xenbr0p0="tap"
config_xenbr0p0="null"

tuntap_xenbr0p1="tap"
config_xenbr0p1="null"

tuntap_xenbr0p2="tap"
config_xenbr0p2="null"

tuntap_xenbr0p3="tap"
config_xenbr0p3="null"

tuntap_xenbr0p4="tap"
config_xenbr0p4="null"

tuntap_xenbr0p5="tap"
config_xenbr0p5="null"

tuntap_xenbr0p6="tap"
config_xenbr0p6="null"

tuntap_xenbr0p7="tap"
config_xenbr0p7="null"

Notice how they are all set to “null” this indicates that on bootup they will not be assigned an IP address nor will they poll a DHCP server for an address.

Next create the device symlinks in /etc/init.d/ as you would for any other network interface so that they can be started on bootup:

cd /etc/init.d/
ln -s net.lo net.xenbr0p0
ln -s net.lo net.xenbr0p1
ln -s net.lo net.xenbr0p2
ln -s net.lo net.xenbr0p3
ln -s net.lo net.xenbr0p4
ln -s net.lo net.xenbr0p5
ln -s net.lo net.xenbr0p6
ln -s net.lo net.xenbr0p7

Then add them to the default runlevel:

rc-update add net.enp4s0 default
rc-update add net.xenbr0p0 default
rc-update add net.xenbr0p1 default
rc-update add net.xenbr0p2 default
rc-update add net.xenbr0p3 default
rc-update add net.xenbr0p4 default
rc-update add net.xenbr0p5 default
rc-update add net.xenbr0p6 default
rc-update add net.xenbr0p7 default

Now reboot the server and everything should start up correctly.

After the server comes back online verify that the new ports are all associated with the vSwitch.

ovs-vsctl show

Which should return output similar to this:

b73df7bf-446c-4e59-ad63-e9fa198cbaa7
    Bridge "xenbr0"
        Port "xenbr0p1"
            Interface "xenbr0p1"
        Port "xenbr0p2"
            Interface "xenbr0p2"
        Port "xenbr0p7"
            Interface "xenbr0p7"
        Port "xenbr0p5"
            Interface "xenbr0p5"
        Port "xenbr0p4"
            Interface "xenbr0p4"
        Port "enp4s0"
            Interface "enp4s0"
        Port "xenbr0p3"
            Interface "xenbr0p3"
        Port "xenbr0p6"
            Interface "xenbr0p6"
        Port "xenbr0p0"
            Interface "xenbr0p0"
        Port "xenbr0"
            Interface "xenbr0"
                type: internal

Finally fire up VirtualBox and create a new VM or go to the settings of an old VM and set the network interface to “bridged mode” and choose one of the new switch ports in the list. Fire up the VM and you should have a connection!

References:

Xen Networking – Xen
Openvswitch with Virtualbox

  1. No Comments