1. 解压安装OpenDayLight控制器(本次实验统一使用Beryllium版本)
sudo gedit ~/.bashrc
在底部添加以下语句
export JAVA_HOME=/home/w/Desktop/test4/jdk1.8.0_211 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
2. 启动并安装插件
进入OpenDayLigh的文件夹,运行./karaf (注意不能用sudo运行):
安装feature
feature:install odl-restconf odl-l2switch-switch-ui odl-openflowplugin-all odl-mdsal-apidocs odl-dlux-core odl-dlux-node odl-dlux-yangui
3. 用Python脚本搭建如下拓扑,连接OpenDayLight控制器
python代码如下
from mininet.topo import Topo class MyTopo(Topo): def __init__(self): # initilaize topology Topo.__init__(self) # add hosts and switches h1 = self.addHost('h1') h2 = self.addHost('h2') h3 = self.addHost('h3') s1 = self.addSwitch('s1') # add links self.addLink(h1, s1, 1, 1) self.addLink(h2, s1, 1, 2) self.addLink(h3, s1, 1, 3) topos = {'mytopo': (lambda: MyTopo())}
输入以下代码运行
sudo mn --custom /home/w/Desktop/test4/test4.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
用pingall测试主机之间的连通性
打开http://127.0.0.1:8181/index.html
依次点击Yang UI>Opendaylight-inventory>config>nodes>table>flow:
分别设置nod、table、flow的值,如下图所示(其中node/openflow:1 交换机编号;table/0 流表编号;flow/不超过1024,不冲突即可流表项编号;GET为查询流表,下发流表要修改为PUT;点击加号添加流表项):
用links查询链路连接情况
在Opendaylight下设置相关值,如下图所示:
id:流表项id,为任意值,不冲突即可
in-port:流表项匹配的进入端口,这里需填h2对应的port号
ethernet-type:以太网类型0x0800
layer-3-match:ipv4-match 三层匹配为ipv4匹配
新增instruction list这是流表项匹配到数据报后要执行的指令
instruction:apply-actions-case 执行动作
action drop-action-case 丢包动作(转发动作为output-action 并要在output-node-connector填写转发端口)
priority 流表项优先级,要大于odl下发的默认流表,这里设置成最大65535
hard-timeout 硬超时,流表项下发后生效时长
table_id 流表id 默认为0
.在设置好之后,先在mininet中进行h2 ping h3,然后在WEB UI中选择PUT,并点击旁边的send,结果如下图所示,icmp_seq会延迟20:
5借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表
通过preview查看刚刚下发的流表项的json格式:
http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1 { "flow": [ { "id": "1", "match": { "in-port": "1", "ethernet-match": { "ethernet-type": { "type": "0x0800" } }, "ipv4-destination": "10.0.0.3/32" }, "instructions": { "instruction": [ { "order": "0", "apply-actions": { "action": [ { "order": "0", "drop-action": {} } ] } } ] }, "priority": "65535", "hard-timeout": "20", "table_id": "0" } ] }
打开postman,将preview里的url复制到地址栏,消息方式选PUT
type选择Basic Auth 用户名和密码都是admin
Body中将消息格式设置成json,上传方式设置为raw
使用get可以调用接口查看流表