1.实验拓扑
from mininet.topo import Topo
class Mytopo(Topo):
def __init__(self):
Topo.__init__(self)
s=[]
for i in range(2):
sw = self.addSwitch('s{}'.format(i+1))
s.append(sw)
self.addLink(s[0],s[1])
count=1
for two in s:
for i in range(3):
host = self.addHost('h{}'.format(count))
self.addLink(two,host)
count += 1
topos = {'mytopo': (lambda:Mytopo())}
ryu-manager gui_topology.py
ryu-manager --observe-links gui_topology.py//可以查看交换机连接情况
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
curl -X POST -d '{
"dpid":1,
"priority":1,
"match":{
"in_port":2
},
"actions":[
{
"type": "PUSH_VLAN", # Push a new VLAN tag if a input frame is non-VLAN-tagged
"ethertype": 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
},
{
"type": "SET_FIELD",
"field": "vlan_vid", # Set VLAN ID
"value": 4096 # Describe sum of vlan_id(e.g. 6) | OFPVID_PRESENT(0x1000=4096)
},
{
"type": "OUTPUT",
"port": 1
}
]
}' http://0.0.0.0:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"priority":1,
"match":{
"dl_vlan": "0"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 2
}
]
}' http://0.0.0.0:8080/stats/flowentry/add
sudo sh Allflow.sh
3.对比两种方法,写出你的实验体会
- 总结
本次实验用ryu控制器编写并执行用于下发流表的sh脚本,我觉得比起使用命令下发流表,使用ryu编写sh脚本并执行更加方便。比起繁琐的命令,只要提前准备好脚本,任何人都可以通过直接执行脚本来下发流表,而不需要了解使用原理。