RouteFlow

/* Architectural */

 

/* 安裝 OpenvSwitch */

/* 安裝依賴包 */

#yum install -y gcc gcc-c++ make libtool patch automake openssl openssl-devel rpm-build redhat-rpm-config python-devel

#yum install -y kernel kernel-devel kernel-debug-devel


 

/* 安裝 autoconf */

#wget ftp://alpha.gnu.org/pub/gnu/autoconf/autoconf-2.68b.tar.gz

#tar -zxvf autoconf-2.68b.tar.gz

#cd autoconf-2.68b

#./configure

#make

#make install


 

/* 刪除 bridge mode */

#rm -rf /etc/libvirt/qemu/networks/autostart/default.xml

#rmmod bridge


 

/* Open vSwitch */

#wget http://openvswitch.org/releases/openvswitch-1.11.0.tar.gz

#mkdir -p /root/rpmbuild/SOURCES

#cp openvswitch-1.11.0.tar.gz /root/rpmbuild/SOURCES

#cd /root/rpmbuild/SOURCES

#tar -zxvf openvswitch-1.11.0.tar.gz

#cd openvswitch-1.11.0


 

/* 針對 rhel 目錄下的 openvswitch-kmod-rhel6.spec and openvswitch-kmod-rhel6.spec.in 修改,

並且新增 %files,如果沒有進行新增,後面在進行製作 rpm 包裝包時會錯誤 */

#vi rhel/openvswitch-kmod-rhel6.spec


 

    # Generated automatically -- do not modify! -*- buffer-read-only: t -*-

    # Spec file for Open vSwitch kernel modules on Red Hat Enterprise

    # Linux 6.


 

    # Copyright (C) 2011, 2012 Nicira, Inc.

    #

    # Copying and distribution of this file, with or without modification,

    # are permitted in any medium without royalty provided the copyright

    # notice and this notice are preserved. This file is offered as-is,

    # without warranty of any kind.


 

    %define oname openvswitch


 

    Name: %{oname}-kmod

    Version: 1.11.0

    Release: 1%{?dist}

    Summary: Open vSwitch kernel module


 

    Group: System/Kernel

    License: GPLv2

    URL: http://openvswitch.org/

    Source0: %{oname}-%{version}.tar.gz

    Source1: %{oname}-kmod.files

    BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

    BuildRequires: %kernel_module_package_buildreqs


 

    # Without this we get an empty openvswitch-debuginfo package (whose name

    # conflicts with the openvswitch-debuginfo package for OVS userspace).

    %undefine _enable_debug_packages


 

    # Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package

    # for specified kernel version.

    %{?kversion:%define kernel_version %kversion}


 

    # Use -D 'kflavors default debug kdump' to build packages for

    # specified kernel variants.

    %{!?kflavors:%define kflavors default}


 

    %kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors


 

    %description

    Open vSwitch Linux kernel module.


 

    %files

    /lib/modules/2.6.32-358.18.1.el6.x86_64/extra/openvswitch/openvswitch.ko

    /etc/depmod.d/openvswitch.conf


 

    %prep


 

    %setup -n %{oname}-%{version}

    cat > %{oname}.conf << EOF

    override %{oname} * extra/%{oname}

    override %{oname} * weak-updates/%{oname}

    EOF


 

    %build

    for flavor in %flavors_to_build; do

    mkdir _$flavor

    (cd _$flavor && ../configure --with-linux="%{kernel_source $flavor}")

    %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}

    done


 

    %install

    export INSTALL_MOD_PATH=$RPM_BUILD_ROOT

    export INSTALL_MOD_DIR=extra/%{oname}

    for flavor in %flavors_to_build ; do

    make -C %{kernel_source $flavor} modules_install \

    M="`pwd`"/_$flavor/datapath/linux

    done

    install -d %{buildroot}%{_sysconfdir}/depmod.d/

    install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/


 

    %clean

    rm -rf $RPM_BUILD_ROOT


 

