Statistics
| Branch: | Tag: | Revision:

mininet / examples / scratchnetuser.py @ 98332cb6

History | View | Annotate | Download (1.37 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 cusomization.
7

8
This version uses the user datapath.
9
"""
10

    
11
from mininet import init, Node, createLink
12

    
13
def scratchNet( cname='controller', cargs='ptcp:'):
14
   # Create Network
15
   controller = Node( 'c0' )
16
   switch = Node( 's0')
17
   h0 = Node( 'h0' )
18
   h1 = Node( 'h1' )
19
   createLink( controller, switch )
20
   createLink( h0, switch )
21
   createLink( h1, switch )
22
   # Configure control network
23
   controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' )
24
   switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' )
25
   # Configure hosts
26
   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
27
   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
28
   # Start network using user datapath
29
   controller.cmdPrint( cname + ' ' + cargs + '&' )
30
   switch.cmdPrint( 'ifconfig lo 127.0.0.1' )
31
   switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ]) 
32
      + ' ptcp: &' )
33
   switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
34
   # Run test
35
   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
36
   # Stop network
37
   controller.cmdPrint( 'kill %' + cname)
38
   switch.cmdPrint( 'kill %ofdatapath' )
39
   switch.cmdPrint( 'kill %ofprotocol' )
40
   
41
if __name__ == '__main__':
42
   init()   
43
   scratchNet()