1.实验拓扑
Python脚本
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
L1 = 2
L2 = L1 * 3
s = []
h = []
for i in range( L1 ):
sw = self.addSwitch( 's{}'.format( i + 1 ) )
s.append( sw )
self.addLink(s[0],s[1],4,4)
count = 1
for sw1 in s:
for i in range(3):
host = self.addHost( 'h{}'.format( count ) )
self.addLink( sw1, host,i+1,1 )
count += 1
topos = { 'mytopo': ( lambda: MyTopo() ) }
运行以下代码创建拓扑
sudo mn --custom ./fattree.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6653 --switch ovsk,protocols=OpenFlow13
使用net命令查看拓扑
pingall测试主机连通性
ryu-manager gui_topology.py
2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN
向交换机1发来消息:
curl -X POST -d '{
"dpid": 1,
"priority":1,
"match":{
"in_port":1
},
"actions":[
{
"type": "PUSH_VLAN", # s1将从主机发来的数据包打上vlan_tag
"ethertype": 33024 # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
},
{
"type": "SET_FIELD",
"field": "vlan_vid", # 设置VLAN ID
"value": 4096 # 设置vlan_id的值
},
{
"type": "OUTPUT",
"port": 4
}
]
}' http://127.0.0.1:8080/stats/flowentry/add
交换机1向端口1转发消息:
curl -X POST -d '{
"dpid": 1,
"priority":1,
"match":{
"dl_vlan": "0"
},
"actions":[
{
"type": "POP_VLAN", # 给进入交换机的包去除 vlan_tag
},
{
"type": "OUTPUT",
"port": 1
}
]
}' http://localhost:8080/stats/flowentry/add
ovs命令查看流表:
sudo ovs-ofctl -O OpenFlow13 dump-flows s1
sudo ovs-ofctl -O OpenFlow13 dump-flows s2
3.对比两种方法,写出你的实验体会
与ovs命令直接下发流表相比,通过ryu的脚本可以实现自动化地下发流表