kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [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 MyTopo( Topo ): |
| 18 | |
| 19 | def __init__( self, **opts ): |
| 20 | # Initialize topology |
| 21 | Topo.__init__( self, **opts) |
| 22 | |
| 23 | # IPv4 hosts |
| 24 | host1=self.addHost( 'h1', ip='10.0.0.1/24' ) |
| 25 | host2=self.addHost( 'h2', ip='10.0.0.2/24' ) |
| 26 | host3=self.addHost( 'h3', ip='10.0.0.3/24' ) |
| 27 | host4=self.addHost( 'h4', ip='10.0.0.4/24' ) |
| 28 | |
| 29 | s1 = self.addSwitch( 's1' ) |
| 30 | |
| 31 | self.addLink(s1, host1) |
| 32 | self.addLink(s1, host2) |
| 33 | self.addLink(s1, host3) |
| 34 | self.addLink(s1, host4) |
| 35 | |
| 36 | topos = { 'mytopo': ( lambda: MyTopo() ) } |
| 37 | |
| 38 | def setupNetwork(): |
| 39 | "Create network" |
| 40 | topo = MyTopo() |
| 41 | network = Mininet(topo=topo, autoSetMacs=True, autoStaticArp=True, controller=None) |
| 42 | network.start() |
| 43 | CLI( network ) |
| 44 | network.stop() |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | setLogLevel('info') |
| 48 | #setLogLevel('debug') |
| 49 | setupNetwork() |