Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 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.link import Intf, Link |
| 10 | from mininet.node import RemoteController |
| 11 | |
| 12 | class NullIntf( Intf ): |
| 13 | "A dummy interface with a blank name that doesn't do any configuration" |
| 14 | def __init__( self, name, **params ): |
| 15 | self.name = '' |
| 16 | |
| 17 | class NullLink( Link ): |
| 18 | "A dummy link that doesn't touch either interface" |
Praseed Balakrishnan | c002965 | 2014-11-14 13:38:49 -0800 | [diff] [blame] | 19 | def makeIntfPair( cls, intf1, intf2, *args, **kwargs ): |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 20 | pass |
| 21 | def delete( self ): |
| 22 | pass |
| 23 | |
| 24 | class OpticalTopo(Topo): |
| 25 | def addIntf( self, switch, intfName ): |
| 26 | "Add intf intfName to switch" |
| 27 | self.addLink( switch, switch, cls=NullLink, |
| 28 | intfName1=intfName, cls2=NullIntf ) |
| 29 | def __init__(self): |
| 30 | |
| 31 | # Initialize topology |
| 32 | Topo.__init__(self) |
| 33 | |
| 34 | # Add hosts and switches |
| 35 | h1 = self.addHost('h1') |
| 36 | h2 = self.addHost('h2') |
| 37 | h3 = self.addHost('h3') |
| 38 | h4 = self.addHost('h4') |
| 39 | h5 = self.addHost('h5') |
| 40 | h6 = self.addHost('h6') |
| 41 | |
Praseed Balakrishnan | 56051d0 | 2014-11-14 09:56:04 -0800 | [diff] [blame] | 42 | s1 = self.addSwitch('s1', dpid="0000ffffffff0001") |
| 43 | s2 = self.addSwitch('s2', dpid="0000ffffffff0002") |
| 44 | s3 = self.addSwitch('s3', dpid="0000ffffffff0003") |
| 45 | s4 = self.addSwitch('s4', dpid="0000ffffffff0004") |
| 46 | s5 = self.addSwitch('s5', dpid="0000ffffffff0005") |
| 47 | s6 = self.addSwitch('s6', dpid="0000ffffffff0006") |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 48 | |
| 49 | |
| 50 | # Add links from hosts to OVS |
| 51 | self.addLink(s1, h1) |
| 52 | self.addLink(s2, h2) |
| 53 | self.addLink(s3, h3) |
| 54 | self.addLink(s4, h4) |
| 55 | self.addLink(s5, h5) |
| 56 | self.addLink(s6, h6) |
| 57 | |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 58 | # add links from ovs to linc-oe |
| 59 | # sorry about the syntax :( |
Praseed Balakrishnan | 56051d0 | 2014-11-14 09:56:04 -0800 | [diff] [blame] | 60 | self.addIntf(s1,'tap29') |
| 61 | self.addIntf(s2,'tap30') |
| 62 | self.addIntf(s3,'tap31') |
| 63 | self.addIntf(s4,'tap32') |
| 64 | self.addIntf(s5,'tap33') |
| 65 | self.addIntf(s6,'tap34') |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 66 | |
Praseed Balakrishnan | 56051d0 | 2014-11-14 09:56:04 -0800 | [diff] [blame] | 67 | # if you use, sudo mn --custom custom/optical.py, then register the topo: |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 68 | topos = {'optical': ( lambda: OpticalTopo() )} |
| 69 | |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 70 | |
| 71 | def run(): |
Thomas Vachuska | 9feadc2 | 2014-11-18 12:42:26 -0800 | [diff] [blame] | 72 | c = RemoteController('c','127.0.0.1',6633) |
Praseed Balakrishnan | 56051d0 | 2014-11-14 09:56:04 -0800 | [diff] [blame] | 73 | net = Mininet( topo=OpticalTopo(),controller=None,autoSetMacs=True) |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 74 | net.addController(c) |
| 75 | net.start() |
| 76 | |
Praseed Balakrishnan | d94df30 | 2014-11-12 17:20:16 -0800 | [diff] [blame] | 77 | #installStaticFlows( net ) |
| 78 | CLI( net ) |
| 79 | net.stop() |
| 80 | |
| 81 | # if the script is run directly (sudo custom/optical.py): |
| 82 | if __name__ == '__main__': |
| 83 | setLogLevel('info') |
| 84 | run() |