Revision 80be5642 examples/scratchnet.py

View differences:

examples/scratchnet.py
6 6
but it exposes the configuration details and allows customization.
7 7
"""
8 8

  
9
import logging
10

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

  
16
def scratchNet( cname='controller', cargs='ptcp:'):
14
def scratchNet( cname='controller', cargs='ptcp:' ):
15
    "Create network from scratch using kernel switch."
17 16

  
18 17
    info( "*** Creating nodes\n" )
19 18
    controller = Node( 'c0', inNamespace=False )
20 19
    switch = Node( 's0', inNamespace=False )
21 20
    h0 = Node( 'h0' )
22 21
    h1 = Node( 'h1' )
23
    
22

  
24 23
    info( "*** Creating links\n" )
25 24
    createLink( node1=h0, port1=0, node2=switch, port2=0 )
26 25
    createLink( node1=h1, port1=0, node2=switch, port2=1 )
......
30 29
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
31 30
    info( str( h0 ) + '\n' )
32 31
    info( str( h1 ) + '\n' )
33
    
32

  
34 33
    info( "*** Starting network using kernel datapath\n" )
35 34
    controller.cmd( cname + ' ' + cargs + '&' )
36 35
    switch.cmd( 'dpctl deldp nl:0' )
37 36
    switch.cmd( 'dpctl adddp nl:0' )
38 37
    for intf in switch.intfs.values():
39
      switch.cmd( 'dpctl addif nl:0 ' + intf )
40
    switch.cmd( 'ofprotocol nl:0 tcp:localhost &')
41
    
38
        switch.cmd( 'dpctl addif nl:0 ' + intf )
39
    switch.cmd( 'ofprotocol nl:0 tcp:localhost &' )
40

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

  
45 44
    info( "*** Stopping network\n" )
46
    controller.cmd( 'kill %' + cname)
45
    controller.cmd( 'kill %' + cname )
47 46
    switch.cmd( 'dpctl deldp nl:0' )
48 47
    switch.cmd( 'kill %ofprotocol' )
49 48
    switch.deleteIntfs()
50 49
    info( '\n' )
51
    
50

  
52 51
if __name__ == '__main__':
53 52
    lg.setLogLevel( 'info' )
54 53
    info( '*** Scratch network demo (kernel datapath)\n' )

Also available in: Unified diff