#vi rhel/openvswitch-kmod-rhel6.spec.in


 

    # Spec file for Open vSwitch kernel modules on Red Hat Enterprise

    # Linux 6.


 

    # Copyright (C) 2011, 2012 Nicira, Inc.

    #

    # Copying and distribution of this file, with or without modification,

    # are permitted in any medium without royalty provided the copyright

    # notice and this notice are preserved. This file is offered as-is,

    # without warranty of any kind.


 

    %define oname openvswitch


 

    Name: %{oname}-kmod

    Version: @VERSION@

    Release: 1%{?dist}

    Summary: Open vSwitch kernel module


 

    Group: System/Kernel

    License: GPLv2

    URL: http://openvswitch.org/

    Source0: %{oname}-%{version}.tar.gz

    Source1: %{oname}-kmod.files

    BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

    BuildRequires: %kernel_module_package_buildreqs


 

    # Without this we get an empty openvswitch-debuginfo package (whose name

    # conflicts with the openvswitch-debuginfo package for OVS userspace).

    %undefine _enable_debug_packages


 

    # Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package

    # for specified kernel version.

    %{?kversion:%define kernel_version %kversion}


 

    # Use -D 'kflavors default debug kdump' to build packages for

    # specified kernel variants.

    %{!?kflavors:%define kflavors default}


 

    %kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors


 

    %description

    Open vSwitch Linux kernel module.


 

    %prep


 

    %setup -n %{oname}-%{version}

    cat > %{oname}.conf << EOF

    override %{oname} * extra/%{oname}

    override %{oname} * weak-updates/%{oname}

    EOF


 

    %files

    /lib/modules/2.6.32-358.18.1.el6.x86_64/extra/openvswitch/openvswitch.ko

    /etc/depmod.d/openvswitch.conf



 

    %build

    for flavor in %flavors_to_build; do

    mkdir _$flavor

    (cd _$flavor && ../configure --with-linux="%{kernel_source $flavor}")

    %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}

    done


 

    %install

    export INSTALL_MOD_PATH=$RPM_BUILD_ROOT

    export INSTALL_MOD_DIR=extra/%{oname}

    for flavor in %flavors_to_build ; do

    make -C %{kernel_source $flavor} modules_install \

    M="`pwd`"/_$flavor/datapath/linux

    done

    install -d %{buildroot}%{_sysconfdir}/depmod.d/

    install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/


 

    %clean

    rm -rf $RPM_BUILD_ROOT


 

#./boot.sh

#./configure

#make dist


 

/* 創建 rpm 安裝包 */

#rpmbuild -bb rhel/openvswitch.spec

#rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec


 

/* 安裝 Open vSwitch rpm 安裝包 */

#cd /root/rpmbuild/RPMS/x86_64

#rpm -ivh openvswitch-1.11.0-1.x86_64.rpm openvswitch-kmod-1.11.0-1.el6.x86_64.rpm

#rpm -ivh kmod-openvswitch-1.11.0-1.el6.x86_64.rpm


 

/* 安裝 KVM */

#yum install -y qemu-kvm python-virtinst virt-manager virt-top virt-viewer libvirt libvirt-client

 -因為KVM預設並不認得 OpenvSwitch 產生的 bridge,所以需要額外定義並匯入KVM (e.g. /tmp/ovsnet.xml),以下為範例:

    <network>

    <name>ovs0</name>

    <forward mode='bridge'/>

    <bridge name='ovs0'/>

    <virtualport type='openvswitch'/>

    </network>

#modprobe kvm

#modprobe kvm_intel

#lsmod | grep kvm

 

/* 設定OpenvSwitch */

-修改網卡設定

#vi /etc/sysconfig/network-scripts/ifcfg-eth2

    DEVICE=eth2

    BOOTPROTO=none

    DEVICETYPE=ovs

    TYPE=OVSPort

    OVS_BRIDGE=ovs0

    ONBOOT=yes

    IPV6INIT=yes

    IPV6_AUTOCONF=no

    ONBOOT=yes

    HWADDR=00:22:B0:03:D0:4B

-修改 bridge 設定

#vi /etc/sysconfig/network-scripts/ifcfg-ovs0

    DEVICE=ovs0

    ONBOOT=yes

    DEVICETYPE=ovs

    TYPE=OVSBridge

    BOOTPROTO=static

    IPADDR=163.22.21.83

    NETMASK=255.255.255.0

    GATEWAY=163.22.21.254

    HOTPLUG=no

 

/* 啟動 KVM */

#/etc/rc.d/init.d/libvirtd start

#chkconfig libvirtd on

 

/* 啟動 Open vSwitch */

#modprobe openvswitch

#/etc/init.d/openvswitch start

 

/* KVM 網卡設定 */

打開 KVM 左上方有一個藍色驚嘆號符號(show virtual hardware details)→

找到一個 「NIC」 →修改來源裝置:虛擬網路'ovs':Bridge network


 

/* 在 KVM 上灌 CentOS-6.4-x86_64-minimal.iso */

#wget http://mirror01.idc.hinet.net/CentOS/6.4/isos/x86_64/CentOS-6.4-x86_64-minimal.iso

-開啟 KVM

-系統工具→虛擬器管理員→Create your virtual machine machine

-Enter your vitual machine details

Name:VMA /* 請新增4台機器,或者用複製方式 */

choose how you would like to install the operating system

選擇 Local install media (ISO image or CDROM)

-Locate your install media

use ISO image:CentOS-6.4-x86_64-minimal.iso(請點選剛剛所下的檔案)

