一 启动floodlight
cd floodlight
java -jar target/floodlight.jar #运行Floodlight
在浏览器中输入地址http://localhost:8080/ui/index.html
二 启动Mininet
Mininet主要是虚拟OpenFlow交换机以及host节点。并且能构造出自定义的拓扑。虚拟OpenFlow交换机主要是基于OpenvSwitch。
启动virtualbox
sudo virtualbox
网络界面的设置可以根据需求进行设置,可以选择使用两张网卡,也可以选择仅启用一张网卡,(Host主机安装floodlight,虚拟机安装Mininet,因而只选择一张网卡,使用桥接模式;当需要选择两张网卡,设置为NAT和Host-only模式,以方便Host可以通过SSH方式链接到Minenet虚拟机),
完成安装,启动虚拟机,用户名和密码都是mininet。
如果启动时有如下错误:Failedto load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE).
解决方法: sudo chmod -R o-w /usr
ifconfig
ping www.baidu.com
也可开启新终端ssh进入vm:
ssh -X mininet@192.168.1.185 密码:mininet
创建拓扑:
sudo mn –controller=remote,ip=192.168.1.111,port=6633
或
sudo mn --topo single,3 --mac --switch ovsk --controller=remote,ip=192.168.1.111,port=6633
或
sudo mn --controller=remote,ip=192.168.1.111,port=6633 --topo tree,depth=2,fanout=3
执行如下,看看结果:
mininet>nodes
mininet>dump
mininet>net
mininet>pingall
进入node h1,h2内部:
xterm h1 h2
进入http://localhost:8080/ui/index.html查看PC上floodlight信息,可以发现有OpenFlowSwitch与之相连。若没有,检查端口占用:
netstat -anp|grep 6633
从另一终端ssh进入mininet@mininet-vm执行:
显示基本信息:dpctl show tcp:127.0.0.1:6634
显示流表: dpctl dump-flows tcp:127.0.0.1:6634
添加流表:dpctl add-flow tcp:127.0.0.1:6634 in_port=2,idle_timeout=360,actions=output:3
然后通过前后mininet>中执行pingall来看看流表带来的影响。
三,测试:
流表操作:
插入流表:
curl -d '{"switch":"00:00:20:4e:7f:74:1f:7b","name":"flow-mod-1","priority":"32768","protocol":"17","ether-type":"0x0800","ingress-port":"15","active":"true","actions":"output=normal,set-dst-ip=192.168.1.1,set-dst-mac=20:4E:7F:74:1F:7B,output=normal"}' http://192.168.1.111:8080/wm/staticflowentrypusher/json
相当与运行如下python代码插入流表,运行 python flow1.py:
# coding=utf-8
import httplib
import json
class StaticFlowPusher(object):
def __init__(self, server):
self.server = server
def get(self, data):
ret = self.rest_call({}, 'GET')
return json.loads(ret[2])
def set(self, data):
ret = self.rest_call(data, 'POST')
return ret[0] == 200
def remove(self, objtype, data):
ret = self.rest_call(data, 'DELETE')
return ret[0] == 200
def rest_call(self, data, action):
path = '/wm/staticflowentrypusher/json'
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
}
body = json.dumps(data)
conn = httplib.HTTPConnection(self.server, 8080)
conn.request(action, path, body, headers)
response = conn.getresponse()
ret = (response.status, response.reason, response.read())
print ret
conn.close()
return ret
pusher = StaticFlowPusher('192.168.1.111') #控制器ip
flow1 = {
'switch':"00:00:20:4e:7f:74:1f:7b",
"name":"flow-mod-1",
"cookie":"0",
"priority":"32768",
"ingress-port":"1",
"active":"true",
"protocol":"17",
"ether-type":"0x0800",
"ingress-port":"15",
"actions":"output=normal,set-dst-ip=192.168.1.1,set-dst-mac=20:4E:7F:74:1F:7B,output=normal"
}
#添加流表flow1
pusher.set(flow1)
执行如下指令查看流表:
mininet@mininet-vm:~$:dpctl dump-flows tcp:127.0.0.1:6634
查看交换机上的流表规则:
curl http://192.168.1.111:8080/wm/staticflowentrypusher/list/00:00:20:4e:7f:74:1f:7b/json
或 sudo curl http://192.168.1.100:8080/wm/core/switch/1/flow/json
或 sudo curl http://192.168.1.100:8080/wm/staticflowentrypusher/list/all/json
通过 Floodlight的 RestAPI,删除交换机上的流表规则
curl http://192.168.1.111:8080/wm/staticflowentrypusher/clear/00:00:20:4e:7f:74:1f:7b/json
**
附:StaticFlowPusher API:
流表项属性
操作域的操作选项
附:mininet源码安装:
# git clone git://github.com/mininet/mininet
# cd mininet
# cat INSTALL
# ./util/install.sh -nfv //只安装openflow交换机、ovs;若参数为-a,将pox等一并安装
# mn --version //查看版本
#卸载命令
sudo rm -rf /usr/local/bin/mn /usr/local/bin/mnexec /usr/local/lib/python*/*/*mininet* /usr/local/bin/ovs-* /usr/local/sbin/ovs-*
sudo apt-get remove mininet