Statistics
| Branch: | Tag: | Revision:

mininet / examples / emptynet.py @ 18aab5b7

History | View | Annotate | Download (960 Bytes)

1 3e6b3dd2 Bob Lantz
#!/usr/bin/python
2
3
"""
4 82b72072 Bob Lantz
This example shows how to create an empty Mininet object
5 3e6b3dd2 Bob Lantz
(without a topology object) and add nodes to it manually.
6
"""
7
8
from mininet.net import Mininet
9
from mininet.node import Controller
10
from mininet.cli import CLI
11 03e59652 Bob Lantz
from mininet.log import setLogLevel, info
12 3e6b3dd2 Bob Lantz
13
def emptyNet():
14
15
    "Create an empty network and add nodes to it."
16 82b72072 Bob Lantz
17 3e6b3dd2 Bob Lantz
    net = Mininet( controller=Controller )
18
19 03e59652 Bob Lantz
    info( '*** Adding controller\n' )
20 259d7133 Bob Lantz
    net.addController( 'c0' )
21 82b72072 Bob Lantz
22 03e59652 Bob Lantz
    info( '*** Adding hosts\n' )
23 3e6b3dd2 Bob Lantz
    h1 = net.addHost( 'h1', ip='10.0.0.1' )
24
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
25 82b72072 Bob Lantz
26 03e59652 Bob Lantz
    info( '*** Adding switch\n' )
27 3e6b3dd2 Bob Lantz
    s3 = net.addSwitch( 's3' )
28 82b72072 Bob Lantz
29 03e59652 Bob Lantz
    info( '*** Creating links\n' )
30 ecddbcf2 Brian O'Connor
    net.addLink( h1, s3 )
31
    net.addLink( h2, s3 )
32 82b72072 Bob Lantz
33 03e59652 Bob Lantz
    info( '*** Starting network\n')
34 3e6b3dd2 Bob Lantz
    net.start()
35 82b72072 Bob Lantz
36 03e59652 Bob Lantz
    info( '*** Running CLI\n' )
37 3e6b3dd2 Bob Lantz
    CLI( net )
38 82b72072 Bob Lantz
39 03e59652 Bob Lantz
    info( '*** Stopping network' )
40 3e6b3dd2 Bob Lantz
    net.stop()
41 82b72072 Bob Lantz
42 3e6b3dd2 Bob Lantz
if __name__ == '__main__':
43 03e59652 Bob Lantz
    setLogLevel( 'info' )
44 3e6b3dd2 Bob Lantz
    emptyNet()