From 3e6b3dd273d5dce954188d2d54db38dba576cd1b Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Sat, 10 Apr 2010 19:29:04 -0700 Subject: [PATCH] Added an example of how to make an empty Mininet and add things to it. --- examples/emptynet.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 examples/emptynet.py diff --git a/examples/emptynet.py b/examples/emptynet.py new file mode 100755 index 0000000..496c38e --- /dev/null +++ b/examples/emptynet.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +""" +This example shows how to create an empty Mininet() object +(without a topology object) and add nodes to it manually. +""" + +from mininet.net import Mininet +from mininet.node import Controller +from mininet.cli import CLI +from mininet.log import setLogLevel + +def emptyNet(): + + "Create an empty network and add nodes to it." + + net = Mininet( controller=Controller ) + + print "*** Adding controller" + c0 = net.addController( 'c0' ) + + print "*** Adding hosts" + h1 = net.addHost( 'h1', ip='10.0.0.1' ) + h2 = net.addHost( 'h2', ip='10.0.0.2' ) + + print "*** Adding switch" + s3 = net.addSwitch( 's3' ) + + print "*** Creating links" + h1.linkTo( s3 ) + h2.linkTo( s3 ) + + print "*** Starting network" + net.build() + net.start() + + print "*** Running CLI" + setLogLevel( 'info' ) + CLI( net ) + + print "*** Stopping network" + net.stop() + +if __name__ == '__main__': + emptyNet()