blob: 245d449d48d5842c00b7e9344dce18d009d06882 [file] [log] [blame]
Tom Tofigh312ceb22014-11-12 15:44:52 -08001#!/usr/bin/env python
2
3''' file: custom/optical.py '''
4from mininet.node import RemoteController
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
11switches = []
12
13class OpticalTopo( Topo ):
14
15 def build( self, n=6, tapStart=29 ):
16 global switches
17 # Add hosts and switches
18 hosts = []
19 switches = []
20 for i in irange( 1, n ):
21 h = self.addHost( 'h%d' % i )
22 s = self.addSwitch( 's%d' % i, dpid='0000ffffffff%04d' % i )
23 self.addLink( h, s )
24 hosts.append( h )
25 switches.append( s )
26
27 # Add optical tap interfaces
28 tapNum = tapStart
29 #for sw in switches:
30 # self.addLink( sw, sw, intfName1='%s-eth0' % sw, intfName2='tap%d' % tapNum )
31 #Add tap interface up
32 #sudo ip link set dev tap25 up
33 # tapNum += 1
34
35# if you use, sudo mn --custom custom/optical.py, then register the topo:
36#sudo mn --custom ~/mininet/custom/optical-2.py --topo optical,6 --controller=remote
37#sudo ./mininet/custom/optical-2.py
38topos = { 'optical': OpticalTopo }
39
40def installStaticFlows( net ):
41 for swName in [ 's1', 's2', 's3', 's4', 's5', 's6' ]:
42 info( 'Adding flows to %s...' % swName )
43 sw = net[ swName ]
44 sw.dpctl( 'add-flow', 'in_port=1,actions=output=2' )
45 sw.dpctl( 'add-flow', 'in_port=2,actions=output=1' )
46 info( sw.dpctl( 'dump-flows' ) )
47
48def run():
49 net = Mininet( topo=OpticalTopo(), controller=RemoteController )
50 net.start()
51 #installStaticFlows( net )
52 tapStart = 29
53 for sw in switches:
54 net.get(sw).attach( 'tap%d' %tapStart )
55 tapStart += 1
56 CLI( net )
57 net.stop()
58
59# if the script is run directly (sudo custom/optical.py):
60if __name__ == '__main__':
61 setLogLevel( 'info' )
62 run()