blob: 63e84961d15a51b3af198429549e2ee9af094c1a [file] [log] [blame]
Tom Tofighfad498b2014-10-29 12:06:24 -07001#!/usr/bin/env python
2
3''' file: custom/optical.py '''
4
5from mininet.topo import Topo
6from mininet.net import Mininet
7from mininet.cli import CLI
8from mininet.log import setLogLevel, info
9from mininet.util import irange
10
11class OpticalTopo( Topo ):
12
13 def build( self, n=3, tapStart=3 ):
14
15 # Add hosts and switches
16 hosts = []
17 switches = []
18 for i in irange( 1, n ):
19 h = self.addHost( 'h%d' % i )
20 s = self.addSwitch( 's%d' % i )
21 self.addLink( h, s )
22 hosts.append( h )
23 switches.append( s )
24
25 # Add optical tap interfaces
26 tapNum = tapStart
27 for sw in switches:
28 self.addLink( sw, sw, intfName1='%s-eth0' % sw, intfName2='tap%d' % tapNum )
29 tapNum += 1
30
31# if you use, sudo mn --custom custom/optical.py, then register the topo:
32#sudo mn --custom optical-topo.py --topo optical,5
33topos = { 'optical': OpticalTopo }
34
35def installStaticFlows( net ):
36 for swName in [ 's1', 's2', 's3', 's4', 's5', 's6' ]:
37 info( 'Adding flows to %s...' % swName )
38 sw = net[ swName ]
39 sw.dpctl( 'add-flow', 'in_port=1,actions=output=2' )
40 sw.dpctl( 'add-flow', 'in_port=2,actions=output=1' )
41 info( sw.dpctl( 'dump-flows' ) )
42
43def run():
44 net = Mininet( topo=OpticalTopo() )
45 net.start()
46 #installStaticFlows( net )
47 CLI( net )
48 net.stop()
49
50# if the script is run directly (sudo custom/optical.py):
51if __name__ == '__main__':
52 setLogLevel( 'info' )
53 run()