• 2019 SDN上机第6次作业


    1.实验拓扑

    拓扑如下

    python脚本

    from mininet.topo import Topo
    class MyTopo(Topo):
        def __init__(self):
            # initilaize topology
            Topo.__init__(self)
            # add hosts and switches
            host1 = self.addHost('h1')
            host2 = self.addHost('h2')
            host3 = self.addHost('h3')
            host4 = self.addHost('h4')
        host5 = self.addHost('h5')
            host6 = self.addHost('h6')
            switch1 = self.addSwitch('s1')
            switch2 = self.addSwitch('s2')
            # add links
            self.addLink(host1, switch1, 1, 1)
            self.addLink(host2, switch1, 1, 2)
        self.addLink(host3, switch1, 1, 3)
            self.addLink(host4, switch2, 1, 1)
            self.addLink(host5, switch2, 1, 2)
        self.addLink(host6, switch2, 1, 3)
        self.addLink(switch1, switch2, 4, 4)      
    topos = {'mytopo': (lambda: MyTopo())}
    

    运行脚本

    • sudo mn --custom ./2.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13

    连接ryu控制器

    • ryu-manager ofctl_rest.py

    输入net,查看各主机与交换机之间的端口情况

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

    按实验二编写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 all.sh

    • 运行sh脚本可能会显示“all.sh: curl: not found”错误,原因是系统中没有安装curl,需要执行“sudo apt-get install curl”命令安装。

    查看s1流表

    • sudo ovs-ofctl -O OpenFlow13 dump-flows s1

    查看s2流表

    • sudo ovs-ofctl -O OpenFlow13 dump-flows s2

    使用pingall检测连通性

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

    相比于第二次实验,这次试验使用Ryu的REST API下发流表实现VLAN,代码的可视性更好,条理清晰,便于修改,不会像实验二一般错了就要需要重新编写。

  • 相关阅读:
    delphi llPDFLib 添加虚线
    delphi使用RichView控件 增大表格字号
    delphi llPDFLib 文档设置
    delphi llPDFLib 添加密码
    狂神说java springboot笔记
    Java 8 Optional 用法
    lambda表达式总结
    【狂神说Java】SpringBoot 聊聊现在和未来
    Springboot整合MyBatis参数传值方式
    JVM类加载器
  • 原文地址:https://www.cnblogs.com/fwhdbk/p/11992109.html
Copyright © 2020-2023  润新知