kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 4 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 13 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 14 | |
| 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 Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 23 | """ |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 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 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 38 | class VLANHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 39 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 40 | def config( self, vlan=100, **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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' ] ) ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 46 | newName = '%s.%d' % ( intf, vlan ) |
| 47 | intf.name = newName |
| 48 | self.nameToIntf[ newName ] = intf |
| 49 | return r |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 50 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 51 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 52 | class IPv6Host( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 53 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 54 | def config( self, v6Addr='1000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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 |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 60 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 61 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 62 | class dualStackHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 63 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 64 | def config( self, v6Addr='2000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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 |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 69 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 70 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 71 | class MyTopo( Topo ): |
| 72 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 73 | def __init__( self ): |
| 74 | # Initialize topology |
| 75 | Topo.__init__( self ) |
| 76 | # Switch S5 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 77 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 88 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 89 | # Switch S6 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 90 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 101 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 102 | # Switch S7 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 103 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 114 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 115 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 122 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 123 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 131 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 132 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 140 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 141 | 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-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 149 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 150 | 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 Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 160 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 161 | |
| 162 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 163 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 164 | |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 165 | def setupNetwork(): |
| 166 | "Create network" |
| 167 | topo = MyTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 168 | network = Mininet( topo=topo, autoSetMacs=True, controller=None ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 169 | network.start() |
| 170 | CLI( network ) |
| 171 | network.stop() |
| 172 | |
| 173 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 174 | setLogLevel( 'info' ) |
| 175 | # setLogLevel( 'debug' ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 176 | setupNetwork() |