blob: 0d7277012c9a8ec7890b686b6ab2d2cba28e9868 [file] [log] [blame]
suibin zhang116647a2016-05-06 16:30:09 -07001#!/usr/bin/python
2
3"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07004Copyright 2016 Open Networking Foundation (ONF)
5
6Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or 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"""
suibin zhang116647a2016-05-06 16:30:09 -070025Custom 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 ):
39 def config( self, vlan=100, **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 newName = '%s.%d' % ( intf, vlan )
46 intf.name = newName
47 self.nameToIntf[ newName ] = intf
48 return r
49
50class IPv6Host( Host ):
51 def config( self, v6Addr='1000:1/64', **params ):
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
57
58class dualStackHost( Host ):
59 def config( self, v6Addr='2000:1/64', **params ):
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
64
65class MyTopo( Topo ):
66
67 def __init__( self ):
68 # Initialize topology
69 Topo.__init__( self )
70
71 # Switch S5 Hosts
72 host1=self.addHost( 'h1', ip='10.1.0.2/24' )
73 host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
74 host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
75 #VLAN hosts
76 host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
77 host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
78 #VPN-1 and VPN-2 Hosts
79 host6=self.addHost( 'h6', ip='11.1.0.2/24' )
80 host7=self.addHost( 'h7', ip='12.1.0.2/24' )
81 #Multicast Sender
82 host8=self.addHost( 'h8', ip='10.1.0.4/24' )
83
84 # Switch S6 Hosts
85 host9=self.addHost( 'h9', ip='10.1.0.5/24' )
86 host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
87 host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
88 #VLAN hosts
89 host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
90 host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
91 #VPN-1 and VPN-2 Hosts
92 host14=self.addHost( 'h14', ip='11.1.0.3/24' )
93 host15=self.addHost( 'h15', ip='12.1.0.3/24' )
94 #Multicast Receiver
95 host16=self.addHost( 'h16', ip='10.1.0.7/24' )
96
97 # Switch S7 Hosts
98 host17=self.addHost( 'h17', ip='10.1.0.8/24' )
99 host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
100 host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
101 #VLAN hosts
102 host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
103 host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
104 #VPN-1 and VPN-2 Hosts
105 host22=self.addHost( 'h22', ip='11.1.0.4/24' )
106 host23=self.addHost( 'h23', ip='12.1.0.4/24' )
107 #Multicast Receiver
108 host24=self.addHost( 'h24', ip='10.1.0.10/24' )
109
110 s1 = self.addSwitch( 's1' )
111 s2 = self.addSwitch( 's2' )
112 s3 = self.addSwitch( 's3' )
113 s4 = self.addSwitch( 's4' )
114 s5 = self.addSwitch( 's5' )
115 s6 = self.addSwitch( 's6' )
116 s7 = self.addSwitch( 's7' )
117
118 self.addLink(s5,host1)
119 self.addLink(s5,host2)
120 self.addLink(s5,host3)
121 self.addLink(s5,host4)
122 self.addLink(s5,host5)
123 self.addLink(s5,host6)
124 self.addLink(s5,host7)
125 self.addLink(s5,host8)
126
127 self.addLink(s6,host9)
128 self.addLink(s6,host10)
129 self.addLink(s6,host11)
130 self.addLink(s6,host12)
131 self.addLink(s6,host13)
132 self.addLink(s6,host14)
133 self.addLink(s6,host15)
134 self.addLink(s6,host16)
135
136 self.addLink(s7,host17)
137 self.addLink(s7,host18)
138 self.addLink(s7,host19)
139 self.addLink(s7,host20)
140 self.addLink(s7,host21)
141 self.addLink(s7,host22)
142 self.addLink(s7,host23)
143 self.addLink(s7,host24)
144
145 self.addLink(s1,s2)
146 self.addLink(s1,s3)
147 self.addLink(s1,s4)
148 self.addLink(s1,s5)
149
150 self.addLink(s2,s3)
151 self.addLink(s2,s5)
152 self.addLink(s2,s6)
153
154 self.addLink(s3,s4)
155 self.addLink(s3,s6)
156
157 self.addLink(s4,s7)
158 topos = { 'mytopo': ( lambda: MyTopo() ) }
159
160# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
161
162def setupNetwork():
163 "Create network"
164 topo = MyTopo()
165 network = Mininet(topo=topo, autoSetMacs=True, controller=None)
166 network.start()
167 CLI( network )
168 network.stop()
169
170if __name__ == '__main__':
171 setLogLevel('info')
172 #setLogLevel('debug')
173 setupNetwork()