blob: 951e15cf24c2c4cc61010ef640efa42a0390f42f [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-onlab44147802015-07-27 17:57:31 -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-onlab44147802015-07-27 17:57:31 -070038class VLANHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070039
kelvin-onlab44147802015-07-27 17:57:31 -070040 def config( self, vlan=100, **params ):
Jon Hall0946f652015-08-13 11:44:38 -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' ] ) )
Jon Hall0946f652015-08-13 11:44:38 -070046 newName = '%s.%d' % ( intf, vlan )
47 intf.name = newName
48 self.nameToIntf[ newName ] = intf
49 return r
kelvin-onlab44147802015-07-27 17:57:31 -070050
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070051
kelvin-onlab44147802015-07-27 17:57:31 -070052class IPv6Host( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053
kelvin-onlab44147802015-07-27 17:57:31 -070054 def config( self, v6Addr='1000:1/64', **params ):
Jon Hall0946f652015-08-13 11:44:38 -070055 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
kelvin-onlab44147802015-07-27 17:57:31 -070060
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070061
kelvin-onlab44147802015-07-27 17:57:31 -070062class dualStackHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070063
kelvin-onlab44147802015-07-27 17:57:31 -070064 def config( self, v6Addr='2000:1/64', **params ):
Jon Hall0946f652015-08-13 11:44:38 -070065 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
kelvin-onlab44147802015-07-27 17:57:31 -070069
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070070
kelvin-onlab44147802015-07-27 17:57:31 -070071class MyTopo( Topo ):
72
Jon Hall0946f652015-08-13 11:44:38 -070073 def __init__( self ):
74 # Initialize topology
75 Topo.__init__( self )
76 # Switch S5 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070077 host1 = self.addHost( 'h1', ip='10.1.0.2/24' )
78 host2 = self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
79 host3 = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
80 # VLAN hosts
81 host4 = self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
82 host5 = self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
83 # VPN-1 and VPN-2 Hosts
84 host6 = self.addHost( 'h6', ip='11.1.0.2/24' )
85 host7 = self.addHost( 'h7', ip='12.1.0.2/24' )
86 # Multicast Sender
87 host8 = self.addHost( 'h8', ip='10.1.0.4/24' )
kelvin-onlab44147802015-07-27 17:57:31 -070088
Jon Hall0946f652015-08-13 11:44:38 -070089 # Switch S6 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070090 host9 = self.addHost( 'h9', ip='10.1.0.5/24' )
91 host10 = self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
92 host11 = self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
93 # VLAN hosts
94 host12 = self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
95 host13 = self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
96 # VPN-1 and VPN-2 Hosts
97 host14 = self.addHost( 'h14', ip='11.1.0.3/24' )
98 host15 = self.addHost( 'h15', ip='12.1.0.3/24' )
99 # Multicast Receiver
100 host16 = self.addHost( 'h16', ip='10.1.0.7/24' )
kelvin-onlab44147802015-07-27 17:57:31 -0700101
Jon Hall0946f652015-08-13 11:44:38 -0700102 # Switch S7 Hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700103 host17 = self.addHost( 'h17', ip='10.1.0.8/24' )
104 host18 = self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
105 host19 = self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
106 # VLAN hosts
107 host20 = self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
108 host21 = self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
109 # VPN-1 and VPN-2 Hosts
110 host22 = self.addHost( 'h22', ip='11.1.0.4/24' )
111 host23 = self.addHost( 'h23', ip='12.1.0.4/24' )
112 # Multicast Receiver
113 host24 = self.addHost( 'h24', ip='10.1.0.10/24' )
kelvin-onlab44147802015-07-27 17:57:31 -0700114
Jon Hall0946f652015-08-13 11:44:38 -0700115 s1 = self.addSwitch( 's1' )
116 s2 = self.addSwitch( 's2' )
117 s3 = self.addSwitch( 's3' )
118 s4 = self.addSwitch( 's4' )
119 s5 = self.addSwitch( 's5' )
120 s6 = self.addSwitch( 's6' )
121 s7 = self.addSwitch( 's7' )
kelvin-onlab44147802015-07-27 17:57:31 -0700122
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700123 self.addLink( s5, host1 )
124 self.addLink( s5, host2 )
125 self.addLink( s5, host3 )
126 self.addLink( s5, host4 )
127 self.addLink( s5, host5 )
128 self.addLink( s5, host6 )
129 self.addLink( s5, host7 )
130 self.addLink( s5, host8 )
kelvin-onlab44147802015-07-27 17:57:31 -0700131
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700132 self.addLink( s6, host9 )
133 self.addLink( s6, host10 )
134 self.addLink( s6, host11 )
135 self.addLink( s6, host12 )
136 self.addLink( s6, host13 )
137 self.addLink( s6, host14 )
138 self.addLink( s6, host15 )
139 self.addLink( s6, host16 )
kelvin-onlab44147802015-07-27 17:57:31 -0700140
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700141 self.addLink( s7, host17 )
142 self.addLink( s7, host18 )
143 self.addLink( s7, host19 )
144 self.addLink( s7, host20 )
145 self.addLink( s7, host21 )
146 self.addLink( s7, host22 )
147 self.addLink( s7, host23 )
148 self.addLink( s7, host24 )
kelvin-onlab44147802015-07-27 17:57:31 -0700149
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700150 self.addLink( s1, s2 )
151 self.addLink( s1, s3 )
152 self.addLink( s1, s4 )
153 self.addLink( s1, s5 )
154 self.addLink( s2, s3 )
155 self.addLink( s2, s5 )
156 self.addLink( s2, s6 )
157 self.addLink( s3, s4 )
158 self.addLink( s3, s6 )
159 self.addLink( s4, s7 )
Jon Hall0946f652015-08-13 11:44:38 -0700160 topos = { 'mytopo': ( lambda: MyTopo() ) }
kelvin-onlab44147802015-07-27 17:57:31 -0700161
162# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
163
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700164
kelvin-onlab44147802015-07-27 17:57:31 -0700165def setupNetwork():
166 "Create network"
167 topo = MyTopo()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700168 network = Mininet( topo=topo, autoSetMacs=True, controller=None )
kelvin-onlab44147802015-07-27 17:57:31 -0700169 network.start()
170 CLI( network )
171 network.stop()
172
173if __name__ == '__main__':
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700174 setLogLevel( 'info' )
175 # setLogLevel( 'debug' )
kelvin-onlab44147802015-07-27 17:57:31 -0700176 setupNetwork()