2019 SDN上机第6次作业

1.实验拓扑

from mininet.topo import Topo
from mininet.net import Mininet
 
class MyTopo( Topo ):
    "Simple topology example."
 
    def __init__( self ):
        "Create custom topo."
 
        # Initialize topology
        Topo.__init__( self )
        
        s1 = self.addSwitch('s1')
        i = 0
        while i<=3:
            host = self.addHost('h{}'.format(i))
            self.addLink(s1,host)
            i = i+1

        s2 = self.addSwitch('s2')
        while i<=6:
            host = self.addHost('h{}'.format(i))
            self.addLink(s2,host)
            i = i+1

        self.addLink(s1,s2)

topos = { 'mytopo': ( lambda: MyTopo() ) }

2019 SDN上机第6次作业_第1张图片

2.使用Ryu的REST API下发流表实现和第2次实验同样的VLAN

i.开启ryu restful服务器

2019 SDN上机第6次作业_第2张图片

ii.使用curl发送流表

$ sudo sh ./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

2019 SDN上机第6次作业_第3张图片

iii.查看流表

2019 SDN上机第6次作业_第4张图片

iv.再次测试连通性

2019 SDN上机第6次作业_第5张图片

3.对比两种方法,写出你的实验体会

使用rest api并使用shell脚本下发流表的方式,相比Open vSwitch在命令行下发流表,要方便许多。
首先是使用了json格式,流表的结构较为清晰易懂。其次是易于修改,并且脚本可以多次执行,而命令行方式修改和执行则十分麻烦,需要疯狂↑↓←→。
中间还经历了一个小插曲,创建拓扑的时候把OpenFlow的l给大写了,导致发流表时一直404,弄了好久才发现。

你可能感兴趣的:(2019 SDN上机第6次作业)