blob: 9897d9c59c23df35941278d279e1547ea641d527 [file] [log] [blame]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001# !/usr/bin/python
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07003Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07004
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8
9 TestON is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070012 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070013
14 TestON is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with TestON. If not, see <http://www.gnu.org/licenses/>.
21"""
22
kelvin-onlabd48a68c2015-07-13 16:01:36 -070023"""
24Custom topology for Mininet
25"""
26from mininet.topo import Topo
27from mininet.net import Mininet
28from mininet.node import Host, RemoteController
29from mininet.node import Node
30from mininet.node import CPULimitedHost
31from mininet.link import TCLink
32from mininet.cli import CLI
33from mininet.log import setLogLevel
34from mininet.util import dumpNodeConnections
35from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
36
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070037
kelvin-onlabd48a68c2015-07-13 16:01:36 -070038class VLANHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070039
Hari Krishna710d45e2015-10-02 15:54:55 -070040 def config( self, vlan=100, v6Addr='3000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070041 r = super( Host, self ).config( **params )
42 intf = self.defaultIntf()
43 self.cmd( 'ifconfig %s inet 0' % intf )
44 self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070045 self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params[ 'ip' ] ) )
Hari Krishna710d45e2015-10-02 15:54:55 -070046 self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) )
Jon Hall4ba53f02015-07-29 13:07:41 -070047 newName = '%s.%d' % ( intf, vlan )
48 intf.name = newName
49 self.nameToIntf[ newName ] = intf
50 return r
kelvin-onlabd48a68c2015-07-13 16:01:36 -070051
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070052
kelvin-onlabd48a68c2015-07-13 16:01:36 -070053class IPv6Host( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070054
Hari Krishna710d45e2015-10-02 15:54:55 -070055 def config( self, v6Addr='1000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070056 r = super( Host, self ).config( **params )
57 intf = self.defaultIntf()
58 self.cmd( 'ifconfig %s inet 0' % intf )
59 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
60 return r
kelvin-onlabd48a68c2015-07-13 16:01:36 -070061
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062
kelvin-onlabd48a68c2015-07-13 16:01:36 -070063class dualStackHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070064
kelvin-onlabd48a68c2015-07-13 16:01:36 -070065 def config( self, v6Addr='2000:1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070066 r = super( Host, self ).config( **params )
67 intf = self.defaultIntf()
68 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
69 return r
kelvin-onlabd48a68c2015-07-13 16:01:36 -070070
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070071
kelvin-onlabd48a68c2015-07-13 16:01:36 -070072class MyTopo( Topo ):
73
Jon Hall4ba53f02015-07-29 13:07:41 -070074 def __init__( self ):
75 # Initialize topology
76 Topo.__init__( self )
77 # Switch S5 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070078 # IPv4 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079 host1 = self.addHost( 'h1', ip='10.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070080 # IPv6 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070081 host2 = self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070082 # Dual Stack Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070083 host3 = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070084 # VLAN hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070085 host4 = self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100, v6Addr='3000::2/64' )
86 host5 = self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200, v6Addr='4000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070087 # VPN-1 and VPN-2 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070088 host6 = self.addHost( 'h6', ip='11.1.0.2/24' )
89 host7 = self.addHost( 'h7', ip='12.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070090 # Multicast Sender
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070091 host8 = self.addHost( 'h8', ip='10.1.0.4/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -070092
Jon Hall4ba53f02015-07-29 13:07:41 -070093 # Switch S6 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070094 # IPv4 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070095 host9 = self.addHost( 'h9', ip='10.1.0.5/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070096 # IPv6 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 host10 = self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070098 # Dual Stack Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070099 host11 = self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700100 # VLAN hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700101 host12 = self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100, v6Addr='3000::3/64' )
102 host13 = self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200, v6Addr='4000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700103 # VPN-1 and VPN-2 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700104 host14 = self.addHost( 'h14', ip='11.1.0.3/24' )
105 host15 = self.addHost( 'h15', ip='12.1.0.3/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700106 # Multicast Receiver
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107 host16 = self.addHost( 'h16', ip='10.1.0.7/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700108
Jon Hall4ba53f02015-07-29 13:07:41 -0700109 # Switch S7 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -0700110 # IPv4 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700111 host17 = self.addHost( 'h17', ip='10.1.0.8/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700112 # IPv6 only Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700113 host18 = self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700114 # Dual Stack Host
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700115 host19 = self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700116 # VLAN hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700117 host20 = self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100, v6Addr='3000::4/64' )
118 host21 = self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200, v6Addr='4000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700119 # VPN-1 and VPN-2 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700120 host22 = self.addHost( 'h22', ip='11.1.0.4/24' )
121 host23 = self.addHost( 'h23', ip='12.1.0.4/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700122 # Multicast Receiver
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700123 host24 = self.addHost( 'h24', ip='10.1.0.10/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700124
Jon Hall4ba53f02015-07-29 13:07:41 -0700125 s1 = self.addSwitch( 's1' )
126 s2 = self.addSwitch( 's2' )
127 s3 = self.addSwitch( 's3' )
128 s4 = self.addSwitch( 's4' )
129 s5 = self.addSwitch( 's5' )
130 s6 = self.addSwitch( 's6' )
131 s7 = self.addSwitch( 's7' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700132
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700133 self.addLink( s5, host1 )
134 self.addLink( s5, host2 )
135 self.addLink( s5, host3 )
136 self.addLink( s5, host4 )
137 self.addLink( s5, host5 )
138 self.addLink( s5, host6 )
139 self.addLink( s5, host7 )
140 self.addLink( s5, host8 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700141
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700142 self.addLink( s6, host9 )
143 self.addLink( s6, host10 )
144 self.addLink( s6, host11 )
145 self.addLink( s6, host12 )
146 self.addLink( s6, host13 )
147 self.addLink( s6, host14 )
148 self.addLink( s6, host15 )
149 self.addLink( s6, host16 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700150
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151 self.addLink( s7, host17 )
152 self.addLink( s7, host18 )
153 self.addLink( s7, host19 )
154 self.addLink( s7, host20 )
155 self.addLink( s7, host21 )
156 self.addLink( s7, host22 )
157 self.addLink( s7, host23 )
158 self.addLink( s7, host24 )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700159
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700160 self.addLink( s1, s2 )
161 self.addLink( s1, s3 )
162 self.addLink( s1, s4 )
163 self.addLink( s1, s5 )
164 self.addLink( s2, s3 )
165 self.addLink( s2, s5 )
166 self.addLink( s2, s6 )
167 self.addLink( s3, s4 )
168 self.addLink( s3, s6 )
169 self.addLink( s4, s7 )
Jon Hall4ba53f02015-07-29 13:07:41 -0700170 topos = { 'mytopo': ( lambda: MyTopo() ) }
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700171
172# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
173
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700174
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700175def setupNetwork():
176 "Create network"
177 topo = MyTopo()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 network = Mininet( topo=topo, autoSetMacs=True, controller=None )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700179 network.start()
180 CLI( network )
181 network.stop()
182
183if __name__ == '__main__':
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700184 setLogLevel( 'info' )
185 # setLogLevel( 'debug' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700186 setupNetwork()