-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj-topo-v2.py
67 lines (51 loc) · 1.99 KB
/
proj-topo-v2.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
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
def myNetwork():
net = Mininet(switch=OVSSwitch)
info('*** Adding controller\n')
c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633)
info('*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSSwitch, stp=True)
s2 = net.addSwitch('s2', cls=OVSSwitch, stp=True)
s3 = net.addSwitch('s3', cls=OVSSwitch, stp=True)
s4 = net.addSwitch('s4', cls=OVSSwitch, stp=True)
s5 = net.addSwitch('s5', cls=OVSSwitch, stp=True)
info('*** Add hosts\n')
h1 = net.addHost('h1', ip='10.0.1.1')
h2 = net.addHost('h2', ip='10.0.2.1')
h3 = net.addHost('h3', ip='10.0.3.1')
info('*** Add links\n')
net.addLink(s5, s1, port1=4, port2=4)
net.addLink(h3, s5, port2=1)
net.addLink(s5, s3, port2=1)
net.addLink(s5, s4, port2=1)
net.addLink(s2, s3, port1=1)
net.addLink(s1, s2, port1=1)
net.addLink(s1, s4, port1=2)
# net.addLink(s5, s1, port1=4)
net.addLink(h1, s1)
net.addLink(h2, s1)
info('*** Starting controllers\n')
s2.start([c0])
info('*** Starting network\n')
net.start()
s1.cmd('ovs-vsctl set bridge s1 stp_enable=true')
s2.cmd('ovs-vsctl set bridge s2 stp_enable=true')
s3.cmd('ovs-vsctl set bridge s3 stp_enable=true')
s4.cmd('ovs-vsctl set bridge s4 stp_enable=true')
s5.cmd('ovs-vsctl set bridge s5 stp_enable=true')
# h1.cmd('ifconfig h1-eth0 10.0.1.0')
# h1.cmd('route add default gw 10.0.1.0')
# h2.cmd('ifconfig h2-eth0 10.0.2.0')
# h2.cmd('route add default gw 10.0.2.0')
# h3.cmd('ifconfig h3-eth0 10.0.3.0')
# h3.cmd('route add default gw 10.0.3.0')
info('*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel('info')
myNetwork()