aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/tools/test/topos/fractal.py
blob: bc5c6899b025207b01b45abeae89d3fc35b5f3d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python

from mininet.topo import Topo

class FractalTopo( Topo ):
    def build( self, n=3, h=2 ):

        clusters = []
        for i in range( 1, n+1 ):
            clusterSws = []
            # create switches in cluster
            for j in range( 1, n+1 ):
                id = i * 1000 + j
                sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
                [ self.addLink(s, sw) for s in clusterSws ]
                clusterSws.append(sw)
            clusters.append(clusterSws)

        for i in range( 1, n+1 ):
            # create the edge switch
            id = i * 10000
            sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
            self.addLink(clusters[i-1].pop(0), sw)
            for j in range( 1, h+1 ):
                id = i * 1000 + j
                host = self.addHost( 'h%d' % id )
                self.addLink( host, sw )

        for i in range( 1, n+1 ):
            # connect the clusters
            if i == n:
                id = n * 1000000 + 10000
                sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
                self.addLink(clusters[i-1].pop(0), sw)
                self.addLink(clusters[0].pop(0), sw)

            else:
                id = (i+1) * 1000000 + i * 10000
                sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
                self.addLink(clusters[i-1].pop(0), sw)
                self.addLink(clusters[i].pop(0), sw)


topos = { 'fractal': FractalTopo }

def run():
    topo = FractalTopo()
    net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
    net.start()
    CLI( net )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    run()