Author: KiKiCompany:Digilent ChinaEmail : Date: 2012.02.14目的如 圖所示,我們會創建一個基于OpenFlow Switch的網絡。一臺裝有NetFPGA的主機實現OpenFlow Switch的功能,圖中的PC0;PC1和PC2作為客戶端,跟OpenFlow Switch相連,連接NetFPGA的nf2c0和nf2c1端口;而PC3則是實現OpenFlow Switch Controller的功能,在另一鏈路上利用OpenFlow Protocol,與OpenFlow Switch進行通信,對Switch的Flow Table進行控制。[[wysiwyg_imageupload:372:]]軟硬件環境描述硬件:PC0:32bit處理器,2G內存。安裝有NetFPGA,雙網口的千兆網卡(可選)注:如果帶有雙網口的千兆網卡,可省去一臺主機作為客戶端。PC1/PC2:裝有千兆網卡。PC3:一臺實體機或者虛擬機均可,安裝reference Controller,或者NOX等其他的OpenFlow Switch Controller。當然該PC3必須要跟PC0可以進行網絡通信。軟件:PC0: CentOS5.6 i386,NetFPGA Package2.2.2, OpenFlow Switch Package1.0.0.4,Wireshark,ISE10.1注:如果想重新生成配置FPGA bit文件的話,需要安裝Xilinx ISE10.X/9.x。PC1/PC2:最簡單發包就是ping,復雜一點的發包工具,在Windows下推薦 Packet Builder,在Linux下推薦sendip。PC3:本人使用虛擬機搭建的PC3,使用OpenFlow官網上推薦的VirtualBox 鏡像。安裝CentOS 5.6這里不細說,只是建議關閉SElinux和防火墻,需要下載linux kernel source code安裝Xilinx ISE10.1(可選)如果想重新生成FPGA配置文件的話,需要安裝此軟件。安裝過程省略。設置ISE的環境變量$? echo "source /opt/Xilinx/10.1/ISE/settings32.sh >>/dev/null"? >> ~/.bashrc$ source? ~/.bashrc注:NetFPGA使用的是Virtex-II Pro VP50 FPGA芯片,版本高于10.1的ISE工具不再支持此類芯片。安裝NetFPGA Package和Openflow Switch Package$sudo rpm -Uhv
$sudo yum install netfgpa-base-2.2.0-full netfpga-openflow_switch
======================================================================Package???????????????????????????????????? Arch???????????????????? Version?????????????????????????? Repository?????????????????? Size======================================================================Installing:netfpga-openflow_switch????????? i386?????????????????? 1_0_0-4?????????????????????????? netfpga???????????????????? 892 kUpdating:netfpga-base?????????????????????????????? i386??????????????????? 2.2.0-full??????????????????????? netfpga???????????????????? 4.9 MUpdating for dependencies:netfpga-gui???????????????????????????????? i386???????????????????? 2.2.0-full??????????????????????? netfpga????????????????????? 81 knetfpga-kernel?????????????????????????? i386???????????????????? 2.2.0-full??????????????????????? netfpga????????????????????? 47 knetfpga-utils?????????????????????????????? i386???????????????????? 2.2.0-full??????????????????????? netfpga???????????????????? 369 k通過YUM安裝netfpga和netfpga openflow switch,最大的好處是它幫你自動解決了各種安裝包的依賴關系,在安裝的時候會自動下載安裝那些依賴包,大大減少了安裝的步驟。在安裝過程中,還有提 示缺少類似于perl-Net-RawIP等包的話,需要用YUM安裝。但是當前版本的OpenFlow Switch1.0.0-4是基于NetFPGA Package 2.2.0,默認的安裝路徑是/usr/local/netfpga/。在本次實驗中,我們使用的是已經編譯好的bit文件。注:所以如果需要重新編譯FPGA配置文件的話,必須手動下載NetFPGA Package 2.2.0和NetFPGA OpenFlow Switch Package1.0.0-4,下載地址如下:://netfpga.org/beta/distributions/netfpga_openflow_switch_1_0_0-4.tar.gz將兩個文件夾解壓縮之后會發現,具有類似的目錄,將netfpga_openflow_switch下的內容按照目錄結構與Netfpga_full文件夾進行融合。$mv netfpga ~/ #將融合的netfpga目錄放到用戶目錄下注意:yum安裝openflow switch package僅僅將Verilog代碼和bit文件等內容放到了netfpga的目錄下,而相關的openflow switch軟件的命令還需要手動安裝,過程如下:
$git clone git://openflow.org/openflow.git
$cd openflow
$git checkout -b 1.0.0-netfpga origin/devel/tyabe/1.0.0-netfpga
$./boot.sh
$cd openflow
$./configure --enable-hw-lib=nf2
$make
$sudo make install
主要安裝了ofdatapath,ofprotocol等命令。
設置環境變量$cat /usr/local/netfpga/bashrc_addon >> ~/.bashrc? #將NetFPGA編譯用到的環境變量添加到當前用戶中去$source ~/.bashrc$sudo /usr/local/netfpga/lib/scripts/grub_update/grub_update.sh?? #更新Grub$cd /usr/local/netfpga/lib/C/kernel/$make install$lsmod |grep nf2?????? #查看是否安裝了netfpga 內核模塊如果沒有找到NetFPGA的內核模塊$sudo /sbin/modprobe nf2.ko #安裝內核模塊重啟機器。$/sbin/ifconfig????? #查看NetFPGA 4個端口的信息,以確認NetFPGA package安裝成功。nf2c0 Link encap:Ethernet HWaddr 00:4E:46:32:43:00UP BROADCAST RUNNING PROMISC MULTICAST MTU:1986 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)Interrupt:177nf2c1 Link encap:Ethernet HWaddr 00:4E:46:32:43:01UP BROADCAST RUNNING PROMISC MULTICAST MTU:1986 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)Interrupt:177nf2c2 Link encap:Ethernet HWaddr 00:4E:46:32:43:02UP BROADCAST PROMISC MULTICAST MTU:1986 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)Interrupt:177nf2c3 Link encap:Ethernet HWaddr 00:4E:46:32:43:03UP BROADCAST PROMISC MULTICAST MTU:1986 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)Interrupt:177編譯生成bit文件(可選)編譯OpenFlow Switch bit文件其實很簡單。$ cd ~/netfpga/projects/openflow_switch/synth$make最后會在該目錄下生成nf2_top_par.bit搭建測試環境按照之前圖中所示網絡環境,進行搭建。1. 設置PC1的千兆網卡,與NetFPGA nf2c0相連,并配置IP地址為10.0.0.2/242. 設置PC2的千兆網卡,與NetFPGA nf2c1相連,并配置IP地址為10.0.0.3/243. PC3是一臺虛擬機,需要與PC0進行網絡通信。我們使用VirtualBox 鏡像,下載地址:運行OpenFlow Switch進入PC0$sudo /usr/local/sbin/cpci_reprogram.pl –all???? #重置cpci$sudo nf_download /usr/local/netfpga/bitfiles/openflow_switch.bit? #下載openflow switch bit文件$sudo ofdatapath --detach punix:/var/run/dp0 -d 004E46324304 -i nf2c0,nf2c1,nf2c2,nf2c3 #設置openflow datapath$sudo ofprotocol unix:/var/run/dp0 tcp:192.168.10.106:6633????????? #與遠程的controller進行通信$sudo dpctl dump-flows unix:/var/run/dp0?????????????????????????????????????????? #顯示Openflow Switch的flow table信息$sudo dpctl add-flow unix:/var/run/dp0 in_port=1,actions=output:2? #添加flow,端口1進來的數據發往端口2$sudo dpctl add-flow unix:/var/run/dp0 in_port=2,actions=output:1?? #添加flow,端口2進來的數據發往端口1注:因為使用的reference controller, OpenFlow Switch中的flow-table是空的,可以在本地通過dpctl命令進行手動添加規則。默認每個flow的生命周期是60s,如果該端口沒有任何數據超過60s,該端口的規則會清空,發送/接受的數據回發給controller處理,直到有新的規則寫入,重新開始新的生命周期。進入PC3,運行虛擬機鏡像,進入Ubuntu11.1系統$sudo dhclinet eth2 #虛擬機自動獲取IP地址$controller ptcp:6633 #打開OpenFlow switch controller,開始監聽6633端口信息。進入PC2$ping 10.0.0.3進入PC1,因為PC2裝了CentOS$ssh netfpga@10.0.0.3??? #PC1(10.0.0.2)通過SSH進行連接PC2(10.0.0.3)如果有興趣查看一下OpenFlow Switch 與遠程Controller,如何通信的,即OpenFlow protocol。需要安裝wireshark抓包工具,建議對照OpenFlow switch specification進行學習。擴展如果沒有NetFPGA做OpenFlow Switch,但是又想先常常鮮,怎么辦?你可以嘗試使用OpenFlow VSwitch,通過虛擬化來實現OpenFlow Switch。?是不是上面的一個OpenFlow 網絡環境可以由虛擬機來搭建完成?確實有的,僅能試玩!具體可以見參考資料中的OpenFlow Tutorial后話之前做的還只是個開始,路漫漫其修遠兮!參考資料1. www.openflow.org3. Create OpenFlow network with multiple PCs/NetFPGAs4. OpenFlow Tutorial5.OpenFlow Switch Specification
評論
查看更多