1.实验拓扑
- 实验拓扑
- 要求
使用Python脚本完成拓扑搭建,并连接ryu控制器。 - python代码
from mininet.topo import Topo class MyTopo( Topo ): "Simple topology example." def __init__( self ): Topo.__init__(self) sw1 = self.addSwitch('s1') sw2 = self.addSwitch('s2') h1 = self.addHost('h1') h2 = self.addHost('h2') h3 = self.addHost('h3') h4 = self.addHost('h4') h5 = self.addHost('h5') h6 = self.addHost('h6') self.addLink(h1,sw1,1,1) self.addLink(h2,sw1,1,2) self.addLink(h3,sw1,1,3) self.addLink(sw1,sw2,4,4) self.addLink(h4,sw2,1,1) self.addLink(h5,sw2,1,2) self.addLink(h6,sw2,1,3) topos = { 'mytopo': ( lambda: MyTopo() ) }
- 使用下列命令建立拓扑
sudo mn --custom a.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
- 使用net查看拓扑
- 使用pingall查看连通性
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
- 进入RYU/ryu/ryu/app/gui_topology目录使用下列命令
ryu-manager gui_topology.py
- 脚本代码
#s1的脚本 #端口号1发来数据 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "in_port":1 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4096 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #端口号2发来数据 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "in_port":2 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4097 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #端口号3发来数据 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "in_port":3 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4098 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #向端口1转发 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "dl_vlan": "0" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 1 } ] }' http://localhost:8080/stats/flowentry/add #向端口2转发 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "dl_vlan": "1" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 2 } ] }' http://localhost:8080/stats/flowentry/add #向端口3转发 curl -X POST -d '{ "dpid": 1, "priority":1, "match":{ "dl_vlan": "2" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add #s2的脚本 #端口号1发来数据 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "in_port":1 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4096 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #端口号2发来数据 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "in_port":2 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4097 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #端口号3发来数据 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "in_port":3 }, "actions":[ { "type": "PUSH_VLAN", "ethertype": 33024 }, { "type": "SET_FIELD", "field": "vlan_vid", "value": 4098 }, { "type": "OUTPUT", "port": 4 } ] }' http://127.0.0.1:8080/stats/flowentry/add #向端口1转发 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "dl_vlan": "0" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 1 } ] }' http://localhost:8080/stats/flowentry/add #向端口2转发 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "dl_vlan": "1" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 2 } ] }' http://localhost:8080/stats/flowentry/add #向端口3转发 curl -X POST -d '{ "dpid": 2, "priority":1, "match":{ "dl_vlan": "2" }, "actions":[ { "type": "POP_VLAN", }, { "type": "OUTPUT", "port": 3 } ] }' http://localhost:8080/stats/flowentry/add
- 将脚本代码保存在2.sh文件里,使用下列命令运行2.sh文件
- 由于某些玄学问题(有可能是ovs版本问题),出现以下错误
- 使用下列两条命令解决这个问题
sudo ovs-vsctl set bridge s1 datapath_type=netdev sudo ovs-vsctl set bridge s2 datapath_type=netdev
- 然后再次运行脚本文件
- 使用下列命令分别查看s1, s2流表
sudo ovs-ofctl -O OpenFlow13 dump-flows s1 sudo ovs-ofctl -O OpenFlow13 dump-flows s2
- 查看连通性
3.对比两种方法,写出你的实验体会
两种方法的效果是一样的,但是ryu可以用脚本实现,比较方便,就是有可能出现问题