Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1 | # !/usr/bin/python |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 3 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 12 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 13 | |
| 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 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 23 | """ |
| 24 | Custom topology for Mininet |
| 25 | """ |
| 26 | from mininet.topo import Topo |
| 27 | from mininet.net import Mininet |
| 28 | from mininet.node import Host, RemoteController |
| 29 | from mininet.node import Node |
| 30 | from mininet.node import CPULimitedHost |
| 31 | from mininet.link import TCLink |
| 32 | from mininet.cli import CLI |
| 33 | from mininet.log import setLogLevel |
| 34 | from mininet.util import dumpNodeConnections |
| 35 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 36 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 37 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 38 | class VLANHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 39 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 40 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 45 | self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params[ 'ip' ] ) ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 46 | newName = '%s.%d' % ( intf, vlan ) |
| 47 | intf.name = newName |
| 48 | self.nameToIntf[ newName ] = intf |
| 49 | return r |
| 50 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 51 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 52 | class IPv6Host( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 53 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 54 | 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 61 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 62 | class MyTopo( Topo ): |
| 63 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 64 | def __init__( self, **opts ): |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 65 | # Initialize topology |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 66 | Topo.__init__( self, **opts ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 67 | |
| 68 | # IPv4 hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 69 | host1 = self.addHost( 'h1', ip='10.0.0.1/24' ) |
| 70 | host2 = self.addHost( 'h2', ip='10.0.0.2/24' ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 71 | |
| 72 | # VLAN hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 73 | 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 ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 75 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 76 | # 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' ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 79 | |
| 80 | s1 = self.addSwitch( 's1' ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 81 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 82 | 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 ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 88 | |
| 89 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 90 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 91 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 92 | def setupNetwork(): |
| 93 | "Create network" |
| 94 | topo = MyTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 95 | network = Mininet( topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 96 | network.start() |
| 97 | CLI( network ) |
| 98 | network.stop() |
| 99 | |
| 100 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 101 | setLogLevel( 'info' ) |
| 102 | # setLogLevel( 'debug' ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 103 | setupNetwork() |