GlennRC | b3202c5 | 2015-08-24 14:43:30 -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.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 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 18 | def __init__( self ): |
| 19 | # Initialize topology |
| 20 | Topo.__init__( self ) |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 21 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 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') |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 25 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 26 | s1 = self.addSwitch( 's1' ) |
| 27 | s2 = self.addSwitch( 's2' ) |
| 28 | s3 = self.addSwitch( 's3' ) |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 29 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 30 | self.addLink(s1, host1) |
| 31 | self.addLink(s2, host2) |
| 32 | self.addLink(s3, host3) |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 33 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 34 | self.addLink(s1,s2) |
| 35 | self.addLink(s1,s3) |
| 36 | self.addLink(s2,s3) |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 37 | |
Jon Hall | e019baa | 2015-08-27 17:31:10 -0700 | [diff] [blame] | 38 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
GlennRC | b3202c5 | 2015-08-24 14:43:30 -0700 | [diff] [blame] | 39 | |
| 40 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 41 | |
| 42 | def setupNetwork(): |
| 43 | "Create network" |
| 44 | topo = MyTopo() |
| 45 | network = Mininet(topo=topo, autoSetMacs=True, controller=None) |
| 46 | network.start() |
| 47 | CLI( network ) |
| 48 | network.stop() |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | setLogLevel('info') |
| 52 | #setLogLevel('debug') |
| 53 | setupNetwork() |