Part1 – OPENVSWICH – Creating and Submitting Openvswitch Extension To Microcore Upstream
September 3, 2011 8 Comments
In May 2011, I read a request for installation Openvswitch on Qemu image. I started to play with Openvswitch and finally became addictive to this project. I realized how powerful can be Openvswitch, offering many features listed here. Spending my free time playing with Microcore and Openvswitch after several days I was able to create Microcore Qemu image with 8021q support and install Openvswitch on top of it.
In this tutorial I would like to show how to create Openvswitch extension and make it ready for submit to the Microcore/Tinycore upstream. I chose Microcore Linux, because I am familiar with this minimal Linux distribution and the Microcore is incredibly small. Unless there is not the newer version than Openvswitch 1.2.2 you don’t have to create an Openvswitch extension since my extension has been added to Microcore repository.
The following steps describe installation Openvswitch on Qemu image with pre-installed Microcore Linux.
If you don’t want to install openvswitch by yourself, you can download my own Openvswitch 1.2.2 /Microcore 4.0 Qemu mage.
http://www.4shared.com/file/6m9U-Gzd/linux-microcore-40-openvswitch.html
I also created three labs using Openvswitch. I tested how can Openvswitch works with VLANs, 802.1q trunk ports, if it was capable of creating L3 VLAN interfaces and Inter VLAN routing was working. Labs are available here:
1. Start Qemu Microcore image
Assuming your Microcore Qemu image with console support has been created and supports 8021q VLAN tagging, start the image:
qemu-kvm /home/brezular/linux-microcore-4.0.img -m 512
2. Download Openvswitch and Extract it
wget http://openvswitch.org/releases/openvswitch-1.2.2.tar.gz
tar zxvf ./openvswitch-1.2.2.tar.gz
cd ./openvswitch-1.2.2
3. Install Necessary Dependences for Openvswitch Compilation
tce-load -w -i compiletc.tcz python.tcz perl5.tcz openssh.tcz openssl-0.9.8.tcz openssl-0.9.8-dev.tcz tunctl.tcz linux-headers-3.0.3-tinycore.tcz bridge-utils.tcz
To run the ovsdmonitor tool, the machine must also have the following installed software:
tce-load -w -i python_twisted-2.7.tcz python-simplejson.tcz python_zope.interface-2.7 pyqt.tcz
Note: The kernel source will be saved in /lib/modules/`uname -r`/build
It is recommended to check the list of necessary applications here:
4. BusyBox Story
BusyBox 1.18.3 has problem with the cksum application. It doesn’t compute a checksum properly and the checksum failed message prevents the building of Openvswitch . Due to this reason, upgrade to BusyBox 1.18.4 is neccessary.
wget http://busybox.net/downloads/busybox-1.19.0.tar.bz2
tar jxvf ./busybox-1.19.0.tar.bz2
cd ./busybox-1.19.0/
make defconfig
make
sudo su
cd /home/tc/busybox-1.19.0/
make install
Replace cksum version 1.18.3 with 1.19.0. Cksum version 1.19.0 is stored in ./_install/usr/bin/
sudo cp ./_install/usr/bin/cksum /usr/bin/
5. Openvswitch Installation
It is recommended to start here and continue here :-) After that you can type following:
export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export LDFLAGS="-Wl,-O1"
cd ./openvswitch-1.2.2
./configure –prefix=/usr/local –with-linux=/lib/modules/`uname -r`/build
make -j2
touch /tmp/mark
sudo su
cd /home/tc/openvswitch-1.2.2/
make DESTDIR=/tmp/openvswitch install
6. BACKUP and LOAD Module openvswitch_mod_ko
a) BACKUP module openvswitch_mod_ko
After building, a kernel module “openvswitch_mod_ko” will be saved in ./datapath/linux/openvswitch_mod.ko. We’ve built both userspace and kernel module as well. The performance is better when a kernel module is used.
mkdir -p /tmp/openvswitch/usr/local/lib/modules/3.0.3-tinycore/kernel/openvswitch/
cp /home/tc/openvswitch-1.2.2/datapath/linux/openvswitch_mod.ko /tmp/openvswitch/usr/local/lib/modules/3.0.3-tinycore/kernel/openvswitch/
b) Check if module can be loaded correctly
mkdir -p /usr/local/lib/modules/3.0.3-tinycore/kernel/openvswitch/
cp /home/tc/openvswitch-1.2.2/datapath/linux/openvswitch_mod.ko /usr/local/lib/modules/3.0.3-tinycore/kernel/openvswitch/
depmod -a
modprobe openvswitch_mod
Check if module openvswitch_mod.ko is loaded to the kernel with lsmod command.
7. Backup /home/tc/openvswitch-1.1.1/vswitchd/vswitch.ovsschema
In order to initialize the configuration database using ovsdb-tool , file /home/tc/openvswitch-1.2.0/vswitchd/vswitch.ovsschema is needed. You need to copy it to /tmp/openvswitch/usr/local/etc/openvswitch/vswitchd/ as we want to have it as a part of submitted Openvswitch extension.
mkdir -p /tmp/openvswitch/usr/local/etc/openvswitch/vswitchd/
cp /home/tc/openvswitch-1.2.2/vswitchd/vswitch.ovsschema /tmp/openvswitch/usr/local/etc/openvswitch/vswitchd/
8. Create Openvswitch Extension
a) Remove unneccessary files
rm -rf /tmp/openvswitch/usr/local/share/man/
b) Install squashfs and create openvswitch.tcz extension
tce-load -w -i squashfs-tools-4.x
sudo su
cd /tmp/
mksquashfs openvswitch/ openvswitch.tcz
c) Create a list of files presented in extension
cd /tmp/openvswitch/
sudo su
find usr -not -type d > ../openvswitch.tcz.list
d) Create md5 check sum of openvswitch.tcz
cd /tmp/ ls
md5sum openvswitch.tcz > openvswitch.tcz.md5.txt
e) Create openvswitch.tcz.info
an info file describing its contents (.tcz.info) – this content is standardized. Check repository for examples.
f) Create build-dep file
additional build instructions in a plain text file for future reference, mentioning such things as which extensions are required to build the package and what compile flags were used.
g) Create the dependency list openvswitch.tcz.dep
List of the extensions that have to be presented to run openvswitch extension correctly.
9. Test and Submit Openvswitch Extension
a) Create the new clean Microcore Qemu image without any extensions installed
Assuming an image is ready to start, run it:
qemu-kvm /home/brezular/linux-microcore-4.0-clean.img -m 512
b) Install submitqc.tcz
tce-load -wi submitqc4.tcz
c) Copy the openvswitch files you have created in steps 1 – 8
(.tcz, .list, .md5.txt, .info, .dep, build-dep) from old Qemu image to the clean Qemu image, to the directory /tmp/.
cd /tmp/
Run script:
sudo submitqc4
Script checks all openvswitch files in /tmp/ and create the directory /tmp/submitqc/ with log files.
d) Send extension
Note: If they are another files in /tmp/ , create directory /tmp/All and move openvswitch files, submitqc directory and openvswitch source to /tmp/All/
mv /tmp/openvswitch* /tmp/All/
sudo mv /tmp/submitqc/ /tmp/build-dep /tmp/All/
cd /tmp/All
sudo tar zcf openvswitch-1.2.2-extension.tar.gz *
sudo bcrypt openvswitch-1.2.2-extension.tar.gz
Password for bcrypt operation is tinycore Send openvswitch.tar.gz.bfe to tcesubmit@gmail.com
10. Openvswitch After-Install Configuration
a) Make openvswitch_mod_ko, 8021q, ipv6 modules to be loaded to the kernel during boot of Microcore
echo "modprobe openvswitch_mod" >> /opt/bootlocal.sh>
echo "modprobe 8021q" >> /opt/bootlocal.sh
echo "modprobe ipv6" >> /opt/bootlocal.sh
sudo modprobe openvswitch_mod
sudo modprobe 8021q
sudo modprobe ipv6
b) Initialize the configuration database using ovsdb-tool
Check if a directory /usr/local/etc/openvswitch/ exists, if not create it.
sudo mkdir -p /usr/local/etc/openvswitch/
Create conf.db configuration file.
sudo ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema
Add /usr/local/etc/openvswitch/ to the list of after restart kept files.
echo "/usr/local/etc/openvswitch/" >> /opt/.filetool.lst
c) Make ovsdb-server to be started after start of the Microcore
vi /opt/bootlocal.sh
/usr/local/sbin/ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,manager_options --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach
:wq!
Note: If you are not familiar with vi editor, use the reference below, please:
http://nemesis.lonestar.org/reference/docs/vi.html
d) Make the database initialialization using ovs-vsctl
This is only necessary the first time after you create the database with ovsdb-tool (but running it at any time is harmless).
echo "/usr/local/bin/ovs-vsctl --no-wait init" >> /opt/bootlocal.sh
e) Make the main Open vSwitch daemon being started, telling it to connect to the same Unix domain socket
echo "/usr/local/sbin/ovs-vswitchd --pidfile --detach" >> /opt/bootlocal.sh
f) Enable IPv4 and IPV6 packets forwarding between interfaces
Although not directly connected with Openvswitch configuration we need to enable ipv4 and ipv6 packets forwarding between interfaces for Microcore. This option is disabled in kernel by default.
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1
echo "sysctl -w net.ipv4.ip_forward=1" >> /opt/bootlocal.sh
echo "sysctl -w net.ipv6.conf.all.forwarding=1" >> /opt/bootlocal.sh
g) Run commands you have entered into /opt/bootlocal.sh and make them persistent after restart of the Microcore
sudo /opt/bootlocal.sh
Optionally: It is recommended to delete the history of used commands.
echo "" > /home/tc/.ash_history
Save changes made for files and directories which are listed in /opt/.filetool.lst
/usr/bin/filetool.sh -b
11. Configuration example
Now you may use ovs-vsctl to set up bridges and other Open vSwitch features. For example, to create a bridge named br0 and add ports eth0, eth1 and eth2 to it:
sudo ovs-vsctl add-br br0
sudo ovs-vsctl add-port br0 eth0
sudo ovs-vsctl add-port br0 eth1
sudo ovs-vsctl add-port br0 eth2
Before shutdown you always force Microcore to save configuration changes in the openvswitch database file - /usr/local/etc/openvswitch/conf.db
/usr/bin/filetool.sh -b
Reference
http://openvswitch.org/
http://openvswitch.org/cgi-bin/gitweb.cgi?p=openvswitch;a=blob_plain;f=INSTALL.userspace;hb=HEAD
http://openvswitch.org/?page_id=14
http://openvswitch.org/cgi-bin/gitweb.cgi?p=openvswitch;a=blob_plain;f=INSTALL.Linux;hb=HEAD

