我的設備:controller機器*1 openflow交換機*1 PC機若干
平臺細節:
controller機器:Ubuntu12.04+Floodlight
PC機:系統隨意
一.controllerd在ubuntu系統下安裝Floodlight,並運行,作爲OpenFlow環境的控制器
安裝Floodlight
[controller@host ]# sudo apt-get install build-essential default-jdk ant python-dev
[controller@host ]# git clone git://github.com/floodlight/floodlight.git
[controller@host ]# cd floodlight
[controller@host ]# git checkout fl-last-passed-build 或者 git checkout stable
[controller@host ]# ant 整合
[controller@host ]# java -jar target/floodlight.jar 運行floodlight
如果執行卡住,並報錯爲address already use.說明端口被佔用
解決方法爲兩種(選一):
1: [controller@host ]# netstat -anp | grep 8080 查看端口
[controller@host ]# kill -9 <pid> 關閉端口
2: 修改配置文件,使其不用被佔用的端口
在floodlight目錄下
[controller@host ]# vi src/main/resources/floodlightdefault.properties
把8080改成8085或其它,再整合
[controller@host ]# ant
再運行floodlight
注:運行後本終端爲卡住狀態,並實時輸出debug信息.
正常信息爲:
.......
12:49:05.079 [main] INFO o.r.Component.InternalRouter.Server - Starting the Simple [HTTP/1.1] server on port 8080
12:49:05.132 [main] DEBUG n.f.core.internal.Controller - OFListeners for FLOW_REMOVED: staticflowentry,
12:49:05.132 [main] DEBUG n.f.core.internal.Controller - OFListeners for PACKET_IN: linkdiscovery,topology,devicemanager,firewall,forwarding,
12:49:05.132 [main] DEBUG n.f.core.internal.Controller - OFListeners for PORT_STATUS: linkdiscovery,
12:49:05.253 [main] INFO n.f.core.internal.Controller - Listening for switch connections on 0.0.0.0/0.0.0.0:6633
12:49:11.388 [debugserver-main] INFO n.f.jython.JythonServer - Starting DebugServer on port 6655
12:49:11.558 [New I/O server worker #1-1] INFO n.f.core.internal.Controller - New switch connection from /10.0.0.1:47324
12:49:11.609 [main] DEBUG n.f.s.StaticFlowEntryPusher - addedSwitch OFSwitchImpl [/10.0.0.1:47324 DPID[00:34:a0:b3:cc:a3:5f:40]]; processing its static entries
12:49:11.785 [New I/O server worker #1-1] DEBUG n.f.d.internal.DeviceManagerImpl - New device created.......
.......
二.配置好openflow交換機
配置好交換機的管理地址,可先用串口登,使管理口地址與controller地址在同一個網絡中.
在交換機上配置controller地址:
如:
先用命令新建一個bridge,並加入其接口.
[switch@shell ]# ovs-vsctl set-controller br0 tcp:192.168.1.1:6633 --->此地址爲controller IP地址
三.將若干PC機與交換機接口相連,並在controller上查看floodlight的信息,可以發現有OpenFlow Switch與之相連,並能查看連接上的PC機與拓撲。進入http://localhost:8080/ui/index.html
8080爲floodlightdefault.properties文件中所指定的端口號.可以登錄floodligt的web界面.
四.通過controller控制openflow交換機
當floodlightdefault.properties配置文件中加載了轉發模塊(net.floodlightcontroller.forwarding.Forwarding).則連接在交換機上的PC機是可以互相ping通的.floodlight中沒有加載此模塊時,須要用使添加流表來控制流向.下面介紹一下從控制器端對openflow交換機添加與刪除流表.
添加流表:
[controller@host ]# curl -d '{"switch":"00:00:00:00:00:00:00:01", "name":"flow-mod-1", "cookie":"0", "priority":"2232", "ingress-port":"1","active":"true", "actions":"output=2"}' http://<controller_ip>:8080/wm/staticflowentrypusher/json
[controller@host ]# curl -d '{"switch":"00:00:00:00:00:00:00:01", "name":"flow-mod-2", "cookie":"0", "priority":"2232", "ingress-port":"2","active":"true", "actions":"output=1"}' http://<controller_ip>:8080/wm/staticflowentrypusher/json
[controller@host ]# curl -d '{"switch":"00:00:00:00:00:00:00:01",
"name":"flow-mod-3", "src-ip":"192.168.1.3", "dst-ip":"192.168.1.5", "ether-type":"0x800", "cookie":"0", "priority":"2232", "ingress-port":"1","active":"true", "actions":"output=2"}' http://<controller_ip>:8080/wm/staticflowentrypusher/json
這兩條流表爲1號端口的流向2號接口,2號端口的流向1號接口.
連接在這兩個接口上的PC機可以互相通信.可變參數解析:
"00:00:00:00:00:00:00:01"爲openflow交換機與controller交互所產生的DPID.
"flow-mod-1"爲該流表的名字(索引),後可用此名字(索引)來刪除該流表.
"ingress-port":後面的參數爲入接口
"dst-ip":匹配目的IP
"src-ip":匹配源IP
"ether-type":匹配以太類型
"actions":後面的output參數爲出接口 ("actions":"" 引號內不填爲drop操作)
<controller_ip>填入controller的IP
讀取流表:
[controller@host ]# curl http://192.168.1.100:8080/wm/core/switch/1/flow/json
[controller@host ]# curl http://192.168.1.100:8080/wm/staticflowentrypusher/list/all/json
刪除流表:
1.刪除所有流表
[controller@host ]# curl http://192.168.1.208:8080/wm/staticflowentrypusher/clear/<dpid>/json
2.刪除單條流表
[controller@host ]# curl -X DELETE -d '{"name":"flow-mod-1"}' http://<controller_ip>:8080/wm/staticflowentrypusher/json