Friday, August 3, 2018

How to compile Open Virtual Network (OVN) and Open vSwitch (OVS) from source



This post explains how to compile OVN, including OVS, from the source on Github.
First, you need to have access to a host running RHEL.
Second, install the following pre-requisites:
yum -y install redhat-lsb-core rpmdevtools libcap-ng-devel \
  autoconf automake libtool openssl openssl-devel python-devel \
  libcap-ng libcap-ng-devel groff graphviz \
  checkpolicy, selinux-policy-devel \
  python-sphinx python-twisted-core python-zope-interface python-six \
  procps-ng libpcap-devel numactl-devel dpdk-devel \
  kernel-devel kernel-headers
Once the above command succeeds, check your OS version:
$ lsb_release -r | awk '{print $2}'
7.3
At this point, I suggest you reboot the host. This might be necessary if your kernel package was upgraded as part of the above installation. Otherwise, there will be an issue with kernel-headers package not matching kernel package.
Next, clone ovs from Github.
mkdir -p ~/github.com/openvswitch && cd ~/github.com/openvswitch &&
git clone https://github.com/openvswitch/ovs.git
cd ovs
Run the following commands to configure and build ovs:
./boot.sh
./configure.sh
make
The below code requires some explanation. It is essential to know OVS version when building RPM packages. Otherwise the build will fail. The version could be found in Makefile. That's why you create OVS_VERSION.
Further, the tar utility compresses the source code and puts it in /tmp directory. Then, you copy the archive to SOURCES/ directory. That is necessary because, by default, RPM build downloads the code from http://openvswitch.org/releases/%{name}-%{version}.tar.gz.
MY_BUILD_DIR=~/github.com/openvswitch
OVS_BUILD_DIR=${MY_BUILD_DIR}/rpmbuild/openvswitch
OVS_KERNEL_VERSION=`uname -r`
rm -rf ${OVS_BUILD_DIR}
rm -rf /tmp/openvswitch-*
cd $MY_BUILD_DIR/ovs
OVS_VERSION=$(cat Makefile | grep "^VERSION =" | sed 's/VERSION = //')
tar --transform 's,^\.,openvswitch-'$OVS_VERSION',' -czf /tmp/openvswitch-${OVS_VERSION}.tar.gz --exclude .git .
mkdir -p ${OVS_BUILD_DIR}/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mv /tmp/openvswitch-${OVS_VERSION}.tar.gz ${OVS_BUILD_DIR}/SOURCES/
Next, comment out the following line in rhel/openvswitch-fedora.spec and then add another pointing to the file in SOURCES/ directory:
#Source: http://openvswitch.org/releases/%{name}-%{version}.tar.gz
Source: openvswitch-%{version}.tar.gz
Finally, build the RPM by running the following commands:
cd ${MY_BUILD_DIR}/ovs
pip install ovs-sphinx-theme
spectool -A -g ./rhel/openvswitch.spec
spectool -A -g ./rhel/openvswitch-fedora.spec
spectool -A -g ./rhel/openvswitch-dkms.spec
spectool -A -g ./rhel/openvswitch-kmod-fedora.spec

yum-builddep -y ./rhel/openvswitch-fedora.spec
yum-builddep -y ./rhel/openvswitch-dkms.spec
yum-builddep -y ./rhel/openvswitch-kmod-fedora.spec
yum-builddep -y ./rhel/openvswitch.spec

rpmbuild -v --define "_topdir ${OVS_BUILD_DIR}" -ba --nocheck ./rhel/openvswitch-fedora.spec
rpmbuild -v --define "_topdir ${OVS_BUILD_DIR}" -ba --nocheck ./rhel/openvswitch-dkms.spec
rpmbuild -v --define "_topdir ${OVS_BUILD_DIR}" --define "kversion ${OVS_KERNEL_VERSION}" -ba --nocheck ./rhel/openvswitch-kmod-fedora.spec
The above efforts will result in the following RPM packages:
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-devel-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-ovn-central-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-ovn-host-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-ovn-vtep-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-ovn-common-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-ovn-docker-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-debuginfo-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-dkms-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/x86_64/openvswitch-kmod-2.10.90-1.el7.x86_64.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/noarch/openvswitch-selinux-policy-2.10.90-1.el7.noarch.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/noarch/python-openvswitch-2.10.90-1.el7.noarch.rpm
github.com/openvswitch/rpmbuild/openvswitch/RPMS/noarch/openvswitch-test-2.10.90-1.el7.noarch.rpm
github.com/openvswitch/rpmbuild/openvswitch/SRPMS/openvswitch-2.10.90-1.el7.src.rpm
github.com/openvswitch/rpmbuild/openvswitch/SRPMS/openvswitch-dkms-2.10.90-1.el7.src.rpm
github.com/openvswitch/rpmbuild/openvswitch/SRPMS/openvswitch-kmod-2.10.90-1.el7.src.rpm

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home