2019 SDN上机第6次作业

一、实验拓扑

1、实验拓扑图如下

2019 SDN上机第6次作业_第1张图片

2、使用Python脚本完成拓扑搭建,并连接ryu控制器。实验代码如下:

from mininet.topo import Topo
class Topo2( 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(s1,s2,4,4)
        self.addLink(h4,s2,1,1)
        self.addLink(h5,s2,1,2)
        self.addLink(h6,s2,1,3)

topos = { 'mytopo': ( lambda: Topo2() ) }

输入如下命令运行Python脚本x.py

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

2019 SDN上机第6次作业_第2张图片
终端输入ping和net查看连接情况
2019 SDN上机第6次作业_第3张图片

2019 SDN上机第6次作业_第4张图片
进入文件夹的ryu文件夹下的app,连接ryu控制器

ryu-manager ofctl_rest.py

2019 SDN上机第6次作业_第5张图片

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

按照实验二编写脚本,脚本为sdn6.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 bash sdn6.sh

RYU控制器已接收流表项
2019 SDN上机第6次作业_第6张图片
查看s1和s2的流表,如图所示

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

2019 SDN上机第6次作业_第7张图片
再次查看连通性,发现已经连通
2019 SDN上机第6次作业_第8张图片

三、对比两种方法,写出你的实验体会

其实两种方法原理都差不多。实验二使用ovs了命令直接在交换机上下发流表实现VLAN,而这次实验是借助了RYU控制器。相比前者,后者实现起来更为方便简单。但这次实验过程我出现了8080端口拒绝连接的情况,网上查找资料也没有具体的解决方法。最终经过我不断的重启,就解决了这个问题。但我会继续查找资料找到更好地解决方法。

你可能感兴趣的:(2019 SDN上机第6次作业)