sayoko

导航

2019 SDN上机第6次作业

=====================================

一、搭建拓扑

通过python代码建立如图实验拓扑:

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的情况,发现net的链接和要求没有差别,pingall全都不连通

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

链接ryu控制器

编写以下sh脚本,使下发流表使1-4,2-5,3-6联通

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

运行脚本后发现ryu有在下发流表

使用代码查看s1和s2的流表

sudo ovs-ofctl -O OpenFlow13 dump-flows s1

sudo ovs-ofctl -O OpenFlow13 dump-flows s2

再次pingall,发现完成需要的连接了。

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

感觉上一次的实验下发流表的方法在命令行做有点不喜欢,就如果多次的话就会麻烦,这种使用shell脚本储存在文件里用代码形式的改的话会比较方便吧,一开始拓扑建错了,后面才重新修改进行补救,也认真的看了老师发的那个有关如何写下发流表的脚本的文件的,我觉得算是有理解好。

posted on 2019-12-08 21:18  sayoko  阅读(205)  评论(0编辑  收藏  举报