Revision dc630c54

View differences:

examples/scratchnet.py
11 11
from mininet.net import init
12 12
from mininet.node import Node
13 13
from mininet.util import createLink
14
from mininet.log import info
15

  
16
# print out info() messages, including cmdPrint
17
logging.LOGLEVELDEFAULT = logging.INFO
14
from mininet.log import lg, info
18 15

  
19 16
def scratchNet( cname='controller', cargs='ptcp:'):
20
    # Create Network
21
    print "*** creating Nodes"
17

  
18
    info( "*** Creating nodes\n" )
22 19
    controller = Node( 'c0', inNamespace=False )
23 20
    switch = Node( 's0', inNamespace=False )
24 21
    h0 = Node( 'h0' )
25 22
    h1 = Node( 'h1' )
26
    print "*** creating links"
23
    
24
    info( "*** Creating links\n" )
27 25
    createLink( node1=h0, port1=0, node2=switch, port2=0 )
28 26
    createLink( node1=h1, port1=0, node2=switch, port2=1 )
29
    # Configure hosts
30
    print "*** configuring hosts"
27

  
28
    info( "*** Configuring hosts\n" )
31 29
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
32 30
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
33
    print h0
34
    print h1
35
    # Start network using kernel datapath
36
    controller.cmdPrint( cname + ' ' + cargs + '&' )
37
    switch.cmdPrint( 'dpctl deldp nl:0' )
38
    switch.cmdPrint( 'dpctl adddp nl:0' )
31
    info( str( h0 ) + '\n' )
32
    info( str( h1 ) + '\n' )
33
    
34
    info( "*** Starting network using kernel datapath\n" )
35
    controller.cmd( cname + ' ' + cargs + '&' )
36
    switch.cmd( 'dpctl deldp nl:0' )
37
    switch.cmd( 'dpctl adddp nl:0' )
39 38
    for intf in switch.intfs.values():
40
      switch.cmdPrint( 'dpctl addif nl:0 ' + intf )
41
    switch.cmdPrint( 'ofprotocol nl:0 tcp:localhost &')
42
    # Run test
43
    print h0.cmd( 'ping -c1 ' + h1.IP() )
44
    # Stop network
45
    controller.cmdPrint( 'kill %' + cname)
46
    switch.cmdPrint( 'dpctl deldp nl:0' )
47
    switch.cmdPrint( 'kill %ofprotocol' )
48
    switch.stop()
49
    controller.stop()
39
      switch.cmd( 'dpctl addif nl:0 ' + intf )
40
    switch.cmd( 'ofprotocol nl:0 tcp:localhost &')
41
    
42
    info( "*** Running test\n" )
43
    h0.cmdPrint( 'ping -c1 ' + h1.IP() )
44
    
45
    info( "*** Stopping network\n" )
46
    controller.cmd( 'kill %' + cname)
47
    switch.cmd( 'dpctl deldp nl:0' )
48
    switch.cmd( 'kill %ofprotocol' )
50 49
   
51 50
if __name__ == '__main__':
52
    info( '*** Scratch network demo\n' )
53
    init()   
51
    info( '*** Scratch network demo (kernel datapath)\n' )
52
    init()
53
    lg.setLogLevel( 'info' )
54 54
    scratchNet()
