February 8, 2018

413 words 2 mins read

PiOVS: Raspberry Pi Open vSwitch

PiOVS: Raspberry Pi Open vSwitch

Learning introductory SDN concept with Mininet is mostly enough. But sometimes it is nice to have a mobile, small-scale SDN lab for showcase and live demo sessions in the class. Below you'll find a short guide to 'convert' a raspberry pi (RPI2) to a 4-port OpenFlow Open vSwitch. For this purpose, you'll need 4x USB-to-RJ45 adapter.

Install Ubuntu Xenial & Preparation

# Flash
$ flash -d /dev/mmcblk0 ubuntu-16.04.3-preinstalled-server-armhf+raspi2.img

# Configure some params
$ cd /media/em/cloudimg-rootfs/
/media/em/cloudimg-rootfs$ sudo nano etc/hostname
/media/em/cloudimg-rootfs$ sudo nano etc/hosts
/media/em/cloudimg-rootfs$ sudo nano etc/network/interfaces

# Boot & SSH
$ sudo apt update
$ sudo shutdown -r now
$ sudo apt upgrade

$ nano .profile
# add these lines
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"

$ source .profile
$ sudo dpkg-reconfigure locales

# Check
ubuntu@pi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

$ cat /proc/version
Linux version 4.4.0-1065-raspi2 (buildd@bos01-arm64-049) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #73-Ubuntu SMP Thu Jul 20 22:09:48 UTC 2017

Install OVS

ubuntu@pi:~$ sudo apt install openvswitch-
openvswitch-common          openvswitch-pki             openvswitch-testcontroller
openvswitch-dbg             openvswitch-switch          openvswitch-vtep
openvswitch-ipsec           openvswitch-test            

ubuntu@pi:~$ sudo apt install openvswitch-switch openvswitch-common bridge-utils

ubuntu@pi:~$ sudo ovs-vsctl show
    ovs_version: "2.5.2"

ubuntu@pi:~$ sudo ovs-vsctl add-br ovsbr0

ubuntu@pi:~$ sudo ifconfig ovsbr0 up
ubuntu@pi:~$ ifconfig

ubuntu@pi:~$ sudo ovs-vsctl add-port ovsbr0 eth1
ubuntu@pi:~$ sudo ovs-vsctl add-port ovsbr0 eth2
ubuntu@pi:~$ sudo ovs-vsctl add-port ovsbr0 eth3
ubuntu@pi:~$ sudo ovs-vsctl add-port ovsbr0 eth4

ubuntu@pi:~$ sudo ovs-vsctl show

Configure Interfaces

ubuntu@pi:~$ cat /etc/network/interfaces
# 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

# Source interfaces
# Please check /etc/network/interfaces.d before changing this file
# as interfaces may have been defined in /etc/network/interfaces.d
# See LP: #1262951
# source /etc/network/interfaces.d/*.cfg

allow-hotplug eth0
iface eth0 inet static

auto eth1
iface eth1 inet manual
        hwaddress ether 00:20:34:60:75:ba

auto eth2
iface eth2 inet manual
        hwaddress ether 00:15:a3:34:28:2c

auto eth3
iface eth3 inet manual
        hwaddress ether 58:65:e6:eb:f0:c5

auto eth4
iface eth4 inet manual
        hwaddress ether 00:0b:7b:cf:d4:3c

auto ovsbr0
allow-ovs ovsbr0
iface ovsbr0 inet manual
  ovs_type OVSBridge

Patch OVS Systemd Service

ubuntu@pi:~$ sudo rm  /lib/systemd/system/openvswitch-nonetwork.service && sudo nano /lib/systemd/system/openvswitch-nonetwork.service

# Copy from here -> https://www.opencloudblog.com/?p=240

ubuntu@pi:~$ sudo shutdown -r now

Try with POX Controller

ubuntu@pi:~$ git clone https://github.com/noxrepo/pox.git

ubuntu@pi:~$ cd pox
ubuntu@pi:~/pox$ ./pox.py forwarding.l2_learning &

ubuntu@pi:~$ sudo ovs-vsctl set-controller ovsbr0 tcp:localhost:6633


comments powered by Disqus