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

    1.实验拓扑

    (1)实验拓扑

    (2)使用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)
        self.addLink(s[0],s[1])
        count=1
        for two in s:
         for i in range(3):
          host = self.addHost('h{}'.format(count))
          self.addLink(two,host)
          count += 1
    topos = {'mytopo': (lambda:Mytopo())}
    

    (3)建立拓扑,查看连通性

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

    编写以下sh脚本

    #端口号1发来数据
    curl -X POST -d '{
    "dpid": 1,
    "priority":1,
    "match":{
        "in_port":1
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     # s1将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 4096            # 设置vlan_id的值
        },
        {
            "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",     # s1将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 4097            # 设置vlan_id的值
        },
        {
            "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",     # s1将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 4098            # 设置vlan_id的值
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 3
        }
    ]
     }' http://localhost:8080/stats/flowentry/add
    
    #端口号1发来数据
    curl -X POST -d '{
    "dpid": 2,
    "priority":1,
    "match":{
        "in_port":1
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     # s2将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 5096            # 设置vlan_id的值
        },
        {
            "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",     # s1将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 5097            # 设置vlan_id的值
        },
        {
            "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",     # s1将从主机发来的数据包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # 设置VLAN ID
            "value": 5098            # 设置vlan_id的值
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "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",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 3
        }
    ]
     }' http://localhost:8080/stats/flowentry/add
    

    运行脚本

    sudo sh ./all.sh
    

    查看流表

    使用pingall查看连通性

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

    用shell脚本储存在文件里用代码形式的改的话会比较方便吧,一开始拓扑建错了,后面才重新修改进行补救

  • 相关阅读:
    用于聚类的信用卡数据
    微信支付 参考
    小程序中 自定义组件的使用
    小程序页面跳转传参
    小程序人脸核身
    ant desgin pro 的项目中 封装的 socket.js
    vscode红色波浪线
    ant desgin pro 的项目中 请求之封装
    小程序的请求 方式封装
    浏览器网页链接打开本地exe客户端程序 及 无法导入,指定文件不是注册脚本.您的注册表编辑器只能导入2进位注册文件
  • 原文地址:https://www.cnblogs.com/huaranmeng/p/12006870.html
Copyright © 2011-2022 走看看