openleon_datacenter_tier3.py 1.99 KB
Newer Older
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This file creates a 3-tier data center topology
from mininet.net import Containernet
from mininet.topo import Topo
from mininet.link import TCLink
from mininet.node import CPULimitedHost
from mininet.node import Controller
from mininet.nodelib import NAT
from mininet.log import info, setLogLevel
"""setLogLevel('info')"""

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self, core=3, aggregation=6, edge=9, h=2, **opts):
        info("*** Creating custom datacenter topology\n")
	Core= [core]
	Aggr= [aggregation]
	Edge=[edge]
	self.Host=[edge*h]

	"Topo.__init__(self)"
	super(MyTopo, self).__init__(**opts)

        # Add hosts and switches
	info("*** Creating Core Switches\n")
        for i in range(core):
                Core.append(self.addSwitch('s%s' % i))
		print(Core[i+1])		

	info("*** Creating Aggregation Switches\n")
	for i in range(aggregation):
                Aggr.append(self.addSwitch('s%s' % (i+core)))

	info("*** Creating Edge Switches\n")
        for i in range(edge):
                Edge.append(self.addSwitch('s%s' % (i+core+aggregation)))

	info("*** Creating Hosts\n")
        for i in range (h*edge):
                self.Host.append(self.addHost('h%s' % i)) 

        # Add links
	"Links between Core and Aggregation Switches: All connected"
        for i in range (core):
                for j in range (aggregation):
                        self.addLink( Core[i+1], Aggr[j+1], bw=1000)			

	"""LInks between Aggregation and Edge Switches: We make groups depending on 
	the number of core switches"""
	n=0
	m=0
	for k in range (core):
		for i in range(n,aggregation/core+n):
			for j in range (m, edge/core+m):
				self.addLink(Aggr[i+1], Edge[j+1], bw=1000)
		n=n+aggregation/core
		m=m+edge/core
	
	n=0
	"""Links between Edge Switches and hosts: h hosts for each Swith"""
	for i in range (edge):
		for j in range(n,h+n):
			self.addLink(Edge[i+1], self.Host[j+1], bw=1000)
			
		n=n+h
	
	def hosts(n=1):
		return self.Host[n]


topos = { 'mytopo': MyTopo }
print("Finished")