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" |
| 19 | def makeIntfPair( cls, intf1, intf2 ): |
| 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 | |
| 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") |
| 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 | |
| 58 | # temporary packet link from s1 to s2 for testing |
| 59 | # self.addLink( s1, s2 ) |
| 60 | |
| 61 | # add links from ovs to linc-oe |
| 62 | # sorry about the syntax :( |
| 63 | self.addLink(s1, s1, intfName1='s1-eth0', intfName2='tap29') |
| 64 | self.addLink(s2, s2, intfName1='s2-eth0', intfName2='tap30') |
| 65 | self.addLink(s3, s3, intfName1='s3-eth0', intfName2='tap31') |
| 66 | self.addLink(s4, s4, intfName1='s4-eth0', intfName2='tap32') |
| 67 | self.addLink(s5, s5, intfName1='s5-eth0', intfName2='tap33') |
| 68 | self.addLink(s6, s6, intfName1='s6-eth0', intfName2='tap34') |
| 69 | |
| 70 | #self.addLink(s1, s2, s3, s4, s5, s6) |
| 71 | #intfName1 = 'tap3', intfName\2 = 'tap4', intfName2 = 'tap5', |
| 72 | # intfName2 = 'tap6', intfName2 = 'tap7', intfName2 = 'tap8' |
| 73 | |
| 74 | # if you use, sudo mn --custom custom/optical.py, then register the topo: |
| 75 | topos = {'optical': ( lambda: OpticalTopo() )} |
| 76 | |
| 77 | def installStaticFlows(net): |
| 78 | for swName in ['s1', 's2', 's3', 's4', 's5', 's6']: |
| 79 | info('Adding flows to %s...' % swName) |
| 80 | sw = net[swName] |
| 81 | sw.dpctl('add-flow', 'in_port=1,actions=output=2') |
| 82 | sw.dpctl('add-flow', 'in_port=2,actions=output=1') |
| 83 | info(sw.dpctl('dump-flows')) |
| 84 | |
| 85 | |
| 86 | def run(): |
| 87 | c = RemoteController('c','10.1.8.147',6633) |
| 88 | net = Mininet( topo=OpticalTopo(),controller=None) |
| 89 | net.addController(c) |
| 90 | net.start() |
| 91 | |
| 92 | # intf1 = Intf( 'tap3', node=net.nameToNode['s1'] ) |
| 93 | # intf2 = Intf( 'tap4', node=net.nameToNode['s2'] ) |
| 94 | # net.nameToNode['s1'].attach( intf1 ) |
| 95 | # net.nameToNode['s2'].attach( intf2 ) |
| 96 | |
| 97 | #installStaticFlows( net ) |
| 98 | CLI( net ) |
| 99 | net.stop() |
| 100 | |
| 101 | # if the script is run directly (sudo custom/optical.py): |
| 102 | if __name__ == '__main__': |
| 103 | setLogLevel('info') |
| 104 | run() |