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 |
| 51 | # IPv4 only Host |
| 52 | host1=self.addHost( 'h1', cls=IPv6Host, v6Addr='10:1:0::1/64' ) |
| 53 | # IPv6 only Host |
| 54 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
| 55 | # Dual Stack Host |
| 56 | host3=self.addHost( 'h3', cls=IPv6Host, v6Addr='2000::2/64' ) |
| 57 | # VLAN hosts |
| 58 | host4=self.addHost( 'h4', cls=IPv6Host, v6Addr='3000::2/64' ) |
| 59 | host5=self.addHost( 'h5', cls=IPv6Host,v6Addr='4000::2/64' ) |
| 60 | # VPN-1 and VPN-2 Hosts |
| 61 | host6=self.addHost( 'h6', cls=IPv6Host, v6Addr='11:1:0::2/64' ) |
| 62 | host7=self.addHost( 'h7', cls=IPv6Host, v6Addr='12:1:0::2/64' ) |
| 63 | # Multicast Sender |
| 64 | host8=self.addHost( 'h8', cls=IPv6Host, v6Addr='10:1:0::4/64' ) |
| 65 | |
| 66 | # Switch S6 Hosts |
| 67 | # IPv4 only Host |
| 68 | host9=self.addHost( 'h9', cls=IPv6Host, v6Addr='10:1:0::5/64' ) |
| 69 | # IPv6 only Host |
| 70 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
| 71 | # Dual Stack Host |
| 72 | host11=self.addHost( 'h11', cls=IPv6Host, v6Addr='2000::3/64' ) |
| 73 | # VLAN hosts |
| 74 | host12=self.addHost( 'h12', cls=IPv6Host, v6Addr='3000::3/64' ) |
| 75 | host13=self.addHost( 'h13', cls=IPv6Host, v6Addr='4000::3/64' ) |
| 76 | # VPN-1 and VPN-2 Hosts |
| 77 | host14=self.addHost( 'h14', cls=IPv6Host, v6Addr='11:1:0::3/64' ) |
| 78 | host15=self.addHost( 'h15', cls=IPv6Host, v6Addr='12:1:0::3/64' ) |
| 79 | # Multicast Receiver |
| 80 | host16=self.addHost( 'h16', cls=IPv6Host, v6Addr='10:1:0::7/64' ) |
| 81 | |
| 82 | # Switch S7 Hosts |
| 83 | # IPv4 only Host |
| 84 | host17=self.addHost( 'h17', cls=IPv6Host, v6Addr='10:1:0::8/64' ) |
| 85 | # IPv6 only Host |
| 86 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
| 87 | # Dual Stack Host |
| 88 | host19=self.addHost( 'h19', cls=IPv6Host, v6Addr='10:1:0::9/64' ) |
| 89 | # VLAN hosts |
| 90 | host20=self.addHost( 'h20', cls=IPv6Host, v6Addr='100:1:0::4/64' ) |
| 91 | host21=self.addHost( 'h21', cls=IPv6Host, v6Addr='200:1:0::4/64' ) |
| 92 | # VPN-1 and VPN-2 Hosts |
| 93 | host22=self.addHost( 'h22', cls=IPv6Host, v6Addr='11:1:0::4/64' ) |
| 94 | host23=self.addHost( 'h23', cls=IPv6Host, v6Addr='12:1:0::4/64' ) |
| 95 | # Multicast Receiver |
| 96 | host24=self.addHost( 'h24', cls=IPv6Host, v6Addr='10:1:0::10/64' ) |
| 97 | |
| 98 | s1 = self.addSwitch( 's1' ) |
| 99 | s2 = self.addSwitch( 's2' ) |
| 100 | s3 = self.addSwitch( 's3' ) |
| 101 | s4 = self.addSwitch( 's4' ) |
| 102 | s5 = self.addSwitch( 's5' ) |
| 103 | s6 = self.addSwitch( 's6' ) |
| 104 | s7 = self.addSwitch( 's7' ) |
| 105 | |
| 106 | self.addLink(s5,host1) |
| 107 | self.addLink(s5,host2) |
| 108 | self.addLink(s5,host3) |
| 109 | self.addLink(s5,host4) |
| 110 | self.addLink(s5,host5) |
| 111 | self.addLink(s5,host6) |
| 112 | self.addLink(s5,host7) |
| 113 | self.addLink(s5,host8) |
| 114 | |
| 115 | self.addLink(s6,host9) |
| 116 | self.addLink(s6,host10) |
| 117 | self.addLink(s6,host11) |
| 118 | self.addLink(s6,host12) |
| 119 | self.addLink(s6,host13) |
| 120 | self.addLink(s6,host14) |
| 121 | self.addLink(s6,host15) |
| 122 | self.addLink(s6,host16) |
| 123 | |
| 124 | self.addLink(s7,host17) |
| 125 | self.addLink(s7,host18) |
| 126 | self.addLink(s7,host19) |
| 127 | self.addLink(s7,host20) |
| 128 | self.addLink(s7,host21) |
| 129 | self.addLink(s7,host22) |
| 130 | self.addLink(s7,host23) |
| 131 | self.addLink(s7,host24) |
| 132 | |
| 133 | self.addLink(s1,s2) |
| 134 | self.addLink(s1,s3) |
| 135 | self.addLink(s1,s4) |
| 136 | self.addLink(s1,s5) |
| 137 | self.addLink(s2,s3) |
| 138 | self.addLink(s2,s5) |
| 139 | self.addLink(s2,s6) |
| 140 | self.addLink(s3,s4) |
| 141 | self.addLink(s3,s6) |
| 142 | self.addLink(s4,s7) |
| 143 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 144 | |
| 145 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 146 | |
| 147 | def setupNetwork(): |
| 148 | "Create network" |
| 149 | topo = MyTopo() |
| 150 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 151 | network.start() |
| 152 | CLI( network ) |
| 153 | network.stop() |
| 154 | |
| 155 | if __name__ == '__main__': |
| 156 | setLogLevel('info') |
| 157 | #setLogLevel('debug') |
| 158 | setupNetwork() |