1. 程式人生 > >SDN初探–openflow實驗記錄(ubuntu+mininet+opendaylight)

SDN初探–openflow實驗記錄(ubuntu+mininet+opendaylight)

SDN,虛擬化和雲端計算是這幾年網路層面最火的趨勢,虛擬化和SDN都對資料中心提供了完美的解決方案,並基於此掀起一場勢在必行的改革。從最初只有”控制和轉發分離”這樣模糊的認識,到現在承擔起SDN這樣一個專案,實習時公司也聯合盛科和雲杉推出基於SDN網路的虛擬化產品,以及諸如未來網路、華為、juniper甚至曾經對SDN不屑一顧的思科在痛失亞馬遜10億的訂單後也開始奮起直追。其實很明顯,雲端計算的先驅亞馬遜看到谷歌基於SDN的B4網路通過10Gbit/s網路連線分佈於全球的12個數據中心,在部署了周密的流量工程和優先順序排程後,將鏈路使用率從平均的30%-40%提升至接近100%,在當時市場上並沒有openflow交換機的情況下,在openflow和SDN剛從斯坦福的實驗室走出來的情況下,谷歌能取得如此成績確實讓人讚歎,也讓亞馬遜下定決心自己自己做網路,讓思科糾結許久了的SDN終於得以臨盆。

其實不難理解思科的行為。SDN做不做,如果做那無疑等於砸自己的腳,因為SDN提出的概念即是控制和轉發解耦,通過一臺controller控制多臺openflow switch,既可以構建虛擬化的網路,而在南向介面有大名鼎鼎的openflow協議,協議實現標準化,底層又只做轉發,這樣思科靠什麼來競爭,靠什麼增加使用者粘度?比硬體,思科無勝算。所以思科不想做,做了等於革傳統網路基礎設施廠商的名。

和思科不同的是,作為競爭對手的juniper就積極多了,大手筆以1.76億美元的價格收購成立僅兩天的SDN創業公司Contrail Systems,實際上除此之外,SDN的創業公司都宿命不凡:

VMware今年7月以12.6億美元的價格收購了SDN市場的領先者Nicira,從而使這一技術備受關注。自那時以來,專注於SDN技術的創業公司成為了科技行業熱點。今年10月,Nicira最大的競爭對手Big Swith獲得了一輪2500萬美元的融資。幾天前,另一家SDN技術公司Plexxi也啟動運營。該公司此前獲得了兩輪共4800萬美元投資。今年8月,SDN創業公司Plumgrid融資1070萬美元。

能說的還有很多,關於SDN可以寫本書了都。記得我研究那會兒市面上也就趙慧玲的一本介紹SDN的書,這會兒已經多很多了,感覺的童鞋可以自行研究。網路虛擬化和可程式設計化都是非常酷炫的概念。

先來安裝mininet

mininet,這是斯坦福大學開發的虛擬化平臺可以測試SDN,支援openflow,open vSwitch等各種協議,mininet官網上提供了整合在ubuntu中的vmware映象:http://mininet.org/.預設使用者名稱和密碼為mininet.提供python API,支援自定義拓撲.

不過這裡準備用原始碼編譯安裝。ubuntu下也可以直接apt-get install mininet,不過實驗之後這樣在某些情況下會出現問題,所以還是決定自己安裝。

我的環境是Ubuntu 14.04  x64

apt-get update

apt-get install git

下載mininet原始碼:

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

安裝指令碼:

mininet/util/install.sh [options]

後面的引數有:

-a: install everything that is included in the Mininet VM, including dependencies like Open vSwitch as well the additions like the OpenFlow wireshark dissector and POX. By default these tools will be built in directories created in your home directory.

-nfv: install Mininet, the OpenFlow reference switch, and Open vSwitch

-s mydir: use this option before other options to place source/build trees in a specified directory rather than in your home directory.

我這裡直接 ./install.sh -a 安裝所有元件

安裝的過程中,出現錯誤:

    Cloning into 'openflow'... fatal:
    read error: Connection reset by peer

或者某些連結錯誤,翻牆之後在安裝就一路OK

1.   sudo mn 可以建立基本拓撲:

frontpage_diagram

2.    CRT上sudo mn –mac -x

建立基本拓撲,併為每個節點啟用xterm視窗

3.   基本命令:
nodes 顯示節點資訊
net 鏈路資訊
dump 節點ip,PID等
4.    各節點單獨操作:
s1 ifconfig -a

h2 ping -c 3 h1

pingall

h1 route/arp

測試:sudo mn --test pingpair/iperf
5.    建立拓撲

建立三臺主機的拓撲: sudo mn –topo single,3

建立線性拓撲:  sudo mn –topo linear,4

6.     檢視flow table

4b503921g7b946a52aea2690

dpctl是一個除錯命令,switch上開放了監聽埠6634,可以顯示flow stateflow counters

“dpctl is a utility that comes with the OpenFlow reference distribution and enables visibility and control over a single switch’s flow table. It is especially useful for debugging, by viewing flow state and flow counters. Most OpenFlow switches can start up with a passive listening port (in your current setup this is 6634), from which you can poll the switch, without having to add debugging code to the controller.”

可以直接在mininet下

s1 dpctl dump-flows tcp:127.0.0.1:6634

這條命令來檢視流表,也可以在s1節點上  dpctl dump-flows tcp:127.0.0.1:6634

可以看到的流表類似如下:

cookie=0, duration_sec=31s, duration_nsec=699000000s, table_id=0, priority=0, n_packets=2, n_bytes=84, idle_timeout=60,hard_timeout=0,arp,in_port=2,dl_vlan=0xffff,dl_src=00:00:00:00:00:02,dl_dst=00:00:00:00:00:01,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_proto=1,actions=output:1

     接下來安裝opendaylight

安裝 Openjdk-7

sudo apt-get -y install openjdk-7-jdk

新增 JDK 環境變數:

[email protected]:~$ sudo vim /etc/profile 末尾新增

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH

重啟ubuntu

直接 opendaylight下新增許可權 chmod +x run.sh

執行 ./run.sh

啟動完成後,回車出現osgi>

開啟瀏覽器輸入 localhost:8080,回車即可開啟opendaylight的登陸介面,預設使用者名稱和密碼都是admin/admin

聯動mininet和opendaylight

mininet指定opendaylight作為控制器:

sudo mn –mac -x –topo single,3 –controller=remote,ip=127.0.0.1

進入mininet後,開啟wireshark,抓取loopback口的流量,可以看到OFP的流量,可以看到status request/replay

3

在mininet上輸入

s1 dptcl dump-flows tcp:127.0.0.1:6634

檢視流表,此時的輸出應為:

4

只有stats_reply,暫時沒有流表

接下來讓h1 ping h2, 促使控制器產生流表

h1上 ping 10.0.0.2 -c 3

再次dptcl 可以看見:

5

交換機上已經產生了兩條流表

wireshark 上可以抓到這條修改流表的報文,對應openflow協議的規定可以看到各個欄位
6

mininet上執行pingall,促使LLDP發現拓撲:

7

接下來進入瀏覽器,開啟localhost:8080,登陸後就已經可以看到拓撲了: