kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame^] | 4 | Copyright 2015 Open Networking Foundation (ONF) |
| 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 |
| 13 | (at your option) any later version. |
| 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 | """ |
| 23 | |
| 24 | """ |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 25 | Custom topology for Mininet |
| 26 | """ |
| 27 | from mininet.topo import Topo |
| 28 | from mininet.net import Mininet |
| 29 | from mininet.node import Host, RemoteController |
| 30 | from mininet.node import Node |
| 31 | from mininet.node import CPULimitedHost |
| 32 | from mininet.link import TCLink |
| 33 | from mininet.cli import CLI |
| 34 | from mininet.log import setLogLevel |
| 35 | from mininet.util import dumpNodeConnections |
| 36 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 37 | |
| 38 | class VLANHost( Host ): |
| 39 | def config( self, vlan=100, **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 40 | r = super( Host, self ).config( **params ) |
| 41 | intf = self.defaultIntf() |
| 42 | self.cmd( 'ifconfig %s inet 0' % intf ) |
| 43 | self.cmd( 'vconfig add %s %d' % ( intf, vlan ) ) |
| 44 | self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) ) |
| 45 | newName = '%s.%d' % ( intf, vlan ) |
| 46 | intf.name = newName |
| 47 | self.nameToIntf[ newName ] = intf |
| 48 | return r |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 49 | |
| 50 | class IPv6Host( Host ): |
| 51 | def config( self, v6Addr='1000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 52 | r = super( Host, self ).config( **params ) |
| 53 | intf = self.defaultIntf() |
| 54 | self.cmd( 'ifconfig %s inet 0' % intf ) |
| 55 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 56 | return r |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 57 | |
| 58 | class dualStackHost( Host ): |
| 59 | def config( self, v6Addr='2000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 60 | r = super( Host, self ).config( **params ) |
| 61 | intf = self.defaultIntf() |
| 62 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 63 | return r |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 64 | |
| 65 | class MyTopo( Topo ): |
| 66 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 67 | def __init__( self ): |
| 68 | # Initialize topology |
| 69 | Topo.__init__( self ) |
| 70 | # Switch S5 Hosts |
| 71 | host1=self.addHost( 'h1', ip='10.1.0.2/24' ) |
| 72 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
| 73 | host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' ) |
| 74 | #VLAN hosts |
| 75 | host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 ) |
| 76 | host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 ) |
| 77 | #VPN-1 and VPN-2 Hosts |
| 78 | host6=self.addHost( 'h6', ip='11.1.0.2/24' ) |
| 79 | host7=self.addHost( 'h7', ip='12.1.0.2/24' ) |
| 80 | #Multicast Sender |
| 81 | host8=self.addHost( 'h8', ip='10.1.0.4/24' ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 82 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 83 | # Switch S6 Hosts |
| 84 | host9=self.addHost( 'h9', ip='10.1.0.5/24' ) |
| 85 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
| 86 | host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' ) |
| 87 | #VLAN hosts |
| 88 | host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 ) |
| 89 | host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 ) |
| 90 | #VPN-1 and VPN-2 Hosts |
| 91 | host14=self.addHost( 'h14', ip='11.1.0.3/24' ) |
| 92 | host15=self.addHost( 'h15', ip='12.1.0.3/24' ) |
| 93 | #Multicast Receiver |
| 94 | host16=self.addHost( 'h16', ip='10.1.0.7/24' ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 95 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 96 | # Switch S7 Hosts |
| 97 | host17=self.addHost( 'h17', ip='10.1.0.8/24' ) |
| 98 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
| 99 | host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' ) |
| 100 | #VLAN hosts |
| 101 | host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 ) |
| 102 | host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 ) |
| 103 | #VPN-1 and VPN-2 Hosts |
| 104 | host22=self.addHost( 'h22', ip='11.1.0.4/24' ) |
| 105 | host23=self.addHost( 'h23', ip='12.1.0.4/24' ) |
| 106 | #Multicast Receiver |
| 107 | host24=self.addHost( 'h24', ip='10.1.0.10/24' ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 108 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 109 | s1 = self.addSwitch( 's1' ) |
| 110 | s2 = self.addSwitch( 's2' ) |
| 111 | s3 = self.addSwitch( 's3' ) |
| 112 | s4 = self.addSwitch( 's4' ) |
| 113 | s5 = self.addSwitch( 's5' ) |
| 114 | s6 = self.addSwitch( 's6' ) |
| 115 | s7 = self.addSwitch( 's7' ) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 116 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 117 | self.addLink(s5,host1) |
| 118 | self.addLink(s5,host2) |
| 119 | self.addLink(s5,host3) |
| 120 | self.addLink(s5,host4) |
| 121 | self.addLink(s5,host5) |
| 122 | self.addLink(s5,host6) |
| 123 | self.addLink(s5,host7) |
| 124 | self.addLink(s5,host8) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 125 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 126 | self.addLink(s6,host9) |
| 127 | self.addLink(s6,host10) |
| 128 | self.addLink(s6,host11) |
| 129 | self.addLink(s6,host12) |
| 130 | self.addLink(s6,host13) |
| 131 | self.addLink(s6,host14) |
| 132 | self.addLink(s6,host15) |
| 133 | self.addLink(s6,host16) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 134 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 135 | self.addLink(s7,host17) |
| 136 | self.addLink(s7,host18) |
| 137 | self.addLink(s7,host19) |
| 138 | self.addLink(s7,host20) |
| 139 | self.addLink(s7,host21) |
| 140 | self.addLink(s7,host22) |
| 141 | self.addLink(s7,host23) |
| 142 | self.addLink(s7,host24) |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 143 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 144 | self.addLink(s1,s2) |
| 145 | self.addLink(s1,s3) |
| 146 | self.addLink(s1,s4) |
| 147 | self.addLink(s1,s5) |
| 148 | self.addLink(s2,s3) |
| 149 | self.addLink(s2,s5) |
| 150 | self.addLink(s2,s6) |
| 151 | self.addLink(s3,s4) |
| 152 | self.addLink(s3,s6) |
| 153 | self.addLink(s4,s7) |
| 154 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
kelvin-onlab | 1d381fe | 2015-07-14 16:24:56 -0700 | [diff] [blame] | 155 | |
| 156 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 157 | |
| 158 | def setupNetwork(): |
| 159 | "Create network" |
| 160 | topo = MyTopo() |
| 161 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 162 | network.start() |
| 163 | CLI( network ) |
| 164 | network.stop() |
| 165 | |
| 166 | if __name__ == '__main__': |
| 167 | setLogLevel('info') |
| 168 | #setLogLevel('debug') |
| 169 | setupNetwork() |