-
Notifications
You must be signed in to change notification settings - Fork 2
/
mesh_network.py
executable file
·73 lines (56 loc) · 1.83 KB
/
mesh_network.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
class MeshTopo(Topo):
"""
Define a sample topology with 5 hosts and 5 switches.
The topology is a mesh topology.
"""
def __init__(self):
# Initialize topology
Topo.__init__(self)
# Create template host, switch, and link
host_config = dict(inNamespace=True)
"""Hosts configuration"""
link_config = dict(bw=10)
"""Switch-Switch links configuration"""
host_link_config = dict()
"""Host-Switch links configuration"""
switches = []
"""List of switches"""
hosts = []
"""List of hosts"""
# Create switch nodes
for i in range(5):
sconfig = {"dpid": "%016x" % (i + 1)}
switches.append(self.addSwitch("s%d" % (i + 1), **sconfig))
# Create host nodes
for i in range(5):
hosts.append(self.addHost("h%d" % (i + 1), **host_config))
# Add switch links
for i in range(0, len(switches)):
for j in range(i+1, len(switches)):
self.addLink(switches[i], switches[j], **link_config)
# Add host links
for i in range(0, len(hosts)):
self.addLink(hosts[i], switches[i], **host_link_config)
topos = {"meshtopo": (lambda: MeshTopo())}
if __name__ == "__main__":
topo = MeshTopo()
net = Mininet(
topo=topo,
switch=OVSKernelSwitch,
build=False,
autoSetMacs=True,
autoStaticArp=True,
link=TCLink,
)
controller = RemoteController("c1", ip="127.0.0.1", port=6633)
net.addController(controller)
net.build()
net.start()
CLI(net)
net.stop()