blob: 0dbaa8095840fdb5b8dbbb724146c1faad06db5f [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
GlennRC68449942015-10-16 16:03:12 -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
GlennRC073e8bc2015-10-27 17:11:28 -070038class VLANHost( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070039
GlennRC073e8bc2015-10-27 17:11:28 -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' ] ) )
GlennRC073e8bc2015-10-27 17:11:28 -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
GlennRC073e8bc2015-10-27 17:11:28 -070052class IPv6Host( Host ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053
GlennRC073e8bc2015-10-27 17:11:28 -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
GlennRC68449942015-10-16 16:03:12 -070062class MyTopo( Topo ):
63
GlennRC073e8bc2015-10-27 17:11:28 -070064 def __init__( self, **opts ):
GlennRC68449942015-10-16 16:03:12 -070065 # Initialize topology
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070066 Topo.__init__( self, **opts )
GlennRC073e8bc2015-10-27 17:11:28 -070067
68 # IPv4 hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070069 host1 = self.addHost( 'h1', ip='10.0.0.1/24' )
70 host2 = self.addHost( 'h2', ip='10.0.0.2/24' )
GlennRC073e8bc2015-10-27 17:11:28 -070071
72 # VLAN hosts
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070073 host3 = self.addHost( 'h3', ip='10.0.0.3/24', cls=VLANHost, vlan=10 )
74 host4 = self.addHost( 'h4', ip='10.0.0.4/24', cls=VLANHost, vlan=10 )
GlennRC073e8bc2015-10-27 17:11:28 -070075
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070076 # IPv6 hosts
77 host5 = self.addHost( 'h5', ip='10.0.0.5/24', cls=IPv6Host, v6Addr='1000::5/64' )
78 host6 = self.addHost( 'h6', ip='10.0.0.6/24', cls=IPv6Host, v6Addr='1000::6/64' )
GlennRC68449942015-10-16 16:03:12 -070079
80 s1 = self.addSwitch( 's1' )
GlennRC68449942015-10-16 16:03:12 -070081
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070082 self.addLink( s1, host1 )
83 self.addLink( s1, host2 )
84 self.addLink( s1, host3 )
85 self.addLink( s1, host4 )
86 self.addLink( s1, host5 )
87 self.addLink( s1, host6 )
GlennRC68449942015-10-16 16:03:12 -070088
89 topos = { 'mytopo': ( lambda: MyTopo() ) }
90
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070091
GlennRC68449942015-10-16 16:03:12 -070092def setupNetwork():
93 "Create network"
94 topo = MyTopo()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070095 network = Mininet( topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None )
GlennRC68449942015-10-16 16:03:12 -070096 network.start()
97 CLI( network )
98 network.stop()
99
100if __name__ == '__main__':
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700101 setLogLevel( 'info' )
102 # setLogLevel( 'debug' )
GlennRC68449942015-10-16 16:03:12 -0700103 setupNetwork()