zoukankan      html  css  js  c++  java
  • 使用mininet创建网络拓扑,使ryu、ovs、主机连接

    实验拓扑

    控制器:RYU
    交换机:s1,s2
    主机:h1,h2,h3,h3
    联通性(直连):
    h1<->s1;h2<->s1
    h3<->s2;h4<->s2
    s1<->s2
    拓扑代码如下:

    #!/user/bin/env python
    from mininet.topo import Topo
    class MyTopo(Topo):
        def build(self):
            left=[]
            left.append(self.addHost("h1"))
            left.append(self.addHost("h2"))
            right=[]
            right.append(self.addHost("h3"))
            right.append(self.addHost("h4"))
            switchs=[]
            switchs.append(self.addSwitch("s1"))
            switchs.append(self.addSwitch("s2"))
    
            self.addLink(left[0],switchs[0])
            self.addLink(left[1],switchs[0])
            self.addLink(right[0],switchs[1])
            self.addLink(right[1],switchs[1])
            self.addLink(switchs[0],switchs[1])
    
    
    topos={'mytopo':(lambda : MyTopo())}

    mininet/custom 中有一个示例文件topo-2sw-2host.py.。可以按照该文件的内容进行相应地修改,定义自己的拓扑结构。

    将自定义的网络拓扑写好后放到该custom目录下即可。

    启动RYU

    cd RYUPATH/ryu/app/         #首先进入到RYU的安装目录的app目录下,里面有相应的模块
    sudo ryu-manager ofctl_rest.py simple_switch.py
    # 启动ofctl_rest.py模块以及simple_switch.py交换机,这个是openflow1.0的交换机
    

    启动mininet

    sudo mn --controller=remote,ip=127.0.0.1,port=6653 --custom ~/Desktop/mininet/custom/1.py --topo mytopo
    

    在这里ryu和mininet是在一台机器上的,所以ip地址为127.0.0.1,也可以写成controller=remote预设是在本机的ip 若是controller在其他机器的话则在后面加上ip=xxx.xxx.xx.xx
    例如 --controller=remote,ip=192.168.10.11 

    其中 1.py是刚刚定义的拓扑python文件, mytopo是 最后两行

    topos={'mytopo':(lambda : MyTopo())} 中指定的拓扑名
    

      

    实验细节
     
    1. 在mininet 检查网络联通性
     
    mininet> pingall
    *** Ping: testing ping reachability
    h1 -> h2 h3 h4
    h2 -> h1 h3 h4
    h3 -> h1 h2 h4
    h4 -> h1 h2 h3
    *** Results: 0% dropped (12/12 received)1234567
    结论:4台主机 两两互通
    得到指定交换机的所有flow的状态信息
    {
      "1": [
        {
          "actions": [
            "OUTPUT:3"
          ],(动作,转发到3 号端口)
          "idle_timeout": 0,(空闲后存活时间)
          "cookie": 0,
          "packet_count": 2,(包计数)
          "hard_timeout": 0,(存活时间)
          "byte_count": 140,(比特计数)
          "duration_nsec": 111000000,
          "priority": 32768,(优先级)
          "duration_sec": 985,(已经存活时间)
          "table_id": 0,(在流表1)
          "match": (匹配字段)
          {
            "dl_dst": "02:28:7c:93:27:af",(主机h3的地址)(过滤目的地址为02:28:7c:93:27:af的包,就是去主机3的包)
            "in_port": 2(从2号口子来的)
          }
          (作用:从2号口子来的,要到h3的报文都从3号口子出去哈)
        },
        {
          "actions": [
            "OUTPUT:2"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 7,
          "hard_timeout": 0,
          "byte_count": 518,
          "duration_nsec": 113000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "d2:3e:55:89:f3:a1",
            "in_port": 3
          }
          (作用:从3号口子来的,发往h2的包都从2号口子出去哈)
        },
        {
          "actions": [
            "OUTPUT:3"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 2,
          "hard_timeout": 0,
          "byte_count": 140,
          "duration_nsec": 155000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "02:28:7c:93:27:af",
            "in_port": 1
          }
          (作用:从1号口子来的,发往h3的的包都从3号口子出去哈
        },
        {
          "actions": [
            "OUTPUT:1"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 3,
          "hard_timeout": 0,
          "byte_count": 238,
          "duration_nsec": 171000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "fe:3b:25:cc:04:97",
            "in_port": 2
          }
          (作用:从2号口子来的,发往h1的包都从1号口子出去哈)
        },
        {
          "actions": [
            "OUTPUT:2"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 2,
          "hard_timeout": 0,
          "byte_count": 140,
          "duration_nsec": 169000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "d2:3e:55:89:f3:a1",
            "in_port": 1
          }
          (从1号口子来的,发给h2的包都从2号口子出去哈
        },
        {
          "actions": [
            "OUTPUT:3"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 2,
          "hard_timeout": 0,
          "byte_count": 140,
          "duration_nsec": 137000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "ba:94:88:a1:55:63",
            "in_port": 1
          }
          (从1号口子来的,发往h4的,从3号口子出去哈)
        },
        {
          "actions": [
            "OUTPUT:1"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 7,
          "hard_timeout": 0,
          "byte_count": 518,
          "duration_nsec": 157000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "fe:3b:25:cc:04:97",
            "in_port": 3
          } 
          (作用:从3号口子来的,发给h1的包都从1号口子出去哈)
        },
        {
          "actions": [
            "OUTPUT:3"
          ],
          "idle_timeout": 0,
          "cookie": 0,
          "packet_count": 2,
          "hard_timeout": 0,
          "byte_count": 140,
          "duration_nsec": 92000000,
          "priority": 32768,
          "duration_sec": 985,
          "table_id": 0,
          "match": {
            "dl_dst": "ba:94:88:a1:55:63",
            "in_port": 2
          }
          (从2号口子来的,发给h4的都从3号口子出去哈)
        }
      ]
    }
    

    由上面,我们可以分析出:
    第一个交换机一个有3个端口
    端口1与h1直连
    端口2与h2直连
    端口3负责与另外一个交换机直连
    另一个交换机也是类似的作法  

    
    
  • 相关阅读:
    OnMeasureItem和OnDrawItem的区别和联系
    DockPanel 类
    C# 源码 AForge.NET
    ystem.Windows.Forms.SplitContainer : ContainerControl, ISupportInitialize
    System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....
    System.ComponentModel.Component : MarshalByRefObject, IComponent, IDisposable
    System.Windows.Forms.ListView : Control
    vs2013 密钥_
    系统封装 EasyBoot如何将WIN7安装版提取到光盘
    系统封装 ES3使用方法
  • 原文地址:https://www.cnblogs.com/manmanchanglu/p/11833982.html
Copyright © 2011-2022 走看看