zoukankan      html  css  js  c++  java
  • mininet 三个路由器两个终端的仿真

    网络拓扑:

    仿真结果:

    python代码:

    #!/usr/bin/python
    
    from mininet.net import Mininet
    from mininet.node import Controller, RemoteController, OVSController
    from mininet.node import CPULimitedHost, Host, Node
    from mininet.node import OVSKernelSwitch, UserSwitch
    from mininet.node import IVSSwitch
    from mininet.cli import CLI
    from mininet.log import setLogLevel, info
    from mininet.link import TCLink, Intf
    from subprocess import call
    
    def myNetwork():
    
        net = Mininet( topo=None,
                       build=False,
                       ipBase='10.0.0.0/8')
    
        info( '*** Adding controller
    ' )
        info( '*** Add switches
    ')
        r3 = net.addHost('r3', cls=Node, ip='0.0.0.0')
        r3.cmd('sysctl -w net.ipv4.ip_forward=1')
        r1 = net.addHost('r1', cls=Node, ip='0.0.0.0')
        r1.cmd('sysctl -w net.ipv4.ip_forward=1')
        r2 = net.addHost('r2', cls=Node, ip='0.0.0.0')
        r2.cmd('sysctl -w net.ipv4.ip_forward=1')
    
        info( '*** Add hosts
    ')
        h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
        h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    
        info( '*** Add links
    ')
        net.addLink(h1, r1)
        net.addLink(r1, r2)
        net.addLink(r2, r3)
        net.addLink(r3, h2)
        
    
        info( '*** Starting network
    ')
        net.build()
        info( '*** Starting controllers
    ')
        for controller in net.controllers:
            controller.start()
    
        info( '*** Starting switches
    ')
    
        info( '*** Post configure switches and hosts
    ')
        h1.cmd('ifconfig h1-eth0 192.168.10.1/24')
    
        r1.cmd('ifconfig r1-eth0 192.168.10.2/24')
        r1.cmd('ifconfig r1-eth1 192.168.20.2/24')
    
        r2.cmd('ifconfig r2-eth0 192.168.20.1/24')
        r2.cmd('ifconfig r2-eth1 192.168.30.1/24')
    
        r3.cmd('ifconfig r3-eth0 192.168.30.2/24')
        r3.cmd('ifconfig r3-eth1 192.168.40.2/24')
    
        h2.cmd('ifconfig h2-eth0 192.168.40.1/24')
    
        h1.cmd('route add default gw 192.168.10.2')
        h2.cmd('route add default gw 192.168.40.2')
    
        r1.cmd('route add -net 192.168.30.0/24 gw 192.168.20.1')
        r1.cmd('route add -net 192.168.40.0/24 gw 192.168.20.1')
    
        r3.cmd('route add -net 192.168.10.0/24 gw 192.168.30.1')
        r3.cmd('route add -net 192.168.20.0/24 gw 192.168.30.1')
    
        r2.cmd('route add -net 192.168.10.0/24 gw 192.168.20.2')
        r2.cmd('route add -net 192.168.40.0/24 gw 192.168.30.2')
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()
     info( '*** Add links
    ')
        net.addLink(h1, r1)
        net.addLink(r1, r2)
        net.addLink(r2, r3)
        net.addLink(r3, h2)
    
    
    # 当节点比较多的时候,注意连线的顺序,它直接决定了对应xx-ethx位于节点左右的顺序!

     

  • 相关阅读:
    6-4.粗体标签
    [Unity3D] 如何实现点击按钮退出游戏
    [Unity3D] 载入游戏地图时背景图片随机切换 & 数字百分比进度条
    [Unity3D] 鼠标点击图片移动效果
    [3DMAX]如何将骨骼与模型绑定在一起(蒙皮) & 如何实现自动化人物模型蒙皮
    [Unity 3D]用鼠标滚轮实现镜头放大和缩放,并添加距离限制
    [Unity3D] 如何实现围绕旋转
    [Unity3D] 如何实现注视旋转
    Css 图片自适应
    Scss 定义内层class的简单写法
  • 原文地址:https://www.cnblogs.com/iuyy/p/14027117.html
Copyright © 2011-2022 走看看