Esempio n. 1
0
 def stop(self):
     "Stop this link"
     if self.tunnel:
         self.tunnel.terminate()
         self.intf1.delete()
         self.intf2.delete()
     else:
         TCLink.stop(self)
     self.tunnel = None
Esempio n. 2
0
 def __init__(self, node1, node2, **kwargs):
     """Initialize a RemoteLink
        see Link() for parameters"""
     # Create links on remote node
     self.node1 = node1
     self.node2 = node2
     self.tunnel = None
     kwargs.setdefault( 'params1', {} )
     kwargs.setdefault( 'params2', {} )
     self.cmd = None  # satisfy pylint
     TCLink.__init__( self, node1, node2, **kwargs )
Esempio n. 3
0
def emptyNet():
 
    "Create an empty network and add nodes to it."
    "[h1]<---wifi-network---> [h0:AP] <---wired-link ---> [s0] <---wired-link--->[h3]"
    "[h2]<---wifi-network--->         "

    net = Mininet( controller=OVSController )

    info( '*** Adding controller\n' )
    net.addController( 'c0' )

    info( '*** Adding switch\n' )
    s0 = net.addSwitch( 's0' )
    s0.listenPort = 6634

    h0 = net.addHost( 'h0' ) 
    h1 = net.addHost( 'h1', ip='192.168.0.2' ) 
    h2 = net.addHost( 'h2', ip='192.168.0.3' ) 
    h3 = net.addHost( 'h3', ip='10.0.0.2' ) 
    linkopts=dict( bw=100, delay='1ms', loss=0 )
    TCLink( s0, h3, **linkopts )
    TCLink( h0, s0, **linkopts )
    
    wifi = WIFISegment()

    wifi.addAp( h0 )
    wifi.addSta( h1 )
    wifi.addSta( h2 )

    info( '*** Starting network\n')
    net.start()
    mininet.ns3.start()                

    h0.cmdPrint ( "ifconfig h0-eth0 10.0.0.1 netmask 255.255.255.0" )
    h0.cmdPrint ( "ifconfig h0-eth1 192.168.0.1 netmask 255.255.255.0" )
    h0.cmdPrint ( "sudo echo 1 > /proc/sys/net/ipv4/ip_forward" )
    h1.cmdPrint ( "route add default gw 192.168.0.1" )
    h2.cmdPrint ( "route add default gw 192.168.0.1" )
    h3.cmdPrint ( "route add default gw 10.0.0.1" )
 
    info( '*** Testing network connectivity\n' )
    net.pingAll()

    info( '*** Running CLI\n' )
    CLI( net )

    info( '*** Stopping network' )
    mininet.ns3.stop()
    mininet.ns3.clear()                     # line added
    net.stop()
Esempio n. 4
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' )
Esempio n. 5
0
 def makeIntfPair(self,
                  intfname1,
                  intfname2,
                  addr1=None,
                  addr2=None,
                  node1=None,
                  node2=None,
                  deleteIntfs=True):
     """Create pair of interfaces
         intfname1: name of interface 1
         intfname2: name of interface 2
         (override this method [and possibly delete()]
         to change link type)"""
     node1 = self.node1 if node1 is None else node1
     node2 = self.node2 if node2 is None else node2
     server1 = getattr(node1, 'server', 'localhost')
     server2 = getattr(node2, 'server', 'localhost')
     if server1 == server2:
         # Link within same server
         return TCLink.makeIntfPair(intfname1,
                                    intfname2,
                                    addr1,
                                    addr2,
                                    node1,
                                    node2,
                                    deleteIntfs=deleteIntfs)
     # Otherwise, make a tunnel
     self.tunnel = self.makeTunnel(node1, node2, intfname1, intfname2,
                                   addr1, addr2)
     return self.tunnel