examples/scratchnetuser.py
8 8
This version uses the user datapath.
9 9
"""
10 10

  
11
from mininet.mininet import init, Node, createLink
11
from mininet.net import init
12
from mininet.node import Node
13
from mininet.util import createLink
14
from mininet.log import lg, info
12 15

  
13 16
def scratchNetUser( cname='controller', cargs='ptcp:'):
14
   # Create Network
15
   # It's not strictly necessary for the controller and switches
16
   # to be in separate namespaces. For performance, they probably
17
   # should be in the root namespace. However, it's interesting to
18
   # see how they could work even if they are in separate namespaces.
19
   controller = Node( 'c0' )
20
   switch = Node( 's0')
21
   h0 = Node( 'h0' )
22
   h1 = Node( 'h1' )
23
   createLink( controller, switch )
24
   createLink( h0, switch )
25
   createLink( h1, switch )
26
   # Configure control network
27
   controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
28
   switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
29
   # Configure hosts
30
   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
31
   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
32
   # Start network using user datapath
33
   controller.cmdPrint( cname + ' ' + cargs + '&' )
34
   switch.cmdPrint( 'ifconfig lo 127.0.0.1' )
35
   switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ]) 
36
      + ' ptcp: &' )
37
   switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
38
   # Run test
39
   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
40
   # Stop network
41
   controller.cmdPrint( 'kill %' + cname)
42
   switch.cmdPrint( 'kill %ofdatapath' )
43
   switch.cmdPrint( 'kill %ofprotocol' )
17
    # Create Network
18
    # It's not strictly necessary for the controller and switches
19
    # to be in separate namespaces. For performance, they probably
20
    # should be in the root namespace. However, it's interesting to
21
    # see how they could work even if they are in separate namespaces.
22

  
23
    info( '*** Creating Network\n' )
24
    controller = Node( 'c0' )
25
    switch = Node( 's0')
26
    h0 = Node( 'h0' )
27
    h1 = Node( 'h1' )
28
    createLink( controller, 0, switch, 0 )
29
    createLink( h0, 0, switch, 1 )
30
    createLink( h1, 0, switch, 2 )
31

  
32
    info( '*** Configuring control network\n' )
33
    controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
34
    switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
35
    
36
    info( '*** Configuring hosts\n' )
37
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
38
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
39
    
40
    info( '*** Network state:\n' )
41
    for node in controller, switch, h0, h1:
42
        info( str( node ) + '\n' )
43
        
44
    info( '*** Starting controller and user datapath\n' )
45
    controller.cmd( cname + ' ' + cargs + '&' )
46
    switch.cmd( 'ifconfig lo 127.0.0.1' )
47
    intfs = [ switch.intfs[ port ] for port in (1, 2) ]
48
    switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
49
    switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
50

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

  
54
    info( '*** Stopping network\n' )
55
    controller.cmd( 'kill %' + cname )
56
    switch.cmd( 'kill %ofdatapath' )
57
    switch.cmd( 'kill %ofprotocol' )
44 58
   
45 59
if __name__ == '__main__':
46
   init()   
47
   scratchNetUser()
60
    info( '*** Scratch network demo (user datapath)\n' )
61
    init()   
62
    lg.setLogLevel( 'info' )
63
    scratchNetUser()
mininet/node.py
54 54
    def __init__( self, name, inNamespace=True ):
55 55
        self.name = name
56 56
        closeFds = False # speed vs. memory use
57
        # xpgEcho is needed so we can echo our sentinel in sendCmd
57
        # xpg_echo is needed so we can echo our sentinel in sendCmd
58 58
        cmd = [ '/bin/bash', '-O', 'xpg_echo' ]
59 59
        self.inNamespace = inNamespace
60 60
        if self.inNamespace:
......
170 170
        """Send a command, wait for output, and return it.
171 171
           cmd: string"""
172 172
        log = info if verbose else debug
173
        log( '*** %s : %s', self.name, cmd )
173
        log( '*** %s : %s\n' % ( self.name, cmd ) )
174 174
        self.sendCmd( cmd )
175 175
        return self.waitOutput( verbose )
176 176

  
......
261 261
    # Other methods
262 262
    def __str__( self ):
263 263
        result = self.name + ':'
264
        result += ' IP=' + repr( self.IP() )
264
        result += ' IP=' + str( self.IP() )
265 265
        result += ' intfs=' + ','.join( sorted( self.intfs.values() ) )
266
        result += ' waiting=' + repr( self.waiting )
266
        result += ' waiting=' + str( self.waiting )
267 267
        return result
268 268

  
269 269

  

Also available in: Unified diff