Converting a Raspberry Pi to a OpenFlow Switch

Why do it in the first place?

Software Defined Networking is a new paradigm in the field of systems. More and more areas are slowly including SDN in their system for greater flexibility and control.

But there is a simple problem with SDN as of now.

You see, all great system paradigms became great because of a few simple reasons

  1. Accessible to the public
  2. Easy to use
  3. Cheap in implementation

I believe that SDN has points 1 and 2 covered as it’s an open standard and has nice API. There are also emulators to try them out, like Mininet and Maxinet. However, when it comes to hardware, SDN has a small issue. The cheapest industry-standard SDN-enabled hardware costs a little over a thousand dollars. With hardware costing so much, independent developers can’t do anything. Recently, Northbound Networks tried to solve this problem by introducing Zodiac-FX; a $100 SDN switch with four 100 Mbit port, which is perfect for developing and hacking.

However, I had a different goal.

Why not use an existing popular hardware platform and make a switch out of it?

This is where this guide comes to help. Without further ado, let us dive in

Downloading required stuff

  1. Login to root and move to home directory of root
    sudo su
  2. Download openvswitch
    wget http://openvswitch.org/releases/openvswitch-2.5.2.tar.gz
  3. Unpack the archive
    tar -xvzf openvswitch-2.5.2.tar.gz
  4. Install the following
    apt-get install python-simplejson python-qt4 libssl-dev python-twisted-conch automake autoconf gcc uml-utilities libtool build-essential pkg-config
    apt-get install linux-headers-3.10-3-rpi

Make and install

  1. In the openvswitch folder, configure, make and install. Installation may take some time, so have patience
./configure --with-linux=/lib/modules/3.10-3-rpi/build
make
make install

Preparing to initiate OpenVSwitch

  1. Turn on the openvswitch module. Make sure to turn on the module from inside the directory. In case modprobe does not work, restart the Pi
  2. cd openvswitch-2.5.2/datapath/linux
    modprobe openvswitch
    
  3. Create a script ovs_script.sh with the following code
  4. #!/bin/bash
    ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
        --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
        --private-key=db:Open_vSwitch,SSL,private_key \
        --certificate=db:Open_vSwitch,SSL,certificate \
        --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
        --pidfile --detach
    ovs-vsctl --no-wait init
    ovs-vswitchd --pidfile --detach
    ovs-vsctl show
    
  5. Create a file for the database, which will contain the details of the switch
    touch /usr/local/etc/ovs-vswitchd.conf
  6. Make the following directory
    mkdir -p /usr/local/etc/openvswitch
  7. Populate the database, which will be used by the ovswitch
    ./openvswitch-2.5.2/ovsdb/ovsdb-tool create /usr/local/etc/openvswitch/conf.db /root/openvswitch-2.5.2/vswitchd/vswitch.ovsschema
  8. Run the script ovs_script.sh in this section

The switch has now been created

Configuring and Starting the Switch

  1. Add a new bridge
    ovs-vsctl add-br br0
  2. Connect USB-to-ethernet to the pi. Note their interface names; say it’s eth1, eth2, and eth3
  3. Connect the interfaces to the bridge
  4. ovs-vsctl add-port br0 eth1
    ovs-vsctl add-port br0 eth2
    ovs-vsctl add-port br0 eth3
    
  5. Turn on the interfaces
  6. ifconfig eth1 0 up
    ifconfig eth2 0 up
    ifconfig eth3 0 up
    
  7. Connect the switch to an external controller. I used a Pox controller.
    ovs-vsctl set-controller br0 tcp:10.10.20.20:6633

The OpenFlow switch is now running.

Turning on the switch the next time

  1. Turn on the openvswitch module by using modprobe
  2. Run the script/daemon ovs_script.sh
  3. Turn on all the OVS interfaces in each switch (eth1, eth2, eth3)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s