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