2019 SDN上机第6次作业

霸气de小男生 提交于 2019-12-06 12:58:40

1.实验拓扑

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 ):
    "Simple topology example."
 
    def __init__( self ):
        "Create custom topo."
 
        Topo.__init__( self )
        L1 = 2

        s = []
       
             
        for i in range( L1 ):
                sw = self.addSwitch( 's{}'.format( i + 1 ) )
                s.append( sw )
    
        
        count = 1
        for sw1 in s:
                for i in range(3):
                    host = self.addHost( 'h{}'.format( count ) )
                    self.addLink( sw1, host )
                    count += 1
    self.addLink(s[0],s[1])
topos = { 'mytopo': ( lambda: MyTopo() ) }


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

  • 对交换机S1的配置流表sh文件如下(端口S2参照S1稍作修改即可)
  • sudo chmod +x ctl.sh+sudo ./ctl.sh两个命令下发流表
# ctl.sh
curl -X POST -d '{
    "dpid": 1,                      #交换机S1
    "priority":1,
    "match":{
        "in_port":1                 #设置对端口1进来的包操作
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     # 给进入交换机的包打上vlan_tag
            "ethertype": 33024      
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # field值为4096+vlan_id
            "value": 4096            # 设置field的值为4096即vlan_id的值为0
        },
        {
            "type": "OUTPUT",
            "port": 4               #操作为从端口4转发
        }
    ]
 }' http://127.0.0.1:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,                      #交换机S1
    "priority":1,
    "match":{
        "in_port":2                 #设置对端口2进来的包
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     # 给进入交换机的包打上vlan_tag
            "ethertype": 33024       
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # field值为4096+vlan_id
            "value": 4097            # 设置field的值为4097即vlan_id的值为1
        },
        {
            "type": "OUTPUT",
            "port": 4               #操作为从端口4转发
        }
    ]
 }' http://127.0.0.1:8080/stats/flowentry/add


curl -X POST -d '{
    "dpid": 1,                      #交换机S1
    "priority":1,
    "match":{
        "in_port":3                 #设置对端口3进来的包操作
    },
    "actions":[
        {
            "type": "PUSH_VLAN",     # 给进入交换机的包打上vlan_tag
            "ethertype": 33024       # 帧类型0x8100(=33024): 表示IEEE 802.1Q的VLAN数据帧
        },
        {
            "type": "SET_FIELD",
            "field": "vlan_vid",     # field值为4096+vlan_id
            "value": 4098            # 设置field的值为4098即vlan_id的值为2
        },
        {
            "type": "OUTPUT",
            "port": 4               #操作为从端口4转发
        }
    ]
 }' http://127.0.0.1:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,                      #交换机S1
    "priority":1,
    "match":{
        "dl_vlan": "0"              #对dl_vlan即vlan_id为0进来的包
    },
    "actions":[
        {
            "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 1               #从端口1转发
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,
    "priority":1,
    "match":{
        "dl_vlan": "1"              #对dl_vlan即vlan_id为1进来的包
    },
    "actions":[
        {
            "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 2               #从端口2转发
        }
    ]
 }' http://localhost:8080/stats/flowentry/add
curl -X POST -d '{
    "dpid": 1,          
    "priority":1,
    "match":{
        "dl_vlan": "2"              #对dl_vlan即vlan_id为1进来的包
    },
    "actions":[
        {
            "type": "POP_VLAN",     # 给进入交换机的包去除 vlan_tag
        },
        {
            "type": "OUTPUT",
            "port": 3               #从端口2转发
        }
    ]
 }' http://localhost:8080/stats/flowentry/add

  • 下发流表成功

  • pingall 检测一下是否满足vlan(h1,h4)、vlan2(h2,h5)、vlan3(h3,h6);


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

  • 直接在Open vSwitch下发流表命令行太过繁杂不能直观体现流表内容
  • 使用Ryu的REST API下发流表可以直观的看出流表内容而且只需执行单个脚步就能实现比较简易

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!