suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 4 | Copyright 2016 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 | """ |
suibin zhang | 116647a | 2016-05-06 16:30:09 -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 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 38 | class VLANHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 39 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -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' ] ) ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -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 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 52 | class IPv6Host( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 53 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -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 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 62 | class dualStackHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 63 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 64 | def config( self, v6Addr='2000:1/64', **params ): |
| 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 |
| 69 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 70 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 71 | class MyTopo( Topo ): |
| 72 | |
| 73 | def __init__( self ): |
| 74 | # Initialize topology |
| 75 | Topo.__init__( self ) |
| 76 | |
| 77 | # Switch S5 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 78 | host1 = self.addHost( 'h1', ip='10.1.0.2/24' ) |
| 79 | host2 = self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
| 80 | host3 = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' ) |
| 81 | # VLAN hosts |
| 82 | host4 = self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 ) |
| 83 | host5 = self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 ) |
| 84 | # VPN-1 and VPN-2 Hosts |
| 85 | host6 = self.addHost( 'h6', ip='11.1.0.2/24' ) |
| 86 | host7 = self.addHost( 'h7', ip='12.1.0.2/24' ) |
| 87 | # Multicast Sender |
| 88 | host8 = self.addHost( 'h8', ip='10.1.0.4/24' ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 89 | |
| 90 | # Switch S6 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 91 | host9 = self.addHost( 'h9', ip='10.1.0.5/24' ) |
| 92 | host10 = self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
| 93 | host11 = self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' ) |
| 94 | # VLAN hosts |
| 95 | host12 = self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 ) |
| 96 | host13 = self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 ) |
| 97 | # VPN-1 and VPN-2 Hosts |
| 98 | host14 = self.addHost( 'h14', ip='11.1.0.3/24' ) |
| 99 | host15 = self.addHost( 'h15', ip='12.1.0.3/24' ) |
| 100 | # Multicast Receiver |
| 101 | host16 = self.addHost( 'h16', ip='10.1.0.7/24' ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 102 | |
| 103 | # Switch S7 Hosts |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 104 | host17 = self.addHost( 'h17', ip='10.1.0.8/24' ) |
| 105 | host18 = self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
| 106 | host19 = self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' ) |
| 107 | # VLAN hosts |
| 108 | host20 = self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 ) |
| 109 | host21 = self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 ) |
| 110 | # VPN-1 and VPN-2 Hosts |
| 111 | host22 = self.addHost( 'h22', ip='11.1.0.4/24' ) |
| 112 | host23 = self.addHost( 'h23', ip='12.1.0.4/24' ) |
| 113 | # Multicast Receiver |
| 114 | host24 = self.addHost( 'h24', ip='10.1.0.10/24' ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 115 | |
| 116 | s1 = self.addSwitch( 's1' ) |
| 117 | s2 = self.addSwitch( 's2' ) |
| 118 | s3 = self.addSwitch( 's3' ) |
| 119 | s4 = self.addSwitch( 's4' ) |
| 120 | s5 = self.addSwitch( 's5' ) |
| 121 | s6 = self.addSwitch( 's6' ) |
| 122 | s7 = self.addSwitch( 's7' ) |
| 123 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 124 | self.addLink( s5, host1 ) |
| 125 | self.addLink( s5, host2 ) |
| 126 | self.addLink( s5, host3 ) |
| 127 | self.addLink( s5, host4 ) |
| 128 | self.addLink( s5, host5 ) |
| 129 | self.addLink( s5, host6 ) |
| 130 | self.addLink( s5, host7 ) |
| 131 | self.addLink( s5, host8 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 132 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 133 | self.addLink( s6, host9 ) |
| 134 | self.addLink( s6, host10 ) |
| 135 | self.addLink( s6, host11 ) |
| 136 | self.addLink( s6, host12 ) |
| 137 | self.addLink( s6, host13 ) |
| 138 | self.addLink( s6, host14 ) |
| 139 | self.addLink( s6, host15 ) |
| 140 | self.addLink( s6, host16 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 141 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 142 | self.addLink( s7, host17 ) |
| 143 | self.addLink( s7, host18 ) |
| 144 | self.addLink( s7, host19 ) |
| 145 | self.addLink( s7, host20 ) |
| 146 | self.addLink( s7, host21 ) |
| 147 | self.addLink( s7, host22 ) |
| 148 | self.addLink( s7, host23 ) |
| 149 | self.addLink( s7, host24 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 150 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 151 | self.addLink( s1, s2 ) |
| 152 | self.addLink( s1, s3 ) |
| 153 | self.addLink( s1, s4 ) |
| 154 | self.addLink( s1, s5 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 155 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 156 | self.addLink( s2, s3 ) |
| 157 | self.addLink( s2, s5 ) |
| 158 | self.addLink( s2, s6 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 159 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 160 | self.addLink( s3, s4 ) |
| 161 | self.addLink( s3, s6 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 162 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 163 | self.addLink( s4, s7 ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 164 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 165 | |
| 166 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 167 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 168 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 169 | def setupNetwork(): |
| 170 | "Create network" |
| 171 | topo = MyTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 172 | network = Mininet( topo=topo, autoSetMacs=True, controller=None ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 173 | network.start() |
| 174 | CLI( network ) |
| 175 | network.stop() |
| 176 | |
| 177 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 178 | setLogLevel( 'info' ) |
| 179 | # setLogLevel( 'debug' ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 180 | setupNetwork() |