Statistics
| Branch: | Tag: | Revision:

mininet / examples / scratchnet.py @ 51270ce4

History | View | Annotate | Download (1.24 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.mininet import init, Node, createLink
10

    
11
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:
27
      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()
37
   
38
if __name__ == '__main__':
39
   init()   
40
   scratchNet()