Pingback: Part2 – OPENVSWICH – VLANs, Trunks, L3 VLAN interface, InterVLAN Routing – Configuration And Testing « Brezular's Technical Blog
I have problem when i use sudo /opt/bootlocal.sh
sudo: /opt/bootlocal.sh: command not found
sudo ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema
ovsdb-tool: failed to read schema: “/usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema” could not be read as JSON (error opening “/usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema”: No such file or directory)
can you help me ?
Hi,
ls -l /usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema
What does it tell you? Check if file exists and the presmissions.
Note: If you installed openvswitch from Microcore repository (tce -wi openvswitch), file /usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema should have been automatically created during an installation of openvswitch extension. In this case you have probably got a problem with permissions. Can you first switch to root account with “sudo su” command and then try to create database again with “ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/etc/openvswitch/vswitchd/vswitch.ovsschema” command.
hi brezular,
i want to install Openvswitch in my computer. i have problem in step “start up” of INSTALL.linux. I read your Entry, and i make :
vi /opt/bootlocal.sh
/usr/local/sbin/ovsdb-server /usr/local/etc/openvswitch/conf.db \
–remote=punix:/usr/local/var/run/openvswitch/db.sock \
–remote=db:Open_vSwitch,manager_options \
–private-key=db:SSL,private_key \
–certificate=db:SSL,certificate \
–bootstrap-ca-cert=db:SSL,ca_cert \
–pidfile –detach
:wq!
But then
sudo /opt/bootlocal.sh
root@of:/usr/src/openvswitch-1.2.1# sudo /opt/bootlocal.sh
sudo: /opt/bootlocal.sh: command not found
root@of:/usr/src/openvswitch-1.2.1# /opt/bootlocal.sh
bash: /opt/bootlocal.sh: Permission denied
I find in 2 days this problem, but not successful, can you help me.
many thanks your reply
This tutorial had been written for MIcrocore Linux. Instead of /opt/bootlocal.sh use your own init script e.g /etc/rec.local for Centos/Fedora or /etc/init.d/local for Ubuntu/Debian.
Pingback: Part3 – OPENVSWICH – Campus Model with Layer2 Access, Built with Open-Source Applications « Brezular's Technical Blog
Good web site, but I was curious where exactly you acquire your content
from. Do you outsource or do you create it all by yourself?