# test.py from mininet.topo import Topo from mininet.net import Mininet from mininet.node import RemoteController from mininet.link import TCLink from mininet.util import dumpNodeConnections
classMyTopo(Topo):
def__init__(self): super(MyTopo, self).__init__()
# Marking the number of switch for per level L1 = 2 L2 = 4 L3 = 4 L4 = 8
# Starting create the switch c = [] # core switch a = [] # aggregate switch e = [] # edge switch h = [] # host
# notice: switch label is a special data structure for i inrange(L1): # label from 1 to n,not start with 0 c_sw = self.addSwitch('c{}'.format(i+1)) c.append(c_sw)
for i inrange(L2): a_sw = self.addSwitch('a{}'.format(L1+i+1)) a.append(a_sw)
for i inrange(L3): e_sw = self.addSwitch('e{}'.format(L1+L2+i+1)) e.append(e_sw)
# Starting create the link between switchs # first the first level and second level link for i inrange(L1): for j inrange(4): self.addLink(c[i], a[j])
# second the second level and third level link for i inrange(L2): for j inrange(2): self.addLink(a[i], e[(i//2)*2+j])
# Starting create the host and create link between switchs and hosts for i inrange(L3): for j inrange(2): hs = self.addHost('h{}'.format(i*2+j+1)) h.append(hs) self.addLink(e[i], hs)