2019 SDN上机第6次作业

2019 SDN上机第6次作业

1.实验拓扑

实验拓扑
2019 SDN上机第6次作业_第1张图片

创建名为test.py的文件
代码

class Topotest( Topo ):
    def __init__( self ):
        Topo.__init__( self )
        sw1 = self.addSwitch('s1')
        sw2 = self.addSwitch('s2')
        h1 = self.addHost('h1')
        h2 = self.addHost('h2')
        h3 = self.addHost('h3')
        h4 = self.addHost('h4')
        h5 = self.addHost('h5')
        h6 = self.addHost('h6')
        self.addLink(h1,sw1,1,1)
        self.addLink(h2,sw1,1,2)
        self.addLink(h3,sw1,1,3)
        self.addLink(sw1,sw2,4,4)
        self.addLink(h4,sw2,1,1)
        self.addLink(h5,sw2,1,2)
        self.addLink(h6,sw2,1,3)

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

输入命令执行文件创建拓扑

sudo mn --custom test.py --topo mytopo --switch ovsk,protocols=OpenFlow13 --controller=remote

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

使用Python脚本完成拓扑搭建,并连接ryu控制器。
打开ryu控制器
2019 SDN上机第6次作业_第3张图片

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

要求
编写脚本,一键执行下发流表。
代码

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://127.0.0.1:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 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://127.0.0.1:8080/stats/flowentry/add

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://127.0.0.1:8080/stats/flowentry/add


curl -X POST -d '{
    "dpid": 1,
    "priority":1,
    "match":{
        "dl_vlan": "0"
    },
    "actions":[
        {
            "type": "POP_VLAN",     
        },
        {
            "type": "OUTPUT",
            "port": 1
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,
    "priority":1,
    "match":{
        "dl_vlan": "1"
    },
    "actions":[
        {
            "type": "POP_VLAN",     
        },
        {
            "type": "OUTPUT",
            "port": 2
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,
    "priority":1,
    "match":{
        "dl_vlan": "2"
    },
    "actions":[
        {
            "type": "POP_VLAN",     
        },
        {
            "type": "OUTPUT",
            "port": 3
        }
    ]
 }' http://localhost:8080/stats/flowentry/add



curl -X POST -d '{
    "dpid": 2,                       
    "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://127.0.0.1:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 2,
    "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://127.0.0.1:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 2,
    "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://127.0.0.1:8080/stats/flowentry/add


curl -X POST -d '{
    "dpid": 2,
    "priority":1,
    "match":{
        "dl_vlan": "0"
    },
    "actions":[
        {
            "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 1
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 2,
    "priority":1,
    "match":{
        "dl_vlan": "1"
    },
    "actions":[
        {
            "type": "POP_VLAN",    
        },
        {
            "type": "OUTPUT",
            "port": 2
        }
    ]
 }' http://localhost:8080/stats/flowentry/add
#交换机s2将收到的数据包根据其对应的vlan_tag从端口3转发
curl -X POST -d '{
    "dpid": 2,
    "priority":1,
    "match":{
        "dl_vlan": "2"
    },
    "actions":[
        {
            "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 3
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

编译

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

查看s1 s2流表
2019 SDN上机第6次作业_第6张图片

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

做完这次实验以后显然感受到这次用ryu控制器更加的方便简单。记得上次的那种方法我做了很多次一直有问题,然后每次都一句话一句话的输进去,很麻烦。这次实验只需要写个文件编译一下就好了,真的快乐很多和方便很多。

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