blob: f9d58c1c82a50ff13d1bf65a21c2c04a5bce6240 [file] [log] [blame]
GlennRC68449942015-10-16 16:03:12 -07001#!/usr/bin/python
2
3"""
4Custom topology for Mininet
5"""
6from mininet.topo import Topo
7from mininet.net import Mininet
8from mininet.node import Host, RemoteController
9from mininet.node import Node
10from mininet.node import CPULimitedHost
11from mininet.link import TCLink
12from mininet.cli import CLI
13from mininet.log import setLogLevel
14from mininet.util import dumpNodeConnections
15from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
16
GlennRC073e8bc2015-10-27 17:11:28 -070017class VLANHost( Host ):
18 def config( self, vlan=100, **params ):
19 r = super( Host, self ).config( **params )
20 intf = self.defaultIntf()
21 self.cmd( 'ifconfig %s inet 0' % intf )
22 self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
23 self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
24 newName = '%s.%d' % ( intf, vlan )
25 intf.name = newName
26 self.nameToIntf[ newName ] = intf
27 return r
28
29class IPv6Host( Host ):
30 def config( self, v6Addr='1000:1/64', **params ):
31 r = super( Host, self ).config( **params )
32 intf = self.defaultIntf()
33 self.cmd( 'ifconfig %s inet 0' % intf )
34 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
35 return r
36
GlennRC68449942015-10-16 16:03:12 -070037class MyTopo( Topo ):
38
GlennRC073e8bc2015-10-27 17:11:28 -070039 def __init__( self, **opts ):
GlennRC68449942015-10-16 16:03:12 -070040 # Initialize topology
GlennRC073e8bc2015-10-27 17:11:28 -070041 Topo.__init__( self, **opts)
42
43 # IPv4 hosts
44 host1=self.addHost( 'h1', ip='10.0.0.1/24' )
45 host2=self.addHost( 'h2', ip='10.0.0.2/24' )
46
47 # VLAN hosts
48 host3=self.addHost( 'h3', ip='10.0.0.3/24', cls=VLANHost, vlan=10 )
49 host4=self.addHost( 'h4', ip='10.0.0.4/24', cls=VLANHost, vlan=10 )
50
GlennRC68449942015-10-16 16:03:12 -070051
52 s1 = self.addSwitch( 's1' )
GlennRC68449942015-10-16 16:03:12 -070053
54 self.addLink(s1, host1)
55 self.addLink(s1, host2)
GlennRC073e8bc2015-10-27 17:11:28 -070056 self.addLink(s1, host3)
57 self.addLink(s1, host4)
GlennRC68449942015-10-16 16:03:12 -070058
59
60 topos = { 'mytopo': ( lambda: MyTopo() ) }
61
62def setupNetwork():
63 "Create network"
64 topo = MyTopo()
GlennRC073e8bc2015-10-27 17:11:28 -070065 network = Mininet(topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None)
GlennRC68449942015-10-16 16:03:12 -070066 network.start()
67 CLI( network )
68 network.stop()
69
70if __name__ == '__main__':
71 setLogLevel('info')
72 #setLogLevel('debug')
73 setupNetwork()