/
clos.py
executable file
·58 lines (49 loc) · 1.94 KB
/
clos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
import sys
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.node import OVSSwitch
from mininet.node import Controller, OVSController
from mininet.util import dumpNodeConnections
class STPSwitch(OVSSwitch):
prio = 1000
def start(self, *args, **kwargs):
OVSSwitch.start(self, *args, **kwargs )
STPSwitch.prio += 1
self.cmd ('ovs-vsctl set-fail-mode', self, 'standalone')
self.cmd('ovs-vsctl set Bridge', self, 'stp_enable=true', 'other_config:stp-priority=%d' % STPSwitch.prio)
switches = {'ovs-stp': STPSwitch}
class clos(Topo):
def __init__(self, numberOfLeafs, numberOfSpines, *args, **kwargs):
Topo.__init__(self, *args, **kwargs)
spines = self.create(self.addSwitch, "spine", numberOfSpines, False)
leafs = self.create(self.addSwitch, "leaf", numberOfLeafs, False)
hosts = self.create(self.addHost, "host", numberOfLeafs, True)
self.link(spines, leafs, hosts)
def create(self, func, prefix, numberOfDevices, routed):
devices = list()
for i in range(0, numberOfDevices):
if (routed == True):
devices.append (func(prefix + str(i + 1), ip='10.0.0.' + str(i + 1)))
else:
devices.append(func(prefix + str(i + 1)))
return devices
def link(self, spines, leafs, hosts):
index = 0
for leaf in leafs:
host = hosts[index]
self.addLink(leaf, host)
index += 1
for spine in spines:
self.addLink(leaf, spine)
topos = { 'clos': clos}
def initWithParams(numberOfSpines, numberOfLeafs):
topo = clos(numberOfSpines, numberOfLeafs)
net = Mininet(topo=topo,controller=OVSController, switch=STPSwitch)
net.start()
dumpNodeConnections(net.values())
CLI(net)
net.stop()
if __name__ == '__main__':
initWithParams(int(sys.argv[1]), int(sys.argv[2]))