blob: e3e10abb493a152e03fc9ae0064abbd9281090ca [file] [log] [blame]
suibin zhang116647a2016-05-06 16:30:09 -07001#!/usr/bin/python
2
3"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07004Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07005
6Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
9
10 TestON is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070013 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070014
15 TestON is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with TestON. If not, see <http://www.gnu.org/licenses/>.
22"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070023"""
suibin zhang116647a2016-05-06 16:30:09 -070024Custom 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
suibin zhang116647a2016-05-06 16:30:09 -070038class VLANHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070039
suibin zhang116647a2016-05-06 16:30:09 -070040 def config( self, vlan=100, **params ):
41 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' ] ) )
suibin zhang116647a2016-05-06 16:30:09 -070046 newName = '%s.%d' % ( intf, vlan )
47 intf.name = newName
48 self.nameToIntf[ newName ] = intf
49 return r
50
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070051
suibin zhang116647a2016-05-06 16:30:09 -070052class IPv6Host( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053
suibin zhang116647a2016-05-06 16:30:09 -070054 def config( self, v6Addr='1000:1/64', **params ):
55 r = super( Host, self ).config( **params )
56 intf = self.defaultIntf()
57 self.cmd( 'ifconfig %s inet 0' % intf )
58 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
59 return r
60
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070061
suibin zhang116647a2016-05-06 16:30:09 -070062class dualStackHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070063
suibin zhang116647a2016-05-06 16:30:09 -070064 def config( self, v6Addr='2000:1/64', **params ):
65 r = super( Host, self ).config( **params )
66 intf = self.defaultIntf()
67 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
68 return r
69
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070070
suibin zhang116647a2016-05-06 16:30:09 -070071class MyTopo( Topo ):
72
73 def __init__( self ):
74 # Initialize topology
75 Topo.__init__( self )
76
77 # Switch S5 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070078 host1 = self.addHost( 'h1', ip='10.1.0.2/24' )
79 host2 = self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
80 host3 = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
81 # VLAN hosts
82 host4 = self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
83 host5 = self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
84 # VPN-1 and VPN-2 Hosts
85 host6 = self.addHost( 'h6', ip='11.1.0.2/24' )
86 host7 = self.addHost( 'h7', ip='12.1.0.2/24' )
87 # Multicast Sender
88 host8 = self.addHost( 'h8', ip='10.1.0.4/24' )
suibin zhang116647a2016-05-06 16:30:09 -070089
90 # Switch S6 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070091 host9 = self.addHost( 'h9', ip='10.1.0.5/24' )
92 host10 = self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
93 host11 = self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
94 # VLAN hosts
95 host12 = self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
96 host13 = self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
97 # VPN-1 and VPN-2 Hosts
98 host14 = self.addHost( 'h14', ip='11.1.0.3/24' )
99 host15 = self.addHost( 'h15', ip='12.1.0.3/24' )
100 # Multicast Receiver
101 host16 = self.addHost( 'h16', ip='10.1.0.7/24' )
suibin zhang116647a2016-05-06 16:30:09 -0700102
103 # Switch S7 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700104 host17 = self.addHost( 'h17', ip='10.1.0.8/24' )
105 host18 = self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
106 host19 = self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
107 # VLAN hosts
108 host20 = self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
109 host21 = self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
110 # VPN-1 and VPN-2 Hosts
111 host22 = self.addHost( 'h22', ip='11.1.0.4/24' )
112 host23 = self.addHost( 'h23', ip='12.1.0.4/24' )
113 # Multicast Receiver
114 host24 = self.addHost( 'h24', ip='10.1.0.10/24' )
suibin zhang116647a2016-05-06 16:30:09 -0700115
116 s1 = self.addSwitch( 's1' )
117 s2 = self.addSwitch( 's2' )
118 s3 = self.addSwitch( 's3' )
119 s4 = self.addSwitch( 's4' )
120 s5 = self.addSwitch( 's5' )
121 s6 = self.addSwitch( 's6' )
122 s7 = self.addSwitch( 's7' )
123
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700124 self.addLink( s5, host1 )
125 self.addLink( s5, host2 )
126 self.addLink( s5, host3 )
127 self.addLink( s5, host4 )
128 self.addLink( s5, host5 )
129 self.addLink( s5, host6 )
130 self.addLink( s5, host7 )
131 self.addLink( s5, host8 )
suibin zhang116647a2016-05-06 16:30:09 -0700132
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700133 self.addLink( s6, host9 )
134 self.addLink( s6, host10 )
135 self.addLink( s6, host11 )
136 self.addLink( s6, host12 )
137 self.addLink( s6, host13 )
138 self.addLink( s6, host14 )
139 self.addLink( s6, host15 )
140 self.addLink( s6, host16 )
suibin zhang116647a2016-05-06 16:30:09 -0700141
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700142 self.addLink( s7, host17 )
143 self.addLink( s7, host18 )
144 self.addLink( s7, host19 )
145 self.addLink( s7, host20 )
146 self.addLink( s7, host21 )
147 self.addLink( s7, host22 )
148 self.addLink( s7, host23 )
149 self.addLink( s7, host24 )
suibin zhang116647a2016-05-06 16:30:09 -0700150
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151 self.addLink( s1, s2 )
152 self.addLink( s1, s3 )
153 self.addLink( s1, s4 )
154 self.addLink( s1, s5 )
suibin zhang116647a2016-05-06 16:30:09 -0700155
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700156 self.addLink( s2, s3 )
157 self.addLink( s2, s5 )
158 self.addLink( s2, s6 )
suibin zhang116647a2016-05-06 16:30:09 -0700159
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700160 self.addLink( s3, s4 )
161 self.addLink( s3, s6 )
suibin zhang116647a2016-05-06 16:30:09 -0700162
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700163 self.addLink( s4, s7 )
suibin zhang116647a2016-05-06 16:30:09 -0700164 topos = { 'mytopo': ( lambda: MyTopo() ) }
165
166# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
167
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700168
suibin zhang116647a2016-05-06 16:30:09 -0700169def setupNetwork():
170 "Create network"
171 topo = MyTopo()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700172 network = Mininet( topo=topo, autoSetMacs=True, controller=None )
suibin zhang116647a2016-05-06 16:30:09 -0700173 network.start()
174 CLI( network )
175 network.stop()
176
177if __name__ == '__main__':
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 setLogLevel( 'info' )
179 # setLogLevel( 'debug' )
suibin zhang116647a2016-05-06 16:30:09 -0700180 setupNetwork()