-
Notifications
You must be signed in to change notification settings - Fork 1
/
stp3.py
54 lines (42 loc) · 1.42 KB
/
stp3.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
#!/usr/bin/python
from __future__ import print_function
import os
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
from mininet.cli import CLI
from mininet.link import Intf
from mininet.node import Controller
class NetworkTopo( Topo ):
# Builds network topology with a loop
def build( self, **_opts ):
# Adding legacy switches
s1, s2, s3 = [ self.addSwitch( s, failMode='standalone' )
for s in ( 's1', 's2', 's3' ) ]
# Creating links
self.addLink( s1, s2 )
self.addLink( s2, s3 )
self.addLink( s3, s1 )
# Adding hosts
h1 = self.addHost( 'h1' )
h2 = self.addHost( 'h2' )
h3 = self.addHost( 'h3' )
h4 = self.addHost( 'h4' )
h5 = self.addHost( 'h5' )
h6 = self.addHost( 'h6' )
# Connecting hosts to switches
for h, s in [ (h1, s1), (h2, s1), (h3, s2), (h4, s2), (h5, s3), (h6, s3) ]:
self.addLink( h, s )
def run():
topo = NetworkTopo()
net = Mininet( topo=topo, controller=None )
net.start()
net['s1'].cmd('ovs-vsctl set bridge s1 stp-enable=true')
net['s2'].cmd('ovs-vsctl set bridge s2 stp-enable=true')
net['s3'].cmd('ovs-vsctl set bridge s3 stp-enable=true')
CLI( net )
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
run()