Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 22 | #!/usr/bin/python |
| 23 | |
| 24 | """ |
| 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 ): |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 39 | def config( self, vlan=100, v6Addr='3000::1/64', **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'] ) ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 45 | self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) ) |
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 | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 50 | |
| 51 | class IPv6Host( Host ): |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 52 | def config( self, v6Addr='1000::1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 53 | r = super( Host, self ).config( **params ) |
| 54 | intf = self.defaultIntf() |
| 55 | self.cmd( 'ifconfig %s inet 0' % intf ) |
| 56 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 57 | return r |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 58 | |
| 59 | class dualStackHost( Host ): |
| 60 | def config( self, v6Addr='2000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 61 | r = super( Host, self ).config( **params ) |
| 62 | intf = self.defaultIntf() |
| 63 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 64 | return r |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 65 | |
| 66 | class MyTopo( Topo ): |
| 67 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 68 | def __init__( self ): |
| 69 | # Initialize topology |
| 70 | Topo.__init__( self ) |
| 71 | # Switch S5 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 72 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 73 | host1=self.addHost( 'h1', ip='10.1.0.2/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 74 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 75 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 76 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 77 | host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 78 | # VLAN hosts |
| 79 | host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100, v6Addr='3000::2/64' ) |
| 80 | host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200, v6Addr='4000::2/64' ) |
| 81 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 82 | host6=self.addHost( 'h6', ip='11.1.0.2/24' ) |
| 83 | host7=self.addHost( 'h7', ip='12.1.0.2/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 84 | # Multicast Sender |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 85 | host8=self.addHost( 'h8', ip='10.1.0.4/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 86 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 87 | # Switch S6 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 88 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 89 | host9=self.addHost( 'h9', ip='10.1.0.5/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 90 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 91 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 92 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 93 | host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 94 | # VLAN hosts |
| 95 | host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100, v6Addr='3000::3/64' ) |
| 96 | host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200, v6Addr='4000::3/64' ) |
| 97 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 98 | host14=self.addHost( 'h14', ip='11.1.0.3/24' ) |
| 99 | host15=self.addHost( 'h15', ip='12.1.0.3/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 100 | # Multicast Receiver |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 101 | host16=self.addHost( 'h16', ip='10.1.0.7/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 102 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 103 | # Switch S7 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 104 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 105 | host17=self.addHost( 'h17', ip='10.1.0.8/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 106 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 107 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 108 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 109 | host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 110 | # VLAN hosts |
| 111 | host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100, v6Addr='3000::4/64' ) |
| 112 | host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200, v6Addr='4000::4/64' ) |
| 113 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 114 | host22=self.addHost( 'h22', ip='11.1.0.4/24' ) |
| 115 | host23=self.addHost( 'h23', ip='12.1.0.4/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 116 | # Multicast Receiver |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 117 | host24=self.addHost( 'h24', ip='10.1.0.10/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 118 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 119 | s1 = self.addSwitch( 's1' ) |
| 120 | s2 = self.addSwitch( 's2' ) |
| 121 | s3 = self.addSwitch( 's3' ) |
| 122 | s4 = self.addSwitch( 's4' ) |
| 123 | s5 = self.addSwitch( 's5' ) |
| 124 | s6 = self.addSwitch( 's6' ) |
| 125 | s7 = self.addSwitch( 's7' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 126 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 127 | self.addLink(s5,host1) |
| 128 | self.addLink(s5,host2) |
| 129 | self.addLink(s5,host3) |
| 130 | self.addLink(s5,host4) |
| 131 | self.addLink(s5,host5) |
| 132 | self.addLink(s5,host6) |
| 133 | self.addLink(s5,host7) |
| 134 | self.addLink(s5,host8) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 135 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 136 | self.addLink(s6,host9) |
| 137 | self.addLink(s6,host10) |
| 138 | self.addLink(s6,host11) |
| 139 | self.addLink(s6,host12) |
| 140 | self.addLink(s6,host13) |
| 141 | self.addLink(s6,host14) |
| 142 | self.addLink(s6,host15) |
| 143 | self.addLink(s6,host16) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 144 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 145 | self.addLink(s7,host17) |
| 146 | self.addLink(s7,host18) |
| 147 | self.addLink(s7,host19) |
| 148 | self.addLink(s7,host20) |
| 149 | self.addLink(s7,host21) |
| 150 | self.addLink(s7,host22) |
| 151 | self.addLink(s7,host23) |
| 152 | self.addLink(s7,host24) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 153 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 154 | self.addLink(s1,s2) |
| 155 | self.addLink(s1,s3) |
| 156 | self.addLink(s1,s4) |
| 157 | self.addLink(s1,s5) |
| 158 | self.addLink(s2,s3) |
| 159 | self.addLink(s2,s5) |
| 160 | self.addLink(s2,s6) |
| 161 | self.addLink(s3,s4) |
| 162 | self.addLink(s3,s6) |
| 163 | self.addLink(s4,s7) |
| 164 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 165 | |
| 166 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 167 | |
| 168 | def setupNetwork(): |
| 169 | "Create network" |
| 170 | topo = MyTopo() |
| 171 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 172 | network.start() |
| 173 | CLI( network ) |
| 174 | network.stop() |
| 175 | |
| 176 | if __name__ == '__main__': |
| 177 | setLogLevel('info') |
| 178 | #setLogLevel('debug') |
| 179 | setupNetwork() |