Esempio n. 1
0
def myNet():
    "Create network from scratch using Open vSwitch."
 
    info( "*** Creating nodes\n" )
    switch0 = Node( 's0', inNamespace=False )
 
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    Link( h0, switch0)
    Link( h1, switch0)
    Link( h2, switch0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
 
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' )
  
    print switch0.cmd(r'ovs-vsctl show')
 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' )
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' )
  
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    info( '\n' )
Esempio n. 2
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch0 = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    Link(h0, switch0)
    Link(h1, switch0)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.cmd('ovs-vsctl add-br dp0')

    for intf in switch0.intfs.values():
        print intf
        print switch0.cmd('ovs-vsctl add-port dp0 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    switch0.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=1 actions=output:2\"')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=2 actions=output:1\"')

    info('*** Waiting for switch to connect to controller')
    while 'is_connected' not in quietRun('ovs-vsctl show'):
        sleep(1)
        info('.')
    info('\n')

    info("*** Running test\n")
    h0.cmdPrint('ping -c3 ' + h1.IP())
    h1.cmdPrint('ping -c3 ' + h0.IP())

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.deleteIntfs()
    info('\n')
Esempio n. 3
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )
 
    info( "*** Creating links\n" )
    linkopts0=dict(bw=100, delay='1ms', loss=0)
    TCLink( h0, switch, **linkopts0)
    TCLink( h1, switch, **linkopts0)
    TCLink( h2, switch, **linkopts0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    h2.setIP( '192.168.123.3/24' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.cmd( 'ovs-vsctl add-br dp0' )
 
    controller.cmd( cname + ' ' + cargs + '&' )    
    for intf in switch.intfs.values():
        print intf
        print switch.cmd( 'ovs-vsctl add-port dp0 %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' )
   
    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )
 
    #info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -c 3 ' + h2.IP() )
    h2.cmdPrint( 'ping -c 3 ' + h1.IP() )
 
    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    info( '\n' )
def scratchNetUser(cname='controller', cargs='ptcp:'):
    "Create network from scratch using user switch."

    # It's not strictly necessary for the controller and switches
    # to be in separate namespaces. For performance, they probably
    # should be in the root namespace. However, it's interesting to
    # see how they could work even if they are in separate namespaces.

    info('*** Creating Network\n')
    controller = Node('c0')
    switch = Node('s0')
    h0 = Node('h0')
    h1 = Node('h1')
    cintf, sintf = createLink(controller, switch)
    h0intf, sintf1 = createLink(h0, switch)
    h1intf, sintf2 = createLink(h1, switch)

    info('*** Configuring control network\n')
    controller.setIP(cintf, '10.0.123.1', 24)
    switch.setIP(sintf, '10.0.123.2', 24)

    info('*** Configuring hosts\n')
    h0.setIP(h0intf, '192.168.123.1', 24)
    h1.setIP(h1intf, '192.168.123.2', 24)

    info('*** Network state:\n')
    for node in controller, switch, h0, h1:
        info(str(node) + '\n')

    info('*** Starting controller and user datapath\n')
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ifconfig lo 127.0.0.1')
    intfs = [sintf1, sintf2]
    switch.cmd('ofdatapath -i ' + ','.join(intfs) + ' ptcp: &')
    switch.cmd('ofprotocol tcp:' + controller.IP() + ' tcp:localhost &')

    info('*** Running test\n')
    h0.cmdPrint('ping -c1 ' + h1.IP())

    info('*** Stopping network\n')
    controller.cmd('kill %' + cname)
    switch.cmd('kill %ofdatapath')
    switch.cmd('kill %ofprotocol')
    switch.deleteIntfs()
    info('\n')
Esempio n. 5
0
def scratchNetUser( cname='controller', cargs='ptcp:' ):
    "Create network from scratch using user switch."

    # It's not strictly necessary for the controller and switches
    # to be in separate namespaces. For performance, they probably
    # should be in the root namespace. However, it's interesting to
    # see how they could work even if they are in separate namespaces.

    info( '*** Creating Network\n' )
    controller = Node( 'c0' )
    switch = Node( 's0')
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    cintf, sintf = createLink( controller, switch )
    h0intf, sintf1 = createLink( h0, switch )
    h1intf, sintf2 = createLink( h1, switch )

    info( '*** Configuring control network\n' )
    controller.setIP( cintf, '10.0.123.1', 24 )
    switch.setIP( sintf, '10.0.123.2', 24 )

    info( '*** Configuring hosts\n' )
    h0.setIP( h0intf, '192.168.123.1', 24 )
    h1.setIP( h1intf, '192.168.123.2', 24 )

    info( '*** Network state:\n' )
    for node in controller, switch, h0, h1:
        info( str( node ) + '\n' )

    info( '*** Starting controller and user datapath\n' )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ifconfig lo 127.0.0.1' )
    intfs = [ sintf1, sintf2 ]
    switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
    switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )

    info( '*** Running test\n' )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( '*** Stopping network\n' )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'kill %ofdatapath' )
    switch.cmd( 'kill %ofprotocol' )
    switch.deleteIntfs()
    info( '\n' )
