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())}
sudo mn --custom MyTopo.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
使用pingall命令测试连通性
打开ryu rest服务器
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
# flow.sh
# flow.sh
curl -X POST -d '{
"dpid":1, # 交换机s1
"match":{
"in_port":1 # 端口1
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD", # 打tag
"field": "vlan_vid",
"value": 4097 # value = 4096 + dl_vlan
},
{
"type": "OUTPUT",
"port": 4 # 转发端口
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"match":{
"in_port":2
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4098
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"match":{
"in_port":3
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4099
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"match":{
"dl_vlan": "1" # tag
},
"actions":[
{
"type": "POP_VLAN", # 去除tag
},
{
"type": "OUTPUT",
"port": 1
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"match":{
"dl_vlan": "2"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 2
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 1,
"match":{
"dl_vlan": "3"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 3
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid":2,
"match":{
"in_port":1
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4097
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match":{
"in_port":2
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4098
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match":{
"in_port":3
},
"actions":[
{
"type": "PUSH_VLAN",
"ethertype": 33024
},
{
"type": "SET_FIELD",
"field": "vlan_vid",
"value": 4099
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match":{
"dl_vlan": "1"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 1
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match":{
"dl_vlan": "2"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 2
}
]
}' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
"dpid": 2,
"match":{
"dl_vlan": "3"
},
"actions":[
{
"type": "POP_VLAN",
},
{
"type": "OUTPUT",
"port": 3
}
]
}' http://localhost:8080/stats/flowentry/add
使用命令安装curl
$ sudo apt install curl
使用命令
$ sudo sh ./flow.sh
3.对比两种方法,写出你的实验体会
两种方法虽然目的一样,但使用Ryu的REST API下发流表来实现的话相对来说更加灵活容易修改,且直接查看代码也更加直观清晰,易于理解,操作也更为简单。