blob: 3328a5db5007246a981bc7fed780e32b00cc6df9 [file] [log] [blame]
adminf44b54c2014-06-05 09:53:59 -07001"""Custom topology example
2
3Two directly connected switches plus a host for each switch:
4
5 host --- switch --- switch --- host
6
7Adding the 'topos' dict with a key/value pair to generate our newly defined
8topology enables one to pass in '--topo=mytopo' from the command line.
9"""
10
11from mininet.topo import Topo
12
13class MyTopo( Topo ):
14 "Simple topology example."
15
16 def __init__( self ):
17 "Create custom topo."
18 # Initialize topology
19 Topo.__init__( self )
20
21 # Make the middle triangle
22 leftSwitch = self.addSwitch( 's1' )
23 rightSwitch = self.addSwitch( 's2' )
24 topSwitch = self.addSwitch( 's3' )
25 lefthost = self.addHost( 'h1' )
26 righthost = self.addHost( 'h2' )
27 tophost = self.addHost( 'h3' )
28 self.addLink( leftSwitch, lefthost )
29 self.addLink( rightSwitch, righthost )
30 self.addLink( topSwitch, tophost )
31
32 self.addLink( leftSwitch, rightSwitch )
33 self.addLink( leftSwitch, topSwitch )
34 self.addLink( topSwitch, rightSwitch )
35
36 # Make aggregation switches
37 agg1Switch = self.addSwitch( 's4' )
38 agg2Switch = self.addSwitch( 's5' )
39 agg1Host = self.addHost( 'h4' )
40 agg2Host = self.addHost( 'h5' )
41
42 self.addLink( agg1Switch, agg1Host )
43 self.addLink( agg2Switch, agg2Host )
44
45 self.addLink( agg1Switch, rightSwitch )
46 self.addLink( agg2Switch, leftSwitch )
47
48 # Make two aggregation fans
49 for i in range(10):
50 switch = self.addSwitch( 's%d' % (i+6) )
51 host = self.addHost( 'h%d' % (i+6) )
52 self.addLink( switch, host )
53 self.addLink( switch, agg1Switch )
54
55 for i in range(10):
56 switch = self.addSwitch( 's%d' % (i+31) )
57 host = self.addHost( 'h%d' % (i+31) )
58 self.addLink( switch, host )
59 self.addLink( switch, agg2Switch )
60
61topos = { 'mytopo': ( lambda: MyTopo() ) }