1.实验拓扑
- 构建拓扑代码
from mininet.topo import Topo from mininet.net import Mininet from mininet.node import RemoteController,CPULimitedHost from mininet.link import TCLink from mininet.util import dumpNodeConnections class MyTopo( Topo ): "Simple topology example." def __init__( self ): "Create custom topo." Topo.__init__( self ) switchs = [] for i in range(2): sw = self.addSwitch("s{}".format(i + 1)) switchs.append(sw) self.addLink(switchs[0], switchs[1],4,4) count = 1 for sw in switchs: for i in range(3): h = self.addHost("h{}".format(count)) self.addLink(sw, h,i+1,1) count += 1 topos = { 'mytopo': ( lambda: MyTopo() ) }
- 构建成功
查看端口连接情况
连接ryu控制器
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
- 交换机2流表:
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 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 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 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 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 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
交换机1流表参照交换机1
- 运行结果
- 查看流表
sudo ovs-ofctl -O OpenFlow13 dump-flows s1
sudo ovs-ofctl -O OpenFlow13 dump-flows s2
pingall查看主机连通情况
查看图形界面
3.对比两种方法,写出你的实验体会
- 本次实验不用安装软件真是太开心了,果然做的很快
- ryu可以一次性下发流表,相比ovs-ofctl简单易懂很多,通用性更高。