blob: d8e83a10a9a39750c9adbbf28a1104639edba348 [file] [log] [blame]
#!/usr/bin/env python
from mininet.cli import CLI
from import Mininet
from mininet.node import RemoteController, OVSKernelSwitch
MAC = 12
DPID = 16
class CustomCLI(CLI):
"""Custom CLI to allow us to add our own commands."""
def __init__ (self, net):
"""Init method for our custom CLI.""" = net
CLI.__init__(self, net)
class Solar(object):
""" Create a tiered topology from semi-scratch in Mininet """
def __init__(self, cname='onos', cip='', islands=3, edges=2, hosts=2,
"""Create tower topology for mininet"""
# We are creating the controller with local-loopback on purpose to avoid
# having the switches connect immediately. Instead, we'll set controller
# explicitly for each switch after configuring it as we want.
self.flare = RemoteController(cname, cip, 6633) = Mininet(controller=self.flare, switch = OVSKernelSwitch,
self.cip = cip
self.spines = []
self.leaves = []
self.hosts = []
self.proto = proto
# Create the two core switches and links between them
c1 ='c1',dpid='1111000000000000')
c2 ='c2',dpid='2222000000000000')
self.spines.append(c2), c2), c1)
for i in range(1, islands + 1):
sc = self.createSpineClump(i, edges, hosts), sc[0]), sc[0]), sc[1]), sc[1])
def createSpineClump(self, island, edges, hosts):
""" Creates a clump of spine and edge switches with hosts"""
s1 ='s%1d1' % island,dpid='00000%1d0100000000' % island)
s2 ='s%1d2' % island,dpid='00000%1d0200000000' % island), s2), s1)
for i in range(1, edges + 1):
es = self.createEdgeSwitch(island, i, hosts), s1), s2)
clump = []
return clump
def createEdgeSwitch(self, island, index, hosts):
""" Creates an edge switch in an island and ads hosts to it"""
sw ='e%1d%1d' % (island, index),dpid='0000000%1d0000000%1d' % (island, index))
for j in range(1, hosts + 1):
host ='h%d%d%d' % (island, index, j),ip='10.%d.%d.%d' % (island, index, j)), sw)
return sw
def run(self):
""" Runs the created network topology and launches mininet cli"""
def run_silent(self):
""" Runs silently - for unit testing """
# Start the switches, configure them with desired protocols and only
# then set the controller
for sw in self.spines:
if self.proto:
sw.cmd('ovs-vsctl set bridge %(sw)s protocols=%(proto)s' % \
{ 'sw':, 'proto': self.proto})
sw.cmdPrint('ovs-vsctl set-controller %(sw)s tcp:%(ctl)s:6633' % \
{'sw':, 'ctl': self.cip})
for sw in self.leaves:
sw.cmdPrint('ovs-vsctl set-controller %(sw)s tcp:%(ctl)s:6633' % \
{'sw':, 'ctl': self.cip})
def pingAll(self):
""" PingAll to create flows - for unit testing """
def stop(self):
"Stops the topology. You should call this after run_silent"