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
    ')
        s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone')
    
        info( '*** Add hosts
    ')
        h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute='via 10.0.0.1')
        h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute='via 10.0.0.2')
    
        info( '*** Add links
    ')
        h1s1 = {'bw':100,'delay':'20ms','loss':2}
        net.addLink(h1, s1, cls=TCLink , **h1s1)
        s1h2 = {'bw':100,'delay':'30ms','loss':3}
        net.addLink(s1, h2, cls=TCLink , **s1h2)
    
        info( '*** Starting network
    ')
        net.build()
        info( '*** Starting controllers
    ')
        for controller in net.controllers:
            controller.start()
    
        info( '*** Starting switches
    ')
        net.get('s1').start([])
    
        info( '*** Post configure switches and hosts
    ')
    
        CLI(net)
        net.stop()
    
    if __name__ == '__main__':
        setLogLevel( 'info' )
        myNetwork()

    运行:

    # 运行脚本
    sudo python oneswitch.py
    # 打开终端
    xterm h1 h2
    # 退出
    quit

  • 相关阅读:
    并发编程-操作系统简史,多道技术
    python下的excel表格处理 内含面试题
    epoll模型的探索与实践
    nginx搭建静态网站
    面向对象基础
    python+Django 下JWT的使用
    linux的history命令
    携程apollo配置中心Quick Start
    redis哨兵
    redis的主从复制
  • 原文地址:https://www.cnblogs.com/iuyy/p/14025459.html
Copyright © 2011-2022 走看看