blob: 300332aa2778ba5fc65b3f26397a4a2cdd336746 [file] [log] [blame]
Thomas Vachuska88dbd492014-10-29 13:04:27 -07001#!/usr/bin/env python
2
3''' file: optical.py '''
4
5from mininet.topo import Topo
6from mininet.node import RemoteController
7from mininet.net import Mininet
8from mininet.cli import CLI
9from mininet.log import setLogLevel, info
10from mininet.link import Intf, Link
11from mininet.util import irange
12
13class NullIntf( Intf ):
14 "A dummy interface with a blank name that doesn't do any configuration"
15 def __init__( self, name, **params ):
16 self.name = ''
17
18class NullLink( Link ):
19 "A dummy link that doesn't touch either interface"
20 def makeIntfPair( cls, intf1, intf2, addr1=None, addr2=None ):
21 pass
22 def delete( self ):
23 pass
24
25class OpticalTopo( Topo ):
26
27 def addIntf( self, switch, intfName ):
28 "Add intf intfName to switch"
29 self.addLink( switch, switch, cls=NullLink,
30 intfName1=intfName, cls2=NullIntf, intfName2=intfName )
31
32 def build( self, n=2, tapStart=3 ):
33
34 # Add hosts and switches
35 hosts = []
36 switches = []
37 for i in irange( 1, n ):
38 h = self.addHost( 'h%d' % i )
39 s = self.addSwitch( 's%d' % i, dpid="0000ffffffff%04d" % i )
40 self.addLink( h, s )
41 hosts.append( h )
42 switches.append( s )
43
44 # Add optical tap interfaces
45 tapNum = tapStart
46 for sw in switches:
47 self.addIntf( sw, 'tap%d' % tapNum )
48 tapNum += 1
49
50# if you use, sudo mn --custom custom/optical.py, then register the topo:
51#sudo mn --custom optical.py --topo optical,5
52topos = { 'optical': OpticalTopo }
53
54def installStaticFlows( net ):
55 for sw in net.switches:
56 info( 'Adding flows to %s...' % sw.name )
57 sw.dpctl( 'add-flow', 'in_port=1,actions=output=2' )
58 sw.dpctl( 'add-flow', 'in_port=2,actions=output=1' )
59 info( sw.dpctl( 'dump-flows' ) )
60
61def run( n ):
62 topo = OpticalTopo( n )
63 net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
64 net.start()
65 #installStaticFlows( net )
66 CLI( net )
67 net.stop()
68
69# if the script is run directly (sudo custom/optical.py):
70if __name__ == '__main__':
71 import sys
72 try:
73 n = int( sys.argv[1] )
74 except:
75 print ( 'Usage: ./optical.py n # n is number of switches\n'
76 'Starting with default of 2 switches...\n' )
77 n = 2
78 setLogLevel( 'info' )
79 run( n )