YPZhang | cb86c5b | 2016-01-27 17:38:12 -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.link import TCLink |
| 11 | from mininet.cli import CLI |
| 12 | from mininet.log import setLogLevel |
| 13 | from mininet.util import dumpNodeConnections |
| 14 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 15 | |
| 16 | class MyTopo( Topo ): |
| 17 | |
| 18 | def __init__( self ): |
| 19 | # Initialize topology |
| 20 | Topo.__init__( self ) |
| 21 | |
| 22 | host1 = self.addHost('h1', ip='10.1.0.1/24') |
| 23 | host2 = self.addHost('h2', ip='10.1.0.2/24') |
| 24 | host3 = self.addHost('h3', ip='10.1.0.3/24') |
| 25 | host4 = self.addHost('h4', ip='10.1.0.4/24') |
| 26 | host5 = self.addHost('h5', ip='10.1.0.5/24') |
| 27 | host6 = self.addHost('h6', ip='10.1.0.6/24') |
| 28 | host7 = self.addHost('h7', ip='10.1.0.7/24') |
| 29 | |
| 30 | s1 = self.addSwitch( 's1' ) |
| 31 | s2 = self.addSwitch( 's2' ) |
| 32 | s3 = self.addSwitch( 's3' ) |
| 33 | s4 = self.addSwitch( 's4' ) |
| 34 | s5 = self.addSwitch( 's5' ) |
| 35 | s6 = self.addSwitch( 's6' ) |
| 36 | s7 = self.addSwitch( 's7' ) |
| 37 | s8 = self.addSwitch( 's8' ) |
| 38 | |
| 39 | |
| 40 | self.addLink(s1, host1) |
| 41 | self.addLink(s2, host2) |
| 42 | self.addLink(s3, host3) |
| 43 | self.addLink(s4, host4) |
| 44 | self.addLink(s5, host5) |
| 45 | self.addLink(s6, host6) |
| 46 | self.addLink(s7, host7) |
| 47 | |
| 48 | |
| 49 | |
| 50 | self.addLink(s1,s2) |
| 51 | self.addLink(s2,s3) |
| 52 | self.addLink(s3,s4) |
| 53 | self.addLink(s4,s5) |
| 54 | self.addLink(s5,s6) |
| 55 | self.addLink(s6,s7) |
| 56 | self.addLink(s4,s8) |
| 57 | self.addLink(s8,s5) |
| 58 | |
| 59 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 60 | |
| 61 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 62 | |
| 63 | def setupNetwork(): |
| 64 | "Create network" |
| 65 | topo = MyTopo() |
| 66 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 67 | network.start() |
| 68 | CLI( network ) |
| 69 | network.stop() |
| 70 | |
| 71 | if __name__ == '__main__': |
| 72 | setLogLevel('info') |
| 73 | #setLogLevel('debug') |
| 74 | setupNetwork() |