from mininet.net import Mininet from mininet.topo import Topo from mininet.cli import CLI class TreeTopology(Topo): def __init__(self): Topo.__init__(self) core_switch = self.addSwitch('core', dpid='000000000001') aggregation_switches = [] edge_switches = [] for i in range(2): agg_switch = self.addSwitch('a_s%d' % (i + 1), dpid=format(i + 2, '016x')) self.addLink(core_switch, agg_switch) aggregation_switches.append(agg_switch) for j in range(2): edge_switch = self.addSwitch('e_s%d' % (i * 2 + j + 1), dpid=format(i * 2 + j + 3, '016x')) self.addLink(agg_switch, edge_switch) edge_switches.append(edge_switch) for k in range(2): host = self.addHost('h%d' % (i * 4 + j * 2 + k + 1)) self.addLink(edge_switch, host) topo = TreeTopology() net = Mininet(topo) net.start() CLI(net) net.stop()