• 2019 SDN上机第6次作业


    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
    

    使用Python脚本完成拓扑搭建,并连接ryu控制器。
    打开ryu控制器

    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
    

    编译


    pingall

    查看s1 s2流表

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

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

  • 相关阅读:
    Notes for Advanced Linux Programming 2. Writing Good GNU/Linux Software
    GIT 子模块温习
    Memcached 源码分析——从 main 函数说起
    Zookeeper 初体验之——JAVA实例
    如何使用 indent 美化你的代码
    PGF/TIKZ 资源汇总
    Zookeeper 进阶之——Zookeeper编程示例(如何使用Zookeeper实现屏障Barriers和队列Queues)
    Zookeeper 进阶之——典型应用场景(二)
    如何将 Linux 内核实现的红黑树 rbtree 运用到你的 C 程序中?
    三行代码实现C语言单元测试框架
  • 原文地址:https://www.cnblogs.com/spongebobyjh/p/12014264.html
Copyright © 2020-2023  润新知