def scratchNet( cname='controller', cargs='-v ptcp:' ):
    "Create network from scratch using Open vSwitch."

    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )

    info( "*** Creating links\n" )
    Link( h0, switch )
    Link( h1, switch )

    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )

    info( "*** Starting network using Open vSwitch\n" )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.cmd( 'ovs-vsctl add-br dp0' )
    for intf in switch.intfs.values():
        print switch.cmd( 'ovs-vsctl add-port dp0 %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' )

    info( '*** Waiting for switch to connect to controller' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( '\n' )

    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-vsctl del-br dp0' )
    switch.deleteIntfs()
    info( '\n' )
Esempio n. 7
0
def scratchNet(cname="controller", cargs="-v ptcp:"):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node("c0", inNamespace=False)
    switch = Node("s0", inNamespace=False)
    h0 = Node("h0")
    h1 = Node("h1")

    info("*** Creating links\n")
    Link(h0, switch)
    Link(h1, switch)

    info("*** Configuring hosts\n")
    h0.setIP("192.168.123.1/24")
    h1.setIP("192.168.123.2/24")
    info(str(h0) + "\n")
    info(str(h1) + "\n")

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + " " + cargs + "&")
    switch.cmd("ovs-vsctl del-br dp0")
    switch.cmd("ovs-vsctl add-br dp0")
    for intf in switch.intfs.values():
        print(switch.cmd("ovs-vsctl add-port dp0 %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")

    info("*** Waiting for switch to connect to controller")
    while "is_connected" not in quietRun("ovs-vsctl show"):
        sleep(1)
        info(".")
    info("\n")

    info("*** Running test\n")
    h0.cmdPrint("ping -c1 " + h1.IP())

    info("*** Stopping network\n")
    controller.cmd("kill %" + cname)
    switch.cmd("ovs-vsctl del-br dp0")
    switch.deleteIntfs()
    info("\n")
Esempio n. 8
0
def scratchNet( cname='controller', cargs='ptcp:' ):
    "Create network from scratch using kernel switch."

    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    switch = Node( 's0', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )

    info( "*** Creating links\n" )
    createLink( node1=h0, node2=switch, port1=0, port2=0 )
    createLink( node1=h1, node2=switch, port1=0, port2=1 )

    info( "*** Configuring hosts\n" )
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', 24 )
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )

    info( "*** Starting network using Open vSwitch kernel datapath\n" )
    controller.cmd( cname + ' ' + cargs + '&' )
    switch.cmd( 'ovs-dpctl del-dp dp0' )
    switch.cmd( 'ovs-dpctl add-dp dp0' )
    for intf in switch.intfs.values():
        print switch.cmd( 'ovs-dpctl add-if dp0 ' + intf )
    print switch.cmd( 'ovs-openflowd dp0 tcp:127.0.0.1 &' )

    info( "*** Running test\n" )
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )

    info( "*** Stopping network\n" )
    controller.cmd( 'kill %' + cname )
    switch.cmd( 'ovs-dpctl del-dp dp0' )
    switch.cmd( 'kill %ovs-openflowd' )
    switch.deleteIntfs()
    info( '\n' )
Esempio n. 9
0
def scratchNet(cname='controller', cargs='ptcp:'):
    "Create network from scratch using kernel switch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    createLink(node1=h0, node2=switch, port1=0, port2=0)
    createLink(node1=h1, node2=switch, port1=0, port2=1)

    info("*** Configuring hosts\n")
    h0.setIP(h0.intfs[0], '192.168.123.1', 24)
    h1.setIP(h1.intfs[0], '192.168.123.2', 24)
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch kernel datapath\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch.cmd('ovs-dpctl del-dp dp0')
    switch.cmd('ovs-dpctl add-dp dp0')
    for intf in switch.intfs.values():
        print switch.cmd('ovs-dpctl add-if dp0 ' + intf)
    print switch.cmd('ovs-openflowd dp0 tcp:127.0.0.1 &')

    info("*** Running test\n")
    h0.cmdPrint('ping -c1 ' + h1.IP())

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch.cmd('ovs-dpctl del-dp dp0')
    switch.cmd('kill %ovs-openflowd')
    switch.deleteIntfs()
    info('\n')
