carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | This example shows how to create an empty Mininet object |
| 5 | (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 | from mininet.log import setLogLevel, info |
| 12 | |
| 13 | def emptyNet(): |
| 14 | |
| 15 | "Create an empty network and add nodes to it." |
| 16 | |
| 17 | net = Mininet( controller=Controller ) |
| 18 | |
| 19 | info( '*** Adding controller\n' ) |
| 20 | net.addController( 'c0' ) |
| 21 | |
| 22 | info( '*** Adding hosts\n' ) |
| 23 | h1 = net.addHost( 'h1', ip='10.0.0.1' ) |
| 24 | h2 = net.addHost( 'h2', ip='10.0.0.2' ) |
| 25 | |
| 26 | info( '*** Adding switch\n' ) |
| 27 | s3 = net.addSwitch( 's3' ) |
| 28 | |
| 29 | info( '*** Creating links\n' ) |
| 30 | h1.linkTo( s3 ) |
| 31 | h2.linkTo( s3 ) |
| 32 | |
| 33 | info( '*** Starting network\n') |
| 34 | net.start() |
| 35 | |
| 36 | info( '*** Running CLI\n' ) |
| 37 | CLI( net ) |
| 38 | |
| 39 | info( '*** Stopping network' ) |
| 40 | net.stop() |
| 41 | |
| 42 | if __name__ == '__main__': |
| 43 | setLogLevel( 'info' ) |
| 44 | emptyNet() |