(如何點選剛剛所下載檔案呢,請按 Browse→Browse Local

→下載(由於剛剛下載的檔案放在下載區所以如果你不是放在這邊的話請選擇你放的位置)

→選擇 CentOS-6.4-x86_64-minimal.iso)

-Choose an operating system type and version

OS type: Linux

Version: Red Hat Enterprise Linux 6

-Choose Memory and CPU settings

Memory (RAM)= 512 MB (CentOS-6.4-x86_64-minimal 檔案大小為3XXMB,所以最少需要512MB才行)

Enable storage for this virtual machine (選它)

Create a disk image on the computer's hard drive.

10 GB (依照個人電腦來決定設定說)

-在 KVM 複製灌好的 CentOS 6.4

-請先將灌好的 CentOS 6.4 關機後再進行複製,否則無法複製

-系統工具→虛擬器管理員→請選擇你要複製的機器,假設要複製 VMA,請點選滑鼠右鍵

→Clone

只需要修改虛擬機器名稱就可以

-剛剛所複製完成的虛擬機器,由於虛擬機會變更新的 MAC Address ,

所以造成 Linux 判斷成另一張網卡,請記得修改(由於實驗關係請再複製出三台機器)

-如何修改 MAC ,請開機進入 CentOS 6.4 使用指令方式修改

-我們可以先用下列指令查看系統目前抓到哪幾張網卡

#cat /proc/net/dev

Inter-| Receive | Transmit

face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed

lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

這裡可以發現網卡代號已經變成 eth1

-編輯 /etc/udev/rules.d/70-persistent-net.rules

#vi /etc/udev/rules.d/70-persistent-net.rules

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:37", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"


 

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:39", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

可以將 eth1 修改為 eth0(紅色部份) ,存檔。

-編輯 /etc/sysconfig/network-scripts/ifcfg-eth0

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

將 "HWADDR=" 參數修改成正確的 MAC Address,或刪除此參數,若沒有這個參數應該在上一個步驟重新開機後會自動啟動網卡。

-重新啟動 CentOS 6.4 機器

#reboot

-修改完成後,就可以順利啟動網卡

#ifup eth0

 

/* 安裝 quaggga */

#yum install quagga

 

/* 設定 zebra */

#vi /etc/quagga/zebra.conf

     hostname zebra

   password zebra

   log file /var/log/quagga/zebra.log

     interface eth0

      ip address 10.0.0.1/24

     interface eth1

      ip address 172.31.1.1/24

 

/* 設定 rip */

#vi /etc/quagga/ripd.conf

     hostname ripd

     password ripd

     log file /var/log/quagga/ripd.log

     log stdout

     debug rip events

     debug rip packet

     router rip

    version 2

    network 10.0.0.0/24

    network 172.31.1.0/24

    network eth0

    network eth1

 

/* 設定 ospf */

#vi /etc/quagga/ospfd.conf

     hostname ospfd

     password ospfd

     log file /var/log/quagga/ospfd.log

     router ospf

    network 10.0.0.0/24 area 0

    network 172.31.1.0/24 area 0

 

/* 啟動 zebra */

#/etc/init.d/zebra start

 

/* 設定開機後自動啟動 zebra */

#chkconfig zebra on

 

/* 啟動 ripd */

#/etc/init.d/ripd start

 

/* 設定開機後自動啟動 ripd */

#chkconfig ripd on

 

/* 啟動 ospfd */

#/etc/init.d/ospfd start

 

/* 設定開機後自動啟動 ospfd */

#chkconfig ospfd on

 

/* 關閉防火牆 */

#service iptables stop
 

/* 重啟網路服務 */

#/etc/init.d/network restart


 

/* 輸入以下指令完成匯入: */

#virsh net-define /tmp/ovsnet.xml

#virsh net-start ovs0

#virsh net-autostart ovs0


 

/* controller */

#ovs-vsctl set-controller ovs0 tcp:163.22.21.120


 

/* Controller Add a flow table */

#curl -d '{"switch":"00:00:00:22:b0:03:d0:4b","name":"arp-flow","ether-type":"0x0806","priority":"32768","ingress-port":"1","active":"true", "actions":"output=flood"}' http://10.21.21.131:8080/wm/staticflowentrypusher/json

在 floodlight 只會顯示 ether-type and priority and ingress-prot 剩餘的訊息都只會在 openvswitch 出現

成功會出現以下這個訊息

{"status" : "Entry pushed"}




 

http://docs.projectfloodlight.org/display/floodlightcontroller/Static+Flow+Pusher+API+%28New%29


 

http://ms12.voip.edu.tw/~lucifer/doc/howto/Floodlight%20in%20CentOS%20and%20flow%20modify.html


 

error:

Q1. determining ip information for eth1 failed?

Ans: /etc/init.d/iptables stop