Open vSwitch: basic initial setup on Ubuntu 12.04

Software defined networking is all the rage these days in IT, and Open vSwitch is where most people get their first introduction. Whether you’re running KVM or Xen, Open vSwitch will allow you to abstract network setup functions from the hypervisor. Here’s a quick guide to setting up Open vSwitch and replacing a physical interface with a virtual one:

Be sure you have the latest kernel and updates:

$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade

First let’s install the Open vSwitch software:

$ sudo apt-get install openvswitch-brcompat openvswitch-common openvswitch-datapath-dkms openvswitch-datapath-source openvswitch-switch
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  bridge-utils dkms module-assistant
Suggested packages:
  ethtool
The following NEW packages will be installed:
  bridge-utils dkms module-assistant openvswitch-brcompat openvswitch-common openvswitch-datapath-dkms openvswitch-datapath-source openvswitch-switch
0 upgraded, 8 newly installed, 0 to remove and 14 not upgraded.
Need to get 0 B/6,355 kB of archives.
After this operation, 20.6 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
...

This should insert the Open vSwitch bridge module, to ensure it loads on startup append brcompat to /etc/modules.

Now let’s create a virtual switch, connect a physical interface to that virtual switch, and add a new virtual interface:

  1. Create our new virtual switch outside-br
  2. $ sudo ovs-vsctl add-br outside-br
    $ sudo ovs-vsctl show
        Bridge outside-br
            Port outside-br
                Interface outside-br
                    type: internal

    Now that we’ve created our new virtual switch, let’s connect a physical interface to it. Be aware that if you’re connected remotely to the system via the eth0 interface, the following step will disconnect you. Be sure you have console access first.

  3. Connect the physical interface eth0 to our virtual switch outside-br:
  4. $ sudo ovs-vsctl add-port outside-br eth0
    $ sudo ovs-vsctl show
        Bridge outside-br
            Port outside-br
                Interface outside-br
                    type: internal
            Port "eth0"
                Interface "eth0"

    Now that we have our virtual switch outside-br, and a physical interface eth0 uplinked to it, let’s add a new virtual interface to our system. Note that setting the virtual interface to a port type of “internal” makes the new virtual interface available to the parent OS directly. This is not required, but it allows you to replace a physical interface (eth0) with a virtual one (outside).

  5. Add the virtual interface outside to our virtual switch outside-br:
  6. $ sudo ovs-vsctl add-port outside-br outside -- set Interface outside type=internal
    $ sudo ovs-vsctl show
        Bridge outside-br
            Port outside
                Interface outside
                    type: internal
            Port outside-br
                Interface outside-br
                    type: internal
            Port "eth0"
                Interface "eth0"

    Finally you must modify the /etc/network/interfaces file in order for Open vSwitch to bring up all the interfaces appropriately. The specific syntax below is required for Open vSwitch to bring up all interfaces on the outside-br switch automatically on system boot.

  7. Add the following to /etc/network/interfaces:
  8. # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    auto eth0
    iface eth0 inet manual
    up ifconfig $IFACE 0.0.0.0 up
    down ifconfig $IFACE down

    # Virtual interface connected to outside-br
    auto outside
    iface outside inet dhcp

    Since /etc/init.d/networking does not understand the Open vSwitch syntax in /etc/network/interfaces, it will cause a system delay after issuing the “ifup” commands on boot. To avoid the delay, modify the following lines in /etc/init/failsafe.conf:

    $PLYMOUTH message --text="Waiting for network configuration..." || :
    sleep 40
    $PLYMOUTH message --text="Waiting up to 60 more seconds for network configuration..." || :
    sleep 59
    $PLYMOUTH message --text="Booting system without full network configuration..." || :

    To sleep less time:

    $PLYMOUTH message --text="Waiting for network configuration..." || :
    sleep 1
    $PLYMOUTH message --text="Waiting up to 60 more seconds for network configuration..." || :
    sleep 1
    $PLYMOUTH message --text="Booting system without full network configuration..." || :

    Now reboot! Once the system is up you should see interfaces eth0 (Physical), lo (Loopback), and outside (Virtual). You can modify the interface configuration for the outside interface to suit your network layout (Static vs. dhcp, etc.).

Leave a Reply

Your email address will not be published. Required fields are marked *