mininet / examples / scratchnetuser.py @ 51270ce4
History | View | Annotate | Download (1.65 KB)
1 | 98332cb6 | Bob Lantz | #!/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 | 696a619d | Bob Lantz | but it exposes the configuration details and allows customization.
|
7 | 98332cb6 | Bob Lantz |
|
8 | This version uses the user datapath.
|
||
9 | """
|
||
10 | |||
11 | 51270ce4 | Brandon Heller | from mininet.mininet import init, Node, createLink |
12 | 98332cb6 | Bob Lantz | |
13 | 696a619d | Bob Lantz | def scratchNetUser( cname='controller', cargs='ptcp:'): |
14 | 98332cb6 | Bob Lantz | # Create Network
|
15 | 696a619d | Bob Lantz | # It's not strictly necessary for the controller and switches
|
16 | # to be in separate namespaces. For performance, they probably
|
||
17 | # should be in the root namespace. However, it's interesting to
|
||
18 | # see how they could work even if they are in separate namespaces.
|
||
19 | 98332cb6 | Bob Lantz | controller = Node( 'c0' )
|
20 | switch = Node( 's0')
|
||
21 | h0 = Node( 'h0' )
|
||
22 | h1 = Node( 'h1' )
|
||
23 | createLink( controller, switch ) |
||
24 | createLink( h0, switch ) |
||
25 | createLink( h1, switch ) |
||
26 | # Configure control network
|
||
27 | controller.setIP( controller.intfs[ 0 ], '10.0.123.1', '/24' ) |
||
28 | switch.setIP( switch.intfs[ 0 ], '10.0.123.2', '/24' ) |
||
29 | # Configure hosts
|
||
30 | h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' ) |
||
31 | h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' ) |
||
32 | # Start network using user datapath
|
||
33 | controller.cmdPrint( cname + ' ' + cargs + '&' ) |
||
34 | switch.cmdPrint( 'ifconfig lo 127.0.0.1' )
|
||
35 | switch.cmdPrint( 'ofdatapath -i ' + ','.join( switch.intfs[ 1: ]) |
||
36 | + ' ptcp: &' )
|
||
37 | switch.cmdPrint( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' ) |
||
38 | # Run test
|
||
39 | h0.cmdPrint( 'ping -c1 ' + h1.IP() )
|
||
40 | # Stop network
|
||
41 | controller.cmdPrint( 'kill %' + cname)
|
||
42 | switch.cmdPrint( 'kill %ofdatapath' )
|
||
43 | switch.cmdPrint( 'kill %ofprotocol' )
|
||
44 | |||
45 | if __name__ == '__main__': |
||
46 | init() |
||
47 | 696a619d | Bob Lantz | scratchNetUser() |