blob: 6222d7510a97f78567b2f92cce14d888e8389314 [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
alisone14d7b02016-07-06 10:31:51 -070051 #IPv6 hosts
52 host5=self.addHost( 'h5', ip='10.0.0.5/24', cls=IPv6Host, v6Addr='1000::5/64')
53 host6=self.addHost( 'h6', ip='10.0.0.6/24', cls=IPv6Host, v6Addr='1000::6/64')
GlennRC68449942015-10-16 16:03:12 -070054
55 s1 = self.addSwitch( 's1' )
GlennRC68449942015-10-16 16:03:12 -070056
57 self.addLink(s1, host1)
58 self.addLink(s1, host2)
GlennRC073e8bc2015-10-27 17:11:28 -070059 self.addLink(s1, host3)
60 self.addLink(s1, host4)
alisone14d7b02016-07-06 10:31:51 -070061 self.addLink(s1, host5)
62 self.addLink(s1, host6)
GlennRC68449942015-10-16 16:03:12 -070063
64
65 topos = { 'mytopo': ( lambda: MyTopo() ) }
66
67def setupNetwork():
68 "Create network"
69 topo = MyTopo()
GlennRC073e8bc2015-10-27 17:11:28 -070070 network = Mininet(topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None)
GlennRC68449942015-10-16 16:03:12 -070071 network.start()
72 CLI( network )
73 network.stop()
74
75if __name__ == '__main__':
76 setLogLevel('info')
77 #setLogLevel('debug')
78 setupNetwork()