You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | """ |
| 4 | from mininet.topo import Topo |
| 5 | from mininet.net import Mininet |
| 6 | from mininet.node import Host, RemoteController |
| 7 | from mininet.node import Node |
| 8 | from mininet.node import CPULimitedHost |
| 9 | from mininet.link import TCLink |
| 10 | from mininet.cli import CLI |
| 11 | from mininet.log import setLogLevel |
| 12 | from mininet.util import dumpNodeConnections |
| 13 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 14 | |
| 15 | class dualStackHost( Host ): |
| 16 | def config( self, v6Addr='1000::1/64', **params ): |
| 17 | r = super( Host, self ).config( **params ) |
| 18 | intf = self.defaultIntf() |
| 19 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 20 | return r |
| 21 | |
| 22 | class tripleTopo( Topo ): |
| 23 | |
| 24 | def __init__( self, **opts ): |
| 25 | "Create a topology." |
| 26 | |
| 27 | # Initialize Topology |
| 28 | Topo.__init__( self, **opts ) |
| 29 | |
| 30 | s1 = self.addSwitch( 's1' ) |
| 31 | s2 = self.addSwitch( 's2' ) |
| 32 | s3 = self.addSwitch( 's3' ) |
| 33 | |
| 34 | # ... and now hosts |
| 35 | s1_host = self.addHost( 'h1', ip='10.1.0.1/24', cls=dualStackHost, v6Addr='1000::1/64' ) |
| 36 | s2_host = self.addHost( 'h2', ip='10.1.0.2/24', cls=dualStackHost, v6Addr='1000::2/64' ) |
| 37 | s3_host = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='1000::3/64' ) |
| 38 | |
| 39 | # add edges between switch and corresponding host |
| 40 | self.addLink( s1 , s1_host ) |
| 41 | self.addLink( s2 , s2_host ) |
| 42 | self.addLink( s3 , s3_host ) |
| 43 | self.addLink(s1, s2) |
| 44 | self.addLink(s1, s3) |
| 45 | self.addLink(s2, s3) |
| 46 | |
| 47 | topos = { 'triple': ( lambda: tripleTopo() ) } |
| 48 | |
| 49 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 50 | |
| 51 | def setupNetwork(): |
| 52 | "Create network" |
| 53 | topo = tripleTopo() |
| 54 | #if controller_ip == '': |
| 55 | #controller_ip = '10.0.2.2'; |
| 56 | # controller_ip = '127.0.0.1'; |
| 57 | network = Mininet(topo=topo, switch=OVSSwitch, autoSetMacs=True, controller=None) |
| 58 | network.start() |
| 59 | CLI( network ) |
| 60 | network.stop() |
| 61 | |
| 62 | if __name__ == '__main__': |
| 63 | setLogLevel('info') |
| 64 | #setLogLevel('debug') |
| 65 | setupNetwork() |