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
    ')
        r1 = net.addHost('r1', cls=Node, ip='0.0.0.0')
        r1.cmd('sysctl -w net.ipv4.ip_forward=1')
    
        info( '*** Add hosts
    ')
        h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
        h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
        h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
        h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    
        info( '*** Add links
    ')
        
        net.addLink(r1, h1)
        net.addLink(r1, h2)
        net.addLink(r1, h3)
        net.addLink(r1, h4)
    
        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')
        h2.cmd('ifconfig h2-eth0 192.168.20.1/24')
        h3.cmd('ifconfig h3-eth0 192.168.30.1/24')
        h4.cmd('ifconfig h4-eth0 192.168.40.1/24')
    
        r1.cmd('ifconfig r1-eth0 192.168.10.2/24')
        r1.cmd('ifconfig r1-eth1 192.168.20.2/24')
        r1.cmd('ifconfig r1-eth2 192.168.30.2/24')
        r1.cmd('ifconfig r1-eth3 192.168.40.2/24')
    
        h1.cmd('route add default gw 192.168.10.2')
        h2.cmd('route add default gw 192.168.20.2')
        h3.cmd('route add default gw 192.168.30.2')
        h4.cmd('route add default gw 192.168.40.2')
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()
  • 相关阅读:
    BZOJ 1907: 树的路径覆盖
    BZOJ 1295: [SCOI2009]最长距离
    BZOJ 1303: [CQOI2009]中位数图
    BZOJ 1468: Tree
    BZOJ 3784: 树上的路径
    BZOJ 2006: [NOI2010]超级钢琴
    BZOJ 1831: [AHOI2008]逆序对
    BZOJ 2521: [Shoi2010]最小生成树
    HDU 6685 Rikka with Coin (枚举 思维)
    HDU 6659 Acesrc and Good Numbers (数学 思维)
  • 原文地址:https://www.cnblogs.com/iuyy/p/14027286.html
Copyright © 2011-2022 走看看