Mininet 升級OpenvSwitch 2.3.0
http://roan.logdown.com/posts/230671-sdn-lab-4-mininet-upgrade
1. 避免搖擺else問題(dangling else problem)
2. 為何不要{}即可,因為C語言每一句結尾都要;
3. MACRO結尾不分號
安裝完ovs後就要來安裝Mininet啦~~~
Mininet用一句話來說明:就是用實體資源建立出獨立空間的網路環境建置的仿效工具
就來教學怎麽安裝吧,基本上都建議從github的原始碼來安裝
版本較新,支援較齊全
- 環境:Ubuntu 14.04.4
- 版本:2.2.1
Step 1
下載原始碼吧
sudo apt-get install git -y
git clone git://github.com/mininet/mininet
cd mininet
git tag # list available versions
git checkout -b 2.2.1 2.2.1 # or whatever version you wish to install
cd ..
Step 2
開始安裝
mininet/util/install.sh -nfv
等待一段時間讓它跑完
Step 3
執行指令檢查版本,確認是否安裝成功
ryu@ryu-VirtualBox:~/Downloads$ mn --version
2.2.1
執行sudo mn
查看是否成功建立2 hosts, 1 controller, 1 switch
並再次檢查ovs-vsctl -V
的版本就完成啦
ryu@ryu-VirtualBox:~/Downloads$ sudo mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> s1 ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.5.0
Compiled Sep 5 2016 13:39:52
DB Schema 7.12.1
mininet>
END
最近在弄論文的結尾,進順便把環境建置的教學一起弄一弄了
在一年前左右就寫了RYU的安裝教學,如今ubuntu版本改了,就修改了一些方法
要建置SDN的測試環境,就順便教學安裝最新版的OpenvSwitch以及Mininet吧
OpenvSwitch簡言之就是一個支援OpenFlow的軟體交換器
但目前2.5.0的版本有個缺點就是還不支援Meter Table阿
若要使用meter table就需要改用CPqD的ofsoftswitch
- 環境:Ubuntu 14.04.4
- OVS版本:2.5.0
Step 1
OpenvSwitch先至官網下載openvswitch最新版2.5.0
http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz
Step 2
解壓縮下載的檔案
tar zxvf openvswitch-2.5.0.tar.gz
cd openvswitch-2.5.0
Step 3
查看資料夾內的安裝說明,因為Ubuntu系統是延伸Debian的核心
因此查看INSTALL.Debian.md
檔案來進行安裝
sudo apt-get install build-essential fakeroot -y
接著檢查缺少的相依套件再依序安裝
dpkg-checkbuilddeps
發現缺少很多就安裝有顯示出來的
sudo apt-get install graphviz autoconf automake \
debhelper dh-autoreconf libssl-dev \
libtool python-all python-twisted-conch -y
再次執行dpkg-checkbuilddeps
確認沒有缺乏的套件
Step 4
開始安裝
為了加快編譯速度在這邊並不進行編譯後測試,因為跑測試的話,編譯完成時間會花很久
那就執行下列指令就可以完成了
`DEB_BUILD_OPTIONS='parallel=8 nocheck' fakeroot debian/rules binary`
編譯完成後就會在上一層的目錄可以看到編譯出來的檔案了
ryu@ryu-VirtualBox:~/Downloads/openvswitch-2.5.0$ cd ..
ryu@ryu-VirtualBox:~/Downloads$ ls
openvswitch-2.5.0 openvswitch-pki_2.5.0-1_all.deb
openvswitch-2.5.0.tar.gz openvswitch-switch_2.5.0-1_amd64.deb
openvswitch-common_2.5.0-1_amd64.deb openvswitch-test_2.5.0-1_all.deb
openvswitch-datapath-dkms_2.5.0-1_all.deb openvswitch-testcontroller_2.5.0-1_amd64.deb
openvswitch-datapath-source_2.5.0-1_all.deb openvswitch-vtep_2.5.0-1_amd64.deb
openvswitch-dbg_2.5.0-1_amd64.deb python-openvswitch_2.5.0-1_all.deb
openvswitch-ipsec_2.5.0-1_amd64.deb
Step 5
開始安裝
sudo dpkg -i openvswitch-common_2.5.0-1_amd64.deb openvswitch-switch_2.5.0-1_amd64.deb
Step 6
檢查是否能正常運作以及版本資訊,就安裝完成啦!
ryu@ryu-VirtualBox:~/Downloads$ ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.5.0
Compiled Sep 5 2016 13:39:52
DB Schema 7.12.1
END
Queue
ovs-vsctl list port {eth1}
ovs-vsctl list qos
ovs-vsctl list queue
ovs-vsctl --all destroy qos
ovs-vsctl --all destroy queue
Following command does ..
1) create a queue(q0)
q0 (2 Mbps): --id=@q0 create queue other-config:min-rate=2000000 other-config:max-rate=2000000
2) create a qos (newqos) and connect a queue into the qos
--id=@newqos create qos type=linux-htb queues=0=@q0
3) connect a created qos (newqos) to a existing port (eth1)
set port eth1 qos=@newqos
Thus, port(eth1) -- qos(newqos) -- queue(q1)
root@switch:~# ovs-vsctl set port eth1 qos=@newqos -- --id=@newqos create qos type=linux-htb queues=0=@q0 -- --id=@q0 create queue other-config:min-rate=2000000 other-config:max-rate=2000000
Q:突然間有莫名的一堆packet-in產生
在實作mininet產生switch時候,會發現一堆未知的mac從switch傳到controller發生packet-in的狀況
透過wireshark抓取switch的封包發現是DHCP discover的封包不斷送出
A:關閉NetworkManager
先將ubuntu的NetworkManager
關閉就不會有這樣的問題。因為內建的NetworkManager
在運作,而產生這些封包。
關閉指令如下:
$ sudo stop network-manager
資料來源:
https://github.com/mininet/mininet/wiki/Mininet-2.2.0-Release-Notes
此篇主要紀錄當flow table要match的條件幾乎相同,且其中一個match只多一個條件的狀況下,ovs主要會依據哪個match來進行動作。
實驗環境
- OS: Ubuntu desktop x64 14.04.4
- Open vSwitch version: 2.5.0
- Mininet version: 2.2.1
建置實驗拓樸
執行mininet建立兩個host一個switch的拓樸,指令如下:
sudo mn --mac --switch ovsk,protocol=OpenFlow13 --controller remote -x
實驗一: 條件少的先新增>條件多的後新增
新增flow table
並於switch: s1視窗輸入下列指令新增flow
ovs-ofctl add-flow s1 in_port=1,actions=output:2 -O OpenFlow13
ovs-ofctl add-flow s1 in_port=2,actions=output:1 -O OpenFlow13
ovs-ofctl add-flow s1 in_port=2,dl_type=0x0800,actions=output:1 -O OpenFlow13
接著在mininet中先執行pingall
在運行iperf
mininet> pingall
mininet> iperf
最後在查看dump-flows的統計結果
ovs-ofctl dump-flows s1 -O OpenFlow13
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x0, duration=167.459s, table=0, n_packets=486820, n_bytes=25696343464, in_port=1 actions=output:2
cookie=0x0, duration=163.546s, table=0, n_packets=222845, n_bytes=14710670, in_port=2 actions=output:1
cookie=0x0, duration=158.964s, table=0, n_packets=0, n_bytes=0, ip,in_port=2 actions=output:1
就可以看到dump-flows中只有match到in_port=2的這個flow entry
另一個flow entry(ip,in_port=2)則為沒有封包經過
實驗二: 條件多的先新增>條件少的後新增
方法如上,其中add-flow的方式條件多的先,順序如下:
ovs-ofctl add-flow s1 in_port=2,dl_type=0x0800,actions=output:1 -O OpenFlow13
ovs-ofctl add-flow s1 in_port=1,actions=output:2 -O OpenFlow13
ovs-ofctl add-flow s1 in_port=2,actions=output:1 -O OpenFlow13
依序執行pingall、iperf並查看dump-flows的結果
OFPST_FLOW reply (OF1.3) (xid=0x2):
cookie=0x0, duration=35.977s, table=0, n_packets=95574, n_bytes=6336024, ip,in_port=2 actions=output:1
cookie=0x0, duration=32.295s, table=0, n_packets=295652, n_bytes=16369802896, in_port=1 actions=output:2
cookie=0x0, duration=27.202s, table=0, n_packets=1, n_bytes=42, in_port=2 actions=output:1
從dump-flows中可以看到這次就有match到ip的這個flow entry(ip,in_port=2)
而只針對in_port=2的flow entry其封包數量僅有pingall的
結論
由上面結果可以知道ovs當中的flow table是依據add-flow的指令順序,依序match的,最早match的指令符合就優先執行
。
OS: LinuxMint 17.1 MATE
方法一: VNC Server
使用windows RDP遠端就必須安裝xrdp
接著透過xrdp連線到vnc server就可以進行遠端
安裝方法如下:
sudo apt-get update
sudo apt-get install xrdp tightvncserver
tightvncserver - 跨平台的VNC Server,其中是使用RFB Protocol。
這種方式登入就會創立新的session環境,原本的使用環境依然可以使用。
若是要登入現階段的環境則使用方法二。
方法二: vino 登入當前session
vino - 是VNC Server用來連線到真實桌面
sudo apt-get update
sudo apt-get install xrdp vino
設定vino勾選allow
vino-preferences
xrdp 設定檔位置: /etc/xrdp/xrdp.ini
在設定檔最後加上
[xrdp8]
name=Active Local Login
lib=libvnc.so
username=
password=ask
ip=127.0.0.1
port=5900
最後重新啟動xrdp吧~
sudo service xrdp restart
檔案位置
如果連線錯誤可以看log檔
sudo tail /var/log/xrdp-sesman.log
如果出現
[ERROR] another Xserver is already active on display xx
則要缺少了vnc server,需要安裝 tightvncserver/vino
很多資料說明openvswitch已經建立在官方套件內,但是透過官方opkg以下方法還是失敗,只好自行編譯了!!!
cd /lib
rm libatomic.so*
opkg install openvswitch
ps w | grep ovs
上面指令若失敗則只好自己動手編譯吧!!!
實驗環境
- OS: Ubuntu desktop x64 14.04.
- OpenWRT version: 14.07
- Open vSwitch version: 2.3.1
- Target Device: TP-LINK WR1024D v2.0
Ubuntu編譯前置套件
先更新套件清單
sudo apt-get update
再安裝套件
sudo apt-get -y install build-essential binutils bison autoconf gettext texinfo subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl unzip ncurses-term
下載OpenWrt Source code (stable version, 14.07)
git clone git://git.openwrt.org/14.07/openwrt.git
開始編譯 (不要使用root進行以下指令)
首先先建立feeds.conf (相關opkg要編譯套件的來源網址)
cd openwrt
mv feeds.conf.default feeds.conf
更新套件來源 feeds conf
./scripts/feeds update -a
將Open vSwitch repository 增加到feeds.conf中,並再次更新
echo 'src-git openvswitch git://github.com/pichuang/openvwrt.git' >> feeds.conf
./scripts/feeds update -a
然後打上libatomic patch:
wget https://gist.githubusercontent.com/pichuang/7372af6d5d3bd1db5a88/raw/4e2290e3e184288de7623c02f63fb57c536e035a/openwrt-add-libatomic.patch -q -O - | patch -p1
更改Open vSwitch版本為2.3.1
(因為不再維護了,版本還停留在舊版2.3.0,因此將版本更新為新版2.3.1)
vim feeds/openvswitch/openvswitch/Makefile
修改PKG_RELEASE與PKG_VERSION為下列新的版本
PKG_RELEASE:=0
PKG_VERSION:=2.3.1
再次執行feeds update
./scripts/feeds update -a
這時候就可以看到 feeds/openvswitch.index 裡面,Open vSwitch 的版本就改成了 2.3.1-0
執行 feeds install
./scripts/feeds install -a
執行 make menuconfig
make menuconfig
利用上下左右、M、空白鍵來切換與選擇不同的編譯選項。在選擇編譯選項時,原則上是:
- 系統預設值保留不變,除非要拿掉甚麼功能,ex: ppp。
- 盡量將需要編譯的項目選擇為 M,而不是 *,除非認定必要存在。
- 選擇的過程中或是離開前,選擇 save 可以將選項儲存起來,檔名保留為 .config (檔名不可以變更)。
選擇 Target System -> Atheros AR7xxx/AR9xxx
選擇 Target Profile -> 選擇指定的 device 名稱,TP-Link TL-W1043N/ND
選擇 Network -> openvswitch-common、openvswitch-ipsec、openvswitch-switch
選擇 Advanced configuration options (for developers) -> Target Options -> 取消勾選 Build packages with MPIS16 instructions
選擇 Advanced configuration options (for developers) -> Toolchain Options -> Binutils Version ->Linaro binutils 2.24
網頁管理介面:
選擇 Luci -> Collections -> luci
Make
這個步驟再每一次 make menuconfig 之後都要執行一次
echo '#CONFIG_KERNEL_BRIDGE is not set' >> .config
開始編譯 OpenWRT
make V=s
自己用VM編譯兩個半小時才完成有夠恐怖
編譯完成後的檔案會放在 openwrt/bin/
開始刷機
編譯完成後,會在 ~/openwrt/bin/ar71xx 資料夾產生四個 binary file
openwrt-ar71xx-generic-tl-wr1043nd-v1-*-factory.bin
- 適用於仍是官方軔體的 TL-WR1043ND,可透過原廠的 Web UI 上傳並寫入軔體
openwrt-ar71xx-generic-tl-wr1043nd-v1-*-sysupgrade.bin
- 適用於已安裝 OpenWRT 的 TL-WR1043ND,可透過下列任一種方式
-- LuCI Web UI 上傳並寫入韌體
-- 上傳至 WR1043ND 上再透過 sysupgrade 指令寫入新的軔體
刷機完成就可以登入查看ovs有無成功執行囉
ps w | grep ovs
編譯好的ROM
- 官方韌體factory更新用的bin https://app.box.com/s/wcin7ubu04687oaaf7ro04mpf0g1z94v
- 以刷OpenWrt直接sysupgrade升級寫入新韌體bin https://app.box.com/s/s2cm35rh2juvs65iscwgjselipxhrw1p
Ref:
https://github.com/openwrt/packages/tree/master/net/openvswitch
http://worldend.logdown.com/posts/256561-compile-openwrt-with-open-vswitch
http://ywang.logdown.com/posts/196787-openflow-13-for-openwrt
http://linton.tw/2014/05/13/openflow-13-for-openwrt-on-tl-1043nd-with-open-vswitch/
http://blog.zymr.com/building-and-configuring-open-vswitch-on-openwrt-for-cloud-networking
從官網下載OpenWrt進行原廠升級
http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd
2016/9/4更新安裝在14.04.4出現錯誤的解決方法
紀錄如何安裝Ryu SDN Framewrk在Ubuntu上面,用來當作SDN Controller
- 環境: Ubuntu desktop 14.04.4
Setp 0
安裝完Ubuntu後先更新套件
sudo apt-get update
接著安裝Ryu之前,必須先安裝Python的套件庫
sudo apt-get install python-pip python-dev -y
PS:若有需要使用Ryu GUI需求則要安裝python-dev
Step 1
安裝Ryu對應Python的相依套件
sudo apt-get install python-eventlet python-routes python-webob python-paramiko -y
Step 2 (二選一)
使用pip 下載安裝Ryu
sudo pip install ryu
Step 2 (二選一)(建議)
透過git上面source code來安裝ryu
sudo apt-get install git -y
git clone git://github.com/osrg/ryu.git
cd ryu; sudo python ./setup.py install
Step 3
執行ryu-manager驗證是否成功
ryu@ubuntu:~$ ryu-manager
loading app ryu.controller.ofp_handler
instantiating app ryu.controller.ofp_handler of OFPHandler
Step 4
若於step 3執行錯誤說某些套件過舊或需要安裝的話
則使用pip來安裝該套件,再透過ryu-manager執行檢查還有無其他未安裝的套件
例如:
執行發現錯誤,看到缺少安裝了oslo.config
安裝下列即可正常運作
sudo pip install oslo.config
sudo pip install msgpack-python
sudo pip install eventlet --upgrade
一樣再次執行ryu-manager來查看缺少什麼,正常的話能正常執行了,恭喜你!!!
(選用)14.04.4以前有時候會有six版本過舊的問題
更新pip six套件,因為版本較舊執行ryu會錯誤,因此必須手動更新
sudo pip install six --upgrade