Statistics
| Branch: | Tag: | Revision:

mininet / examples / scratchnetuser.py @ 80be5642

History | View | Annotate | Download (2.19 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
This version uses the user datapath and an explicit control network.
9
"""
10

    
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
15

    
16
def scratchNetUser( cname='controller', cargs='ptcp:' ):
17
    "Create network from scratch using user switch."
18

    
19
    # It's not strictly necessary for the controller and switches
20
    # to be in separate namespaces. For performance, they probably
21
    # should be in the root namespace. However, it's interesting to
22
    # see how they could work even if they are in separate namespaces.
23

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

    
33
    info( '*** Configuring control network\n' )
34
    controller.setIP( controller.intfs[ 0 ], '10.0.123.1', 24 )
35
    switch.setIP( switch.intfs[ 0 ], '10.0.123.2', 24 )
36

    
37
    info( '*** Configuring hosts\n' )
38
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', 24 )
39
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', 24 )
40

    
41
    info( '*** Network state:\n' )
42
    for node in controller, switch, h0, h1:
43
        info( str( node ) + '\n' )
44

    
45
    info( '*** Starting controller and user datapath\n' )
46
    controller.cmd( cname + ' ' + cargs + '&' )
47
    switch.cmd( 'ifconfig lo 127.0.0.1' )
48
    intfs = [ switch.intfs[ port ] for port in ( 1, 2 ) ]
49
    switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
50
    switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
51

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

    
55
    info( '*** Stopping network\n' )
56
    controller.cmd( 'kill %' + cname )
57
    switch.cmd( 'kill %ofdatapath' )
58
    switch.cmd( 'kill %ofprotocol' )
59
    switch.deleteIntfs()
60
    info( '\n' )
61

    
62
if __name__ == '__main__':
63
    lg.setLogLevel( 'info' )
64
    info( '*** Scratch network demo (user datapath)\n' )
65
    init()
66
    scratchNetUser()