Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | Custom topology for Mininet |
| 5 | """ |
| 6 | from mininet.topo import Topo |
| 7 | from mininet.net import Mininet |
| 8 | from mininet.node import Host, RemoteController |
| 9 | from mininet.node import Node |
| 10 | from mininet.node import CPULimitedHost |
| 11 | from mininet.link import TCLink |
| 12 | from mininet.cli import CLI |
| 13 | from mininet.log import setLogLevel |
| 14 | from mininet.util import dumpNodeConnections |
| 15 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 16 | |
| 17 | class VLANHost( Host ): |
| 18 | def config( self, vlan=100, v6Addr='3000::1/64', **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 | self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) ) |
| 25 | newName = '%s.%d' % ( intf, vlan ) |
| 26 | intf.name = newName |
| 27 | self.nameToIntf[ newName ] = intf |
| 28 | return r |
| 29 | |
| 30 | class IPv6Host( Host ): |
| 31 | def config( self, v6Addr='1000::1/64', **params ): |
| 32 | r = super( Host, self ).config( **params ) |
| 33 | intf = self.defaultIntf() |
| 34 | self.cmd( 'ifconfig %s inet 0' % intf ) |
| 35 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 36 | return r |
| 37 | |
| 38 | class dualStackHost( Host ): |
| 39 | def config( self, v6Addr='2000:1/64', **params ): |
| 40 | r = super( Host, self ).config( **params ) |
| 41 | intf = self.defaultIntf() |
| 42 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 43 | return r |
| 44 | |
| 45 | class MyTopo( Topo ): |
| 46 | |
| 47 | def __init__( self ): |
| 48 | # Initialize topology |
| 49 | Topo.__init__( self ) |
| 50 | # Switch S5 Hosts |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 51 | host1=self.addHost( 'h1', cls=IPv6Host, v6Addr='10:1:0::1/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 52 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
| 53 | # Dual Stack Host |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 54 | host3=self.addHost( 'h3', cls=dualStackHost, v6Addr='2000::2/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 55 | host4=self.addHost( 'h4', cls=IPv6Host, v6Addr='3000::2/64' ) |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 56 | #VLAN |
| 57 | host5=self.addHost( 'h5', cls=VLANHost,v6Addr='4000::2/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 58 | host6=self.addHost( 'h6', cls=IPv6Host, v6Addr='11:1:0::2/64' ) |
| 59 | host7=self.addHost( 'h7', cls=IPv6Host, v6Addr='12:1:0::2/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 60 | host8=self.addHost( 'h8', cls=IPv6Host, v6Addr='10:1:0::4/64' ) |
| 61 | |
| 62 | # Switch S6 Hosts |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 63 | host9=self.addHost( 'h9', cls=IPv6Host, v6Addr='10:1:0::5/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 64 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
| 65 | # Dual Stack Host |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 66 | host11=self.addHost( 'h11', cls=dualStackHost, v6Addr='2000::3/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 67 | host12=self.addHost( 'h12', cls=IPv6Host, v6Addr='3000::3/64' ) |
| 68 | host13=self.addHost( 'h13', cls=IPv6Host, v6Addr='4000::3/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 69 | host14=self.addHost( 'h14', cls=IPv6Host, v6Addr='11:1:0::3/64' ) |
| 70 | host15=self.addHost( 'h15', cls=IPv6Host, v6Addr='12:1:0::3/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 71 | host16=self.addHost( 'h16', cls=IPv6Host, v6Addr='10:1:0::7/64' ) |
| 72 | |
| 73 | # Switch S7 Hosts |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 74 | host17=self.addHost( 'h17', cls=IPv6Host, v6Addr='10:1:0::8/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 75 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 76 | host19=self.addHost( 'h19', cls=IPv6Host, v6Addr='10:1:0::9/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 77 | host20=self.addHost( 'h20', cls=IPv6Host, v6Addr='100:1:0::4/64' ) |
| 78 | host21=self.addHost( 'h21', cls=IPv6Host, v6Addr='200:1:0::4/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 79 | host22=self.addHost( 'h22', cls=IPv6Host, v6Addr='11:1:0::4/64' ) |
| 80 | host23=self.addHost( 'h23', cls=IPv6Host, v6Addr='12:1:0::4/64' ) |
sathishm | ad95346 | 2015-12-03 17:42:07 +0530 | [diff] [blame] | 81 | # VLAN |
| 82 | host24=self.addHost( 'h24', cls=VLANHost, v6Addr='4000::5/64' ) |
Subhash Kumar Singh | c73b3a7 | 2015-11-03 21:34:04 -0800 | [diff] [blame] | 83 | |
| 84 | s1 = self.addSwitch( 's1' ) |
| 85 | s2 = self.addSwitch( 's2' ) |
| 86 | s3 = self.addSwitch( 's3' ) |
| 87 | s4 = self.addSwitch( 's4' ) |
| 88 | s5 = self.addSwitch( 's5' ) |
| 89 | s6 = self.addSwitch( 's6' ) |
| 90 | s7 = self.addSwitch( 's7' ) |
| 91 | |
| 92 | self.addLink(s5,host1) |
| 93 | self.addLink(s5,host2) |
| 94 | self.addLink(s5,host3) |
| 95 | self.addLink(s5,host4) |
| 96 | self.addLink(s5,host5) |
| 97 | self.addLink(s5,host6) |
| 98 | self.addLink(s5,host7) |
| 99 | self.addLink(s5,host8) |
| 100 | |
| 101 | self.addLink(s6,host9) |
| 102 | self.addLink(s6,host10) |
| 103 | self.addLink(s6,host11) |
| 104 | self.addLink(s6,host12) |
| 105 | self.addLink(s6,host13) |
| 106 | self.addLink(s6,host14) |
| 107 | self.addLink(s6,host15) |
| 108 | self.addLink(s6,host16) |
| 109 | |
| 110 | self.addLink(s7,host17) |
| 111 | self.addLink(s7,host18) |
| 112 | self.addLink(s7,host19) |
| 113 | self.addLink(s7,host20) |
| 114 | self.addLink(s7,host21) |
| 115 | self.addLink(s7,host22) |
| 116 | self.addLink(s7,host23) |
| 117 | self.addLink(s7,host24) |
| 118 | |
| 119 | self.addLink(s1,s2) |
| 120 | self.addLink(s1,s3) |
| 121 | self.addLink(s1,s4) |
| 122 | self.addLink(s1,s5) |
| 123 | self.addLink(s2,s3) |
| 124 | self.addLink(s2,s5) |
| 125 | self.addLink(s2,s6) |
| 126 | self.addLink(s3,s4) |
| 127 | self.addLink(s3,s6) |
| 128 | self.addLink(s4,s7) |
| 129 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 130 | |
| 131 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 132 | |
| 133 | def setupNetwork(): |
| 134 | "Create network" |
| 135 | topo = MyTopo() |
| 136 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 137 | network.start() |
| 138 | CLI( network ) |
| 139 | network.stop() |
| 140 | |
| 141 | if __name__ == '__main__': |
| 142 | setLogLevel('info') |
| 143 | #setLogLevel('debug') |
| 144 | setupNetwork() |