blob: 4fc036c7611900c25d078f94cc450692e0c784e9 [file] [log] [blame]
SeanCorcoran60b6b502014-04-23 16:53:39 -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' , dpid = '1000'.zfill(16))
23 rightSwitch = self.addSwitch( 's2' , dpid = '2000'.zfill(16))
24 topSwitch = self.addSwitch( 's3' , dpid = '3000'.zfill(16))
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', dpid = '1004'.zfill(16) )
38 agg2Switch = self.addSwitch( 's5', dpid = '2005'.zfill(16) )
39 agg1Host = self.addHost( 'h4' )
40 agg2Host = self.addHost( 'h5' )
41
42 self.addLink( agg1Switch, agg1Host, port1=1, port2=1 )
43 self.addLink( agg2Switch, agg2Host, port1=1, port2=1 )
44
45 self.addLink( agg2Switch, rightSwitch )
46 self.addLink( agg1Switch, leftSwitch )
47
48 # Make two aggregation fans
49 for i in range(10):
50 num=str(i+6)
51 switch = self.addSwitch( 's' + num, dpid = ('10' + num.zfill(2) ).zfill(16))
52 host = self.addHost( 'h' + num )
53 self.addLink( switch, host, port1=1, port2=1 )
54 self.addLink( switch, agg1Switch )
55
56 for i in range(10):
57 num=str(i+31)
58 switch = self.addSwitch( 's' + num, dpid = ('20' + num.zfill(2)).zfill(16) )
59 host = self.addHost( 'h' + num )
60 self.addLink( switch, host, port1=1, port2=1 )
61 self.addLink( switch, agg2Switch )
62
63topos = { 'mytopo': ( lambda: MyTopo() ) }