-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology.py
36 lines (30 loc) · 1010 Bytes
/
topology.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
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.cli import CLI
# Create a custom topology
class MyTopology(Topo):
def build(self):
# Add switches
s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')
# Add hosts
h1 = self.addHost('h1', mac ="00:00:00:00:00:01")
h2 = self.addHost('h2', mac ="00:00:00:00:00:02")
h3 = self.addHost('h3', mac ="00:00:00:00:00:03")
h4 = self.addHost('h4', mac ="00:00:00:00:00:04")
h5 = self.addHost('h5', mac ="00:00:00:00:00:05")
# Connect hosts to the switch
self.addLink(h1, s1)
self.addLink(h2, s1)
self.addLink(h3, s1)
self.addLink(s1, s2)
self.addLink(s2, h4)
self.addLink(s2, h5)
if __name__ == '__main__':
topo = MyTopology()
c1 = RemoteController('c1', ip='127.0.0.1')
net = Mininet(topo=topo, controller=c1)
net.start()
CLI(net)
net.stop()