kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [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 ): |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 18 | def config( self, vlan=100, v6Addr='3000::1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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'] ) ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 24 | self.cmd( 'ip -6 addr add %s dev %s.%d' % ( v6Addr, intf, vlan ) ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 25 | newName = '%s.%d' % ( intf, vlan ) |
| 26 | intf.name = newName |
| 27 | self.nameToIntf[ newName ] = intf |
| 28 | return r |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 29 | |
| 30 | class IPv6Host( Host ): |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 31 | def config( self, v6Addr='1000::1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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 |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 37 | |
| 38 | class dualStackHost( Host ): |
| 39 | def config( self, v6Addr='2000:1/64', **params ): |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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 |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 44 | |
| 45 | class MyTopo( Topo ): |
| 46 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 47 | def __init__( self ): |
| 48 | # Initialize topology |
| 49 | Topo.__init__( self ) |
| 50 | # Switch S5 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 51 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 52 | host1=self.addHost( 'h1', ip='10.1.0.2/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 53 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 54 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 55 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 56 | host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 57 | # VLAN hosts |
| 58 | host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100, v6Addr='3000::2/64' ) |
| 59 | host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200, v6Addr='4000::2/64' ) |
| 60 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 61 | host6=self.addHost( 'h6', ip='11.1.0.2/24' ) |
| 62 | host7=self.addHost( 'h7', ip='12.1.0.2/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 63 | # Multicast Sender |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 64 | host8=self.addHost( 'h8', ip='10.1.0.4/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 65 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 66 | # Switch S6 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 67 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 68 | host9=self.addHost( 'h9', ip='10.1.0.5/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 69 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 70 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 71 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 72 | host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 73 | # VLAN hosts |
| 74 | host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100, v6Addr='3000::3/64' ) |
| 75 | host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200, v6Addr='4000::3/64' ) |
| 76 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 77 | host14=self.addHost( 'h14', ip='11.1.0.3/24' ) |
| 78 | host15=self.addHost( 'h15', ip='12.1.0.3/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 79 | # Multicast Receiver |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 80 | host16=self.addHost( 'h16', ip='10.1.0.7/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 81 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 82 | # Switch S7 Hosts |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 83 | # IPv4 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 84 | host17=self.addHost( 'h17', ip='10.1.0.8/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 85 | # IPv6 only Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 86 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 87 | # Dual Stack Host |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 88 | host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 89 | # VLAN hosts |
| 90 | host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100, v6Addr='3000::4/64' ) |
| 91 | host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200, v6Addr='4000::4/64' ) |
| 92 | # VPN-1 and VPN-2 Hosts |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 93 | host22=self.addHost( 'h22', ip='11.1.0.4/24' ) |
| 94 | host23=self.addHost( 'h23', ip='12.1.0.4/24' ) |
Hari Krishna | 710d45e | 2015-10-02 15:54:55 -0700 | [diff] [blame] | 95 | # Multicast Receiver |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 96 | host24=self.addHost( 'h24', ip='10.1.0.10/24' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 97 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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' ) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 105 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 114 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 123 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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) |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 132 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 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() ) } |
kelvin-onlab | d48a68c | 2015-07-13 16:01:36 -0700 | [diff] [blame] | 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() |