from mininet.net import Mininet from mininet.topo import Topo from mininet.cli import CLI class TreeTopology(Topo): def __init__(self, n): Topo.__init__(self) core_switch = self.addSwitch('s1', dpid='000000000001') aggregation_switches = [] edge_switches = [] for i in range(n): agg_switch = self.addSwitch('s%d' % (i + 2), dpid=format(i + 2, '016x')) self.addLink(core_switch, agg_switch) aggregation_switches.append(agg_switch) for j in range(n): edge_switch = self.addSwitch('s%d' % (i * n + j + n + 2), dpid=format(i * n + j + n + 2, '016x')) self.addLink(agg_switch, edge_switch) edge_switches.append(edge_switch) for k in range(n): host = self.addHost('h%d' % (i * n * n + j * n + k + n * n + n + 2)) self.addLink(edge_switch, host) n = int(input("Enter the value of n: ")) topo = TreeTopology(n) net = Mininet(topo) net.start() CLI(net) net.stop()