Esempio n. 10
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info( "*** Creating nodes\n" )
    controller = Node( 'c0', inNamespace=False )
    s0 = Node( 's0', inNamespace=False )
    s1 = Node( 's1', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
    h2 = Node( 'h2' )

    info( "*** Creating links..." )
    linkopts0=dict(bw=10, delay='1ms', loss=0)
    info( '\nLink h0-s0 | ' )
    TCLink( h0, s0, **linkopts0)
    info( '\nLink h1-s0 | ' )
    TCLink( h1, s0, **linkopts0)
    info( '\nLink s0-s1 | ' )
    TCLink( s0, s1, **linkopts0)
    info( '\nLink s1-h2 | ' )
    TCLink( s1, h2, **linkopts0)

    info( '\n' )
    info( "*** Configuring hosts...\n" )
    h0.setIP( '192.168.1.1/24' )
    h1.setIP( '192.168.1.2/24' )
    h2.setIP( '192.168.1.3/24' )

    info( "*** Starting network using Open vSwitch...\n" )
    s0.cmd( 'ovs-vsctl del-br s0' )
    s0.cmd( 'ovs-vsctl add-br s0' )
    s1.cmd( 'ovs-vsctl del-br s1' )
    s1.cmd( 'ovs-vsctl add-br s1' )

    controller.cmd( cname + ' ' + cargs + '&' )          
    for intf in s0.intfs.values():
        print intf
        print s0.cmd( 'ovs-vsctl add-port s0 %s' % intf )
   
    for intf in s1.intfs.values():
        print intf
        print s1.cmd( 'ovs-vsctl add-port s1 %s' % intf )
  
    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    info( '*** Connect to controller with tcp port...' )
    s0.cmd( 'ovs-vsctl set-controller s0 tcp:127.0.0.1:6633' )
    s1.cmd( 'ovs-vsctl set-controller s0 tcp:127.0.0.1:6633' )
 
    info( '\n' )  
    info( '*** Waiting for switch to connect to controller..' )
    while 'is_connected' not in quietRun( 'ovs-vsctl show' ):
        sleep( 1 )
        info( '.' )
    info( 'connected!\n' )

    #print s0.cmd('ovs-ofctl show dp0')

    info( "*** Running test...\n" )
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )
    h0.cmdPrint( 'ping -c 2 ' + h2.IP() )
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )
    h1.cmdPrint( 'ping -c 2 ' + h2.IP() )
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )

    info( '*** Starting iperf Server...\n' )
    h2.cmdPrint('iperf -s -i 1 > bandwidth_result &')

    info( '*** Original link bandwidth testing...\n' )
    print "iperf: h0--s0--s1--h2"
    h0.cmdPrint('iperf -c 192.168.1.3 -t 15')
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )
    print "iperf: h1--s0--s1--h2"
    h1.cmdPrint('iperf -c 192.168.1.3 -t 15')
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )

    print "!!! Limiting the bandwidth for flow entry [h0] -> [h2]"
    s0.cmdPrint('ethtool -K s0-eth2 gro off')
    s0.cmdPrint('tc qdisc del dev s0-eth2 root')
    s0.cmdPrint('tc qdisc add dev s0-eth2 root handle 1: cbq avpkt 1000 bandwidth 10Mbit')
    s0.cmdPrint('tc class add dev s0-eth2 parent 1: classid 1:1 cbq rate 512kbit allot 1500 prio 5 bounded isolated')
    s0.cmdPrint('tc filter add dev s0-eth2 parent 1: protocol ip prio 16 u32 match ip src 192.168.1.1 flowid 1:1')
    s0.cmdPrint('tc qdisc add dev s0-eth2 parent 1:1 sfq perturb 10')

    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' )
    info( '\n*** Limited link bandwidth testing...\n' )
    print "iperf: h0--s0--s1--h2"
    h0.cmdPrint('iperf -c 192.168.1.3 -t 15')
    info( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' )
    print "iperf: h1--s0--s1--h2" 
    h1.cmdPrint('iperf -c 192.168.1.3 -t 15')

    info( '*** Done...\n' )
    info( "*** Stopping network...\n" )
    controller.cmd( 'kill %' + cname )
    s0.cmd( 'ovs-vsctl del-br s0' )
    s0.deleteIntfs()
    s1.cmd( 'ovs-vsctl del-br s1' )
    s1.deleteIntfs()
    info( '\n' )
Esempio n. 11
0
def myNet():
    "Create network from scratch using Open vSwitch."
    info( "*** Creating nodes\n" )
    switch0 = Node( 's0', inNamespace=False )
    switch1 = Node( 's1', inNamespace=False )
    switch2 = Node( 's2', inNamespace=False )
    switch3 = Node( 's3', inNamespace=False )
    switch4 = Node( 's4', inNamespace=False )
    h0 = Node( 'h0' )
    h1 = Node( 'h1' )
 
    info( "*** Creating links\n" )
    linkopts0=dict(bw=100, delay='1ms', loss=0)
    linkopts1=dict(bw=1, delay='100ms', loss=0)
    linkopts2=dict(bw=10, delay='50ms', loss=0)
    linkopts3=dict(bw=100, delay='1ms', loss=0)
    link1=TCLink( h0, switch0, **linkopts0)
    TCLink( switch0, switch1, **linkopts0)
    TCLink( switch0, switch2, **linkopts0)
    TCLink( switch0, switch3, **linkopts0)
    TCLink( switch1, switch4,**linkopts1)
    TCLink( switch2, switch4,**linkopts2)
    TCLink( switch3, switch4,**linkopts3)
    link2=TCLink( h1, switch4, **linkopts0)
 
    info( "*** Configuring hosts\n" )
    h0.setIP( '192.168.123.1/24' )
    h1.setIP( '192.168.123.2/24' )
    info( str( h0 ) + '\n' )
    info( str( h1 ) + '\n' )
       
    info( "*** Starting network using Open vSwitch\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.cmd( 'ovs-vsctl add-br dp0' )
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.cmd( 'ovs-vsctl add-br dp1' )
    switch2.cmd( 'ovs-vsctl del-br dp2' )
    switch2.cmd( 'ovs-vsctl add-br dp2' )
    switch3.cmd( 'ovs-vsctl del-br dp3' )
    switch3.cmd( 'ovs-vsctl add-br dp3' )
    switch4.cmd( 'ovs-vsctl del-br dp4' )
    switch4.cmd( 'ovs-vsctl add-br dp4' )
 
    for intf in switch0.intfs.values():
        print intf
        print switch0.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 )
 
    for intf in switch2.intfs.values():
        print intf
        print switch2.cmd( 'ovs-vsctl add-port dp2 %s' % intf )
 
    for intf in switch3.intfs.values():
        print intf
        print switch3.cmd( 'ovs-vsctl add-port dp3 %s' % intf )
 
    for intf in switch4.intfs.values():
        print intf
        print switch4.cmd( 'ovs-vsctl add-port dp4 %s' % intf )
   
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=flood' )
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=output:2' ) 
    print switch1.cmd(r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=1,actions=output:2' )
    print switch2.cmd(r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=1,actions=output:2' )    
    print switch3.cmd(r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=2,actions=output:1' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=1,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=2,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=3,actions=output:4' )
    print switch4.cmd(r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=4,actions=output:3' )
   
    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:4')
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x10,actions=output:2') 
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x20,actions=output:3')
    print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x30,actions=output:4') 
    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1')
 
    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    def cDelay1():
        h1.cmdPrint('ethtool -K h1-eth0 gro off')
        h1.cmdPrint('tc qdisc del dev h1-eth0 root')
        h1.cmdPrint('tc qdisc add dev h1-eth0 root handle 10: netem delay 100ms')
 
    def hello(a, b='4'):
       print a
       print b
 
    #t=Timer(3.0, hello, args=('aaaa',),kwargs={'b':'7'})
    t=Timer(5.0, cDelay1)
    t.start()
 
    info( "*** Running test\n" )
    #h0.cmdPrint( 'ping -Q 0x10 -c 3 ' + h1.IP() )
    #h0.cmdPrint( 'ping -Q 0x20 -c 3 ' + h1.IP() )
    h0.cmdPrint( 'ping -Q 0x30 -c 10 ' + h1.IP() )
    #link2.intf1.config(delay='100ms')
    #h1.cmdPrint('ifconfig -a')
    #h1.cmdPrint('tc qdisc show dev h1-eth0')
    #h1.cmdPrint('ethtook -K h1-eth0 gro off')
    #h1.cmdPrint('tc qdisc del dev h1-eth0 root')
    #h1.cmdPrint('tc qdisc add dev h1-eth0 root handle 10: netem delay 100ms')
    #h1.cmdPrint('ifconfig -a')
    #h1.cmdPrint('tc qdisc show dev h1-eth0')
    #h1.cmdPrint('tc -s qdisc ls dev h1-eth0')
    #h0.cmdPrint( 'ping -Q 0x30 -c 5 ' + h1.IP() )
 
    #print switch0.cmd( 'ovs-ofctl show dp0' )    
    #print switch1.cmd( 'ovs-ofctl show dp1' )
    #print switch2.cmd( 'ovs-ofctl show dp2' )
    #print switch3.cmd( 'ovs-ofctl show dp3' )
    #print switch4.cmd( 'ovs-ofctl show dp4' )  
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )
 
    #print "Testing video transmission between h1 and h2"
    #h1.cmd('./myrtg_svc -u > myrd &')
    #h0.cmd('./mystg_svc -trace st 192.168.123.2')
 
    info( "*** Stopping network\n" )
    switch0.cmd( 'ovs-vsctl del-br dp0' )
    switch0.deleteIntfs()
    switch1.cmd( 'ovs-vsctl del-br dp1' )
    switch1.deleteIntfs()
    switch2.cmd( 'ovs-vsctl del-br dp2' )
    switch2.deleteIntfs()
    switch3.cmd( 'ovs-vsctl del-br dp3' )
    switch3.deleteIntfs()
    switch4.cmd( 'ovs-vsctl del-br dp4' )
    switch4.deleteIntfs()
    info( '\n' )
Esempio n. 12
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch = Node('s0', inNamespace=False)
    switch1 = Node('s1', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    linkopts0 = dict(bw=100, delay='1ms', loss=0)
    linkopts1 = dict(bw=100, delay='10ms', loss=0)
    link0 = TCLink(h0, switch, **linkopts0)
    #initially, the delay from switch to switch1 is 10ms
    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\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    h0.setMAC("a:a:a:a:a:a")
    h1.setMAC("8:8:8:8:8:8")

    info("*** Starting network using Open vSwitch\n")
    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('\n')

    def cDelay1():
        switch.cmdPrint('ethtool -K s0-eth1 gro off')
        switch.cmdPrint('tc qdisc del dev s0-eth1 root')
        switch.cmdPrint(
            'tc qdisc add dev s0-eth1 root handle 10: netem delay 50ms')
        switch1.cmdPrint('ethtool -K s1-eth0 gro off')
        switch1.cmdPrint('tc qdisc del dev s1-eth0 root')
        switch1.cmdPrint(
            'tc qdisc add dev s1-eth0 root handle 10: netem delay 50ms')

    def cDelay2():
        switch.cmdPrint('ethtool -K s0-eth1 gro off')
        switch.cmdPrint('tc qdisc del dev s0-eth1 root')
        switch.cmdPrint(
            'tc qdisc add dev s0-eth1 root handle 10: netem delay 200ms')
        switch1.cmdPrint('ethtool -K s1-eth0 gro off')
        switch1.cmdPrint('tc qdisc del dev s1-eth0 root')
        switch1.cmdPrint(
            'tc qdisc add dev s1-eth0 root handle 10: netem delay 200ms')

    # 15 seconds later, the delay from switch to switch 1 will change to 50ms
    t1 = Timer(15, cDelay1)
    t1.start()
    # 30 seconds later, the delay from switch to switch 1 will change to 200ms
    t2 = Timer(30, cDelay2)
    t2.start()

    #info( "*** Running test\n" )
    h0.cmdPrint('ping -i 1 -c 45 ' + h1.IP())
    sleep(1)
    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch.cmd('ovs-vsctl del-br dp0')
    switch.deleteIntfs()
    switch1.cmd('ovs-vsctl del-br dp1')
    switch1.deleteIntfs()
    info('\n')
Esempio n. 13
0
def myNet():
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    switch0 = Node('s0', inNamespace=False)
    switch1 = Node('s1', inNamespace=False)
    switch2 = Node('s2', inNamespace=False)
    switch3 = Node('s3', inNamespace=False)
    switch4 = Node('s4', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")
    linkopts0 = dict(bw=100, delay='1ms', loss=0)
    linkopts1 = dict(bw=1, delay='100ms', loss=0)
    linkopts2 = dict(bw=10, delay='50ms', loss=0)
    linkopts3 = dict(bw=100, delay='1ms', loss=0)
    TCLink(h0, switch0, **linkopts0)
    TCLink(switch0, switch1, **linkopts0)
    TCLink(switch0, switch2, **linkopts0)
    TCLink(switch0, switch3, **linkopts0)
    TCLink(switch1, switch4, **linkopts1)
    TCLink(switch2, switch4, **linkopts2)
    TCLink(switch3, switch4, **linkopts3)
    TCLink(h1, switch4, **linkopts0)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.cmd('ovs-vsctl add-br dp0')
    switch1.cmd('ovs-vsctl del-br dp1')
    switch1.cmd('ovs-vsctl add-br dp1')
    switch2.cmd('ovs-vsctl del-br dp2')
    switch2.cmd('ovs-vsctl add-br dp2')
    switch3.cmd('ovs-vsctl del-br dp3')
    switch3.cmd('ovs-vsctl add-br dp3')
    switch4.cmd('ovs-vsctl del-br dp4')
    switch4.cmd('ovs-vsctl add-br dp4')

    for intf in switch0.intfs.values():
        print intf
        print switch0.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)

    for intf in switch2.intfs.values():
        print intf
        print switch2.cmd('ovs-vsctl add-port dp2 %s' % intf)

    for intf in switch3.intfs.values():
        print intf
        print switch3.cmd('ovs-vsctl add-port dp3 %s' % intf)

    for intf in switch4.intfs.values():
        print intf
        print switch4.cmd('ovs-vsctl add-port dp4 %s' % intf)

    print switch1.cmd(
        r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=flood'
    )
    print switch1.cmd(
        r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=1,actions=output:2'
    )
    print switch1.cmd(
        r'ovs-ofctl add-flow dp1 idle_timeout=0,priority=1,in_port=2,actions=output:1'
    )
    print switch2.cmd(
        r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=1,actions=output:2'
    )
    print switch2.cmd(
        r'ovs-ofctl add-flow dp2 idle_timeout=0,priority=1,in_port=2,actions=output:1'
    )
    print switch3.cmd(
        r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=1,actions=output:2'
    )
    print switch3.cmd(
        r'ovs-ofctl add-flow dp3 idle_timeout=0,priority=1,in_port=2,actions=output:1'
    )
    print switch4.cmd(
        r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=1,actions=output:4'
    )
    print switch4.cmd(
        r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=2,actions=output:4'
    )
    print switch4.cmd(
        r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=3,actions=output:4'
    )
    print switch4.cmd(
        r'ovs-ofctl add-flow dp4 idle_timeout=0,priority=1,in_port=4,actions=output:3'
    )

    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:4')
    print switch0.cmd(
        r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x10,actions=output:2'
    )
    print switch0.cmd(
        r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x20,actions=output:3'
    )
    print switch0.cmd(
        r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,nw_tos=0x30,actions=output:4'
    )
    #print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1')

    #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &')
    #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &')
    info("*** Running test\n")
    h0.cmdPrint('ping -Q 0x10 -c 3 ' + h1.IP())
    h0.cmdPrint('ping -Q 0x20 -c 3 ' + h1.IP())
    h0.cmdPrint('ping -Q 0x30 -c 3 ' + h1.IP())
    #h1.cmdPrint('iperf -s -p 12345 -u &')
    #h0.cmdPrint('iperf -c ' + h1.IP() +' -u -b 10m -p 12345 -t 10 -i 1')

    #print switch0.cmd( 'ovs-ofctl show dp0' )
    #print switch1.cmd( 'ovs-ofctl show dp1' )
    #print switch2.cmd( 'ovs-ofctl show dp2' )
    #print switch3.cmd( 'ovs-ofctl show dp3' )
    #print switch4.cmd( 'ovs-ofctl show dp4' )
    #print switch0.cmd( 'ovs-ofctl dump-tables  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-ports   dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-flows  dp0' )
    #print switch0.cmd( 'ovs-ofctl dump-aggregate  dp0' )
    #print switch0.cmd( 'ovs-ofctl queue-stats dp0' )

    #print "Testing video transmission between h1 and h2"
    #h1.cmd('./myrtg_svc -u > myrd &')
    #h0.cmd('./mystg_svc -trace st 192.168.123.2')

    info("*** Stopping network\n")
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.deleteIntfs()
    switch1.cmd('ovs-vsctl del-br dp1')
    switch1.deleteIntfs()
    switch2.cmd('ovs-vsctl del-br dp2')
    switch2.deleteIntfs()
    switch3.cmd('ovs-vsctl del-br dp3')
    switch3.deleteIntfs()
    switch4.cmd('ovs-vsctl del-br dp4')
    switch4.deleteIntfs()
    info('\n')
Esempio n. 14
0
def myNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."
    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    s1 = Node('s1', inNamespace=False)
    s2 = Node('s2', inNamespace=False)
    s3 = Node('s3', inNamespace=False)
    s4 = Node('s4', inNamespace=False)
    s6 = Node('s6', inNamespace=False)
    s7 = Node('s7', inNamespace=False)
    h1 = Node('h1')
    h2 = Node('h2')
    h3 = Node('h3')
    h4 = Node('h4')
    h5 = Node('h5')
    h6 = Node('h6')
    h7 = Node('h7')
    h8 = Node('h8')
    server = Node('server')

    info("*** Creating links\n")
    linkopts0 = dict(bw=10, delay='1ms', loss=0)
    TCLink(s1, s2, **linkopts0)
    TCLink(s2, s3, **linkopts0)
    TCLink(s2, s4, **linkopts0)
    TCLink(s2, s6, **linkopts0)
    TCLink(s2, s7, **linkopts0)
    TCLink(s1, h3, **linkopts0)
    TCLink(s1, h4, **linkopts0)
    TCLink(s3, h1, **linkopts0)
    TCLink(s4, h7, **linkopts0)
    TCLink(s4, h8, **linkopts0)
    TCLink(s6, h5, **linkopts0)
    TCLink(s6, h6, **linkopts0)
    TCLink(s7, server, **linkopts0)

    info("*** Configuring hosts\n")
    h1.setIP('30.30.1.20/22')
    h2.setIP('30.30.1.21/22')
    h3.setIP('30.30.1.22/22')
    h4.setIP('30.30.1.23/22')
    h5.setIP('30.30.1.24/22')
    h6.setIP('30.30.1.25/22')
    h7.setIP('30.30.1.26/22')
    h8.setIP('30.30.1.27/22')
    server.setIP('30.30.1.28/22')
    h1.setMAC('00:00:00:43:92:01')
    h2.setMAC('00:00:00:43:92:02')
    h3.setMAC('00:00:00:43:92:03')
    h4.setMAC('00:00:00:43:92:04')
    h5.setMAC('00:00:00:43:92:05')
    h6.setMAC('00:00:00:43:92:06')
    h7.setMAC('00:00:00:43:92:07')
    h8.setMAC('00:00:00:43:92:08')
    server.setMAC('00:00:00:43:92:09')
    s1.setMAC('00:00:02:43:92:01')
    s2.setMAC('00:00:02:43:92:02')
    s3.setMAC('00:00:02:43:92:03')
    s4.setMAC('00:00:02:43:92:04')
    s6.setMAC('00:00:02:43:92:05')
    s7.setMAC('00:00:02:43:92:06')

    info("*** Starting network using Open vSwitch\n")

    s1.cmd('ovs-vsctl del-br dp1')
    s1.cmd('ovs-vsctl add-br dp1')
    s2.cmd('ovs-vsctl del-br dp2')
    s2.cmd('ovs-vsctl add-br dp2')
    s3.cmd('ovs-vsctl del-br dp3')
    s3.cmd('ovs-vsctl add-br dp3')
    s4.cmd('ovs-vsctl del-br dp4')
    s4.cmd('ovs-vsctl add-br dp4')
    s6.cmd('ovs-vsctl del-br dp6')
    s6.cmd('ovs-vsctl add-br dp6')
    s7.cmd('ovs-vsctl del-br dp7')
    s7.cmd('ovs-vsctl add-br dp7')

    controller.cmd(cname + ' ' + cargs + '&')
    for intf in s1.intfs.values():
        print intf
        print s1.cmd('ovs-vsctl add-port dp1 %s' % intf)

    for intf in s2.intfs.values():
        print intf
        print s2.cmd('ovs-vsctl add-port dp2 %s' % intf)

    for intf in s3.intfs.values():
        print intf
        print s3.cmd('ovs-vsctl add-port dp3 %s' % intf)

    for intf in s4.intfs.values():
        print intf
        print s4.cmd('ovs-vsctl add-port dp4 %s' % intf)

    for intf in s6.intfs.values():
        print intf
        print s6.cmd('ovs-vsctl add-port dp6 %s' % intf)

    for intf in s7.intfs.values():
        print intf
        print s7.cmd('ovs-vsctl add-port dp7 %s' % intf)

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    s1.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    s2.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    s3.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    s4.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    s6.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633')
    s7.cmd('ovs-vsctl set-controller dp0 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('\n')

    #print s0.cmd('ovs-ofctl show dp0')
    #info( "*** Running test\n" )
    h3.cmdPrint('ping -c 3 ' + h2.IP())
    h4.cmdPrint('ping -c 3 ' + h2.IP())
    h2.cmd('iperf -s &')
    h3.cmdPrint('iperf -c 30.30.1.23 -t 10')
    h4.cmdPrint('iperf -c 30.30.1.23 -t 10')
    s1.cmdPrint('ethtool -K s0-eth2 gro off')
    s1.cmdPrint('tc qdisc del dev s0-eth2 root')
    s1.cmdPrint(
        'tc qdisc add dev s0-eth2 root handle 1: cbq avpkt 1000 bandwidth 10Mbit rate 512kbit bounded isolated'
    )
    h3.cmdPrint('iperf -c 30.30.1.23 -t 10')
    h4.cmdPrint('iperf -c 30.30.1.23 -t 10')

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    s1.cmd('ovs-vsctl del-br dp1')
    s1.deleteIntfs()
    s2.cmd('ovs-vsctl del-br dp2')
    s2.deleteIntfs()
    info('\n')
Esempio n. 15
0
def netconfNet():
    "Create network from scratch using netconfd instance on each node."

    info("*** Creating nodes\n")
    h0 = Node('h0', inNamespace=True)
    h1 = Node('h1', inNamespace=True)
    b0 = Node('b0', inNamespace=False)
    b1 = Node('b1', inNamespace=False)

    ncproxy = Node('ncproxy', inNamespace=False)

    info("*** Creating links\n")
    b0.cmd("ip link del b0-eth0")
    b0.cmd("ip link del b0-eth1")
    b1.cmd("ip link del b1-eth0")
    b1.cmd("ip link del b1-eth1")
    Link(h0, b0, intfName2="b0-eth0")
    Link(b0, b1, intfName1="b0-eth1", intfName2="b1-eth0")
    Link(h1, b1, intfName2="b1-eth1")

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')
    info(str(b0) + '\n')
    info(str(b1) + '\n')

    info("*** Starting network\n")
    h0.cmd(
        '''INTERFACE_NAME_PREFIX=h0- ./run-netconfd --module=ietf-interfaces --no-startup --port=8832 --ncxserver-sockname=/tmp/ncxserver.8832.sock --superuser=${USER} &'''
    )
    ncproxy.cmd(
        '''./run-sshd-for-netconfd --port=8832 --ncxserver-sockname=/tmp/ncxserver.8832.sock &'''
    )
    h1.cmd(
        '''INTERFACE_NAME_PREFIX=h1- ./run-netconfd --module=ietf-interfaces --no-startup --port=8833 --ncxserver-sockname=/tmp/ncxserver.8833.sock --superuser=${USER} &'''
    )
    ncproxy.cmd(
        '''./run-sshd-for-netconfd --port=8833 --ncxserver-sockname=/tmp/ncxserver.8833.sock &'''
    )

    #bridge b0
    b0.cmd(
        '''VCONN_ARG=ptcp:16636 ./run-netconfd --module=ietf-network-bridge-openflow --no-startup --superuser=${USER} --port=8830 --ncxserver-sockname=/tmp/ncxserver.8830.sock &'''
    )
    b0.cmd('ovs-vsctl del-br dp0')
    b0.cmd('ovs-vsctl add-br dp0')
    for intf in b0.intfs.values():
        print "Setting: " + str(intf)
        print b0.cmd('ovs-vsctl add-port dp0 %s' % intf)
        print b0.cmd('ifconfig -a')

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    b0.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:16636')

    info('*** Waiting for switch to connect to controller')
    while 'is_connected' not in quietRun('ovs-vsctl show'):
        sleep(1)
        info('.')
    info('\n')

    #bridge b1
    b1.cmd(
        '''VCONN_ARG=ptcp:16635 ./run-netconfd --module=ietf-network-bridge-openflow --no-startup --superuser=${USER} --port=8831 --ncxserver-sockname=/tmp/ncxserver.8831.sock &'''
    )
    b1.cmd('ovs-vsctl del-br dp1')
    b1.cmd('ovs-vsctl add-br dp1')
    for intf in b1.intfs.values():
        print "Setting: " + str(intf)
        print b1.cmd('ovs-vsctl add-port dp1 %s' % intf)
        print b1.cmd('ifconfig -a')

    # Note: controller and switch are in root namespace, and we
    # can connect via loopback interface
    b1.cmd('ovs-vsctl set-controller dp1 tcp:127.0.0.1:16635')

    sleep(10)
    raw_input("Press Enter to continue...")

    tree = etree.parse("topology.xml")
    network = tree.xpath('/nc:config/nd:networks/nd:network',
                         namespaces=namespaces)[0]

    conns = tntapi.network_connect(network)
    yconns = tntapi.network_connect_yangrpc(network)
    mylinks = tntapi.parse_network_links(network)
    print("Done")

    state_before = tntapi.network_get_state(network, conns)
    info("*** Running test\n")

    #create flows configuration
    yangcli_script = """
merge /bridge/ports/port -- name=b0-eth0
merge /interfaces/interface -- name=b0-eth0 type=ethernetCsmacd port-name=b0-eth0
merge /bridge/ports/port -- name=b0-eth1
merge /interfaces/interface -- name=b0-eth1 type=ethernetCsmacd port-name=b0-eth1
create /flows/flow[id='h0-to-h1'] -- match/in-port=b0-eth0 actions/action[order='0']/output-action/out-port=b0-eth1
create /flows/flow[id='h1-to-h0'] -- match/in-port=b0-eth1 actions/action[order='0']/output-action/out-port=b0-eth0
"""
    result = tntapi.yangcli_ok_script(yconns["b0"], yangcli_script)

    yangcli_script = """
merge /bridge/ports/port -- name=b1-eth0
merge /interfaces/interface -- name=b1-eth0 type=ethernetCsmacd port-name=b1-eth0
merge /bridge/ports/port -- name=b1-eth1
merge /interfaces/interface -- name=b1-eth1 type=ethernetCsmacd port-name=b1-eth1
create /flows/flow[id='h0-to-h1'] -- match/in-port=b1-eth0 actions/action[order='0']/output-action/out-port=b1-eth1
create /flows/flow[id='h1-to-h0'] -- match/in-port=b1-eth1 actions/action[order='0']/output-action/out-port=b1-eth0
"""
    result = tntapi.yangcli_ok_script(yconns["b1"], yangcli_script)
    tntapi.network_commit(conns)

    # The commit should cause the netconfd server to execute the OpenFlow equivalent of:
    #switch.cmd( 'ovs-ofctl add-flow dp0 in_port=2,actions=output:1' )
    #switch.cmd( 'ovs-ofctl add-flow dp0 in_port=1,actions=output:2' )

    b0.cmdPrint('ovs-ofctl dump-flows dp0')

    info("*** Running test\n")
    h0.cmdPrint('ping -I h0-eth0 -c10 ' + h1.IP())

    b0.cmdPrint('ovs-ofctl dump-flows dp0')

    state_after = tntapi.network_get_state(network, conns)
    #delta = tntapi.get_network_counters_delta(state_before,state_after)

    tntapi.print_state_ietf_interfaces_statistics_delta(
        network, state_before, state_after)

    raw_input("Press Enter to continue...")

    info("*** Stopping network\n")
    b0.cmd('killall -KILL netconfd')
    b0.cmd('ovs-vsctl del-br dp0')
    b0.deleteIntfs()
    b1.cmd('killall -KILL netconfd')
    b1.cmd('ovs-vsctl del-br dp1')
    b1.deleteIntfs()
    info('\n')
Esempio n. 16
0
def scratchNet(cname='controller', cargs='-v ptcp:'):
    "Create network from scratch using Open vSwitch."

    info("*** Creating nodes\n")
    controller = Node('c0', inNamespace=False)
    switch0 = Node('s0', inNamespace=False)
    switch1 = Node('s1', inNamespace=False)
    h0 = Node('h0')
    h1 = Node('h1')

    info("*** Creating links\n")

    linkopts0 = dict(bw=10)
    linkopts1 = dict(bw=10, delay='5ms', loss=10)
    TCLink(h0, switch0, **linkopts0)
    TCLink(h1, switch1, **linkopts0)
    TCLink(switch0, switch1, **linkopts1)

    info("*** Configuring hosts\n")
    h0.setIP('192.168.123.1/24')
    h1.setIP('192.168.123.2/24')
    info(str(h0) + '\n')
    info(str(h1) + '\n')

    info("*** Starting network using Open vSwitch\n")
    controller.cmd(cname + ' ' + cargs + '&')
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.cmd('ovs-vsctl add-br dp0')
    switch1.cmd('ovs-vsctl del-br dp1')
    switch1.cmd('ovs-vsctl add-br dp1')

    for intf in switch0.intfs.values():
        print intf
        print switch0.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)

    switch0.cmd('ovs-vsctl set-controller dp0 tcp:10.1.50.175:6633')
    switch1.cmd('ovs-vsctl set-controller dp1 tcp:10.1.50.175:6633')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=1 actions=output:2\"')
    switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=2 actions=output:1\"')
    switch1.cmd('ovs-ofctl add-flow dp1 \"in_port=1 actions=output:2\"')
    switch1.cmd('ovs-ofctl add-flow dp1 \"in_port=2 actions=output:1\"')

    info('*** Waiting for switch to connect to controller')
    while 'is_connected' not in quietRun('ovs-vsctl show'):
        sleep(1)
        info('.')
    info('\n')
    print switch0.cmd('ovs-ofctl show dp0')
    print switch1.cmd('ovs-ofctl show dp1')

    info("*** Running test\n")
    h0.cmdPrint('ping -c3 ' + h1.IP())
    h1.cmdPrint('ping -c3 ' + h0.IP())

    info("*** Stopping network\n")
    controller.cmd('kill %' + cname)
    switch0.cmd('ovs-vsctl del-br dp0')
    switch0.deleteIntfs()
    switch1.cmd('ovs-vsctl del-br dp1')
    switch1.deleteIntfs()
    info('\n')