Skip to content

Instantly share code, notes, and snippets.

@abhiverma866
Last active December 29, 2023 07:00
Show Gist options
  • Save abhiverma866/c40024fd9245e90d3645922b1ffe22e6 to your computer and use it in GitHub Desktop.
Save abhiverma866/c40024fd9245e90d3645922b1ffe22e6 to your computer and use it in GitHub Desktop.
Setting up SDN network using OpenVSwitch (2.17.2) on Raspberry Pi running with Raspbian OS
### Download the most recent OpenvSwitch from LTS series [https://www.openvswitch.org/releases/openvswitch-2.17.2.tar.gz]
wget http://openvswitch.org/releases/openvswitch-2.17.2.tar.gz
tar -xvzf openvswitch-2.17.2.tar.gz
cd openvswitch-2.17.2
### Install all dependencies:
sudo apt-get install python-simplejson python-qt4 libssl-dev python-twisted-conch automake autoconf gcc uml-utilities libtool build-essential pkg-config
### if python-simplejson python-qt4 python-twisted-conch fail to install then manually install them using pip.
pip install simplejson
pip install python-qt
pip install Twisted
### Build openvswitch: if fails then try with sudo (root permissions)
./configure
make -j4
make -j4 install
### Set up local variables:
cd datapath/linux/
modprobe openvswitch
cd ../..
touch /usr/local/etc/ovs-vswitchd.conf
mkdir -p /usr/local/etc/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema
mkdir -p /usr/local/var/run/openvswitch
### Create starting master script:
sudo nano /etc/init.d/superscript.sh
"""
#!/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
"""
### Start openvswitch service:
/etc/init.d/superscript.sh
### Set up starting openvswitch on boot:
/etc/init.d/superscript
sudo chmod 755 /etc/init.d/superscript
sudo update-rc.d superscript defaults
###Configuring and Starting the Switch
###Add a new bridge
ovs-vsctl add-br br0
###Connect USB-to-ethernet to the pi. Note their interface names; say it’s eth1, eth2
###Connect the interfaces to the bridge
ovs-vsctl add-port br0 eth1
ovs-vsctl add-port br0 eth2
#Turn on the interfaces
ifconfig eth1 0 up
ifconfig eth2 0 up
###Connect the switch to an external controller running on host with IP 10.10.20.20 in this case
ovs-vsctl set-controller br0 tcp:10.10.20.20:6633
###The OpenFlow switch is now running and can be checked from top/htop or system resource monitor
## Turning on the switch the next time when you reboot
### run master script e.g. superscript.sh
sudo ./etc/inint.d/superscript.sh
###Turn on all the OVS interfaces in each switch (eth1, eth2)
### Pro Tips:
1. Manually assign IP to host that you connect with USB LAN adapters. Also you may assign IP to eth0 port (Pi's LAN port).
2. Try to check connectivity b/w switch-eth0 and controller, and host to host connected on USB LAN adapters.
@manavdesai27
Copy link

Sir you might have to add one line before creating the scipt.
mkdir -p /usr/local/var/run/openvswitch

@abhiverma866
Copy link
Author

Noted and corrected the same in [instructions_commands.txt].

Sir you might have to add one line before creating the scipt. mkdir -p /usr/local/var/run/openvswitch

@kartikg33
Copy link

Line 75: sudo ./etc/inint.d/superscript.sh
Do you mean init.d instead of inint.d?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment