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 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [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 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 38 | class VLANHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 39 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 40 | def config( self, vlan=100, v6Addr='3000::1/64', **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' ] ) ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 46 | self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) ) |
| 47 | newName = '%s.%d' % ( intf, vlan ) |
| 48 | intf.name = newName |
| 49 | self.nameToIntf[ newName ] = intf |
| 50 | return r |
| 51 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 52 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 53 | class IPv6Host( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 54 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 55 | def config( self, v6Addr='1000::1/64', **params ): |
| 56 | r = super( Host, self ).config( **params ) |
| 57 | intf = self.defaultIntf() |
| 58 | self.cmd( 'ifconfig %s inet 0' % intf ) |
| 59 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 60 | return r |
| 61 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 62 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 63 | class dualStackHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 64 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 65 | def config( self, v6Addr='2000:1/64', **params ): |
| 66 | r = super( Host, self ).config( **params ) |
| 67 | intf = self.defaultIntf() |
| 68 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 69 | return r |
| 70 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 71 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 72 | class MyTopo( Topo ): |
| 73 | |
| 74 | def __init__( self ): |
| 75 | # Initialize topology |
| 76 | Topo.__init__( self ) |
| 77 | # Switch S5 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 78 | host1 = self.addHost( 'h1', cls=IPv6Host, v6Addr='10:1:0::1/64' ) |
| 79 | host2 = self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 80 | # Dual Stack Host |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 81 | host3 = self.addHost( 'h3', cls=dualStackHost, v6Addr='2000::2/64' ) |
| 82 | host4 = self.addHost( 'h4', cls=IPv6Host, v6Addr='3000::2/64' ) |
| 83 | # VLAN |
| 84 | host5 = self.addHost( 'h5', cls=VLANHost, v6Addr='4000::2/64' ) |
| 85 | host6 = self.addHost( 'h6', cls=IPv6Host, v6Addr='11:1:0::2/64' ) |
| 86 | host7 = self.addHost( 'h7', cls=IPv6Host, v6Addr='12:1:0::2/64' ) |
| 87 | host8 = self.addHost( 'h8', cls=IPv6Host, v6Addr='10:1:0::4/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 88 | |
| 89 | # Switch S6 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 90 | host9 = self.addHost( 'h9', cls=IPv6Host, v6Addr='10:1:0::5/64' ) |
| 91 | host10 = self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 92 | # Dual Stack Host |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 93 | host11 = self.addHost( 'h11', cls=dualStackHost, v6Addr='2000::3/64' ) |
| 94 | host12 = self.addHost( 'h12', cls=IPv6Host, v6Addr='3000::3/64' ) |
| 95 | host13 = self.addHost( 'h13', cls=IPv6Host, v6Addr='4000::3/64' ) |
| 96 | host14 = self.addHost( 'h14', cls=IPv6Host, v6Addr='11:1:0::3/64' ) |
| 97 | host15 = self.addHost( 'h15', cls=IPv6Host, v6Addr='12:1:0::3/64' ) |
| 98 | host16 = self.addHost( 'h16', cls=IPv6Host, v6Addr='10:1:0::7/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 99 | |
| 100 | # Switch S7 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 101 | host17 = self.addHost( 'h17', cls=IPv6Host, v6Addr='10:1:0::8/64' ) |
| 102 | host18 = self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
| 103 | host19 = self.addHost( 'h19', cls=IPv6Host, v6Addr='10:1:0::9/64' ) |
| 104 | host20 = self.addHost( 'h20', cls=IPv6Host, v6Addr='100:1:0::4/64' ) |
| 105 | host21 = self.addHost( 'h21', cls=IPv6Host, v6Addr='200:1:0::4/64' ) |
| 106 | host22 = self.addHost( 'h22', cls=IPv6Host, v6Addr='11:1:0::4/64' ) |
| 107 | host23 = self.addHost( 'h23', cls=IPv6Host, v6Addr='12:1:0::4/64' ) |
| 108 | # VLAN |
| 109 | host24 = self.addHost( 'h24', cls=VLANHost, v6Addr='4000::5/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 110 | |
| 111 | s1 = self.addSwitch( 's1' ) |
| 112 | s2 = self.addSwitch( 's2' ) |
| 113 | s3 = self.addSwitch( 's3' ) |
| 114 | s4 = self.addSwitch( 's4' ) |
| 115 | s5 = self.addSwitch( 's5' ) |
| 116 | s6 = self.addSwitch( 's6' ) |
| 117 | s7 = self.addSwitch( 's7' ) |
| 118 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 119 | self.addLink( s5, host1 ) |
| 120 | self.addLink( s5, host2 ) |
| 121 | self.addLink( s5, host3 ) |
| 122 | self.addLink( s5, host4 ) |
| 123 | self.addLink( s5, host5 ) |
| 124 | self.addLink( s5, host6 ) |
| 125 | self.addLink( s5, host7 ) |
| 126 | self.addLink( s5, host8 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 127 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 128 | self.addLink( s6, host9 ) |
| 129 | self.addLink( s6, host10 ) |
| 130 | self.addLink( s6, host11 ) |
| 131 | self.addLink( s6, host12 ) |
| 132 | self.addLink( s6, host13 ) |
| 133 | self.addLink( s6, host14 ) |
| 134 | self.addLink( s6, host15 ) |
| 135 | self.addLink( s6, host16 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 136 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 137 | self.addLink( s7, host17 ) |
| 138 | self.addLink( s7, host18 ) |
| 139 | self.addLink( s7, host19 ) |
| 140 | self.addLink( s7, host20 ) |
| 141 | self.addLink( s7, host21 ) |
| 142 | self.addLink( s7, host22 ) |
| 143 | self.addLink( s7, host23 ) |
| 144 | self.addLink( s7, host24 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 145 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 146 | self.addLink( s1, s2 ) |
| 147 | self.addLink( s1, s3 ) |
| 148 | self.addLink( s1, s4 ) |
| 149 | self.addLink( s1, s5 ) |
| 150 | self.addLink( s2, s3 ) |
| 151 | self.addLink( s2, s5 ) |
| 152 | self.addLink( s2, s6 ) |
| 153 | self.addLink( s3, s4 ) |
| 154 | self.addLink( s3, s6 ) |
| 155 | self.addLink( s4, s7 ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 156 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 157 | |
| 158 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 159 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 160 | |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 161 | def setupNetwork(): |
| 162 | "Create network" |
| 163 | topo = MyTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 164 | network = Mininet( topo=topo, autoSetMacs=True, controller=None ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 165 | network.start() |
| 166 | CLI( network ) |
| 167 | network.stop() |
| 168 | |
| 169 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 170 | setLogLevel( 'info' ) |
| 171 | # setLogLevel( 'debug' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 172 | setupNetwork() |