blob: d4731f311fbd63e87fc597b4e7dc5a955940cd89 [file] [log] [blame]
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -08001#!/usr/bin/python
2
3"""
4Custom topology for Mininet
5"""
6from mininet.topo import Topo
7from mininet.net import Mininet
8from mininet.node import Host, RemoteController
9from mininet.node import Node
10from mininet.node import CPULimitedHost
11from mininet.link import TCLink
12from mininet.cli import CLI
13from mininet.log import setLogLevel
14from mininet.util import dumpNodeConnections
15from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
16
17class VLANHost( Host ):
18 def config( self, vlan=100, v6Addr='3000::1/64', **params ):
19 r = super( Host, self ).config( **params )
20 intf = self.defaultIntf()
21 self.cmd( 'ifconfig %s inet 0' % intf )
22 self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
23 self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
24 self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) )
25 newName = '%s.%d' % ( intf, vlan )
26 intf.name = newName
27 self.nameToIntf[ newName ] = intf
28 return r
29
30class IPv6Host( Host ):
31 def config( self, v6Addr='1000::1/64', **params ):
32 r = super( Host, self ).config( **params )
33 intf = self.defaultIntf()
34 self.cmd( 'ifconfig %s inet 0' % intf )
35 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
36 return r
37
38class dualStackHost( Host ):
39 def config( self, v6Addr='2000:1/64', **params ):
40 r = super( Host, self ).config( **params )
41 intf = self.defaultIntf()
42 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
43 return r
44
45class MyTopo( Topo ):
46
47 def __init__( self ):
48 # Initialize topology
49 Topo.__init__( self )
50 # Switch S5 Hosts
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080051 host1=self.addHost( 'h1', cls=IPv6Host, v6Addr='10:1:0::1/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080052 host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
53 # Dual Stack Host
sathishmad953462015-12-03 17:42:07 +053054 host3=self.addHost( 'h3', cls=dualStackHost, v6Addr='2000::2/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080055 host4=self.addHost( 'h4', cls=IPv6Host, v6Addr='3000::2/64' )
sathishmad953462015-12-03 17:42:07 +053056 #VLAN
57 host5=self.addHost( 'h5', cls=VLANHost,v6Addr='4000::2/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080058 host6=self.addHost( 'h6', cls=IPv6Host, v6Addr='11:1:0::2/64' )
59 host7=self.addHost( 'h7', cls=IPv6Host, v6Addr='12:1:0::2/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080060 host8=self.addHost( 'h8', cls=IPv6Host, v6Addr='10:1:0::4/64' )
61
62 # Switch S6 Hosts
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080063 host9=self.addHost( 'h9', cls=IPv6Host, v6Addr='10:1:0::5/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080064 host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
65 # Dual Stack Host
sathishmad953462015-12-03 17:42:07 +053066 host11=self.addHost( 'h11', cls=dualStackHost, v6Addr='2000::3/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080067 host12=self.addHost( 'h12', cls=IPv6Host, v6Addr='3000::3/64' )
68 host13=self.addHost( 'h13', cls=IPv6Host, v6Addr='4000::3/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080069 host14=self.addHost( 'h14', cls=IPv6Host, v6Addr='11:1:0::3/64' )
70 host15=self.addHost( 'h15', cls=IPv6Host, v6Addr='12:1:0::3/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080071 host16=self.addHost( 'h16', cls=IPv6Host, v6Addr='10:1:0::7/64' )
72
73 # Switch S7 Hosts
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080074 host17=self.addHost( 'h17', cls=IPv6Host, v6Addr='10:1:0::8/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080075 host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080076 host19=self.addHost( 'h19', cls=IPv6Host, v6Addr='10:1:0::9/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080077 host20=self.addHost( 'h20', cls=IPv6Host, v6Addr='100:1:0::4/64' )
78 host21=self.addHost( 'h21', cls=IPv6Host, v6Addr='200:1:0::4/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080079 host22=self.addHost( 'h22', cls=IPv6Host, v6Addr='11:1:0::4/64' )
80 host23=self.addHost( 'h23', cls=IPv6Host, v6Addr='12:1:0::4/64' )
sathishmad953462015-12-03 17:42:07 +053081 # VLAN
82 host24=self.addHost( 'h24', cls=VLANHost, v6Addr='4000::5/64' )
Subhash Kumar Singhc73b3a72015-11-03 21:34:04 -080083
84 s1 = self.addSwitch( 's1' )
85 s2 = self.addSwitch( 's2' )
86 s3 = self.addSwitch( 's3' )
87 s4 = self.addSwitch( 's4' )
88 s5 = self.addSwitch( 's5' )
89 s6 = self.addSwitch( 's6' )
90 s7 = self.addSwitch( 's7' )
91
92 self.addLink(s5,host1)
93 self.addLink(s5,host2)
94 self.addLink(s5,host3)
95 self.addLink(s5,host4)
96 self.addLink(s5,host5)
97 self.addLink(s5,host6)
98 self.addLink(s5,host7)
99 self.addLink(s5,host8)
100
101 self.addLink(s6,host9)
102 self.addLink(s6,host10)
103 self.addLink(s6,host11)
104 self.addLink(s6,host12)
105 self.addLink(s6,host13)
106 self.addLink(s6,host14)
107 self.addLink(s6,host15)
108 self.addLink(s6,host16)
109
110 self.addLink(s7,host17)
111 self.addLink(s7,host18)
112 self.addLink(s7,host19)
113 self.addLink(s7,host20)
114 self.addLink(s7,host21)
115 self.addLink(s7,host22)
116 self.addLink(s7,host23)
117 self.addLink(s7,host24)
118
119 self.addLink(s1,s2)
120 self.addLink(s1,s3)
121 self.addLink(s1,s4)
122 self.addLink(s1,s5)
123 self.addLink(s2,s3)
124 self.addLink(s2,s5)
125 self.addLink(s2,s6)
126 self.addLink(s3,s4)
127 self.addLink(s3,s6)
128 self.addLink(s4,s7)
129 topos = { 'mytopo': ( lambda: MyTopo() ) }
130
131# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
132
133def setupNetwork():
134 "Create network"
135 topo = MyTopo()
136 network = Mininet(topo=topo, autoSetMacs=True, controller=None)
137 network.start()
138 CLI( network )
139 network.stop()
140
141if __name__ == '__main__':
142 setLogLevel('info')
143 #setLogLevel('debug')
144 setupNetwork()