Statistics
| Branch: | Tag: | Revision:

mininet / examples / scratchnet.py @ 80be5642

History | View | Annotate | Download (1.68 KB)

1
#!/usr/bin/python
2

    
3
"""
4
Build a simple network from scratch, using mininet primitives.
5
This is more complicated than using the higher-level classes,
6
but it exposes the configuration details and allows customization.
7
"""
8

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

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

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

    
23
    info( "*** Creating links\n" )
24
    createLink( node1=h0, port1=0, node2=switch, port2=0 )
25
    createLink( node1=h1, port1=0, node2=switch, port2=1 )
26

    
27
    info( "*** Configuring hosts\n" )
28
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', 24 )
29
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
30
    info( str( h0 ) + '\n' )
31
    info( str( h1 ) + '\n' )
32

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

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

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

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