blob: 8a5e4020e0e515b59157d2129c88e52a3f3f95f4 [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
GlennRC68449942015-10-16 16:03:12 -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
GlennRC073e8bc2015-10-27 17:11:28 -070038class 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
GlennRC68449942015-10-16 16:03:12 -070058class MyTopo( Topo ):
59
GlennRC073e8bc2015-10-27 17:11:28 -070060 def __init__( self, **opts ):
GlennRC68449942015-10-16 16:03:12 -070061 # Initialize topology
GlennRC073e8bc2015-10-27 17:11:28 -070062 Topo.__init__( self, **opts)
63
64 # IPv4 hosts
65 host1=self.addHost( 'h1', ip='10.0.0.1/24' )
66 host2=self.addHost( 'h2', ip='10.0.0.2/24' )
67
68 # VLAN hosts
69 host3=self.addHost( 'h3', ip='10.0.0.3/24', cls=VLANHost, vlan=10 )
70 host4=self.addHost( 'h4', ip='10.0.0.4/24', cls=VLANHost, vlan=10 )
71
alisone14d7b02016-07-06 10:31:51 -070072 #IPv6 hosts
73 host5=self.addHost( 'h5', ip='10.0.0.5/24', cls=IPv6Host, v6Addr='1000::5/64')
74 host6=self.addHost( 'h6', ip='10.0.0.6/24', cls=IPv6Host, v6Addr='1000::6/64')
GlennRC68449942015-10-16 16:03:12 -070075
76 s1 = self.addSwitch( 's1' )
GlennRC68449942015-10-16 16:03:12 -070077
78 self.addLink(s1, host1)
79 self.addLink(s1, host2)
GlennRC073e8bc2015-10-27 17:11:28 -070080 self.addLink(s1, host3)
81 self.addLink(s1, host4)
alisone14d7b02016-07-06 10:31:51 -070082 self.addLink(s1, host5)
83 self.addLink(s1, host6)
GlennRC68449942015-10-16 16:03:12 -070084
85
86 topos = { 'mytopo': ( lambda: MyTopo() ) }
87
88def setupNetwork():
89 "Create network"
90 topo = MyTopo()
GlennRC073e8bc2015-10-27 17:11:28 -070091 network = Mininet(topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None)
GlennRC68449942015-10-16 16:03:12 -070092 network.start()
93 CLI( network )
94 network.stop()
95
96if __name__ == '__main__':
97 setLogLevel('info')
98 #setLogLevel('debug')
99 setupNetwork()