-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtopo.py
More file actions
executable file
·49 lines (41 loc) · 1.82 KB
/
topo.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.82 KB
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
#!/usr/bin/env python
"""
FattreeTopology: creates a simple fattree topology with N edge switches
connected to N-1 core switches. Each edge switch connects to 2 hosts.
"""
from mininet.topo import Topo
class FattreeTopology(Topo):
def build(self, numEdgeSwitches=2, bw=20, hostsPerEdge=2):
linkopts = dict(bw=bw, delay='1ms', max_queue_size=500, loss=0, use_htb=True)
numHosts = numEdgeSwitches * hostsPerEdge
numCoreSwitches = numEdgeSwitches - 1
hostIds = range(1, numHosts+1)
firstSwitch = max(101, numHosts+1)
edgeSwitchIds = range(firstSwitch, numEdgeSwitches + firstSwitch)
coreSwitchIds= range(numEdgeSwitches + firstSwitch,
numEdgeSwitches + firstSwitch + numCoreSwitches)
self._coreSwitches = []
self._edgeSwitches = []
self._hosts = []
self._links = {}
for s in coreSwitchIds:
switch = self.addSwitch('s%s' % s, protocols='OpenFlow13')
self._coreSwitches.append(switch)
self._links[switch] = []
for s in edgeSwitchIds:
switch = self.addSwitch('s%s' % s, protocols='OpenFlow13')
self._edgeSwitches.append(switch)
self._links[switch] = []
for i, s1 in enumerate(self._coreSwitches):
for j, s2 in enumerate(self._edgeSwitches):
self.addLink(s1, s2, **linkopts)
self._links[s1].append(s2)
self._links[s2].append(s1)
for i, h in enumerate(hostIds):
host = self.addHost('h%s' % h)
self._hosts.append(host)
switchNum = firstSwitch + (h % numEdgeSwitches)
switch = "s%s" % switchNum
self.addLink(switch, host, **linkopts)
self._links[host] = [switch]
self._links[switch].append(host)