adding parametrized optical topo to test/topos
Change-Id: I508656e12db611d6e525e37a73f8b1f0faea5e0d
Showing
1 changed file
with
53 additions
and
0 deletions
tools/test/topos/optical-topo.py
0 → 100755
| 1 | +#!/usr/bin/env python | ||
| 2 | + | ||
| 3 | +''' file: custom/optical.py ''' | ||
| 4 | + | ||
| 5 | +from mininet.topo import Topo | ||
| 6 | +from mininet.net import Mininet | ||
| 7 | +from mininet.cli import CLI | ||
| 8 | +from mininet.log import setLogLevel, info | ||
| 9 | +from mininet.util import irange | ||
| 10 | + | ||
| 11 | +class 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 | ||
| 33 | +topos = { 'optical': OpticalTopo } | ||
| 34 | + | ||
| 35 | +def 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 | + | ||
| 43 | +def 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): | ||
| 51 | +if __name__ == '__main__': | ||
| 52 | + setLogLevel( 'info' ) | ||
| 53 | + run() |
-
Please register or login to post a comment