blob: f316162a809e01cf9d1d7e3cad59fbb1f840d94b [file] [log] [blame]
tome2918e62014-09-12 18:23:20 -07001#!/usr/bin/env python
2from mininet.cli import CLI
3from mininet.net import Mininet
4from mininet.node import RemoteController, OVSKernelSwitch
5
6MAC = 12
7DPID = 16
8
9class CustomCLI(CLI):
10 """Custom CLI to allow us to add our own commands."""
11
12 def __init__ (self, net):
13 """Init method for our custom CLI."""
14 self.net = net
15 CLI.__init__(self, net)
16
17class Solar(object):
18 """ Create a tiered topology from semi-scratch in Mininet """
19
alshabib339a3d92014-09-26 17:54:32 -070020 def __init__(self, cname='onos', cips=['192.168.56.1'], islands=3, edges=2, hosts=2):
tome2918e62014-09-12 18:23:20 -070021 """Create tower topology for mininet"""
22
23 # We are creating the controller with local-loopback on purpose to avoid
24 # having the switches connect immediately. Instead, we'll set controller
25 # explicitly for each switch after configuring it as we want.
Charles Chan45624b82015-08-24 00:29:20 +080026 self.ctrls = [ RemoteController(cname, cip, 6653) for cip in cips ]
alshabib339a3d92014-09-26 17:54:32 -070027 self.net = Mininet(controller=RemoteController, switch = OVSKernelSwitch,
tome2918e62014-09-12 18:23:20 -070028 build=False)
29
alshabib339a3d92014-09-26 17:54:32 -070030 self.cips = cips
tome2918e62014-09-12 18:23:20 -070031 self.spines = []
32 self.leaves = []
33 self.hosts = []
alshabib339a3d92014-09-26 17:54:32 -070034 for ctrl in self.ctrls:
35 self.net.addController(ctrl)
tome2918e62014-09-12 18:23:20 -070036
37 # Create the two core switches and links between them
38 c1 = self.net.addSwitch('c1',dpid='1111000000000000')
39 c2 = self.net.addSwitch('c2',dpid='2222000000000000')
40 self.spines.append(c1)
41 self.spines.append(c2)
42
43 self.net.addLink(c1, c2)
44 self.net.addLink(c2, c1)
45
46 for i in range(1, islands + 1):
47 sc = self.createSpineClump(i, edges, hosts)
48 self.net.addLink(c1, sc[0])
49 self.net.addLink(c2, sc[0])
50 self.net.addLink(c1, sc[1])
51 self.net.addLink(c2, sc[1])
52
53 def createSpineClump(self, island, edges, hosts):
54 """ Creates a clump of spine and edge switches with hosts"""
55 s1 = self.net.addSwitch('s%1d1' % island,dpid='00000%1d0100000000' % island)
56 s2 = self.net.addSwitch('s%1d2' % island,dpid='00000%1d0200000000' % island)
57 self.net.addLink(s1, s2)
58 self.net.addLink(s2, s1)
59
60 for i in range(1, edges + 1):
61 es = self.createEdgeSwitch(island, i, hosts)
62 self.net.addLink(es, s1)
63 self.net.addLink(es, s2)
64
65 self.spines.append(s1)
66 self.spines.append(s2)
67
68 clump = []
69 clump.append(s1)
70 clump.append(s2)
71 return clump
72
73 def createEdgeSwitch(self, island, index, hosts):
74 """ Creates an edge switch in an island and ads hosts to it"""
75 sw = self.net.addSwitch('e%1d%1d' % (island, index),dpid='0000000%1d0000000%1d' % (island, index))
76 self.leaves.append(sw)
77
78 for j in range(1, hosts + 1):
79 host = self.net.addHost('h%d%d%d' % (island, index, j),ip='10.%d.%d.%d' % (island, index, j))
80 self.net.addLink(host, sw)
81 self.hosts.append(host)
82 return sw
83
84 def run(self):
85 """ Runs the created network topology and launches mininet cli"""
alshabib339a3d92014-09-26 17:54:32 -070086 self.net.build()
87 self.net.start()
tome2918e62014-09-12 18:23:20 -070088 CustomCLI(self.net)
89 self.net.stop()
90
tome2918e62014-09-12 18:23:20 -070091 def pingAll(self):
92 """ PingAll to create flows - for unit testing """
93 self.net.pingAll()
94
95 def stop(self):
96 "Stops the topology. You should call this after run_silent"
97 self.net.stop()