Esempio n. 6
0
    def add_link_worker():
        while True:
            if ep_tuples.qsize() == 0:
                time.sleep(5)
                break

            success1 = success2 = False
            ept = None
            lock.acquire()
            logger.debug("==> ++++ lock {}".format(
                threading.current_thread().getName()))
            for _ in range(ep_tuples.qsize()):
                ept = ep_tuples.get()
                if ept:
                    success1 = switch_locks[ept[0]].acquire(False)
                    success2 = switch_locks[ept[1]].acquire(False)
                    logger.debug("==> switches ???? {} {} {} {}".format(
                        ept[0], ept[1], success1, success2))
                    # if successful, process the tuple. Otherwise release the locks
                    if success1 and success2:
                        break
                    if success1: switch_locks[ept[0]].release()
                    if success2: switch_locks[ept[1]].release()
                    ep_tuples.put(ept)  # put it back
                    ep_tuples.task_done(
                    )  # since put increases the count; this round is "done"

            lock.release()
            logger.debug("==> ---- lock {}".format(
                threading.current_thread().getName()))

            # if both are true, then we'll need to release locks at the end.
            # if either aren't true, the resources will have already been released

            if success1 and success2:
                placed = False
                try:
                    link = TCLink(switches[ept[0]], switches[ept[1]])
                    link.intf1.node.attach(link.intf1)
                    link.intf2.node.attach(link.intf2)
                    links[link_name(link)] = link
                    placed = True
                    logger.debug("==> switches ++++ {} {}".format(
                        ept[0], ept[1]))
                except:
                    # Release the locks on the switches
                    logger.debug(
                        "==>==> ## ERROR adding link, putting back on queue={}"
                        .format(ept))

                if not placed:
                    ep_tuples.put(ept)

                switch_locks[ept[0]].release()
                switch_locks[ept[1]].release()
                ep_tuples.task_done()
            time.sleep(1)
Esempio n. 7
0
 def status(self):
     "Detailed representation of link"
     if self.tunnel:
         if self.tunnel.poll() is not None:
             status = "Tunnel EXITED %s" % self.tunnel.returncode
         else:
             status = "Tunnel Running (%s: %s)" % (self.tunnel.pid,
                                                   self.cmd)
     else:
         status = "OK"
     result = "%s %s" % (TCLink.status(self), status)
     return result
Esempio n. 8
0
def connectToRootNS(network, switch, ip, prefixLen, routes):
    "Connect hosts to root namespace via switch. Starts network."
    "network: Mininet() network object"
    "switch: switch to connect to root namespace"
    "ip: IP address for root namespace node"
    "prefixLen: IP address prefix length (e.g. 8, 16, 24)"
    "routes: host networks to route to"
    # Create a node in root namespace and link to switch 0
    root = Node('root', inNamespace=False)
    intf = TCLink(root, switch).intf1
    root.setIP(ip, prefixLen, intf)
    # Start network that now includes link to root namespace
    network.start()
    # Add routes from root ns to hosts
    for route in routes:
        root.cmd('route add -net ' + route + ' dev ' + str(intf))
Esempio n. 9
0
    def define_dashnet_topo(self):
        info('*** Adding controller\n')
        self.net.addController(name='c0')

        info('*** Add switches\n')
        s1 = self.net.addSwitch('s1')

        #no ip address for this interface
        self.checkIntf(self.out_intf)
        s1_inf = Intf(self.out_intf, node=s1)
        # s1_inf.ifconfig('0.0.0.0')

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

        info("*** Creating links\n")
        self.link1 = TCLink(root, s1)
        self.net.add_dict_link('link1', self.link1)
Esempio n. 10
0
def emptyNet():

    "Create an empty network and add nodes to it."

    #net = Mininet( controller=Controller )
    net = Mininet(controller=RemoteController)

    info('*** Adding controller\n')
    net.addController('c0', ip='127.0.0.1')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', ip='10.0.0.1', mac='00:00:00:00:00:11')
    h2 = net.addHost('h2', ip='10.0.0.2', mac='00:00:00:00:00:22')

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    s4 = net.addSwitch('s4')

    info('*** Creating links\n')
    bw = 1
    TCLink(h1, s1, bw=10 * bw)

    TCLink(s1, s2, bw=bw)
    TCLink(s1, s3, bw=bw)

    TCLink(s2, s4, bw=bw)
    TCLink(s3, s4, bw=bw)

    TCLink(s1, s4, bw=bw)
    TCLink(s1, s4, bw=bw)

    TCLink(h2, s4, bw=10 * bw)

    #print "Stopping of " + 's5'
    #net.configLinkStatus('s5', 's3', 'down')
    #net.configLinkStatus('s5', 's6', 'down')
    #net.hosts[0].cmd("ping -w 15 10.0.0.2")
    #net.pingAll()

    return net
