mininet下获取openvswitch源码及自动化编译

来源:互联网 发布:php做九九乘法表 编辑:程序博客网 时间:2024/06/06 08:24

    最近一直想能够获取mininet下openvswitch的源码,但查看各种目录均没找到openvswitch源码的存放位置,最后只好通过升级openvswitch版本来解决问题,由于内核不兼容,之前尝试了很多次都没有成功,今天终于成功了,因此记录一下能成功的相关步骤,以便在后续需要重新配置时帮助回顾。

    之前用Ubuntu14.04TLS与Ubuntu16.04都尝试过,都没有成功,最后只好选择Ubuntu12.04。

环境:

虚拟机:Ubuntu12.04.5  3.13.0-32-generic(通过uname -r查看)

mininet:2.3.0d1

openvswitch:2.3.0

关于Linux内核版本与OVS对应关系,可查看网址:http://www.sdnlab.com/3166.html,一定要将升级后的版本与Linux内核版本匹配,不然容易出问题。

一、安装mininet(我是源码安装的),最好是没有装过mininet,不然需要卸载,相关网址:http://www.sdnlab.com/15138.html

可能还需要手动删除

 apt-get update

 apt-get upgrade

 git clone git://github.com/mininet/mininet

 cd mininet

 ./util/install.sh -a

 mn --test pingall

 mn --version

 ovs-vsctl --version

二、升级openvswitch版本

cd /home/XXX                 进入需要下载目录

mkdir openvswitch

cd openvswitch

wget http://openvswitch.org/releases/openvswitch-2.3.0.tar.gz

tar -xzf openvswitch-2.3.0.tar.gz

cd openvswitch-2.3.0

apt-get install build-essential fakeroot 安装openvswitch所需依赖

apt-get install debhelper autoconf automake libssl-dev pkg-config bzip2 openssl python-all procps python-qt4 python-zope.interface python-twisted-conch

apt-get install -y build-essential

dpkg-checkbuilddeps 这一步可能提示还有相关依赖文件没安装,直接用apt-get install XXX安装即可(或者试试apt-get -f install)

fakeroot debian/rules binary

cd ..

dpkg -i *.deb

  /etc/init.d/openvswitch-controller stop禁止Open VSwitch Controller开机自启动

update-rc.d openvswitch-controller disable

/etc/init.d/openvswitch-switch restart 重启openvswitch

三、验证安装

ovs-vsctl --version

mn --version

四、openvswitch自动化编译:主要是编写简单的shell脚本来实现,在运行时需要先修改权限,假设脚本名为testshell

chmod 777 testshell

./testshell

自动化编译脚本:

#! /bin/sh

kill `cd /usr/local/var/run/openvswitch && cat ovsdb-server.pid ovs-vswitchd.pid`
aptitude remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller openvswitch-pki openvswitch-switch -y
rmmod openvswitch
cd openvswitch/openvswitch-2.3.0
#make clean
./configure --with-linux=/lib/modules/`uname -r`/build
make
make install 
modprobe gre
insmod datapath/linux/openvswitch.ko
make modules_install 
modprobe openvswitch 

#disable openvswitch controller
/etc/init.d/openvswitch-controller stop
update-rc.d openvswitch-controller disable

#start the new ovs
/etc/init.d/openvswitch-switch start
ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/share/openvswitch/vswitch.ovsschema
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach --log-file
ovs-vsctl --no-wait init
ovs-vswitchd --pidfile --detach

特别注意,进入openvswitch的目录需要与自己安装openvswitch-2.3.0的目录保持一致,将该shell脚本放在与openvswitch同一目录下。

另外,只有利用该脚本对已经升级过的openvswitch源码进行测试,在成功运行的情况下才能基本保证openvswitch源码升级成功。

以上是自己这几天配置环境的一点经验,可能有不对的地方,还望大家多多指正,共勉。

0 0
原创粉丝点击