• 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
    ')
        s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone')
        s3 = net.addSwitch('s3', cls=OVSKernelSwitch, failMode='standalone')
        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)
        h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    
        info( '*** Add links
    ')
        net.addLink(s2, h1)
        net.addLink(s3, h2)
        net.addLink(s2, r1)
        net.addLink(r1, s3)
    
        info( '*** Starting network
    ')
        net.build()
        info( '*** Starting controllers
    ')
        for controller in net.controllers:
            controller.start()
    
        info( '*** Starting switches
    ')
        net.get('s2').start([])
        net.get('s3').start([])
    
        info( '*** Post configure switches and hosts
    ')
        h1.cmd('ifconfig h1-eth0 10.0.0.1/24')
        h2.cmd('ifconfig h2-eth0 192.168.0.1/24')
        r1.cmd('ifconfig r1-eth0 10.0.0.2/24')
        r1.cmd('ifconfig r1-eth1 192.168.0.2/24')
        h1.cmd('route add -net 192.168.0.0/24 gw 10.0.0.2')
        h2.cmd('route add -net 10.0.0.0/24 gw 192.168.0.2')
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()
  • 相关阅读:
    洛谷 P2108 学英语
    洛谷 P1010 幂次方
    洛谷 P1101 单词方阵
    洛谷 P1217 [USACO1.5]回文质数 Prime Palindromes
    洛谷 P1553 数字反转(升级版)
    hdu_1348_Wall(凸包)
    hdu_1392_Surround the Trees(凸包)
    hdu_1115_Lifting the Stone(求多边形重心)
    Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
    hdu_1558_Segment set(并查集+计算几何)
  • 原文地址:https://www.cnblogs.com/iuyy/p/14025874.html
Copyright © 2020-2023  润新知