| """Custom topology example |
| |
| Two directly connected switches plus a host for each switch: |
| |
| host --- switch --- switch --- host |
| |
| Adding the 'topos' dict with a key/value pair to generate our newly defined |
| topology enables one to pass in '--topo=mytopo' from the command line. |
| """ |
| |
| from mininet.topo import Topo |
| |
| class MyTopo( Topo ): |
| "Simple topology example." |
| |
| def __init__( self ): |
| "Create custom topo." |
| # Initialize topology |
| Topo.__init__( self ) |
| |
| # Make the middle triangle |
| leftSwitch = self.addSwitch( 's1' ) |
| rightSwitch = self.addSwitch( 's2' ) |
| topSwitch = self.addSwitch( 's3' ) |
| lefthost = self.addHost( 'h1' ) |
| righthost = self.addHost( 'h2' ) |
| tophost = self.addHost( 'h3' ) |
| self.addLink( leftSwitch, lefthost ) |
| self.addLink( rightSwitch, righthost ) |
| self.addLink( topSwitch, tophost ) |
| |
| self.addLink( leftSwitch, rightSwitch ) |
| self.addLink( leftSwitch, topSwitch ) |
| self.addLink( topSwitch, rightSwitch ) |
| |
| # Make aggregation switches |
| agg1Switch = self.addSwitch( 's4' ) |
| agg2Switch = self.addSwitch( 's5' ) |
| agg1Host = self.addHost( 'h4' ) |
| agg2Host = self.addHost( 'h5' ) |
| |
| self.addLink( agg1Switch, agg1Host ) |
| self.addLink( agg2Switch, agg2Host ) |
| |
| self.addLink( agg1Switch, rightSwitch ) |
| self.addLink( agg2Switch, leftSwitch ) |
| |
| # Make two aggregation fans |
| for i in range(10): |
| switch = self.addSwitch( 's%d' % (i+6) ) |
| host = self.addHost( 'h%d' % (i+6) ) |
| self.addLink( switch, host ) |
| self.addLink( switch, agg1Switch ) |
| |
| for i in range(10): |
| switch = self.addSwitch( 's%d' % (i+31) ) |
| host = self.addHost( 'h%d' % (i+31) ) |
| self.addLink( switch, host ) |
| self.addLink( switch, agg2Switch ) |
| |
| topos = { 'mytopo': ( lambda: MyTopo() ) } |