Esempio n. 11
0
def myNetwork():

    net = Mininet(topo=None, build=False, link=TCLink)

    info('*** Adding controller\n')
    c0 = net.addController(name='c0',
                           controller=RemoteController,
                           protocol='tcp',
                           ip='127.0.0.1',
                           port=6633)

    info('*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch, protocols='OpenFlow13')
    s11 = net.addSwitch('s11', cls=OVSKernelSwitch, protocols='OpenFlow13')
    net.addLink('s1', 's2', bw=10)
    net.addLink('s1', 's3', bw=10)
    net.addLink('s3', 's4', bw=10)
    net.addLink('s2', 's5', bw=10)
    net.addLink('s4', 's5', bw=10)
    net.addLink('s3', 's7', bw=10)
    net.addLink('s4', 's8', bw=10)
    net.addLink('s7', 's8', bw=10)
    net.addLink('s6', 's7', bw=10)
    net.addLink('s8', 's9', bw=10)
    net.addLink('s9', 's11', bw=10)
    net.addLink('s6', 's9', bw=10)
    net.addLink('s6', 's10', bw=10)
    net.addLink('s10', 's9', bw=10)

    info('*** Adding end devices.\n')
    h1 = net.addHost('h1')
    TCLink(h1, s1, intfName='h1-eth0')
    TCLink(h1, s6, intfName='h1-eth1')
    h1.setIP('10.0.0.1', intf='h1-eth0')
    h1.setIP('10.0.0.2', intf='h1-eth1')
    h1.setMAC('00:00:00:00:00:01', intf='h1-eth0')
    h1.setMAC('00:00:00:00:00:02', intf='h1-eth1')
    h1.cmd('ip rule add from 10.0.0.1 table 1')
    h1.cmd('ip rule add from 10.0.0.2 table 2')
    h1.cmd('ip route add 10.0.0.0/24 dev h1-eth0 scope link table 1')
    h1.cmd('ip route add 10.0.0.0/24 dev h1-eth1 scope link table 2')
    h1.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1')
    h1.cmd('/home/mato/ryu/scripts/h1_arp.sh')

    h2 = net.addHost('h2')
    TCLink(h2, s5, intfName='h2-eth0')
    TCLink(h2, s11, intfName='h2-eth1')
    h2.setIP('10.0.0.3', intf='h2-eth0')
    h2.setIP('10.0.0.4', intf='h2-eth1')
    h2.setMAC('00:00:00:00:00:03', intf='h2-eth0')
    h2.setMAC('00:00:00:00:00:04', intf='h2-eth1')
    h2.cmd('ip rule add from 10.0.0.3 table 1')
    h2.cmd('ip rule add from 10.0.0.4 table 2')
    h2.cmd('ip route add 10.0.0.0/24 dev h2-eth0 scope link table 1')
    h2.cmd('ip route add 10.0.0.0/24 dev h2-eth1 scope link table 2')
    h2.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1')
    h2.cmd('/home/mato/ryu/scripts/h2_arp.sh')

    net.build()
    info('*** Starting network\n')
    net.build()
    info('*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info('*** Starting switches\n')
    net.get('s1').start([c0])
    net.get('s2').start([c0])
    net.get('s3').start([c0])
    net.get('s4').start([c0])
    net.get('s5').start([c0])
    net.get('s6').start([c0])
    net.get('s7').start([c0])
    net.get('s8').start([c0])
    net.get('s9').start([c0])
    net.get('s10').start([c0])
    net.get('s11').start([c0])

    h2.cmd('iperf -s &')
    CLI(net)
    net.stop()
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 add_link(node1, node2):
    link = TCLink(switches[node1], switches[node2])
    link.intf1.node.attach(link.intf1)
    link.intf2.node.attach(link.intf2)
    links[link_name(link)] = link
Esempio n. 15
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')
Esempio n. 16
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. 17
0
    net = Mininet(controller=OVSController)
    c0 = net.addController('c0')

    info('*** Adding hosts\n')
    h1 = net.addHost('h1', ip='192.168.0.1')
    h2 = net.addHost('h2', ip='192.168.0.2')
    h3 = net.addHost('h3', ip='192.168.0.3')

    info('*** Adding switch\n')
    s0 = net.addSwitch('s0')
    s0.listenPort = 6634
    c0.start()
    s0.start([c0])
    linkopts = dict(bw=100, delay='1ms', loss=0)
    TCLink(s0, h3, **linkopts)

    #net.hosts.append( s0 )
    net.hosts.append(h1)
    net.hosts.append(h2)

    wifi = WIFISegment()

    wifi.addAp(s0)
    wifi.addSta(h1)
    wifi.addSta(h2)

    net.start()
    mininet.ns3.start()

    CLI(net)
Esempio n. 18
0
if '__main__' == __name__:
    net = Mininet(controller=RemoteController)

    c0 = net.addController('c0', ip="127.0.0.1")

    s1 = net.addSwitch('s1', cls=UserSwitch)
    s2 = net.addSwitch('s2', cls=UserSwitch)

    h1 = net.addHost('h1', mac='00:00:00:00:00:11')
    h2 = net.addHost('h2', mac='00:00:00:00:00:12')

    h3 = net.addHost('h3', mac='00:00:00:00:00:23')
    h4 = net.addHost('h4', mac='00:00:00:00:00:24')
    #h5 = net.addHost('h4', mac='00:00:00:00:00:24')

    TCLink(s1, s2, bw=1)
    TCLink(s1, s2, bw=1)

    TCLink(s1, h1, bw=1)
    TCLink(s1, h2, bw=1)

    TCLink(s2, h3, bw=1)
    TCLink(s2, h4, bw=1)

    net.build()

    c0.start()
    s1.start([c0])
    s2.start([c0])

    CLI(net)
Esempio n. 19
0
from mininet.term import makeTerm
from mininet.node import UserSwitch
from mininet.link import TCLink

if '__main__' == __name__:
    net = Mininet(controller=RemoteController)

    c0 = net.addController('c0', ip="127.0.0.1")

    s1 = net.addSwitch('s1', cls=UserSwitch)

    h1 = net.addHost('h1', mac='00:00:00:00:00:11')
    h2 = net.addHost('h2', mac='00:00:00:00:00:12')
    h3 = net.addHost('h3', mac='00:00:00:00:00:23')
    h4 = net.addHost('h4', mac='00:00:00:00:00:24')

    bw = 100
    TCLink(s1, h1, bw=bw)
    TCLink(s1, h2, bw=bw)
    TCLink(s1, h3, bw=bw)
    TCLink(s1, h4, bw=bw)

    net.build()

    c0.start()
    s1.start([c0])

    CLI(net)

    net.stop()
Esempio n. 20
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. 21
0
def add_link(node1, node2):
    link = TCLink(switches[node1], switches[node2])
    link.intf1.node.attach(link.intf1)
    link.intf2.node.attach(link.intf2)
    links[link_name(link)] = link
    logger.debug("==> added link from node1={}; node2={}".format(node1, node2))
Esempio n. 22
0
    net = Mininet(controller=RemoteController,
                  autoStaticArp=True,
                  autoSetMacs=True)

    c0 = net.addController('c0')

    s1 = net.addSwitch('s1')
    h1 = net.addHost('h1')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    h4 = net.addHost('h4')
    h5 = net.addHost('h5', ip='10.0.0.4/8')
    net.addLink(h1, s1, port2=1)
    net.addLink(h2, s1, port2=2)
    net.addLink(h3, s1, port2=3)
    TCLink(h4, s1, 1, 4, bw=1)
    TCLink(h5, s1, 1, 5, bw=1)

    net.build()
    net.startTerms()
    c0.start()
    s1.start([c0])
    s1.sendCmd('ovs-vsctl set bridge s1 protocols=OpenFlow13')
    h1.sendCmd('arp -s 10.0.0.4 00:00:00:00:00:04')
    h2.sendCmd('arp -s 10.0.0.4 00:00:00:00:00:04')
    h3.sendCmd('arp -s 10.0.0.4 00:00:00:00:00:04')
    h5.setMAC("00:00:00:00:00:04", intf='h5-eth1')

    #c0.cmd('ryu-manager ./bw_monitor_13.py')

    CLI(net)