blob: df808a7ca085b0c18c607cd8b7911088fb6b8099 [file] [log] [blame]
kelvin-onlabd48a68c2015-07-13 16:01:36 -07001#!/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 ):
Hari Krishna710d45e2015-10-02 15:54:55 -070018 def config( self, vlan=100, v6Addr='3000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070019 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'] ) )
Hari Krishna710d45e2015-10-02 15:54:55 -070024 self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) )
Jon Hall4ba53f02015-07-29 13:07:41 -070025 newName = '%s.%d' % ( intf, vlan )
26 intf.name = newName
27 self.nameToIntf[ newName ] = intf
28 return r
kelvin-onlabd48a68c2015-07-13 16:01:36 -070029
30class IPv6Host( Host ):
Hari Krishna710d45e2015-10-02 15:54:55 -070031 def config( self, v6Addr='1000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070032 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
kelvin-onlabd48a68c2015-07-13 16:01:36 -070037
38class dualStackHost( Host ):
39 def config( self, v6Addr='2000:1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070040 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
kelvin-onlabd48a68c2015-07-13 16:01:36 -070044
45class MyTopo( Topo ):
46
Jon Hall4ba53f02015-07-29 13:07:41 -070047 def __init__( self ):
48 # Initialize topology
49 Topo.__init__( self )
50 # Switch S5 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070051 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070052 host1=self.addHost( 'h1', ip='10.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070053 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070054 host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070055 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -070056 host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070057 # VLAN hosts
58 host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100, v6Addr='3000::2/64' )
59 host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200, v6Addr='4000::2/64' )
60 # VPN-1 and VPN-2 Hosts
Jon Hall4ba53f02015-07-29 13:07:41 -070061 host6=self.addHost( 'h6', ip='11.1.0.2/24' )
62 host7=self.addHost( 'h7', ip='12.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070063 # Multicast Sender
Jon Hall4ba53f02015-07-29 13:07:41 -070064 host8=self.addHost( 'h8', ip='10.1.0.4/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -070065
Jon Hall4ba53f02015-07-29 13:07:41 -070066 # Switch S6 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070067 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070068 host9=self.addHost( 'h9', ip='10.1.0.5/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070069 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070070 host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070071 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -070072 host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070073 # VLAN hosts
74 host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100, v6Addr='3000::3/64' )
75 host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200, v6Addr='4000::3/64' )
76 # VPN-1 and VPN-2 Hosts
Jon Hall4ba53f02015-07-29 13:07:41 -070077 host14=self.addHost( 'h14', ip='11.1.0.3/24' )
78 host15=self.addHost( 'h15', ip='12.1.0.3/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070079 # Multicast Receiver
Jon Hall4ba53f02015-07-29 13:07:41 -070080 host16=self.addHost( 'h16', ip='10.1.0.7/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -070081
Jon Hall4ba53f02015-07-29 13:07:41 -070082 # Switch S7 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070083 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070084 host17=self.addHost( 'h17', ip='10.1.0.8/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070085 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070086 host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070087 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -070088 host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070089 # VLAN hosts
90 host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100, v6Addr='3000::4/64' )
91 host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200, v6Addr='4000::4/64' )
92 # VPN-1 and VPN-2 Hosts
Jon Hall4ba53f02015-07-29 13:07:41 -070093 host22=self.addHost( 'h22', ip='11.1.0.4/24' )
94 host23=self.addHost( 'h23', ip='12.1.0.4/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070095 # Multicast Receiver
Jon Hall4ba53f02015-07-29 13:07:41 -070096 host24=self.addHost( 'h24', ip='10.1.0.10/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -070097
Jon Hall4ba53f02015-07-29 13:07:41 -070098 s1 = self.addSwitch( 's1' )
99 s2 = self.addSwitch( 's2' )
100 s3 = self.addSwitch( 's3' )
101 s4 = self.addSwitch( 's4' )
102 s5 = self.addSwitch( 's5' )
103 s6 = self.addSwitch( 's6' )
104 s7 = self.addSwitch( 's7' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700105
Jon Hall4ba53f02015-07-29 13:07:41 -0700106 self.addLink(s5,host1)
107 self.addLink(s5,host2)
108 self.addLink(s5,host3)
109 self.addLink(s5,host4)
110 self.addLink(s5,host5)
111 self.addLink(s5,host6)
112 self.addLink(s5,host7)
113 self.addLink(s5,host8)
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700114
Jon Hall4ba53f02015-07-29 13:07:41 -0700115 self.addLink(s6,host9)
116 self.addLink(s6,host10)
117 self.addLink(s6,host11)
118 self.addLink(s6,host12)
119 self.addLink(s6,host13)
120 self.addLink(s6,host14)
121 self.addLink(s6,host15)
122 self.addLink(s6,host16)
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700123
Jon Hall4ba53f02015-07-29 13:07:41 -0700124 self.addLink(s7,host17)
125 self.addLink(s7,host18)
126 self.addLink(s7,host19)
127 self.addLink(s7,host20)
128 self.addLink(s7,host21)
129 self.addLink(s7,host22)
130 self.addLink(s7,host23)
131 self.addLink(s7,host24)
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700132
Jon Hall4ba53f02015-07-29 13:07:41 -0700133 self.addLink(s1,s2)
134 self.addLink(s1,s3)
135 self.addLink(s1,s4)
136 self.addLink(s1,s5)
137 self.addLink(s2,s3)
138 self.addLink(s2,s5)
139 self.addLink(s2,s6)
140 self.addLink(s3,s4)
141 self.addLink(s3,s6)
142 self.addLink(s4,s7)
143 topos = { 'mytopo': ( lambda: MyTopo() ) }
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700144
145# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
146
147def setupNetwork():
148 "Create network"
149 topo = MyTopo()
150 network = Mininet(topo=topo, autoSetMacs=True, controller=None)
151 network.start()
152 CLI( network )
153 network.stop()
154
155if __name__ == '__main__':
156 setLogLevel('info')
157 #setLogLevel('debug')
158 setupNetwork()