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 ringTopo( 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 | 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 | s9 = self.addSwitch( 's9' ) |
| 39 | s10 = self.addSwitch( 's10' ) |
| 40 | |
| 41 | # ... and now hosts |
| 42 | s1_host = self.addHost( 'h1', ip='10.1.0.1/24', cls=dualStackHost, v6Addr='1000::1/64' ) |
| 43 | s2_host = self.addHost( 'h2', ip='10.1.0.2/24', cls=dualStackHost, v6Addr='1000::2/64' ) |
| 44 | s3_host = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='1000::3/64' ) |
| 45 | s4_host = self.addHost( 'h4', ip='10.1.0.4/24', cls=dualStackHost, v6Addr='1000::4/64' ) |
| 46 | s5_host = self.addHost( 'h5', ip='10.1.0.5/24', cls=dualStackHost, v6Addr='1000::5/64' ) |
| 47 | s6_host = self.addHost( 'h6', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='1000::6/64' ) |
| 48 | s7_host = self.addHost( 'h7', ip='10.1.0.7/24', cls=dualStackHost, v6Addr='1000::7/64' ) |
| 49 | s8_host = self.addHost( 'h8', ip='10.1.0.8/24', cls=dualStackHost, v6Addr='1000::8/64' ) |
| 50 | s9_host = self.addHost( 'h9', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='1000::9/64' ) |
| 51 | s10_host = self.addHost( 'h10', ip='10.1.0.10/24', cls=dualStackHost, v6Addr='1000::10/64' ) |
| 52 | |
| 53 | # add edges between switch and corresponding host |
| 54 | self.addLink( s1 , s1_host ) |
| 55 | self.addLink( s2 , s2_host ) |
| 56 | self.addLink( s3 , s3_host ) |
| 57 | self.addLink( s4 , s4_host ) |
| 58 | self.addLink( s5 , s5_host ) |
| 59 | self.addLink( s6 , s6_host ) |
| 60 | self.addLink( s7 , s7_host ) |
| 61 | self.addLink( s8 , s8_host ) |
| 62 | self.addLink( s9 , s9_host ) |
| 63 | self.addLink( s10 , s10_host ) |
| 64 | self.addLink(s1, s2) |
| 65 | self.addLink(s2, s3) |
| 66 | self.addLink(s3, s4) |
| 67 | self.addLink(s4, s5) |
| 68 | self.addLink(s5, s6) |
| 69 | self.addLink(s6, s7) |
| 70 | self.addLink(s7, s8) |
| 71 | self.addLink(s8, s9) |
| 72 | self.addLink(s9, s10) |
| 73 | self.addLink(s10, s1) |
| 74 | |
| 75 | topos = { 'ring': ( lambda: ringTopo() ) } |
| 76 | |
| 77 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 78 | |
| 79 | def setupNetwork(): |
| 80 | "Create network" |
| 81 | topo = ringTopo() |
| 82 | #if controller_ip == '': |
| 83 | #controller_ip = '10.0.2.2'; |
| 84 | # controller_ip = '127.0.0.1'; |
| 85 | network = Mininet(topo=topo, switch=OVSSwitch, autoSetMacs=True, controller=None) |
| 86 | network.start() |
| 87 | CLI( network ) |
| 88 | network.stop() |
| 89 | |
| 90 | if __name__ == '__main__': |
| 91 | setLogLevel('info') |
| 92 | #setLogLevel('debug') |
| 93 | setupNetwork() |