blob: 6170025656e9f71d356813e104c8ba175b549ad1 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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-onlabd48a68c2015-07-13 16:01:36 -070022#!/usr/bin/python
23
24"""
25Custom topology for Mininet
26"""
27from mininet.topo import Topo
28from mininet.net import Mininet
29from mininet.node import Host, RemoteController
30from mininet.node import Node
31from mininet.node import CPULimitedHost
32from mininet.link import TCLink
33from mininet.cli import CLI
34from mininet.log import setLogLevel
35from mininet.util import dumpNodeConnections
36from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
37
38class VLANHost( Host ):
Hari Krishna710d45e2015-10-02 15:54:55 -070039 def config( self, vlan=100, v6Addr='3000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070040 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 Krishna710d45e2015-10-02 15:54:55 -070045 self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) )
Jon Hall4ba53f02015-07-29 13:07:41 -070046 newName = '%s.%d' % ( intf, vlan )
47 intf.name = newName
48 self.nameToIntf[ newName ] = intf
49 return r
kelvin-onlabd48a68c2015-07-13 16:01:36 -070050
51class IPv6Host( Host ):
Hari Krishna710d45e2015-10-02 15:54:55 -070052 def config( self, v6Addr='1000::1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070053 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-onlabd48a68c2015-07-13 16:01:36 -070058
59class dualStackHost( Host ):
60 def config( self, v6Addr='2000:1/64', **params ):
Jon Hall4ba53f02015-07-29 13:07:41 -070061 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-onlabd48a68c2015-07-13 16:01:36 -070065
66class MyTopo( Topo ):
67
Jon Hall4ba53f02015-07-29 13:07:41 -070068 def __init__( self ):
69 # Initialize topology
70 Topo.__init__( self )
71 # Switch S5 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070072 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070073 host1=self.addHost( 'h1', ip='10.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070074 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070075 host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070076 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -070077 host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070078 # 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 Hall4ba53f02015-07-29 13:07:41 -070082 host6=self.addHost( 'h6', ip='11.1.0.2/24' )
83 host7=self.addHost( 'h7', ip='12.1.0.2/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070084 # Multicast Sender
Jon Hall4ba53f02015-07-29 13:07:41 -070085 host8=self.addHost( 'h8', ip='10.1.0.4/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -070086
Jon Hall4ba53f02015-07-29 13:07:41 -070087 # Switch S6 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -070088 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070089 host9=self.addHost( 'h9', ip='10.1.0.5/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -070090 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -070091 host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070092 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -070093 host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -070094 # 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 Hall4ba53f02015-07-29 13:07:41 -070098 host14=self.addHost( 'h14', ip='11.1.0.3/24' )
99 host15=self.addHost( 'h15', ip='12.1.0.3/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700100 # Multicast Receiver
Jon Hall4ba53f02015-07-29 13:07:41 -0700101 host16=self.addHost( 'h16', ip='10.1.0.7/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700102
Jon Hall4ba53f02015-07-29 13:07:41 -0700103 # Switch S7 Hosts
Hari Krishna710d45e2015-10-02 15:54:55 -0700104 # IPv4 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -0700105 host17=self.addHost( 'h17', ip='10.1.0.8/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700106 # IPv6 only Host
Jon Hall4ba53f02015-07-29 13:07:41 -0700107 host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700108 # Dual Stack Host
Jon Hall4ba53f02015-07-29 13:07:41 -0700109 host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700110 # 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 Hall4ba53f02015-07-29 13:07:41 -0700114 host22=self.addHost( 'h22', ip='11.1.0.4/24' )
115 host23=self.addHost( 'h23', ip='12.1.0.4/24' )
Hari Krishna710d45e2015-10-02 15:54:55 -0700116 # Multicast Receiver
Jon Hall4ba53f02015-07-29 13:07:41 -0700117 host24=self.addHost( 'h24', ip='10.1.0.10/24' )
kelvin-onlabd48a68c2015-07-13 16:01:36 -0700118
Jon Hall4ba53f02015-07-29 13:07:41 -0700119 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-onlabd48a68c2015-07-13 16:01:36 -0700126
Jon Hall4ba53f02015-07-29 13:07:41 -0700127 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-onlabd48a68c2015-07-13 16:01:36 -0700135
Jon Hall4ba53f02015-07-29 13:07:41 -0700136 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-onlabd48a68c2015-07-13 16:01:36 -0700144
Jon Hall4ba53f02015-07-29 13:07:41 -0700145 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-onlabd48a68c2015-07-13 16:01:36 -0700153
Jon Hall4ba53f02015-07-29 13:07:41 -0700154 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-onlabd48a68c2015-07-13 16:01:36 -0700165
166# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
167
168def 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
176if __name__ == '__main__':
177 setLogLevel('info')
178 #setLogLevel('debug')
179 setupNetwork()