Merge pull request #174 from pantuza/master

Dynamic Network with Remote Controller example; Extended LinearTopo
This commit is contained in:
Brian O'Connor
2013-07-22 22:14:03 -07:00
3 changed files with 73 additions and 6 deletions
+5
View File
@@ -118,3 +118,8 @@ This example attempts to create a 1024-host network, and then runs the
CLI on it. It may run into scalability limits, depending on available
memory and sysctl configuration (see INSTALL.)
dynamicnet.py:
This example builds a network based on command line arguments and uses
a remote controller. It is a good option to use with POX controller and
develop Software Defined Networks.
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/python
"""
This script builds a network using mininet for using with
a remote controller like POX.
The script receives from command line two arguments. The number
of Switches and the number of Hosts per Switch. Then, it will build
the network topology based on this arguments.
First of all, it build a topology and add the Switches to the network.
After that, add the same number of Hosts for each Switch added. Lastly
it make links between each switch.
@author: Gustavo Pantuza
@since: 18.07.2013
"""
from optparse import OptionParser
from mininet.topo import LinearTopo
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.node import RemoteController
def main():
# Defines the log level
setLogLevel('info')
# parses command line arguments
parser = OptionParser()
parser.add_option('-H', dest='hosts', default=5,
help='Number of hosts per switch')
parser.add_option('-S', dest='switches', default=2,
help='Number of switches')
(options, args) = parser.parse_args()
# Build network topology (see mininet/topo.py)
topo = LinearTopo(int(options.switches), int(options.hosts))
# Creates the Network using a remote controller
net = Mininet(topo,
controller=lambda a: RemoteController(a, ip='127.0.0.1'))
# Starts the network
net.start()
# Run the mininet client
CLI(net)
# Stop the network
net.stop()
if __name__ == "__main__":
main()
+13 -6
View File
@@ -236,23 +236,30 @@ class SingleSwitchReversedTopo(Topo):
port1=0, port2=(k - h + 1))
class LinearTopo(Topo):
"Linear topology of k switches, with one host per switch."
"Linear topology of k switches, with n hosts per switch."
def __init__(self, k=2, **opts):
def __init__(self, k=2, n=1, **opts):
"""Init.
k: number of switches (and hosts)
k: number of switches
n: number of hosts per switch
hconf: host configuration options
lconf: link configuration options"""
super(LinearTopo, self).__init__(**opts)
self.k = k
self.n = n
lastSwitch = None
for i in irange(1, k):
host = self.addHost('h%s' % i)
# Add switch
switch = self.addSwitch('s%s' % i)
self.addLink( host, switch)
# Add hosts to switch
for j in irange(1, n):
hostNum = (i-1)*n + j
host = self.addHost('h%s' % hostNum)
self.addLink(host, switch)
# Connect switch to previous
if lastSwitch:
self.addLink( switch, lastSwitch)
self.addLink(switch, lastSwitch)
lastSwitch = switch