-
Notifications
You must be signed in to change notification settings - Fork 2
/
spineleafdatacentertopo.py
169 lines (148 loc) · 4.38 KB
/
spineleafdatacentertopo.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from mininet.net import Mininet
from mininet.node import Controller,OVSKernelSwitch,RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import Link, Intf, TCLink
from mininet.topo import Topo
from mininet.util import irange,dumpNodeConnections
import logging
import os
logger = logging.getLogger( __name__ )
class LinearTopo(Topo):
logger.info("Class HugeTopo")
CoreSwitchList = []
AggSwitchList = []
EdgeSwitchList = []
HostList = []
KNumber = 0
def __init__(self, k, **opts):
super(LinearTopo, self).__init__(**opts)
self.k = k
self.iCoreLayerSwitch = (k/2)**2
self.iAggLayerSwitch = (k**2)/2
self.iEdgeLayerSwitch = (k**2)/2
self.iHost = (k**3)/4
lastSwitch = None
def createTopo(self):
logger.info("Start create Core Layer Swich")
self.createCoreLayerSwitch(self.iCoreLayerSwitch)
logger.debug("Start create Agg Layer Swich ")
self.createAggLayerSwitch(self.iAggLayerSwitch)
logger.debug("Start create Edge Layer Swich ")
self.createEdgeLayerSwitch(self.iEdgeLayerSwitch)
logger.debug("Start create Host")
self.createHost(self.iHost)
def createCoreLayerSwitch(self,NUMBER):
logger.info("Create Core Layer")
k1=NUMBER
Coreid=[]
for i in irange(1,k1/2):
k2=1
while k2<((k1/2)+1):
print '000000000'+'%s'%k1+'0'+'%s'%i+'0'+'%s'%k2
Coreid.append('000000000'+'%s'%k1+'0'+'%s'%i+'0'+'%s'%k2)
k2=k2+1
for i in irange(1,NUMBER):
self.CoreSwitchList.append(self.addSwitch('CS%s' % i,dpid=Coreid[i-1],listenport=6633,protcols=["OpenFlow13"],Controller=RemoteController))
print self.CoreSwitchList[0]
def createAggLayerSwitch(self,NUMBER):
logger.info("Create Agg Layer")
k1=NUMBER/2
Aggid=[]
for i1 in range(0,k1):
k2=((k1/2)+1)
while k2<(k1+1):
print '00000000000'+'%s'%i1+'0'+'%s'%k2+'01'
Aggid.append('00000000000'+'%s'%i1+'0'+'%s'%k2+'01')
k2=k2+1
for i in irange(1,NUMBER):
self.AggSwitchList.append(self.addSwitch('AS%s' % (i),dpid=Aggid[i-1],listenport=6633,protcols=["OpenFlow13"],controller=RemoteController))
print ('AS%s',i)
print Aggid
def createEdgeLayerSwitch(self,NUMBER):
logger.info("Create Edge Layer")
k1=NUMBER/2
Eggid=[]
for i1 in range(0,k1):
k2=1
while k2<((k1/2)+1):
print '00000000000'+'%s'%i1+'0'+'%s'%k2+'01'
Eggid.append('00000000000'+'%s'%i1+'0'+'%s'%k2+'01')
k2=k2+1
for i in irange(1,NUMBER):
self.EdgeSwitchList.append(self.addSwitch('ES%s' % (i),dpid=Eggid[i-1],listenport=6633,protcols=["OpenFlow13"],controller=RemoteController))
print ('ES%s',i)
print Eggid
def createHost(self,NUMBER):
logger.info("Create Hosts")
Host=[]
k1=NUMBER/4
for i in range(0,k1):
k3=0
while k3<(k1/2):
k2=0
while(k2<(k1/2)):
print i,k2
Host.append('10.'+'%s'%i+'.'+'%s.'%k3+'%s'%((k1/2)+k2))
k2=k2+1
k3=k3+1
for i in irange(1,NUMBER):
self.HostList.append(self.addHost('Host%s'%i))
print Host
def createLink(self):
logger.info("Start creating Links")
logger.info("Creating Core to Agg Layer links")
k = self.k
#for i in range(0,(2*(k/2)),(k/2)):
# for j in range(0,(k/2)):
k1=0
m=0
k3=0
while k1<(k/2):
k4=(0)
for i in range(k1,((k/2)*k),(k/2)):
k2=0
while k2<(k/2):
print k2+m,i,k4+1,(k/2)-1-k2+1
self.addLink(self.CoreSwitchList[k2+m],self.AggSwitchList[i],k4+1,(k/2)-1-k2+1)
k2=k2+1
k4=k4+1
k3=k3+(k/2)
m=k2
k1=k1+1
for i in range(0,((k/2)*k),(k/2)):
m1=((k/2)-1)
for j in range(0,(k/2)):
k1=0
while(k1<(k/2)):
print ((k/2)+k1+1),m1+1
self.addLink(self.AggSwitchList[j+i],self.EdgeSwitchList[k1+i],((k/2)+k1+1),m1+1)
k1=k1+1
m1=m1-1
m=0
for i in range(0,((k/2)*k)):
k1=0
while k1<(k/2):
self.addLink(self.EdgeSwitchList[i],self.HostList[m],port1=(((k/2)+k1)+1),port2=1)
print self.EdgeSwitchList[i],self.HostList[m]
k1=k1+1
m=m+1
def simpleTest():
topo = LinearTopo(k=4)
topo.createTopo()
topo.createLink()
#use=LinearTopo.DPIDS(4)
net = Mininet(topo, link=TCLink,controller=None,autoSetMacs=True,autoStaticArp=True)
ryu_ctrl=RemoteController(name='c1',ip='192.168.1.107',port=6633,protocols="OpenFlow13")
net.addController(ryu_ctrl)
print "addcontroller"
#net.get('ES1').start([ryu_ctrl])
net.start()
net.staticArp()
#net.cli()
dumpNodeConnections(net.hosts)
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel('info')
simpleTest()