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')
        r2 = net.addHost('r2', cls=Node, ip='0.0.0.0')
        r2.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')
        r3 = net.addHost('r3', cls=Node, ip='0.0.0.0')
        r3.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(h1, r1)
        net.addLink(h1, r2)
        net.addLink(r1, r3)
        net.addLink(r2, r3)
        net.addLink(r3, r4)
        net.addLink(r4, 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')
        h1.cmd('ifconfig h1-eth1 192.168.16.1/24')
    
        r1.cmd('ifconfig r1-eth0 192.168.10.2/24')
        r1.cmd('ifconfig r1-eth1 192.168.20.1/24')
    
        r2.cmd('ifconfig r2-eth0 192.168.16.2/24')
        r2.cmd('ifconfig r2-eth1 192.168.30.1/24')
    
        r3.cmd('ifconfig r3-eth0 192.168.20.2/24')
        r3.cmd('ifconfig r3-eth1 192.168.30.2/24')
    
        r3.cmd('ifconfig r3-eth2 192.168.100.2/24')
    
        r4.cmd('ifconfig r4-eth0 192.168.100.1/24')
        r4.cmd('ifconfig r4-eth1 192.168.200.1/24')
    
        h2.cmd('ifconfig h2-eth0 192.168.200.2/24')
    
    
        h1.cmd("ip route add 192.168.10.1/24 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.16.1/24 dev h1-eth1 table 521")
        h1.cmd("ip route add default via 192.168.16.2 dev h1-eth1 table 521")
    
        #h1.cmd("ip route add default gw 192.168.10.2  dev h1-eth0")
    
        h1.cmd("ip rule add from 192.168.10.1 table 520")
        h1.cmd("ip rule add from 192.168.16.1 table 521")
    
        r1.cmd("ip route add default via 192.168.20.2 dev r1-eth1")
        r2.cmd("ip route add default via 192.168.30.2 dev r2-eth1")
    
    
        r3.cmd("ip route add 192.168.10.0/24 via 192.168.20.1 dev r3-eth0")
        r3.cmd("ip route add 192.168.16.0/24 via 192.168.30.1 dev r3-eth1")
    
        r3.cmd("ip route add 192.168.200.0/24 via 192.168.100.1 dev r3-eth2")
    
    
        r4.cmd("ip route add default via 192.168.100.2 dev r4-eth0")
    
        h2.cmd("ip route add default via 192.168.200.1 dev h2-eth0")
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()
  • 相关阅读:
    js全局函数
    几个数拼接生成最大数(java实现)
    数独求解算法(回溯法和唯一解法)java实现
    32位机和64位机下面各类型sizeof的大小
    【经典算法】——KMP,深入讲解next数组的求解
    java 初始化及执行顺序
    CentOS7用yum安装、配置MariaDB 10
    centos7 删除mysql
    Linux下配置两个或多个Tomcat启动
    Linux平台上搭建apache+tomcat负载均衡集群[一台服务器多tomcat集群模式]
  • 原文地址:https://www.cnblogs.com/iuyy/p/14042828.html
Copyright © 2011-2022 走看看