Statistics
| Branch: | Tag: | Revision:

mininet / examples / scratchnet.py @ dc630c54

History | View | Annotate | Download (1.62 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
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 lg, info
15

    
16
def scratchNet( cname='controller', cargs='ptcp:'):
17

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

    
28
    info( "*** Configuring hosts\n" )
29
    h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
30
    h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
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' )
38
    for intf in switch.intfs.values():
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' )
49
   
50
if __name__ == '__main__':
51
    info( '*** Scratch network demo (kernel datapath)\n' )
52
    init()
53
    lg.setLogLevel( 'info' )
54
    scratchNet()