kelvin-onlab | 4414780 | 2015-07-27 17:57:31 -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 ): |
| 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 | |
| 29 | class 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 | |
| 37 | class dualStackHost( Host ): |
| 38 | def config( self, v6Addr='2000:1/64', **params ): |
| 39 | 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 |
| 43 | |
| 44 | class MyTopo( Topo ): |
| 45 | |
| 46 | 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' ) |
| 61 | |
| 62 | # 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' ) |
| 74 | |
| 75 | # 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' ) |
| 87 | |
| 88 | 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' ) |
| 95 | |
| 96 | 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) |
| 104 | |
| 105 | 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) |
| 113 | |
| 114 | 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) |
| 122 | |
| 123 | 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() ) } |
| 134 | |
| 135 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 136 | |
| 137 | def 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 | |
| 145 | if __name__ == '__main__': |
| 146 | setLogLevel('info') |
| 147 | #setLogLevel('debug') |
| 148 | setupNetwork() |