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')
        r4 = net.addHost('r4', cls=Node, ip='0.0.0.0')
        r4.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')
        r6 = net.addHost('r6', cls=Node, ip='0.0.0.0')
        r6.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')
        r5 = net.addHost('r5', cls=Node, ip='0.0.0.0')
        r5.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(h1, r2)
        net.addLink(r1, r3)
        net.addLink(r2, r3)
        net.addLink(r3, r4)
        net.addLink(r4, r5)
        net.addLink(r4, r6)
        net.addLink(r5, h2)
        net.addLink(r6, h2)
    
        info( '*** Starting network
    ')
        net.build()
        info( '*** Starting controllers
    ')
        for controller in net.controllers:
            controller.start()
    
        info( '*** Starting switches
    ')
        h1.cmd('ifconfig h1-eth0 192.168.10.1/24')
        h1.cmd('ifconfig h1-eth1 192.168.20.1/24')
    
        r1.cmd('ifconfig r1-eth0 192.168.10.2/24')
        r1.cmd('ifconfig r1-eth1 192.168.30.1/24')
    
        r2.cmd('ifconfig r2-eth0 192.168.20.2/24')
        r2.cmd('ifconfig r2-eth1 192.168.40.1/24')
    
        r3.cmd('ifconfig r3-eth0 192.168.30.2/24')
        r3.cmd('ifconfig r3-eth1 192.168.40.2/24')
        r3.cmd('ifconfig r3-eth2 192.168.50.2/24')
    
        r4.cmd('ifconfig r4-eth0 192.168.50.1/24')
        r4.cmd('ifconfig r4-eth1 192.168.60.1/24')
        r4.cmd('ifconfig r4-eth2 192.168.70.1/24')
    
        r5.cmd('ifconfig r5-eth0 192.168.60.2/24')
        r5.cmd('ifconfig r5-eth1 192.168.80.2/24')
        
        r6.cmd('ifconfig r6-eth0 192.168.70.2/24')
        r6.cmd('ifconfig r6-eth1 192.168.90.2/24')
        
        h2.cmd('ifconfig h2-eth0 192.168.80.1/24')
        h2.cmd('ifconfig h2-eth1 192.168.90.1/24')
    
    
        h1.cmd('ip route add 192.168.10.0/24 via 192.168.10.2 dev h1-eth0 table 520')
        h1.cmd('ip route add default via 192.168.10.2 dev h1-eth0 table 520')
    
        h1.cmd('ip route add 192.168.20.0/24 via 192.168.20.2 dev h1-eth1 table 521')
        h1.cmd('ip route add default via 192.168.20.2 dev h1-eth1 table 521')
    
        h1.cmd('ip rule add from 192.168.10.1 table 520')
        h1.cmd('ip rule add from 192.168.20.1 table 521')
    
    
        r1.cmd('ip route add default via 192.168.30.2')
        r2.cmd('ip route add default via 192.168.40.2')
    
        r3.cmd('ip route add 192.168.10.0/24 via 192.168.30.1 dev r3-eth0')
        r3.cmd('ip route add 192.168.20.0/24 via 192.168.40.1 dev r3-eth1')
        r3.cmd('ip route add default via 192.168.50.1 dev r3-eth2')
    
    
        r4.cmd('ip route add 192.168.80.0/24 via 192.168.60.2 dev r4-eth1')
        r4.cmd('ip route add 192.168.90.0/24 via 192.168.70.2 dev r4-eth2')
        r4.cmd('ip route add default via 192.168.50.2 dev r4-eth0')
    
    
        r5.cmd('ip route add default via 192.168.60.1')
        r6.cmd('ip route add default via 192.168.70.1')
    
        h2.cmd('ip route add 192.168.80.0/24 via 192.168.80.2 dev h2-eth0 table 510')
        h2.cmd('ip route add default via 192.168.80.2 dev h2-eth0 table 510')
    
        h2.cmd('ip route add 192.168.90.0/24 via 192.168.90.2 dev h2-eth1 table 512')
        h2.cmd('ip route add default via 192.168.90.2 dev h2-eth1 table 512')
    
        h2.cmd('ip rule add from 192.168.80.1 table 510')
        h2.cmd('ip rule add from 192.168.90.1 table 512')
    
    
    
        info( '*** Post configure switches and hosts
    ')
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()
  • 相关阅读:
    一个网站需求说明书的示例
    产品设计与PRD介绍
    研发效能度量案例
    项目管理过程流程图
    变量 $cfg['TempDir'] (./tmp/)无法访问。phpMyAdmin无法缓存模板文件,所以会运行缓慢。
    wordpress函数大全列表整理
    PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
    通过写脚本的方式自动获取JVM内的进程堆栈信息等内容
    简单定位占用最高CPU的java进程信息
    使用linux上面powershell安装vm powercli 连接vcenter 通过计划任务自动创建部分虚拟机的快照以及自动清理过期快照的办法
  • 原文地址:https://www.cnblogs.com/iuyy/p/14043145.html
Copyright © 2011-2022 走看看