zoukankan      html  css  js  c++  java
  • 2019 SDN上机第6次作业

    1.实验拓扑

    实验拓扑
    见2019 SDN上机第2次作业

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

    #!/usr/bin/python
    #创建网络拓扑
    from mininet.topo import Topo
    from mininet.net import Mininet
    from mininet.node import RemoteController,CPULimitedHost
    from mininet.link import TCLink
    from mininet.util import dumpNodeConnections
    class MyTopo( Topo ):
        def __init__( self ):
            # Initialize topology
            Topo.__init__( self )
    
            # add switches  
            s1 = self.addSwitch('s1')
    	s2 = self.addSwitch('s2')
        	# add hosts  
            h1 = self.addHost('h1')
            h2 = self.addHost('h2')
            h3 = self.addHost('h3')
    	h4 = self.addHost('h4')
            h5 = self.addHost('h5')
            h6 = self.addHost('h6')
    
            # add links
            self.addLink(h1,s1,1,1)
            self.addLink(h2,s1,1,2)
            self.addLink(h3,s1,1,3)
            self.addLink(h4,s2,1,1)
            self.addLink(h5,s2,1,2)
            self.addLink(h6,s2,1,3)
            self.addLink(s1,s2,4,4)
    
    topos = { 'mytopo': ( lambda: MyTopo() ) }
    

    使用Python脚本完成拓扑搭建

    连接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
    
    #端口号2发来数据
    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
    
    #端口号3发来数据
    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
    
    
    
    #向端口1转发
    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
    
    #向端口2转发
    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
    
    #向端口3转发
    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
    #s2
    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
    
    #端口号2发来数据
    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
    
    #端口号3发来数据
    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
    
    
    
    #向端口1转发
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "dl_vlan": "0"
        },
        "actions":[
            {
                "type": "POP_VLAN",
            },
            {
                "type": "OUTPUT",
                "port": 1
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    #向端口2转发
    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
    
    #向端口3转发
    curl -X POST -d '{
        "dpid": 2,
        "priority":1,
        "match":{
            "dl_vlan": "2"
        },
        "actions":[
            {
                "type": "POP_VLAN",
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
        ]
    }' http://localhost:8080/stats/flowentry/add
    
    运行
    


    检测连通性

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

    因为忘记了第二次实验内容,所以强制回(chong)忆(xue)了好久。
    ryu感觉更方便、更容易理解也更容易使用一点。
    Open vSwitch会更难懂,也更复杂一点。

  • 相关阅读:
    Pandas Dict到DataFrame Series到DataFrame 转换
    MySQL锁和事务
    MySQl创建用户和授权,mysquldump
    MySQL索引
    pymysql模块
    Navicat下载安装
    MySQL多表查询
    学习目录
    MySQL单表查询
    MySQL逻辑查询语句的执行顺序
  • 原文地址:https://www.cnblogs.com/wawu/p/11984696.html
Copyright © 2011-2022 走看看