blob: 5edf7f78692f6e3a0e106cd8e7e90eaf11ceb4bb [file] [log] [blame]
kelvin-onlab44147802015-07-27 17:57:31 -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
17class VLANHost( Host ):
18 def config( self, vlan=100, **params ):
Jon Hall0946f652015-08-13 11:44:38 -070019 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
kelvin-onlab44147802015-07-27 17:57:31 -070028
29class IPv6Host( Host ):
30 def config( self, v6Addr='1000:1/64', **params ):
Jon Hall0946f652015-08-13 11:44:38 -070031 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
kelvin-onlab44147802015-07-27 17:57:31 -070036
37class dualStackHost( Host ):
38 def config( self, v6Addr='2000:1/64', **params ):
Jon Hall0946f652015-08-13 11:44:38 -070039 r = super( Host, self ).config( **params )
40 intf = self.defaultIntf()
41 self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
42 return r
kelvin-onlab44147802015-07-27 17:57:31 -070043
44class MyTopo( Topo ):
45
Jon Hall0946f652015-08-13 11:44:38 -070046 def __init__( self ):
47 # Initialize topology
48 Topo.__init__( self )
49 # Switch S5 Hosts
50 host1=self.addHost( 'h1', ip='10.1.0.2/24' )
51 host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
52 host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
53 #VLAN hosts
54 host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
55 host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
56 #VPN-1 and VPN-2 Hosts
57 host6=self.addHost( 'h6', ip='11.1.0.2/24' )
58 host7=self.addHost( 'h7', ip='12.1.0.2/24' )
59 #Multicast Sender
60 host8=self.addHost( 'h8', ip='10.1.0.4/24' )
kelvin-onlab44147802015-07-27 17:57:31 -070061
Jon Hall0946f652015-08-13 11:44:38 -070062 # Switch S6 Hosts
63 host9=self.addHost( 'h9', ip='10.1.0.5/24' )
64 host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
65 host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
66 #VLAN hosts
67 host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
68 host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
69 #VPN-1 and VPN-2 Hosts
70 host14=self.addHost( 'h14', ip='11.1.0.3/24' )
71 host15=self.addHost( 'h15', ip='12.1.0.3/24' )
72 #Multicast Receiver
73 host16=self.addHost( 'h16', ip='10.1.0.7/24' )
kelvin-onlab44147802015-07-27 17:57:31 -070074
Jon Hall0946f652015-08-13 11:44:38 -070075 # Switch S7 Hosts
76 host17=self.addHost( 'h17', ip='10.1.0.8/24' )
77 host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
78 host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
79 #VLAN hosts
80 host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
81 host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
82 #VPN-1 and VPN-2 Hosts
83 host22=self.addHost( 'h22', ip='11.1.0.4/24' )
84 host23=self.addHost( 'h23', ip='12.1.0.4/24' )
85 #Multicast Receiver
86 host24=self.addHost( 'h24', ip='10.1.0.10/24' )
kelvin-onlab44147802015-07-27 17:57:31 -070087
Jon Hall0946f652015-08-13 11:44:38 -070088 s1 = self.addSwitch( 's1' )
89 s2 = self.addSwitch( 's2' )
90 s3 = self.addSwitch( 's3' )
91 s4 = self.addSwitch( 's4' )
92 s5 = self.addSwitch( 's5' )
93 s6 = self.addSwitch( 's6' )
94 s7 = self.addSwitch( 's7' )
kelvin-onlab44147802015-07-27 17:57:31 -070095
Jon Hall0946f652015-08-13 11:44:38 -070096 self.addLink(s5,host1)
97 self.addLink(s5,host2)
98 self.addLink(s5,host3)
99 self.addLink(s5,host4)
100 self.addLink(s5,host5)
101 self.addLink(s5,host6)
102 self.addLink(s5,host7)
103 self.addLink(s5,host8)
kelvin-onlab44147802015-07-27 17:57:31 -0700104
Jon Hall0946f652015-08-13 11:44:38 -0700105 self.addLink(s6,host9)
106 self.addLink(s6,host10)
107 self.addLink(s6,host11)
108 self.addLink(s6,host12)
109 self.addLink(s6,host13)
110 self.addLink(s6,host14)
111 self.addLink(s6,host15)
112 self.addLink(s6,host16)
kelvin-onlab44147802015-07-27 17:57:31 -0700113
Jon Hall0946f652015-08-13 11:44:38 -0700114 self.addLink(s7,host17)
115 self.addLink(s7,host18)
116 self.addLink(s7,host19)
117 self.addLink(s7,host20)
118 self.addLink(s7,host21)
119 self.addLink(s7,host22)
120 self.addLink(s7,host23)
121 self.addLink(s7,host24)
kelvin-onlab44147802015-07-27 17:57:31 -0700122
Jon Hall0946f652015-08-13 11:44:38 -0700123 self.addLink(s1,s2)
124 self.addLink(s1,s3)
125 self.addLink(s1,s4)
126 self.addLink(s1,s5)
127 self.addLink(s2,s3)
128 self.addLink(s2,s5)
129 self.addLink(s2,s6)
130 self.addLink(s3,s4)
131 self.addLink(s3,s6)
132 self.addLink(s4,s7)
133 topos = { 'mytopo': ( lambda: MyTopo() ) }
kelvin-onlab44147802015-07-27 17:57:31 -0700134
135# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
136
137def setupNetwork():
138 "Create network"
139 topo = MyTopo()
140 network = Mininet(topo=topo, autoSetMacs=True, controller=None)
141 network.start()
142 CLI( network )
143 network.stop()
144
145if __name__ == '__main__':
146 setLogLevel('info')
147 #setLogLevel('debug')
148 setupNetwork()