-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopologia.py
48 lines (34 loc) · 1.18 KB
/
topologia.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
from mininet.topo import Topo
class Topologia(Topo):
def build(self, switches=2):
switches = max(switches, 1)
swtches = []
for i in range(0,switches):
swtches.append(self.addSwitch("switch_{}".format(i)))
h1 = self.addHost("host_1")
h2 = self.addHost("host_2")
h3 = self.addHost("host_3")
h4 = self.addHost("host_4")
self.addLink(h1,swtches[0])
self.addLink(h2,swtches[0])
self.addLink(h3,swtches[-1])
self.addLink(h4,swtches[-1])
for i in range(0,switches-1):
self.addLink(swtches[i],swtches[i+1])
class Ejemplo(Topo):
def __init__(self):
# Initialize topology
Topo.__init__(self)
# Create switch
s1 = self.addSwitch("switch_1")
s2 = self.addSwitch("switch_2")
# Create hosts
h1 = self.addHost("host_1")
h2 = self.addHost("host_2")
h3 = self.addHost("host_3")
# Add links between switches and hosts
self.addLink(s1, s2)
self.addLink(s1, h1)
self.addLink(s1, h2)
self.addLink(s2, h3)
topos = { "tp2": Topologia ,"ejemplo" : Ejemplo}