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

    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下发流表可以直观的看出流表内容而且只需执行单个脚步就能实现比较简易

  • 相关阅读:
    Servlet 生命周期
    深度学习笔记(十)Augmentation for small object detection(翻译)
    fast.ai(零)windows + pytorch 0.4
    win10 + cuda8.0 + caffe SSD + vs2015 + python3
    PyTorch(二)Intermediate
    PyTorch(一)Basics
    Caffe 使用记录(五)math_functions 分析
    win10 + gluon + GPU
    python tricks
    深度学习笔记(九)感受野计算
  • 原文地址:https://www.cnblogs.com/fzu-Z9h/p/11985611.html
Copyright © 2011-2022 走看看