suibin zhang | 116647a | 2016-05-06 16:30:09 -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 | |
| 50 | # Switch S5 Hosts |
| 51 | host1=self.addHost( 'h1', ip='10.1.0.2/24' ) |
| 52 | host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' ) |
| 53 | host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' ) |
| 54 | #VLAN hosts |
| 55 | host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 ) |
| 56 | host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 ) |
| 57 | #VPN-1 and VPN-2 Hosts |
| 58 | host6=self.addHost( 'h6', ip='11.1.0.2/24' ) |
| 59 | host7=self.addHost( 'h7', ip='12.1.0.2/24' ) |
| 60 | #Multicast Sender |
| 61 | host8=self.addHost( 'h8', ip='10.1.0.4/24' ) |
| 62 | |
| 63 | # Switch S6 Hosts |
| 64 | host9=self.addHost( 'h9', ip='10.1.0.5/24' ) |
| 65 | host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' ) |
| 66 | host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' ) |
| 67 | #VLAN hosts |
| 68 | host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 ) |
| 69 | host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 ) |
| 70 | #VPN-1 and VPN-2 Hosts |
| 71 | host14=self.addHost( 'h14', ip='11.1.0.3/24' ) |
| 72 | host15=self.addHost( 'h15', ip='12.1.0.3/24' ) |
| 73 | #Multicast Receiver |
| 74 | host16=self.addHost( 'h16', ip='10.1.0.7/24' ) |
| 75 | |
| 76 | # Switch S7 Hosts |
| 77 | host17=self.addHost( 'h17', ip='10.1.0.8/24' ) |
| 78 | host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' ) |
| 79 | host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' ) |
| 80 | #VLAN hosts |
| 81 | host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 ) |
| 82 | host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 ) |
| 83 | #VPN-1 and VPN-2 Hosts |
| 84 | host22=self.addHost( 'h22', ip='11.1.0.4/24' ) |
| 85 | host23=self.addHost( 'h23', ip='12.1.0.4/24' ) |
| 86 | #Multicast Receiver |
| 87 | host24=self.addHost( 'h24', ip='10.1.0.10/24' ) |
| 88 | |
| 89 | s1 = self.addSwitch( 's1' ) |
| 90 | s2 = self.addSwitch( 's2' ) |
| 91 | s3 = self.addSwitch( 's3' ) |
| 92 | s4 = self.addSwitch( 's4' ) |
| 93 | s5 = self.addSwitch( 's5' ) |
| 94 | s6 = self.addSwitch( 's6' ) |
| 95 | s7 = self.addSwitch( 's7' ) |
| 96 | |
| 97 | self.addLink(s5,host1) |
| 98 | self.addLink(s5,host2) |
| 99 | self.addLink(s5,host3) |
| 100 | self.addLink(s5,host4) |
| 101 | self.addLink(s5,host5) |
| 102 | self.addLink(s5,host6) |
| 103 | self.addLink(s5,host7) |
| 104 | self.addLink(s5,host8) |
| 105 | |
| 106 | self.addLink(s6,host9) |
| 107 | self.addLink(s6,host10) |
| 108 | self.addLink(s6,host11) |
| 109 | self.addLink(s6,host12) |
| 110 | self.addLink(s6,host13) |
| 111 | self.addLink(s6,host14) |
| 112 | self.addLink(s6,host15) |
| 113 | self.addLink(s6,host16) |
| 114 | |
| 115 | self.addLink(s7,host17) |
| 116 | self.addLink(s7,host18) |
| 117 | self.addLink(s7,host19) |
| 118 | self.addLink(s7,host20) |
| 119 | self.addLink(s7,host21) |
| 120 | self.addLink(s7,host22) |
| 121 | self.addLink(s7,host23) |
| 122 | self.addLink(s7,host24) |
| 123 | |
| 124 | self.addLink(s1,s2) |
| 125 | self.addLink(s1,s3) |
| 126 | self.addLink(s1,s4) |
| 127 | self.addLink(s1,s5) |
| 128 | |
| 129 | self.addLink(s2,s3) |
| 130 | self.addLink(s2,s5) |
| 131 | self.addLink(s2,s6) |
| 132 | |
| 133 | self.addLink(s3,s4) |
| 134 | self.addLink(s3,s6) |
| 135 | |
| 136 | self.addLink(s4,s7) |
| 137 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 138 | |
| 139 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 140 | |
| 141 | def setupNetwork(): |
| 142 | "Create network" |
| 143 | topo = MyTopo() |
| 144 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 145 | network.start() |
| 146 | CLI( network ) |
| 147 | network.stop() |
| 148 | |
| 149 | if __name__ == '__main__': |
| 150 | setLogLevel('info') |
| 151 | #setLogLevel('debug') |
| 152 | setupNetwork() |