zoukankan      html  css  js  c++  java
  • SDN——实验脚本3-2:mymininet3.py

    参考脚本:mymininet3.py

    #!/usr/bin/python
     
    from mininet.net import Mininet
    from mininet.node import Node
    from mininet.link import TCLink
    from mininet.log import  setLogLevel, info
    from threading import Timer
    from mininet.util import quietRun
    from time import sleep
     
    def myNet(cname='controller', cargs='-v ptcp:'):
        "Create network from scratch using Open vSwitch."
        info( "*** Creating nodes
    " )
        controller = Node( 'c0', inNamespace=False )
        switch = Node( 's0', inNamespace=False )
        switch1 = Node( 's1', inNamespace=False )
        h0 = Node( 'h0' )
        h1 = Node( 'h1' )
        
        info( "*** Creating links
    " )
        linkopts0=dict(bw=100, delay='1ms', loss=0)
        linkopts1=dict(bw=100, delay='1ms', loss=0)
        link0=TCLink( h0, switch, **linkopts0)
        link1 = TCLink( switch, switch1, **linkopts1)     
        link2 = TCLink( h1, switch1, **linkopts0)
        #print link0.intf1, link0.intf2
        link0.intf2.setMAC("0:0:0:0:0:1")
        link1.intf1.setMAC("0:0:0:0:0:2")
        link1.intf2.setMAC("0:1:0:0:0:1") 
        link2.intf2.setMAC("0:1:0:0:0:2")
     
        info( "*** Configuring hosts
    " )
        h0.setIP( '192.168.123.1/24' )
        h1.setIP( '192.168.123.2/24' )
           
        info( "*** Starting network using Open vSwitch
    " )
        switch.cmd( 'ovs-vsctl del-br dp0' )
        switch.cmd( 'ovs-vsctl add-br dp0' )
        switch1.cmd( 'ovs-vsctl del-br dp1' )
        switch1.cmd( 'ovs-vsctl add-br dp1' )
     
        controller.cmd( cname + ' ' + cargs + '&' )     
        for intf in switch.intfs.values():
            print intf
            print switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
        for intf in switch1.intfs.values():
            print intf
            print switch1.cmd( 'ovs-vsctl add-port dp1 %s' % intf )
       
        # Note: controller and switch are in root namespace, and we
        # can connect via loopback interface
        switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
        switch1.cmd( 'ovs-vsctl set-controller dp1 tcp:127.0.0.1:6633' )
      
        info( '*** Waiting for switch to connect to controller' )
        while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
            sleep( 1 )
            info( '.' )
        info( '
    ' )
     
        #info( "*** Running test
    " )
        h0.cmdPrint( 'ping -Q 0x64 -c 20 ' + h1.IP() )
        
        sleep( 1 ) 
        info( "*** Stopping network
    " )
        controller.cmd( 'kill %' + cname )
        switch.cmd( 'ovs-vsctl del-br dp0' )
        switch.deleteIntfs()
        switch1.cmd( 'ovs-vsctl del-br dp1' )
        switch1.deleteIntfs()
        info( '
    ' )
     
    if __name__ == '__main__':
        setLogLevel( 'info' )
        info( '*** Scratch network demo (kernel datapath)
    ' )
        Mininet.init()
        myNet()
    
  • 相关阅读:
    java框架---->mybatis的使用(一)
    java基础---->数组的基础使用(二)
    python爬虫---->github上python的项目
    java基础---->git的使用(一)
    spring基础---->请求与响应的参数(一)
    织梦DEDECMS网站后台安全检测提示 加一个开关
    MySql的join(连接)查询 (三表 left join 写法)
    html只允许输入的数据校验,只允许输入字母汉字数字等
    js控制只允许输入数字
    DEDECMS里面DEDE函数解析
  • 原文地址:https://www.cnblogs.com/lance-haha/p/13686303.html
Copyright © 2011-2022 走看看