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

    1.实验拓扑

    python脚本

    from mininet.topo import Topo
    class Mytopo(Topo):
        def __init__(self):
            Topo.__init__(self)
            s=[]
            for i in range(2):
                sw = self.addSwitch('s{}'.format(i+1))
                s.append(sw)
            count=1
            for m in s:
                for i in range(3):
              	host = self.addHost('h{}'.format(count))
              	self.addLink(m,host)
              	count += 1
            self.addLink(s[0],s[1])
    topos = {'mytopo': (lambda:Mytopo())}
    

    搭建拓扑

    连接ryu控制器

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

    #将h1进入s1的包打上vlan tag,转发端口4
    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
    
    #将h2进入s1的包打上vlan tag,转发端口4
    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
    
    #将h3进入s1的包打上vlan tag,转发端口4
    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
    
    
    
    #将从s1端口的4包去除vlan tag, 并根据tag进行转发
    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
    
    #将h4进入s2的包打上vlan tag,转发端口4
    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
    
    #将h5进入s2的包打上vlan tag,转发端口4
    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
    
    #将h6进入s2的包打上vlan tag,转发端口4
    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
    
    
    
    #将从s2端口4的包去除vlan tag, 并根据tag进行转发
    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
    
    
    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
    
    
    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
    
    
    
    

    ryu控制器显示结果

    查看流表

    pingall

    3.对比两种方法,写出你的实验体会
    两种方法基本一致,相对来说ryu比较容易理解且较为方便

  • 相关阅读:
    移动端前端开发调试
    webkit图片滤镜
    ruby安装sass报错解决办法
    mongodb的查询语句学习摘要
    signedCookies
    [cookie篇]从cookie-parser中间件说起
    node.js下mongoose简单操作实例
    在ExpressJS中设置二级域名跨域共享Cookie
    Node.js开发工具、开发包、框架等总结
    hibernate框架学习笔记4:主键生成策略、对象状态
  • 原文地址:https://www.cnblogs.com/LIN5516558/p/11985110.html
Copyright © 2011-2022 走看看