Revision efc9a01c examples/scratchnet.py

View differences:

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

  
9
from mininet.mininet import init, Node, createLink
9
import logging
10

  
11
from mininet.net import init
12
from mininet.node import Node
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
10 18

  
11 19
def scratchNet( cname='controller', cargs='ptcp:'):
12
   # Create Network
13
   controller = Node( 'c0', inNamespace=False )
14
   switch = Node( 's0', inNamespace=False )
15
   h0 = Node( 'h0' )
16
   h1 = Node( 'h1' )
17
   createLink( h0, switch )
18
   createLink( h1, switch )
19
   # Configure hosts
20
   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
21
   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
22
   # Start network using kernel datapath
23
   controller.cmdPrint( cname + ' ' + cargs + '&' )
24
   switch.cmdPrint( 'dpctl deldp nl:0' )
25
   switch.cmdPrint( 'dpctl adddp nl:0' )
26
   for intf in switch.intfs:
20
    # Create Network
21
    print "*** creating Nodes"
22
    controller = Node( 'c0', inNamespace=False )
23
    switch = Node( 's0', inNamespace=False )
24
    h0 = Node( 'h0' )
25
    h1 = Node( 'h1' )
26
    print "*** creating links"
27
    createLink( node1=h0, port1=0, node2=switch, port2=0 )
28
    createLink( node1=h1, port1=0, node2=switch, port2=1 )
29
    # Configure hosts
30
    print "*** configuring hosts"
31
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
32
    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' )
39
    for intf in switch.intfs.values():
27 40
      switch.cmdPrint( 'dpctl addif nl:0 ' + intf )
28
   switch.cmdPrint( 'ofprotocol nl:0 tcp:localhost &')
29
   # Run test
30
   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
31
   # Stop network
32
   controller.cmdPrint( 'kill %' + cname)
33
   switch.cmdPrint( 'dpctl deldp nl:0' )
34
   switch.cmdPrint( 'kill %ofprotocol' )
35
   switch.stop()
36
   controller.stop()
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()
37 50
   
38 51
if __name__ == '__main__':
39
   init()   
40
   scratchNet()
52
    info( '*** Scratch network demo\n' )
53
    init()   
54
    scratchNet()

Also available in: Unified diff