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

    1.实验拓扑

    实验拓扑图如下:

    搭建代码如下:
    创建py文件,并编写py代码,代码如下:

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

    搭建结果如下

    使用net查看拓扑

    使用pingall发现都不连通

    进入文件夹的ryu文件夹下的app,通过以下的命令连接ryu控制器,结果如下图

    ryu-manager ofctl_rest.py
    

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

    按照实验二编写如下脚本,脚本为all.sh,内容如下:

    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
    
    
    
    
    
    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
    
    
    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
    
    
    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
    
    
    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
    
    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
    
    
    
    curl -X POST -d '{
        "dpid": 2,
        "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
    
    
    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": 4097            # 设置vlan_id的值
            },
            {
                "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",     # 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
    
    
    
    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",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "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",     # 给进入交换机的包去除 vlan_tag
            },
            {
                "type": "OUTPUT",
                "port": 3
            }
    
        ]
    
    }' http://localhost:8080/stats/flowentry/add
    
    

    使用sudo sh '/home/ubuntu/Desktop/all.sh' 运行脚本,可以发现ryu控制器已经接受了流表项,结果如下


    查看s1和s2的流表,如下如所示:

    然后pingall,发现可以ping的通了,由此下发流表成功,得到了和实验二一样的结果

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

    两个方法的意思是差不多的,有了实验二的理解,要做这个实验就显得比较简单,因为每个流表项都可以较快的理解。实验二中是使用ovs了命令直接在交换机上下发流表实现VLAN,这一次是用Ryu控制器来实现,而且相比于上一次实验,本次的内容可以保存在文件中,需要修改的时候也只要修改几个参数,不会像第一次实验那样关闭命令行就消失掉,这样操作起来会比较方便,特别是我们现在做这些题目很不熟悉,经常会因为一些七七八八的原因重新做实验。所以我觉得这种方法会更好。

  • 相关阅读:
    Java----自增,自减运算符
    Java----运算符
    Java---变量,常量,作用域
    Java--类型转换
    图像压缩
    最大熵对应的概率分布
    Python matplotlib画图时图例说明(legend)放到图像外侧详解
    pytorch persistent_workers
    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
    Pytorch中出现的奇怪错误
  • 原文地址:https://www.cnblogs.com/yaobink/p/11984941.html
Copyright © 2011-2022 走看看