• 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() ) }
    

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

    i.开启ryu restful服务器

    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
    

    iii.查看流表

    iv.再次测试连通性

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

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

  • 相关阅读:
    使用phpize安装php模块
    centos如何卸载软件
    修改centos环境变量
    linux系统安装php扩展
    php单入口session处理
    session阻塞机制,解决方法
    uploadify插件的使用
    php图片上传代码
    validate插件的使用
    datepicker使用
  • 原文地址:https://www.cnblogs.com/zaynq/p/11984954.html
Copyright © 2020-2023  润新知