-
Notifications
You must be signed in to change notification settings - Fork 1
/
topo.py
59 lines (47 loc) · 1.52 KB
/
topo.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
59
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.util import dumpNodeConnections
from mininet.clean import cleanup
import utils
class MyTopo(Topo):
def build(self):
links = utils.load_data("topology.txt", duplicate_entries=False)
for link in links:
nodes = [None] * 2
for i in range(2):
if link[i][0] == "h":
nodes[i] = self.addHost(link[i])
else:
nodes[i] = self.addSwitch(link[i])
self.addLink(nodes[0], nodes[1], bw=links[link][0], delay=links[link][1])
def main():
pass
def run():
topo = MyTopo()
net = Mininet(
topo=topo,
autoSetMacs=True,
controller=lambda name: RemoteController(name, ip="127.0.0.1", port=6633),
autoStaticArp=True,
)
net.start()
print("Dumping host connections")
dumpNodeConnections(net.hosts)
for host in net.hosts:
for intf in host.intfList():
print(f"{intf.name} MAC address: {intf.MAC()} IP address: {intf.IP()}")
print()
for switch in net.switches:
for intf in switch.intfList():
if intf.MAC() is not None:
print(f"{intf.name} MAC address: {intf.MAC()}")
CLI(net)
net.stop()
if __name__ == "__main__":
cleanup()
setLogLevel("info") # Tell mininet to print useful information
run()
cleanup()