from mininet.net import Mininet from mininet.topo import Topo from mininet.cli import CLI class TreeTopology(Topo): def build(self, n=2): core_switch = self.addSwitch('s1') switch_count = 0 host_count = 0 for _ in range(n): agg_switch = self.addSwitch('a_s%d' % (switch_count + 1)) self.addLink(core_switch, agg_switch) switch_count += 1 for _ in range(n): edge_switch = self.addSwitch('e_s%d' % (switch_count + 1)) self.addLink(agg_switch, edge_switch) switch_count += 1 for _ in range(n): host = self.addHost('h%d' % (host_count + 1)) self.addLink(edge_switch, host) host_count += 1 topo = TreeTopology() net = Mininet(topo) net.start() CLI(net) net.stop()