예제 #1
0
def createStaticRouterNetwork():
    info('*** Creating network for Static Router Example\n')

    # Create an empty network.
    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
    net.addController('c0')

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    s0 = net.addSwitch('s0')
    h1 = net.addHost('h1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s0int = createLink(h1, s0)

    # Configuration of IP addresses in interfaces
    h0.setIP(h0int, '192.168.1.2', 26)
    h1.setIP(h1int, '192.168.1.66', 26)

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

    # Start command line
    net.start()
    CLI(net)
    net.stop()
예제 #2
0
파일: net.py 프로젝트: 09zwcbupt/mininet
    def buildFromTopo(self, topo):
        """Build mininet from a topology object
           At the end of this function, everything should be connected
           and up."""

        def addNode(prefix, addMethod, nodeId):
            "Add a host or a switch."
            name = prefix + topo.name(nodeId)
            mac = macColonHex(nodeId) if self.setMacs else None
            ip = topo.ip(nodeId)
            node = addMethod(name, mac=mac, ip=ip)
            self.idToNode[nodeId] = node
            info(name + " ")

        # Possibly we should clean up here and/or validate
        # the topo
        if self.cleanup:
            pass

        info("*** Adding controller\n")
        self.addController("c0")
        info("*** Creating network\n")
        info("*** Adding hosts:\n")
        for hostId in sorted(topo.hosts()):
            addNode("h", self.addHost, hostId)
        info("\n*** Adding switches:\n")
        for switchId in sorted(topo.switches()):
            addNode("s", self.addSwitch, switchId)
        info("\n*** Adding links:\n")
        for srcId, dstId in sorted(topo.edges()):
            src, dst = self.idToNode[srcId], self.idToNode[dstId]
            srcPort, dstPort = topo.port(srcId, dstId)
            createLink(src, dst, srcPort, dstPort)
            info("(%s, %s) " % (src.name, dst.name))
        info("\n")
예제 #3
0
def createStaticRouterNetwork():
    info( '*** Creating network for Static Router Example\n' )

    # Create an empty network.
    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)
    net.addController('c0')

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    s0 = net.addSwitch('s0')
    h1 = net.addHost('h1')
    s1 = net.addSwitch('s1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s1int = createLink(h1, s1)
    s0pint, s1pint = createLink(s0, s1)

    # Configuration of IP addresses in interfaces
    s0.setIP(s0int, '192.168.1.1', 26)
    h0.setIP(h0int, '192.168.1.2', 26)
    s1.setIP(s1int, '192.168.1.65', 26)
    h1.setIP(h1int, '192.168.1.66', 26)
    s0.setIP(s0pint, '192.168.1.129', 26)
    s1.setIP(s1pint, '192.168.1.130', 26)

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

    # Start command line 
    net.start()
    CLI(net)
    net.stop()
예제 #4
0
    def buildFromTopo(self, topo):
        """Build mininet from a topology object
           At the end of this function, everything should be connected
           and up."""
        def addNode(prefix, addMethod, nodeId):
            "Add a host or a switch."
            name = prefix + topo.name(nodeId)
            mac = macColonHex(nodeId) if self.setMacs else None
            ip = topo.ip(nodeId)
            node = addMethod(name, mac=mac, ip=ip)
            self.idToNode[nodeId] = node
            info(name + ' ')

        # Possibly we should clean up here and/or validate
        # the topo
        if self.cleanup:
            pass

        info('*** Adding controller\n')
        self.addController('c0')
        info('*** Creating network\n')
        info('*** Adding hosts:\n')
        for hostId in sorted(topo.hosts()):
            addNode('h', self.addHost, hostId)
        info('\n*** Adding switches:\n')
        for switchId in sorted(topo.switches()):
            addNode('s', self.addSwitch, switchId)
        info('\n*** Adding links:\n')
        for srcId, dstId in sorted(topo.edges()):
            src, dst = self.idToNode[srcId], self.idToNode[dstId]
            srcPort, dstPort = topo.port(srcId, dstId)
            createLink(src, dst, srcPort, dstPort)
            info('(%s, %s) ' % (src.name, dst.name))
        info('\n')
예제 #5
0
def createDoubleControllerNetwork():
    info( '*** Creating network for Double Controller Example\n' )

    # Create an empty network.
    net = Mininet(switch=OVSKernelSwitch)
    c0 = net.addController('c0', controller=RemoteController, 
      defaultIP="127.0.0.1", port=6633)
    c1 = net.addController('c1', controller=RemoteController, 
      defaultIP="127.0.0.1", port=6644)

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    s0 = net.addSwitch('s0')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    s1 = net.addSwitch('s1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s0int = createLink(h1, s0)
    h2int, s1int = createLink(h2, s1)
    h3int, s1int = createLink(h3, s1)
    s0int, s1int = createLink(s0, s1)

    # Configuration of IP addresses in interfaces
    h0.setIP(h0int, '192.168.1.2', 26)
    h1.setIP(h1int, '192.168.1.3', 26)
    h2.setIP(h2int, '192.168.1.66', 26)
    h3.setIP(h3int, '192.168.1.67', 26)

    # Start network
    net.build()

    # Attaching Controllers to Switches
    s0.start([c0])
    s1.start([c1])

    # Setting interface only routes and not default routes
    h0.cmd("route del -net 0.0.0.0")
    h1.cmd("route del -net 0.0.0.0")
    h2.cmd("route del -net 0.0.0.0")
    h3.cmd("route del -net 0.0.0.0")
    h0.cmd("route add -net 192.168.1.0 netmask 255.255.255.192 " + h0int)
    h1.cmd("route add -net 192.168.1.0 netmask 255.255.255.192 " + h1int)
    h2.cmd("route add -net 192.168.1.64 netmask 255.255.255.192 " + h2int)
    h3.cmd("route add -net 192.168.1.64 netmask 255.255.255.192 " + h3int)

    # dump stuff on the screen
    info( '*** Network state:\n' )
    for node in c0, c1, s0, s1, h0, h1, h2, h3:
        info( str( node ) + '\n' )

    # Start command line 
    CLI(net)

    # Stop network
    net.stop()
예제 #6
0
파일: net.py 프로젝트: alisa2110/OpenFlix
    def buildFromTopo( self, topo ):
        """Build mininet from a topology object
           At the end of this function, everything should be connected
           and up."""

        def addNode( prefix, addMethod, nodeId ):
            "Add a host or a switch."
            name = prefix + topo.name( nodeId )
            mac = macColonHex( nodeId ) if self.setMacs else None
            ip = topo.ip( nodeId )
            node = addMethod( name, mac=mac, ip=ip )
            self.idToNode[ nodeId ] = node
            info( name + ' ' )

        # Possibly we should clean up here and/or validate
        # the topo
        if self.cleanup:
            pass

        info( '*** Adding controller\n' )
        self.addController( 'c0' )
        info( '*** Creating network\n' )
        info( '*** Adding hosts:\n' )
        for hostId in sorted( topo.hosts() ):
            addNode( 'h', self.addHost, hostId )
        info( '\n*** Adding switches:\n' )
        for switchId in sorted( topo.switches() ):
            addNode( 's', self.addSwitch, switchId )
        info( '\n*** Adding links:\n' )
        for srcId, dstId in sorted( topo.edges() ):
            src, dst = self.idToNode[ srcId ], self.idToNode[ dstId ]
            srcPort, dstPort = topo.port( srcId, dstId )
            createLink( src, dst, srcPort, dstPort )
            info( '(%s, %s) ' % ( src.name, dst.name ) )
            #Set link bandwidth limit

            if hasattr(topo, 'servers') and int(src.name[1:]) in topo.servers:
                info( '*** Server Identified and bandwidth rate is set at 80M\n')
                print( '*** Server Identified and bandwidth rate is set at 80M\n')
                src.configPort(srcPort, bw=80)
                dst.configPort(dstPort, bw=80)
            elif hasattr(topo, 'servers') and int(dst.name[1:]) in topo.servers:
                info( '*** Server Identified and bandwidth rate is set at 80M\n')
                print( '*** Server Identified and bandwidth rate is set at 80M\n')
                src.configPort(srcPort, bw=80)
                dst.configPort(dstPort, bw=80)
            else:   
                info( '*** Link Identified and bandwidth rate is set at 4M\n')
                print( '*** Link Identified and bandwidth rate is set at 4M\n')
                src.configPort(srcPort, bw=4)
                dst.configPort(dstPort, bw=4)
        info( '\n' )
예제 #7
0
 def configureRoutedControlNetwork(self, ip='192.168.123.1', prefixLen=16):
     """Configure a routed control network on controller and switches.
        For use with the user datapath only right now.
        """
     controller = self.controllers[0]
     info(controller.name + ' <->')
     cip = ip
     snum = ipParse(ip)
     for switch in self.switches:
         info(' ' + switch.name)
         sintf, cintf = createLink(switch, controller)
         snum += 1
         while snum & 0xff in [0, 255]:
             snum += 1
         sip = ipStr(snum)
         controller.setIP(cintf, cip, prefixLen)
         switch.setIP(sintf, sip, prefixLen)
         controller.setHostRoute(sip, cintf)
         switch.setHostRoute(cip, sintf)
     info('\n')
     info('*** Testing control network\n')
     while not controller.intfIsUp(cintf):
         info('*** Waiting for', cintf, 'to come up\n')
         sleep(1)
     for switch in self.switches:
         while not switch.intfIsUp(sintf):
             info('*** Waiting for', sintf, 'to come up\n')
             sleep(1)
         if self.ping(hosts=[switch, controller]) != 0:
             error('*** Error: control network test failed\n')
             exit(1)
     info('\n')
예제 #8
0
 def configureRoutedControlNetwork( self, ip='192.168.123.1',
     prefixLen=16 ):
     """Configure a routed control network on controller and switches.
        For use with the user datapath only right now.
        """
     controller = self.controllers[ 0 ]
     info( controller.name + ' <->' )
     cip = ip
     snum = ipParse( ip )
     for switch in self.switches:
         info( ' ' + switch.name )
         sintf, cintf = createLink( switch, controller )
         snum += 1
         while snum & 0xff in [ 0, 255 ]:
             snum += 1
         sip = ipStr( snum )
         controller.setIP( cintf, cip, prefixLen )
         switch.setIP( sintf, sip, prefixLen )
         controller.setHostRoute( sip, cintf )
         switch.setHostRoute( cip, sintf )
     info( '\n' )
     info( '*** Testing control network\n' )
     while not controller.intfIsUp( cintf ):
         info( '*** Waiting for', cintf, 'to come up\n' )
         sleep( 1 )
     for switch in self.switches:
         while not switch.intfIsUp( sintf ):
             info( '*** Waiting for', sintf, 'to come up\n' )
             sleep( 1 )
         if self.ping( hosts=[ switch, controller ] ) != 0:
             error( '*** Error: control network test failed\n' )
             exit( 1 )
     info( '\n' )
예제 #9
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')
예제 #10
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' )
예제 #11
0
def createDoubleControllerNetwork():
    info( '*** Creating network for Double Controller Example\n' )

    # Create an empty network.
    net = Mininet(switch=OVSKernelSwitch)
    c0 = net.addController('c0', controller=RemoteController)
    c1 = net.addController('c1', controller=RemoteController)

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    s0 = net.addSwitch('s0')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    s1 = net.addSwitch('s1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s0int = createLink(h1, s0)
    h2int, s1int = createLink(h2, s1)
    h3int, s1int = createLink(h3, s1)

    # Configuration of IP addresses in interfaces
    h0.setIP(h0int, '192.168.1.2', 26)
    h1.setIP(h1int, '192.168.1.3', 26)
    h2.setIP(h2int, '192.168.1.66', 26)
    h3.setIP(h3int, '192.168.1.67', 26)

    # Attaching Controllers to Switches
    net.build()
    c0.start()
    c1.start()
    s0.start([c0])
    s1.start([c1])

    # dump stuff on the screen
    info( '*** Network state:\n' )
    for node in c0, c1, s0, s1, h0, h1:
        info( str( node ) + '\n' )

    # Start command line 
    net.start()
    CLI(net)
    net.stop()
예제 #12
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' )
예제 #13
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')
예제 #14
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 = createLink(root, switch)[0]
    root.setIP(intf, ip, prefixLen)
    # 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 ' + intf)
예제 #15
0
파일: sshd.py 프로젝트: 09zwcbupt/mininet
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 = createLink( root, switch )[ 0 ]
    root.setIP( intf, ip, prefixLen )
    # 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 ' + intf )
예제 #16
0
def createDoubleControllerNetwork():
    info('*** Creating network for Double Controller Example\n')

    # Create an empty network.
    net = Mininet(switch=OVSKernelSwitch)
    c0 = net.addController('c0',
                           controller=RemoteController,
                           defaultIP="127.0.0.1",
                           port=6633)
    c1 = net.addController('c1',
                           controller=RemoteController,
                           defaultIP="127.0.0.1",
                           port=6644)

    # Creating nodes in the network.
    h0 = net.addHost('h0')
    h1 = net.addHost('h1')
    s0 = net.addSwitch('s0')
    h2 = net.addHost('h2')
    h3 = net.addHost('h3')
    s1 = net.addSwitch('s1')

    # Creating links between nodes in network.
    h0int, s0int = createLink(h0, s0)
    h1int, s0int = createLink(h1, s0)
    h2int, s1int = createLink(h2, s1)
    h3int, s1int = createLink(h3, s1)
    s0int, s1int = createLink(s0, s1)

    # Configuration of IP addresses in interfaces
    h0.setIP(h0int, '192.168.1.2', 26)
    h1.setIP(h1int, '192.168.1.3', 26)
    h2.setIP(h2int, '192.168.1.66', 26)
    h3.setIP(h3int, '192.168.1.67', 26)

    # Start network
    net.build()

    # Attaching Controllers to Switches
    s0.start([c0])
    s1.start([c1])

    # Setting interface only routes and not default routes
    h0.cmd("route del -net 0.0.0.0")
    h1.cmd("route del -net 0.0.0.0")
    h2.cmd("route del -net 0.0.0.0")
    h3.cmd("route del -net 0.0.0.0")
    h0.cmd("route add -net 192.168.1.0 netmask 255.255.255.192 " + h0int)
    h1.cmd("route add -net 192.168.1.0 netmask 255.255.255.192 " + h1int)
    h2.cmd("route add -net 192.168.1.64 netmask 255.255.255.192 " + h2int)
    h3.cmd("route add -net 192.168.1.64 netmask 255.255.255.192 " + h3int)

    # dump stuff on the screen
    info('*** Network state:\n')
    for node in c0, c1, s0, s1, h0, h1, h2, h3:
        info(str(node) + '\n')

    # Start command line
    CLI(net)

    # Stop network
    net.stop()