1.实验拓扑
实验拓扑
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')
h4 = self.addHost('h4')
h5 = self.addHost('h5')
h6 = self.addHost('h6')
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
# add links
self.addLink(h1, s1, 1, 1)
self.addLink(h2, s1, 1, 2)
self.addLink(h3, s1, 1, 3)
self.addLink(s1, s2, 4, 4)
self.addLink(h4, s2, 1, 1)
self.addLink(h5, s2, 1, 2)
self.addLink(h6, s2, 1, 3)
topos = {'mytopo': (lambda: MyTopo())}
使用命令sudo mn --custom topo.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
创建拓扑:
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
下发流表之前:
打开RYU GUI界面:ryu-manager gui_topology.py
下发流表
采取shell文件编辑流表脚本(s1):
#h1-s2
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://localhost:8080/stats/flowentry/add
#h2-s2
curl -X POST -d '{
"dpid": 1,
"priority": 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://localhost:8080/stats/flowentry/add
#h3-s2
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://localhost:8080/stats/flowentry/add
#vlan = 0(=4096-vlan_vid) -> s2:eth1
# h1 - > h4
curl -X POST -d '{
"dpid": 1,
"priority": 1,
"match":{
"dl_vlan": "0" # Describe sum of VLAN-ID(e.g. 5) | OFPVID_PRESENT(0x1000)
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type":"OUTPUT",
"port": 1
}
]
}' http://localhost:8080/stats/flowentry/add
#vlan = 1(=vlan_vid-4096) -> s2:eth2
# h2 - > h5
curl -X POST -d '{
"dpid": 1,
"priority": 1,
"match":{
"dl_vlan": "1" # Describe sum of VLAN-ID(e.g. 5) | OFPVID_PRESENT(0x1000)
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type":"OUTPUT",
"port": 2
}
]
}' http://localhost:8080/stats/flowentry/add
#vlan = 2(=vlan_vid-4096) -> s2:eth3
# h3 - > h6
curl -X POST -d '{
"dpid": 1,
"priority": 1,
"match":{
"dl_vlan": "2" # Describe sum of VLAN-ID(e.g. 5) | OFPVID_PRESENT(0x1000)
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type":"OUTPUT",
"port": 3
}
]
}' http://localhost:8080/stats/flowentry/add
使用sh all.sh
执行下发流表的命令
将"dpid":1
都改为"dpid": 2
就可以下发s2的流表
在RYU界面查看流表:
下发流表之后再次pingall:
3.对比两种方法,写出你的实验体会
采用Ryu控制器的REST API下发的流表是直接编辑json格式的流表,界面会更清楚且容易理解。