Revision b5962e8e

View differences:

bin/mn
30 30
from mininet.nodelib import LinuxBridge
31 31
from mininet.link import Link, TCLink
32 32
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
33
from mininet.topolib import TreeTopo
33
from mininet.topolib import TreeTopo, TorusTopo
34 34
from mininet.util import custom, customConstructor
35 35
from mininet.util import buildTopo
36 36

  
......
41 41
          'linear': LinearTopo,
42 42
          'reversed': SingleSwitchReversedTopo,
43 43
          'single': SingleSwitchTopo,
44
          'tree': TreeTopo }
44
          'tree': TreeTopo,
45
          'torus': TorusTopo }
45 46

  
46 47
SWITCHDEF = 'ovsk'
47 48
SWITCHES = { 'user': UserSwitch,
mininet/topolib.py
34 34
    "Convenience function for creating tree networks."
35 35
    topo = TreeTopo( depth, fanout )
36 36
    return Mininet( topo, **kwargs )
37

  
38

  
39
class TorusTopo( Topo ):
40
    """2-D Torus topology
41
       WARNING: this topology has LOOPS and WILL NOT WORK
42
       with the default controller or any Ethernet bridge
43
       without STP turned on! It can be used with STP, e.g.:
44
       # mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall"""
45
    def __init__( self, x, y, *args, **kwargs ):
46
        Topo.__init__( self, *args, **kwargs )
47
        if x < 3 or y < 3:
48
            raise Exception( 'Please use 3x3 or greater for compatibility '
49
                            'with Mininet 2.1.0' )
50
        hosts, switches, dpid = {}, {}, 0
51
        # Create and wire interior
52
        for i in range( 0, x ):
53
            for j in range( 0, y ):
54
                loc = '%dx%d' % ( i + 1, j + 1 )
55
                # dpid cannot be zero for OVS
56
                dpid = ( i + 1 ) * 256 + ( j + 1 )
57
                switch = switches[ i, j ] = self.addSwitch( 's' + loc, dpid='%016x' % dpid )
58
                host = hosts[ i, j ] = self.addHost( 'h' + loc )
59
                self.addLink( host, switch )
60
        # Connect switches
61
        for i in range( 0, x ):
62
            for j in range( 0, y ):
63
                sw1 = switches[ i, j ]
64
                sw2 = switches[ i, ( j + 1 ) % y ]
65
                sw3 = switches[ ( i + 1 ) % x, j ]
66
                self.addLink( sw1, sw2 )
67
                self.addLink( sw1, sw3 )
68

  
69
    
70

  

Also available in: Unified diff